LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/1] fix for pwm-mxs period divider computation
@ 2015-02-18 8:18 Gaetan Hug
2015-02-18 8:18 ` [PATCH 1/1] fixing " Gaetan Hug
2015-02-18 12:08 ` [PATCH 0/1] fix for " Thierry Reding
0 siblings, 2 replies; 4+ messages in thread
From: Gaetan Hug @ 2015-02-18 8:18 UTC (permalink / raw)
To: thierry.reding; +Cc: linux-pwm, linux-kernel, Gaetan Hug
Hello Thierry,
I found a bug in the pwm-mxs.c driver for the i.MX28 platform.
The driver computes from the desired period which clock divider it
should be using. This computation assumes that the link between the
register value and the actual divider value is raising 2 to the power of
the registry value.
div = 1 << regvalue
This is true only for the first 5 values out of 8. Next values are
64, 256 and, 1024.
This affects only the user only if he requests a period > 0.04369s.
Gaetan Hug (1):
fixing pwm-mxs period divider computation
drivers/pwm/pwm-mxs.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] fixing pwm-mxs period divider computation
2015-02-18 8:18 [PATCH 0/1] fix for pwm-mxs period divider computation Gaetan Hug
@ 2015-02-18 8:18 ` Gaetan Hug
2015-02-18 12:11 ` Thierry Reding
2015-02-18 12:08 ` [PATCH 0/1] fix for " Thierry Reding
1 sibling, 1 reply; 4+ messages in thread
From: Gaetan Hug @ 2015-02-18 8:18 UTC (permalink / raw)
To: thierry.reding; +Cc: linux-pwm, linux-kernel, Gaetan Hug
---
drivers/pwm/pwm-mxs.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index f75ecb0..bbb2f8a 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -52,15 +52,18 @@ static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned long rate;
unsigned long long c;
+ unsigned const int cdiv[PERIOD_CDIV_MAX] = {1, 2, 4, 8, 16, 64, 256, 1024};
+
rate = clk_get_rate(mxs->clk);
+
while (1) {
- c = rate / (1 << div);
+ c = rate / cdiv[div];
c = c * period_ns;
do_div(c, 1000000000);
if (c < PERIOD_PERIOD_MAX)
break;
div++;
- if (div > PERIOD_CDIV_MAX)
+ if (div >= PERIOD_CDIV_MAX)
return -EINVAL;
}
--
1.7.10.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/1] fix for pwm-mxs period divider computation
2015-02-18 8:18 [PATCH 0/1] fix for pwm-mxs period divider computation Gaetan Hug
2015-02-18 8:18 ` [PATCH 1/1] fixing " Gaetan Hug
@ 2015-02-18 12:08 ` Thierry Reding
1 sibling, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2015-02-18 12:08 UTC (permalink / raw)
To: Gaetan Hug; +Cc: linux-pwm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
On Wed, Feb 18, 2015 at 09:18:55AM +0100, Gaetan Hug wrote:
> Hello Thierry,
>
> I found a bug in the pwm-mxs.c driver for the i.MX28 platform.
>
> The driver computes from the desired period which clock divider it
> should be using. This computation assumes that the link between the
> register value and the actual divider value is raising 2 to the power of
> the registry value.
>
> div = 1 << regvalue
>
> This is true only for the first 5 values out of 8. Next values are
> 64, 256 and, 1024.
> This affects only the user only if he requests a period > 0.04369s.
Can you put this description into the commit message of the proper
patch, please?
Also, the subject should be in the following format:
pwm: mxs: Fix period divider computation
Thanks,
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] fixing pwm-mxs period divider computation
2015-02-18 8:18 ` [PATCH 1/1] fixing " Gaetan Hug
@ 2015-02-18 12:11 ` Thierry Reding
0 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2015-02-18 12:11 UTC (permalink / raw)
To: Gaetan Hug; +Cc: linux-pwm, linux-kernel, Shawn Guo, Fabio Estevam
[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]
On Wed, Feb 18, 2015 at 09:18:56AM +0100, Gaetan Hug wrote:
> ---
> drivers/pwm/pwm-mxs.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
Adding Shawn and Fabio, hence quoting the full patch.
> diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
> index f75ecb0..bbb2f8a 100644
> --- a/drivers/pwm/pwm-mxs.c
> +++ b/drivers/pwm/pwm-mxs.c
> @@ -52,15 +52,18 @@ static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> unsigned long rate;
> unsigned long long c;
>
> + unsigned const int cdiv[PERIOD_CDIV_MAX] = {1, 2, 4, 8, 16, 64, 256, 1024};
This could prbably be static const and could be in file scope rather
than in this function.
Thierry
> +
> rate = clk_get_rate(mxs->clk);
> +
> while (1) {
> - c = rate / (1 << div);
> + c = rate / cdiv[div];
> c = c * period_ns;
> do_div(c, 1000000000);
> if (c < PERIOD_PERIOD_MAX)
> break;
> div++;
> - if (div > PERIOD_CDIV_MAX)
> + if (div >= PERIOD_CDIV_MAX)
> return -EINVAL;
> }
>
> --
> 1.7.10.4
>
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-18 12:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 8:18 [PATCH 0/1] fix for pwm-mxs period divider computation Gaetan Hug
2015-02-18 8:18 ` [PATCH 1/1] fixing " Gaetan Hug
2015-02-18 12:11 ` Thierry Reding
2015-02-18 12:08 ` [PATCH 0/1] fix for " Thierry Reding
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).