cpu.c 11 KB

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