]> Git Repo - J-linux.git/commitdiff
pwm: meson: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <[email protected]>
Wed, 14 Feb 2024 09:31:59 +0000 (10:31 +0100)
committerUwe Kleine-König <[email protected]>
Mon, 19 Feb 2024 10:04:12 +0000 (11:04 +0100)
This prepares the pwm-meson 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/6cc57880e910e6ffd8df15bc4a41c42fe9523293.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <[email protected]>
drivers/pwm/pwm-meson.c

index 8f67d6ba443de3dea0a8520b8138c94d9fd54a38..40a5b64c26f5a453edffbee838923a8e5d12aff4 100644 (file)
@@ -102,7 +102,6 @@ struct meson_pwm_data {
 };
 
 struct meson_pwm {
-       struct pwm_chip chip;
        const struct meson_pwm_data *data;
        struct meson_pwm_channel channels[MESON_NUM_PWMS];
        void __iomem *base;
@@ -115,7 +114,7 @@ struct meson_pwm {
 
 static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip)
 {
-       return container_of(chip, struct meson_pwm, chip);
+       return pwmchip_get_drvdata(chip);
 }
 
 static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
@@ -529,29 +528,29 @@ static int meson_pwm_init_channels(struct pwm_chip *chip)
 
 static int meson_pwm_probe(struct platform_device *pdev)
 {
+       struct pwm_chip *chip;
        struct meson_pwm *meson;
        int err;
 
-       meson = devm_kzalloc(&pdev->dev, sizeof(*meson), GFP_KERNEL);
-       if (!meson)
-               return -ENOMEM;
+       chip = devm_pwmchip_alloc(&pdev->dev, MESON_NUM_PWMS, sizeof(*meson));
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
+       meson = to_meson_pwm(chip);
 
        meson->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(meson->base))
                return PTR_ERR(meson->base);
 
        spin_lock_init(&meson->lock);
-       meson->chip.dev = &pdev->dev;
-       meson->chip.ops = &meson_pwm_ops;
-       meson->chip.npwm = MESON_NUM_PWMS;
+       chip->ops = &meson_pwm_ops;
 
        meson->data = of_device_get_match_data(&pdev->dev);
 
-       err = meson_pwm_init_channels(&meson->chip);
+       err = meson_pwm_init_channels(chip);
        if (err < 0)
                return err;
 
-       err = devm_pwmchip_add(&pdev->dev, &meson->chip);
+       err = devm_pwmchip_add(&pdev->dev, chip);
        if (err < 0)
                return dev_err_probe(&pdev->dev, err,
                                     "failed to register PWM chip\n");
This page took 0.0492 seconds and 4 git commands to generate.