0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/delay.h>
0012 #include <linux/io.h>
0013 #include <linux/module.h>
0014 #include <linux/notifier.h>
0015 #include <linux/of_address.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/reboot.h>
0018
0019 #include <asm/proc-fns.h>
0020
0021 static void __iomem *base;
0022 static u32 reboot_offset;
0023
0024 static int hisi_restart_handler(struct notifier_block *this,
0025 unsigned long mode, void *cmd)
0026 {
0027 writel_relaxed(0xdeadbeef, base + reboot_offset);
0028
0029 while (1)
0030 cpu_do_idle();
0031
0032 return NOTIFY_DONE;
0033 }
0034
0035 static struct notifier_block hisi_restart_nb = {
0036 .notifier_call = hisi_restart_handler,
0037 .priority = 128,
0038 };
0039
0040 static int hisi_reboot_probe(struct platform_device *pdev)
0041 {
0042 struct device_node *np = pdev->dev.of_node;
0043 int err;
0044
0045 base = of_iomap(np, 0);
0046 if (!base) {
0047 WARN(1, "failed to map base address");
0048 return -ENODEV;
0049 }
0050
0051 if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
0052 pr_err("failed to find reboot-offset property\n");
0053 iounmap(base);
0054 return -EINVAL;
0055 }
0056
0057 err = register_restart_handler(&hisi_restart_nb);
0058 if (err) {
0059 dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
0060 err);
0061 iounmap(base);
0062 }
0063
0064 return err;
0065 }
0066
0067 static const struct of_device_id hisi_reboot_of_match[] = {
0068 { .compatible = "hisilicon,sysctrl" },
0069 {}
0070 };
0071 MODULE_DEVICE_TABLE(of, hisi_reboot_of_match);
0072
0073 static struct platform_driver hisi_reboot_driver = {
0074 .probe = hisi_reboot_probe,
0075 .driver = {
0076 .name = "hisi-reboot",
0077 .of_match_table = hisi_reboot_of_match,
0078 },
0079 };
0080 module_platform_driver(hisi_reboot_driver);