Skip to content

Commit 3df4c63

Browse files
jneannelag-linaro
authored andcommitted
mfd: tps65219: Add support for soft shutdown via sys-off API
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> Signed-off-by: Lee Jones <lee@kernel.org> Link: https://lore.kernel.org/r/20230608071947.3467751-1-jneanne@baylibre.com
1 parent 95100ed commit 3df4c63

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

drivers/mfd/tps65219.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ static int tps65219_cold_reset(struct tps65219 *tps)
2525
TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK);
2626
}
2727

28-
static int tps65219_restart(struct notifier_block *this,
29-
unsigned long reboot_mode, void *cmd)
28+
static int tps65219_soft_shutdown(struct tps65219 *tps)
3029
{
31-
struct tps65219 *tps;
30+
return regmap_update_bits(tps->regmap, TPS65219_REG_MFP_CTRL,
31+
TPS65219_MFP_I2C_OFF_REQ_MASK,
32+
TPS65219_MFP_I2C_OFF_REQ_MASK);
33+
}
3234

33-
tps = container_of(this, struct tps65219, nb);
35+
static int tps65219_power_off_handler(struct sys_off_data *data)
36+
{
37+
tps65219_soft_shutdown(data->cb_data);
38+
return NOTIFY_DONE;
39+
}
3440

41+
static int tps65219_restart(struct tps65219 *tps, unsigned long reboot_mode)
42+
{
3543
if (reboot_mode == REBOOT_WARM)
3644
tps65219_warm_reset(tps);
3745
else
@@ -40,10 +48,11 @@ static int tps65219_restart(struct notifier_block *this,
4048
return NOTIFY_DONE;
4149
}
4250

43-
static struct notifier_block pmic_rst_restart_nb = {
44-
.notifier_call = tps65219_restart,
45-
.priority = 200,
46-
};
51+
static int tps65219_restart_handler(struct sys_off_data *data)
52+
{
53+
tps65219_restart(data->cb_data, data->mode);
54+
return NOTIFY_DONE;
55+
}
4756

4857
static const struct resource tps65219_pwrbutton_resources[] = {
4958
DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"),
@@ -269,13 +278,22 @@ static int tps65219_probe(struct i2c_client *client)
269278
}
270279
}
271280

272-
tps->nb = pmic_rst_restart_nb;
273-
ret = register_restart_handler(&tps->nb);
281+
ret = devm_register_restart_handler(tps->dev,
282+
tps65219_restart_handler,
283+
tps);
284+
274285
if (ret) {
275286
dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
276287
return ret;
277288
}
278289

290+
ret = devm_register_power_off_handler(tps->dev,
291+
tps65219_power_off_handler,
292+
tps);
293+
if (ret) {
294+
dev_err(tps->dev, "failed to register power-off handler: %d\n", ret);
295+
return ret;
296+
}
279297
return 0;
280298
}
281299

0 commit comments

Comments
 (0)