cpu.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2013
  4. * NVIDIA Corporation <www.nvidia.com>
  5. */
  6. #include <common.h>
  7. #include <log.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/ahb.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/flow.h>
  12. #include <asm/arch/pinmux.h>
  13. #include <asm/arch/tegra.h>
  14. #include <asm/arch-tegra/clk_rst.h>
  15. #include <asm/arch-tegra/pmc.h>
  16. #include <asm/arch-tegra/tegra_i2c.h>
  17. #include <asm/arch-tegra/ap.h>
  18. #include <linux/delay.h>
  19. #include "../cpu.h"
  20. /* In case this function is not defined */
  21. __weak void pmic_enable_cpu_vdd(void) {}
  22. /* Tegra124-specific CPU init code */
  23. static void enable_cpu_power_rail(void)
  24. {
  25. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  26. debug("%s entry\n", __func__);
  27. /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
  28. pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SCL_PZ6);
  29. pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SDA_PZ7);
  30. pmic_enable_cpu_vdd();
  31. /*
  32. * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
  33. * set it for 5ms as per SysEng (102MHz*5ms = 510000 (7C830h).
  34. */
  35. writel(0x7C830, &pmc->pmc_cpupwrgood_timer);
  36. /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
  37. clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
  38. setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
  39. }
  40. static void enable_cpu_clocks(void)
  41. {
  42. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  43. struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
  44. u32 reg;
  45. debug("%s entry\n", __func__);
  46. /* Wait for PLL-X to lock */
  47. do {
  48. reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  49. debug("%s: PLLX base = 0x%08X\n", __func__, reg);
  50. } while ((reg & (1 << pllinfo->lock_det)) == 0);
  51. debug("%s: PLLX locked, delay for stable clocks\n", __func__);
  52. /* Wait until all clocks are stable */
  53. udelay(PLL_STABILIZATION_DELAY);
  54. debug("%s: Setting CCLK_BURST and DIVIDER\n", __func__);
  55. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  56. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  57. debug("%s: Enabling clock to all CPUs\n", __func__);
  58. /* Enable the clock to all CPUs */
  59. reg = CLR_CPU3_CLK_STP | CLR_CPU2_CLK_STP | CLR_CPU1_CLK_STP |
  60. CLR_CPU0_CLK_STP;
  61. writel(reg, &clkrst->crc_clk_cpu_cmplx_clr);
  62. debug("%s: Enabling main CPU complex clocks\n", __func__);
  63. /* Always enable the main CPU complex clocks */
  64. clock_enable(PERIPH_ID_CPU);
  65. clock_enable(PERIPH_ID_CPULP);
  66. clock_enable(PERIPH_ID_CPUG);
  67. debug("%s: Done\n", __func__);
  68. }
  69. static void remove_cpu_resets(void)
  70. {
  71. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  72. u32 reg;
  73. debug("%s entry\n", __func__);
  74. /* Take the slow and fast partitions out of reset */
  75. reg = CLR_NONCPURESET;
  76. writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
  77. writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
  78. /* Clear the SW-controlled reset of the slow cluster */
  79. reg = CLR_CPURESET0 | CLR_DBGRESET0 | CLR_CORERESET0 | CLR_CXRESET0 |
  80. CLR_L2RESET | CLR_PRESETDBG;
  81. writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
  82. /* Clear the SW-controlled reset of the fast cluster */
  83. reg = CLR_CPURESET0 | CLR_DBGRESET0 | CLR_CORERESET0 | CLR_CXRESET0 |
  84. CLR_CPURESET1 | CLR_DBGRESET1 | CLR_CORERESET1 | CLR_CXRESET1 |
  85. CLR_CPURESET2 | CLR_DBGRESET2 | CLR_CORERESET2 | CLR_CXRESET2 |
  86. CLR_CPURESET3 | CLR_DBGRESET3 | CLR_CORERESET3 | CLR_CXRESET3 |
  87. CLR_L2RESET | CLR_PRESETDBG;
  88. writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
  89. }
  90. static void tegra124_ram_repair(void)
  91. {
  92. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  93. u32 ram_repair_timeout; /*usec*/
  94. u32 val;
  95. /*
  96. * Request the Flow Controller perform RAM repair whenever it turns on
  97. * a power rail that requires RAM repair.
  98. */
  99. clrbits_le32(&flow->ram_repair, RAM_REPAIR_BYPASS_EN);
  100. /* Request SW trigerred RAM repair by setting req bit */
  101. /* cluster 0 */
  102. setbits_le32(&flow->ram_repair, RAM_REPAIR_REQ);
  103. /* Wait for completion (status == 0) */
  104. ram_repair_timeout = 500;
  105. do {
  106. udelay(1);
  107. val = readl(&flow->ram_repair);
  108. } while (!(val & RAM_REPAIR_STS) && ram_repair_timeout--);
  109. if (!ram_repair_timeout)
  110. debug("Ram Repair cluster0 failed\n");
  111. /* cluster 1 */
  112. setbits_le32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
  113. /* Wait for completion (status == 0) */
  114. ram_repair_timeout = 500;
  115. do {
  116. udelay(1);
  117. val = readl(&flow->ram_repair_cluster1);
  118. } while (!(val & RAM_REPAIR_STS) && ram_repair_timeout--);
  119. if (!ram_repair_timeout)
  120. debug("Ram Repair cluster1 failed\n");
  121. }
  122. /**
  123. * Tegra124 requires some special clock initialization, including setting up
  124. * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
  125. */
  126. void tegra124_init_clocks(void)
  127. {
  128. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  129. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  130. struct clk_rst_ctlr *clkrst =
  131. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  132. u32 val;
  133. debug("%s entry\n", __func__);
  134. /* Set active CPU cluster to G */
  135. clrbits_le32(&flow->cluster_control, 1);
  136. /* Change the oscillator drive strength */
  137. val = readl(&clkrst->crc_osc_ctrl);
  138. val &= ~OSC_XOFS_MASK;
  139. val |= (OSC_DRIVE_STRENGTH << OSC_XOFS_SHIFT);
  140. writel(val, &clkrst->crc_osc_ctrl);
  141. /* Update same value in PMC_OSC_EDPD_OVER XOFS field for warmboot */
  142. val = readl(&pmc->pmc_osc_edpd_over);
  143. val &= ~PMC_XOFS_MASK;
  144. val |= (OSC_DRIVE_STRENGTH << PMC_XOFS_SHIFT);
  145. writel(val, &pmc->pmc_osc_edpd_over);
  146. /* Set HOLD_CKE_LOW_EN to 1 */
  147. setbits_le32(&pmc->pmc_cntrl2, HOLD_CKE_LOW_EN);
  148. debug("Setting up PLLX\n");
  149. init_pllx();
  150. val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
  151. writel(val, &clkrst->crc_clk_sys_rate);
  152. /* Enable clocks to required peripherals. TBD - minimize this list */
  153. debug("Enabling clocks\n");
  154. clock_set_enable(PERIPH_ID_CACHE2, 1);
  155. clock_set_enable(PERIPH_ID_GPIO, 1);
  156. clock_set_enable(PERIPH_ID_TMR, 1);
  157. clock_set_enable(PERIPH_ID_CPU, 1);
  158. clock_set_enable(PERIPH_ID_EMC, 1);
  159. clock_set_enable(PERIPH_ID_I2C5, 1);
  160. clock_set_enable(PERIPH_ID_APBDMA, 1);
  161. clock_set_enable(PERIPH_ID_MEM, 1);
  162. clock_set_enable(PERIPH_ID_CORESIGHT, 1);
  163. clock_set_enable(PERIPH_ID_MSELECT, 1);
  164. clock_set_enable(PERIPH_ID_DVFS, 1);
  165. /*
  166. * Set MSELECT clock source as PLLP (00), and ask for a clock
  167. * divider that would set the MSELECT clock at 102MHz for a
  168. * PLLP base of 408MHz.
  169. */
  170. clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
  171. CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
  172. /* Give clock time to stabilize */
  173. udelay(IO_STABILIZATION_DELAY);
  174. /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
  175. clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
  176. /* Give clock time to stabilize */
  177. udelay(IO_STABILIZATION_DELAY);
  178. /* Take required peripherals out of reset */
  179. debug("Taking periphs out of reset\n");
  180. reset_set_enable(PERIPH_ID_CACHE2, 0);
  181. reset_set_enable(PERIPH_ID_GPIO, 0);
  182. reset_set_enable(PERIPH_ID_TMR, 0);
  183. reset_set_enable(PERIPH_ID_COP, 0);
  184. reset_set_enable(PERIPH_ID_EMC, 0);
  185. reset_set_enable(PERIPH_ID_I2C5, 0);
  186. reset_set_enable(PERIPH_ID_APBDMA, 0);
  187. reset_set_enable(PERIPH_ID_MEM, 0);
  188. reset_set_enable(PERIPH_ID_CORESIGHT, 0);
  189. reset_set_enable(PERIPH_ID_MSELECT, 0);
  190. reset_set_enable(PERIPH_ID_DVFS, 0);
  191. debug("%s exit\n", __func__);
  192. }
  193. static bool is_partition_powered(u32 partid)
  194. {
  195. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  196. u32 reg;
  197. /* Get power gate status */
  198. reg = readl(&pmc->pmc_pwrgate_status);
  199. return !!(reg & (1 << partid));
  200. }
  201. static void unpower_partition(u32 partid)
  202. {
  203. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  204. debug("%s: part ID = %08X\n", __func__, partid);
  205. /* Is the partition on? */
  206. if (is_partition_powered(partid)) {
  207. /* Yes, toggle the partition power state (ON -> OFF) */
  208. debug("power_partition, toggling state\n");
  209. writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
  210. /* Wait for the power to come down */
  211. while (is_partition_powered(partid))
  212. ;
  213. /* Give I/O signals time to stabilize */
  214. udelay(IO_STABILIZATION_DELAY);
  215. }
  216. }
  217. void unpower_cpus(void)
  218. {
  219. debug("%s entry: G cluster\n", __func__);
  220. /* Power down the fast cluster rail partition */
  221. debug("%s: CRAIL\n", __func__);
  222. unpower_partition(CRAIL);
  223. /* Power down the fast cluster non-CPU partition */
  224. debug("%s: C0NC\n", __func__);
  225. unpower_partition(C0NC);
  226. /* Power down the fast cluster CPU0 partition */
  227. debug("%s: CE0\n", __func__);
  228. unpower_partition(CE0);
  229. debug("%s: done\n", __func__);
  230. }
  231. static void power_partition(u32 partid)
  232. {
  233. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  234. debug("%s: part ID = %08X\n", __func__, partid);
  235. /* Is the partition already on? */
  236. if (!is_partition_powered(partid)) {
  237. /* No, toggle the partition power state (OFF -> ON) */
  238. debug("power_partition, toggling state\n");
  239. writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
  240. /* Wait for the power to come up */
  241. while (!is_partition_powered(partid))
  242. ;
  243. /* Give I/O signals time to stabilize */
  244. udelay(IO_STABILIZATION_DELAY);
  245. }
  246. }
  247. void powerup_cpus(void)
  248. {
  249. /* We boot to the fast cluster */
  250. debug("%s entry: G cluster\n", __func__);
  251. /* Power up the fast cluster rail partition */
  252. debug("%s: CRAIL\n", __func__);
  253. power_partition(CRAIL);
  254. /* Power up the fast cluster non-CPU partition */
  255. debug("%s: C0NC\n", __func__);
  256. power_partition(C0NC);
  257. /* Power up the fast cluster CPU0 partition */
  258. debug("%s: CE0\n", __func__);
  259. power_partition(CE0);
  260. debug("%s: done\n", __func__);
  261. }
  262. void start_cpu(u32 reset_vector)
  263. {
  264. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  265. debug("%s entry, reset_vector = %x\n", __func__, reset_vector);
  266. /*
  267. * High power clusters are on after software reset,
  268. * it may interfere with tegra124_ram_repair.
  269. * unpower them.
  270. */
  271. unpower_cpus();
  272. tegra124_init_clocks();
  273. /* Set power-gating timer multiplier */
  274. writel((MULT_8 << TIMER_MULT_SHIFT) | (MULT_8 << TIMER_MULT_CPU_SHIFT),
  275. &pmc->pmc_pwrgate_timer_mult);
  276. enable_cpu_power_rail();
  277. powerup_cpus();
  278. tegra124_ram_repair();
  279. enable_cpu_clocks();
  280. clock_enable_coresight(1);
  281. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  282. remove_cpu_resets();
  283. debug("%s exit, should continue @ reset_vector\n", __func__);
  284. }