]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mfd: stpmic1: Attempt system shutdown twice in case PMIC is confused
authorMarek Vasut <marex@nabladev.com>
Thu, 22 Jan 2026 11:13:21 +0000 (12:13 +0100)
committerLee Jones <lee@kernel.org>
Wed, 25 Mar 2026 12:44:46 +0000 (12:44 +0000)
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: 6e9df38f359a ("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>
drivers/mfd/stpmic1.c

index 081827bc05961ce3aa6beca8a801ad0417b62915..7c677b0344c604a265f9712da9ce657504385672 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <dt-bindings/mfd/st,stpmic1.h>
 
+#define STPMIC1_MAX_RETRIES 2
+
 #define STPMIC1_MAIN_IRQ 0
 
 static const struct regmap_range stpmic1_readable_ranges[] = {
@@ -121,9 +123,23 @@ static const struct regmap_irq_chip stpmic1_regmap_irq_chip = {
 static int stpmic1_power_off(struct sys_off_data *data)
 {
        struct stpmic1 *ddata = data->cb_data;
+       int ret;
+
+       /*
+        * 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.
+        */
+       for (int retries = 0; retries < STPMIC1_MAX_RETRIES; retries++) {
+               ret = regmap_update_bits(ddata->regmap, MAIN_CR, SOFTWARE_SWITCH_OFF,
+                                        SOFTWARE_SWITCH_OFF);
+               if (!ret)
+                       return NOTIFY_DONE;
+       }
 
-       regmap_update_bits(ddata->regmap, MAIN_CR,
-                          SOFTWARE_SWITCH_OFF, SOFTWARE_SWITCH_OFF);
+       dev_err(ddata->dev, "Failed to access PMIC I2C bus (%d)\n", ret);
 
        return NOTIFY_DONE;
 }