cpu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (c) 2010-2012, 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. gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
  31. rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
  32. switch (rev) {
  33. case CHIPID_TEGRA20:
  34. return 2;
  35. break;
  36. case CHIPID_TEGRA30:
  37. case CHIPID_TEGRA114:
  38. default:
  39. return 4;
  40. break;
  41. }
  42. }
  43. /*
  44. * Timing tables for each SOC for all four oscillator options.
  45. */
  46. struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
  47. /*
  48. * T20: 1 GHz
  49. *
  50. * Register Field Bits Width
  51. * ------------------------------
  52. * PLLX_BASE p 22:20 3
  53. * PLLX_BASE n 17: 8 10
  54. * PLLX_BASE m 4: 0 5
  55. * PLLX_MISC cpcon 11: 8 4
  56. */
  57. {
  58. { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
  59. { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
  60. { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
  61. { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
  62. },
  63. /*
  64. * T25: 1.2 GHz
  65. *
  66. * Register Field Bits Width
  67. * ------------------------------
  68. * PLLX_BASE p 22:20 3
  69. * PLLX_BASE n 17: 8 10
  70. * PLLX_BASE m 4: 0 5
  71. * PLLX_MISC cpcon 11: 8 4
  72. */
  73. {
  74. { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
  75. { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
  76. { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
  77. { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
  78. },
  79. /*
  80. * T30: 1.4 GHz
  81. *
  82. * Register Field Bits Width
  83. * ------------------------------
  84. * PLLX_BASE p 22:20 3
  85. * PLLX_BASE n 17: 8 10
  86. * PLLX_BASE m 4: 0 5
  87. * PLLX_MISC cpcon 11: 8 4
  88. */
  89. {
  90. { .n = 862, .m = 8, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
  91. { .n = 583, .m = 8, .p = 0, .cpcon = 4 }, /* OSC: 19.2 MHz */
  92. { .n = 700, .m = 6, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
  93. { .n = 700, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
  94. },
  95. /*
  96. * T114: 700 MHz
  97. *
  98. * Register Field Bits Width
  99. * ------------------------------
  100. * PLLX_BASE p 23:20 4
  101. * PLLX_BASE n 15: 8 8
  102. * PLLX_BASE m 7: 0 8
  103. */
  104. {
  105. { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
  106. { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
  107. { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
  108. { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
  109. },
  110. };
  111. void adjust_pllp_out_freqs(void)
  112. {
  113. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  114. struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_PERIPH];
  115. u32 reg;
  116. /* Set T30 PLLP_OUT1, 2, 3 & 4 freqs to 9.6, 48, 102 & 204MHz */
  117. reg = readl(&pll->pll_out[0]); /* OUTA, contains OUT2 / OUT1 */
  118. reg |= (IN_408_OUT_48_DIVISOR << PLLP_OUT2_RATIO) | PLLP_OUT2_OVR
  119. | (IN_408_OUT_9_6_DIVISOR << PLLP_OUT1_RATIO) | PLLP_OUT1_OVR;
  120. writel(reg, &pll->pll_out[0]);
  121. reg = readl(&pll->pll_out[1]); /* OUTB, contains OUT4 / OUT3 */
  122. reg |= (IN_408_OUT_204_DIVISOR << PLLP_OUT4_RATIO) | PLLP_OUT4_OVR
  123. | (IN_408_OUT_102_DIVISOR << PLLP_OUT3_RATIO) | PLLP_OUT3_OVR;
  124. writel(reg, &pll->pll_out[1]);
  125. }
  126. int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
  127. u32 divp, u32 cpcon)
  128. {
  129. u32 reg;
  130. /* If PLLX is already enabled, just return */
  131. if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
  132. debug("pllx_set_rate: PLLX already enabled, returning\n");
  133. return 0;
  134. }
  135. debug(" pllx_set_rate entry\n");
  136. /* Set BYPASS, m, n and p to PLLX_BASE */
  137. reg = PLL_BYPASS_MASK | (divm << PLL_DIVM_SHIFT);
  138. reg |= ((divn << PLL_DIVN_SHIFT) | (divp << PLL_DIVP_SHIFT));
  139. writel(reg, &pll->pll_base);
  140. /* Set cpcon to PLLX_MISC */
  141. reg = (cpcon << PLL_CPCON_SHIFT);
  142. /* Set dccon to PLLX_MISC if freq > 600MHz */
  143. if (divn > 600)
  144. reg |= (1 << PLL_DCCON_SHIFT);
  145. writel(reg, &pll->pll_misc);
  146. /* Enable PLLX */
  147. reg = readl(&pll->pll_base);
  148. reg |= PLL_ENABLE_MASK;
  149. /* Disable BYPASS */
  150. reg &= ~PLL_BYPASS_MASK;
  151. writel(reg, &pll->pll_base);
  152. /* Set lock_enable to PLLX_MISC */
  153. reg = readl(&pll->pll_misc);
  154. reg |= PLL_LOCK_ENABLE_MASK;
  155. writel(reg, &pll->pll_misc);
  156. return 0;
  157. }
  158. void init_pllx(void)
  159. {
  160. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  161. struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
  162. int soc_type, sku_info, chip_sku;
  163. enum clock_osc_freq osc;
  164. struct clk_pll_table *sel;
  165. debug("init_pllx entry\n");
  166. /* get SOC (chip) type */
  167. soc_type = tegra_get_chip();
  168. debug(" init_pllx: SoC = 0x%02X\n", soc_type);
  169. /* get SKU info */
  170. sku_info = tegra_get_sku_info();
  171. debug(" init_pllx: SKU info byte = 0x%02X\n", sku_info);
  172. /* get chip SKU, combo of the above info */
  173. chip_sku = tegra_get_chip_sku();
  174. debug(" init_pllx: Chip SKU = %d\n", chip_sku);
  175. /* get osc freq */
  176. osc = clock_get_osc_freq();
  177. debug(" init_pllx: osc = %d\n", osc);
  178. /* set pllx */
  179. sel = &tegra_pll_x_table[chip_sku][osc];
  180. pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
  181. /* adjust PLLP_out1-4 on T3x/T114 */
  182. if (soc_type >= CHIPID_TEGRA30) {
  183. debug(" init_pllx: adjusting PLLP out freqs\n");
  184. adjust_pllp_out_freqs();
  185. }
  186. }
  187. void enable_cpu_clock(int enable)
  188. {
  189. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  190. u32 clk;
  191. /*
  192. * NOTE:
  193. * Regardless of whether the request is to enable or disable the CPU
  194. * clock, every processor in the CPU complex except the master (CPU 0)
  195. * will have it's clock stopped because the AVP only talks to the
  196. * master.
  197. */
  198. if (enable) {
  199. /* Initialize PLLX */
  200. init_pllx();
  201. /* Wait until all clocks are stable */
  202. udelay(PLL_STABILIZATION_DELAY);
  203. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  204. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  205. }
  206. /*
  207. * Read the register containing the individual CPU clock enables and
  208. * always stop the clocks to CPUs > 0.
  209. */
  210. clk = readl(&clkrst->crc_clk_cpu_cmplx);
  211. clk |= 1 << CPU1_CLK_STP_SHIFT;
  212. if (get_num_cpus() == 4)
  213. clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
  214. /* Stop/Unstop the CPU clock */
  215. clk &= ~CPU0_CLK_STP_MASK;
  216. clk |= !enable << CPU0_CLK_STP_SHIFT;
  217. writel(clk, &clkrst->crc_clk_cpu_cmplx);
  218. clock_enable(PERIPH_ID_CPU);
  219. }
  220. static int is_cpu_powered(void)
  221. {
  222. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  223. return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
  224. }
  225. static void remove_cpu_io_clamps(void)
  226. {
  227. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  228. u32 reg;
  229. /* Remove the clamps on the CPU I/O signals */
  230. reg = readl(&pmc->pmc_remove_clamping);
  231. reg |= CPU_CLMP;
  232. writel(reg, &pmc->pmc_remove_clamping);
  233. /* Give I/O signals time to stabilize */
  234. udelay(IO_STABILIZATION_DELAY);
  235. }
  236. void powerup_cpu(void)
  237. {
  238. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  239. u32 reg;
  240. int timeout = IO_STABILIZATION_DELAY;
  241. if (!is_cpu_powered()) {
  242. /* Toggle the CPU power state (OFF -> ON) */
  243. reg = readl(&pmc->pmc_pwrgate_toggle);
  244. reg &= PARTID_CP;
  245. reg |= START_CP;
  246. writel(reg, &pmc->pmc_pwrgate_toggle);
  247. /* Wait for the power to come up */
  248. while (!is_cpu_powered()) {
  249. if (timeout-- == 0)
  250. printf("CPU failed to power up!\n");
  251. else
  252. udelay(10);
  253. }
  254. /*
  255. * Remove the I/O clamps from CPU power partition.
  256. * Recommended only on a Warm boot, if the CPU partition gets
  257. * power gated. Shouldn't cause any harm when called after a
  258. * cold boot according to HW, probably just redundant.
  259. */
  260. remove_cpu_io_clamps();
  261. }
  262. }
  263. void reset_A9_cpu(int reset)
  264. {
  265. /*
  266. * NOTE: Regardless of whether the request is to hold the CPU in reset
  267. * or take it out of reset, every processor in the CPU complex
  268. * except the master (CPU 0) will be held in reset because the
  269. * AVP only talks to the master. The AVP does not know that there
  270. * are multiple processors in the CPU complex.
  271. */
  272. int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
  273. int num_cpus = get_num_cpus();
  274. int cpu;
  275. debug("reset_a9_cpu entry\n");
  276. /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
  277. for (cpu = 1; cpu < num_cpus; cpu++)
  278. reset_cmplx_set_enable(cpu, mask, 1);
  279. reset_cmplx_set_enable(0, mask, reset);
  280. /* Enable/Disable master CPU reset */
  281. reset_set_enable(PERIPH_ID_CPU, reset);
  282. }
  283. void clock_enable_coresight(int enable)
  284. {
  285. u32 rst, src = 2;
  286. int soc_type;
  287. debug("clock_enable_coresight entry\n");
  288. clock_set_enable(PERIPH_ID_CORESIGHT, enable);
  289. reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
  290. if (enable) {
  291. /*
  292. * Put CoreSight on PLLP_OUT0 and divide it down as per
  293. * PLLP base frequency based on SoC type (T20/T30/T114).
  294. * Clock divider request would setup CSITE clock as 144MHz
  295. * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
  296. */
  297. soc_type = tegra_get_chip();
  298. if (soc_type == CHIPID_TEGRA30 || soc_type == CHIPID_TEGRA114)
  299. src = CLK_DIVIDER(NVBL_PLLP_KHZ, 204000);
  300. else if (soc_type == CHIPID_TEGRA20)
  301. src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
  302. else
  303. printf("%s: Unknown SoC type %X!\n",
  304. __func__, soc_type);
  305. clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
  306. /* Unlock the CPU CoreSight interfaces */
  307. rst = CORESIGHT_UNLOCK;
  308. writel(rst, CSITE_CPU_DBG0_LAR);
  309. writel(rst, CSITE_CPU_DBG1_LAR);
  310. if (get_num_cpus() == 4) {
  311. writel(rst, CSITE_CPU_DBG2_LAR);
  312. writel(rst, CSITE_CPU_DBG3_LAR);
  313. }
  314. }
  315. }
  316. void halt_avp(void)
  317. {
  318. for (;;) {
  319. writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
  320. | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
  321. FLOW_CTLR_HALT_COP_EVENTS);
  322. }
  323. }