From: Romain Gantois <romain.gantois@bootlin.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-iio@vger.kernel.org
Subject: Re: [PATCH 4/4] regulator: ltm8054: Support output current limit control
Date: Tue, 16 Sep 2025 16:27:25 +0200 [thread overview]
Message-ID: <8772650.T7Z3S40VBb@fw-rgant> (raw)
In-Reply-To: <aMlj1OcfH8r9Zz6x@smile.fi.intel.com>
[-- Attachment #1: Type: text/plain, Size: 2787 bytes --]
On Tuesday, 16 September 2025 15:19:16 CEST Andy Shevchenko wrote:
> 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?
>
This one is indeed unnecessary.
> > + /* 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;
This cast avoids an overflow of the multiplication, since the result may
easily exceed 32 bytes in size.
> > + do_div(tmp, (u32)LTM8054_MAX_CTL_V);
>
> Why casting?
Since do_div() is a macro, I casted the second argument just to be safe, but
it seems that do_div() already does this internally, so I'll just drop the
cast.
Thanks,
--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2025-09-16 14:27 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 10:24 [PATCH 0/4] Add support for the LTM8054 voltage regulator Romain Gantois
2025-09-16 10:24 ` [PATCH 1/4] regulator: dt-bindings: Add Linear Technology LTM8054 regulator Romain Gantois
2025-09-16 13:25 ` Rob Herring (Arm)
2025-09-16 19:24 ` David Lechner
2025-09-17 15:51 ` Romain Gantois
2025-09-18 7:30 ` Romain Gantois
2025-09-16 10:24 ` [PATCH 2/4] iio: add processed write API Romain Gantois
2025-09-16 11:19 ` Mark Brown
2025-09-16 13:00 ` Romain Gantois
2025-09-16 13:03 ` Andy Shevchenko
2025-09-16 19:23 ` David Lechner
2025-09-17 15:46 ` Romain Gantois
2025-09-20 11:56 ` Jonathan Cameron
2025-09-16 10:24 ` [PATCH 3/4] regulator: Support the LTM8054 voltage regulator Romain Gantois
2025-09-16 13:12 ` Andy Shevchenko
2025-09-16 13:20 ` Andy Shevchenko
2025-09-16 14:17 ` Romain Gantois
2025-09-18 9:31 ` Romain Gantois
2025-09-18 19:17 ` Andy Shevchenko
2025-09-19 8:19 ` Romain Gantois
2025-09-16 10:24 ` [PATCH 4/4] regulator: ltm8054: Support output current limit control Romain Gantois
2025-09-16 13:19 ` Andy Shevchenko
2025-09-16 14:27 ` Romain Gantois [this message]
2025-09-17 7:02 ` Andy Shevchenko
2025-09-17 7:03 ` Andy Shevchenko
2025-09-25 7:54 ` Romain Gantois
-- strict thread matches above, loose matches on Subject: below --
2025-10-18 19:30 Andy Shevchenko
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=8772650.T7Z3S40VBb@fw-rgant \
--to=romain.gantois@bootlin.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
/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;
as well as URLs for NNTP newsgroup(s).