1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2002 ARM Ltd.
5 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
6 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/delay.h>
12 #include <linux/device.h>
14 #include <linux/of_address.h>
15 #include <linux/smp.h>
17 #include <linux/firmware/qcom/qcom_scm.h>
19 #include <asm/smp_plat.h>
22 #define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x35a0
23 #define SCSS_CPU1CORE_RESET 0x2d80
24 #define SCSS_DBG_STATUS_CORE_PWRDUP 0x2e64
26 #define APCS_CPU_PWR_CTL 0x04
27 #define PLL_CLAMP BIT(8)
28 #define CORE_PWRD_UP BIT(7)
29 #define COREPOR_RST BIT(5)
30 #define CORE_RST BIT(4)
31 #define L2DT_SLP BIT(3)
32 #define CORE_MEM_CLAMP BIT(1)
35 #define APC_PWR_GATE_CTL 0x14
36 #define BHS_CNT_SHIFT 24
37 #define LDO_PWR_DWN_SHIFT 16
38 #define LDO_BYP_SHIFT 8
39 #define BHS_SEG_SHIFT 1
42 #define APCS_SAW2_VCTL 0x14
43 #define APCS_SAW2_2_VCTL 0x1c
45 extern void secondary_startup_arm(void);
47 #ifdef CONFIG_HOTPLUG_CPU
48 static void qcom_cpu_die(unsigned int cpu
)
54 static int scss_release_secondary(unsigned int cpu
)
56 struct device_node
*node
;
59 node
= of_find_compatible_node(NULL
, NULL
, "qcom,gcc-msm8660");
61 pr_err("%s: can't find node\n", __func__
);
65 base
= of_iomap(node
, 0);
70 writel_relaxed(0, base
+ VDD_SC1_ARRAY_CLAMP_GFS_CTL
);
71 writel_relaxed(0, base
+ SCSS_CPU1CORE_RESET
);
72 writel_relaxed(3, base
+ SCSS_DBG_STATUS_CORE_PWRDUP
);
79 static int cortex_a7_release_secondary(unsigned int cpu
)
83 struct device_node
*cpu_node
, *acc_node
;
86 cpu_node
= of_get_cpu_node(cpu
, NULL
);
90 acc_node
= of_parse_phandle(cpu_node
, "qcom,acc", 0);
96 reg
= of_iomap(acc_node
, 0);
102 /* Put the CPU into reset. */
103 reg_val
= CORE_RST
| COREPOR_RST
| CLAMP
| CORE_MEM_CLAMP
;
104 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
106 /* Turn on the BHS and set the BHS_CNT to 16 XO clock cycles */
107 writel(BHS_EN
| (0x10 << BHS_CNT_SHIFT
), reg
+ APC_PWR_GATE_CTL
);
108 /* Wait for the BHS to settle */
111 reg_val
&= ~CORE_MEM_CLAMP
;
112 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
114 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
117 reg_val
= (reg_val
| BIT(17)) & ~CLAMP
;
118 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
121 /* Release CPU out of reset and bring it to life. */
122 reg_val
&= ~(CORE_RST
| COREPOR_RST
);
123 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
124 reg_val
|= CORE_PWRD_UP
;
125 writel(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
129 of_node_put(acc_node
);
131 of_node_put(cpu_node
);
135 static int kpssv1_release_secondary(unsigned int cpu
)
138 void __iomem
*reg
, *saw_reg
;
139 struct device_node
*cpu_node
, *acc_node
, *saw_node
;
142 cpu_node
= of_get_cpu_node(cpu
, NULL
);
146 acc_node
= of_parse_phandle(cpu_node
, "qcom,acc", 0);
152 saw_node
= of_parse_phandle(cpu_node
, "qcom,saw", 0);
158 reg
= of_iomap(acc_node
, 0);
164 saw_reg
= of_iomap(saw_node
, 0);
170 /* Turn on CPU rail */
171 writel_relaxed(0xA4, saw_reg
+ APCS_SAW2_VCTL
);
175 /* Krait bring-up sequence */
176 val
= PLL_CLAMP
| L2DT_SLP
| CLAMP
;
177 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
179 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
184 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
189 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
194 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
199 writel_relaxed(val
, reg
+ APCS_CPU_PWR_CTL
);
206 of_node_put(saw_node
);
208 of_node_put(acc_node
);
210 of_node_put(cpu_node
);
214 static int kpssv2_release_secondary(unsigned int cpu
)
217 struct device_node
*cpu_node
, *l2_node
, *acc_node
, *saw_node
;
218 void __iomem
*l2_saw_base
;
222 cpu_node
= of_get_cpu_node(cpu
, NULL
);
226 acc_node
= of_parse_phandle(cpu_node
, "qcom,acc", 0);
232 l2_node
= of_parse_phandle(cpu_node
, "next-level-cache", 0);
238 saw_node
= of_parse_phandle(l2_node
, "qcom,saw", 0);
244 reg
= of_iomap(acc_node
, 0);
250 l2_saw_base
= of_iomap(saw_node
, 0);
256 /* Turn on the BHS, turn off LDO Bypass and power down LDO */
257 reg_val
= (64 << BHS_CNT_SHIFT
) | (0x3f << LDO_PWR_DWN_SHIFT
) | BHS_EN
;
258 writel_relaxed(reg_val
, reg
+ APC_PWR_GATE_CTL
);
260 /* wait for the BHS to settle */
263 /* Turn on BHS segments */
264 reg_val
|= 0x3f << BHS_SEG_SHIFT
;
265 writel_relaxed(reg_val
, reg
+ APC_PWR_GATE_CTL
);
267 /* wait for the BHS to settle */
270 /* Finally turn on the bypass so that BHS supplies power */
271 reg_val
|= 0x3f << LDO_BYP_SHIFT
;
272 writel_relaxed(reg_val
, reg
+ APC_PWR_GATE_CTL
);
274 /* enable max phases */
275 writel_relaxed(0x10003, l2_saw_base
+ APCS_SAW2_2_VCTL
);
279 reg_val
= COREPOR_RST
| CLAMP
;
280 writel_relaxed(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
285 writel_relaxed(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
289 reg_val
&= ~COREPOR_RST
;
290 writel_relaxed(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
293 reg_val
|= CORE_PWRD_UP
;
294 writel_relaxed(reg_val
, reg
+ APCS_CPU_PWR_CTL
);
299 iounmap(l2_saw_base
);
303 of_node_put(saw_node
);
305 of_node_put(l2_node
);
307 of_node_put(acc_node
);
309 of_node_put(cpu_node
);
314 static DEFINE_PER_CPU(int, cold_boot_done
);
316 static int qcom_boot_secondary(unsigned int cpu
, int (*func
)(unsigned int))
320 if (!per_cpu(cold_boot_done
, cpu
)) {
323 per_cpu(cold_boot_done
, cpu
) = true;
327 * Send the secondary CPU a soft interrupt, thereby causing
328 * the boot monitor to read the system wide flags register,
329 * and branch to the address found there.
331 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
336 static int msm8660_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
338 return qcom_boot_secondary(cpu
, scss_release_secondary
);
341 static int cortex_a7_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
343 return qcom_boot_secondary(cpu
, cortex_a7_release_secondary
);
346 static int kpssv1_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
348 return qcom_boot_secondary(cpu
, kpssv1_release_secondary
);
351 static int kpssv2_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
353 return qcom_boot_secondary(cpu
, kpssv2_release_secondary
);
356 static void __init
qcom_smp_prepare_cpus(unsigned int max_cpus
)
360 if (qcom_scm_set_cold_boot_addr(secondary_startup_arm
)) {
361 for_each_present_cpu(cpu
) {
362 if (cpu
== smp_processor_id())
364 set_cpu_present(cpu
, false);
366 pr_warn("Failed to set CPU boot address, disabling SMP\n");
370 static const struct smp_operations smp_msm8660_ops __initconst
= {
371 .smp_prepare_cpus
= qcom_smp_prepare_cpus
,
372 .smp_boot_secondary
= msm8660_boot_secondary
,
373 #ifdef CONFIG_HOTPLUG_CPU
374 .cpu_die
= qcom_cpu_die
,
377 CPU_METHOD_OF_DECLARE(qcom_smp
, "qcom,gcc-msm8660", &smp_msm8660_ops
);
379 static const struct smp_operations qcom_smp_cortex_a7_ops __initconst
= {
380 .smp_prepare_cpus
= qcom_smp_prepare_cpus
,
381 .smp_boot_secondary
= cortex_a7_boot_secondary
,
382 #ifdef CONFIG_HOTPLUG_CPU
383 .cpu_die
= qcom_cpu_die
,
386 CPU_METHOD_OF_DECLARE(qcom_smp_msm8226
, "qcom,msm8226-smp", &qcom_smp_cortex_a7_ops
);
387 CPU_METHOD_OF_DECLARE(qcom_smp_msm8909
, "qcom,msm8909-smp", &qcom_smp_cortex_a7_ops
);
388 CPU_METHOD_OF_DECLARE(qcom_smp_msm8916
, "qcom,msm8916-smp", &qcom_smp_cortex_a7_ops
);
390 static const struct smp_operations qcom_smp_kpssv1_ops __initconst
= {
391 .smp_prepare_cpus
= qcom_smp_prepare_cpus
,
392 .smp_boot_secondary
= kpssv1_boot_secondary
,
393 #ifdef CONFIG_HOTPLUG_CPU
394 .cpu_die
= qcom_cpu_die
,
397 CPU_METHOD_OF_DECLARE(qcom_smp_kpssv1
, "qcom,kpss-acc-v1", &qcom_smp_kpssv1_ops
);
399 static const struct smp_operations qcom_smp_kpssv2_ops __initconst
= {
400 .smp_prepare_cpus
= qcom_smp_prepare_cpus
,
401 .smp_boot_secondary
= kpssv2_boot_secondary
,
402 #ifdef CONFIG_HOTPLUG_CPU
403 .cpu_die
= qcom_cpu_die
,
406 CPU_METHOD_OF_DECLARE(qcom_smp_kpssv2
, "qcom,kpss-acc-v2", &qcom_smp_kpssv2_ops
);