2 * Copyright (C) 2014 Linaro Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
11 #include <linux/init.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/reboot.h>
14 #include <linux/regmap.h>
17 #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
18 #define INTEGRATOR_HDR_LOCK_OFFSET 0x14
19 #define INTEGRATOR_CM_CTRL_RESET (1 << 3)
21 #define VERSATILE_SYS_LOCK_OFFSET 0x20
22 #define VERSATILE_SYS_RESETCTL_OFFSET 0x40
24 /* Magic unlocking token used on all Versatile boards */
25 #define VERSATILE_LOCK_VAL 0xA05F
28 * We detect the different syscon types from the compatible strings.
30 enum versatile_reboot {
34 REALVIEW_REBOOT_PB1176,
35 REALVIEW_REBOOT_PB11MP,
40 /* Pointer to the system controller */
41 static struct regmap *syscon_regmap;
42 static enum versatile_reboot versatile_reboot_type;
44 static const struct of_device_id versatile_reboot_of_match[] = {
46 .compatible = "arm,core-module-integrator",
47 .data = (void *)INTEGRATOR_REBOOT_CM
50 .compatible = "arm,core-module-versatile",
51 .data = (void *)VERSATILE_REBOOT_CM,
54 .compatible = "arm,realview-eb-syscon",
55 .data = (void *)REALVIEW_REBOOT_EB,
58 .compatible = "arm,realview-pb1176-syscon",
59 .data = (void *)REALVIEW_REBOOT_PB1176,
62 .compatible = "arm,realview-pb11mp-syscon",
63 .data = (void *)REALVIEW_REBOOT_PB11MP,
66 .compatible = "arm,realview-pba8-syscon",
67 .data = (void *)REALVIEW_REBOOT_PBA8,
70 .compatible = "arm,realview-pbx-syscon",
71 .data = (void *)REALVIEW_REBOOT_PBX,
76 static int versatile_reboot(struct notifier_block *this, unsigned long mode,
79 /* Unlock the reset register */
80 /* Then hit reset on the different machines */
81 switch (versatile_reboot_type) {
82 case INTEGRATOR_REBOOT_CM:
83 regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
85 regmap_update_bits(syscon_regmap,
86 INTEGRATOR_HDR_CTRL_OFFSET,
87 INTEGRATOR_CM_CTRL_RESET,
88 INTEGRATOR_CM_CTRL_RESET);
90 case VERSATILE_REBOOT_CM:
91 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
93 regmap_update_bits(syscon_regmap,
94 VERSATILE_SYS_RESETCTL_OFFSET,
97 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
100 case REALVIEW_REBOOT_EB:
101 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
103 regmap_write(syscon_regmap,
104 VERSATILE_SYS_RESETCTL_OFFSET, 0x0008);
106 case REALVIEW_REBOOT_PB1176:
107 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
109 regmap_write(syscon_regmap,
110 VERSATILE_SYS_RESETCTL_OFFSET, 0x0100);
112 case REALVIEW_REBOOT_PB11MP:
113 case REALVIEW_REBOOT_PBA8:
114 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
116 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
118 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
121 case REALVIEW_REBOOT_PBX:
122 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
124 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
126 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
135 static struct notifier_block versatile_reboot_nb = {
136 .notifier_call = versatile_reboot,
140 static int __init versatile_reboot_probe(void)
142 const struct of_device_id *reboot_id;
143 struct device_node *np;
146 np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
150 versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
152 syscon_regmap = syscon_node_to_regmap(np);
153 if (IS_ERR(syscon_regmap))
154 return PTR_ERR(syscon_regmap);
156 err = register_restart_handler(&versatile_reboot_nb);
160 pr_info("versatile reboot driver registered\n");
163 device_initcall(versatile_reboot_probe);