20 Jan, 2021

1 commit

  • [ Upstream commit 1eda52334e6d13eb1a85f713ce06dd39342b5020 ]

    With MAX_PWM being defined to 255 the code

    unsigned long period;
    ...
    period = ctx->pwm->args.period;
    state.duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);

    calculates a too small value for duty_cycle if the configured period is
    big (either by discarding the 64 bit value ctx->pwm->args.period or by
    overflowing the multiplication). As this results in a too slow fan and
    so maybe an overheating machine better be safe than sorry and error out
    in .probe.

    Signed-off-by: Uwe Kleine-König
    Link: https://lore.kernel.org/r/20201215092031.152243-1-u.kleine-koenig@pengutronix.de
    Signed-off-by: Guenter Roeck
    Signed-off-by: Sasha Levin

    Uwe Kleine-König
     

12 Nov, 2020

1 commit

  • To convert the number of pulses counted into an RPM estimation, we need
    to divide by the width of our measurement interval instead of
    multiplying by it. If the width of the measurement interval is zero we
    don't update the RPM value to avoid dividing by zero.

    We also don't need to do 64-bit division, with 32-bits we can handle a
    fan running at over 4 million RPM.

    Signed-off-by: Paul Barker
    Link: https://lore.kernel.org/r/20201111164643.7087-1-pbarker@konsulko.com
    Signed-off-by: Guenter Roeck

    Paul Barker
     

24 Sep, 2020

1 commit


16 Jun, 2020

1 commit


24 Jan, 2020

1 commit

  • The pwm-fan driver stops the fan in suspend but leaves the fan on in
    shutdown. It seems strange to leave the fan on in shutdown because there
    is no use case in my mind and the gpio-fan driver on the other hand stops
    in shutdown.

    This change turns off the fan in shutdown. If anyone complains then we'll
    add an optional property to switch the behavior.

    Cc: Rob Herring
    Cc: Mark Rutland
    Cc: Kamil Debski
    Cc: Bartlomiej Zolnierkiewicz
    Cc: Guenter Roeck
    Cc: Thierry Reding
    Cc: Uwe Kleine-König
    Signed-off-by: Akinobu Mita
    Link: https://lore.kernel.org/r/1579534344-11694-1-git-send-email-akinobu.mita@gmail.com
    Signed-off-by: Guenter Roeck

    Akinobu Mita
     

29 Aug, 2019

1 commit

  • The PWM fan interrupt is optional, so we don't want an error message in
    the kernel log if it wasn't specified.

    Signed-off-by: Thierry Reding
    Reviewed-by: Stephen Boyd
    Acked-by: Guenter Roeck
    Acked-by: Bartlomiej Zolnierkiewicz
    Link: https://lore.kernel.org/r/20190828083411.2496-2-thierry.reding@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Thierry Reding
     

24 Jun, 2019

1 commit


31 May, 2019

1 commit

  • Based on 3 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [kishon] [vijay] [abraham]
    [i] [kishon]@[ti] [com] this program is distributed in the hope that
    it will be useful but without any warranty without even the implied
    warranty of merchantability or fitness for a particular purpose see
    the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [graeme] [gregory]
    [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i]
    [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema]
    [hk] [hemahk]@[ti] [com] this program is distributed in the hope
    that it will be useful but without any warranty without even the
    implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1105 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

16 May, 2019

1 commit

  • Pull thermal soc updates from Eduardo Valentin:

    - thermal core has a new devm_* API for registering cooling devices. I
    took the entire series, that is why you see changes on drivers/hwmon
    in this pull (Guenter Roeck)

    - rockchip thermal driver gains support to PX30 SoC (Elaine Zhang)

    - the generic-adc thermal driver now considers the lookup table DT
    property as optional (Jean-Francois Dagenais)

    - Refactoring of tsens thermal driver (Amit Kucheria)

    - Cleanups on cpu cooling driver (Daniel Lezcano)

    - broadcom thermal driver dropped support to ACPI (Srinath Mannam)

    - tegra thermal driver gains support to OC hw throttle and GPU throtle
    (Wei Ni)

    - Fixes in several thermal drivers.

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal: (59 commits)
    hwmon: (pwm-fan) Use devm_thermal_of_cooling_device_register
    hwmon: (npcm750-pwm-fan) Use devm_thermal_of_cooling_device_register
    hwmon: (mlxreg-fan) Use devm_thermal_of_cooling_device_register
    hwmon: (gpio-fan) Use devm_thermal_of_cooling_device_register
    hwmon: (aspeed-pwm-tacho) Use devm_thermal_of_cooling_device_register
    thermal: rcar_gen3_thermal: Fix to show correct trip points number
    thermal: rcar_thermal: update calculation formula for R-Car Gen3 SoCs
    thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power
    thermal: rockchip: Support the PX30 SoC in thermal driver
    dt-bindings: rockchip-thermal: Support the PX30 SoC compatible
    thermal: rockchip: fix up the tsadc pinctrl setting error
    thermal: broadcom: Remove ACPI support
    thermal: Fix build error of missing devm_ioremap_resource on UM
    thermal/drivers/cpu_cooling: Remove pointless field
    thermal/drivers/cpu_cooling: Add Software Package Data Exchange (SPDX)
    thermal/drivers/cpu_cooling: Fixup the header and copyright
    thermal/drivers/cpu_cooling: Remove pointless test in power2state()
    thermal: rcar_gen3_thermal: disable interrupt in .remove
    thermal: rcar_gen3_thermal: fix interrupt type
    thermal: Introduce devm_thermal_of_cooling_device_register
    ...

    Linus Torvalds
     

14 May, 2019

1 commit

  • Use devm_thermal_of_cooling_device_register() to register the cooling
    device. Also use devm_add_action_or_reset() to stop the fan on device
    removal, and to disable the pwm. Introduce a local 'dev' variable in
    the probe function to make the code easier to read.

    As a side effect, this fixes a bug seen if pwm_fan_of_get_cooling_data()
    returned an error. In that situation, the pwm was not disabled, and
    the fan was not stopped. Using devm functions also ensures that the
    pwm is disabled and that the fan is stopped only after the hwmon device
    has been unregistered.

    Cc: Lukasz Majewski
    Signed-off-by: Guenter Roeck
    Signed-off-by: Eduardo Valentin

    Guenter Roeck
     

16 Apr, 2019

3 commits

  • Printing the error code for a failure provides a head-start for
    debugging, since it's often sufficient to pinpoint the origin of the
    failure. We already do this for some probe-failure messages, so let's
    make the rest of them consistent.

    Signed-off-by: Robin Murphy
    Signed-off-by: Guenter Roeck

    Robin Murphy
     
  • This adds RPM support to the pwm-fan driver in order to use with
    fancontrol/pwmconfig. This feature is intended for fans with a tachometer
    output signal, which generate a defined number of pulses per revolution.

    Signed-off-by: Stefan Wahren
    Reviewed-by: Robin Murphy
    Signed-off-by: Robin Murphy
    [groeck: Drop unused 'devattr' variable]
    Signed-off-by: Guenter Roeck

    Stefan Wahren
     
  • In case pwm_fan_of_get_cooling_data() fails we should disable the PWM
    just like in the other error cases.

    Fixes: 2e5219c77183 ("hwmon: (pwm-fan) Read PWM FAN configuration from device tree")
    Cc: # 4.14+
    Reported-by: Guenter Rock
    Signed-off-by: Stefan Wahren
    Signed-off-by: Guenter Roeck

    Stefan Wahren
     

24 Feb, 2019

1 commit


17 Dec, 2018

1 commit


11 Oct, 2018

2 commits

  • Technically this is not required because disabling the PWM should be
    enough. However, when support for atomic operations was implemented in
    the PWM subsystem, only actual changes to the PWM channel are applied
    during pwm_config(), which means that during after resume from suspend
    the old settings won't be applied.

    One possible solution is for the PWM driver to implement its own PM
    operations such that settings from before suspend get applied on resume.
    This has the disadvantage of completely ignoring any particular ordering
    requirements that PWM user drivers might have, so it is best to leave it
    up to the user drivers to apply the settings that they want at the
    appropriate time.

    Another way to solve this would be to read back the current state of the
    PWM at the time of resume. That way, in case the configuration was lost
    during suspend, applying the old settings in PWM user drivers would
    actually get them applied because they differ from the current settings.
    However, not all PWM drivers support reading the hardware state, and not
    all hardware may support it.

    The best workaround at this point seems to be to let PWM user drivers
    tell the PWM subsystem that the PWM is turned off by, in addition to
    disabling it, also setting the duty cycle to 0. This causes the resume
    operation to apply a configuration that is different from the current
    configuration, resulting in the proper state from before suspend getting
    restored.

    Signed-off-by: Thierry Reding
    Signed-off-by: Guenter Roeck

    Thierry Reding
     
  • Probe deferrals aren't actual errors, so silence the error message in
    case the PWM cannot yet be acquired.

    Signed-off-by: Thierry Reding
    Signed-off-by: Guenter Roeck

    Thierry Reding
     

13 Jun, 2018

1 commit

  • The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
    This patch replaces cases of:

    devm_kzalloc(handle, a * b, gfp)

    with:
    devm_kcalloc(handle, a * b, gfp)

    as well as handling cases of:

    devm_kzalloc(handle, a * b * c, gfp)

    with:

    devm_kzalloc(handle, array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    devm_kcalloc(handle, array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    devm_kzalloc(handle, 4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    Some manual whitespace fixes were needed in this patch, as Coccinelle
    really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    expression HANDLE;
    type TYPE;
    expression THING, E;
    @@

    (
    devm_kzalloc(HANDLE,
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression HANDLE;
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    expression HANDLE;
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    expression HANDLE;
    identifier SIZE, COUNT;
    @@

    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression HANDLE;
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression HANDLE;
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    expression HANDLE;
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    devm_kzalloc(HANDLE,
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression HANDLE;
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression HANDLE;
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
    |
    devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
    |
    devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
    |
    devm_kzalloc(HANDLE, C1 * C2, ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

12 Jun, 2017

1 commit


17 May, 2016

1 commit

  • The PWM framework has clarified the concept of reference PWM config (the
    platform dependent config retrieved from the DT or the PWM lookup table)
    and real PWM state.

    Use pwm_get_args() when the PWM user wants to retrieve this reference
    config and not the current state.

    This is part of the rework allowing the PWM framework to support
    hardware readout and expose real PWM state even when the PWM has just
    been requested (before the user calls pwm_config/enable/disable()).

    Signed-off-by: Boris Brezillon
    Acked-by: Kamil Debski
    Signed-off-by: Thierry Reding

    Boris Brezillon
     

21 Sep, 2015

1 commit


13 Apr, 2015

1 commit


17 Mar, 2015

1 commit


10 Mar, 2015

4 commits


12 Nov, 2014

1 commit


04 Aug, 2014

2 commits

  • The dev_set_drvdata() call is equivalent to the platform_set_drvdata() call in
    next line.

    Signed-off-by: Axel Lin
    Signed-off-by: Guenter Roeck

    Axel Lin
     
  • The pwm-fan driver enables control of fans connected to PWM lines.
    This driver uses the PWM framework, so it is compatible with all
    PWM devices that provide drivers through the PWM framework.

    Signed-off-by: Kamil Debski
    Reviewed-by: Varka Bhadram
    Reviewed-by: Tobias Klauser
    [Guenter Roeck: Last argument to devm_of_pwm_get is pointer, use NULL]
    Signed-off-by: Guenter Roeck

    Kamil Debski