Skip to content

Commit ffdc5c5

Browse files
Marek Vasutlag-linaro
authored andcommitted
mfd: stpmic1: Attempt system shutdown twice in case PMIC is confused
Attempt to shut down again, in case the first attempt failed. The STPMIC1 might get confused and the first regmap_update_bits() returns with -ETIMEDOUT / -110 . If that or similar transient failure occurs, try to shut down again. If the second attempt fails, there is some bigger problem, report it to user. Cc: stable@vger.kernel.org Fixes: 6e9df38 ("mfd: stpmic1: Add PMIC poweroff via sys-off handler") Signed-off-by: Marek Vasut <marex@nabladev.com> Link: https://patch.msgid.link/20260122111423.62591-1-marex@nabladev.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent a5a65a7 commit ffdc5c5

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

drivers/mfd/stpmic1.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <dt-bindings/mfd/st,stpmic1.h>
1818

19+
#define STPMIC1_MAX_RETRIES 2
20+
1921
#define STPMIC1_MAIN_IRQ 0
2022

2123
static const struct regmap_range stpmic1_readable_ranges[] = {
@@ -121,9 +123,23 @@ static const struct regmap_irq_chip stpmic1_regmap_irq_chip = {
121123
static int stpmic1_power_off(struct sys_off_data *data)
122124
{
123125
struct stpmic1 *ddata = data->cb_data;
126+
int ret;
127+
128+
/*
129+
* Attempt to shut down again, in case the first attempt failed.
130+
* The STPMIC1 might get confused and the first regmap_update_bits()
131+
* returns with -ETIMEDOUT / -110 . If that or similar transient
132+
* failure occurs, try to shut down again. If the second attempt
133+
* fails, there is some bigger problem, report it to user.
134+
*/
135+
for (int retries = 0; retries < STPMIC1_MAX_RETRIES; retries++) {
136+
ret = regmap_update_bits(ddata->regmap, MAIN_CR, SOFTWARE_SWITCH_OFF,
137+
SOFTWARE_SWITCH_OFF);
138+
if (!ret)
139+
return NOTIFY_DONE;
140+
}
124141

125-
regmap_update_bits(ddata->regmap, MAIN_CR,
126-
SOFTWARE_SWITCH_OFF, SOFTWARE_SWITCH_OFF);
142+
dev_err(ddata->dev, "Failed to access PMIC I2C bus (%d)\n", ret);
127143

128144
return NOTIFY_DONE;
129145
}

0 commit comments

Comments
 (0)