Skip to contentSkip to conversation

power: regulator: tps65941: Fix voltage calculation for ldo

PATCH In review Udit Kumar 3 participants 3 messages Feb 11, 2025 – Feb 18, 2025

lore
Share & tools
lore

Udit Kumar

author
#0 lore raw

PATCH 1/1 power: regulator: tps65941: Fix voltage calculation for ldo

As per TRM[0] Section 8.7.1 "TPS6594-Q1 Registers", LDOx_Vout bit 6-1, define the NVM voltage settings.
Along side table 8-4 of above TRM, shows voltage to value mapping.

Driver wrongly using bits 5-1 to calculate voltage, and to convert voltage to value driver was using buck's calculation. So fix those calculation.

[0]: https://www.ti.com/lit/ds/symlink/tps6594-q1.pdf

Fixes 5d7dbd22cf7d ("power: regulator: tps65941: use function callbacks for conversion ops")

---
Bootlogs
https://gist.github.com/uditkumarti/298bd277da11eb82146d7aff24c402ba

 drivers/power/regulator/tps65941_regulator.c | 16 +++++++++++++---
 include/power/tps65941.h                     |  3 ++-
 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/power/regulator/tps65941_regulator.c +13 -3
index bc4d153fd8..13f94b730d 100644
@@ -388,6 +388,14 @@ static int tps65941_ldo_enable(struct udevice *dev, int op, bool *enable)
 	return 0;
 }
 
+static int tps65941_ldo_volt2val(__maybe_unused int idx, int uV)
+{
+	if (uV > TPS65941_LDO_VOLT_MAX || uV < TPS65941_LDO_VOLT_MIN)
+		return -EINVAL;
+
+	return ((uV - 600000) / 50000 + 0x4) << TPS65941_LDO_MODE_MASK;
+}
+
 static int tps65941_ldo_val2volt(__maybe_unused int idx, int val)
 {
 	if (val > TPS65941_LDO_VOLT_MAX_HEX || val < TPS65941_LDO_VOLT_MIN_HEX)
@@ -459,7 +467,7 @@ static int tps65224_ldo_val2volt(int idx, int val)
 static const struct tps65941_reg_conv_ops ldo_conv_ops[] = {
 	[TPS65941_LDO_CONV_OPS_IDX] = {
 		.volt_mask = TPS65941_LDO_VOLT_MASK,
-		.volt2val = tps65941_buck_volt2val,
+		.volt2val = tps65941_ldo_volt2val,
 		.val2volt = tps65941_ldo_val2volt,
 	},
 	[TPS65224_LDO_CONV_OPS_IDX] = {
@@ -472,7 +480,7 @@ static const struct tps65941_reg_conv_ops ldo_conv_ops[] = {
 static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 {
 	unsigned int hex, adr;
-	int ret, ret_volt, idx;
+	int ret, ret_volt, idx, ldo_bypass;
 	struct dm_regulator_uclass_plat *uc_pdata;
 	const struct tps65941_reg_conv_ops *conv_ops;
 	ulong chip_id;
@@ -502,7 +510,9 @@ static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 	if (ret < 0)
 		return ret;
 
+	ldo_bypass = ret & TPS65941_LDO_BYPASS_EN;
 	ret &= conv_ops->volt_mask;
+	ret = ret >> TPS65941_LDO_MODE_MASK;
 	ret_volt = conv_ops->val2volt(idx, ret);
 	if (ret_volt < 0)
 		return ret_volt;
@@ -531,7 +541,7 @@ static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 		ret &= ~TPS65224_LDO_VOLT_MASK;
 		ret |= hex;
 	} else {
-		ret = hex;
+		ret = hex | ldo_bypass;
 	}
 
 	ret = pmic_reg_write(dev->parent, adr, ret);
include/power/tps65941.h +2 -1
index cec85333f0..a026ec5695 100644
@@ -21,10 +21,11 @@
 #define TPS65941_BUCK_VOLT_MAX		3340000
 #define TPS65941_BUCK_MODE_MASK		0x1
 
-#define TPS65941_LDO_VOLT_MASK		0x3E
+#define TPS65941_LDO_VOLT_MASK		0x7E
 #define TPS65941_LDO_VOLT_MAX_HEX	0x3A
 #define TPS65941_LDO_VOLT_MIN_HEX	0x4
 #define TPS65941_LDO_VOLT_MAX		3300000
+#define TPS65941_LDO_VOLT_MIN		600000
 #define TPS65941_LDO_MODE_MASK		0x1
 #define TPS65941_LDO_BYPASS_EN		0x80
 #define TP65941_BUCK_CONF_SLEW_MASK	0x7
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Udit

Quoted 82 lines · Udit Kumar

As per TRM[0] Section 8.7.1 "TPS6594-Q1 Registers", LDOx_Vout bit 6-1, define the NVM voltage settings.
Along side table 8-4 of above TRM, shows voltage to value mapping.

Driver wrongly using bits 5-1 to calculate voltage, and to convert voltage to value driver was using buck's calculation. So fix those calculation.

[0]: https://www.ti.com/lit/ds/symlink/tps6594-q1.pdf

Fixes 5d7dbd22cf7d ("power: regulator: tps65941: use function callbacks for conversion ops")

---
Bootlogs
https://gist.github.com/uditkumarti/298bd277da11eb82146d7aff24c402ba

 drivers/power/regulator/tps65941_regulator.c | 16 +++++++++++++---
 include/power/tps65941.h                     |  3 ++-
 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/power/regulator/tps65941_regulator.c +13 -3
index bc4d153fd8..13f94b730d 100644
@@ -388,6 +388,14 @@ static int tps65941_ldo_enable(struct udevice *dev, int op, bool *enable)
 	return 0;
 }
 
+static int tps65941_ldo_volt2val(__maybe_unused int idx, int uV)
+{
+	if (uV > TPS65941_LDO_VOLT_MAX || uV < TPS65941_LDO_VOLT_MIN)
+		return -EINVAL;
+
+	return ((uV - 600000) / 50000 + 0x4) << TPS65941_LDO_MODE_MASK;
+}
+
 static int tps65941_ldo_val2volt(__maybe_unused int idx, int val)
 {
 	if (val > TPS65941_LDO_VOLT_MAX_HEX || val < TPS65941_LDO_VOLT_MIN_HEX)
@@ -459,7 +467,7 @@ static int tps65224_ldo_val2volt(int idx, int val)
 static const struct tps65941_reg_conv_ops ldo_conv_ops[] = {
 	[TPS65941_LDO_CONV_OPS_IDX] = {
 		.volt_mask = TPS65941_LDO_VOLT_MASK,
-		.volt2val = tps65941_buck_volt2val,
+		.volt2val = tps65941_ldo_volt2val,
 		.val2volt = tps65941_ldo_val2volt,
 	},
 	[TPS65224_LDO_CONV_OPS_IDX] = {
@@ -472,7 +480,7 @@ static const struct tps65941_reg_conv_ops ldo_conv_ops[] = {
 static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 {
 	unsigned int hex, adr;
-	int ret, ret_volt, idx;
+	int ret, ret_volt, idx, ldo_bypass;
 	struct dm_regulator_uclass_plat *uc_pdata;
 	const struct tps65941_reg_conv_ops *conv_ops;
 	ulong chip_id;
@@ -502,7 +510,9 @@ static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 	if (ret < 0)
 		return ret;
 
+	ldo_bypass = ret & TPS65941_LDO_BYPASS_EN;
 	ret &= conv_ops->volt_mask;
+	ret = ret >> TPS65941_LDO_MODE_MASK;
 	ret_volt = conv_ops->val2volt(idx, ret);
 	if (ret_volt < 0)
 		return ret_volt;
@@ -531,7 +541,7 @@ static int tps65941_ldo_val(struct udevice *dev, int op, int *uV)
 		ret &= ~TPS65224_LDO_VOLT_MASK;
 		ret |= hex;
 	} else {
-		ret = hex;
+		ret = hex | ldo_bypass;
 	}
 
 	ret = pmic_reg_write(dev->parent, adr, ret);
include/power/tps65941.h +0 -0
index cec85333f0..a026ec5695 100644
@@ -21,10 +21,11 @@
 #define TPS65941_BUCK_VOLT_MAX		3340000
 #define TPS65941_BUCK_MODE_MASK		0x1

include/power/tps65941.h line 31

Quoted 10 lines
include/power/tps65941.h +2 -1
 
-#define TPS65941_LDO_VOLT_MASK		0x3E
+#define TPS65941_LDO_VOLT_MASK		0x7E
 #define TPS65941_LDO_VOLT_MAX_HEX	0x3A
 #define TPS65941_LDO_VOLT_MIN_HEX	0x4
 #define TPS65941_LDO_VOLT_MAX		3300000
+#define TPS65941_LDO_VOLT_MIN		600000
 #define TPS65941_LDO_MODE_MASK		0x1
 #define TPS65941_LDO_BYPASS_EN		0x80
 #define TP65941_BUCK_CONF_SLEW_MASK	0x7
Signature · 2 lines
Thanking You
Neha Malcom Francis
#2 lore raw
In reply to Udit Kumar
Quoted 9 lines · Udit Kumar

As per TRM[0] Section 8.7.1 "TPS6594-Q1 Registers", LDOx_Vout bit 6-1, define the NVM voltage settings.
Along side table 8-4 of above TRM, shows voltage to value mapping.

Driver wrongly using bits 5-1 to calculate voltage, and to convert voltage to value driver was using buck's calculation. So fix those calculation.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom