Skip to contentSkip to conversation

mfd: axp20x: preserve other control bits when powering off

PATCH Applied Oleg Proshkin 3 participants 3 messages Jun 11 – Jun 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: axp20x: preserve other control bits when powering off

axp20x_power_off() triggers shutdown by writing AXP20X_OFF (BIT(7)) to the power-off control register with regmap_write(), which rewrites the whole register and clears other control bits in it.

On the AXP221/AXP223 (and the register-compatible AXP228) - that register also holds the CHGLED auto-control bit.
Clearing it during an orderly shutdown disables the hardware charge indicator, so the charge LED stays dark while the board is powered off and charging. Other variants keep unrelated configuration in the same register too.

Set only the power-off bit with regmap_set_bits() and leave the rest of the register untouched. The shutdown register is readable on every variant, so the read-modify-write should be safe.

Tested on a ClockworkPi uConsole (Raspberry Pi Compute Module 4, AXP228, which enumerates as AXP221): register AXP20X_OFF_CTRL reads 0x08 at runtime, so the old code left it 0x80 whereas setting only BIT(7) leaves 0x88. Writing 0x88 at power-off enables the charge LED while still powering off the PMIC.

---
 drivers/mfd/axp20x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/axp20x.c +1 -1
index 679364189..50df66de2 100644
@@ -1253,7 +1253,7 @@ static int axp20x_power_off(struct sys_off_data *data)
 		break;
 	}
 
-	regmap_write(axp20x->regmap, shutdown_reg, AXP20X_OFF);
+	regmap_set_bits(axp20x->regmap, shutdown_reg, AXP20X_OFF);
 
 	/* Give capacitors etc. time to drain to avoid kernel panic msg. */
 	mdelay(500);
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Oleg Proshkin

axp20x_power_off() triggers shutdown by writing AXP20X_OFF (BIT(7)) to the power-off control register with regmap_write(), which rewrites the whole register and clears other control bits in it.

On the AXP221/AXP223 (and the register-compatible AXP228) - that register also holds the CHGLED auto-control bit.
Clearing it during an orderly shutdown disables the hardware charge indicator, so the charge LED stays dark while the board is powered off and charging. Other variants keep unrelated configuration in the same register too.

Set only the power-off bit with regmap_set_bits() and leave the rest of the register untouched. The shutdown register is readable on every variant, so the read-modify-write should be safe.

Quoted 7 lines

Tested on a ClockworkPi uConsole (Raspberry Pi Compute Module 4, AXP228, which enumerates as AXP221): register AXP20X_OFF_CTRL reads 0x08 at runtime, so the old code left it 0x80 whereas setting only BIT(7) leaves 0x88. Writing 0x88 at power-off enables the charge LED while still powering off the PMIC.

Makes sense.

Quoted 20 lines
---
 drivers/mfd/axp20x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/axp20x.c +1 -2
index 679364189..50df66de2 100644
@@ -1253,7 +1253,7 @@ static int axp20x_power_off(struct sys_off_data *data)
                break;
        }
 
-       regmap_write(axp20x->regmap, shutdown_reg, AXP20X_OFF);
+       regmap_set_bits(axp20x->regmap, shutdown_reg, AXP20X_OFF);
 
        /* Give capacitors etc. time to drain to avoid kernel panic msg. */
        mdelay(500);
--

2.50.1 (Apple Git-155)

maintainer Applied
#2 lore raw

Re: (subset) [PATCH] mfd: axp20x: preserve other control bits when powering off

In reply to Oleg Proshkin
Quoted 4 lines · Oleg Proshkin

axp20x_power_off() triggers shutdown by writing AXP20X_OFF (BIT(7)) to the power-off control register with regmap_write(), which rewrites the whole register and clears other control bits in it.

Quoted 8 lines

On the AXP221/AXP223 (and the register-compatible AXP228) - that register also holds the CHGLED auto-control bit.
Clearing it during an orderly shutdown disables the hardware charge indicator, so the charge LED stays dark while the board is powered off and charging. Other variants keep unrelated configuration in the same register too.

[...]

Applied, thanks!

[1/1] mfd: axp20x: preserve other control bits when powering off

      commit: c5fda2d006d3f77d3788823c4f875c745e355451

--
Lee Jones [李琼斯]