pwm: atmel-hlcdc: Prepare removing pwm_chip from driver data
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:30:58 +0000 (10:30 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 15 Feb 2024 11:59:19 +0000 (12:59 +0100)
This prepares the driver for further changes that will drop struct
pwm_chip chip from struct atmel_hlcdc_pwm. Use the pwm_chip as driver
data instead of the atmel_hlcdc_pwm to get access to the pwm_chip in
the .suspend() and .resume() callbacks and atmel_hlcdc_pwm_remove()
without using atmel->chip.

Link: https://lore.kernel.org/r/0e97342f15540c7330d405eaaf3e68baa8e1e488.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-atmel-hlcdc.c

index 2d64af045fc5ab77baa99f1644ff257ab976d153..718f1b1cce0b4cc4a4b58688ec6a63ccf9ca8d7b 100644 (file)
@@ -182,8 +182,9 @@ static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_sama5d3_errata = {
 
 static int atmel_hlcdc_pwm_suspend(struct device *dev)
 {
-       struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev);
-       struct pwm_device *pwm = &atmel->chip.pwms[0];
+       struct pwm_chip *chip = dev_get_drvdata(dev);
+       struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
+       struct pwm_device *pwm = &chip->pwms[0];
 
        /* Keep the periph clock enabled if the PWM is still running. */
        if (!pwm->state.enabled)
@@ -194,8 +195,9 @@ static int atmel_hlcdc_pwm_suspend(struct device *dev)
 
 static int atmel_hlcdc_pwm_resume(struct device *dev)
 {
-       struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev);
-       struct pwm_device *pwm = &atmel->chip.pwms[0];
+       struct pwm_chip *chip = dev_get_drvdata(dev);
+       struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
+       struct pwm_device *pwm = &chip->pwms[0];
        int ret;
 
        /* Re-enable the periph clock it was stopped during suspend. */
@@ -205,7 +207,7 @@ static int atmel_hlcdc_pwm_resume(struct device *dev)
                        return ret;
        }
 
-       return atmel_hlcdc_pwm_apply(&atmel->chip, pwm, &pwm->state);
+       return atmel_hlcdc_pwm_apply(chip, pwm, &pwm->state);
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(atmel_hlcdc_pwm_pm_ops,
@@ -241,6 +243,7 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
 {
        const struct of_device_id *match;
        struct device *dev = &pdev->dev;
+       struct pwm_chip *chip;
        struct atmel_hlcdc_pwm *atmel;
        struct atmel_hlcdc *hlcdc;
        int ret;
@@ -260,26 +263,28 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
                atmel->errata = match->data;
 
        atmel->hlcdc = hlcdc;
-       atmel->chip.ops = &atmel_hlcdc_pwm_ops;
-       atmel->chip.dev = dev;
-       atmel->chip.npwm = 1;
+       chip = &atmel->chip;
+       chip->ops = &atmel_hlcdc_pwm_ops;
+       chip->dev = dev;
+       chip->npwm = 1;
 
-       ret = pwmchip_add(&atmel->chip);
+       ret = pwmchip_add(chip);
        if (ret) {
                clk_disable_unprepare(hlcdc->periph_clk);
                return ret;
        }
 
-       platform_set_drvdata(pdev, atmel);
+       platform_set_drvdata(pdev, chip);
 
        return 0;
 }
 
 static void atmel_hlcdc_pwm_remove(struct platform_device *pdev)
 {
-       struct atmel_hlcdc_pwm *atmel = platform_get_drvdata(pdev);
+       struct pwm_chip *chip = platform_get_drvdata(pdev);
+       struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
 
-       pwmchip_remove(&atmel->chip);
+       pwmchip_remove(chip);
 
        clk_disable_unprepare(atmel->hlcdc->periph_clk);
 }