warmboot_avp.c 6.7 KB

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