diff mbox series

[v2] mfd: tps65910: Correct power-off programming sequence

Message ID 20200524192643.18207-1-digetx@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] mfd: tps65910: Correct power-off programming sequence | expand

Commit Message

Dmitry Osipenko May 24, 2020, 7:26 p.m. UTC
This patch fixes system shutdown on a devices that use TPS65910 as a
system's power controller. In accordance to the TPS65910 datasheet, the
PMIC's state-machine transitions into the OFF state only when DEV_OFF
bit of DEVCTRL_REG is set. The ON / SLEEP states also should be cleared,
otherwise PMIC won't get into a proper state on shutdown. Devices like
Nexus 7 tablet and Ouya game console are now shutting down properly.

Tested-by: Zack Pearsall <zpearsall@yahoo.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---

Changelog:

v2: - Now using a single tps65910_reg_update_bits() instead of set+clear.
      Thanks to Michał Mirosław for the suggestion.

 drivers/mfd/tps65910.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Lee Jones May 26, 2020, 8:24 a.m. UTC | #1
On Sun, 24 May 2020, Dmitry Osipenko wrote:

> This patch fixes system shutdown on a devices that use TPS65910 as a
> system's power controller. In accordance to the TPS65910 datasheet, the
> PMIC's state-machine transitions into the OFF state only when DEV_OFF
> bit of DEVCTRL_REG is set. The ON / SLEEP states also should be cleared,
> otherwise PMIC won't get into a proper state on shutdown. Devices like
> Nexus 7 tablet and Ouya game console are now shutting down properly.
> 
> Tested-by: Zack Pearsall <zpearsall@yahoo.com>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> 
> Changelog:
> 
> v2: - Now using a single tps65910_reg_update_bits() instead of set+clear.
>       Thanks to Michał Mirosław for the suggestion.

Michał should review.

>  drivers/mfd/tps65910.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index 11959021b50a..3f4483dec871 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -440,8 +440,13 @@ static void tps65910_power_off(void)
>  			DEVCTRL_PWR_OFF_MASK) < 0)
>  		return;
>  
> -	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
> -			DEVCTRL_DEV_ON_MASK);
> +	if (tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
> +			DEVCTRL_DEV_SLP_MASK) < 0)
> +		return;
> +
> +	tps65910_reg_update_bits(tps65910, TPS65910_DEVCTRL,
> +				 DEVCTRL_DEV_OFF_MASK | DEVCTRL_DEV_ON_MASK,
> +				 DEVCTRL_DEV_OFF_MASK);
>  }
>  
>  static int tps65910_i2c_probe(struct i2c_client *i2c,
Michał Mirosław May 26, 2020, 3:01 p.m. UTC | #2
On Sun, May 24, 2020 at 10:26:43PM +0300, Dmitry Osipenko wrote:
> This patch fixes system shutdown on a devices that use TPS65910 as a
> system's power controller. In accordance to the TPS65910 datasheet, the
> PMIC's state-machine transitions into the OFF state only when DEV_OFF
> bit of DEVCTRL_REG is set. The ON / SLEEP states also should be cleared,
> otherwise PMIC won't get into a proper state on shutdown. Devices like
> Nexus 7 tablet and Ouya game console are now shutting down properly.

The datasheets of 65910 and 65911 say that ON and SLP bits are cleared
during OFF state. But I guess the hardware might work differently.

[...]
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -440,8 +440,13 @@ static void tps65910_power_off(void)
>  			DEVCTRL_PWR_OFF_MASK) < 0)
>  		return;
>  
> -	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
> -			DEVCTRL_DEV_ON_MASK);
> +	if (tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
> +			DEVCTRL_DEV_SLP_MASK) < 0)
> +		return;
> +
> +	tps65910_reg_update_bits(tps65910, TPS65910_DEVCTRL,
> +				 DEVCTRL_DEV_OFF_MASK | DEVCTRL_DEV_ON_MASK,
> +				 DEVCTRL_DEV_OFF_MASK);
>  }

There is tps65910_reg_set_bits() at the start of function. I guess it
doesn't work if your changes are needed. Maybe you can remove it?

I would also include your observations about the chip's behaviour in the
commit message so it doesn't get "fixed" later.

Best Regards,
Michał Mirosław
Dmitry Osipenko May 27, 2020, 3:03 p.m. UTC | #3
26.05.2020 18:01, Michał Mirosław пишет:
> On Sun, May 24, 2020 at 10:26:43PM +0300, Dmitry Osipenko wrote:
>> This patch fixes system shutdown on a devices that use TPS65910 as a
>> system's power controller. In accordance to the TPS65910 datasheet, the
>> PMIC's state-machine transitions into the OFF state only when DEV_OFF
>> bit of DEVCTRL_REG is set. The ON / SLEEP states also should be cleared,
>> otherwise PMIC won't get into a proper state on shutdown. Devices like
>> Nexus 7 tablet and Ouya game console are now shutting down properly.
> 
> The datasheets of 65910 and 65911 say that ON and SLP bits are cleared
> during OFF state. But I guess the hardware might work differently.

Indeed, sounds like we can remove the SLP bit-clearing safely. IIUC,
both tps65910 and tps65911 are nearly the same in regards to the
power-off programming, tps65911 only supports an additional (sequential)
power-off mode.

I'm not sure whether we've tried to remove the SLP bit-clearing before,
will be interesting to try.

> [...]
>> --- a/drivers/mfd/tps65910.c
>> +++ b/drivers/mfd/tps65910.c
>> @@ -440,8 +440,13 @@ static void tps65910_power_off(void)
>>  			DEVCTRL_PWR_OFF_MASK) < 0)
>>  		return;
>>  
>> -	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
>> -			DEVCTRL_DEV_ON_MASK);
>> +	if (tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
>> +			DEVCTRL_DEV_SLP_MASK) < 0)
>> +		return;
>> +
>> +	tps65910_reg_update_bits(tps65910, TPS65910_DEVCTRL,
>> +				 DEVCTRL_DEV_OFF_MASK | DEVCTRL_DEV_ON_MASK,
>> +				 DEVCTRL_DEV_OFF_MASK);
>>  }
> 
> There is tps65910_reg_set_bits() at the start of function. I guess it
> doesn't work if your changes are needed. Maybe you can remove it?

It enables the "sequential power-off, reverse of power-on sequence",
like datasheet says. I think it works and we actually need that PWR_OFF
bit to be set separately, before setting the DEV_OFF bit.

> I would also include your observations about the chip's behaviour in the
> commit message so it doesn't get "fixed" later.

I'll add a clarifying comment about it in v3, thank you for the suggestions.
diff mbox series

Patch

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 11959021b50a..3f4483dec871 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -440,8 +440,13 @@  static void tps65910_power_off(void)
 			DEVCTRL_PWR_OFF_MASK) < 0)
 		return;
 
-	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
-			DEVCTRL_DEV_ON_MASK);
+	if (tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
+			DEVCTRL_DEV_SLP_MASK) < 0)
+		return;
+
+	tps65910_reg_update_bits(tps65910, TPS65910_DEVCTRL,
+				 DEVCTRL_DEV_OFF_MASK | DEVCTRL_DEV_ON_MASK,
+				 DEVCTRL_DEV_OFF_MASK);
 }
 
 static int tps65910_i2c_probe(struct i2c_client *i2c,