Skip to content

Commit

Permalink
pwm: Fix pwm_apply_args()
Browse files Browse the repository at this point in the history
Commit 5ec803e ("pwm: Add core infrastructure to allow atomic
updates"), implemented pwm_disable() as a wrapper around
pwm_apply_state(), and then, commit ef2bf49 ("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 <boris.brezillon@free-electrons.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Suggested-by: Brian Norris <briannorris@chromium.org>
Fixes: 5ec803e ("pwm: Add core infrastructure to allow atomic updates")
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Boris Brezillon authored and Thierry Reding committed Jun 23, 2016
1 parent cc51846 commit 33cdcee
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ static inline bool pwm_can_sleep(struct pwm_device *pwm)

static inline void pwm_apply_args(struct pwm_device *pwm)
{
struct pwm_state state = { };

/*
* PWM users calling pwm_apply_args() expect to have a fresh config
* where the polarity and period are set according to pwm_args info.
Expand All @@ -476,18 +478,20 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
* at startup (even if they are actually enabled), thus authorizing
* polarity setting.
*
* Instead of setting ->enabled to false, we call pwm_disable()
* before pwm_set_polarity() to ensure that everything is configured
* as expected, and the PWM is really disabled when the user request
* it.
* To fulfill this requirement, we apply a new state which disables
* the PWM device and set the reference period and polarity config.
*
* Note that PWM users requiring a smooth handover between the
* bootloader and the kernel (like critical regulators controlled by
* PWM devices) will have to switch to the atomic API and avoid calling
* pwm_apply_args().
*/
pwm_disable(pwm);
pwm_set_polarity(pwm, pwm->args.polarity);

state.enabled = false;
state.polarity = pwm->args.polarity;
state.period = pwm->args.period;

pwm_apply_state(pwm, &state);
}

struct pwm_lookup {
Expand Down

0 comments on commit 33cdcee

Please sign in to comment.