mfd: stpmic1: Attempt system shutdown twice in case PMIC is confused
Subsystems (2)
PATCH v2 1/1 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: Lee Jones <[email protected]>
Cc: Pascal PAILLET-LME <[email protected]>
Cc: Paul Cercueil <[email protected]>
Cc: Sean Nyekjaer <[email protected]>
Cc: [email protected]
---
V2: - Use a retry loop
- Cc stable
--- drivers/mfd/stpmic1.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/mfd/stpmic1.c +18 -3
@@ -121,9 +121,24 @@ 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; - -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +int i, ret; + +for (i =0 ; i <2 ; i++) { + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF , +SOFTWARE_SWITCH_OFF ); +if (!ret) +return NOTIFY_DONE ; + +/* +* 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. +*/ +if (i) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret); + }return NOTIFY_DONE ; }
Signature · 1 line
2.51.0
Lee Jones
maintainerQuoted 27 lines · Marek Vasut
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.Fixes 6e9df38f359a ("mfd: stpmic1: Add PMIC poweroff via sys-off handler")Signed-off-by Marek Vasut <[email protected]>---
Cc: Lee Jones <[email protected]>
Cc: Pascal PAILLET-LME <[email protected]>
Cc: Paul Cercueil <[email protected]>
Cc: Sean Nyekjaer <[email protected]>
Cc: [email protected]
---
V2: - Use a retry loop
- Cc stable--- drivers/mfd/stpmic1.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)drivers/mfd/stpmic1.c +0
-0
drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 126
Quoted 9 lines
drivers/mfd/stpmic1.c +3
-3@@ -121,9 +121,24 @@ 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; - -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +int i, ret; + +for (i =0 ; i <2 ; i++) {
for (int retries = 0; retries < MAX_RETIRES; retries++)
Quoted 4 lines
drivers/mfd/stpmic1.c +4
-0+ ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF , +SOFTWARE_SWITCH_OFF ); +if (!ret) +return NOTIFY_DONE ;
drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 140
Quoted 10 lines
drivers/mfd/stpmic1.c +10
-0+ +/* +* 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. +*/ +if (i) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret);
Users aren't going to care if this works on the first or second attempt.
I would only issue the error once we've given up.
No return error in the fail case?
define NOTIFY_DONE 0x0000 /* Don't care */
Harsh!
Quoted 7 lines
drivers/mfd/stpmic1.c +1
-0+ }return NOTIFY_DONE ; }Signature · 1 line
2.51.0
Signature · 1 line
Lee Jones [李琼斯]
Quoted 31 lines · Lee Jones
drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 126
Quoted 11 lines
+++
b/drivers/mfd/stpmic1.cdrivers/mfd/stpmic1.c +3
-3@@ -121,9 +121,24 @@ 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; - -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +int i, ret; + +for (i =0 ; i <2 ; i++) {for (int retries = 0; retries <
MAX_RETIRES; retries++)Quoted 4 lines
drivers/mfd/stpmic1.c +4
-0+ ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF , +SOFTWARE_SWITCH_OFF ); +if (!ret) +return NOTIFY_DONE ;drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 140
Quoted 10 lines
drivers/mfd/stpmic1.c +10
-0+ +/* +* 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. +*/ +if (i) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret);Users aren't going to care if this works on the first or second attempt.
Quoted 7 lines
I would only issue the error once we've given up.
No return error in the fail case?
define NOTIFY_DONE 0x0000 /* Don't care */Harsh!
That is the only option, because there may be additional shutdown notifiers and those should also be run.
The rest is fixed in V3.