blob: 0ba5fdce186f44cf4f36e97321e1707cf8660b79 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Haojian Zhuang4a9b3732014-05-13 17:11:28 +08002/*
3 * Hisilicon SoC reset code
4 *
5 * Copyright (c) 2014 Hisilicon Ltd.
6 * Copyright (c) 2014 Linaro Ltd.
7 *
8 * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
Haojian Zhuang4a9b3732014-05-13 17:11:28 +08009 */
10
11#include <linux/delay.h>
12#include <linux/io.h>
13#include <linux/module.h>
Guenter Roeck67245342014-09-30 10:48:35 -070014#include <linux/notifier.h>
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080015#include <linux/of_address.h>
16#include <linux/platform_device.h>
17#include <linux/reboot.h>
18
19#include <asm/proc-fns.h>
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080020
21static void __iomem *base;
22static u32 reboot_offset;
23
Guenter Roeck67245342014-09-30 10:48:35 -070024static int hisi_restart_handler(struct notifier_block *this,
25 unsigned long mode, void *cmd)
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080026{
27 writel_relaxed(0xdeadbeef, base + reboot_offset);
28
29 while (1)
30 cpu_do_idle();
Guenter Roeck67245342014-09-30 10:48:35 -070031
32 return NOTIFY_DONE;
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080033}
34
Guenter Roeck67245342014-09-30 10:48:35 -070035static struct notifier_block hisi_restart_nb = {
36 .notifier_call = hisi_restart_handler,
37 .priority = 128,
38};
39
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080040static int hisi_reboot_probe(struct platform_device *pdev)
41{
42 struct device_node *np = pdev->dev.of_node;
Guenter Roeck67245342014-09-30 10:48:35 -070043 int err;
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080044
45 base = of_iomap(np, 0);
46 if (!base) {
47 WARN(1, "failed to map base address");
48 return -ENODEV;
49 }
50
51 if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
52 pr_err("failed to find reboot-offset property\n");
Arvind Yadavbae170e2016-08-12 20:49:18 +053053 iounmap(base);
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080054 return -EINVAL;
55 }
56
Guenter Roeck67245342014-09-30 10:48:35 -070057 err = register_restart_handler(&hisi_restart_nb);
Arvind Yadavbae170e2016-08-12 20:49:18 +053058 if (err) {
Guenter Roeck67245342014-09-30 10:48:35 -070059 dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
60 err);
Arvind Yadavbae170e2016-08-12 20:49:18 +053061 iounmap(base);
62 }
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080063
Guenter Roeck67245342014-09-30 10:48:35 -070064 return err;
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080065}
66
Fabian Frederick8fb08852015-03-16 20:17:12 +010067static const struct of_device_id hisi_reboot_of_match[] = {
Haojian Zhuang4a9b3732014-05-13 17:11:28 +080068 { .compatible = "hisilicon,sysctrl" },
69 {}
70};
71
72static struct platform_driver hisi_reboot_driver = {
73 .probe = hisi_reboot_probe,
74 .driver = {
75 .name = "hisi-reboot",
76 .of_match_table = hisi_reboot_of_match,
77 },
78};
79module_platform_driver(hisi_reboot_driver);