mfd: stpmic1: Attempt system shutdown twice in case PMIC is confused
PATCH 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]
--- drivers/mfd/stpmic1.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/mfd/stpmic1.c +16 -2
@@ -121,9 +121,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; + + 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. +*/ + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +if (ret) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret); -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF );return NOTIFY_DONE ; }
Signature · 1 line
2.51.0
Quoted 5 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.
I don't think I have ever seen my devices fail to shutdown. Have you ever seen the second call fail?
Quoted 3 lines
Fixes 6e9df38f359a ("mfd: stpmic1: Add PMIC poweroff via sys-off handler")Signed-off-by Marek Vasut <[email protected]>
Quoted 43 lines
---
Cc: Lee Jones <[email protected]>
Cc: Pascal PAILLET-LME <[email protected]>
Cc: Paul Cercueil <[email protected]>
Cc: Sean Nyekjaer <[email protected]>
Cc: [email protected]--- drivers/mfd/stpmic1.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/mfd/stpmic1.c +16
-3@@ -121,9 +121,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; + + 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. +*/ + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +if (ret) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret); -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF );return NOTIFY_DONE ; } --2.51.0
Quoted 9 lines · Sean Nyekjaer
Quoted 5 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.I don't think I have ever seen my devices fail to shutdown. Have you ever seen the second call fail?
I have sporadically seen the first call fail with timeout, not the second one yet. If the second call fails, I think we have a real bad hardware problem.
Maybe these issues are hidden on devices which use SCMI too, so they never get properly fixed in the direct hardware access kernel drivers anymore, sigh.
Lee Jones
maintainerQuoted 30 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]--- drivers/mfd/stpmic1.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/mfd/stpmic1.c +4
-0@@ -121,9 +121,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; + + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF ); +if (!ret)
drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 137
Quoted 10 lines
drivers/mfd/stpmic1.c +10
-0+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. +*/ + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF );
I think it would be better to put it into a loop with 2 retries.
Quoted 11 lines
drivers/mfd/stpmic1.c +2
-2+if (ret) +dev_err (ddata->dev,"Failed to access PMIC I2C bus (%d)\n" , ret); -regmap_update_bits (ddata->regmap,MAIN_CR , -SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF );return NOTIFY_DONE ; }Signature · 1 line
2.51.0
Signature · 1 line
Lee Jones [李琼斯]
Quoted 36 lines · Lee Jones
Quoted 34 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]--- drivers/mfd/stpmic1.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/mfd/stpmic1.c +8
-0@@ -121,9 +121,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; + + 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.
Quoted 8 lines
drivers/mfd/stpmic1.c static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { · line 137
Quoted 6 lines
drivers/mfd/stpmic1.c +6
-0+* 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. +*/ + ret =regmap_update_bits (ddata->regmap,MAIN_CR ,SOFTWARE_SWITCH_OFF ,SOFTWARE_SWITCH_OFF );I think it would be better to put it into a loop with 2 retries.
I sent V2 like that now.