cpu.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <common.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/arch/flow.h>
  20. #include <asm/arch/pinmux.h>
  21. #include <asm/arch/tegra.h>
  22. #include <asm/arch-tegra/clk_rst.h>
  23. #include <asm/arch-tegra/pmc.h>
  24. #include "../tegra-common/cpu.h"
  25. /* Tegra114-specific CPU init code */
  26. static void enable_cpu_power_rail(void)
  27. {
  28. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  29. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  30. u32 reg;
  31. debug("enable_cpu_power_rail entry\n");
  32. /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
  33. pinmux_tristate_disable(PINGRP_PWR_I2C_SCL);
  34. pinmux_tristate_disable(PINGRP_PWR_I2C_SDA);
  35. /*
  36. * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
  37. * set it for 25ms (102MHz * .025)
  38. */
  39. reg = 0x26E8F0;
  40. writel(reg, &pmc->pmc_cpupwrgood_timer);
  41. /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
  42. clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
  43. setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
  44. /*
  45. * Set CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2_0_CAR2PMC_CPU_ACK_WIDTH
  46. * to 408 to satisfy the requirement of having at least 16 CPU clock
  47. * cycles before clamp removal.
  48. */
  49. clrbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 0xFFF);
  50. setbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 408);
  51. }
  52. static void enable_cpu_clocks(void)
  53. {
  54. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  55. u32 reg;
  56. debug("enable_cpu_clocks entry\n");
  57. /* Wait for PLL-X to lock */
  58. do {
  59. reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  60. } while ((reg & PLL_LOCK_MASK) == 0);
  61. /* Wait until all clocks are stable */
  62. udelay(PLL_STABILIZATION_DELAY);
  63. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  64. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  65. /* Always enable the main CPU complex clocks */
  66. clock_enable(PERIPH_ID_CPU);
  67. clock_enable(PERIPH_ID_CPULP);
  68. clock_enable(PERIPH_ID_CPUG);
  69. }
  70. static void remove_cpu_resets(void)
  71. {
  72. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  73. u32 reg;
  74. debug("remove_cpu_resets entry\n");
  75. /* Take the slow non-CPU partition out of reset */
  76. reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
  77. writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpulp_cmplx_clr);
  78. /* Take the fast non-CPU partition out of reset */
  79. reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
  80. writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpug_cmplx_clr);
  81. /* Clear the SW-controlled reset of the slow cluster */
  82. reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
  83. reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
  84. writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
  85. /* Clear the SW-controlled reset of the fast cluster */
  86. reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
  87. reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
  88. reg |= (CLR_CPURESET1+CLR_DBGRESET1+CLR_CORERESET1+CLR_CXRESET1);
  89. reg |= (CLR_CPURESET2+CLR_DBGRESET2+CLR_CORERESET2+CLR_CXRESET2);
  90. reg |= (CLR_CPURESET3+CLR_DBGRESET3+CLR_CORERESET3+CLR_CXRESET3);
  91. writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
  92. }
  93. /**
  94. * The T114 requires some special clock initialization, including setting up
  95. * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
  96. */
  97. void t114_init_clocks(void)
  98. {
  99. struct clk_rst_ctlr *clkrst =
  100. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  101. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  102. u32 val;
  103. debug("t114_init_clocks entry\n");
  104. /* Set active CPU cluster to G */
  105. clrbits_le32(&flow->cluster_control, 1);
  106. writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
  107. debug("Setting up PLLX\n");
  108. init_pllx();
  109. val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
  110. writel(val, &clkrst->crc_clk_sys_rate);
  111. /* Enable clocks to required peripherals. TBD - minimize this list */
  112. debug("Enabling clocks\n");
  113. clock_set_enable(PERIPH_ID_CACHE2, 1);
  114. clock_set_enable(PERIPH_ID_GPIO, 1);
  115. clock_set_enable(PERIPH_ID_TMR, 1);
  116. clock_set_enable(PERIPH_ID_RTC, 1);
  117. clock_set_enable(PERIPH_ID_CPU, 1);
  118. clock_set_enable(PERIPH_ID_EMC, 1);
  119. clock_set_enable(PERIPH_ID_I2C5, 1);
  120. clock_set_enable(PERIPH_ID_FUSE, 1);
  121. clock_set_enable(PERIPH_ID_PMC, 1);
  122. clock_set_enable(PERIPH_ID_APBDMA, 1);
  123. clock_set_enable(PERIPH_ID_MEM, 1);
  124. clock_set_enable(PERIPH_ID_IRAMA, 1);
  125. clock_set_enable(PERIPH_ID_IRAMB, 1);
  126. clock_set_enable(PERIPH_ID_IRAMC, 1);
  127. clock_set_enable(PERIPH_ID_IRAMD, 1);
  128. clock_set_enable(PERIPH_ID_CORESIGHT, 1);
  129. clock_set_enable(PERIPH_ID_MSELECT, 1);
  130. clock_set_enable(PERIPH_ID_EMC1, 1);
  131. clock_set_enable(PERIPH_ID_MC1, 1);
  132. clock_set_enable(PERIPH_ID_DVFS, 1);
  133. /*
  134. * Set MSELECT clock source as PLLP (00), and ask for a clock
  135. * divider that would set the MSELECT clock at 102MHz for a
  136. * PLLP base of 408MHz.
  137. */
  138. clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
  139. CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
  140. /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
  141. clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
  142. /* Give clocks time to stabilize */
  143. udelay(1000);
  144. /* Take required peripherals out of reset */
  145. debug("Taking periphs out of reset\n");
  146. reset_set_enable(PERIPH_ID_CACHE2, 0);
  147. reset_set_enable(PERIPH_ID_GPIO, 0);
  148. reset_set_enable(PERIPH_ID_TMR, 0);
  149. reset_set_enable(PERIPH_ID_COP, 0);
  150. reset_set_enable(PERIPH_ID_EMC, 0);
  151. reset_set_enable(PERIPH_ID_I2C5, 0);
  152. reset_set_enable(PERIPH_ID_FUSE, 0);
  153. reset_set_enable(PERIPH_ID_APBDMA, 0);
  154. reset_set_enable(PERIPH_ID_MEM, 0);
  155. reset_set_enable(PERIPH_ID_CORESIGHT, 0);
  156. reset_set_enable(PERIPH_ID_MSELECT, 0);
  157. reset_set_enable(PERIPH_ID_EMC1, 0);
  158. reset_set_enable(PERIPH_ID_MC1, 0);
  159. reset_set_enable(PERIPH_ID_DVFS, 0);
  160. debug("t114_init_clocks exit\n");
  161. }
  162. static bool is_partition_powered(u32 partid)
  163. {
  164. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  165. u32 reg;
  166. /* Get power gate status */
  167. reg = readl(&pmc->pmc_pwrgate_status);
  168. return !!(reg & (1 << partid));
  169. }
  170. static bool is_clamp_enabled(u32 partid)
  171. {
  172. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  173. u32 reg;
  174. /* Get clamp status. */
  175. reg = readl(&pmc->pmc_clamp_status);
  176. return !!(reg & (1 << partid));
  177. }
  178. static void power_partition(u32 partid)
  179. {
  180. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  181. debug("%s: part ID = %08X\n", __func__, partid);
  182. /* Is the partition already on? */
  183. if (!is_partition_powered(partid)) {
  184. /* No, toggle the partition power state (OFF -> ON) */
  185. debug("power_partition, toggling state\n");
  186. writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
  187. /* Wait for the power to come up */
  188. while (!is_partition_powered(partid))
  189. ;
  190. /* Wait for the clamp status to be cleared */
  191. while (is_clamp_enabled(partid))
  192. ;
  193. /* Give I/O signals time to stabilize */
  194. udelay(IO_STABILIZATION_DELAY);
  195. }
  196. }
  197. void powerup_cpus(void)
  198. {
  199. debug("powerup_cpus entry\n");
  200. /* We boot to the fast cluster */
  201. debug("powerup_cpus entry: G cluster\n");
  202. /* Power up the fast cluster rail partition */
  203. power_partition(CRAIL);
  204. /* Power up the fast cluster non-CPU partition */
  205. power_partition(C0NC);
  206. /* Power up the fast cluster CPU0 partition */
  207. power_partition(CE0);
  208. }
  209. void start_cpu(u32 reset_vector)
  210. {
  211. u32 imme, inst;
  212. debug("start_cpu entry, reset_vector = %x\n", reset_vector);
  213. t114_init_clocks();
  214. /* Enable VDD_CPU */
  215. enable_cpu_power_rail();
  216. /* Get the CPU(s) running */
  217. enable_cpu_clocks();
  218. /* Enable CoreSight */
  219. clock_enable_coresight(1);
  220. /* Take CPU(s) out of reset */
  221. remove_cpu_resets();
  222. /* Set the entry point for CPU execution from reset */
  223. /*
  224. * A01P with patched boot ROM; vector hard-coded to 0x4003fffc.
  225. * See nvbug 1193357 for details.
  226. */
  227. /* mov r0, #lsb(reset_vector) */
  228. imme = reset_vector & 0xffff;
  229. inst = imme & 0xfff;
  230. inst |= ((imme >> 12) << 16);
  231. inst |= 0xe3000000;
  232. writel(inst, 0x4003fff0);
  233. /* movt r0, #msb(reset_vector) */
  234. imme = (reset_vector >> 16) & 0xffff;
  235. inst = imme & 0xfff;
  236. inst |= ((imme >> 12) << 16);
  237. inst |= 0xe3400000;
  238. writel(inst, 0x4003fff4);
  239. /* bx r0 */
  240. writel(0xe12fff10, 0x4003fff8);
  241. /* b -12 */
  242. imme = (u32)-20;
  243. inst = (imme >> 2) & 0xffffff;
  244. inst |= 0xea000000;
  245. writel(inst, 0x4003fffc);
  246. /* Write to orignal location for compatibility */
  247. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  248. /* If the CPU(s) don't already have power, power 'em up */
  249. powerup_cpus();
  250. }