pwm: atmel-hlcdc: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:30:59 +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 pwm-atmel-hlcdc driver to further changes of the pwm
core outlined in the commit introducing devm_pwmchip_alloc(). There is
no intended semantical change and the driver should behave as before.

Link: https://lore.kernel.org/r/4724c6a0f052160ac80ba5a3065c9470778b7457.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 718f1b1cce0b4cc4a4b58688ec6a63ccf9ca8d7b..2afb302be02c1101e033bb4cefaba996ddc68524 100644 (file)
@@ -28,7 +28,6 @@ struct atmel_hlcdc_pwm_errata {
 };
 
 struct atmel_hlcdc_pwm {
-       struct pwm_chip chip;
        struct atmel_hlcdc *hlcdc;
        struct clk *cur_clk;
        const struct atmel_hlcdc_pwm_errata *errata;
@@ -36,7 +35,7 @@ struct atmel_hlcdc_pwm {
 
 static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
 {
-       return container_of(chip, struct atmel_hlcdc_pwm, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -250,9 +249,10 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
 
        hlcdc = dev_get_drvdata(dev->parent);
 
-       atmel = devm_kzalloc(dev, sizeof(*atmel), GFP_KERNEL);
-       if (!atmel)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(dev, 1, sizeof(*atmel));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       atmel = to_atmel_hlcdc_pwm(chip);
 
        ret = clk_prepare_enable(hlcdc->periph_clk);
        if (ret)
@@ -263,10 +263,7 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
                atmel->errata = match->data;
 
        atmel->hlcdc = hlcdc;
-       chip = &atmel->chip;
        chip->ops = &atmel_hlcdc_pwm_ops;
-       chip->dev = dev;
-       chip->npwm = 1;
 
        ret = pwmchip_add(chip);
        if (ret) {