blob: 01b8c71697cb7f4f5f60a84c95c3090e91d26303 [file] [log] [blame]
Abhimanyu Kapur78be3172013-07-30 17:05:28 -07001/* 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>
Pramod Gurav18a702e2014-09-25 17:03:51 +053023#include <linux/pm.h>
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070024
25static void __iomem *msm_ps_hold;
Bjorn Anderssonfd8b8f12018-01-07 19:33:13 -080026static int deassert_pshold(struct notifier_block *nb, unsigned long action,
Pramod Gurav18a702e2014-09-25 17:03:51 +053027 void *data)
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070028{
29 writel(0, msm_ps_hold);
30 mdelay(10000);
Pramod Gurav18a702e2014-09-25 17:03:51 +053031
32 return NOTIFY_DONE;
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070033}
34
Pramod Gurav18a702e2014-09-25 17:03:51 +053035static struct notifier_block restart_nb = {
Bjorn Anderssonfd8b8f12018-01-07 19:33:13 -080036 .notifier_call = deassert_pshold,
Pramod Gurav18a702e2014-09-25 17:03:51 +053037 .priority = 128,
38};
39
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070040static void do_msm_poweroff(void)
41{
Bjorn Anderssonfd8b8f12018-01-07 19:33:13 -080042 deassert_pshold(&restart_nb, 0, NULL);
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070043}
44
45static int msm_restart_probe(struct platform_device *pdev)
46{
47 struct device *dev = &pdev->dev;
48 struct resource *mem;
49
50 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
51 msm_ps_hold = devm_ioremap_resource(dev, mem);
52 if (IS_ERR(msm_ps_hold))
53 return PTR_ERR(msm_ps_hold);
54
Pramod Gurav18a702e2014-09-25 17:03:51 +053055 register_restart_handler(&restart_nb);
56
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070057 pm_power_off = do_msm_poweroff;
Pramod Gurav18a702e2014-09-25 17:03:51 +053058
Abhimanyu Kapur78be3172013-07-30 17:05:28 -070059 return 0;
60}
61
62static const struct of_device_id of_msm_restart_match[] = {
63 { .compatible = "qcom,pshold", },
64 {},
65};
66MODULE_DEVICE_TABLE(of, of_msm_restart_match);
67
68static struct platform_driver msm_restart_driver = {
69 .probe = msm_restart_probe,
70 .driver = {
71 .name = "msm-restart",
72 .of_match_table = of_match_ptr(of_msm_restart_match),
73 },
74};
75
76static int __init msm_restart_init(void)
77{
78 return platform_driver_register(&msm_restart_driver);
79}
80device_initcall(msm_restart_init);