2 * Copyright 2014 Linaro Ltd.
3 * Copyright (C) 2014 ZTE Corporation.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/delay.h>
11 #include <linux/errno.h>
12 #include <linux/init.h>
14 #include <linux/jiffies.h>
16 #include <linux/of_address.h>
17 #include <linux/smp.h>
19 #include <asm/cacheflush.h>
21 #include <asm/fncpy.h>
22 #include <asm/proc-fns.h>
23 #include <asm/smp_scu.h>
24 #include <asm/smp_plat.h>
28 #define AON_SYS_CTRL_RESERVED1 0xa8
30 #define BUS_MATRIX_REMAP_CONFIG 0x00
32 #define PCU_CPU0_CTRL 0x00
33 #define PCU_CPU1_CTRL 0x04
34 #define PCU_CPU1_ST 0x0c
35 #define PCU_GLOBAL_CTRL 0x14
36 #define PCU_EXPEND_CONTROL 0x34
38 #define ZX_IRAM_BASE 0x00200000
40 static void __iomem *pcu_base;
41 static void __iomem *matrix_base;
42 static void __iomem *scu_base;
44 void __init zx_smp_prepare_cpus(unsigned int max_cpus)
46 struct device_node *np;
47 unsigned long base = 0;
48 void __iomem *aonsysctrl_base;
49 void __iomem *sys_iram;
51 base = scu_a9_get_base();
52 scu_base = ioremap(base, SZ_256);
54 pr_err("%s: failed to map scu\n", __func__);
60 np = of_find_compatible_node(NULL, NULL, "zte,sysctrl");
62 pr_err("%s: failed to find sysctrl node\n", __func__);
66 aonsysctrl_base = of_iomap(np, 0);
67 if (!aonsysctrl_base) {
68 pr_err("%s: failed to map aonsysctrl\n", __func__);
74 * Write the address of secondary startup into the
75 * system-wide flags register. The BootMonitor waits
76 * until it receives a soft interrupt, and then the
77 * secondary CPU branches to this address.
79 __raw_writel(__pa_symbol(zx_secondary_startup),
80 aonsysctrl_base + AON_SYS_CTRL_RESERVED1);
82 iounmap(aonsysctrl_base);
85 np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
86 pcu_base = of_iomap(np, 0);
90 np = of_find_compatible_node(NULL, NULL, "zte,zx-bus-matrix");
91 matrix_base = of_iomap(np, 0);
93 WARN_ON(!matrix_base);
95 /* Map the first 4 KB IRAM for suspend usage */
96 sys_iram = __arm_ioremap_exec(ZX_IRAM_BASE, PAGE_SIZE, false);
97 zx_secondary_startup_pa = __pa_symbol(zx_secondary_startup);
98 fncpy(sys_iram, &zx_resume_jump, zx_suspend_iram_sz);
101 static int zx_boot_secondary(unsigned int cpu, struct task_struct *idle)
103 static bool first_boot = true;
106 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
111 /* Swap the base address mapping between IRAM and IROM */
112 writel_relaxed(0x1, matrix_base + BUS_MATRIX_REMAP_CONFIG);
115 writel_relaxed(0x0, pcu_base + PCU_CPU1_CTRL);
117 /* Wait for power on ack */
118 while (readl_relaxed(pcu_base + PCU_CPU1_ST) & 0x4)
121 /* Swap back the mapping of IRAM and IROM */
122 writel_relaxed(0x0, matrix_base + BUS_MATRIX_REMAP_CONFIG);
127 #ifdef CONFIG_HOTPLUG_CPU
128 static inline void cpu_enter_lowpower(void)
133 "mcr p15, 0, %1, c7, c5, 0\n"
134 " mcr p15, 0, %1, c7, c10, 4\n"
138 " mrc p15, 0, %0, c1, c0, 1\n"
140 " mcr p15, 0, %0, c1, c0, 1\n"
141 " mrc p15, 0, %0, c1, c0, 0\n"
143 " mcr p15, 0, %0, c1, c0, 0\n"
145 : "r" (0), "Ir" (CR_C), "Ir" (0x40)
149 static int zx_cpu_kill(unsigned int cpu)
151 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
153 writel_relaxed(0x2, pcu_base + PCU_CPU1_CTRL);
155 while ((readl_relaxed(pcu_base + PCU_CPU1_ST) & 0x3) != 0x0) {
156 if (time_after(jiffies, timeout)) {
157 pr_err("*** cpu1 poweroff timeout\n");
164 static void zx_cpu_die(unsigned int cpu)
166 scu_power_mode(scu_base, SCU_PM_POWEROFF);
167 cpu_enter_lowpower();
174 static void zx_secondary_init(unsigned int cpu)
176 scu_power_mode(scu_base, SCU_PM_NORMAL);
179 static const struct smp_operations zx_smp_ops __initconst = {
180 .smp_prepare_cpus = zx_smp_prepare_cpus,
181 .smp_secondary_init = zx_secondary_init,
182 .smp_boot_secondary = zx_boot_secondary,
183 #ifdef CONFIG_HOTPLUG_CPU
184 .cpu_kill = zx_cpu_kill,
185 .cpu_die = zx_cpu_die,
189 CPU_METHOD_OF_DECLARE(zx_smp, "zte,zx296702-smp", &zx_smp_ops);