xref: /linux/drivers/power/reset/tps65086-restart.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
180698507SEmil Renner Berthing // SPDX-License-Identifier: GPL-2.0
280698507SEmil Renner Berthing /*
380698507SEmil Renner Berthing  * Copyright (C) 2021 Emil Renner Berthing
480698507SEmil Renner Berthing  */
580698507SEmil Renner Berthing 
680698507SEmil Renner Berthing #include <linux/mfd/tps65086.h>
780698507SEmil Renner Berthing #include <linux/mod_devicetable.h>
880698507SEmil Renner Berthing #include <linux/module.h>
980698507SEmil Renner Berthing #include <linux/platform_device.h>
1080698507SEmil Renner Berthing #include <linux/reboot.h>
1180698507SEmil Renner Berthing 
tps65086_restart_notify(struct sys_off_data * data)12e68b7181SAndrew Davis static int tps65086_restart_notify(struct sys_off_data *data)
1380698507SEmil Renner Berthing {
14*11d2642eSAndrew Davis 	struct tps65086 *tps65086 = data->cb_data;
1580698507SEmil Renner Berthing 	int ret;
1680698507SEmil Renner Berthing 
1780698507SEmil Renner Berthing 	ret = regmap_write(tps65086->regmap, TPS65086_FORCESHUTDN, 1);
1880698507SEmil Renner Berthing 	if (ret) {
19*11d2642eSAndrew Davis 		dev_err(tps65086->dev, "%s: error writing to tps65086 pmic: %d\n",
2080698507SEmil Renner Berthing 			__func__, ret);
2180698507SEmil Renner Berthing 		return NOTIFY_DONE;
2280698507SEmil Renner Berthing 	}
2380698507SEmil Renner Berthing 
2480698507SEmil Renner Berthing 	/* give it a little time */
2580698507SEmil Renner Berthing 	mdelay(200);
2680698507SEmil Renner Berthing 
2780698507SEmil Renner Berthing 	WARN_ON(1);
2880698507SEmil Renner Berthing 
2980698507SEmil Renner Berthing 	return NOTIFY_DONE;
3080698507SEmil Renner Berthing }
3180698507SEmil Renner Berthing 
tps65086_restart_probe(struct platform_device * pdev)3280698507SEmil Renner Berthing static int tps65086_restart_probe(struct platform_device *pdev)
3380698507SEmil Renner Berthing {
34*11d2642eSAndrew Davis 	struct tps65086 *tps65086 = dev_get_drvdata(pdev->dev.parent);
3580698507SEmil Renner Berthing 
36*11d2642eSAndrew Davis 	return devm_register_sys_off_handler(&pdev->dev,
37e68b7181SAndrew Davis 					     SYS_OFF_MODE_RESTART,
38e68b7181SAndrew Davis 					     SYS_OFF_PRIO_HIGH,
39e68b7181SAndrew Davis 					     tps65086_restart_notify,
40*11d2642eSAndrew Davis 					     tps65086);
4180698507SEmil Renner Berthing }
4280698507SEmil Renner Berthing 
4380698507SEmil Renner Berthing static const struct platform_device_id tps65086_restart_id_table[] = {
4480698507SEmil Renner Berthing 	{ "tps65086-reset", },
4580698507SEmil Renner Berthing 	{ /* sentinel */ }
4680698507SEmil Renner Berthing };
4780698507SEmil Renner Berthing MODULE_DEVICE_TABLE(platform, tps65086_restart_id_table);
4880698507SEmil Renner Berthing 
4980698507SEmil Renner Berthing static struct platform_driver tps65086_restart_driver = {
5080698507SEmil Renner Berthing 	.driver = {
5180698507SEmil Renner Berthing 		.name = "tps65086-restart",
5280698507SEmil Renner Berthing 	},
5380698507SEmil Renner Berthing 	.probe = tps65086_restart_probe,
5480698507SEmil Renner Berthing 	.id_table = tps65086_restart_id_table,
5580698507SEmil Renner Berthing };
5680698507SEmil Renner Berthing module_platform_driver(tps65086_restart_driver);
5780698507SEmil Renner Berthing 
5880698507SEmil Renner Berthing MODULE_AUTHOR("Emil Renner Berthing <kernel@esmil.dk>");
5980698507SEmil Renner Berthing MODULE_DESCRIPTION("TPS65086 restart driver");
60