mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Michael Grzeschik <m.grzeschik@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] PWM: imx: pwm-imx-tpm: Add driver support
Date: Tue, 28 Jan 2025 11:25:40 +0100	[thread overview]
Message-ID: <Z5iwpH1rFFa92l85@pengutronix.de> (raw)
In-Reply-To: <20250126213930.256425-1-m.grzeschik@pengutronix.de>

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@pengutronix.de>
> ---
> +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 |



      reply	other threads:[~2025-01-28 10:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-26 21:39 Michael Grzeschik
2025-01-28 10:25 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z5iwpH1rFFa92l85@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.grzeschik@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox