public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: pwm-mxs: Apply configuration before disabling PWM.
@ 2013-06-19 11:51 Robin van der Gracht
  2013-06-21 10:02 ` Thierry Reding
  0 siblings, 1 reply; 3+ messages in thread
From: Robin van der Gracht @ 2013-06-19 11:51 UTC (permalink / raw)
  To: thierry.reding; +Cc: linux-kernel, shawn.guo, Robin van der Gracht

When disabling the pwm, the output state locks at its current state.
We have to be sure the last configuration applied. Which in most
cases sets duty cycle to 0%. To prevent the pwm from taking on
100% duty cycle when disabled during a high state.

Configuration applies at the beginning of a new output period.

Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
 drivers/pwm/pwm-mxs.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index 3febddd..4ddc063 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -21,6 +21,7 @@
 #include <linux/pwm.h>
 #include <linux/slab.h>
 #include <linux/stmp_device.h>
+#include <linux/delay.h>
 
 #define SET	0x4
 #define CLR	0x8
@@ -40,6 +41,7 @@ struct mxs_pwm_chip {
 	struct pwm_chip chip;
 	struct clk *clk;
 	void __iomem *base;
+	unsigned long period_ns;
 };
 
 #define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip)
@@ -92,6 +94,7 @@ static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	if (!test_bit(PWMF_ENABLED, &pwm->flags))
 		clk_disable_unprepare(mxs->clk);
 
+	mxs->period_ns = period_ns;
 	return 0;
 }
 
@@ -113,6 +116,11 @@ static void mxs_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip);
 
+	/*
+	 * Ensure latest configuration applied.
+	 */
+	ndelay(mxs->period_ns);
+
 	writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR);
 
 	clk_disable_unprepare(mxs->clk);
-- 
1.7.9.5


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

end of thread, other threads:[~2013-06-26  6:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-19 11:51 [PATCH] pwm: pwm-mxs: Apply configuration before disabling PWM Robin van der Gracht
2013-06-21 10:02 ` Thierry Reding
2013-06-26  6:52   ` Robin van der Gracht

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