pwm: dwc: Make use of devm_pwmchip_alloc() function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:31:20 +0000 (10:31 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Mon, 19 Feb 2024 10:04:08 +0000 (11:04 +0100)
This prepares the pwm-dwc 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.

Also convert the to_dwc_pwm() helper macro to a static inline to get
some type safety.

Link: https://lore.kernel.org/r/64e64a9a8644600d51b234ad9bcae951b5748998.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-dwc-core.c
drivers/pwm/pwm-dwc.h

index ac7a0b2cb8b926688fd71219eb39dbae06f35ab2..de1d2ac3316c251c73124de4bbb954fa248f247e 100644 (file)
@@ -164,15 +164,13 @@ struct pwm_chip *dwc_pwm_alloc(struct device *dev)
        struct pwm_chip *chip;
        struct dwc_pwm *dwc;
 
-       dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
-       if (!dwc)
-               return ERR_PTR(-ENOMEM);
-       chip = &dwc->chip;
+       chip = devm_pwmchip_alloc(dev, DWC_TIMERS_TOTAL, sizeof(*dwc));
+       if (IS_ERR(chip))
+               return chip;
+       dwc = to_dwc_pwm(chip);
 
        dwc->clk_ns = 10;
-       chip->dev = dev;
        chip->ops = &dwc_pwm_ops;
-       chip->npwm = DWC_TIMERS_TOTAL;
 
        dev_set_drvdata(dev, chip);
        return chip;
index 432a3b4c81fd1dfcbf4fc03f09b95640ce6d7d48..5887371803fd8687515e4e447a0dde3a2034d9d0 100644 (file)
@@ -40,12 +40,15 @@ struct dwc_pwm_ctx {
 };
 
 struct dwc_pwm {
-       struct pwm_chip chip;
        void __iomem *base;
        unsigned int clk_ns;
        struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
 };
-#define to_dwc_pwm(p)  (container_of((p), struct dwc_pwm, chip))
+
+static inline struct dwc_pwm *to_dwc_pwm(struct pwm_chip *chip)
+{
+       return pwmchip_get_drvdata(chip);
+}
 
 static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset)
 {