pwm: atmel-hlcdc: Prepare removing pwm_chip from driver data

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>
This commit is contained in:
Uwe Kleine-König 2024-02-14 10:30:58 +01:00
parent 8de8ccaca9
commit 0ba76822eb

View 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);
}