linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: linux-pwm@vger.kernel.org,
	Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
Subject: [PATCH] pwm: imx: don't reprogram PWMSAR if PWM is disabled
Date: Wed, 23 Jul 2014 12:09:47 +0400	[thread overview]
Message-ID: <1406102987-14797-1-git-send-email-dbaryshkov@gmail.com> (raw)

From: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>

Writing several values to PWMSAR register with PWM being disabled can
lead to FIFO (connected to PWMSAR) being overflown. Then after enabling
PWM, hardware will use stale values. Instead cache the duty cycles and
write them to the hardware only before enabling PWM.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
---
 drivers/pwm/pwm-imx.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index c735127..79c2b24 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -46,6 +46,7 @@ struct imx_chip {
 	struct clk	*clk_ipg;
 
 	void __iomem	*mmio_base;
+	unsigned long	duty_cycles;
 
 	struct pwm_chip	chip;
 
@@ -105,7 +106,7 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,
 {
 	struct imx_chip *imx = to_imx_chip(chip);
 	unsigned long long c;
-	unsigned long period_cycles, duty_cycles, prescale;
+	unsigned long period_cycles, prescale;
 	u32 cr;
 
 	c = clk_get_rate(imx->clk_per);
@@ -118,7 +119,7 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,
 	period_cycles /= prescale;
 	c = (unsigned long long)period_cycles * duty_ns;
 	do_div(c, period_ns);
-	duty_cycles = c;
+	imx->duty_cycles = c;
 
 	/*
 	 * according to imx pwm RM, the real period value should be
@@ -134,7 +135,8 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,
 
 	period_cycles -= 2;
 
-	writel(duty_cycles, imx->mmio_base + MX3_PWMSAR);
+	if (test_bit(PWMF_ENABLED, &pwm->flags))
+		writel(imx->duty_cycles, imx->mmio_base + MX3_PWMSAR);
 	writel(period_cycles, imx->mmio_base + MX3_PWMPR);
 
 	cr = readl(imx->mmio_base + MX3_PWMCR);
@@ -157,6 +159,9 @@ static void imx_pwm_set_enable_v2(struct pwm_chip *chip, bool enable)
 	struct imx_chip *imx = to_imx_chip(chip);
 	u32 val;
 
+	if (enable)
+		writel(imx->duty_cycles, imx->mmio_base + MX3_PWMSAR);
+
 	val = readl(imx->mmio_base + MX3_PWMCR);
 
 	if (enable)
-- 
1.9.3


             reply	other threads:[~2014-07-23  8:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23  8:09 Dmitry Eremin-Solenikov [this message]
2014-08-01 18:02 ` [PATCH] pwm: imx: don't reprogram PWMSAR if PWM is disabled Dmitry Eremin-Solenikov
2014-08-05  0:47   ` Dmitry Eremin-Solenikov
2014-08-05  1:36   ` Shawn Guo
2014-08-05  8:48     ` Liu Ying
2014-08-25 13:56       ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406102987-14797-1-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.com \
    --cc=dmitry_eremin@mentor.com \
    --cc=linux-pwm@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).