Devicetree
 help / color / mirror / Atom feed
From: "Paul Louvel" <paul.louvel@bootlin.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Paul Louvel" <paul.louvel@bootlin.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Herve Codina" <herve.codina@bootlin.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>
Subject: Re: [PATCH 4/5] regulator: Support regulators where the voltage selector spans two registers
Date: Fri, 23 Oct 2026 12:02:46 +0200	[thread overview]
Message-ID: <DMC4R59FLPFW.2VD3S7QQHIIQA@bootlin.com> (raw)
In-Reply-To: <atpGAeQIzOBnYzZS@sirena.org.uk>

On Thu Oct 22, 2026 at 7:21 PM CEST, Mark Brown wrote:
> On Wed, Oct 21, 2026 at 12:27:45PM +0200, Paul Louvel wrote:
>> Some devices uses 8-bit registers to store the voltage selector across
>> two registers: one for the least significant bits and one for the most
>> significant bits.
>
>> +static int set_oversize_voltage_sel(struct regulator_dev *rdev, unsigned int sel)
>> +{
>> +	int val_bytes = regmap_get_val_bytes(rdev->regmap);
>> +	__le16 val;
>> +
>> +	if (val_bytes != 1)
>> +		return -EINVAL;
>> +
>> +	val = cpu_to_le16(sel);
>> +
>> +	return regmap_bulk_write(rdev->regmap, rdev->desc->vsel_reg, &val, 2);
>> +}
>
> This ignores the shift and mask but the get still pays attention to them
> due to code sharing.  Either there should be checks that reject them
> like we have for val_bytes or there should be a read/modify/write here,
> obviously the former is much easier and that'd be totally fine.  IIRC
> there's some existing drivers we could convert but that's a separate
> thing.

set_oversize_voltage_sel() does not apply the shift itself because both callers
already shift sel into position before calling it [1][2].

Using two separate regmap_update_bits() calls, one per register, would be
equally simple, and it would guarantee that reserved bits outside vsel_mask are
not overwritten on devices that are sensitive (not the case for the LM51772).

[1]: https://elixir.bootlin.com/linux/v7.3/source/drivers/regulator/helpers.c#L222
[2]: https://elixir.bootlin.com/linux/v7.3/source/drivers/regulator/helpers.c#L285

Thanks.
Best regards,
-- 
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2026-10-23 10:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 10:27 [PATCH 0/5] Add TI LM51772 buck-boost voltage regulator Paul Louvel
2026-10-21 10:27 ` [PATCH 1/5] regulator: dt-bindings: Add regulator-boot-force-off property Paul Louvel
2026-10-21 17:01   ` Conor Dooley
2026-10-21 17:11     ` Paul Louvel
2026-10-22  7:08       ` Krzysztof Kozlowski
2026-10-22 12:22       ` Mark Brown
2026-10-22 12:39         ` Paul Louvel
2026-10-21 10:27 ` [PATCH 2/5] regulator: dt-bindings: Add TI LM51772 support Paul Louvel
2026-10-21 10:44   ` sashiko-bot
2026-10-21 10:27 ` [PATCH 3/5] regulator: core: Add mechanism to force disable a regulator at boot Paul Louvel
2026-10-21 10:46   ` sashiko-bot
2026-10-21 15:17     ` Paul Louvel
2026-10-22 13:48   ` Mark Brown
2026-10-21 10:27 ` [PATCH 4/5] regulator: Support regulators where the voltage selector spans two registers Paul Louvel
2026-10-21 10:45   ` sashiko-bot
2026-10-21 15:10     ` Paul Louvel
2026-10-22 17:21   ` Mark Brown
2026-10-23 10:02     ` Paul Louvel [this message]
2026-10-21 10:27 ` [PATCH 5/5] regulator: Add TI LM51772 support Paul Louvel
2026-10-21 10:56   ` sashiko-bot
2026-10-21 15:14     ` Paul Louvel
2026-10-21 15:10   ` Uwe Kleine-König
2026-10-22 17:34   ` Mark Brown
2026-10-23  7:24     ` Paul Louvel
2026-10-22 13:42 ` [PATCH 0/5] Add TI LM51772 buck-boost voltage regulator Mark Brown
2026-10-23 10:31   ` Paul Louvel

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=DMC4R59FLPFW.2VD3S7QQHIIQA@bootlin.com \
    --to=paul.louvel@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=herve.codina@bootlin.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquel.raynal@bootlin.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