pwm: samsung: Fix output race on disabling
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Thu, 5 Mar 2015 08:14:03 +0000 (09:14 +0100)
committerThierry Reding <thierry.reding@gmail.com>
Fri, 27 Mar 2015 12:06:47 +0000 (13:06 +0100)
commit4a1c683c98e4e2997c79258bffbb9be4af4fba83
tree305543fa7a9731704c71d52e62be572d71355618
parent24ccea1ce6717b91bb1e71b12cfd956f8d32dcf3
pwm: samsung: Fix output race on disabling

When disabling the Samsung PWM the output state remains at the level it
was at the end of a PWM cycle. In other words, calling pwm_disable()
when at 100% duty cycle will keep the output active, while at all other
settings the output will go/stay inactive. On top of that the Samsung
PWM settings are double-buffered, which means the new settings only get
applied at the start of a new PWM cycle.

This results in a race if the PWM is at 100% duty cycle and a driver
calls:

  pwm_config(pwm, 0, period);
  pwm_disable(pwm);

In this case the PWMs output will unexpectedly stay active, unless a new
PWM cycle happened to start between the register writes in pwm_config()
and pwm_disable(). As far as I can tell this is a regression introduced
by 3bdf878, before that a call to pwm_config() would call
pwm_samsung_enable() which, while heavy-handed, made sure the expected
settings were live.

To resolve this, while not re-introducing the issues 3bdf878 (flickering
as the PWM got reset while in a PWM cycle) fixed, only force an update
of the settings when at 100% duty cycle, which shouldn't have any
noticeable effect on the output but is enough to ensure the behaviour is
as expected on disable.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-samsung.c