Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Jerome Neanne and committed by
Lee Jones
3df4c636 95100ed6

+28 -10
+28 -10
drivers/mfd/tps65219.c
··· 25 25 TPS65219_MFP_COLD_RESET_I2C_CTRL_MASK); 26 26 } 27 27 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) 30 29 { 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 + } 32 34 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 + } 34 40 41 + static int tps65219_restart(struct tps65219 *tps, unsigned long reboot_mode) 42 + { 35 43 if (reboot_mode == REBOOT_WARM) 36 44 tps65219_warm_reset(tps); 37 45 else ··· 48 40 return NOTIFY_DONE; 49 41 } 50 42 51 - static struct notifier_block pmic_rst_restart_nb = { 52 - .notifier_call = tps65219_restart, 53 - .priority = 200, 54 - }; 43 + static int tps65219_restart_handler(struct sys_off_data *data) 44 + { 45 + tps65219_restart(data->cb_data, data->mode); 46 + return NOTIFY_DONE; 47 + } 55 48 56 49 static const struct resource tps65219_pwrbutton_resources[] = { 57 50 DEFINE_RES_IRQ_NAMED(TPS65219_INT_PB_FALLING_EDGE_DETECT, "falling"), ··· 278 269 } 279 270 } 280 271 281 - tps->nb = pmic_rst_restart_nb; 282 - ret = register_restart_handler(&tps->nb); 272 + ret = devm_register_restart_handler(tps->dev, 273 + tps65219_restart_handler, 274 + tps); 275 + 283 276 if (ret) { 284 277 dev_err(tps->dev, "cannot register restart handler, %d\n", ret); 285 278 return ret; 286 279 } 287 280 281 + ret = devm_register_power_off_handler(tps->dev, 282 + tps65219_power_off_handler, 283 + tps); 284 + if (ret) { 285 + dev_err(tps->dev, "failed to register power-off handler: %d\n", ret); 286 + return ret; 287 + } 288 288 return 0; 289 289 } 290 290