21 Sep, 2019

2 commits

  • It is surprising for a PWM consumer when the variable holding the
    requested state is modified by pwm_apply_state(). Consider for example a
    driver doing:

    #define PERIOD 5000000
    #define DUTY_LITTLE 10
    ...
    struct pwm_state state = {
    .period = PERIOD,
    .duty_cycle = DUTY_LITTLE,
    .polarity = PWM_POLARITY_NORMAL,
    .enabled = true,
    };

    pwm_apply_state(mypwm, &state);
    ...
    state.duty_cycle = PERIOD / 2;
    pwm_apply_state(mypwm, &state);

    For sure the second call to pwm_apply_state() should still have
    state.period = PERIOD and not something the hardware driver chose for a
    reason that doesn't necessarily apply to the second call.

    So declare the state argument as a pointer to a const type and adapt all
    drivers' .apply callbacks.

    Signed-off-by: Uwe Kleine-König
    Signed-off-by: Thierry Reding

    Uwe Kleine-König
     
  • The pwm-fsl-ftm driver is one of only three PWM drivers which updates
    the state for the caller of pwm_apply_state(). This might have
    surprising results if the caller reuses the values expecting them to
    still represent the same state.

    Signed-off-by: Uwe Kleine-König
    Signed-off-by: Thierry Reding

    Uwe Kleine-König
     

09 Jul, 2019

1 commit

  • …erry.reding/linux-pwm

    Pull pwm updates from Thierry Reding:
    "This set of changes contains a new driver for SiFive SoCs as well as
    enhancements to the core (device links are used to track dependencies
    between PWM providers and consumers, support for PWM controllers via
    ACPI, sysfs will now suspend/resume PWMs that it has claimed) and
    various existing drivers"

    * tag 'pwm/for-5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (37 commits)
    pwm: fsl-ftm: Make sure to unlock mutex on failure
    pwm: fsl-ftm: Use write protection for prescaler & polarity
    pwm: fsl-ftm: More relaxed permissions for updating period
    pwm: atmel-hlcdc: Add compatible for SAM9X60 HLCDC's PWM
    pwm: bcm2835: Improve precision of PWM
    leds: pwm: Support ACPI via firmware-node framework
    pwm: Add support referencing PWMs from ACPI
    pwm: rcar: Remove suspend/resume support
    pwm: sysfs: Add suspend/resume support
    pwm: Add power management descriptions
    pwm: meson: Add documentation to the driver
    pwm: meson: Add support PWM_POLARITY_INVERSED when disabling
    pwm: meson: Don't cache struct pwm_state internally
    pwm: meson: Read the full hardware state in meson_pwm_get_state()
    pwm: meson: Simplify the calculation of the pre-divider and count
    pwm: meson: Move pwm_set_chip_data() to meson_pwm_request()
    pwm: meson: Add the per-channel register offsets and bits in a struct
    pwm: meson: Add the meson_pwm_channel data to struct meson_pwm
    pwm: meson: Pass struct pwm_device to meson_pwm_calc()
    pwm: meson: Don't duplicate the polarity internally
    ...

    Linus Torvalds
     

26 Jun, 2019

3 commits

  • Upon failure to enable clocks while trying to enable the PWM, make sure
    to unlock the mutex that was taken to avoid a deadlock during subsequent
    operations.

    Reported-by: kbuild test robot
    Reported-by: Julia Lawall
    Cc: Patrick Havelange
    Signed-off-by: Thierry Reding

    Thierry Reding
     
  • Modifying the prescaler or polarity value must be done with the
    write protection disabled. Currently this is working by chance as
    the write protection is in a disabled state by default.
    This patch makes sure that we enable/disable the write protection
    when needed.

    Signed-off-by: Patrick Havelange
    Signed-off-by: Thierry Reding

    Patrick Havelange
     
  • The Flextimer has only one period for several channels. The PWM
    subsystem doesn't allow to model something like that. The current
    implementation simply disallows changing the period once it has
    been set, having as a side effect that you need to enable and
    disable the PWM if you want to change the period.

    The driver should allow as much freedom as possible for configuring
    the period and duty cycle. Therefore, this patch reworks the code
    to allow the following:

    - period and duty_cycle can be set at will when the PWM is disabled;
    - when enabling a PWM, verify that the period is either not set yet,
    or the same as the other already enabled PWM(s), and fail if not;
    - allow to change the period on the fly when the PWM is the only one
    enabled.

    It also allows to have different periods configured for different PWMs.
    Only one period can be used at a time, thus the first PWM to be enabled
    will set that period, only other PWMs with that same period can be
    enabled at the same time. To use another PWM with another period, the
    enabled PWMs must be disabled first.

    Example scenario :
    echo 5000000 > pwm0/period #OK
    echo 1000000 > pwm0/duty_cycle #OK
    echo 1000000 > pwm1/period #OK
    echo 1000000 > pwm1/duty_cycle #OK
    echo 1 > pwm0/enable #OK
    echo 1 > pwm1/enable #FAIL (pwm0/period != pwm1/period)
    echo 0 > pwm0/enable #OK
    echo 1 > pwm1/enable #OK
    echo 1000000 > pwm0/period #OK
    echo 2000000 > pwm0/period #OK
    echo 1 > pwm0/enable #FAIL (pwm0/period != pwm1/period)
    echo 2000000 > pwm1/period #OK (pwm1 still running, changed on the fly)
    echo 1 > pwm0/enable #OK (now pwm0/period == pwm1/period)
    echo 3000000 > pwm1/period #FAIL (other PWMs running)
    echo 0 > pwm0/enable #OK
    echo 3000000 > pwm1/period #OK (only this PWM running)

    Adapting the code to satisfy these constraints turned up a number of
    additional issues with the current implementation:
    - the prescaler value 0 was not used (when it could have been);
    - when setting the period was not possible, the internal state was
    inconsistent;
    - the maximal value for configuring the period was never used;

    Since all of these interact with each other, rather than trying to fix
    each individual issue, this patch reworks how the period and duty cycle
    are set entirely, with the following additional improvements:
    - implement the new apply() method instead of the individual methods;
    - return the exact used period/duty_cycle values;
    - more coherent argument types for period, duty_cycle;

    Signed-off-by: Patrick Havelange
    Signed-off-by: Thierry Reding

    Patrick Havelange
     

31 May, 2019

1 commit

  • Based on 1 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

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

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

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

    Thomas Gleixner
     

26 Apr, 2019

1 commit


10 Jul, 2018

3 commits

  • Enabled the support for the new SoC i.MX8QM by adding the compatible
    string of "fsl,imx8qm-ftm-pwm" and its per-compatible data with setting
    "has_enable_bits" to "true".

    Signed-off-by: Shenwei Wang
    Signed-off-by: Thierry Reding

    shenwei.wang@nxp.com
     
  • On the i.MX8x SoC family, an additional PWM enable bit is added for each
    PWM channel in the register FTM_SC[23:16]. It supports 8 channels. Bit
    16 is for channel 0, and bit 23 is for channel 7. As the IP version
    information can not be obtained via any of the FTM registers, a property
    of "has_enable_bits" is added via per-compatible data structure.

    Signed-off-by: Shenwei Wang
    Signed-off-by: Thierry Reding

    shenwei.wang@nxp.com
     
  • The current driver assumes that the ftm_sys clock works as one of the
    clock sources for the IP block as well as the IP interface clock. This
    assumption does not apply any more on the latest i.MX8x SoC family. On
    i.MX8x SoCs, a dedicated IP interface clock is introduced and it must be
    enabled before accessing any FTM registers. Moreover, the clock can not
    be used as the source clock for the FTM IP block. This patch introduces
    the ipg_clk as the dedicated IP interface clock and by default it is the
    same as the ftm_sys clock if not specified.

    Signed-off-by: Shenwei Wang
    Signed-off-by: Thierry Reding

    shenwei.wang@nxp.com
     

04 Jan, 2017

1 commit


14 Apr, 2016

1 commit

  • Use flat regmap cache to avoid lockdep warning at probe:

    [ 0.697285] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:2755 lockdep_trace_alloc+0x15c/0x160()
    [ 0.697449] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))

    The RB-tree regmap cache needs to allocate new space on first writes.
    However, allocations in an atomic context (e.g. when a spinlock is held)
    are not allowed. The function regmap_write calls map->lock, which
    acquires a spinlock in the fast_io case. Since the pwm-fsl-ftm driver
    uses MMIO, the regmap bus of type regmap_mmio is being used which has
    fast_io set to true.

    The MMIO space of the pwm-fsl-ftm driver is reasonable condense, hence
    using the much faster flat regmap cache is anyway the better choice.

    Signed-off-by: Stefan Agner
    Cc: Mark Brown
    Signed-off-by: Thierry Reding

    Stefan Agner
     

16 Dec, 2015

1 commit

  • A FTM PWM instance enables/disables three clocks: The bus clock, the
    counter clock and the PWM clock. The bus clock gets enabled on
    pwm_request, whereas the counter and PWM clocks will be enabled upon
    pwm_enable.

    The driver has three closesly related issues when enabling/disabling
    clocks during suspend/resume:
    - The three clocks are not treated differently in regards to the
    individual PWM state enabled/requested. This can lead to clocks
    getting disabled which have not been enabled in the first place
    (a PWM channel which only has been requested going through
    suspend/resume).

    - When entering suspend, the current behavior relies on the
    FTM_OUTMASK register: If a PWM output is unmasked, the driver
    assumes the clocks are enabled. However, some PWM instances
    have only 2 channels connected (e.g. Vybrid's FTM1). In that case,
    the FTM_OUTMASK reads 0x3 if all channels are disabled, even if
    the code wrote 0xff to it before. For those PWM instances, the
    current approach to detect enabled PWM signals does not work.

    - A third issue applies to the bus clock only, which can get enabled
    multiple times (once for each PWM channel of a PWM chip). This is
    fine, however when entering suspend mode, the clock only gets
    disabled once.

    This change introduces a different approach by relying on the enable
    and prepared counters of the clock framework and using the frameworks
    PWM signal states to address all three issues.

    Clocks get disabled during suspend and back enabled on resume
    regarding to the PWM channels individual state (requested/enabled).

    Since we do not count the clock enables in the driver, this change no
    longer clears the Status and Control registers Clock Source Selection
    (FTM_SC[CLKS]). However, since we disable the selected clock anyway,
    and we explicitly select the clock source on reenabling a PWM channel
    this approach should not make a difference in practice.

    Signed-off-by: Stefan Agner
    Signed-off-by: Thierry Reding

    Stefan Agner
     

01 Dec, 2014

3 commits


20 Aug, 2014

2 commits

  • The regmap core supports different endian modes for devices. This patch
    convert to direct regmap API usage, preparing to support big endianness
    for LS1 SoC.

    Using the regmap framework it will be easy to support devices that only
    differ in endianness with the same device driver.

    Signed-off-by: Xiubo Li
    Signed-off-by: Thierry Reding

    Xiubo Li
     
  • This patch intends to prepare for converting to direct regmap API usage.

    Signed-off-by: Xiubo Li
    Signed-off-by: Thierry Reding

    Xiubo Li
     

23 May, 2014

1 commit


19 Mar, 2014

1 commit

  • The FTM PWM device can be found on Vybrid VF610 Tower and
    Layerscape LS-1 SoCs.

    Signed-off-by: Xiubo Li
    Signed-off-by: Alison Wang
    Signed-off-by: Jingchang Lu
    Reviewed-by: Sascha Hauer
    Reviewed-by: Yuan Yao
    Signed-off-by: Thierry Reding

    Xiubo Li