summaryrefslogtreecommitdiff
path: root/drivers/pwm/pwm-sti.c
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2016-08-16 10:35:00 +0100
committerThierry Reding <thierry.reding@gmail.com>2016-09-08 10:55:08 +0200
commitd81738b76feee2cf8f296ef943966f3f2a0e3fce (patch)
tree9fbb3c73ddeab99a0418e417671ececd0c679a6f /drivers/pwm/pwm-sti.c
parentc5f94ae639236e53970841d494d1ac2140181232 (diff)
pwm: sti: Only request clock rate when needed
In the original code the clock rate was only obtained during initialisation; however, the rate may change between then and its use. This patch ensures the correct rate is acquired just before use. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-sti.c')
-rw-r--r--drivers/pwm/pwm-sti.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 388f2aa285ae..da0c1bf2a705 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -51,7 +51,6 @@ struct sti_pwm_compat_data {
struct sti_pwm_chip {
struct device *dev;
- unsigned long clk_rate;
struct clk *pwm_clk;
struct regmap *regmap;
struct sti_pwm_compat_data *cdata;
@@ -86,13 +85,20 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
unsigned int *prescale)
{
struct sti_pwm_compat_data *cdata = pc->cdata;
+ unsigned long clk_rate;
unsigned long val;
unsigned int ps;
+ clk_rate = clk_get_rate(pc->pwm_clk);
+ if (!clk_rate) {
+ dev_err(pc->dev, "failed to get clock rate\n");
+ return -EINVAL;
+ }
+
/*
* prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1
*/
- val = NSEC_PER_SEC / pc->clk_rate;
+ val = NSEC_PER_SEC / clk_rate;
val *= cdata->max_pwm_cnt + 1;
if (period % val) {
@@ -353,12 +359,6 @@ static int sti_pwm_probe(struct platform_device *pdev)
return PTR_ERR(pc->pwm_clk);
}
- pc->clk_rate = clk_get_rate(pc->pwm_clk);
- if (!pc->clk_rate) {
- dev_err(dev, "failed to get clock rate\n");
- return -EINVAL;
- }
-
ret = clk_prepare(pc->pwm_clk);
if (ret) {
dev_err(dev, "failed to prepare clock\n");