From: Alban Bedel <alban.bedel@avionic-design.de>
To: Roland Stigge <stigge@antcom.de>
Cc: Thierry Reding <thierry.reding@avionic-design.de>,
LKML <linux-kernel@vger.kernel.org>,
Alexandre Pereira da Silva <aletes.xgr@gmail.com>
Subject: Re: [PATCH] pwm: lpc32xx - Fix the PWM polarity
Date: Thu, 8 Nov 2012 11:33:53 +0100 [thread overview]
Message-ID: <20121108113353.4fdbb25c@avionic-0020.adnet.avionic-design.de> (raw)
In-Reply-To: <509B80A7.1060700@antcom.de>
On Thu, 08 Nov 2012 10:51:35 +0100
Roland Stigge <stigge@antcom.de> wrote:
> On 07/11/12 16:25, Alban Bedel wrote:
> > Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de>
> > ---
> > drivers/pwm/pwm-lpc32xx.c | 6 +++++-
> > 1 files changed, 5 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-lpc32xx.c b/drivers/pwm/pwm-lpc32xx.c
> > index adb87f0..0dc278d 100644
> > --- a/drivers/pwm/pwm-lpc32xx.c
> > +++ b/drivers/pwm/pwm-lpc32xx.c
> > @@ -51,7 +51,11 @@ static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >
> > c = 256 * duty_ns;
> > do_div(c, period_ns);
> > - duty_cycles = c;
> > + if (c == 0)
> > + c = 256;
> > + if (c > 255)
> > + c = 255;
> > + duty_cycles = 256 - c;
>
> Except for the range check (for the original c > 255), this results in:
>
> duty_cycles = 256 - c
>
> except for (c == 0) where
>
> duty_cycles = 1
No it lead to duty_cycles = 0
> which actually is
>
> duty_cycles = (256 - c) - 255
>
> (think with the original c)
>
> i.e. nearly a polarity inversion in the case of (c == 0).
>
> Why is the case (c == 0) so special here? Maybe you can document this,
> if it is really intended?
It is intended, the formular for duty value in the register is:
duty = (256 - 256*duty_ns/period_ns) % 256
But the code avoid the modulo by clamping '256*duty_ns/period_ns' to 1-256.
Perhaps something like:
if (c > 255)
c = 255;
duty_cycles = (256 - c) % 256;
would be easier to understand.
Alban
next prev parent reply other threads:[~2012-11-08 10:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-05 16:48 [PATCH] pwm: lpc32xx - Fix the PWM polarity Alban Bedel
2012-11-05 21:03 ` Thierry Reding
2012-11-06 9:36 ` Roland Stigge
[not found] ` <CAAAP30HwBzYFpy942UyiQX2SkzV4naBbhwichp201bvfEm2mxA@mail.gmail.com>
2012-11-06 17:19 ` Alban Bedel
2012-11-07 15:25 ` Alban Bedel
2012-11-07 15:58 ` Alexandre Pereira da Silva
2012-11-08 9:51 ` Roland Stigge
2012-11-08 10:33 ` Alban Bedel [this message]
2012-11-08 10:44 ` Roland Stigge
2012-11-08 11:23 ` Alban Bedel
2012-11-08 11:46 ` Alban Bedel
2012-11-08 13:12 ` Roland Stigge
2012-11-08 13:49 ` Alexandre Pereira da Silva
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=20121108113353.4fdbb25c@avionic-0020.adnet.avionic-design.de \
--to=alban.bedel@avionic-design.de \
--cc=aletes.xgr@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stigge@antcom.de \
--cc=thierry.reding@avionic-design.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.