1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Linaro Ltd.
7 #include <linux/init.h>
8 #include <linux/mfd/syscon.h>
9 #include <linux/reboot.h>
10 #include <linux/regmap.h>
13 #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
14 #define INTEGRATOR_HDR_LOCK_OFFSET 0x14
15 #define INTEGRATOR_CM_CTRL_RESET (1 << 3)
17 #define VERSATILE_SYS_LOCK_OFFSET 0x20
18 #define VERSATILE_SYS_RESETCTL_OFFSET 0x40
20 /* Magic unlocking token used on all Versatile boards */
21 #define VERSATILE_LOCK_VAL 0xA05F
24 * We detect the different syscon types from the compatible strings.
26 enum versatile_reboot {
30 REALVIEW_REBOOT_PB1176,
31 REALVIEW_REBOOT_PB11MP,
36 /* Pointer to the system controller */
37 static struct regmap *syscon_regmap;
38 static enum versatile_reboot versatile_reboot_type;
40 static const struct of_device_id versatile_reboot_of_match[] = {
42 .compatible = "arm,core-module-integrator",
43 .data = (void *)INTEGRATOR_REBOOT_CM
46 .compatible = "arm,core-module-versatile",
47 .data = (void *)VERSATILE_REBOOT_CM,
50 .compatible = "arm,realview-eb-syscon",
51 .data = (void *)REALVIEW_REBOOT_EB,
54 .compatible = "arm,realview-pb1176-syscon",
55 .data = (void *)REALVIEW_REBOOT_PB1176,
58 .compatible = "arm,realview-pb11mp-syscon",
59 .data = (void *)REALVIEW_REBOOT_PB11MP,
62 .compatible = "arm,realview-pba8-syscon",
63 .data = (void *)REALVIEW_REBOOT_PBA8,
66 .compatible = "arm,realview-pbx-syscon",
67 .data = (void *)REALVIEW_REBOOT_PBX,
72 static int versatile_reboot(struct notifier_block *this, unsigned long mode,
75 /* Unlock the reset register */
76 /* Then hit reset on the different machines */
77 switch (versatile_reboot_type) {
78 case INTEGRATOR_REBOOT_CM:
79 regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
81 regmap_update_bits(syscon_regmap,
82 INTEGRATOR_HDR_CTRL_OFFSET,
83 INTEGRATOR_CM_CTRL_RESET,
84 INTEGRATOR_CM_CTRL_RESET);
86 case VERSATILE_REBOOT_CM:
87 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
89 regmap_update_bits(syscon_regmap,
90 VERSATILE_SYS_RESETCTL_OFFSET,
93 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
96 case REALVIEW_REBOOT_EB:
97 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
99 regmap_write(syscon_regmap,
100 VERSATILE_SYS_RESETCTL_OFFSET, 0x0008);
102 case REALVIEW_REBOOT_PB1176:
103 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
105 regmap_write(syscon_regmap,
106 VERSATILE_SYS_RESETCTL_OFFSET, 0x0100);
108 case REALVIEW_REBOOT_PB11MP:
109 case REALVIEW_REBOOT_PBA8:
110 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
112 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
114 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
117 case REALVIEW_REBOOT_PBX:
118 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
120 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
122 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
131 static struct notifier_block versatile_reboot_nb = {
132 .notifier_call = versatile_reboot,
136 static int __init versatile_reboot_probe(void)
138 const struct of_device_id *reboot_id;
139 struct device_node *np;
142 np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
146 versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
148 syscon_regmap = syscon_node_to_regmap(np);
150 if (IS_ERR(syscon_regmap))
151 return PTR_ERR(syscon_regmap);
153 err = register_restart_handler(&versatile_reboot_nb);
157 pr_info("versatile reboot driver registered\n");
160 device_initcall(versatile_reboot_probe);