cpu.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * (C) Copyright 2013
  3. * NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/ahb.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/flow.h>
  12. #include <asm/arch/pinmux.h>
  13. #include <asm/arch/tegra.h>
  14. #include <asm/arch-tegra/clk_rst.h>
  15. #include <asm/arch-tegra/pmc.h>
  16. #include <asm/arch-tegra/ap.h>
  17. #include "../tegra-common/cpu.h"
  18. /* Tegra124-specific CPU init code */
  19. static void enable_cpu_power_rail(void)
  20. {
  21. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  22. debug("enable_cpu_power_rail entry\n");
  23. /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
  24. pinmux_tristate_disable(PINGRP_PWR_I2C_SCL);
  25. pinmux_tristate_disable(PINGRP_PWR_I2C_SDA);
  26. pmic_enable_cpu_vdd();
  27. /*
  28. * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
  29. * set it for 5ms as per SysEng (102MHz*5ms = 510000 (7C830h).
  30. */
  31. writel(0x7C830, &pmc->pmc_cpupwrgood_timer);
  32. /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
  33. clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
  34. setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
  35. }
  36. static void enable_cpu_clocks(void)
  37. {
  38. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  39. u32 reg;
  40. debug("enable_cpu_clocks entry\n");
  41. /* Wait for PLL-X to lock */
  42. do {
  43. reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
  44. debug("%s: PLLX base = 0x%08X\n", __func__, reg);
  45. } while ((reg & PLL_LOCK_MASK) == 0);
  46. debug("%s: PLLX locked, delay for stable clocks\n", __func__);
  47. /* Wait until all clocks are stable */
  48. udelay(PLL_STABILIZATION_DELAY);
  49. debug("%s: Setting CCLK_BURST and DIVIDER\n", __func__);
  50. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  51. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  52. debug("%s: Enabling clock to all CPUs\n", __func__);
  53. /* Enable the clock to all CPUs */
  54. reg = CLR_CPU3_CLK_STP | CLR_CPU2_CLK_STP | CLR_CPU1_CLK_STP |
  55. CLR_CPU0_CLK_STP;
  56. writel(reg, &clkrst->crc_clk_cpu_cmplx_clr);
  57. debug("%s: Enabling main CPU complex clocks\n", __func__);
  58. /* Always enable the main CPU complex clocks */
  59. clock_enable(PERIPH_ID_CPU);
  60. clock_enable(PERIPH_ID_CPULP);
  61. clock_enable(PERIPH_ID_CPUG);
  62. debug("%s: Done\n", __func__);
  63. }
  64. static void remove_cpu_resets(void)
  65. {
  66. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  67. u32 reg;
  68. debug("remove_cpu_resets entry\n");
  69. /* Take the slow and fast partitions out of reset */
  70. reg = CLR_NONCPURESET;
  71. writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
  72. writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
  73. /* Clear the SW-controlled reset of the slow cluster */
  74. reg = CLR_CPURESET0 | CLR_DBGRESET0 | CLR_CORERESET0 | CLR_CXRESET0 |
  75. CLR_L2RESET | CLR_PRESETDBG;
  76. writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
  77. /* Clear the SW-controlled reset of the fast cluster */
  78. reg = CLR_CPURESET0 | CLR_DBGRESET0 | CLR_CORERESET0 | CLR_CXRESET0 |
  79. CLR_CPURESET1 | CLR_DBGRESET1 | CLR_CORERESET1 | CLR_CXRESET1 |
  80. CLR_CPURESET2 | CLR_DBGRESET2 | CLR_CORERESET2 | CLR_CXRESET2 |
  81. CLR_CPURESET3 | CLR_DBGRESET3 | CLR_CORERESET3 | CLR_CXRESET3 |
  82. CLR_L2RESET | CLR_PRESETDBG;
  83. writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
  84. }
  85. /**
  86. * The Tegra124 requires some special clock initialization, including setting up
  87. * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
  88. */
  89. void tegra124_init_clocks(void)
  90. {
  91. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  92. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  93. struct clk_rst_ctlr *clkrst =
  94. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  95. u32 val;
  96. debug("tegra124_init_clocks entry\n");
  97. /* Set active CPU cluster to G */
  98. clrbits_le32(&flow->cluster_control, 1);
  99. /* Change the oscillator drive strength */
  100. val = readl(&clkrst->crc_osc_ctrl);
  101. val &= ~OSC_XOFS_MASK;
  102. val |= (OSC_DRIVE_STRENGTH << OSC_XOFS_SHIFT);
  103. writel(val, &clkrst->crc_osc_ctrl);
  104. /* Update same value in PMC_OSC_EDPD_OVER XOFS field for warmboot */
  105. val = readl(&pmc->pmc_osc_edpd_over);
  106. val &= ~PMC_XOFS_MASK;
  107. val |= (OSC_DRIVE_STRENGTH << PMC_XOFS_SHIFT);
  108. writel(val, &pmc->pmc_osc_edpd_over);
  109. /* Set HOLD_CKE_LOW_EN to 1 */
  110. setbits_le32(&pmc->pmc_cntrl2, HOLD_CKE_LOW_EN);
  111. debug("Setting up PLLX\n");
  112. init_pllx();
  113. val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
  114. writel(val, &clkrst->crc_clk_sys_rate);
  115. /* Enable clocks to required peripherals. TBD - minimize this list */
  116. debug("Enabling clocks\n");
  117. clock_set_enable(PERIPH_ID_CACHE2, 1);
  118. clock_set_enable(PERIPH_ID_GPIO, 1);
  119. clock_set_enable(PERIPH_ID_TMR, 1);
  120. clock_set_enable(PERIPH_ID_CPU, 1);
  121. clock_set_enable(PERIPH_ID_EMC, 1);
  122. clock_set_enable(PERIPH_ID_I2C5, 1);
  123. clock_set_enable(PERIPH_ID_APBDMA, 1);
  124. clock_set_enable(PERIPH_ID_MEM, 1);
  125. clock_set_enable(PERIPH_ID_CORESIGHT, 1);
  126. clock_set_enable(PERIPH_ID_MSELECT, 1);
  127. clock_set_enable(PERIPH_ID_DVFS, 1);
  128. /*
  129. * Set MSELECT clock source as PLLP (00), and ask for a clock
  130. * divider that would set the MSELECT clock at 102MHz for a
  131. * PLLP base of 408MHz.
  132. */
  133. clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
  134. CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
  135. /* Give clock time to stabilize */
  136. udelay(IO_STABILIZATION_DELAY);
  137. /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
  138. clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
  139. /* Give clock time to stabilize */
  140. udelay(IO_STABILIZATION_DELAY);
  141. /* Take required peripherals out of reset */
  142. debug("Taking periphs out of reset\n");
  143. reset_set_enable(PERIPH_ID_CACHE2, 0);
  144. reset_set_enable(PERIPH_ID_GPIO, 0);
  145. reset_set_enable(PERIPH_ID_TMR, 0);
  146. reset_set_enable(PERIPH_ID_COP, 0);
  147. reset_set_enable(PERIPH_ID_EMC, 0);
  148. reset_set_enable(PERIPH_ID_I2C5, 0);
  149. reset_set_enable(PERIPH_ID_APBDMA, 0);
  150. reset_set_enable(PERIPH_ID_MEM, 0);
  151. reset_set_enable(PERIPH_ID_CORESIGHT, 0);
  152. reset_set_enable(PERIPH_ID_MSELECT, 0);
  153. reset_set_enable(PERIPH_ID_DVFS, 0);
  154. debug("tegra124_init_clocks exit\n");
  155. }
  156. static bool is_partition_powered(u32 partid)
  157. {
  158. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  159. u32 reg;
  160. /* Get power gate status */
  161. reg = readl(&pmc->pmc_pwrgate_status);
  162. return !!(reg & (1 << partid));
  163. }
  164. static void power_partition(u32 partid)
  165. {
  166. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  167. debug("%s: part ID = %08X\n", __func__, partid);
  168. /* Is the partition already on? */
  169. if (!is_partition_powered(partid)) {
  170. /* No, toggle the partition power state (OFF -> ON) */
  171. debug("power_partition, toggling state\n");
  172. writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
  173. /* Wait for the power to come up */
  174. while (!is_partition_powered(partid))
  175. ;
  176. /* Give I/O signals time to stabilize */
  177. udelay(IO_STABILIZATION_DELAY);
  178. }
  179. }
  180. void powerup_cpus(void)
  181. {
  182. debug("powerup_cpus entry\n");
  183. /* We boot to the fast cluster */
  184. debug("powerup_cpus entry: G cluster\n");
  185. /* Power up the fast cluster rail partition */
  186. debug("powerup_cpus: CRAIL\n");
  187. power_partition(CRAIL);
  188. /* Power up the fast cluster non-CPU partition */
  189. debug("powerup_cpus: C0NC\n");
  190. power_partition(C0NC);
  191. /* Power up the fast cluster CPU0 partition */
  192. debug("powerup_cpus: CE0\n");
  193. power_partition(CE0);
  194. debug("powerup_cpus: done\n");
  195. }
  196. void start_cpu(u32 reset_vector)
  197. {
  198. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  199. debug("start_cpu entry, reset_vector = %x\n", reset_vector);
  200. tegra124_init_clocks();
  201. /* Set power-gating timer multiplier */
  202. writel((MULT_8 << TIMER_MULT_SHIFT) | (MULT_8 << TIMER_MULT_CPU_SHIFT),
  203. &pmc->pmc_pwrgate_timer_mult);
  204. enable_cpu_power_rail();
  205. enable_cpu_clocks();
  206. clock_enable_coresight(1);
  207. remove_cpu_resets();
  208. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  209. powerup_cpus();
  210. debug("start_cpu exit, should continue @ reset_vector\n");
  211. }