Commit ebe88b6a authored by Stefan Wahren's avatar Stefan Wahren Committed by Thierry Reding

pwm: bcm2835: Calculate scaler in ->config()

Currently pwm-bcm2835 assumes a fixed clock rate and stores the
resulting scaler in the driver structure. But with the upcoming
PWM clock support for clk-bcm2835 the rate could change, so
calculate the scaler in the ->config() callback.
Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
Reviewed-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent c7b91b33
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
struct bcm2835_pwm { struct bcm2835_pwm {
struct pwm_chip chip; struct pwm_chip chip;
struct device *dev; struct device *dev;
unsigned long scaler;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
}; };
...@@ -66,6 +65,7 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -66,6 +65,7 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns) int duty_ns, int period_ns)
{ {
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip); struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
if (period_ns <= MIN_PERIOD) { if (period_ns <= MIN_PERIOD) {
dev_err(pc->dev, "period %d not supported, minimum %d\n", dev_err(pc->dev, "period %d not supported, minimum %d\n",
...@@ -73,8 +73,8 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -73,8 +73,8 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
return -EINVAL; return -EINVAL;
} }
writel(duty_ns / pc->scaler, pc->base + DUTY(pwm->hwpwm)); writel(duty_ns / scaler, pc->base + DUTY(pwm->hwpwm));
writel(period_ns / pc->scaler, pc->base + PERIOD(pwm->hwpwm)); writel(period_ns / scaler, pc->base + PERIOD(pwm->hwpwm));
return 0; return 0;
} }
...@@ -156,8 +156,6 @@ static int bcm2835_pwm_probe(struct platform_device *pdev) ...@@ -156,8 +156,6 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
pc->scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
pc->chip.dev = &pdev->dev; pc->chip.dev = &pdev->dev;
pc->chip.ops = &bcm2835_pwm_ops; pc->chip.ops = &bcm2835_pwm_ops;
pc->chip.npwm = 2; pc->chip.npwm = 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment