1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* |
3 | * Copyright (C) 2021 Emil Renner Berthing |
4 | */ |
5 | |
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> |
11 | |
12 | static int tps65086_restart_notify(struct sys_off_data *data) |
13 | { |
14 | struct tps65086 *tps65086 = data->cb_data; |
15 | int ret; |
16 | |
17 | ret = regmap_write(map: tps65086->regmap, TPS65086_FORCESHUTDN, val: 1); |
18 | if (ret) { |
19 | dev_err(tps65086->dev, "%s: error writing to tps65086 pmic: %d\n" , |
20 | __func__, ret); |
21 | return NOTIFY_DONE; |
22 | } |
23 | |
24 | /* give it a little time */ |
25 | mdelay(200); |
26 | |
27 | WARN_ON(1); |
28 | |
29 | return NOTIFY_DONE; |
30 | } |
31 | |
32 | static int tps65086_restart_probe(struct platform_device *pdev) |
33 | { |
34 | struct tps65086 *tps65086 = dev_get_drvdata(dev: pdev->dev.parent); |
35 | |
36 | return devm_register_sys_off_handler(dev: &pdev->dev, |
37 | mode: SYS_OFF_MODE_RESTART, |
38 | SYS_OFF_PRIO_HIGH, |
39 | callback: tps65086_restart_notify, |
40 | cb_data: tps65086); |
41 | } |
42 | |
43 | static const struct platform_device_id tps65086_restart_id_table[] = { |
44 | { "tps65086-reset" , }, |
45 | { /* sentinel */ } |
46 | }; |
47 | MODULE_DEVICE_TABLE(platform, tps65086_restart_id_table); |
48 | |
49 | static struct platform_driver tps65086_restart_driver = { |
50 | .driver = { |
51 | .name = "tps65086-restart" , |
52 | }, |
53 | .probe = tps65086_restart_probe, |
54 | .id_table = tps65086_restart_id_table, |
55 | }; |
56 | module_platform_driver(tps65086_restart_driver); |
57 | |
58 | MODULE_AUTHOR("Emil Renner Berthing <kernel@esmil.dk>" ); |
59 | MODULE_DESCRIPTION("TPS65086 restart driver" ); |
60 | |