aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-rockchip/platsmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-rockchip/platsmp.c')
-rw-r--r--arch/arm/mach-rockchip/platsmp.c223
1 files changed, 180 insertions, 43 deletions
diff --git a/arch/arm/mach-rockchip/platsmp.c b/arch/arm/mach-rockchip/platsmp.c
index 189684f55927..f26fcdca2445 100644
--- a/arch/arm/mach-rockchip/platsmp.c
+++ b/arch/arm/mach-rockchip/platsmp.c
@@ -19,7 +19,11 @@
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_address.h> 21#include <linux/of_address.h>
22#include <linux/regmap.h>
23#include <linux/mfd/syscon.h>
22 24
25#include <linux/reset.h>
26#include <linux/cpu.h>
23#include <asm/cacheflush.h> 27#include <asm/cacheflush.h>
24#include <asm/cp15.h> 28#include <asm/cp15.h>
25#include <asm/smp_scu.h> 29#include <asm/smp_scu.h>
@@ -37,23 +41,78 @@ static int ncores;
37 41
38#define PMU_PWRDN_SCU 4 42#define PMU_PWRDN_SCU 4
39 43
40static void __iomem *pmu_base_addr; 44static struct regmap *pmu;
41 45
42static inline bool pmu_power_domain_is_on(int pd) 46static int pmu_power_domain_is_on(int pd)
43{ 47{
44 return !(readl_relaxed(pmu_base_addr + PMU_PWRDN_ST) & BIT(pd)); 48 u32 val;
49 int ret;
50
51 ret = regmap_read(pmu, PMU_PWRDN_ST, &val);
52 if (ret < 0)
53 return ret;
54
55 return !(val & BIT(pd));
45} 56}
46 57
47static void pmu_set_power_domain(int pd, bool on) 58struct reset_control *rockchip_get_core_reset(int cpu)
48{ 59{
49 u32 val = readl_relaxed(pmu_base_addr + PMU_PWRDN_CON); 60 struct device *dev = get_cpu_device(cpu);
50 if (on) 61 struct device_node *np;
51 val &= ~BIT(pd); 62
63 /* The cpu device is only available after the initial core bringup */
64 if (dev)
65 np = dev->of_node;
52 else 66 else
53 val |= BIT(pd); 67 np = of_get_cpu_node(cpu, 0);
54 writel(val, pmu_base_addr + PMU_PWRDN_CON);
55 68
56 while (pmu_power_domain_is_on(pd) != on) { } 69 return of_reset_control_get(np, NULL);
70}
71
72static int pmu_set_power_domain(int pd, bool on)
73{
74 u32 val = (on) ? 0 : BIT(pd);
75 int ret;
76
77 /*
78 * We need to soft reset the cpu when we turn off the cpu power domain,
79 * or else the active processors might be stalled when the individual
80 * processor is powered down.
81 */
82 if (read_cpuid_part() != ARM_CPU_PART_CORTEX_A9) {
83 struct reset_control *rstc = rockchip_get_core_reset(pd);
84
85 if (IS_ERR(rstc)) {
86 pr_err("%s: could not get reset control for core %d\n",
87 __func__, pd);
88 return PTR_ERR(rstc);
89 }
90
91 if (on)
92 reset_control_deassert(rstc);
93 else
94 reset_control_assert(rstc);
95
96 reset_control_put(rstc);
97 }
98
99 ret = regmap_update_bits(pmu, PMU_PWRDN_CON, BIT(pd), val);
100 if (ret < 0) {
101 pr_err("%s: could not update power domain\n", __func__);
102 return ret;
103 }
104
105 ret = -1;
106 while (ret != on) {
107 ret = pmu_power_domain_is_on(pd);
108 if (ret < 0) {
109 pr_err("%s: could not read power domain state\n",
110 __func__);
111 return ret;
112 }
113 }
114
115 return 0;
57} 116}
58 117
59/* 118/*
@@ -63,7 +122,9 @@ static void pmu_set_power_domain(int pd, bool on)
63static int __cpuinit rockchip_boot_secondary(unsigned int cpu, 122static int __cpuinit rockchip_boot_secondary(unsigned int cpu,
64 struct task_struct *idle) 123 struct task_struct *idle)
65{ 124{
66 if (!sram_base_addr || !pmu_base_addr) { 125 int ret;
126
127 if (!sram_base_addr || !pmu) {
67 pr_err("%s: sram or pmu missing for cpu boot\n", __func__); 128 pr_err("%s: sram or pmu missing for cpu boot\n", __func__);
68 return -ENXIO; 129 return -ENXIO;
69 } 130 }
@@ -75,7 +136,24 @@ static int __cpuinit rockchip_boot_secondary(unsigned int cpu,
75 } 136 }
76 137
77 /* start the core */ 138 /* start the core */
78 pmu_set_power_domain(0 + cpu, true); 139 ret = pmu_set_power_domain(0 + cpu, true);
140 if (ret < 0)
141 return ret;
142
143 if (read_cpuid_part() != ARM_CPU_PART_CORTEX_A9) {
144 /* We communicate with the bootrom to active the cpus other
145 * than cpu0, after a blob of initialize code, they will
146 * stay at wfe state, once they are actived, they will check
147 * the mailbox:
148 * sram_base_addr + 4: 0xdeadbeaf
149 * sram_base_addr + 8: start address for pc
150 * */
151 udelay(10);
152 writel(virt_to_phys(rockchip_secondary_startup),
153 sram_base_addr + 8);
154 writel(0xDEADBEAF, sram_base_addr + 4);
155 dsb_sev();
156 }
79 157
80 return 0; 158 return 0;
81} 159}
@@ -110,8 +188,6 @@ static int __init rockchip_smp_prepare_sram(struct device_node *node)
110 return -EINVAL; 188 return -EINVAL;
111 } 189 }
112 190
113 sram_base_addr = of_iomap(node, 0);
114
115 /* set the boot function for the sram code */ 191 /* set the boot function for the sram code */
116 rockchip_boot_fn = virt_to_phys(rockchip_secondary_startup); 192 rockchip_boot_fn = virt_to_phys(rockchip_secondary_startup);
117 193
@@ -125,54 +201,115 @@ static int __init rockchip_smp_prepare_sram(struct device_node *node)
125 return 0; 201 return 0;
126} 202}
127 203
128static void __init rockchip_smp_prepare_cpus(unsigned int max_cpus) 204static struct regmap_config rockchip_pmu_regmap_config = {
205 .reg_bits = 32,
206 .val_bits = 32,
207 .reg_stride = 4,
208};
209
210static int __init rockchip_smp_prepare_pmu(void)
129{ 211{
130 struct device_node *node; 212 struct device_node *node;
131 unsigned int i; 213 void __iomem *pmu_base;
132 214
133 node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu"); 215 /*
216 * This function is only called via smp_ops->smp_prepare_cpu().
217 * That only happens if a "/cpus" device tree node exists
218 * and has an "enable-method" property that selects the SMP
219 * operations defined herein.
220 */
221 node = of_find_node_by_path("/cpus");
222
223 pmu = syscon_regmap_lookup_by_phandle(node, "rockchip,pmu");
224 of_node_put(node);
225 if (!IS_ERR(pmu))
226 return 0;
227
228 pmu = syscon_regmap_lookup_by_compatible("rockchip,rk3066-pmu");
229 if (!IS_ERR(pmu))
230 return 0;
231
232 /* fallback, create our own regmap for the pmu area */
233 pmu = NULL;
234 node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-pmu");
134 if (!node) { 235 if (!node) {
135 pr_err("%s: missing scu\n", __func__); 236 pr_err("%s: could not find pmu dt node\n", __func__);
136 return; 237 return -ENODEV;
137 } 238 }
138 239
139 scu_base_addr = of_iomap(node, 0); 240 pmu_base = of_iomap(node, 0);
140 if (!scu_base_addr) { 241 if (!pmu_base) {
141 pr_err("%s: could not map scu registers\n", __func__); 242 pr_err("%s: could not map pmu registers\n", __func__);
142 return; 243 return -ENOMEM;
143 } 244 }
144 245
145 node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-smp-sram"); 246 pmu = regmap_init_mmio(NULL, pmu_base, &rockchip_pmu_regmap_config);
146 if (!node) { 247 if (IS_ERR(pmu)) {
147 pr_err("%s: could not find sram dt node\n", __func__); 248 int ret = PTR_ERR(pmu);
148 return; 249
250 iounmap(pmu_base);
251 pmu = NULL;
252 pr_err("%s: regmap init failed\n", __func__);
253 return ret;
149 } 254 }
150 255
151 if (rockchip_smp_prepare_sram(node)) 256 return 0;
152 return; 257}
153 258
154 node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-pmu"); 259static void __init rockchip_smp_prepare_cpus(unsigned int max_cpus)
260{
261 struct device_node *node;
262 unsigned int i;
263
264 node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-smp-sram");
155 if (!node) { 265 if (!node) {
156 pr_err("%s: could not find pmu dt node\n", __func__); 266 pr_err("%s: could not find sram dt node\n", __func__);
157 return; 267 return;
158 } 268 }
159 269
160 pmu_base_addr = of_iomap(node, 0); 270 sram_base_addr = of_iomap(node, 0);
161 if (!pmu_base_addr) { 271 if (!sram_base_addr) {
162 pr_err("%s: could not map pmu registers\n", __func__); 272 pr_err("%s: could not map sram registers\n", __func__);
163 return; 273 return;
164 } 274 }
165 275
166 /* enable the SCU power domain */ 276 if (rockchip_smp_prepare_pmu())
167 pmu_set_power_domain(PMU_PWRDN_SCU, true); 277 return;
168
169 /*
170 * While the number of cpus is gathered from dt, also get the number
171 * of cores from the scu to verify this value when booting the cores.
172 */
173 ncores = scu_get_core_count(scu_base_addr);
174 278
175 scu_enable(scu_base_addr); 279 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
280 if (rockchip_smp_prepare_sram(node))
281 return;
282
283 /* enable the SCU power domain */
284 pmu_set_power_domain(PMU_PWRDN_SCU, true);
285
286 node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
287 if (!node) {
288 pr_err("%s: missing scu\n", __func__);
289 return;
290 }
291
292 scu_base_addr = of_iomap(node, 0);
293 if (!scu_base_addr) {
294 pr_err("%s: could not map scu registers\n", __func__);
295 return;
296 }
297
298 /*
299 * While the number of cpus is gathered from dt, also get the
300 * number of cores from the scu to verify this value when
301 * booting the cores.
302 */
303 ncores = scu_get_core_count(scu_base_addr);
304 pr_err("%s: ncores %d\n", __func__, ncores);
305
306 scu_enable(scu_base_addr);
307 } else {
308 unsigned int l2ctlr;
309
310 asm ("mrc p15, 1, %0, c9, c0, 2\n" : "=r" (l2ctlr));
311 ncores = ((l2ctlr >> 24) & 0x3) + 1;
312 }
176 313
177 /* Make sure that all cores except the first are really off */ 314 /* Make sure that all cores except the first are really off */
178 for (i = 1; i < ncores; i++) 315 for (i = 1; i < ncores; i++)