1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Emil Renner Berthing
6 #include <linux/mfd/tps65086.h>
7 #include <linux/mod_devicetable.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/reboot.h>
12 struct tps65086_restart {
13 struct notifier_block handler;
17 static int tps65086_restart_notify(struct notifier_block *this,
18 unsigned long mode, void *cmd)
20 struct tps65086_restart *tps65086_restart =
21 container_of(this, struct tps65086_restart, handler);
22 struct tps65086 *tps65086 = dev_get_drvdata(tps65086_restart->dev->parent);
25 ret = regmap_write(tps65086->regmap, TPS65086_FORCESHUTDN, 1);
27 dev_err(tps65086_restart->dev, "%s: error writing to tps65086 pmic: %d\n",
32 /* give it a little time */
40 static int tps65086_restart_probe(struct platform_device *pdev)
42 struct tps65086_restart *tps65086_restart;
45 tps65086_restart = devm_kzalloc(&pdev->dev, sizeof(*tps65086_restart), GFP_KERNEL);
46 if (!tps65086_restart)
49 platform_set_drvdata(pdev, tps65086_restart);
51 tps65086_restart->handler.notifier_call = tps65086_restart_notify;
52 tps65086_restart->handler.priority = 192;
53 tps65086_restart->dev = &pdev->dev;
55 ret = register_restart_handler(&tps65086_restart->handler);
57 dev_err(&pdev->dev, "%s: cannot register restart handler: %d\n",
65 static int tps65086_restart_remove(struct platform_device *pdev)
67 struct tps65086_restart *tps65086_restart = platform_get_drvdata(pdev);
70 ret = unregister_restart_handler(&tps65086_restart->handler);
72 dev_err(&pdev->dev, "%s: cannot unregister restart handler: %d\n",
80 static const struct platform_device_id tps65086_restart_id_table[] = {
81 { "tps65086-reset", },
84 MODULE_DEVICE_TABLE(platform, tps65086_restart_id_table);
86 static struct platform_driver tps65086_restart_driver = {
88 .name = "tps65086-restart",
90 .probe = tps65086_restart_probe,
91 .remove = tps65086_restart_remove,
92 .id_table = tps65086_restart_id_table,
94 module_platform_driver(tps65086_restart_driver);
96 MODULE_AUTHOR("Emil Renner Berthing <kernel@esmil.dk>");
97 MODULE_DESCRIPTION("TPS65086 restart driver");