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

index 32350a357278df0c1857524480266a95ee24aadc..61189cea10467089801349c001d0286efca621dc 100644 (file)
@@ -20,7 +20,6 @@
 #define LP3943_MAX_PERIOD              1600000
 
 struct lp3943_pwm {
-       struct pwm_chip chip;
        struct lp3943 *lp3943;
        struct lp3943_platform_data *pdata;
        struct lp3943_pwm_map pwm_map[LP3943_NUM_PWMS];
@@ -28,7 +27,7 @@ struct lp3943_pwm {
 
 static inline struct lp3943_pwm *to_lp3943_pwm(struct pwm_chip *chip)
 {
-       return container_of(chip, struct lp3943_pwm, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 static struct lp3943_pwm_map *
@@ -273,12 +272,14 @@ static int lp3943_pwm_parse_dt(struct device *dev,
 static int lp3943_pwm_probe(struct platform_device *pdev)
 {
        struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent);
+       struct pwm_chip *chip;
        struct lp3943_pwm *lp3943_pwm;
        int ret;
 
-       lp3943_pwm = devm_kzalloc(&pdev->dev, sizeof(*lp3943_pwm), GFP_KERNEL);
-       if (!lp3943_pwm)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(&pdev->dev, LP3943_NUM_PWMS, sizeof(*lp3943_pwm));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       lp3943_pwm = to_lp3943_pwm(chip);
 
        lp3943_pwm->pdata = lp3943->pdata;
        if (!lp3943_pwm->pdata) {
@@ -292,11 +293,9 @@ static int lp3943_pwm_probe(struct platform_device *pdev)
        }
 
        lp3943_pwm->lp3943 = lp3943;
-       lp3943_pwm->chip.dev = &pdev->dev;
-       lp3943_pwm->chip.ops = &lp3943_pwm_ops;
-       lp3943_pwm->chip.npwm = LP3943_NUM_PWMS;
+       chip->ops = &lp3943_pwm_ops;
 
-       return devm_pwmchip_add(&pdev->dev, &lp3943_pwm->chip);
+       return devm_pwmchip_add(&pdev->dev, chip);
 }
 
 #ifdef CONFIG_OF