pwm: sprd: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:32:37 +0000 (10:32 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 22 Feb 2024 13:39:10 +0000 (14:39 +0100)
This prepares the pwm-sprd 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.

Tested-by: Chunyan Zhang <zhang.lyra@gmail.com>
Link: https://lore.kernel.org/r/543213f44686ee72d8f88897bf2ca616e837ae44.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-sprd.c

index a38f50c3dc005741720493a1d4a775c488bd4a06..4c76ca5e4cdd66f4fd93c4e3002347ef240f386f 100644 (file)
@@ -34,13 +34,12 @@ struct sprd_pwm_chn {
 
 struct sprd_pwm_chip {
        void __iomem *base;
-       struct pwm_chip chip;
        struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
 };
 
 static inline struct sprd_pwm_chip* sprd_pwm_from_chip(struct pwm_chip *chip)
 {
-       return container_of(chip, struct sprd_pwm_chip, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 /*
@@ -248,6 +247,7 @@ static int sprd_pwm_clk_init(struct device *dev,
 
 static int sprd_pwm_probe(struct platform_device *pdev)
 {
+       struct pwm_chip *chip;
        struct sprd_pwm_chip *spc;
        struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
        int ret, npwm;
@@ -256,9 +256,10 @@ static int sprd_pwm_probe(struct platform_device *pdev)
        if (npwm < 0)
                return npwm;
 
-       spc = devm_kzalloc(&pdev->dev, sizeof(*spc), GFP_KERNEL);
-       if (!spc)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*spc));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       spc = sprd_pwm_from_chip(chip);
 
        spc->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(spc->base))
@@ -266,11 +267,9 @@ static int sprd_pwm_probe(struct platform_device *pdev)
 
        memcpy(spc->chn, chn, sizeof(chn));
 
-       spc->chip.dev = &pdev->dev;
-       spc->chip.ops = &sprd_pwm_ops;
-       spc->chip.npwm = npwm;
+       chip->ops = &sprd_pwm_ops;
 
-       ret = devm_pwmchip_add(&pdev->dev, &spc->chip);
+       ret = devm_pwmchip_add(&pdev->dev, chip);
        if (ret)
                dev_err(&pdev->dev, "failed to add PWM chip\n");