pwm: brcmstb: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:31:09 +0000 (10:31 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 15 Feb 2024 11:59:20 +0000 (12:59 +0100)
This prepares the pwm-brcmstb 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/adf9cb04f5d84ae604e97d4dc0708ff3677d72d7.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-brcmstb.c

index 0fdeb0b2dbf3762970702e49cf7e764f0aee5d5a..82d27d07ba91b2f4f4b8deba12545db6fa409390 100644 (file)
@@ -54,7 +54,6 @@
 struct brcmstb_pwm {
        void __iomem *base;
        struct clk *clk;
-       struct pwm_chip chip;
 };
 
 static inline u32 brcmstb_pwm_readl(struct brcmstb_pwm *p,
@@ -77,7 +76,7 @@ static inline void brcmstb_pwm_writel(struct brcmstb_pwm *p, u32 value,
 
 static inline struct brcmstb_pwm *to_brcmstb_pwm(struct pwm_chip *chip)
 {
-       return container_of(chip, struct brcmstb_pwm, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 /*
@@ -230,12 +229,14 @@ MODULE_DEVICE_TABLE(of, brcmstb_pwm_of_match);
 
 static int brcmstb_pwm_probe(struct platform_device *pdev)
 {
+       struct pwm_chip *chip;
        struct brcmstb_pwm *p;
        int ret;
 
-       p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
-       if (!p)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*p));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       p = to_brcmstb_pwm(chip);
 
        p->clk = devm_clk_get_enabled(&pdev->dev, NULL);
        if (IS_ERR(p->clk))
@@ -244,15 +245,13 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, p);
 
-       p->chip.dev = &pdev->dev;
-       p->chip.ops = &brcmstb_pwm_ops;
-       p->chip.npwm = 2;
+       chip->ops = &brcmstb_pwm_ops;
 
        p->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(p->base))
                return PTR_ERR(p->base);
 
-       ret = devm_pwmchip_add(&pdev->dev, &p->chip);
+       ret = devm_pwmchip_add(&pdev->dev, chip);
        if (ret)
                return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");