Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: mxs: Make use of devm_pwmchip_alloc() function

This prepares the pwm-mxs 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_mxs_pwm_chip() helper macro to a static inline to
get some type safety.

Link: https://lore.kernel.org/r/39203f3bfbf4e97654db78bdc7e0c9a2b72c1368.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

+18 -14
+18 -14
drivers/pwm/pwm-mxs.c
··· 37 37 }; 38 38 39 39 struct mxs_pwm_chip { 40 - struct pwm_chip chip; 41 40 struct clk *clk; 42 41 void __iomem *base; 43 42 }; 44 43 45 - #define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip) 44 + static inline struct mxs_pwm_chip *to_mxs_pwm_chip(struct pwm_chip *chip) 45 + { 46 + return pwmchip_get_drvdata(chip); 47 + } 46 48 47 49 static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 48 50 const struct pwm_state *state) ··· 122 120 static int mxs_pwm_probe(struct platform_device *pdev) 123 121 { 124 122 struct device_node *np = pdev->dev.of_node; 123 + struct pwm_chip *chip; 125 124 struct mxs_pwm_chip *mxs; 125 + u32 npwm; 126 126 int ret; 127 127 128 - mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); 129 - if (!mxs) 130 - return -ENOMEM; 128 + ret = of_property_read_u32(np, "fsl,pwm-number", &npwm); 129 + if (ret < 0) { 130 + dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); 131 + return ret; 132 + } 133 + 134 + chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*mxs)); 135 + if (IS_ERR(chip)) 136 + return PTR_ERR(chip); 137 + mxs = to_mxs_pwm_chip(chip); 131 138 132 139 mxs->base = devm_platform_ioremap_resource(pdev, 0); 133 140 if (IS_ERR(mxs->base)) ··· 146 135 if (IS_ERR(mxs->clk)) 147 136 return PTR_ERR(mxs->clk); 148 137 149 - mxs->chip.dev = &pdev->dev; 150 - mxs->chip.ops = &mxs_pwm_ops; 151 - 152 - ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); 153 - if (ret < 0) { 154 - dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); 155 - return ret; 156 - } 138 + chip->ops = &mxs_pwm_ops; 157 139 158 140 /* FIXME: Only do this if the PWM isn't already running */ 159 141 ret = stmp_reset_block(mxs->base); 160 142 if (ret) 161 143 return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n"); 162 144 163 - ret = devm_pwmchip_add(&pdev->dev, &mxs->chip); 145 + ret = devm_pwmchip_add(&pdev->dev, chip); 164 146 if (ret < 0) { 165 147 dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret); 166 148 return ret;