2 * Copyright (C) 2014 Linaro Ltd.
4 * Author: Linus Walleij <linus.walleij@linaro.org>
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>
16 #include <asm/system_misc.h>
18 #define REALVIEW_SYS_LOCK_OFFSET 0x20
19 #define REALVIEW_SYS_LOCK_VAL 0xA05F
20 #define REALVIEW_SYS_RESETCTL_OFFSET 0x40
23 * We detect the different syscon types from the compatible strings.
25 enum versatile_reboot {
27 REALVIEW_REBOOT_PB1176,
28 REALVIEW_REBOOT_PB11MP,
33 /* Pointer to the system controller */
34 static struct regmap *syscon_regmap;
35 static enum versatile_reboot versatile_reboot_type;
37 static const struct of_device_id versatile_reboot_of_match[] = {
39 .compatible = "arm,realview-eb-syscon",
40 .data = (void *)REALVIEW_REBOOT_EB,
43 .compatible = "arm,realview-pb1176-syscon",
44 .data = (void *)REALVIEW_REBOOT_PB1176,
47 .compatible = "arm,realview-pb11mp-syscon",
48 .data = (void *)REALVIEW_REBOOT_PB11MP,
51 .compatible = "arm,realview-pba8-syscon",
52 .data = (void *)REALVIEW_REBOOT_PBA8,
55 .compatible = "arm,realview-pbx-syscon",
56 .data = (void *)REALVIEW_REBOOT_PBX,
60 static void versatile_reboot(enum reboot_mode mode, const char *cmd)
62 /* Unlock the reset register */
63 regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
64 REALVIEW_SYS_LOCK_VAL);
65 /* Then hit reset on the different machines */
66 switch (versatile_reboot_type) {
67 case REALVIEW_REBOOT_EB:
68 regmap_write(syscon_regmap,
69 REALVIEW_SYS_RESETCTL_OFFSET, 0x0008);
71 case REALVIEW_REBOOT_PB1176:
72 regmap_write(syscon_regmap,
73 REALVIEW_SYS_RESETCTL_OFFSET, 0x0100);
75 case REALVIEW_REBOOT_PB11MP:
76 case REALVIEW_REBOOT_PBA8:
77 regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
79 regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
82 case REALVIEW_REBOOT_PBX:
83 regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
85 regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
92 static int __init versatile_reboot_probe(void)
94 const struct of_device_id *reboot_id;
95 struct device_node *np;
97 np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
101 versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
103 syscon_regmap = syscon_node_to_regmap(np);
104 if (IS_ERR(syscon_regmap))
105 return PTR_ERR(syscon_regmap);
107 arm_pm_restart = versatile_reboot;
108 pr_info("versatile reboot driver registered\n");
111 device_initcall(versatile_reboot_probe);