| Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Linaro Ltd. |
| 4 | * |
| 5 | * Author: Linus Walleij <linus.walleij@linaro.org> |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/mfd/syscon.h> |
| 9 | #include <linux/reboot.h> |
| 10 | #include <linux/regmap.h> |
| 11 | #include <linux/of.h> |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 12 | |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 13 | #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C |
| 14 | #define INTEGRATOR_HDR_LOCK_OFFSET 0x14 |
| 15 | #define INTEGRATOR_CM_CTRL_RESET (1 << 3) |
| 16 | |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 17 | #define VERSATILE_SYS_LOCK_OFFSET 0x20 |
| 18 | #define VERSATILE_SYS_RESETCTL_OFFSET 0x40 |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 19 | |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 20 | /* Magic unlocking token used on all Versatile boards */ |
| 21 | #define VERSATILE_LOCK_VAL 0xA05F |
| 22 | |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 23 | /* |
| 24 | * We detect the different syscon types from the compatible strings. |
| 25 | */ |
| 26 | enum versatile_reboot { |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 27 | INTEGRATOR_REBOOT_CM, |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 28 | VERSATILE_REBOOT_CM, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 29 | REALVIEW_REBOOT_EB, |
| 30 | REALVIEW_REBOOT_PB1176, |
| 31 | REALVIEW_REBOOT_PB11MP, |
| 32 | REALVIEW_REBOOT_PBA8, |
| 33 | REALVIEW_REBOOT_PBX, |
| 34 | }; |
| 35 | |
| 36 | /* Pointer to the system controller */ |
| 37 | static struct regmap *syscon_regmap; |
| 38 | static enum versatile_reboot versatile_reboot_type; |
| 39 | |
| 40 | static const struct of_device_id versatile_reboot_of_match[] = { |
| 41 | { |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 42 | .compatible = "arm,core-module-integrator", |
| 43 | .data = (void *)INTEGRATOR_REBOOT_CM |
| 44 | }, |
| 45 | { |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 46 | .compatible = "arm,core-module-versatile", |
| 47 | .data = (void *)VERSATILE_REBOOT_CM, |
| 48 | }, |
| 49 | { |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 50 | .compatible = "arm,realview-eb-syscon", |
| 51 | .data = (void *)REALVIEW_REBOOT_EB, |
| 52 | }, |
| 53 | { |
| 54 | .compatible = "arm,realview-pb1176-syscon", |
| 55 | .data = (void *)REALVIEW_REBOOT_PB1176, |
| 56 | }, |
| 57 | { |
| 58 | .compatible = "arm,realview-pb11mp-syscon", |
| 59 | .data = (void *)REALVIEW_REBOOT_PB11MP, |
| 60 | }, |
| 61 | { |
| 62 | .compatible = "arm,realview-pba8-syscon", |
| 63 | .data = (void *)REALVIEW_REBOOT_PBA8, |
| 64 | }, |
| 65 | { |
| 66 | .compatible = "arm,realview-pbx-syscon", |
| 67 | .data = (void *)REALVIEW_REBOOT_PBX, |
| 68 | }, |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 69 | {}, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
| Guenter Roeck | 25a5b57 | 2015-01-25 12:30:40 -0800 | [diff] [blame] | 72 | static int versatile_reboot(struct notifier_block *this, unsigned long mode, |
| 73 | void *cmd) |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 74 | { |
| 75 | /* Unlock the reset register */ |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 76 | /* Then hit reset on the different machines */ |
| 77 | switch (versatile_reboot_type) { |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 78 | case INTEGRATOR_REBOOT_CM: |
| 79 | regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET, |
| 80 | VERSATILE_LOCK_VAL); |
| 81 | regmap_update_bits(syscon_regmap, |
| 82 | INTEGRATOR_HDR_CTRL_OFFSET, |
| 83 | INTEGRATOR_CM_CTRL_RESET, |
| 84 | INTEGRATOR_CM_CTRL_RESET); |
| 85 | break; |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 86 | case VERSATILE_REBOOT_CM: |
| 87 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| 88 | VERSATILE_LOCK_VAL); |
| 89 | regmap_update_bits(syscon_regmap, |
| 90 | VERSATILE_SYS_RESETCTL_OFFSET, |
| 91 | 0x0107, |
| 92 | 0x0105); |
| 93 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| 94 | 0); |
| 95 | break; |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 96 | case REALVIEW_REBOOT_EB: |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 97 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 98 | VERSATILE_LOCK_VAL); |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 99 | regmap_write(syscon_regmap, |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 100 | VERSATILE_SYS_RESETCTL_OFFSET, 0x0008); |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 101 | break; |
| 102 | case REALVIEW_REBOOT_PB1176: |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 103 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 104 | VERSATILE_LOCK_VAL); |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 105 | regmap_write(syscon_regmap, |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 106 | VERSATILE_SYS_RESETCTL_OFFSET, 0x0100); |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 107 | break; |
| 108 | case REALVIEW_REBOOT_PB11MP: |
| 109 | case REALVIEW_REBOOT_PBA8: |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 110 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 111 | VERSATILE_LOCK_VAL); |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 112 | regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 113 | 0x0000); |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 114 | regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 115 | 0x0004); |
| 116 | break; |
| 117 | case REALVIEW_REBOOT_PBX: |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 118 | regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET, |
| Linus Walleij | 0160817 | 2014-12-19 16:56:27 +0100 | [diff] [blame] | 119 | VERSATILE_LOCK_VAL); |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 120 | regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 121 | 0x00f0); |
| Linus Walleij | 3f652c9 | 2016-01-25 09:29:53 +0100 | [diff] [blame] | 122 | regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET, |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 123 | 0x00f4); |
| 124 | break; |
| 125 | } |
| 126 | dsb(); |
| Guenter Roeck | 25a5b57 | 2015-01-25 12:30:40 -0800 | [diff] [blame] | 127 | |
| 128 | return NOTIFY_DONE; |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| Guenter Roeck | 25a5b57 | 2015-01-25 12:30:40 -0800 | [diff] [blame] | 131 | static struct notifier_block versatile_reboot_nb = { |
| 132 | .notifier_call = versatile_reboot, |
| 133 | .priority = 192, |
| 134 | }; |
| 135 | |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 136 | static int __init versatile_reboot_probe(void) |
| 137 | { |
| 138 | const struct of_device_id *reboot_id; |
| 139 | struct device_node *np; |
| Guenter Roeck | 25a5b57 | 2015-01-25 12:30:40 -0800 | [diff] [blame] | 140 | int err; |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 141 | |
| 142 | np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match, |
| 143 | &reboot_id); |
| 144 | if (!np) |
| 145 | return -ENODEV; |
| 146 | versatile_reboot_type = (enum versatile_reboot)reboot_id->data; |
| 147 | |
| 148 | syscon_regmap = syscon_node_to_regmap(np); |
| 149 | if (IS_ERR(syscon_regmap)) |
| 150 | return PTR_ERR(syscon_regmap); |
| 151 | |
| Guenter Roeck | 25a5b57 | 2015-01-25 12:30:40 -0800 | [diff] [blame] | 152 | err = register_restart_handler(&versatile_reboot_nb); |
| 153 | if (err) |
| 154 | return err; |
| 155 | |
| Linus Walleij | 0e545f5 | 2014-05-22 10:20:38 +0200 | [diff] [blame] | 156 | pr_info("versatile reboot driver registered\n"); |
| 157 | return 0; |
| 158 | } |
| 159 | device_initcall(versatile_reboot_probe); |