linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
@ 2023-05-11 12:21 Jerome Neanne
  2023-05-17  6:25 ` Tony Lindgren
  2023-05-25 10:48 ` Lee Jones
  0 siblings, 2 replies; 9+ messages in thread
From: Jerome Neanne @ 2023-05-11 12:21 UTC (permalink / raw)
  To: tony, lee; +Cc: linux-omap, linux-kernel, khilman, nm, afd, msp, Jerome Neanne

Use new API for power-off mode support:
Link: https://lwn.net/Articles/894511/
Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/

sys-off API allows support of shutdown handler and restart handler.

Shutdown was not supported before that enhancement.
This is required for platform that are not using PSCI.

Test:
- restart:
  # reboot
  Default is cold reset:
  # cat /sys/kernel/reboot/mode
  Switch boot mode to warm reset:
  # echo warm > /sys/kernel/reboot/mode
- power-off:
  # halt

Tested on AM62-LP-SK board.

Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
Suggested-by: Andrew Davis <afd@ti.com>
Reviewed-by: Andrew Davis <afd@ti.com>
---

Notes:
    Change-log v2 to v1
    v1: Link: https://lore.kernel.org/all/20230203140150.13071-1-jneanne@baylibre.com/
    Andrew Davis Review:
    - Use new helpers devm_register_restart_handler and devm_register_power_off_handler
    Vignesh Raghavendra:
    - Fix typo on board name in commit message

 drivers/mfd/tps65219.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
index 0e402fda206b..5115d0a66701 100644
--- a/drivers/mfd/tps65219.c
+++ b/drivers/mfd/tps65219.c
@@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
 				  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
 }
 
-static int tps65219_restart(struct notifier_block *this,
-			    unsigned long reboot_mode, void *cmd)
+static int tps65219_soft_shutdown(struct tps65219 *tps)
 {
-	struct tps65219 *tps;
+	return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
+				  TPS65219_MFP_I2C_OFF_REQ_MASK,
+				  TPS65219_MFP_I2C_OFF_REQ_MASK);
+}
 
-	tps = container_of(this, struct tps65219, nb);
+static int tps65219_power_off_handler(struct sys_off_data *data)
+{
+	tps65219_soft_shutdown(data->cb_data);
+	return NOTIFY_DONE;
+}
 
+static int tps65219_restart(struct tps65219 *tps,
+			    unsigned long reboot_mode)
+{
 	if (reboot_mode == REBOOT_WARM)
 		tps65219_warm_reset(tps);
 	else
 		tps65219_cold_reset(tps);
-
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block pmic_rst_restart_nb = {
-	.notifier_call = tps65219_restart,
-	.priority = 200,
-};
+static int tps65219_restart_handler(struct sys_off_data *data)
+{
+	tps65219_restart(data->cb_data, data->mode);
+	return NOTIFY_DONE;
+}
 
 static const struct resource tps65219_pwrbutton_resources[] = {
 	DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
@@ -269,13 +278,23 @@ static int tps65219_probe(struct i2c_client *client)
 		}
 	}
 
-	tps->nb = pmic_rst_restart_nb;
-	ret = register_restart_handler(&tps->nb);
+	ret = devm_register_restart_handler(tps->dev,
+					    tps65219_restart_handler,
+					    tps);
+
 	if (ret) {
 		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
 		return ret;
 	}
 
+	ret = devm_register_power_off_handler(tps->dev,
+					      tps65219_power_off_handler,
+					      tps);
+	if (ret) {
+		dev_err(tps->dev, "failed to register power-off handler: %d\n",
+			ret);
+		return ret;
+	}
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-05-11 12:21 [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API Jerome Neanne
@ 2023-05-17  6:25 ` Tony Lindgren
  2023-05-25 10:48 ` Lee Jones
  1 sibling, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2023-05-17  6:25 UTC (permalink / raw)
  To: Jerome Neanne; +Cc: lee, linux-omap, linux-kernel, khilman, nm, afd, msp

* Jerome Neanne <jneanne@baylibre.com> [230511 12:21]:
> Use new API for power-off mode support:
> Link: https://lwn.net/Articles/894511/
> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
> 
> sys-off API allows support of shutdown handler and restart handler.

Reviewed-by: Tony Lindgren <tony@atomide.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-05-11 12:21 [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API Jerome Neanne
  2023-05-17  6:25 ` Tony Lindgren
@ 2023-05-25 10:48 ` Lee Jones
  1 sibling, 0 replies; 9+ messages in thread
From: Lee Jones @ 2023-05-25 10:48 UTC (permalink / raw)
  To: Jerome Neanne; +Cc: tony, linux-omap, linux-kernel, khilman, nm, afd, msp

On Thu, 11 May 2023, Jerome Neanne wrote:

> Use new API for power-off mode support:
> Link: https://lwn.net/Articles/894511/
> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
> 
> sys-off API allows support of shutdown handler and restart handler.
> 
> Shutdown was not supported before that enhancement.
> This is required for platform that are not using PSCI.
> 
> Test:
> - restart:
>   # reboot
>   Default is cold reset:
>   # cat /sys/kernel/reboot/mode
>   Switch boot mode to warm reset:
>   # echo warm > /sys/kernel/reboot/mode
> - power-off:
>   # halt
> 
> Tested on AM62-LP-SK board.
> 
> Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
> Suggested-by: Andrew Davis <afd@ti.com>
> Reviewed-by: Andrew Davis <afd@ti.com>
> ---
> 
> Notes:
>     Change-log v2 to v1
>     v1: Link: https://lore.kernel.org/all/20230203140150.13071-1-jneanne@baylibre.com/
>     Andrew Davis Review:
>     - Use new helpers devm_register_restart_handler and devm_register_power_off_handler
>     Vignesh Raghavendra:
>     - Fix typo on board name in commit message
> 
>  drivers/mfd/tps65219.c | 41 ++++++++++++++++++++++++++++++-----------
>  1 file changed, 30 insertions(+), 11 deletions(-)

Couple of nits.
 
> diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
> index 0e402fda206b..5115d0a66701 100644
> --- a/drivers/mfd/tps65219.c
> +++ b/drivers/mfd/tps65219.c
> @@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
>  				  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
>  }
>  
> -static int tps65219_restart(struct notifier_block *this,
> -			    unsigned long reboot_mode, void *cmd)
> +static int tps65219_soft_shutdown(struct tps65219 *tps)
>  {
> -	struct tps65219 *tps;
> +	return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
> +				  TPS65219_MFP_I2C_OFF_REQ_MASK,
> +				  TPS65219_MFP_I2C_OFF_REQ_MASK);
> +}
>  
> -	tps = container_of(this, struct tps65219, nb);
> +static int tps65219_power_off_handler(struct sys_off_data *data)
> +{
> +	tps65219_soft_shutdown(data->cb_data);
> +	return NOTIFY_DONE;
> +}
>  
> +static int tps65219_restart(struct tps65219 *tps,
> +			    unsigned long reboot_mode)

Why the line-wrap?

> +{
>  	if (reboot_mode == REBOOT_WARM)
>  		tps65219_warm_reset(tps);
>  	else
>  		tps65219_cold_reset(tps);
> -

This has nothing to do with the patch, and I liked it better before.

>  	return NOTIFY_DONE;
>  }
>  
> -static struct notifier_block pmic_rst_restart_nb = {
> -	.notifier_call = tps65219_restart,
> -	.priority = 200,
> -};
> +static int tps65219_restart_handler(struct sys_off_data *data)
> +{
> +	tps65219_restart(data->cb_data, data->mode);
> +	return NOTIFY_DONE;
> +}
>  
>  static const struct resource tps65219_pwrbutton_resources[] = {
>  	DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
> @@ -269,13 +278,23 @@ static int tps65219_probe(struct i2c_client *client)
>  		}
>  	}
>  
> -	tps->nb = pmic_rst_restart_nb;
> -	ret = register_restart_handler(&tps->nb);
> +	ret = devm_register_restart_handler(tps->dev,
> +					    tps65219_restart_handler,
> +					    tps);
> +
>  	if (ret) {
>  		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
>  		return ret;
>  	}
>  
> +	ret = devm_register_power_off_handler(tps->dev,
> +					      tps65219_power_off_handler,
> +					      tps);
> +	if (ret) {
> +		dev_err(tps->dev, "failed to register power-off handler: %d\n",
> +			ret);

I wouldn't wrap here either to be honest.

checkpatch.pl now complains at 100-chars.

> +		return ret;
> +	}
>  	return 0;
>  }
>  
> -- 
> 2.34.1
> 

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-03-01 16:35   ` Andrew Davis
@ 2023-03-03 15:12     ` jerome Neanne
  0 siblings, 0 replies; 9+ messages in thread
From: jerome Neanne @ 2023-03-03 15:12 UTC (permalink / raw)
  To: Andrew Davis, Lee Jones; +Cc: tony, linux-omap, linux-kernel, khilman, nm, msp



On 01/03/2023 17:35, Andrew Davis wrote:
> On 3/1/23 10:07 AM, Lee Jones wrote:
>> On Fri, 03 Feb 2023, Jerome Neanne wrote:
>>
>>> Use new API for power-off mode support:
>>> Link: https://lwn.net/Articles/894511/
>>> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
>>>
>>> sys-off API allows support of shutdown handler and restart handler.
>>>
>>> Shutdown was not supported before that enhancement.
>>> This is required for platform that are not using PSCI.
>>>
> 
> Not sure what platform doesn't have PSCI off, since you tested on
> AM62-SK I'm guessing you manually disabled the PSCI off for testing?
> 
> Anyway I don't see any huge issues with the code itself, small comment 
> below.
> 
>>> Test:
>>> - restart:
>>>    # reboot
>>>    Default is cold reset:
>>>    # cat /sys/kernel/reboot/mode
>>>    Switch boot mode to warm reset:
>>>    # echo warm > /sys/kernel/reboot/mode
>>> - power-off:
>>>    # halt
>>>
>>> Tested on AM62-SP-SK board.
>>>
>>> Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
>>> Suggested-by: Andrew Davis <afd@ti.com>
>>
>> A review from Andrew would be helpful here.
>>
>>> ---
>>>   drivers/mfd/tps65219.c | 45 +++++++++++++++++++++++++++++++-----------
>>>   1 file changed, 34 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
>>> index 0e402fda206b..c134f3f6e202 100644
>>> --- a/drivers/mfd/tps65219.c
>>> +++ b/drivers/mfd/tps65219.c
>>> @@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
>>>                     TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
>>>   }
>>> -static int tps65219_restart(struct notifier_block *this,
>>> -                unsigned long reboot_mode, void *cmd)
>>> +static int tps65219_soft_shutdown(struct tps65219 *tps)
>>>   {
>>> -    struct tps65219 *tps;
>>> +    return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
>>> +                  TPS65219_MFP_I2C_OFF_REQ_MASK,
>>> +                  TPS65219_MFP_I2C_OFF_REQ_MASK);
>>> +}
>>> -    tps = container_of(this, struct tps65219, nb);
>>> +static int tps65219_power_off_handler(struct sys_off_data *data)
>>> +{
>>> +    tps65219_soft_shutdown(data->cb_data);
>>> +    return NOTIFY_DONE;
>>> +}
>>> +static int tps65219_restart(struct tps65219 *tps,
>>> +                unsigned long reboot_mode)
>>> +{
>>>       if (reboot_mode == REBOOT_WARM)
>>>           tps65219_warm_reset(tps);
>>>       else
>>>           tps65219_cold_reset(tps);
>>> -
>>>       return NOTIFY_DONE;
>>>   }
>>> -static struct notifier_block pmic_rst_restart_nb = {
>>> -    .notifier_call = tps65219_restart,
>>> -    .priority = 200,
>>> -};
>>> +static int tps65219_restart_handler(struct sys_off_data *data)
>>> +{
>>> +    tps65219_restart(data->cb_data, data->mode);
>>> +    return NOTIFY_DONE;
>>> +}
>>>   static const struct resource tps65219_pwrbutton_resources[] = {
>>>       DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, 
>>> "falling"),
>>> @@ -269,13 +278,27 @@ static int tps65219_probe(struct i2c_client 
>>> *client)
>>>           }
>>>       }
>>> -    tps->nb = pmic_rst_restart_nb;
>>> -    ret = register_restart_handler(&tps->nb);
>>> +    ret = devm_register_sys_off_handler(tps->dev,
>>> +                        SYS_OFF_MODE_RESTART,
>>> +                        SYS_OFF_PRIO_HIGH,
> 
> Why not default prio? SYS_OFF_PRIO_DEFAULT
I'm not completely clear about PRIO recommendations. Will follow your 
suggestion.
> 
> Then you can use this new helper devm_register_restart_handler()
Sure!
> 
>>> +                        tps65219_restart_handler,
>>> +                        tps);
>>> +
>>>       if (ret) {
>>>           dev_err(tps->dev, "cannot register restart handler, %d\n", 
>>> ret);
>>>           return ret;
>>>       }
>>> +    ret = devm_register_sys_off_handler(tps->dev,
>>> +                        SYS_OFF_MODE_POWER_OFF,
>>> +                        SYS_OFF_PRIO_DEFAULT,
>>> +                        tps65219_power_off_handler,
>>> +                        tps);
> 
> 
> devm_register_power_off_handler()?
> 
Oh yes, right, this is solving the PRIO question by construction. This 
is definitely a better option
> Otherwise I see no major issues,
> 
> Reviewed-by: Andrew Davis <afd@ti.com>
> 
> Andrew
> 
>>> +    if (ret) {
>>> +        dev_err(tps->dev, "failed to register sys-off handler: %d\n",
>>> +            ret);
>>> +        return ret;
>>> +    }
>>>       return 0;
>>>   }
>>> -- 
>>> 2.34.1
>>>
>>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-03-03  5:36 ` Vignesh Raghavendra
@ 2023-03-03  9:48   ` jerome Neanne
  0 siblings, 0 replies; 9+ messages in thread
From: jerome Neanne @ 2023-03-03  9:48 UTC (permalink / raw)
  To: Vignesh Raghavendra, tony, lee
  Cc: linux-omap, linux-kernel, khilman, nm, afd, msp



On 03/03/2023 06:36, Vignesh Raghavendra wrote:
> 
> 
> On 03/02/23 19:31, Jerome Neanne wrote:
>> Use new API for power-off mode support:
>> Link: https://lwn.net/Articles/894511/
>> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
>>
>> sys-off API allows support of shutdown handler and restart handler.
>>
>> Shutdown was not supported before that enhancement.
>> This is required for platform that are not using PSCI.
>>
>> Test:
>> - restart:
>>    # reboot
>>    Default is cold reset:
>>    # cat /sys/kernel/reboot/mode
>>    Switch boot mode to warm reset:
>>    # echo warm > /sys/kernel/reboot/mode
>> - power-off:
>>    # halt
>>
>> Tested on AM62-SP-SK board.
>>
> 
> There is no -SP-SK that I am aware of.. Do you mean -LP-SK?
You are right, this is a typo. It's LP-SK
> [...]
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-02-03 14:01 Jerome Neanne
  2023-03-01 16:07 ` Lee Jones
@ 2023-03-03  5:36 ` Vignesh Raghavendra
  2023-03-03  9:48   ` jerome Neanne
  1 sibling, 1 reply; 9+ messages in thread
From: Vignesh Raghavendra @ 2023-03-03  5:36 UTC (permalink / raw)
  To: Jerome Neanne, tony, lee; +Cc: linux-omap, linux-kernel, khilman, nm, afd, msp



On 03/02/23 19:31, Jerome Neanne wrote:
> Use new API for power-off mode support:
> Link: https://lwn.net/Articles/894511/
> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
> 
> sys-off API allows support of shutdown handler and restart handler.
> 
> Shutdown was not supported before that enhancement.
> This is required for platform that are not using PSCI.
> 
> Test:
> - restart:
>   # reboot
>   Default is cold reset:
>   # cat /sys/kernel/reboot/mode
>   Switch boot mode to warm reset:
>   # echo warm > /sys/kernel/reboot/mode
> - power-off:
>   # halt
> 
> Tested on AM62-SP-SK board.
> 

There is no -SP-SK that I am aware of.. Do you mean -LP-SK?
[...]

-- 
Regards
Vignesh

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-03-01 16:07 ` Lee Jones
@ 2023-03-01 16:35   ` Andrew Davis
  2023-03-03 15:12     ` jerome Neanne
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Davis @ 2023-03-01 16:35 UTC (permalink / raw)
  To: Lee Jones, Jerome Neanne; +Cc: tony, linux-omap, linux-kernel, khilman, nm, msp

On 3/1/23 10:07 AM, Lee Jones wrote:
> On Fri, 03 Feb 2023, Jerome Neanne wrote:
> 
>> Use new API for power-off mode support:
>> Link: https://lwn.net/Articles/894511/
>> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
>>
>> sys-off API allows support of shutdown handler and restart handler.
>>
>> Shutdown was not supported before that enhancement.
>> This is required for platform that are not using PSCI.
>>

Not sure what platform doesn't have PSCI off, since you tested on
AM62-SK I'm guessing you manually disabled the PSCI off for testing?

Anyway I don't see any huge issues with the code itself, small comment below.

>> Test:
>> - restart:
>>    # reboot
>>    Default is cold reset:
>>    # cat /sys/kernel/reboot/mode
>>    Switch boot mode to warm reset:
>>    # echo warm > /sys/kernel/reboot/mode
>> - power-off:
>>    # halt
>>
>> Tested on AM62-SP-SK board.
>>
>> Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
>> Suggested-by: Andrew Davis <afd@ti.com>
> 
> A review from Andrew would be helpful here.
> 
>> ---
>>   drivers/mfd/tps65219.c | 45 +++++++++++++++++++++++++++++++-----------
>>   1 file changed, 34 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
>> index 0e402fda206b..c134f3f6e202 100644
>> --- a/drivers/mfd/tps65219.c
>> +++ b/drivers/mfd/tps65219.c
>> @@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
>>   				  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
>>   }
>>   
>> -static int tps65219_restart(struct notifier_block *this,
>> -			    unsigned long reboot_mode, void *cmd)
>> +static int tps65219_soft_shutdown(struct tps65219 *tps)
>>   {
>> -	struct tps65219 *tps;
>> +	return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
>> +				  TPS65219_MFP_I2C_OFF_REQ_MASK,
>> +				  TPS65219_MFP_I2C_OFF_REQ_MASK);
>> +}
>>   
>> -	tps = container_of(this, struct tps65219, nb);
>> +static int tps65219_power_off_handler(struct sys_off_data *data)
>> +{
>> +	tps65219_soft_shutdown(data->cb_data);
>> +	return NOTIFY_DONE;
>> +}
>>   
>> +static int tps65219_restart(struct tps65219 *tps,
>> +			    unsigned long reboot_mode)
>> +{
>>   	if (reboot_mode == REBOOT_WARM)
>>   		tps65219_warm_reset(tps);
>>   	else
>>   		tps65219_cold_reset(tps);
>> -
>>   	return NOTIFY_DONE;
>>   }
>>   
>> -static struct notifier_block pmic_rst_restart_nb = {
>> -	.notifier_call = tps65219_restart,
>> -	.priority = 200,
>> -};
>> +static int tps65219_restart_handler(struct sys_off_data *data)
>> +{
>> +	tps65219_restart(data->cb_data, data->mode);
>> +	return NOTIFY_DONE;
>> +}
>>   
>>   static const struct resource tps65219_pwrbutton_resources[] = {
>>   	DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
>> @@ -269,13 +278,27 @@ static int tps65219_probe(struct i2c_client *client)
>>   		}
>>   	}
>>   
>> -	tps->nb = pmic_rst_restart_nb;
>> -	ret = register_restart_handler(&tps->nb);
>> +	ret = devm_register_sys_off_handler(tps->dev,
>> +					    SYS_OFF_MODE_RESTART,
>> +					    SYS_OFF_PRIO_HIGH,

Why not default prio? SYS_OFF_PRIO_DEFAULT

Then you can use this new helper devm_register_restart_handler()

>> +					    tps65219_restart_handler,
>> +					    tps);
>> +
>>   	if (ret) {
>>   		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
>>   		return ret;
>>   	}
>>   
>> +	ret = devm_register_sys_off_handler(tps->dev,
>> +					    SYS_OFF_MODE_POWER_OFF,
>> +					    SYS_OFF_PRIO_DEFAULT,
>> +					    tps65219_power_off_handler,
>> +					    tps);


devm_register_power_off_handler()?

Otherwise I see no major issues,

Reviewed-by: Andrew Davis <afd@ti.com>

Andrew

>> +	if (ret) {
>> +		dev_err(tps->dev, "failed to register sys-off handler: %d\n",
>> +			ret);
>> +		return ret;
>> +	}
>>   	return 0;
>>   }
>>   
>> -- 
>> 2.34.1
>>
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
  2023-02-03 14:01 Jerome Neanne
@ 2023-03-01 16:07 ` Lee Jones
  2023-03-01 16:35   ` Andrew Davis
  2023-03-03  5:36 ` Vignesh Raghavendra
  1 sibling, 1 reply; 9+ messages in thread
From: Lee Jones @ 2023-03-01 16:07 UTC (permalink / raw)
  To: Jerome Neanne; +Cc: tony, linux-omap, linux-kernel, khilman, nm, afd, msp

On Fri, 03 Feb 2023, Jerome Neanne wrote:

> Use new API for power-off mode support:
> Link: https://lwn.net/Articles/894511/
> Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/
> 
> sys-off API allows support of shutdown handler and restart handler.
> 
> Shutdown was not supported before that enhancement.
> This is required for platform that are not using PSCI.
> 
> Test:
> - restart:
>   # reboot
>   Default is cold reset:
>   # cat /sys/kernel/reboot/mode
>   Switch boot mode to warm reset:
>   # echo warm > /sys/kernel/reboot/mode
> - power-off:
>   # halt
> 
> Tested on AM62-SP-SK board.
> 
> Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
> Suggested-by: Andrew Davis <afd@ti.com>

A review from Andrew would be helpful here.

> ---
>  drivers/mfd/tps65219.c | 45 +++++++++++++++++++++++++++++++-----------
>  1 file changed, 34 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
> index 0e402fda206b..c134f3f6e202 100644
> --- a/drivers/mfd/tps65219.c
> +++ b/drivers/mfd/tps65219.c
> @@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
>  				  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
>  }
>  
> -static int tps65219_restart(struct notifier_block *this,
> -			    unsigned long reboot_mode, void *cmd)
> +static int tps65219_soft_shutdown(struct tps65219 *tps)
>  {
> -	struct tps65219 *tps;
> +	return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
> +				  TPS65219_MFP_I2C_OFF_REQ_MASK,
> +				  TPS65219_MFP_I2C_OFF_REQ_MASK);
> +}
>  
> -	tps = container_of(this, struct tps65219, nb);
> +static int tps65219_power_off_handler(struct sys_off_data *data)
> +{
> +	tps65219_soft_shutdown(data->cb_data);
> +	return NOTIFY_DONE;
> +}
>  
> +static int tps65219_restart(struct tps65219 *tps,
> +			    unsigned long reboot_mode)
> +{
>  	if (reboot_mode == REBOOT_WARM)
>  		tps65219_warm_reset(tps);
>  	else
>  		tps65219_cold_reset(tps);
> -
>  	return NOTIFY_DONE;
>  }
>  
> -static struct notifier_block pmic_rst_restart_nb = {
> -	.notifier_call = tps65219_restart,
> -	.priority = 200,
> -};
> +static int tps65219_restart_handler(struct sys_off_data *data)
> +{
> +	tps65219_restart(data->cb_data, data->mode);
> +	return NOTIFY_DONE;
> +}
>  
>  static const struct resource tps65219_pwrbutton_resources[] = {
>  	DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
> @@ -269,13 +278,27 @@ static int tps65219_probe(struct i2c_client *client)
>  		}
>  	}
>  
> -	tps->nb = pmic_rst_restart_nb;
> -	ret = register_restart_handler(&tps->nb);
> +	ret = devm_register_sys_off_handler(tps->dev,
> +					    SYS_OFF_MODE_RESTART,
> +					    SYS_OFF_PRIO_HIGH,
> +					    tps65219_restart_handler,
> +					    tps);
> +
>  	if (ret) {
>  		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
>  		return ret;
>  	}
>  
> +	ret = devm_register_sys_off_handler(tps->dev,
> +					    SYS_OFF_MODE_POWER_OFF,
> +					    SYS_OFF_PRIO_DEFAULT,
> +					    tps65219_power_off_handler,
> +					    tps);
> +	if (ret) {
> +		dev_err(tps->dev, "failed to register sys-off handler: %d\n",
> +			ret);
> +		return ret;
> +	}
>  	return 0;
>  }
>  
> -- 
> 2.34.1
> 

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API
@ 2023-02-03 14:01 Jerome Neanne
  2023-03-01 16:07 ` Lee Jones
  2023-03-03  5:36 ` Vignesh Raghavendra
  0 siblings, 2 replies; 9+ messages in thread
From: Jerome Neanne @ 2023-02-03 14:01 UTC (permalink / raw)
  To: tony, lee; +Cc: linux-omap, linux-kernel, khilman, nm, afd, msp, Jerome Neanne

Use new API for power-off mode support:
Link: https://lwn.net/Articles/894511/
Link: https://lore.kernel.org/all/7hfseqa7l0.fsf@baylibre.com/

sys-off API allows support of shutdown handler and restart handler.

Shutdown was not supported before that enhancement.
This is required for platform that are not using PSCI.

Test:
- restart:
  # reboot
  Default is cold reset:
  # cat /sys/kernel/reboot/mode
  Switch boot mode to warm reset:
  # echo warm > /sys/kernel/reboot/mode
- power-off:
  # halt

Tested on AM62-SP-SK board.

Signed-off-by: Jerome Neanne <jneanne@baylibre.com>
Suggested-by: Andrew Davis <afd@ti.com>
---
 drivers/mfd/tps65219.c | 45 +++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
index 0e402fda206b..c134f3f6e202 100644
--- a/drivers/mfd/tps65219.c
+++ b/drivers/mfd/tps65219.c
@@ -25,25 +25,34 @@ static int tps65219_cold_reset(struct tps65219 *tps)
 				  TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
 }
 
-static int tps65219_restart(struct notifier_block *this,
-			    unsigned long reboot_mode, void *cmd)
+static int tps65219_soft_shutdown(struct tps65219 *tps)
 {
-	struct tps65219 *tps;
+	return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
+				  TPS65219_MFP_I2C_OFF_REQ_MASK,
+				  TPS65219_MFP_I2C_OFF_REQ_MASK);
+}
 
-	tps = container_of(this, struct tps65219, nb);
+static int tps65219_power_off_handler(struct sys_off_data *data)
+{
+	tps65219_soft_shutdown(data->cb_data);
+	return NOTIFY_DONE;
+}
 
+static int tps65219_restart(struct tps65219 *tps,
+			    unsigned long reboot_mode)
+{
 	if (reboot_mode == REBOOT_WARM)
 		tps65219_warm_reset(tps);
 	else
 		tps65219_cold_reset(tps);
-
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block pmic_rst_restart_nb = {
-	.notifier_call = tps65219_restart,
-	.priority = 200,
-};
+static int tps65219_restart_handler(struct sys_off_data *data)
+{
+	tps65219_restart(data->cb_data, data->mode);
+	return NOTIFY_DONE;
+}
 
 static const struct resource tps65219_pwrbutton_resources[] = {
 	DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
@@ -269,13 +278,27 @@ static int tps65219_probe(struct i2c_client *client)
 		}
 	}
 
-	tps->nb = pmic_rst_restart_nb;
-	ret = register_restart_handler(&tps->nb);
+	ret = devm_register_sys_off_handler(tps->dev,
+					    SYS_OFF_MODE_RESTART,
+					    SYS_OFF_PRIO_HIGH,
+					    tps65219_restart_handler,
+					    tps);
+
 	if (ret) {
 		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
 		return ret;
 	}
 
+	ret = devm_register_sys_off_handler(tps->dev,
+					    SYS_OFF_MODE_POWER_OFF,
+					    SYS_OFF_PRIO_DEFAULT,
+					    tps65219_power_off_handler,
+					    tps);
+	if (ret) {
+		dev_err(tps->dev, "failed to register sys-off handler: %d\n",
+			ret);
+		return ret;
+	}
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-25 10:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11 12:21 [PATCH] mfd: tps65219: Add support for soft shutdown via sys-off API Jerome Neanne
2023-05-17  6:25 ` Tony Lindgren
2023-05-25 10:48 ` Lee Jones
  -- strict thread matches above, loose matches on Subject: below --
2023-02-03 14:01 Jerome Neanne
2023-03-01 16:07 ` Lee Jones
2023-03-01 16:35   ` Andrew Davis
2023-03-03 15:12     ` jerome Neanne
2023-03-03  5:36 ` Vignesh Raghavendra
2023-03-03  9:48   ` jerome Neanne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).