Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * ZTE zx296702 SoC reset code
4 *
5 * Copyright (c) 2015 Linaro Ltd.
6 *
7 * Author: Jun Nie <jun.nie@linaro.org>
8 */
9
10#include <linux/delay.h>
11#include <linux/io.h>
12#include <linux/module.h>
13#include <linux/notifier.h>
14#include <linux/of_address.h>
15#include <linux/platform_device.h>
16#include <linux/reboot.h>
17
18static void __iomem *base;
19static void __iomem *pcu_base;
20
21static int zx_restart_handler(struct notifier_block *this,
22 unsigned long mode, void *cmd)
23{
24 writel_relaxed(1, base + 0xb0);
25 writel_relaxed(1, pcu_base + 0x34);
26
27 mdelay(50);
28 pr_emerg("Unable to restart system\n");
29
30 return NOTIFY_DONE;
31}
32
33static struct notifier_block zx_restart_nb = {
34 .notifier_call = zx_restart_handler,
35 .priority = 128,
36};
37
38static int zx_reboot_probe(struct platform_device *pdev)
39{
40 struct device_node *np = pdev->dev.of_node;
41 int err;
42
43 base = of_iomap(np, 0);
44 if (!base) {
45 WARN(1, "failed to map base address");
46 return -ENODEV;
47 }
48
49 np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
50 pcu_base = of_iomap(np, 0);
51 of_node_put(np);
52 if (!pcu_base) {
53 iounmap(base);
54 WARN(1, "failed to map pcu_base address");
55 return -ENODEV;
56 }
57
58 err = register_restart_handler(&zx_restart_nb);
59 if (err) {
60 iounmap(base);
61 iounmap(pcu_base);
62 dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
63 err);
64 }
65
66 return err;
67}
68
69static const struct of_device_id zx_reboot_of_match[] = {
70 { .compatible = "zte,sysctrl" },
71 {}
72};
73MODULE_DEVICE_TABLE(of, zx_reboot_of_match);
74
75static struct platform_driver zx_reboot_driver = {
76 .probe = zx_reboot_probe,
77 .driver = {
78 .name = "zx-reboot",
79 .of_match_table = zx_reboot_of_match,
80 },
81};
82module_platform_driver(zx_reboot_driver);
83
84MODULE_DESCRIPTION("ZTE SoCs reset driver");
85MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>");
86MODULE_LICENSE("GPL v2");