Linux PWM subsystem development
 help / color / mirror / Atom feed
* [PATCH] pwm: iqs620a: Correct a stale state variable
@ 2021-01-15  5:00 Jeff LaBundy
  2021-01-15  7:45 ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff LaBundy @ 2021-01-15  5:00 UTC (permalink / raw)
  To: thierry.reding; +Cc: u.kleine-koenig, lee.jones, linux-pwm, Jeff LaBundy

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, force the iqs620_pwm->out_en flag to follow
the IQS620_PWR_SETTINGS_PWM_OUT field instead, as was the original
design intent.

Fixes: 6f0841a8197b ("pwm: Add support for Azoteq IQS620A PWM generator")
Signed-off-by: Jeff LaBundy <jeff@labundy.com>
---
 drivers/pwm/pwm-iqs620a.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-iqs620a.c b/drivers/pwm/pwm-iqs620a.c
index 5ede825..5eb8fa4 100644
--- a/drivers/pwm/pwm-iqs620a.c
+++ b/drivers/pwm/pwm-iqs620a.c
@@ -79,6 +79,8 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 					 IQS620_PWR_SETTINGS_PWM_OUT, 0);
 		if (ret)
 			goto err_mutex;
+
+		iqs620_pwm->out_en = false;
 	}
 
 	if (duty_scale) {
@@ -97,9 +99,9 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 					 IQS620_PWR_SETTINGS_PWM_OUT, 0xff);
 		if (ret)
 			goto err_mutex;
-	}
 
-	iqs620_pwm->out_en = state->enabled;
+		iqs620_pwm->out_en = true;
+	}
 
 err_mutex:
 	mutex_unlock(&iqs620_pwm->lock);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-19  2:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-15  5:00 [PATCH] pwm: iqs620a: Correct a stale state variable Jeff LaBundy
2021-01-15  7:45 ` Uwe Kleine-König
2021-01-18  4:30   ` Jeff LaBundy
2021-01-18  8:02     ` Uwe Kleine-König
2021-01-19  2:55       ` Jeff LaBundy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox