diff options
Diffstat (limited to 'drivers/pwm/pwm-atmel-tcb.c')
-rw-r--r-- | drivers/pwm/pwm-atmel-tcb.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/drivers/pwm/pwm-atmel-tcb.c b/drivers/pwm/pwm-atmel-tcb.c index d42c897cb8..528e54c599 100644 --- a/drivers/pwm/pwm-atmel-tcb.c +++ b/drivers/pwm/pwm-atmel-tcb.c @@ -47,7 +47,6 @@ struct atmel_tcb_channel { }; struct atmel_tcb_pwm_chip { - struct pwm_chip chip; spinlock_t lock; u8 channel; u8 width; @@ -63,7 +62,7 @@ static const u8 atmel_tcb_divisors[] = { 2, 8, 32, 128, 0, }; static inline struct atmel_tcb_pwm_chip *to_tcb_chip(struct pwm_chip *chip) { - return container_of(chip, struct atmel_tcb_pwm_chip, chip); + return pwmchip_get_drvdata(chip); } static int atmel_tcb_pwm_request(struct pwm_chip *chip, @@ -327,7 +326,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, if ((atcbpwm && atcbpwm->duty > 0 && atcbpwm->duty != atcbpwm->period) && (atcbpwm->div != i || atcbpwm->period != period)) { - dev_err(chip->dev, + dev_err(pwmchip_parent(chip), "failed to configure period_ns: PWM group already configured with a different value\n"); return -EINVAL; } @@ -388,6 +387,7 @@ static const struct of_device_id atmel_tcb_of_match[] = { static int atmel_tcb_pwm_probe(struct platform_device *pdev) { + struct pwm_chip *chip; const struct of_device_id *match; struct atmel_tcb_pwm_chip *tcbpwm; const struct atmel_tcb_config *config; @@ -396,9 +396,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) int err; int channel; - tcbpwm = devm_kzalloc(&pdev->dev, sizeof(*tcbpwm), GFP_KERNEL); - if (tcbpwm == NULL) - return -ENOMEM; + chip = devm_pwmchip_alloc(&pdev->dev, NPWM, sizeof(*tcbpwm)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + tcbpwm = to_tcb_chip(chip); err = of_property_read_u32(np, "reg", &channel); if (err < 0) { @@ -436,9 +437,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) } } - tcbpwm->chip.dev = &pdev->dev; - tcbpwm->chip.ops = &atmel_tcb_pwm_ops; - tcbpwm->chip.npwm = NPWM; + chip->ops = &atmel_tcb_pwm_ops; tcbpwm->channel = channel; tcbpwm->width = config->counter_width; @@ -448,11 +447,11 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) spin_lock_init(&tcbpwm->lock); - err = pwmchip_add(&tcbpwm->chip); + err = pwmchip_add(chip); if (err < 0) goto err_disable_clk; - platform_set_drvdata(pdev, tcbpwm); + platform_set_drvdata(pdev, chip); return 0; @@ -473,9 +472,10 @@ err_slow_clk: static void atmel_tcb_pwm_remove(struct platform_device *pdev) { - struct atmel_tcb_pwm_chip *tcbpwm = platform_get_drvdata(pdev); + struct pwm_chip *chip = platform_get_drvdata(pdev); + struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip); - pwmchip_remove(&tcbpwm->chip); + pwmchip_remove(chip); clk_disable_unprepare(tcbpwm->slow_clk); clk_put(tcbpwm->gclk); @@ -491,7 +491,8 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids); static int atmel_tcb_pwm_suspend(struct device *dev) { - struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip); struct atmel_tcb_channel *chan = &tcbpwm->bkup; unsigned int channel = tcbpwm->channel; @@ -505,7 +506,8 @@ static int atmel_tcb_pwm_suspend(struct device *dev) static int atmel_tcb_pwm_resume(struct device *dev) { - struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip); struct atmel_tcb_channel *chan = &tcbpwm->bkup; unsigned int channel = tcbpwm->channel; |