mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* pwm: atmel: PWM may not properly disable
@ 2016-05-11  8:48 Guillermo Rodriguez Garcia
  2016-05-11 13:39 ` Thierry Reding
  0 siblings, 1 reply; 8+ messages in thread
From: Guillermo Rodriguez Garcia @ 2016-05-11  8:48 UTC (permalink / raw)
  To: Thierry Reding, linux-kernel, linux-pwm; +Cc: Nicolas Ferre

Hello all,

I am seeing a problem with the atmel-pwm driver where disabling a PWM
channel sometimes leaves the output at the wrong level ("wrong" == not
idle, as per the configured polarity). This causes problems when the
PWM is used to drive a LED or certain types of buzzers.

The issue seems to be in the atmel_pwm_disable function [1], which
disables the clock immediately after writing to the PWM_DIS register.
As a result, the write does not seem to take effect.

I have verified that this is the cause of the problem this by waiting
until the channel is effectively disabled (by checking the PWM_SR
register) before disabling the clock. This fixes the issue and the PWM
output now stays at the idle level after the channel is disabled.

For the above I used a modified version of a patch that was posted to
the list some time ago [2]. Note that only atmel_pwm_disable needs to
be patched, there seems to be no need to patch atmel_pwm_enable. The
code is as follows:

     atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
+    while (atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm)) {
+        cpu_relax();
+    }

     clk_disable(atmel_pwm->clk);

Is this acceptable? Should I submit an updated patch?

 [1]: http://lxr.free-electrons.com/source/drivers/pwm/pwm-atmel.c#L253
 [2]: https://lkml.org/lkml/2014/10/1/605

(If possible, please CC me in any replies)
-- 
Guillermo Rodriguez Garcia
guille.rodriguez@gmail.com

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

end of thread, other threads:[~2016-05-13 11:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11  8:48 pwm: atmel: PWM may not properly disable Guillermo Rodriguez Garcia
2016-05-11 13:39 ` Thierry Reding
2016-05-11 14:31   ` Guillermo Rodriguez Garcia
2016-05-12 10:11     ` Guillermo Rodriguez Garcia
2016-05-12 11:49       ` Guillermo Rodriguez Garcia
2016-05-12 12:14         ` Thierry Reding
2016-05-12 13:24           ` Guillermo Rodriguez Garcia
2016-05-13 11:14             ` Guillermo Rodriguez Garcia

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

all inboxes | Powered by JetHome®