Message ID | 1424247536-16476-2-git-send-email-ghug@induct.be |
---|---|
State | Superseded |
Headers | show |
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 >
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; }