ap20.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. void init_pllx(void)
  33. {
  34. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  35. u32 reg;
  36. /* If PLLX is already enabled, just return */
  37. reg = readl(&clkrst->crc_pllx_base);
  38. if (reg & PLL_ENABLE)
  39. return;
  40. /* Set PLLX_MISC */
  41. reg = CPCON; /* CPCON[11:8] = 0001 */
  42. writel(reg, &clkrst->crc_pllx_misc);
  43. /* Use 12MHz clock here */
  44. reg = (PLL_BYPASS | PLL_DIVM);
  45. reg |= (1000 << 8); /* DIVN = 0x3E8 */
  46. writel(reg, &clkrst->crc_pllx_base);
  47. reg |= PLL_ENABLE;
  48. writel(reg, &clkrst->crc_pllx_base);
  49. reg &= ~PLL_BYPASS;
  50. writel(reg, &clkrst->crc_pllx_base);
  51. }
  52. static void enable_cpu_clock(int enable)
  53. {
  54. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  55. u32 reg, clk;
  56. /*
  57. * NOTE:
  58. * Regardless of whether the request is to enable or disable the CPU
  59. * clock, every processor in the CPU complex except the master (CPU 0)
  60. * will have it's clock stopped because the AVP only talks to the
  61. * master. The AVP does not know (nor does it need to know) that there
  62. * are multiple processors in the CPU complex.
  63. */
  64. if (enable) {
  65. /* Initialize PLLX */
  66. init_pllx();
  67. /* Wait until all clocks are stable */
  68. udelay(PLL_STABILIZATION_DELAY);
  69. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  70. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  71. }
  72. /* Fetch the register containing the main CPU complex clock enable */
  73. reg = readl(&clkrst->crc_clk_out_enb_l);
  74. reg |= CLK_ENB_CPU;
  75. /*
  76. * Read the register containing the individual CPU clock enables and
  77. * always stop the clock to CPU 1.
  78. */
  79. clk = readl(&clkrst->crc_clk_cpu_cmplx);
  80. clk |= CPU1_CLK_STP;
  81. if (enable) {
  82. /* Unstop the CPU clock */
  83. clk &= ~CPU0_CLK_STP;
  84. } else {
  85. /* Stop the CPU clock */
  86. clk |= CPU0_CLK_STP;
  87. }
  88. writel(clk, &clkrst->crc_clk_cpu_cmplx);
  89. writel(reg, &clkrst->crc_clk_out_enb_l);
  90. }
  91. static int is_cpu_powered(void)
  92. {
  93. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  94. return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
  95. }
  96. static void remove_cpu_io_clamps(void)
  97. {
  98. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  99. u32 reg;
  100. /* Remove the clamps on the CPU I/O signals */
  101. reg = readl(&pmc->pmc_remove_clamping);
  102. reg |= CPU_CLMP;
  103. writel(reg, &pmc->pmc_remove_clamping);
  104. /* Give I/O signals time to stabilize */
  105. udelay(IO_STABILIZATION_DELAY);
  106. }
  107. static void powerup_cpu(void)
  108. {
  109. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  110. u32 reg;
  111. int timeout = IO_STABILIZATION_DELAY;
  112. if (!is_cpu_powered()) {
  113. /* Toggle the CPU power state (OFF -> ON) */
  114. reg = readl(&pmc->pmc_pwrgate_toggle);
  115. reg &= PARTID_CP;
  116. reg |= START_CP;
  117. writel(reg, &pmc->pmc_pwrgate_toggle);
  118. /* Wait for the power to come up */
  119. while (!is_cpu_powered()) {
  120. if (timeout-- == 0)
  121. printf("CPU failed to power up!\n");
  122. else
  123. udelay(10);
  124. }
  125. /*
  126. * Remove the I/O clamps from CPU power partition.
  127. * Recommended only on a Warm boot, if the CPU partition gets
  128. * power gated. Shouldn't cause any harm when called after a
  129. * cold boot according to HW, probably just redundant.
  130. */
  131. remove_cpu_io_clamps();
  132. }
  133. }
  134. static void enable_cpu_power_rail(void)
  135. {
  136. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  137. u32 reg;
  138. reg = readl(&pmc->pmc_cntrl);
  139. reg |= CPUPWRREQ_OE;
  140. writel(reg, &pmc->pmc_cntrl);
  141. /*
  142. * The TI PMU65861C needs a 3.75ms delay between enabling
  143. * the power rail and enabling the CPU clock. This delay
  144. * between SM1EN and SM1 is for switching time + the ramp
  145. * up of the voltage to the CPU (VDD_CPU from PMU).
  146. */
  147. udelay(3750);
  148. }
  149. static void reset_A9_cpu(int reset)
  150. {
  151. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  152. u32 reg, cpu;
  153. /*
  154. * NOTE: Regardless of whether the request is to hold the CPU in reset
  155. * or take it out of reset, every processor in the CPU complex
  156. * except the master (CPU 0) will be held in reset because the
  157. * AVP only talks to the master. The AVP does not know that there
  158. * are multiple processors in the CPU complex.
  159. */
  160. /* Hold CPU 1 in reset */
  161. cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
  162. writel(cpu, &clkrst->crc_cpu_cmplx_set);
  163. reg = readl(&clkrst->crc_rst_dev_l);
  164. if (reset) {
  165. /* Now place CPU0 into reset */
  166. cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
  167. writel(cpu, &clkrst->crc_cpu_cmplx_set);
  168. /* Enable master CPU reset */
  169. reg |= SWR_CPU_RST;
  170. } else {
  171. /* Take CPU0 out of reset */
  172. cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
  173. writel(cpu, &clkrst->crc_cpu_cmplx_clr);
  174. /* Disable master CPU reset */
  175. reg &= ~SWR_CPU_RST;
  176. }
  177. writel(reg, &clkrst->crc_rst_dev_l);
  178. }
  179. static void clock_enable_coresight(int enable)
  180. {
  181. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  182. u32 rst, clk, src;
  183. rst = readl(&clkrst->crc_rst_dev_u);
  184. clk = readl(&clkrst->crc_clk_out_enb_u);
  185. if (enable) {
  186. rst &= ~SWR_CSITE_RST;
  187. clk |= CLK_ENB_CSITE;
  188. } else {
  189. rst |= SWR_CSITE_RST;
  190. clk &= ~CLK_ENB_CSITE;
  191. }
  192. writel(clk, &clkrst->crc_clk_out_enb_u);
  193. writel(rst, &clkrst->crc_rst_dev_u);
  194. if (enable) {
  195. /*
  196. * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
  197. * 1.5, giving an effective frequency of 144MHz.
  198. * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
  199. * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
  200. */
  201. src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
  202. writel(src, &clkrst->crc_clk_src_csite);
  203. /* Unlock the CPU CoreSight interfaces */
  204. rst = 0xC5ACCE55;
  205. writel(rst, CSITE_CPU_DBG0_LAR);
  206. writel(rst, CSITE_CPU_DBG1_LAR);
  207. }
  208. }
  209. void start_cpu(u32 reset_vector)
  210. {
  211. /* Enable VDD_CPU */
  212. enable_cpu_power_rail();
  213. /* Hold the CPUs in reset */
  214. reset_A9_cpu(1);
  215. /* Disable the CPU clock */
  216. enable_cpu_clock(0);
  217. /* Enable CoreSight */
  218. clock_enable_coresight(1);
  219. /*
  220. * Set the entry point for CPU execution from reset,
  221. * if it's a non-zero value.
  222. */
  223. if (reset_vector)
  224. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  225. /* Enable the CPU clock */
  226. enable_cpu_clock(1);
  227. /* If the CPU doesn't already have power, power it up */
  228. powerup_cpu();
  229. /* Take the CPU out of reset */
  230. reset_A9_cpu(0);
  231. }
  232. void halt_avp(void)
  233. {
  234. for (;;) {
  235. writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
  236. | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
  237. FLOW_CTLR_HALT_COP_EVENTS);
  238. }
  239. }
  240. void enable_scu(void)
  241. {
  242. struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
  243. u32 reg;
  244. /* If SCU already setup/enabled, return */
  245. if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
  246. return;
  247. /* Invalidate all ways for all processors */
  248. writel(0xFFFF, &scu->scu_inv_all);
  249. /* Enable SCU - bit 0 */
  250. reg = readl(&scu->scu_ctrl);
  251. reg |= SCU_CTRL_ENABLE;
  252. writel(reg, &scu->scu_ctrl);
  253. }
  254. void init_pmc_scratch(void)
  255. {
  256. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  257. int i;
  258. /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
  259. for (i = 0; i < 23; i++)
  260. writel(0, &pmc->pmc_scratch1+i);
  261. /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
  262. writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
  263. }
  264. void cpu_start(void)
  265. {
  266. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  267. /* enable JTAG */
  268. writel(0xC0, &pmt->pmt_cfg_ctl);
  269. if (s_first_boot) {
  270. /*
  271. * Need to set this before cold-booting,
  272. * otherwise we'll end up in an infinite loop.
  273. */
  274. s_first_boot = 0;
  275. cold_boot();
  276. }
  277. }
  278. void tegra2_start()
  279. {
  280. if (s_first_boot) {
  281. /* Init Debug UART Port (115200 8n1) */
  282. uart_init();
  283. /* Init PMC scratch memory */
  284. init_pmc_scratch();
  285. }
  286. #ifdef CONFIG_ENABLE_CORTEXA9
  287. /* take the mpcore out of reset */
  288. cpu_start();
  289. /* configure cache */
  290. cache_configure();
  291. #endif
  292. }