platsmp.c 7.8 KB

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