Skip to contentSkip to conversation

power: pmic: rk8xx: Don't set RK817_POWER_EN_SAVE bits

PATCH New Chris Morgan 1 participant 1 message Nov 25

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 power: pmic: rk8xx: Don't set RK817_POWER_EN_SAVE bits

From: Chris Morgan <[email protected]>

Don't set the RK817_POWER_EN_SAVE0 or RK817_POWER_EN_SAVE1 bits, unless the device-tree property of "not-save-power-en" is present and set to 0.

Per a discussion on the mailing list these registers are used by the BSP kernel to save the regulator state at early power-on so that late shutdown can ensure the regulators stay at this state to prevent a possible overvolt situation. However, these registers are not used by mainline Linux and actively setting them in U-boot interferes with their function for BSP kernels, causing systems to hang when regulators are enabled or disabled incorrectly. [1]

By skipping this behavior except when the BSP only parameter is present and set to 0, we can preserve the registers function without creating additional problems.

[1] https://gist.github.com/fr0z3n-cs/047b24a6fd430e816fe02a877ad7ab8c

---
 drivers/power/pmic/rk8xx.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/power/pmic/rk8xx.c +17 -9
index 95b71d2fe49..614d749d5ff 100644
@@ -293,15 +293,23 @@ static int rk8xx_probe(struct udevice *dev)
 		off_source = RK817_OFF_SOURCE;
 		init_data = rk817_init_reg;
 		init_data_num = ARRAY_SIZE(rk817_init_reg);
-		power_en0 = pmic_reg_read(dev, RK817_POWER_EN0);
-		power_en1 = pmic_reg_read(dev, RK817_POWER_EN1);
-		power_en2 = pmic_reg_read(dev, RK817_POWER_EN2);
-		power_en3 = pmic_reg_read(dev, RK817_POWER_EN3);
-
-		value = (power_en0 & 0x0f) | ((power_en1 & 0x0f) << 4);
-		pmic_reg_write(dev, RK817_POWER_EN_SAVE0, value);
-		value = (power_en2 & 0x0f) | ((power_en3 & 0x0f) << 4);
-		pmic_reg_write(dev, RK817_POWER_EN_SAVE1, value);
+		/*
+		 * If the BSP only attribute of "not-save-power-en" is present
+		 * and if it is 0, only then would we save the register values
+		 * for use by the BSP kernel for use on shutdown. If the value
+		 * is not present or not 0, we skip this.
+		 */
+		if (!dev_read_u32_default(dev, "not-save-power-en", 1)) {
+			power_en0 = pmic_reg_read(dev, RK817_POWER_EN0);
+			power_en1 = pmic_reg_read(dev, RK817_POWER_EN1);
+			power_en2 = pmic_reg_read(dev, RK817_POWER_EN2);
+			power_en3 = pmic_reg_read(dev, RK817_POWER_EN3);
+
+			value = (power_en0 & 0x0f) | ((power_en1 & 0x0f) << 4);
+			pmic_reg_write(dev, RK817_POWER_EN_SAVE0, value);
+			value = (power_en2 & 0x0f) | ((power_en3 & 0x0f) << 4);
+			pmic_reg_write(dev, RK817_POWER_EN_SAVE1, value);
+		}
 		break;
 	case RK806_ID: {
 		u32 rst_fun = 2;
Signature · 1 line
2.53.0