pwm: iqs620a: Correct a stale state variable
authorJeff LaBundy <jeff@labundy.com>
Tue, 19 Jan 2021 04:30:29 +0000 (22:30 -0600)
committerThierry Reding <thierry.reding@gmail.com>
Mon, 22 Feb 2021 14:18:50 +0000 (15:18 +0100)
commit28208c7b4a2c38ea91b6ee04f6023d3145257f5d
tree3b7f44b5dc811fe3931bb4ef54ac18122bcd0166
parent72d6b2459dbd539c1369149e501fdc3dc8ddef16
pwm: iqs620a: Correct a stale state variable

If duty cycle is first set to a value that is sufficiently high to
enable the output (e.g. 10000 ns) but then lowered to a value that
is quantized to zero (e.g. 1000 ns), the output is disabled as the
device cannot drive a constant zero (as expected).

However if the device is later re-initialized due to watchdog bite,
the output is re-enabled at the next-to-last duty cycle (10000 ns).
This is because the iqs620_pwm->out_en flag unconditionally tracks
state->enabled instead of what was actually written to the device.

To solve this problem, use one state variable that encodes all 257
states of the output (duty_scale) with 0 representing tri-state, 1
representing the minimum available duty cycle and 256 representing
100% duty cycle.

Signed-off-by: Jeff LaBundy <jeff@labundy.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-iqs620a.c