cpu.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * Copyright (c) 2010-2015, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/clock.h>
  9. #include <asm/arch/gp_padctrl.h>
  10. #include <asm/arch/pinmux.h>
  11. #include <asm/arch/tegra.h>
  12. #include <asm/arch-tegra/clk_rst.h>
  13. #include <asm/arch-tegra/pmc.h>
  14. #include <asm/arch-tegra/scu.h>
  15. #include "cpu.h"
  16. int get_num_cpus(void)
  17. {
  18. struct apb_misc_gp_ctlr *gp;
  19. uint rev;
  20. debug("%s entry\n", __func__);
  21. gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
  22. rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
  23. switch (rev) {
  24. case CHIPID_TEGRA20:
  25. return 2;
  26. break;
  27. case CHIPID_TEGRA30:
  28. case CHIPID_TEGRA114:
  29. case CHIPID_TEGRA124:
  30. case CHIPID_TEGRA210:
  31. default:
  32. return 4;
  33. break;
  34. }
  35. }
  36. /*
  37. * Timing tables for each SOC for all four oscillator options.
  38. */
  39. struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
  40. /*
  41. * T20: 1 GHz
  42. *
  43. * Register Field Bits Width
  44. * ------------------------------
  45. * PLLX_BASE p 22:20 3
  46. * PLLX_BASE n 17: 8 10
  47. * PLLX_BASE m 4: 0 5
  48. * PLLX_MISC cpcon 11: 8 4
  49. */
  50. {
  51. { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
  52. { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
  53. { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
  54. { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
  55. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */
  56. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */
  57. },
  58. /*
  59. * T25: 1.2 GHz
  60. *
  61. * Register Field Bits Width
  62. * ------------------------------
  63. * PLLX_BASE p 22:20 3
  64. * PLLX_BASE n 17: 8 10
  65. * PLLX_BASE m 4: 0 5
  66. * PLLX_MISC cpcon 11: 8 4
  67. */
  68. {
  69. { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
  70. { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
  71. { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
  72. { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
  73. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */
  74. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */
  75. },
  76. /*
  77. * T30: 600 MHz
  78. *
  79. * Register Field Bits Width
  80. * ------------------------------
  81. * PLLX_BASE p 22:20 3
  82. * PLLX_BASE n 17: 8 10
  83. * PLLX_BASE m 4: 0 5
  84. * PLLX_MISC cpcon 11: 8 4
  85. */
  86. {
  87. { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
  88. { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
  89. { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
  90. { .n = 600, .m = 26, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
  91. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */
  92. { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */
  93. },
  94. /*
  95. * T114: 700 MHz
  96. *
  97. * Register Field Bits Width
  98. * ------------------------------
  99. * PLLX_BASE p 23:20 4
  100. * PLLX_BASE n 15: 8 8
  101. * PLLX_BASE m 7: 0 8
  102. */
  103. {
  104. { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
  105. { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
  106. { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
  107. { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
  108. { .n = 0, .m = 0, .p = 0 }, /* OSC: 38.4 MHz (N/A) */
  109. { .n = 0, .m = 0, .p = 0 }, /* OSC: 48.0 MHz (N/A) */
  110. },
  111. /*
  112. * T124: 700 MHz
  113. *
  114. * Register Field Bits Width
  115. * ------------------------------
  116. * PLLX_BASE p 23:20 4
  117. * PLLX_BASE n 15: 8 8
  118. * PLLX_BASE m 7: 0 8
  119. */
  120. {
  121. { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
  122. { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
  123. { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
  124. { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
  125. { .n = 0, .m = 0, .p = 0 }, /* OSC: 38.4 MHz (N/A) */
  126. { .n = 0, .m = 0, .p = 0 }, /* OSC: 48.0 MHz (N/A) */
  127. },
  128. /*
  129. * T210: 700 MHz
  130. *
  131. * Register Field Bits Width
  132. * ------------------------------
  133. * PLLX_BASE p 24:20 5
  134. * PLLX_BASE n 15: 8 8
  135. * PLLX_BASE m 7: 0 8
  136. */
  137. {
  138. { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz = 702 MHz*/
  139. { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz = 700.8 MHz*/
  140. { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz = 696 MHz*/
  141. { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz = 702 MHz*/
  142. { .n = 36, .m = 1, .p = 1 }, /* OSC: 38.4 MHz = 691.2 MHz */
  143. { .n = 58, .m = 2, .p = 1 }, /* OSC: 48.0 MHz = 696 MHz */
  144. },
  145. };
  146. static inline void pllx_set_iddq(void)
  147. {
  148. #if defined(CONFIG_TEGRA124) || defined(CONFIG_TEGRA210)
  149. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  150. u32 reg;
  151. debug("%s entry\n", __func__);
  152. /* Disable IDDQ */
  153. reg = readl(&clkrst->crc_pllx_misc3);
  154. reg &= ~PLLX_IDDQ_MASK;
  155. writel(reg, &clkrst->crc_pllx_misc3);
  156. udelay(2);
  157. debug("%s: IDDQ: PLLX IDDQ = 0x%08X\n", __func__,
  158. readl(&clkrst->crc_pllx_misc3));
  159. #endif
  160. }
  161. int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
  162. u32 divp, u32 cpcon)
  163. {
  164. struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
  165. int chip = tegra_get_chip();
  166. u32 reg;
  167. debug("%s entry\n", __func__);
  168. /* If PLLX is already enabled, just return */
  169. if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
  170. debug("%s: PLLX already enabled, returning\n", __func__);
  171. return 0;
  172. }
  173. pllx_set_iddq();
  174. /* Set BYPASS, m, n and p to PLLX_BASE */
  175. reg = PLL_BYPASS_MASK | (divm << pllinfo->m_shift);
  176. reg |= (divn << pllinfo->n_shift) | (divp << pllinfo->p_shift);
  177. writel(reg, &pll->pll_base);
  178. /* Set cpcon to PLLX_MISC */
  179. if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
  180. reg = (cpcon << pllinfo->kcp_shift);
  181. else
  182. reg = 0;
  183. /*
  184. * TODO(twarren@nvidia.com) Check which SoCs use DCCON
  185. * and add to pllinfo table if needed!
  186. */
  187. /* Set dccon to PLLX_MISC if freq > 600MHz */
  188. if (divn > 600)
  189. reg |= (1 << PLL_DCCON_SHIFT);
  190. writel(reg, &pll->pll_misc);
  191. /* Disable BYPASS */
  192. reg = readl(&pll->pll_base);
  193. reg &= ~PLL_BYPASS_MASK;
  194. writel(reg, &pll->pll_base);
  195. debug("%s: base = 0x%08X\n", __func__, reg);
  196. /* Set lock_enable to PLLX_MISC if lock_ena is valid (i.e. 0-31) */
  197. reg = readl(&pll->pll_misc);
  198. if (pllinfo->lock_ena < 32)
  199. reg |= (1 << pllinfo->lock_ena);
  200. writel(reg, &pll->pll_misc);
  201. debug("%s: misc = 0x%08X\n", __func__, reg);
  202. /* Enable PLLX last, once it's all configured */
  203. reg = readl(&pll->pll_base);
  204. reg |= PLL_ENABLE_MASK;
  205. writel(reg, &pll->pll_base);
  206. debug("%s: base final = 0x%08X\n", __func__, reg);
  207. return 0;
  208. }
  209. void init_pllx(void)
  210. {
  211. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  212. struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
  213. int soc_type, sku_info, chip_sku;
  214. enum clock_osc_freq osc;
  215. struct clk_pll_table *sel;
  216. debug("%s entry\n", __func__);
  217. /* get SOC (chip) type */
  218. soc_type = tegra_get_chip();
  219. debug("%s: SoC = 0x%02X\n", __func__, soc_type);
  220. /* get SKU info */
  221. sku_info = tegra_get_sku_info();
  222. debug("%s: SKU info byte = 0x%02X\n", __func__, sku_info);
  223. /* get chip SKU, combo of the above info */
  224. chip_sku = tegra_get_chip_sku();
  225. debug("%s: Chip SKU = %d\n", __func__, chip_sku);
  226. /* get osc freq */
  227. osc = clock_get_osc_freq();
  228. debug("%s: osc = %d\n", __func__, osc);
  229. /* set pllx */
  230. sel = &tegra_pll_x_table[chip_sku][osc];
  231. pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
  232. }
  233. void enable_cpu_clock(int enable)
  234. {
  235. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  236. u32 clk;
  237. debug("%s entry\n", __func__);
  238. /*
  239. * NOTE:
  240. * Regardless of whether the request is to enable or disable the CPU
  241. * clock, every processor in the CPU complex except the master (CPU 0)
  242. * will have it's clock stopped because the AVP only talks to the
  243. * master.
  244. */
  245. if (enable) {
  246. /* Initialize PLLX */
  247. init_pllx();
  248. /* Wait until all clocks are stable */
  249. udelay(PLL_STABILIZATION_DELAY);
  250. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  251. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  252. }
  253. /*
  254. * Read the register containing the individual CPU clock enables and
  255. * always stop the clocks to CPUs > 0.
  256. */
  257. clk = readl(&clkrst->crc_clk_cpu_cmplx);
  258. clk |= 1 << CPU1_CLK_STP_SHIFT;
  259. if (get_num_cpus() == 4)
  260. clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
  261. /* Stop/Unstop the CPU clock */
  262. clk &= ~CPU0_CLK_STP_MASK;
  263. clk |= !enable << CPU0_CLK_STP_SHIFT;
  264. writel(clk, &clkrst->crc_clk_cpu_cmplx);
  265. clock_enable(PERIPH_ID_CPU);
  266. }
  267. static int is_cpu_powered(void)
  268. {
  269. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  270. return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
  271. }
  272. static void remove_cpu_io_clamps(void)
  273. {
  274. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  275. u32 reg;
  276. debug("%s entry\n", __func__);
  277. /* Remove the clamps on the CPU I/O signals */
  278. reg = readl(&pmc->pmc_remove_clamping);
  279. reg |= CPU_CLMP;
  280. writel(reg, &pmc->pmc_remove_clamping);
  281. /* Give I/O signals time to stabilize */
  282. udelay(IO_STABILIZATION_DELAY);
  283. }
  284. void powerup_cpu(void)
  285. {
  286. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  287. u32 reg;
  288. int timeout = IO_STABILIZATION_DELAY;
  289. debug("%s entry\n", __func__);
  290. if (!is_cpu_powered()) {
  291. /* Toggle the CPU power state (OFF -> ON) */
  292. reg = readl(&pmc->pmc_pwrgate_toggle);
  293. reg &= PARTID_CP;
  294. reg |= START_CP;
  295. writel(reg, &pmc->pmc_pwrgate_toggle);
  296. /* Wait for the power to come up */
  297. while (!is_cpu_powered()) {
  298. if (timeout-- == 0)
  299. printf("CPU failed to power up!\n");
  300. else
  301. udelay(10);
  302. }
  303. /*
  304. * Remove the I/O clamps from CPU power partition.
  305. * Recommended only on a Warm boot, if the CPU partition gets
  306. * power gated. Shouldn't cause any harm when called after a
  307. * cold boot according to HW, probably just redundant.
  308. */
  309. remove_cpu_io_clamps();
  310. }
  311. }
  312. void reset_A9_cpu(int reset)
  313. {
  314. /*
  315. * NOTE: Regardless of whether the request is to hold the CPU in reset
  316. * or take it out of reset, every processor in the CPU complex
  317. * except the master (CPU 0) will be held in reset because the
  318. * AVP only talks to the master. The AVP does not know that there
  319. * are multiple processors in the CPU complex.
  320. */
  321. int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
  322. int num_cpus = get_num_cpus();
  323. int cpu;
  324. debug("%s entry\n", __func__);
  325. /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
  326. for (cpu = 1; cpu < num_cpus; cpu++)
  327. reset_cmplx_set_enable(cpu, mask, 1);
  328. reset_cmplx_set_enable(0, mask, reset);
  329. /* Enable/Disable master CPU reset */
  330. reset_set_enable(PERIPH_ID_CPU, reset);
  331. }
  332. void clock_enable_coresight(int enable)
  333. {
  334. u32 rst, src = 2;
  335. debug("%s entry\n", __func__);
  336. clock_set_enable(PERIPH_ID_CORESIGHT, enable);
  337. reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
  338. if (enable) {
  339. /*
  340. * Put CoreSight on PLLP_OUT0 and divide it down as per
  341. * PLLP base frequency based on SoC type (T20/T30+).
  342. * Clock divider request would setup CSITE clock as 144MHz
  343. * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
  344. */
  345. src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ);
  346. clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
  347. /* Unlock the CPU CoreSight interfaces */
  348. rst = CORESIGHT_UNLOCK;
  349. writel(rst, CSITE_CPU_DBG0_LAR);
  350. writel(rst, CSITE_CPU_DBG1_LAR);
  351. if (get_num_cpus() == 4) {
  352. writel(rst, CSITE_CPU_DBG2_LAR);
  353. writel(rst, CSITE_CPU_DBG3_LAR);
  354. }
  355. }
  356. }
  357. void halt_avp(void)
  358. {
  359. debug("%s entry\n", __func__);
  360. for (;;) {
  361. writel(HALT_COP_EVENT_JTAG | (FLOW_MODE_STOP << 29),
  362. FLOW_CTLR_HALT_COP_EVENTS);
  363. }
  364. }