pwm: bcm2835: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:31:03 +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-bcm2835 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/441489772bdfbb2cd206fd534b36c63e8c50843a.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-bcm2835.c

index 711c174bbe2337ef82ef5f650e8ba7379e778a08..aa35acbb0cbcf5dd9aa0ca6f73d53e297c097cdd 100644 (file)
@@ -24,7 +24,6 @@
 #define PERIOD_MIN             0x2
 
 struct bcm2835_pwm {
-       struct pwm_chip chip;
        void __iomem *base;
        struct clk *clk;
        unsigned long rate;
@@ -32,7 +31,7 @@ struct bcm2835_pwm {
 
 static inline struct bcm2835_pwm *to_bcm2835_pwm(struct pwm_chip *chip)
 {
-       return container_of(chip, struct bcm2835_pwm, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 static int bcm2835_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
@@ -134,12 +133,14 @@ static void devm_clk_rate_exclusive_put(void *data)
 
 static int bcm2835_pwm_probe(struct platform_device *pdev)
 {
+       struct pwm_chip *chip;
        struct bcm2835_pwm *pc;
        int ret;
 
-       pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
-       if (!pc)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*pc));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       pc = to_bcm2835_pwm(chip);
 
        pc->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(pc->base))
@@ -165,14 +166,12 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
                return dev_err_probe(&pdev->dev, -EINVAL,
                                     "failed to get clock rate\n");
 
-       pc->chip.dev = &pdev->dev;
-       pc->chip.ops = &bcm2835_pwm_ops;
-       pc->chip.atomic = true;
-       pc->chip.npwm = 2;
+       chip->ops = &bcm2835_pwm_ops;
+       chip->atomic = true;
 
        platform_set_drvdata(pdev, pc);
 
-       ret = devm_pwmchip_add(&pdev->dev, &pc->chip);
+       ret = devm_pwmchip_add(&pdev->dev, chip);
        if (ret < 0)
                return dev_err_probe(&pdev->dev, ret,
                                     "failed to add pwmchip\n");