1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/delay.h>
28#include <linux/io.h>
29#include <linux/notifier.h>
30#include <linux/of_device.h>
31#include <linux/of_address.h>
32#include <linux/platform_device.h>
33#include <linux/reboot.h>
34#include <linux/stat.h>
35#include <linux/slab.h>
36
37struct xgene_reboot_context {
38 struct device *dev;
39 void *csr;
40 u32 mask;
41 struct notifier_block restart_handler;
42};
43
44static int xgene_restart_handler(struct notifier_block *this,
45 unsigned long mode, void *cmd)
46{
47 struct xgene_reboot_context *ctx =
48 container_of(this, struct xgene_reboot_context,
49 restart_handler);
50
51
52 writel(ctx->mask, ctx->csr);
53
54 mdelay(1000);
55
56 dev_emerg(ctx->dev, "Unable to restart system\n");
57
58 return NOTIFY_DONE;
59}
60
61static int xgene_reboot_probe(struct platform_device *pdev)
62{
63 struct xgene_reboot_context *ctx;
64 struct device *dev = &pdev->dev;
65 int err;
66
67 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
68 if (!ctx)
69 return -ENOMEM;
70
71 ctx->csr = of_iomap(dev->of_node, 0);
72 if (!ctx->csr) {
73 dev_err(dev, "can not map resource\n");
74 return -ENODEV;
75 }
76
77 if (of_property_read_u32(dev->of_node, "mask", &ctx->mask))
78 ctx->mask = 0xFFFFFFFF;
79
80 ctx->dev = dev;
81 ctx->restart_handler.notifier_call = xgene_restart_handler;
82 ctx->restart_handler.priority = 128;
83 err = register_restart_handler(&ctx->restart_handler);
84 if (err) {
85 iounmap(ctx->csr);
86 dev_err(dev, "cannot register restart handler (err=%d)\n", err);
87 }
88
89 return err;
90}
91
92static const struct of_device_id xgene_reboot_of_match[] = {
93 { .compatible = "apm,xgene-reboot" },
94 {}
95};
96
97static struct platform_driver xgene_reboot_driver = {
98 .probe = xgene_reboot_probe,
99 .driver = {
100 .name = "xgene-reboot",
101 .of_match_table = xgene_reboot_of_match,
102 },
103};
104
105static int __init xgene_reboot_init(void)
106{
107 return platform_driver_register(&xgene_reboot_driver);
108}
109device_initcall(xgene_reboot_init);
110