diff options
author | Mark Brown <broonie@kernel.org> | 2014-11-26 23:39:02 +0300 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-11-26 23:39:02 +0300 |
commit | 75ff9420448e7bb30ab8265463595e794ce0c3aa (patch) | |
tree | ea00f0cff2f6a272d60a518eb6dde6e14263b5b7 /drivers/pwm/pwm-atmel.c | |
parent | 4524df83c7fc4f44702099a2db7b3cc938eb111f (diff) | |
parent | 206c5f60a3d902bc4b56dab2de3e88de5eb06108 (diff) | |
download | linux-75ff9420448e7bb30ab8265463595e794ce0c3aa.tar.xz |
Merge tag 'v3.18-rc4' into regulator-max77686
Linux 3.18-rc4
Diffstat (limited to 'drivers/pwm/pwm-atmel.c')
-rw-r--r-- | drivers/pwm/pwm-atmel.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 6e700a541ca3..d3c22de9ee47 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -102,7 +102,7 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns) { struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); - unsigned long clk_rate, prd, dty; + unsigned long prd, dty; unsigned long long div; unsigned int pres = 0; u32 val; @@ -113,20 +113,18 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return -EBUSY; } - clk_rate = clk_get_rate(atmel_pwm->clk); - div = clk_rate; + /* Calculate the period cycles and prescale value */ + div = (unsigned long long)clk_get_rate(atmel_pwm->clk) * period_ns; + do_div(div, NSEC_PER_SEC); - /* Calculate the period cycles */ while (div > PWM_MAX_PRD) { - div = clk_rate / (1 << pres); - div = div * period_ns; - /* 1/Hz = 100000000 ns */ - do_div(div, 1000000000); - - if (pres++ > PRD_MAX_PRES) { - dev_err(chip->dev, "pres exceeds the maximum value\n"); - return -EINVAL; - } + div >>= 1; + pres++; + } + + if (pres > PRD_MAX_PRES) { + dev_err(chip->dev, "pres exceeds the maximum value\n"); + return -EINVAL; } /* Calculate the duty cycles */ |