blob: 76153ac0706cb78438b918cd57aeb669825989a9 [file] [log] [blame]
Jun Niedd9f1482015-07-15 11:25:58 +08001/*
2 * ZTE zx296702 SoC reset code
3 *
4 * Copyright (c) 2015 Linaro Ltd.
5 *
6 * Author: Jun Nie <jun.nie@linaro.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/delay.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/notifier.h>
17#include <linux/of_address.h>
18#include <linux/platform_device.h>
19#include <linux/reboot.h>
20
Jun Niedd9f1482015-07-15 11:25:58 +080021static void __iomem *base;
22static void __iomem *pcu_base;
23
24static int zx_restart_handler(struct notifier_block *this,
25 unsigned long mode, void *cmd)
26{
27 writel_relaxed(1, base + 0xb0);
28 writel_relaxed(1, pcu_base + 0x34);
29
30 mdelay(50);
31 pr_emerg("Unable to restart system\n");
32
33 return NOTIFY_DONE;
34}
35
36static struct notifier_block zx_restart_nb = {
37 .notifier_call = zx_restart_handler,
38 .priority = 128,
39};
40
41static int zx_reboot_probe(struct platform_device *pdev)
42{
43 struct device_node *np = pdev->dev.of_node;
44 int err;
45
46 base = of_iomap(np, 0);
47 if (!base) {
48 WARN(1, "failed to map base address");
49 return -ENODEV;
50 }
51
52 np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
53 pcu_base = of_iomap(np, 0);
54 if (!pcu_base) {
55 iounmap(base);
56 WARN(1, "failed to map pcu_base address");
57 return -ENODEV;
58 }
59
60 err = register_restart_handler(&zx_restart_nb);
Arvind Yadav7531be52016-09-14 16:35:31 +053061 if (err) {
62 iounmap(base);
63 iounmap(pcu_base);
Jun Niedd9f1482015-07-15 11:25:58 +080064 dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
65 err);
Arvind Yadav7531be52016-09-14 16:35:31 +053066 }
Jun Niedd9f1482015-07-15 11:25:58 +080067
68 return err;
69}
70
71static const struct of_device_id zx_reboot_of_match[] = {
72 { .compatible = "zte,sysctrl" },
73 {}
74};
75
76static struct platform_driver zx_reboot_driver = {
77 .probe = zx_reboot_probe,
78 .driver = {
79 .name = "zx-reboot",
80 .of_match_table = zx_reboot_of_match,
81 },
82};
83module_platform_driver(zx_reboot_driver);
Jesse Chan51793172017-11-20 12:58:27 -080084
85MODULE_DESCRIPTION("ZTE SoCs reset driver");
86MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>");
87MODULE_LICENSE("GPL v2");