blob: 06d34ab47df535a84ae5e419170bcb28eb06d1de [file] [log] [blame]
Linus Walleij0e545f52014-05-22 10:20:38 +02001/*
2 * Copyright (C) 2014 Linaro Ltd.
3 *
4 * Author: Linus Walleij <linus.walleij@linaro.org>
5 *
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.
9 *
10 */
11#include <linux/init.h>
12#include <linux/mfd/syscon.h>
13#include <linux/reboot.h>
14#include <linux/regmap.h>
15#include <linux/of.h>
Linus Walleij0e545f52014-05-22 10:20:38 +020016
Linus Walleij01608172014-12-19 16:56:27 +010017#define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
18#define INTEGRATOR_HDR_LOCK_OFFSET 0x14
19#define INTEGRATOR_CM_CTRL_RESET (1 << 3)
20
Linus Walleij3f652c92016-01-25 09:29:53 +010021#define VERSATILE_SYS_LOCK_OFFSET 0x20
22#define VERSATILE_SYS_RESETCTL_OFFSET 0x40
Linus Walleij0e545f52014-05-22 10:20:38 +020023
Linus Walleij01608172014-12-19 16:56:27 +010024/* Magic unlocking token used on all Versatile boards */
25#define VERSATILE_LOCK_VAL 0xA05F
26
Linus Walleij0e545f52014-05-22 10:20:38 +020027/*
28 * We detect the different syscon types from the compatible strings.
29 */
30enum versatile_reboot {
Linus Walleij01608172014-12-19 16:56:27 +010031 INTEGRATOR_REBOOT_CM,
Linus Walleij3f652c92016-01-25 09:29:53 +010032 VERSATILE_REBOOT_CM,
Linus Walleij0e545f52014-05-22 10:20:38 +020033 REALVIEW_REBOOT_EB,
34 REALVIEW_REBOOT_PB1176,
35 REALVIEW_REBOOT_PB11MP,
36 REALVIEW_REBOOT_PBA8,
37 REALVIEW_REBOOT_PBX,
38};
39
40/* Pointer to the system controller */
41static struct regmap *syscon_regmap;
42static enum versatile_reboot versatile_reboot_type;
43
44static const struct of_device_id versatile_reboot_of_match[] = {
45 {
Linus Walleij01608172014-12-19 16:56:27 +010046 .compatible = "arm,core-module-integrator",
47 .data = (void *)INTEGRATOR_REBOOT_CM
48 },
49 {
Linus Walleij3f652c92016-01-25 09:29:53 +010050 .compatible = "arm,core-module-versatile",
51 .data = (void *)VERSATILE_REBOOT_CM,
52 },
53 {
Linus Walleij0e545f52014-05-22 10:20:38 +020054 .compatible = "arm,realview-eb-syscon",
55 .data = (void *)REALVIEW_REBOOT_EB,
56 },
57 {
58 .compatible = "arm,realview-pb1176-syscon",
59 .data = (void *)REALVIEW_REBOOT_PB1176,
60 },
61 {
62 .compatible = "arm,realview-pb11mp-syscon",
63 .data = (void *)REALVIEW_REBOOT_PB11MP,
64 },
65 {
66 .compatible = "arm,realview-pba8-syscon",
67 .data = (void *)REALVIEW_REBOOT_PBA8,
68 },
69 {
70 .compatible = "arm,realview-pbx-syscon",
71 .data = (void *)REALVIEW_REBOOT_PBX,
72 },
Linus Walleij01608172014-12-19 16:56:27 +010073 {},
Linus Walleij0e545f52014-05-22 10:20:38 +020074};
75
Guenter Roeck25a5b572015-01-25 12:30:40 -080076static int versatile_reboot(struct notifier_block *this, unsigned long mode,
77 void *cmd)
Linus Walleij0e545f52014-05-22 10:20:38 +020078{
79 /* Unlock the reset register */
Linus Walleij0e545f52014-05-22 10:20:38 +020080 /* Then hit reset on the different machines */
81 switch (versatile_reboot_type) {
Linus Walleij01608172014-12-19 16:56:27 +010082 case INTEGRATOR_REBOOT_CM:
83 regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
84 VERSATILE_LOCK_VAL);
85 regmap_update_bits(syscon_regmap,
86 INTEGRATOR_HDR_CTRL_OFFSET,
87 INTEGRATOR_CM_CTRL_RESET,
88 INTEGRATOR_CM_CTRL_RESET);
89 break;
Linus Walleij3f652c92016-01-25 09:29:53 +010090 case VERSATILE_REBOOT_CM:
91 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
92 VERSATILE_LOCK_VAL);
93 regmap_update_bits(syscon_regmap,
94 VERSATILE_SYS_RESETCTL_OFFSET,
95 0x0107,
96 0x0105);
97 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
98 0);
99 break;
Linus Walleij0e545f52014-05-22 10:20:38 +0200100 case REALVIEW_REBOOT_EB:
Linus Walleij3f652c92016-01-25 09:29:53 +0100101 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
Linus Walleij01608172014-12-19 16:56:27 +0100102 VERSATILE_LOCK_VAL);
Linus Walleij0e545f52014-05-22 10:20:38 +0200103 regmap_write(syscon_regmap,
Linus Walleij3f652c92016-01-25 09:29:53 +0100104 VERSATILE_SYS_RESETCTL_OFFSET, 0x0008);
Linus Walleij0e545f52014-05-22 10:20:38 +0200105 break;
106 case REALVIEW_REBOOT_PB1176:
Linus Walleij3f652c92016-01-25 09:29:53 +0100107 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
Linus Walleij01608172014-12-19 16:56:27 +0100108 VERSATILE_LOCK_VAL);
Linus Walleij0e545f52014-05-22 10:20:38 +0200109 regmap_write(syscon_regmap,
Linus Walleij3f652c92016-01-25 09:29:53 +0100110 VERSATILE_SYS_RESETCTL_OFFSET, 0x0100);
Linus Walleij0e545f52014-05-22 10:20:38 +0200111 break;
112 case REALVIEW_REBOOT_PB11MP:
113 case REALVIEW_REBOOT_PBA8:
Linus Walleij3f652c92016-01-25 09:29:53 +0100114 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
Linus Walleij01608172014-12-19 16:56:27 +0100115 VERSATILE_LOCK_VAL);
Linus Walleij3f652c92016-01-25 09:29:53 +0100116 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
Linus Walleij0e545f52014-05-22 10:20:38 +0200117 0x0000);
Linus Walleij3f652c92016-01-25 09:29:53 +0100118 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
Linus Walleij0e545f52014-05-22 10:20:38 +0200119 0x0004);
120 break;
121 case REALVIEW_REBOOT_PBX:
Linus Walleij3f652c92016-01-25 09:29:53 +0100122 regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
Linus Walleij01608172014-12-19 16:56:27 +0100123 VERSATILE_LOCK_VAL);
Linus Walleij3f652c92016-01-25 09:29:53 +0100124 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
Linus Walleij0e545f52014-05-22 10:20:38 +0200125 0x00f0);
Linus Walleij3f652c92016-01-25 09:29:53 +0100126 regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
Linus Walleij0e545f52014-05-22 10:20:38 +0200127 0x00f4);
128 break;
129 }
130 dsb();
Guenter Roeck25a5b572015-01-25 12:30:40 -0800131
132 return NOTIFY_DONE;
Linus Walleij0e545f52014-05-22 10:20:38 +0200133}
134
Guenter Roeck25a5b572015-01-25 12:30:40 -0800135static struct notifier_block versatile_reboot_nb = {
136 .notifier_call = versatile_reboot,
137 .priority = 192,
138};
139
Linus Walleij0e545f52014-05-22 10:20:38 +0200140static int __init versatile_reboot_probe(void)
141{
142 const struct of_device_id *reboot_id;
143 struct device_node *np;
Guenter Roeck25a5b572015-01-25 12:30:40 -0800144 int err;
Linus Walleij0e545f52014-05-22 10:20:38 +0200145
146 np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
147 &reboot_id);
148 if (!np)
149 return -ENODEV;
150 versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
151
152 syscon_regmap = syscon_node_to_regmap(np);
153 if (IS_ERR(syscon_regmap))
154 return PTR_ERR(syscon_regmap);
155
Guenter Roeck25a5b572015-01-25 12:30:40 -0800156 err = register_restart_handler(&versatile_reboot_nb);
157 if (err)
158 return err;
159
Linus Walleij0e545f52014-05-22 10:20:38 +0200160 pr_info("versatile reboot driver registered\n");
161 return 0;
162}
163device_initcall(versatile_reboot_probe);