* [PATCH v3] iio: magnetometer: si7210: simplify probe with devm_regulator_get_enable_read_voltage()
@ 2026-02-16 13:17 Antoniu Miclaus
2026-02-20 11:01 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Antoniu Miclaus @ 2026-02-16 13:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Antoniu Miclaus, linux-iio, linux-kernel
Cc: Andy Shevchenko
Simplify probe by using devm_regulator_get_enable_read_voltage() to
get, enable and read the regulator voltage in a single call, caching
the value at probe time.
This is a functional change as VDD voltage is now read once at probe
rather than dynamically on each temperature measurement. However, in
real deployments it is very rare for VDD to change after initial probe.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v3:
- reorder vdd_uV struct member placement (after fetch_lock instead of
at the end) to maintain proper struct field ordering
- update commit message to clarify the functional change
drivers/iio/magnetometer/si7210.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/magnetometer/si7210.c b/drivers/iio/magnetometer/si7210.c
index 27e3feba7a0f..2a36abd1c99d 100644
--- a/drivers/iio/magnetometer/si7210.c
+++ b/drivers/iio/magnetometer/si7210.c
@@ -128,8 +128,8 @@ static const struct regmap_config si7210_regmap_conf = {
struct si7210_data {
struct regmap *regmap;
struct i2c_client *client;
- struct regulator *vdd;
struct mutex fetch_lock; /* lock for a single measurement fetch */
+ unsigned int vdd_uV;
s8 temp_offset;
s8 temp_gain;
s8 scale_20_a[A_REGS_COUNT];
@@ -221,12 +221,8 @@ static int si7210_read_raw(struct iio_dev *indio_dev,
temp *= (1 + (data->temp_gain / 2048));
temp += (int)(MICRO / 16) * data->temp_offset;
- ret = regulator_get_voltage(data->vdd);
- if (ret < 0)
- return ret;
-
/* temp -= 0.222 * VDD */
- temp -= 222 * div_s64(ret, MILLI);
+ temp -= 222 * (data->vdd_uV / MILLI);
*val = div_s64(temp, MILLI);
@@ -396,14 +392,11 @@ static int si7210_probe(struct i2c_client *client)
return dev_err_probe(&client->dev, PTR_ERR(data->regmap),
"failed to register regmap\n");
- data->vdd = devm_regulator_get(&client->dev, "vdd");
- if (IS_ERR(data->vdd))
- return dev_err_probe(&client->dev, PTR_ERR(data->vdd),
- "failed to get VDD regulator\n");
-
- ret = regulator_enable(data->vdd);
- if (ret)
- return ret;
+ ret = devm_regulator_get_enable_read_voltage(&client->dev, "vdd");
+ if (ret < 0)
+ return dev_err_probe(&client->dev, ret,
+ "Failed to get vdd regulator\n");
+ data->vdd_uV = ret;
indio_dev->name = dev_name(&client->dev);
indio_dev->modes = INDIO_DIRECT_MODE;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v3] iio: magnetometer: si7210: simplify probe with devm_regulator_get_enable_read_voltage()
2026-02-16 13:17 [PATCH v3] iio: magnetometer: si7210: simplify probe with devm_regulator_get_enable_read_voltage() Antoniu Miclaus
@ 2026-02-20 11:01 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-02-20 11:01 UTC (permalink / raw)
To: Antoniu Miclaus
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel, Andy Shevchenko
On Mon, 16 Feb 2026 15:17:04 +0200
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> Simplify probe by using devm_regulator_get_enable_read_voltage() to
> get, enable and read the regulator voltage in a single call, caching
> the value at probe time.
>
> This is a functional change as VDD voltage is now read once at probe
> rather than dynamically on each temperature measurement. However, in
> real deployments it is very rare for VDD to change after initial probe.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Applied. Thanks
Jonathan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-20 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-16 13:17 [PATCH v3] iio: magnetometer: si7210: simplify probe with devm_regulator_get_enable_read_voltage() Antoniu Miclaus
2026-02-20 11:01 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®