[PATCH 1/3] regulator: don't cache vsel to ensure voltage setting

From: Matti Vaittinen
Date: Thu May 16 2024 - 04:53:59 EST


Some PMICs treat the vsel_reg same as apply-bit. Eg, when voltage range
is changed, the new voltage setting is not taking effect until the vsel
register is written.

Force the vsel value to be written to hardware even if the old selector
was same as the new (but range changed) by using regmap_write_bits() and
not the regmap_update_bits().

Signed-off-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

---
I have a feeling this same thing should be done with the apply-bit
writes. I just wonder why no-one has reported problems with it. Maybe
all the hardware with the apply bit has 'self clearing' apply register
marked as volatile? Anyways, I'll leave it out of this patch because I
have no hardware to test the apply-bit stuff, and as I haven't seen any
problem reports about it.
---
drivers/regulator/helpers.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index d49268336553..28c2f40b19cc 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -211,8 +211,14 @@ int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
if (ret)
return ret;

- ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
- rdev->desc->vsel_mask, sel);
+ /*
+ * Some PMICs treat the vsel_reg same as apply-bit. Force it
+ * to be written even if the old selector were same as the new
+ * (but range changed) by using regmap_write_bits() and not the
+ * regmap_update_bits().
+ */
+ ret = regmap_write_bits(rdev->regmap, rdev->desc->vsel_reg,
+ rdev->desc->vsel_mask, sel);
}

if (ret)
--
2.44.0


--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]

Attachment: signature.asc
Description: PGP signature