On Sun, Jan 26, 2025 at 10:39:30PM +0100, Michael Grzeschik wrote: > Import the Linux v6.12 state of the driver to enable barebox control of PWM > LEDs, backlights and other peripherals. > > This has been tested on the IMX93. > > Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx> > --- > +static int pwm_imx_tpm_probe(struct device *dev) > +{ > + struct pwm_chip *chip; > + struct imx_tpm_pwm *tpm; > + struct clk *clk; > + void __iomem *base; > + int ret; > + unsigned int npwm; > + u32 val; > + int i; > + > + base = dev_platform_ioremap_resource(dev, 0); > + if (IS_ERR(base)) > + return PTR_ERR(base); > + > + clk = clk_get_enabled(dev, NULL); > + if (IS_ERR(clk)) > + return dev_err_probe(dev, PTR_ERR(clk), > + "failed to get PWM clock\n"); > + > + /* get number of channels */ > + val = readl(base + PWM_IMX_TPM_PARAM); > + npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val); > + > + tpm = xzalloc(sizeof(*tpm)); > + if (IS_ERR(tpm)) > + return PTR_ERR(tpm); xzalloc never returns an error (and if it would, it would likely be NULL) > + > + for (i = 0; i < npwm; i++) { > + struct imx_tpm_pwm_chip *tpmc = &tpm->pwm[i]; check npwm against ARRAY_SIZE(tpm->pwm)? > + > + chip = &tpmc->chip; > + > + tpmc->tpm = tpm; > + tpmc->tpm->base = base; > + tpmc->tpm->clk = clk; > + > + chip->ops = &imx_tpm_pwm_ops; > + chip->devname = basprintf("pwm%d", i); Use xasprintf() when not checking for an error. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |