Re: [PATCH 4/4] regulator: ltm8054: Support output current limit control

From: Andy Shevchenko
Date: Tue Sep 16 2025 - 09:19:35 EST


On Tue, Sep 16, 2025 at 12:24:09PM +0200, Romain Gantois wrote:
> The LTM8054 supports setting a fixed output current limit using a sense
> resistor connected to a dedicated pin. This limit can then be lowered
> dynamically by varying the voltage level of the CTL pin.
>
> Support controlling the LTM8054's output current limit.

...

> in microvolts

Yeah, using _mV postfix will make it visible that those are in micro-Volts.

...

> +static int ltm8054_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA)
> +{
> + struct ltm8054_priv *priv = rdev_get_drvdata(rdev);
> + u64 vdac_uV;
> +
> + min_uA = clamp_t(int, min_uA, priv->min_uA, priv->max_uA);
> +
> + /* adjusted current limit = Rsense current limit * CTL pin voltage / max CTL pin voltage */
> + vdac_uV = (u64)min_uA * LTM8054_MAX_CTL_V;
> + do_div(vdac_uV, priv->max_uA);
> +
> + dev_dbg(&rdev->dev,
> + "Setting current limit to %duA, CTL pin to %duV\n", min_uA, (int)vdac_uV);

Why casting?

> + /* Standard IIO voltage unit is mV, scale accordingly. */
> + return iio_write_channel_processed_scale(priv->ctl_dac, vdac_uV, 1000);
> +}

...

> + ret = of_property_read_u32(np, "lltc,iout-rsense-micro-ohms", &rsense);

device_property_read_u32()

> + if (ret < 0) {

Be consistent with a style, in the previous patch it was 'if (ret)'.

> + dev_err(dev, "failed to get sense resistor value\n");
> + return ret;
> + }
> +
> + if (rsense == 0) {
> + dev_err(dev, "invalid value zero for sense resistor\n");
> + return -EINVAL;
> + }
> +
> + /* The maximum output current limit is the one set by the Rsense resistor */
> + tmp = 1000000 * (u64)LTM8054_VOUT_IOUT_MAX;

Yo may use MICRO and drop the casting.

> + do_div(tmp, rsense);
> + priv->max_uA = tmp;
> +
> + /* Applying a voltage below LTM8054_MAX_CTL_V on the CTL pin reduces
> + * the output current limit. If this level drops below
> + * LTM8054_MIN_CTL_V the regulator stops switching
> + */

/*
* Besides missing period at the end this is not correct multi-line style of
* the comments. Use this example.
*/

> + tmp = LTM8054_MIN_CTL_V * (u64)priv->max_uA;
> + do_div(tmp, (u32)LTM8054_MAX_CTL_V);

Why casting?

> + priv->min_uA = tmp;

--
With Best Regards,
Andy Shevchenko