warmboot_avp.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 <common.h>
  24. #include <asm/io.h>
  25. #include <asm/arch/clock.h>
  26. #include <asm/arch/flow.h>
  27. #include <asm/arch/pinmux.h>
  28. #include <asm/arch/tegra.h>
  29. #include <asm/arch-tegra/ap.h>
  30. #include <asm/arch-tegra/clk_rst.h>
  31. #include <asm/arch-tegra/pmc.h>
  32. #include <asm/arch-tegra/warmboot.h>
  33. #include "warmboot_avp.h"
  34. #define DEBUG_RESET_CORESIGHT
  35. void wb_start(void)
  36. {
  37. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  38. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  39. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  40. struct clk_rst_ctlr *clkrst =
  41. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  42. union osc_ctrl_reg osc_ctrl;
  43. union pllx_base_reg pllx_base;
  44. union pllx_misc_reg pllx_misc;
  45. union scratch3_reg scratch3;
  46. u32 reg;
  47. /* enable JTAG & TBE */
  48. writel(CONFIG_CTL_TBE | CONFIG_CTL_JTAG, &pmt->pmt_cfg_ctl);
  49. /* Are we running where we're supposed to be? */
  50. asm volatile (
  51. "adr %0, wb_start;" /* reg: wb_start address */
  52. : "=r"(reg) /* output */
  53. /* no input, no clobber list */
  54. );
  55. if (reg != NV_WB_RUN_ADDRESS)
  56. goto do_reset;
  57. /* Are we running with AVP? */
  58. if (readl(NV_PA_PG_UP_BASE + PG_UP_TAG_0) != PG_UP_TAG_AVP)
  59. goto do_reset;
  60. #ifdef DEBUG_RESET_CORESIGHT
  61. /* Assert CoreSight reset */
  62. reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
  63. reg |= SWR_CSITE_RST;
  64. writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
  65. #endif
  66. /* TODO: Set the drive strength - maybe make this a board parameter? */
  67. osc_ctrl.word = readl(&clkrst->crc_osc_ctrl);
  68. osc_ctrl.xofs = 4;
  69. osc_ctrl.xoe = 1;
  70. writel(osc_ctrl.word, &clkrst->crc_osc_ctrl);
  71. /* Power up the CPU complex if necessary */
  72. if (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU)) {
  73. reg = PWRGATE_TOGGLE_PARTID_CPU | PWRGATE_TOGGLE_START;
  74. writel(reg, &pmc->pmc_pwrgate_toggle);
  75. while (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU))
  76. ;
  77. }
  78. /* Remove the I/O clamps from the CPU power partition. */
  79. reg = readl(&pmc->pmc_remove_clamping);
  80. reg |= CPU_CLMP;
  81. writel(reg, &pmc->pmc_remove_clamping);
  82. reg = EVENT_ZERO_VAL_20 | EVENT_MSEC | EVENT_MODE_STOP;
  83. writel(reg, &flow->halt_cop_events);
  84. /* Assert CPU complex reset */
  85. reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
  86. reg |= CPU_RST;
  87. writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
  88. /* Hold both CPUs in reset */
  89. reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_CPURESET1 | CPU_CMPLX_DERESET0 |
  90. CPU_CMPLX_DERESET1 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DBGRESET1;
  91. writel(reg, &clkrst->crc_cpu_cmplx_set);
  92. /* Halt CPU1 at the flow controller for uni-processor configurations */
  93. writel(EVENT_MODE_STOP, &flow->halt_cpu1_events);
  94. /*
  95. * Set the CPU reset vector. SCRATCH41 contains the physical
  96. * address of the CPU-side restoration code.
  97. */
  98. reg = readl(&pmc->pmc_scratch41);
  99. writel(reg, EXCEP_VECTOR_CPU_RESET_VECTOR);
  100. /* Select CPU complex clock source */
  101. writel(CCLK_PLLP_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  102. /* Start the CPU0 clock and stop the CPU1 clock */
  103. reg = CPU_CMPLX_CPU_BRIDGE_CLKDIV_4 | CPU_CMPLX_CPU0_CLK_STP_RUN |
  104. CPU_CMPLX_CPU1_CLK_STP_STOP;
  105. writel(reg, &clkrst->crc_clk_cpu_cmplx);
  106. /* Enable the CPU complex clock */
  107. reg = readl(&clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
  108. reg |= CLK_ENB_CPU;
  109. writel(reg, &clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
  110. /* Make sure the resets were held for at least 2 microseconds */
  111. reg = readl(TIMER_USEC_CNTR);
  112. while (readl(TIMER_USEC_CNTR) <= (reg + 2))
  113. ;
  114. #ifdef DEBUG_RESET_CORESIGHT
  115. /*
  116. * De-assert CoreSight reset.
  117. * NOTE: We're leaving the CoreSight clock on the oscillator for
  118. * now. It will be restored to its original clock source
  119. * when the CPU-side restoration code runs.
  120. */
  121. reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
  122. reg &= ~SWR_CSITE_RST;
  123. writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
  124. #endif
  125. /* Unlock the CPU CoreSight interfaces */
  126. reg = 0xC5ACCE55;
  127. writel(reg, CSITE_CPU_DBG0_LAR);
  128. writel(reg, CSITE_CPU_DBG1_LAR);
  129. /*
  130. * Sample the microsecond timestamp again. This is the time we must
  131. * use when returning from LP0 for PLL stabilization delays.
  132. */
  133. reg = readl(TIMER_USEC_CNTR);
  134. writel(reg, &pmc->pmc_scratch1);
  135. pllx_base.word = 0;
  136. pllx_misc.word = 0;
  137. scratch3.word = readl(&pmc->pmc_scratch3);
  138. /* Get the OSC. For 19.2 MHz, use 19 to make the calculations easier */
  139. reg = (readl(TIMER_USEC_CFG) & USEC_CFG_DIVISOR_MASK) + 1;
  140. /*
  141. * According to the TRM, for 19.2MHz OSC, the USEC_DIVISOR is 0x5f, and
  142. * USEC_DIVIDEND is 0x04. So, if USEC_DIVISOR > 26, OSC is 19.2 MHz.
  143. *
  144. * reg is used to calculate the pllx freq, which is used to determine if
  145. * to set dccon or not.
  146. */
  147. if (reg > 26)
  148. reg = 19;
  149. /* PLLX_BASE.PLLX_DIVM */
  150. if (scratch3.pllx_base_divm == reg)
  151. reg = 0;
  152. else
  153. reg = 1;
  154. /* PLLX_BASE.PLLX_DIVN */
  155. pllx_base.divn = scratch3.pllx_base_divn;
  156. reg = scratch3.pllx_base_divn << reg;
  157. /* PLLX_BASE.PLLX_DIVP */
  158. pllx_base.divp = scratch3.pllx_base_divp;
  159. reg = reg >> scratch3.pllx_base_divp;
  160. pllx_base.bypass = 1;
  161. /* PLLX_MISC_DCCON must be set for pllx frequency > 600 MHz. */
  162. if (reg > 600)
  163. pllx_misc.dccon = 1;
  164. /* PLLX_MISC_LFCON */
  165. pllx_misc.lfcon = scratch3.pllx_misc_lfcon;
  166. /* PLLX_MISC_CPCON */
  167. pllx_misc.cpcon = scratch3.pllx_misc_cpcon;
  168. writel(pllx_misc.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_misc);
  169. writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  170. pllx_base.enable = 1;
  171. writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  172. pllx_base.bypass = 0;
  173. writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  174. writel(0, flow->halt_cpu_events);
  175. reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DERESET0;
  176. writel(reg, &clkrst->crc_cpu_cmplx_clr);
  177. reg = PLLM_OUT1_RSTN_RESET_DISABLE | PLLM_OUT1_CLKEN_ENABLE |
  178. PLLM_OUT1_RATIO_VAL_8;
  179. writel(reg, &clkrst->crc_pll[CLOCK_ID_MEMORY].pll_out[0]);
  180. reg = SCLK_SWAKE_FIQ_SRC_PLLM_OUT1 | SCLK_SWAKE_IRQ_SRC_PLLM_OUT1 |
  181. SCLK_SWAKE_RUN_SRC_PLLM_OUT1 | SCLK_SWAKE_IDLE_SRC_PLLM_OUT1 |
  182. SCLK_SYS_STATE_IDLE;
  183. writel(reg, &clkrst->crc_sclk_brst_pol);
  184. /* avp_resume: no return after the write */
  185. reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
  186. reg &= ~CPU_RST;
  187. writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
  188. /* avp_halt: */
  189. avp_halt:
  190. reg = EVENT_MODE_STOP | EVENT_JTAG;
  191. writel(reg, flow->halt_cop_events);
  192. goto avp_halt;
  193. do_reset:
  194. /*
  195. * Execution comes here if something goes wrong. The chip is reset and
  196. * a cold boot is performed.
  197. */
  198. writel(SWR_TRIG_SYS_RST, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
  199. goto do_reset;
  200. }
  201. /*
  202. * wb_end() is a dummy function, and must be directly following wb_start(),
  203. * and is used to calculate the size of wb_start().
  204. */
  205. void wb_end(void)
  206. {
  207. }