platsmp.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2002 ARM Ltd.
  4. * All Rights Reserved
  5. * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  6. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/errno.h>
  10. #include <linux/delay.h>
  11. #include <linux/device.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/smp.h>
  15. #include <linux/io.h>
  16. #include <linux/qcom_scm.h>
  17. #include <asm/smp_plat.h>
  18. #define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x35a0
  19. #define SCSS_CPU1CORE_RESET 0x2d80
  20. #define SCSS_DBG_STATUS_CORE_PWRDUP 0x2e64
  21. #define APCS_CPU_PWR_CTL 0x04
  22. #define PLL_CLAMP BIT(8)
  23. #define CORE_PWRD_UP BIT(7)
  24. #define COREPOR_RST BIT(5)
  25. #define CORE_RST BIT(4)
  26. #define L2DT_SLP BIT(3)
  27. #define CORE_MEM_CLAMP BIT(1)
  28. #define CLAMP BIT(0)
  29. #define APC_PWR_GATE_CTL 0x14
  30. #define BHS_CNT_SHIFT 24
  31. #define LDO_PWR_DWN_SHIFT 16
  32. #define LDO_BYP_SHIFT 8
  33. #define BHS_SEG_SHIFT 1
  34. #define BHS_EN BIT(0)
  35. #define APCS_SAW2_VCTL 0x14
  36. #define APCS_SAW2_2_VCTL 0x1c
  37. extern void secondary_startup_arm(void);
  38. #ifdef CONFIG_HOTPLUG_CPU
  39. static void qcom_cpu_die(unsigned int cpu)
  40. {
  41. wfi();
  42. }
  43. #endif
  44. static int scss_release_secondary(unsigned int cpu)
  45. {
  46. struct device_node *node;
  47. void __iomem *base;
  48. node = of_find_compatible_node(NULL, NULL, "qcom,gcc-msm8660");
  49. if (!node) {
  50. pr_err("%s: can't find node\n", __func__);
  51. return -ENXIO;
  52. }
  53. base = of_iomap(node, 0);
  54. of_node_put(node);
  55. if (!base)
  56. return -ENOMEM;
  57. writel_relaxed(0, base + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
  58. writel_relaxed(0, base + SCSS_CPU1CORE_RESET);
  59. writel_relaxed(3, base + SCSS_DBG_STATUS_CORE_PWRDUP);
  60. mb();
  61. iounmap(base);
  62. return 0;
  63. }
  64. static int cortex_a7_release_secondary(unsigned int cpu)
  65. {
  66. int ret = 0;
  67. void __iomem *reg;
  68. struct device_node *cpu_node, *acc_node;
  69. u32 reg_val;
  70. cpu_node = of_get_cpu_node(cpu, NULL);
  71. if (!cpu_node)
  72. return -ENODEV;
  73. acc_node = of_parse_phandle(cpu_node, "qcom,acc", 0);
  74. if (!acc_node) {
  75. ret = -ENODEV;
  76. goto out_acc;
  77. }
  78. reg = of_iomap(acc_node, 0);
  79. if (!reg) {
  80. ret = -ENOMEM;
  81. goto out_acc_map;
  82. }
  83. /* Put the CPU into reset. */
  84. reg_val = CORE_RST | COREPOR_RST | CLAMP | CORE_MEM_CLAMP;
  85. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  86. /* Turn on the BHS and set the BHS_CNT to 16 XO clock cycles */
  87. writel(BHS_EN | (0x10 << BHS_CNT_SHIFT), reg + APC_PWR_GATE_CTL);
  88. /* Wait for the BHS to settle */
  89. udelay(2);
  90. reg_val &= ~CORE_MEM_CLAMP;
  91. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  92. reg_val |= L2DT_SLP;
  93. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  94. udelay(2);
  95. reg_val = (reg_val | BIT(17)) & ~CLAMP;
  96. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  97. udelay(2);
  98. /* Release CPU out of reset and bring it to life. */
  99. reg_val &= ~(CORE_RST | COREPOR_RST);
  100. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  101. reg_val |= CORE_PWRD_UP;
  102. writel(reg_val, reg + APCS_CPU_PWR_CTL);
  103. iounmap(reg);
  104. out_acc_map:
  105. of_node_put(acc_node);
  106. out_acc:
  107. of_node_put(cpu_node);
  108. return ret;
  109. }
  110. static int kpssv1_release_secondary(unsigned int cpu)
  111. {
  112. int ret = 0;
  113. void __iomem *reg, *saw_reg;
  114. struct device_node *cpu_node, *acc_node, *saw_node;
  115. u32 val;
  116. cpu_node = of_get_cpu_node(cpu, NULL);
  117. if (!cpu_node)
  118. return -ENODEV;
  119. acc_node = of_parse_phandle(cpu_node, "qcom,acc", 0);
  120. if (!acc_node) {
  121. ret = -ENODEV;
  122. goto out_acc;
  123. }
  124. saw_node = of_parse_phandle(cpu_node, "qcom,saw", 0);
  125. if (!saw_node) {
  126. ret = -ENODEV;
  127. goto out_saw;
  128. }
  129. reg = of_iomap(acc_node, 0);
  130. if (!reg) {
  131. ret = -ENOMEM;
  132. goto out_acc_map;
  133. }
  134. saw_reg = of_iomap(saw_node, 0);
  135. if (!saw_reg) {
  136. ret = -ENOMEM;
  137. goto out_saw_map;
  138. }
  139. /* Turn on CPU rail */
  140. writel_relaxed(0xA4, saw_reg + APCS_SAW2_VCTL);
  141. mb();
  142. udelay(512);
  143. /* Krait bring-up sequence */
  144. val = PLL_CLAMP | L2DT_SLP | CLAMP;
  145. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  146. val &= ~L2DT_SLP;
  147. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  148. mb();
  149. ndelay(300);
  150. val |= COREPOR_RST;
  151. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  152. mb();
  153. udelay(2);
  154. val &= ~CLAMP;
  155. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  156. mb();
  157. udelay(2);
  158. val &= ~COREPOR_RST;
  159. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  160. mb();
  161. udelay(100);
  162. val |= CORE_PWRD_UP;
  163. writel_relaxed(val, reg + APCS_CPU_PWR_CTL);
  164. mb();
  165. iounmap(saw_reg);
  166. out_saw_map:
  167. iounmap(reg);
  168. out_acc_map:
  169. of_node_put(saw_node);
  170. out_saw:
  171. of_node_put(acc_node);
  172. out_acc:
  173. of_node_put(cpu_node);
  174. return ret;
  175. }
  176. static int kpssv2_release_secondary(unsigned int cpu)
  177. {
  178. void __iomem *reg;
  179. struct device_node *cpu_node, *l2_node, *acc_node, *saw_node;
  180. void __iomem *l2_saw_base;
  181. unsigned reg_val;
  182. int ret;
  183. cpu_node = of_get_cpu_node(cpu, NULL);
  184. if (!cpu_node)
  185. return -ENODEV;
  186. acc_node = of_parse_phandle(cpu_node, "qcom,acc", 0);
  187. if (!acc_node) {
  188. ret = -ENODEV;
  189. goto out_acc;
  190. }
  191. l2_node = of_parse_phandle(cpu_node, "next-level-cache", 0);
  192. if (!l2_node) {
  193. ret = -ENODEV;
  194. goto out_l2;
  195. }
  196. saw_node = of_parse_phandle(l2_node, "qcom,saw", 0);
  197. if (!saw_node) {
  198. ret = -ENODEV;
  199. goto out_saw;
  200. }
  201. reg = of_iomap(acc_node, 0);
  202. if (!reg) {
  203. ret = -ENOMEM;
  204. goto out_map;
  205. }
  206. l2_saw_base = of_iomap(saw_node, 0);
  207. if (!l2_saw_base) {
  208. ret = -ENOMEM;
  209. goto out_saw_map;
  210. }
  211. /* Turn on the BHS, turn off LDO Bypass and power down LDO */
  212. reg_val = (64 << BHS_CNT_SHIFT) | (0x3f << LDO_PWR_DWN_SHIFT) | BHS_EN;
  213. writel_relaxed(reg_val, reg + APC_PWR_GATE_CTL);
  214. mb();
  215. /* wait for the BHS to settle */
  216. udelay(1);
  217. /* Turn on BHS segments */
  218. reg_val |= 0x3f << BHS_SEG_SHIFT;
  219. writel_relaxed(reg_val, reg + APC_PWR_GATE_CTL);
  220. mb();
  221. /* wait for the BHS to settle */
  222. udelay(1);
  223. /* Finally turn on the bypass so that BHS supplies power */
  224. reg_val |= 0x3f << LDO_BYP_SHIFT;
  225. writel_relaxed(reg_val, reg + APC_PWR_GATE_CTL);
  226. /* enable max phases */
  227. writel_relaxed(0x10003, l2_saw_base + APCS_SAW2_2_VCTL);
  228. mb();
  229. udelay(50);
  230. reg_val = COREPOR_RST | CLAMP;
  231. writel_relaxed(reg_val, reg + APCS_CPU_PWR_CTL);
  232. mb();
  233. udelay(2);
  234. reg_val &= ~CLAMP;
  235. writel_relaxed(reg_val, reg + APCS_CPU_PWR_CTL);
  236. mb();
  237. udelay(2);
  238. reg_val &= ~COREPOR_RST;
  239. writel_relaxed(reg_val, reg + APCS_CPU_PWR_CTL);
  240. mb();
  241. reg_val |= CORE_PWRD_UP;
  242. writel_relaxed(reg_val, reg + APCS_CPU_PWR_CTL);
  243. mb();
  244. ret = 0;
  245. iounmap(l2_saw_base);
  246. out_saw_map:
  247. iounmap(reg);
  248. out_map:
  249. of_node_put(saw_node);
  250. out_saw:
  251. of_node_put(l2_node);
  252. out_l2:
  253. of_node_put(acc_node);
  254. out_acc:
  255. of_node_put(cpu_node);
  256. return ret;
  257. }
  258. static DEFINE_PER_CPU(int, cold_boot_done);
  259. static int qcom_boot_secondary(unsigned int cpu, int (*func)(unsigned int))
  260. {
  261. int ret = 0;
  262. if (!per_cpu(cold_boot_done, cpu)) {
  263. ret = func(cpu);
  264. if (!ret)
  265. per_cpu(cold_boot_done, cpu) = true;
  266. }
  267. /*
  268. * Send the secondary CPU a soft interrupt, thereby causing
  269. * the boot monitor to read the system wide flags register,
  270. * and branch to the address found there.
  271. */
  272. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  273. return ret;
  274. }
  275. static int msm8660_boot_secondary(unsigned int cpu, struct task_struct *idle)
  276. {
  277. return qcom_boot_secondary(cpu, scss_release_secondary);
  278. }
  279. static int cortex_a7_boot_secondary(unsigned int cpu, struct task_struct *idle)
  280. {
  281. return qcom_boot_secondary(cpu, cortex_a7_release_secondary);
  282. }
  283. static int kpssv1_boot_secondary(unsigned int cpu, struct task_struct *idle)
  284. {
  285. return qcom_boot_secondary(cpu, kpssv1_release_secondary);
  286. }
  287. static int kpssv2_boot_secondary(unsigned int cpu, struct task_struct *idle)
  288. {
  289. return qcom_boot_secondary(cpu, kpssv2_release_secondary);
  290. }
  291. static void __init qcom_smp_prepare_cpus(unsigned int max_cpus)
  292. {
  293. int cpu;
  294. if (qcom_scm_set_cold_boot_addr(secondary_startup_arm)) {
  295. for_each_present_cpu(cpu) {
  296. if (cpu == smp_processor_id())
  297. continue;
  298. set_cpu_present(cpu, false);
  299. }
  300. pr_warn("Failed to set CPU boot address, disabling SMP\n");
  301. }
  302. }
  303. static const struct smp_operations smp_msm8660_ops __initconst = {
  304. .smp_prepare_cpus = qcom_smp_prepare_cpus,
  305. .smp_boot_secondary = msm8660_boot_secondary,
  306. #ifdef CONFIG_HOTPLUG_CPU
  307. .cpu_die = qcom_cpu_die,
  308. #endif
  309. };
  310. CPU_METHOD_OF_DECLARE(qcom_smp, "qcom,gcc-msm8660", &smp_msm8660_ops);
  311. static const struct smp_operations qcom_smp_cortex_a7_ops __initconst = {
  312. .smp_prepare_cpus = qcom_smp_prepare_cpus,
  313. .smp_boot_secondary = cortex_a7_boot_secondary,
  314. #ifdef CONFIG_HOTPLUG_CPU
  315. .cpu_die = qcom_cpu_die,
  316. #endif
  317. };
  318. CPU_METHOD_OF_DECLARE(qcom_smp_msm8226, "qcom,msm8226-smp", &qcom_smp_cortex_a7_ops);
  319. CPU_METHOD_OF_DECLARE(qcom_smp_msm8909, "qcom,msm8909-smp", &qcom_smp_cortex_a7_ops);
  320. CPU_METHOD_OF_DECLARE(qcom_smp_msm8916, "qcom,msm8916-smp", &qcom_smp_cortex_a7_ops);
  321. static const struct smp_operations qcom_smp_kpssv1_ops __initconst = {
  322. .smp_prepare_cpus = qcom_smp_prepare_cpus,
  323. .smp_boot_secondary = kpssv1_boot_secondary,
  324. #ifdef CONFIG_HOTPLUG_CPU
  325. .cpu_die = qcom_cpu_die,
  326. #endif
  327. };
  328. CPU_METHOD_OF_DECLARE(qcom_smp_kpssv1, "qcom,kpss-acc-v1", &qcom_smp_kpssv1_ops);
  329. static const struct smp_operations qcom_smp_kpssv2_ops __initconst = {
  330. .smp_prepare_cpus = qcom_smp_prepare_cpus,
  331. .smp_boot_secondary = kpssv2_boot_secondary,
  332. #ifdef CONFIG_HOTPLUG_CPU
  333. .cpu_die = qcom_cpu_die,
  334. #endif
  335. };
  336. CPU_METHOD_OF_DECLARE(qcom_smp_kpssv2, "qcom,kpss-acc-v2", &qcom_smp_kpssv2_ops);