ap20.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * (C) Copyright 2010-2011
  3. * NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include "ap20.h"
  24. #include <asm/io.h>
  25. #include <asm/arch/tegra2.h>
  26. #include <asm/arch/clk_rst.h>
  27. #include <asm/arch/pmc.h>
  28. #include <asm/arch/pinmux.h>
  29. #include <asm/arch/scu.h>
  30. #include <common.h>
  31. u32 s_first_boot = 1;
  32. static void enable_cpu_clock(int enable)
  33. {
  34. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  35. u32 reg, clk;
  36. /*
  37. * NOTE:
  38. * Regardless of whether the request is to enable or disable the CPU
  39. * clock, every processor in the CPU complex except the master (CPU 0)
  40. * will have it's clock stopped because the AVP only talks to the
  41. * master. The AVP does not know (nor does it need to know) that there
  42. * are multiple processors in the CPU complex.
  43. */
  44. if (enable) {
  45. /* Wait until all clocks are stable */
  46. udelay(PLL_STABILIZATION_DELAY);
  47. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  48. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  49. }
  50. /* Fetch the register containing the main CPU complex clock enable */
  51. reg = readl(&clkrst->crc_clk_out_enb_l);
  52. reg |= CLK_ENB_CPU;
  53. /*
  54. * Read the register containing the individual CPU clock enables and
  55. * always stop the clock to CPU 1.
  56. */
  57. clk = readl(&clkrst->crc_clk_cpu_cmplx);
  58. clk |= CPU1_CLK_STP;
  59. if (enable) {
  60. /* Unstop the CPU clock */
  61. clk &= ~CPU0_CLK_STP;
  62. } else {
  63. /* Stop the CPU clock */
  64. clk |= CPU0_CLK_STP;
  65. }
  66. writel(clk, &clkrst->crc_clk_cpu_cmplx);
  67. writel(reg, &clkrst->crc_clk_out_enb_l);
  68. }
  69. static int is_cpu_powered(void)
  70. {
  71. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  72. return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
  73. }
  74. static void remove_cpu_io_clamps(void)
  75. {
  76. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  77. u32 reg;
  78. /* Remove the clamps on the CPU I/O signals */
  79. reg = readl(&pmc->pmc_remove_clamping);
  80. reg |= CPU_CLMP;
  81. writel(reg, &pmc->pmc_remove_clamping);
  82. /* Give I/O signals time to stabilize */
  83. udelay(IO_STABILIZATION_DELAY);
  84. }
  85. static void powerup_cpu(void)
  86. {
  87. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  88. u32 reg;
  89. int timeout = IO_STABILIZATION_DELAY;
  90. if (!is_cpu_powered()) {
  91. /* Toggle the CPU power state (OFF -> ON) */
  92. reg = readl(&pmc->pmc_pwrgate_toggle);
  93. reg &= PARTID_CP;
  94. reg |= START_CP;
  95. writel(reg, &pmc->pmc_pwrgate_toggle);
  96. /* Wait for the power to come up */
  97. while (!is_cpu_powered()) {
  98. if (timeout-- == 0)
  99. printf("CPU failed to power up!\n");
  100. else
  101. udelay(10);
  102. }
  103. /*
  104. * Remove the I/O clamps from CPU power partition.
  105. * Recommended only on a Warm boot, if the CPU partition gets
  106. * power gated. Shouldn't cause any harm when called after a
  107. * cold boot according to HW, probably just redundant.
  108. */
  109. remove_cpu_io_clamps();
  110. }
  111. }
  112. static void enable_cpu_power_rail(void)
  113. {
  114. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  115. u32 reg;
  116. reg = readl(&pmc->pmc_cntrl);
  117. reg |= CPUPWRREQ_OE;
  118. writel(reg, &pmc->pmc_cntrl);
  119. /*
  120. * The TI PMU65861C needs a 3.75ms delay between enabling
  121. * the power rail and enabling the CPU clock. This delay
  122. * between SM1EN and SM1 is for switching time + the ramp
  123. * up of the voltage to the CPU (VDD_CPU from PMU).
  124. */
  125. udelay(3750);
  126. }
  127. static void reset_A9_cpu(int reset)
  128. {
  129. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  130. u32 reg, cpu;
  131. /*
  132. * NOTE: Regardless of whether the request is to hold the CPU in reset
  133. * or take it out of reset, every processor in the CPU complex
  134. * except the master (CPU 0) will be held in reset because the
  135. * AVP only talks to the master. The AVP does not know that there
  136. * are multiple processors in the CPU complex.
  137. */
  138. /* Hold CPU 1 in reset */
  139. cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
  140. writel(cpu, &clkrst->crc_cpu_cmplx_set);
  141. reg = readl(&clkrst->crc_rst_dev_l);
  142. if (reset) {
  143. /* Now place CPU0 into reset */
  144. cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
  145. writel(cpu, &clkrst->crc_cpu_cmplx_set);
  146. /* Enable master CPU reset */
  147. reg |= SWR_CPU_RST;
  148. } else {
  149. /* Take CPU0 out of reset */
  150. cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
  151. writel(cpu, &clkrst->crc_cpu_cmplx_clr);
  152. /* Disable master CPU reset */
  153. reg &= ~SWR_CPU_RST;
  154. }
  155. writel(reg, &clkrst->crc_rst_dev_l);
  156. }
  157. static void clock_enable_coresight(int enable)
  158. {
  159. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  160. u32 rst, clk, src;
  161. rst = readl(&clkrst->crc_rst_dev_u);
  162. clk = readl(&clkrst->crc_clk_out_enb_u);
  163. if (enable) {
  164. rst &= ~SWR_CSITE_RST;
  165. clk |= CLK_ENB_CSITE;
  166. } else {
  167. rst |= SWR_CSITE_RST;
  168. clk &= ~CLK_ENB_CSITE;
  169. }
  170. writel(clk, &clkrst->crc_clk_out_enb_u);
  171. writel(rst, &clkrst->crc_rst_dev_u);
  172. if (enable) {
  173. /*
  174. * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
  175. * 1.5, giving an effective frequency of 144MHz.
  176. * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
  177. * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
  178. */
  179. src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
  180. writel(src, &clkrst->crc_clk_src_csite);
  181. /* Unlock the CPU CoreSight interfaces */
  182. rst = 0xC5ACCE55;
  183. writel(rst, CSITE_CPU_DBG0_LAR);
  184. writel(rst, CSITE_CPU_DBG1_LAR);
  185. }
  186. }
  187. void start_cpu(u32 reset_vector)
  188. {
  189. /* Enable VDD_CPU */
  190. enable_cpu_power_rail();
  191. /* Hold the CPUs in reset */
  192. reset_A9_cpu(1);
  193. /* Disable the CPU clock */
  194. enable_cpu_clock(0);
  195. /* Enable CoreSight */
  196. clock_enable_coresight(1);
  197. /*
  198. * Set the entry point for CPU execution from reset,
  199. * if it's a non-zero value.
  200. */
  201. if (reset_vector)
  202. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  203. /* Enable the CPU clock */
  204. enable_cpu_clock(1);
  205. /* If the CPU doesn't already have power, power it up */
  206. powerup_cpu();
  207. /* Take the CPU out of reset */
  208. reset_A9_cpu(0);
  209. }
  210. void halt_avp(void)
  211. {
  212. for (;;) {
  213. writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
  214. | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
  215. FLOW_CTLR_HALT_COP_EVENTS);
  216. }
  217. }
  218. void enable_scu(void)
  219. {
  220. struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
  221. u32 reg;
  222. /* If SCU already setup/enabled, return */
  223. if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
  224. return;
  225. /* Invalidate all ways for all processors */
  226. writel(0xFFFF, &scu->scu_inv_all);
  227. /* Enable SCU - bit 0 */
  228. reg = readl(&scu->scu_ctrl);
  229. reg |= SCU_CTRL_ENABLE;
  230. writel(reg, &scu->scu_ctrl);
  231. }
  232. void init_pmc_scratch(void)
  233. {
  234. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  235. int i;
  236. /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
  237. for (i = 0; i < 23; i++)
  238. writel(0, &pmc->pmc_scratch1+i);
  239. /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
  240. writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
  241. }
  242. void cpu_start(void)
  243. {
  244. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  245. /* enable JTAG */
  246. writel(0xC0, &pmt->pmt_cfg_ctl);
  247. if (s_first_boot) {
  248. /*
  249. * Need to set this before cold-booting,
  250. * otherwise we'll end up in an infinite loop.
  251. */
  252. s_first_boot = 0;
  253. cold_boot();
  254. }
  255. }
  256. void tegra2_start()
  257. {
  258. if (s_first_boot) {
  259. /* Init Debug UART Port (115200 8n1) */
  260. uart_init();
  261. /* Init PMC scratch memory */
  262. init_pmc_scratch();
  263. }
  264. #ifdef CONFIG_ENABLE_CORTEXA9
  265. /* take the mpcore out of reset */
  266. cpu_start();
  267. /* configure cache */
  268. cache_configure();
  269. #endif
  270. }