@@ -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;
@@ -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)
{
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. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/pwm/pwm-dwc-core.c | 10 ++++------ drivers/pwm/pwm-dwc.h | 7 +++++-- 2 files changed, 9 insertions(+), 8 deletions(-)