Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 1 | /* |
Thomas Petazzoni | df863de | 2014-02-17 15:23:22 +0100 | [diff] [blame] | 2 | * System controller support for Armada 370, 375 and XP platforms. |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2012 Marvell |
| 5 | * |
| 6 | * Lior Amsalem <alior@marvell.com> |
| 7 | * Gregory CLEMENT <gregory.clement@free-electrons.com> |
| 8 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 9 | * |
| 10 | * This file is licensed under the terms of the GNU General Public |
| 11 | * License version 2. This program is licensed "as is" without any |
| 12 | * warranty of any kind, whether express or implied. |
| 13 | * |
Thomas Petazzoni | df863de | 2014-02-17 15:23:22 +0100 | [diff] [blame] | 14 | * The Armada 370, 375 and Armada XP SoCs have a range of |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 15 | * miscellaneous registers, that do not belong to a particular device, |
| 16 | * but rather provide system-level features. This basic |
| 17 | * system-controller driver provides a device tree binding for those |
| 18 | * registers, and implements utility functions offering various |
| 19 | * features related to those registers. |
| 20 | * |
| 21 | * For now, the feature set is limited to restarting the platform by a |
| 22 | * soft-reset, but it might be extended in the future. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/of_address.h> |
| 28 | #include <linux/io.h> |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 29 | #include <linux/reboot.h> |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 30 | #include "common.h" |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 31 | |
| 32 | static void __iomem *system_controller_base; |
| 33 | |
| 34 | struct mvebu_system_controller { |
| 35 | u32 rstoutn_mask_offset; |
| 36 | u32 system_soft_reset_offset; |
| 37 | |
| 38 | u32 rstoutn_mask_reset_out_en; |
| 39 | u32 system_soft_reset; |
Gregory CLEMENT | 00504be | 2014-04-14 15:54:03 +0200 | [diff] [blame^] | 40 | |
| 41 | u32 resume_boot_addr; |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 42 | }; |
| 43 | static struct mvebu_system_controller *mvebu_sc; |
| 44 | |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 45 | static const struct mvebu_system_controller armada_370_xp_system_controller = { |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 46 | .rstoutn_mask_offset = 0x60, |
| 47 | .system_soft_reset_offset = 0x64, |
| 48 | .rstoutn_mask_reset_out_en = 0x1, |
| 49 | .system_soft_reset = 0x1, |
| 50 | }; |
| 51 | |
Thomas Petazzoni | df863de | 2014-02-17 15:23:22 +0100 | [diff] [blame] | 52 | static const struct mvebu_system_controller armada_375_system_controller = { |
| 53 | .rstoutn_mask_offset = 0x54, |
| 54 | .system_soft_reset_offset = 0x58, |
| 55 | .rstoutn_mask_reset_out_en = 0x1, |
| 56 | .system_soft_reset = 0x1, |
Gregory CLEMENT | 00504be | 2014-04-14 15:54:03 +0200 | [diff] [blame^] | 57 | .resume_boot_addr = 0xd4, |
Thomas Petazzoni | df863de | 2014-02-17 15:23:22 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 60 | static const struct mvebu_system_controller orion_system_controller = { |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 61 | .rstoutn_mask_offset = 0x108, |
| 62 | .system_soft_reset_offset = 0x10c, |
| 63 | .rstoutn_mask_reset_out_en = 0x4, |
| 64 | .system_soft_reset = 0x1, |
| 65 | }; |
| 66 | |
Josh Cartwright | a8cacc0 | 2014-02-11 10:24:02 -0600 | [diff] [blame] | 67 | static const struct of_device_id of_system_controller_table[] = { |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 68 | { |
| 69 | .compatible = "marvell,orion-system-controller", |
| 70 | .data = (void *) &orion_system_controller, |
| 71 | }, { |
| 72 | .compatible = "marvell,armada-370-xp-system-controller", |
| 73 | .data = (void *) &armada_370_xp_system_controller, |
Thomas Petazzoni | df863de | 2014-02-17 15:23:22 +0100 | [diff] [blame] | 74 | }, { |
| 75 | .compatible = "marvell,armada-375-system-controller", |
| 76 | .data = (void *) &armada_375_system_controller, |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 77 | }, |
| 78 | { /* end of list */ }, |
| 79 | }; |
| 80 | |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 81 | void mvebu_restart(enum reboot_mode mode, const char *cmd) |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 82 | { |
| 83 | if (!system_controller_base) { |
| 84 | pr_err("Cannot restart, system-controller not available: check the device tree\n"); |
| 85 | } else { |
| 86 | /* |
| 87 | * Enable soft reset to assert RSTOUTn. |
| 88 | */ |
| 89 | writel(mvebu_sc->rstoutn_mask_reset_out_en, |
| 90 | system_controller_base + |
| 91 | mvebu_sc->rstoutn_mask_offset); |
| 92 | /* |
| 93 | * Assert soft reset. |
| 94 | */ |
| 95 | writel(mvebu_sc->system_soft_reset, |
| 96 | system_controller_base + |
| 97 | mvebu_sc->system_soft_reset_offset); |
| 98 | } |
| 99 | |
| 100 | while (1) |
| 101 | ; |
| 102 | } |
| 103 | |
Gregory CLEMENT | 00504be | 2014-04-14 15:54:03 +0200 | [diff] [blame^] | 104 | #ifdef CONFIG_SMP |
| 105 | void mvebu_system_controller_set_cpu_boot_addr(void *boot_addr) |
| 106 | { |
| 107 | BUG_ON(system_controller_base == NULL); |
| 108 | BUG_ON(mvebu_sc->resume_boot_addr == 0); |
| 109 | writel(virt_to_phys(boot_addr), system_controller_base + |
| 110 | mvebu_sc->resume_boot_addr); |
| 111 | } |
| 112 | #endif |
| 113 | |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 114 | static int __init mvebu_system_controller_init(void) |
| 115 | { |
Josh Cartwright | a8cacc0 | 2014-02-11 10:24:02 -0600 | [diff] [blame] | 116 | const struct of_device_id *match; |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 117 | struct device_node *np; |
| 118 | |
Josh Cartwright | a8cacc0 | 2014-02-11 10:24:02 -0600 | [diff] [blame] | 119 | np = of_find_matching_node_and_match(NULL, of_system_controller_table, |
| 120 | &match); |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 121 | if (np) { |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 122 | system_controller_base = of_iomap(np, 0); |
| 123 | mvebu_sc = (struct mvebu_system_controller *)match->data; |
Jisheng Zhang | abe511a | 2013-08-27 12:41:14 +0800 | [diff] [blame] | 124 | of_node_put(np); |
Gregory CLEMENT | 31af49d | 2012-06-01 18:21:46 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Gregory CLEMENT | 00504be | 2014-04-14 15:54:03 +0200 | [diff] [blame^] | 130 | early_initcall(mvebu_system_controller_init); |