1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * System controller support for Armada 370, 375 and XP platforms.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2012 Marvell
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Lior Amsalem <alior@marvell.com>
7*4882a593Smuzhiyun * Gregory CLEMENT <gregory.clement@free-electrons.com>
8*4882a593Smuzhiyun * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * This file is licensed under the terms of the GNU General Public
11*4882a593Smuzhiyun * License version 2. This program is licensed "as is" without any
12*4882a593Smuzhiyun * warranty of any kind, whether express or implied.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The Armada 370, 375 and Armada XP SoCs have a range of
15*4882a593Smuzhiyun * miscellaneous registers, that do not belong to a particular device,
16*4882a593Smuzhiyun * but rather provide system-level features. This basic
17*4882a593Smuzhiyun * system-controller driver provides a device tree binding for those
18*4882a593Smuzhiyun * registers, and implements utility functions offering various
19*4882a593Smuzhiyun * features related to those registers.
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * For now, the feature set is limited to restarting the platform by a
22*4882a593Smuzhiyun * soft-reset, but it might be extended in the future.
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include <linux/kernel.h>
26*4882a593Smuzhiyun #include <linux/init.h>
27*4882a593Smuzhiyun #include <linux/of_address.h>
28*4882a593Smuzhiyun #include <linux/io.h>
29*4882a593Smuzhiyun #include <linux/reboot.h>
30*4882a593Smuzhiyun #include "common.h"
31*4882a593Smuzhiyun #include "mvebu-soc-id.h"
32*4882a593Smuzhiyun #include "pmsu.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define ARMADA_375_CRYPT0_ENG_TARGET 41
35*4882a593Smuzhiyun #define ARMADA_375_CRYPT0_ENG_ATTR 1
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun static void __iomem *system_controller_base;
38*4882a593Smuzhiyun static phys_addr_t system_controller_phys_base;
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun struct mvebu_system_controller {
41*4882a593Smuzhiyun u32 rstoutn_mask_offset;
42*4882a593Smuzhiyun u32 system_soft_reset_offset;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun u32 rstoutn_mask_reset_out_en;
45*4882a593Smuzhiyun u32 system_soft_reset;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun u32 resume_boot_addr;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun u32 dev_id;
50*4882a593Smuzhiyun u32 rev_id;
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun static struct mvebu_system_controller *mvebu_sc;
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun static const struct mvebu_system_controller armada_370_xp_system_controller = {
55*4882a593Smuzhiyun .rstoutn_mask_offset = 0x60,
56*4882a593Smuzhiyun .system_soft_reset_offset = 0x64,
57*4882a593Smuzhiyun .rstoutn_mask_reset_out_en = 0x1,
58*4882a593Smuzhiyun .system_soft_reset = 0x1,
59*4882a593Smuzhiyun .dev_id = 0x38,
60*4882a593Smuzhiyun .rev_id = 0x3c,
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun static const struct mvebu_system_controller armada_375_system_controller = {
64*4882a593Smuzhiyun .rstoutn_mask_offset = 0x54,
65*4882a593Smuzhiyun .system_soft_reset_offset = 0x58,
66*4882a593Smuzhiyun .rstoutn_mask_reset_out_en = 0x1,
67*4882a593Smuzhiyun .system_soft_reset = 0x1,
68*4882a593Smuzhiyun .resume_boot_addr = 0xd4,
69*4882a593Smuzhiyun .dev_id = 0x38,
70*4882a593Smuzhiyun .rev_id = 0x3c,
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static const struct mvebu_system_controller orion_system_controller = {
74*4882a593Smuzhiyun .rstoutn_mask_offset = 0x108,
75*4882a593Smuzhiyun .system_soft_reset_offset = 0x10c,
76*4882a593Smuzhiyun .rstoutn_mask_reset_out_en = 0x4,
77*4882a593Smuzhiyun .system_soft_reset = 0x1,
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun static const struct of_device_id of_system_controller_table[] = {
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun .compatible = "marvell,orion-system-controller",
83*4882a593Smuzhiyun .data = (void *) &orion_system_controller,
84*4882a593Smuzhiyun }, {
85*4882a593Smuzhiyun .compatible = "marvell,armada-370-xp-system-controller",
86*4882a593Smuzhiyun .data = (void *) &armada_370_xp_system_controller,
87*4882a593Smuzhiyun }, {
88*4882a593Smuzhiyun .compatible = "marvell,armada-375-system-controller",
89*4882a593Smuzhiyun .data = (void *) &armada_375_system_controller,
90*4882a593Smuzhiyun },
91*4882a593Smuzhiyun { /* end of list */ },
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun
mvebu_restart(enum reboot_mode mode,const char * cmd)94*4882a593Smuzhiyun void mvebu_restart(enum reboot_mode mode, const char *cmd)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun if (!system_controller_base) {
97*4882a593Smuzhiyun pr_err("Cannot restart, system-controller not available: check the device tree\n");
98*4882a593Smuzhiyun } else {
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun * Enable soft reset to assert RSTOUTn.
101*4882a593Smuzhiyun */
102*4882a593Smuzhiyun writel(mvebu_sc->rstoutn_mask_reset_out_en,
103*4882a593Smuzhiyun system_controller_base +
104*4882a593Smuzhiyun mvebu_sc->rstoutn_mask_offset);
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * Assert soft reset.
107*4882a593Smuzhiyun */
108*4882a593Smuzhiyun writel(mvebu_sc->system_soft_reset,
109*4882a593Smuzhiyun system_controller_base +
110*4882a593Smuzhiyun mvebu_sc->system_soft_reset_offset);
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun while (1)
114*4882a593Smuzhiyun ;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
mvebu_system_controller_get_soc_id(u32 * dev,u32 * rev)117*4882a593Smuzhiyun int mvebu_system_controller_get_soc_id(u32 *dev, u32 *rev)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun if (of_machine_is_compatible("marvell,armada380") &&
120*4882a593Smuzhiyun system_controller_base) {
121*4882a593Smuzhiyun *dev = readl(system_controller_base + mvebu_sc->dev_id) >> 16;
122*4882a593Smuzhiyun *rev = (readl(system_controller_base + mvebu_sc->rev_id) >> 8)
123*4882a593Smuzhiyun & 0xF;
124*4882a593Smuzhiyun return 0;
125*4882a593Smuzhiyun } else
126*4882a593Smuzhiyun return -ENODEV;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun #if defined(CONFIG_SMP) && defined(CONFIG_MACH_MVEBU_V7)
mvebu_armada375_smp_wa_init(void)130*4882a593Smuzhiyun static void mvebu_armada375_smp_wa_init(void)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun u32 dev, rev;
133*4882a593Smuzhiyun phys_addr_t resume_addr_reg;
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun if (mvebu_get_soc_id(&dev, &rev) != 0)
136*4882a593Smuzhiyun return;
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun if (rev != ARMADA_375_Z1_REV)
139*4882a593Smuzhiyun return;
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun resume_addr_reg = system_controller_phys_base +
142*4882a593Smuzhiyun mvebu_sc->resume_boot_addr;
143*4882a593Smuzhiyun mvebu_setup_boot_addr_wa(ARMADA_375_CRYPT0_ENG_TARGET,
144*4882a593Smuzhiyun ARMADA_375_CRYPT0_ENG_ATTR,
145*4882a593Smuzhiyun resume_addr_reg);
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun
mvebu_system_controller_set_cpu_boot_addr(void * boot_addr)148*4882a593Smuzhiyun void mvebu_system_controller_set_cpu_boot_addr(void *boot_addr)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun BUG_ON(system_controller_base == NULL);
151*4882a593Smuzhiyun BUG_ON(mvebu_sc->resume_boot_addr == 0);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun if (of_machine_is_compatible("marvell,armada375"))
154*4882a593Smuzhiyun mvebu_armada375_smp_wa_init();
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun writel(__pa_symbol(boot_addr), system_controller_base +
157*4882a593Smuzhiyun mvebu_sc->resume_boot_addr);
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun #endif
160*4882a593Smuzhiyun
mvebu_system_controller_init(void)161*4882a593Smuzhiyun static int __init mvebu_system_controller_init(void)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun const struct of_device_id *match;
164*4882a593Smuzhiyun struct device_node *np;
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun np = of_find_matching_node_and_match(NULL, of_system_controller_table,
167*4882a593Smuzhiyun &match);
168*4882a593Smuzhiyun if (np) {
169*4882a593Smuzhiyun struct resource res;
170*4882a593Smuzhiyun system_controller_base = of_iomap(np, 0);
171*4882a593Smuzhiyun of_address_to_resource(np, 0, &res);
172*4882a593Smuzhiyun system_controller_phys_base = res.start;
173*4882a593Smuzhiyun mvebu_sc = (struct mvebu_system_controller *)match->data;
174*4882a593Smuzhiyun of_node_put(np);
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun early_initcall(mvebu_system_controller_init);
181