pwm: fsl-ftm: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:31:27 +0000 (10:31 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Mon, 19 Feb 2024 10:04:09 +0000 (11:04 +0100)
This prepares the pwm-fsl-ftm 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/b3c75dea5b2944402b14944fdf71a5db0e26cbd7.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-fsl-ftm.c

index b4f8dff60c50a99d36ee27683df86efbe1fbad84..2510c10ca47303d789feb760756da6c5fee45ec8 100644 (file)
@@ -40,7 +40,6 @@ struct fsl_pwm_periodcfg {
 };
 
 struct fsl_pwm_chip {
-       struct pwm_chip chip;
        struct mutex lock;
        struct regmap *regmap;
 
@@ -55,7 +54,7 @@ struct fsl_pwm_chip {
 
 static inline struct fsl_pwm_chip *to_fsl_chip(struct pwm_chip *chip)
 {
-       return container_of(chip, struct fsl_pwm_chip, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 static void ftm_clear_write_protection(struct fsl_pwm_chip *fpc)
@@ -398,15 +397,14 @@ static int fsl_pwm_probe(struct platform_device *pdev)
        void __iomem *base;
        int ret;
 
-       fpc = devm_kzalloc(&pdev->dev, sizeof(*fpc), GFP_KERNEL);
-       if (!fpc)
-               return -ENOMEM;
-       chip = &fpc->chip;
+       chip = devm_pwmchip_alloc(&pdev->dev, 8, sizeof(*fpc));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       fpc = to_fsl_chip(chip);
 
        mutex_init(&fpc->lock);
 
        fpc->soc = of_device_get_match_data(&pdev->dev);
-       chip->dev = &pdev->dev;
 
        base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(base))
@@ -446,9 +444,7 @@ static int fsl_pwm_probe(struct platform_device *pdev)
        if (IS_ERR(fpc->ipg_clk))
                fpc->ipg_clk = fpc->clk[FSL_PWM_CLK_SYS];
 
-
        chip->ops = &fsl_pwm_ops;
-       chip->npwm = 8;
 
        ret = devm_pwmchip_add(&pdev->dev, chip);
        if (ret < 0) {