1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2014 Linaro Ltd.
4 * Copyright (C) 2014 ZTE Corporation.
7 #include <linux/delay.h>
8 #include <linux/errno.h>
9 #include <linux/init.h>
11 #include <linux/jiffies.h>
13 #include <linux/of_address.h>
14 #include <linux/smp.h>
16 #include <asm/cacheflush.h>
18 #include <asm/fncpy.h>
19 #include <asm/proc-fns.h>
20 #include <asm/smp_scu.h>
21 #include <asm/smp_plat.h>
25 #define AON_SYS_CTRL_RESERVED1 0xa8
27 #define BUS_MATRIX_REMAP_CONFIG 0x00
29 #define PCU_CPU0_CTRL 0x00
30 #define PCU_CPU1_CTRL 0x04
31 #define PCU_CPU1_ST 0x0c
32 #define PCU_GLOBAL_CTRL 0x14
33 #define PCU_EXPEND_CONTROL 0x34
35 #define ZX_IRAM_BASE 0x00200000
37 static void __iomem
*pcu_base
;
38 static void __iomem
*matrix_base
;
39 static void __iomem
*scu_base
;
41 void __init
zx_smp_prepare_cpus(unsigned int max_cpus
)
43 struct device_node
*np
;
44 unsigned long base
= 0;
45 void __iomem
*aonsysctrl_base
;
46 void __iomem
*sys_iram
;
48 base
= scu_a9_get_base();
49 scu_base
= ioremap(base
, SZ_256
);
51 pr_err("%s: failed to map scu\n", __func__
);
57 np
= of_find_compatible_node(NULL
, NULL
, "zte,sysctrl");
59 pr_err("%s: failed to find sysctrl node\n", __func__
);
63 aonsysctrl_base
= of_iomap(np
, 0);
64 if (!aonsysctrl_base
) {
65 pr_err("%s: failed to map aonsysctrl\n", __func__
);
71 * Write the address of secondary startup into the
72 * system-wide flags register. The BootMonitor waits
73 * until it receives a soft interrupt, and then the
74 * secondary CPU branches to this address.
76 __raw_writel(__pa_symbol(zx_secondary_startup
),
77 aonsysctrl_base
+ AON_SYS_CTRL_RESERVED1
);
79 iounmap(aonsysctrl_base
);
82 np
= of_find_compatible_node(NULL
, NULL
, "zte,zx296702-pcu");
83 pcu_base
= of_iomap(np
, 0);
87 np
= of_find_compatible_node(NULL
, NULL
, "zte,zx-bus-matrix");
88 matrix_base
= of_iomap(np
, 0);
90 WARN_ON(!matrix_base
);
92 /* Map the first 4 KB IRAM for suspend usage */
93 sys_iram
= __arm_ioremap_exec(ZX_IRAM_BASE
, PAGE_SIZE
, false);
94 zx_secondary_startup_pa
= __pa_symbol(zx_secondary_startup
);
95 fncpy(sys_iram
, &zx_resume_jump
, zx_suspend_iram_sz
);
98 static int zx_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
100 static bool first_boot
= true;
103 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
108 /* Swap the base address mapping between IRAM and IROM */
109 writel_relaxed(0x1, matrix_base
+ BUS_MATRIX_REMAP_CONFIG
);
112 writel_relaxed(0x0, pcu_base
+ PCU_CPU1_CTRL
);
114 /* Wait for power on ack */
115 while (readl_relaxed(pcu_base
+ PCU_CPU1_ST
) & 0x4)
118 /* Swap back the mapping of IRAM and IROM */
119 writel_relaxed(0x0, matrix_base
+ BUS_MATRIX_REMAP_CONFIG
);
124 #ifdef CONFIG_HOTPLUG_CPU
125 static inline void cpu_enter_lowpower(void)
130 "mcr p15, 0, %1, c7, c5, 0\n"
131 " mcr p15, 0, %1, c7, c10, 4\n"
135 " mrc p15, 0, %0, c1, c0, 1\n"
137 " mcr p15, 0, %0, c1, c0, 1\n"
138 " mrc p15, 0, %0, c1, c0, 0\n"
140 " mcr p15, 0, %0, c1, c0, 0\n"
142 : "r" (0), "Ir" (CR_C
), "Ir" (0x40)
146 static int zx_cpu_kill(unsigned int cpu
)
148 unsigned long timeout
= jiffies
+ msecs_to_jiffies(2000);
150 writel_relaxed(0x2, pcu_base
+ PCU_CPU1_CTRL
);
152 while ((readl_relaxed(pcu_base
+ PCU_CPU1_ST
) & 0x3) != 0x0) {
153 if (time_after(jiffies
, timeout
)) {
154 pr_err("*** cpu1 poweroff timeout\n");
161 static void zx_cpu_die(unsigned int cpu
)
163 scu_power_mode(scu_base
, SCU_PM_POWEROFF
);
164 cpu_enter_lowpower();
171 static void zx_secondary_init(unsigned int cpu
)
173 scu_power_mode(scu_base
, SCU_PM_NORMAL
);
176 static const struct smp_operations zx_smp_ops __initconst
= {
177 .smp_prepare_cpus
= zx_smp_prepare_cpus
,
178 .smp_secondary_init
= zx_secondary_init
,
179 .smp_boot_secondary
= zx_boot_secondary
,
180 #ifdef CONFIG_HOTPLUG_CPU
181 .cpu_kill
= zx_cpu_kill
,
182 .cpu_die
= zx_cpu_die
,
186 CPU_METHOD_OF_DECLARE(zx_smp
, "zte,zx296702-smp", &zx_smp_ops
);