05 Sep, 2016

1 commit

  • Exported pwm channels aren't removed before the pwmchip and are
    leaked. This results in invalid sysfs files. This fix removes
    all exported pwm channels before chip removal.

    Signed-off-by: David Hsu
    Fixes: 76abbdde2d95 ("pwm: Add sysfs interface")
    Signed-off-by: Thierry Reding

    David Hsu
     

25 Jul, 2016

2 commits


09 Jul, 2016

1 commit


08 Jul, 2016

2 commits

  • The PWM framework expects PWM users to configure the duty cycle in nano-
    seconds, but many users want to express the duty cycle relatively to the
    period value (i.e. duty_cycle = 33% of the period).

    Add the pwm_{get,set}_relative_duty_cycle() helpers to ease this kind of
    conversion.

    Signed-off-by: Boris Brezillon
    Tested-by: Heiko Stuebner
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • The pwm_init_state() helper prepares a new state object containing the
    current PWM state except for the polarity and period fields which are
    set to the reference values (those in struct pwm_args).

    This is particularly useful for PWM users who want to apply a new duty-
    cycle expressed relatively to the reference period without changing the
    enable state.

    Signed-off-by: Boris Brezillon
    Tested-by: Heiko Stuebner
    Signed-off-by: Thierry Reding

    Boris Brezillon
     

24 Jun, 2016

1 commit

  • Commit 5ec803edcb70 ("pwm: Add core infrastructure to allow atomic
    updates"), implemented pwm_disable() as a wrapper around
    pwm_apply_state(), and then, commit ef2bf4997f7d ("pwm: Improve args
    checking in pwm_apply_state()") added missing checks on the ->period
    value in pwm_apply_state() to ensure we were not passing inappropriate
    values to the ->config() or ->apply() methods.

    The conjunction of these 2 commits led to a case where pwm_disable()
    was no longer succeeding, thus preventing the polarity setting done
    in pwm_apply_args().

    Set a valid period in pwm_apply_args() to ensure polarity setting
    won't be rejected.

    Signed-off-by: Boris Brezillon
    Reported-by: Geert Uytterhoeven
    Suggested-by: Brian Norris
    Fixes: 5ec803edcb70 ("pwm: Add core infrastructure to allow atomic updates")
    Tested-by: Geert Uytterhoeven
    Reviewed-by: Brian Norris
    Signed-off-by: Thierry Reding

    Boris Brezillon
     

10 Jun, 2016

2 commits

  • Supply a PWM capture callback op in order to pass back information
    obtained by running analysis on a PWM signal. This would normally (at
    least during testing) be called from the sysfs routines with a view to
    printing out PWM capture data which has been encoded into a string.

    Signed-off-by: Lee Jones
    [thierry.reding@gmail.com: make capture data unsigned int for symmetry]
    Signed-off-by: Thierry Reding

    Lee Jones
     
  • It seems like in the process of refactoring pwm_config() to utilize the
    newly-introduced pwm_apply_state() API, some args/bounds checking was
    dropped.

    In particular, I noted that we are now allowing invalid period
    selections, e.g.:

    # echo 1 > /sys/class/pwm/pwmchip0/export
    # cat /sys/class/pwm/pwmchip0/pwm1/period
    100
    # echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
    [... driver may or may not reject the value, or trigger some logic bug ...]

    It's better to see:

    # echo 1 > /sys/class/pwm/pwmchip0/export
    # cat /sys/class/pwm/pwmchip0/pwm1/period
    100
    # echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
    -bash: echo: write error: Invalid argument

    This patch reintroduces some bounds checks in both pwm_config() (for its
    signed parameters; we don't want to convert negative values into large
    unsigned values) and in pwm_apply_state() (which fix the above described
    behavior, as well as other potential API misuses).

    Fixes: 5ec803edcb70 ("pwm: Add core infrastructure to allow atomic updates")
    Signed-off-by: Brian Norris
    Acked-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Brian Norris
     

17 May, 2016

6 commits

  • Add an ->apply() method to the pwm_ops struct to allow PWM drivers to
    implement atomic updates. This method is preferred over the ->enable(),
    ->disable() and ->config() methods if available.

    Add the pwm_apply_state() function to the PWM user API.

    Note that the pwm_apply_state() does not guarantee the atomicity of the
    update operation, it all depends on the availability and implementation
    of the ->apply() method.

    pwm_enable/disable/set_polarity/config() are now implemented as wrappers
    around the pwm_apply_state() function.

    pwm_adjust_config() is allowing smooth handover between the bootloader
    and the kernel. This function tries to adapt the current PWM state to
    the PWM arguments coming from a PWM lookup table or a DT definition
    without changing the duty_cycle/period proportion.

    Signed-off-by: Boris Brezillon
    [thierry.reding@gmail.com: fix a couple of typos]
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • Add a ->get_state() function to the pwm_ops struct to let PWM drivers
    initialize the PWM state attached to a PWM device.

    Signed-off-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • Prepare the transition to PWM atomic update by moving the enabled and
    disabled state into the pwm_state struct. This way we can easily update
    the whole PWM state by copying the new state in the ->state field.

    Signed-off-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • The PWM state, represented by its period, duty_cycle and polarity is
    currently directly stored in the PWM device. Declare a pwm_state
    structure embedding those field so that we can later use this struct
    to atomically update all the PWM parameters at once.

    All pwm_get_xxx() helpers are now implemented as wrappers around
    pwm_get_state().

    Signed-off-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • Before the introduction of pwm_args, the core was resetting the PWM
    period and polarity states to the reference values (those provided
    through the DT, a PWM lookup table or hardcoded in the driver).

    Now that all PWM users are correctly using pwm_args to configure their
    PWM device, we can safely remove the pwm_apply_args() call in pwm_get()
    and of_pwm_get().

    We can also get rid of the pwm_set_period() call in pwm_apply_args(),
    because PWM users are now directly using pargs->period instead of
    pwm_get_period(). By doing that we avoid messing with the current PWM
    period.

    The only remaining bit in pwm_apply_args() is the initial polarity
    setting, and it should go away when all PWM users have been patched to
    use the atomic API (with this API the polarity will be set along with
    other PWM arguments when configuring the PWM).

    Signed-off-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Boris Brezillon
     
  • PWM devices are not protected against concurrent accesses. The lock in
    struct pwm_device might let PWM users think it is, but it's actually
    only protecting the enabled state.

    Removing this lock should be fine as long as all PWM users are aware
    that accesses to the PWM device have to be serialized, which seems to be
    the case for all of them except the sysfs interface. Patch the sysfs
    code by adding a lock to the pwm_export struct and making sure it's
    taken for all relevant accesses to the exported PWM device.

    Signed-off-by: Boris Brezillon
    Signed-off-by: Thierry Reding

    Boris BREZILLON
     

03 May, 2016

1 commit

  • Currently the PWM core mixes the current PWM state with the per-platform
    reference config (specified through the PWM lookup table, DT definition
    or directly hardcoded in PWM drivers).

    Create a struct pwm_args to store this reference configuration, so that
    PWM users can differentiate between the current and reference
    configurations.

    Patch all places where pwm->args should be initialized. We keep the
    pwm_set_polarity/period() calls until all PWM users are patched to use
    pwm_args instead of pwm_get_period/polarity().

    Signed-off-by: Boris Brezillon
    [thierry.reding@gmail.com: reword kerneldoc comments]
    Signed-off-by: Thierry Reding

    Boris Brezillon
     

10 Nov, 2015

1 commit

  • The pwm_enable() function didn't clear the enabled bit if a call to the
    driver's ->enable() callback returned an error. The result was that the
    state of the PWM core was wrong. Clearing the bit when enable returns
    an error ensures the state is properly set.

    Tested-by: Jonathan Richardson
    Reviewed-by: Dmitry Torokhov
    Signed-off-by: Jonathan Richardson
    [thierry.reding@gmail.com: add missing kerneldoc for the lock]
    Signed-off-by: Thierry Reding

    Jonathan Richardson
     

17 Aug, 2015

2 commits


20 Jul, 2015

3 commits


12 Jun, 2015

1 commit

  • Add a new function to register a PWM chip with channels that have their
    initial polarity as specified by an additional parameter. This benefits
    drivers of controllers that by default operate with inversed polarity
    by removing the need to modify the polarity during initialization.

    Signed-off-by: Tim Kryger
    Signed-off-by: Jonathan Richardson
    [thierry.reding@gmail.com: export pwmchip_add_with_polarity()]
    Signed-off-by: Thierry Reding

    Tim Kryger
     

06 May, 2015

1 commit


21 May, 2014

2 commits


10 Feb, 2014

1 commit

  • Before we had the PWM framework we used to have a barebone PWM api. The
    HAVE_PWM Kconfig symbol used to be selected by the PWM drivers to specify
    the PWM API is present in the kernel. Since the last legacy driver is gone
    the HAVE_PWM symbol can go aswell.

    Signed-off-by: Sascha Hauer
    Cc: Dmitry Torokhov
    Cc: Eric Miao
    Cc: Haojian Zhuang
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-kernel@vger.kernel.org
    Cc: Thierry Reding
    Cc: linux-pwm@vger.kernel.orig
    Cc: Russell King
    Cc: Ralf Baechle
    Signed-off-by: Thierry Reding

    Sascha Hauer
     

21 Jun, 2013

1 commit

  • Add a simple sysfs interface to the generic PWM framework.

    /sys/class/pwm/
    `-- pwmchipN/ for each PWM chip
    |-- export (w/o) ask the kernel to export a PWM channel
    |-- npwm (r/o) number of PWM channels in this PWM chip
    |-- pwmX/ for each exported PWM channel
    | |-- duty_cycle (r/w) duty cycle (in nanoseconds)
    | |-- enable (r/w) enable/disable PWM
    | |-- period (r/w) period (in nanoseconds)
    | `-- polarity (r/w) polarity of PWM (normal/inversed)
    `-- unexport (w/o) return a PWM channel to the kernel

    Based on work by Lars Poeschel.

    Signed-off-by: H Hartley Sweeten
    Cc: Thierry Reding
    Cc: Lars Poeschel
    Cc: Ryan Mallon
    Cc: Rob Landley
    Signed-off-by: Thierry Reding

    H Hartley Sweeten
     

27 Feb, 2013

1 commit

  • Pull PWM changes from Thierry Reding:
    "A new driver has been added to support the PWM mode of the timer
    counter blocks found on Atmel AT91 SoCs. The VT8500 driver now
    supports changing the PWM signal polarity and the TI drivers (EHRPWM
    and ECAP) gained suspend and resume functionality.

    User drivers can now query the core for whether access to a PWM device
    will sleep (if the PWM chip is on a slow bus such as I2C or SPI).

    The pwm-backlight driver now handles the backlight BL_CORE_FBBLANK
    state in addition to the FB layer's blanking states.

    To round things off, a few fixes and cleanups are also included"

    * tag 'for-3.9-rc1' of git://gitorious.org/linux-pwm/linux-pwm:
    pwm: twl: Use to_twl() instead of container_of()
    pwm: tegra: assume CONFIG_OF
    pwm_backlight: Validate dft_brightness in main probe function
    pwm: Export pwm_{set,get}_chip_data()
    pwm: Make Kconfig entries more consistent
    pwm: Add can_sleep property to drivers
    pwm: Add pwm_can_sleep() as exported API to users
    pwm-backlight: handle BL_CORE_FBBLANK state
    pwm: pwm-tiecap: Low power sleep support
    pwm: pwm-tiehrpwm: Low power sleep support
    pwm: pwm-tiehrpwm: Update the clock handling of pwm-tiehrpwm driver
    pwm: vt8500: Add polarity support
    pwm: vt8500: Register write busy test performed incorrectly
    pwm: atmel: add Timer Counter Block PWM driver

    Linus Torvalds
     

02 Feb, 2013

3 commits


30 Jan, 2013

1 commit


23 Nov, 2012

1 commit

  • Add support for encoding PWM properties in bit encoded form with
    of_pwm_xlate_with_flags() function support. Platforms require platform
    specific PWM properties has to populate in 3rd cell of the pwm-specifier
    and PWM driver should also set .of_xlate support with this function.
    Currently PWM property polarity encoded in bit position 0 of the third
    cell in pwm-specifier.

    Signed-off-by: Philip, Avinash
    Acked-by: Grant Likely
    Signed-off-by: Thierry Reding

    Philip, Avinash
     

20 Sep, 2012

1 commit


10 Sep, 2012

2 commits

  • Add resource managed variants of pwm_get() and pwm_put() for
    convenience. Code is largely inspired by the equivalent devm functions
    of the regulator framework.

    Signed-off-by: Alexandre Courbot
    Signed-off-by: Thierry Reding

    Alexandre Courbot
     
  • Some hardware supports inverting the polarity of the PWM signal. This
    commit adds support to the PWM framework to allow users of the PWM API
    to configure the polarity. Note that in order to reduce complexity,
    changing the polarity of a PWM signal is only allowed while the PWM is
    disabled.

    A practical example where this can prove useful is to simulate inversion
    of the duty cycle. While inversion of polarity and duty cycle are not
    exactly the same, the differences for most use-cases are negligible.

    Signed-off-by: Philip, Avinash
    Signed-off-by: Thierry Reding

    Philip, Avinash
     

15 Jun, 2012

3 commits

  • This patch adds helpers to support device tree bindings for the generic
    PWM API. Device tree binding documentation for PWM controllers is also
    provided.

    Acked-by: Arnd Bergmann
    Reviewed-by: Shawn Guo
    Signed-off-by: Thierry Reding

    Thierry Reding
     
  • In order to get rid of the global namespace for PWM devices, this commit
    provides an alternative method, similar to that of the regulator or
    clock frameworks, for registering a static mapping for PWM devices. This
    works by providing a table with a provider/consumer map in the board
    setup code.

    With the new pwm_get() and pwm_put() functions available, usage of
    pwm_request() and pwm_free() becomes deprecated.

    Reviewed-by: Shawn Guo
    Reviewed-by: Mark Brown
    Signed-off-by: Thierry Reding

    Thierry Reding
     
  • This commit adds a debugfs interface that can be used to list the
    current internal state of the PWM devices registered with the PWM
    framework.

    Reviewed-by: Mark Brown
    Reviewed-by: Shawn Guo
    Signed-off-by: Thierry Reding

    Thierry Reding