1 /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  */
13 
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/io.h>
19 #include <linux/of.h>
20 #include <linux/platform_device.h>
21 #include <linux/module.h>
22 #include <linux/reboot.h>
23 #include <linux/pm.h>
24 
25 static void __iomem *msm_ps_hold;
26 static int do_msm_restart(struct notifier_block *nb, unsigned long action,
27 			   void *data)
28 {
29 	writel(0, msm_ps_hold);
30 	mdelay(10000);
31 
32 	return NOTIFY_DONE;
33 }
34 
35 static struct notifier_block restart_nb = {
36 	.notifier_call = do_msm_restart,
37 	.priority = 128,
38 };
39 
40 static void do_msm_poweroff(void)
41 {
42 	/* TODO: Add poweroff capability */
43 	do_msm_restart(&restart_nb, 0, NULL);
44 }
45 
46 static int msm_restart_probe(struct platform_device *pdev)
47 {
48 	struct device *dev = &pdev->dev;
49 	struct resource *mem;
50 
51 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52 	msm_ps_hold = devm_ioremap_resource(dev, mem);
53 	if (IS_ERR(msm_ps_hold))
54 		return PTR_ERR(msm_ps_hold);
55 
56 	register_restart_handler(&restart_nb);
57 
58 	pm_power_off = do_msm_poweroff;
59 
60 	return 0;
61 }
62 
63 static const struct of_device_id of_msm_restart_match[] = {
64 	{ .compatible = "qcom,pshold", },
65 	{},
66 };
67 MODULE_DEVICE_TABLE(of, of_msm_restart_match);
68 
69 static struct platform_driver msm_restart_driver = {
70 	.probe = msm_restart_probe,
71 	.driver = {
72 		.name = "msm-restart",
73 		.of_match_table = of_match_ptr(of_msm_restart_match),
74 	},
75 };
76 
77 static int __init msm_restart_init(void)
78 {
79 	return platform_driver_register(&msm_restart_driver);
80 }
81 device_initcall(msm_restart_init);
82