cpu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * Copyright (c) 2010-2014, 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. * T124: 700 MHz
  112. *
  113. * Register Field Bits Width
  114. * ------------------------------
  115. * PLLX_BASE p 23:20 4
  116. * PLLX_BASE n 15: 8 8
  117. * PLLX_BASE m 7: 0 8
  118. */
  119. {
  120. { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
  121. { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
  122. { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
  123. { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
  124. },
  125. };
  126. static inline void pllx_set_iddq(void)
  127. {
  128. #if defined(CONFIG_TEGRA124)
  129. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  130. u32 reg;
  131. /* Disable IDDQ */
  132. reg = readl(&clkrst->crc_pllx_misc3);
  133. reg &= ~PLLX_IDDQ_MASK;
  134. writel(reg, &clkrst->crc_pllx_misc3);
  135. udelay(2);
  136. debug("%s: IDDQ: PLLX IDDQ = 0x%08X\n", __func__,
  137. readl(&clkrst->crc_pllx_misc3));
  138. #endif
  139. }
  140. int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
  141. u32 divp, u32 cpcon)
  142. {
  143. int chip = tegra_get_chip();
  144. u32 reg;
  145. /* If PLLX is already enabled, just return */
  146. if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
  147. debug("pllx_set_rate: PLLX already enabled, returning\n");
  148. return 0;
  149. }
  150. debug(" pllx_set_rate entry\n");
  151. pllx_set_iddq();
  152. /* Set BYPASS, m, n and p to PLLX_BASE */
  153. reg = PLL_BYPASS_MASK | (divm << PLL_DIVM_SHIFT);
  154. reg |= ((divn << PLL_DIVN_SHIFT) | (divp << PLL_DIVP_SHIFT));
  155. writel(reg, &pll->pll_base);
  156. /* Set cpcon to PLLX_MISC */
  157. if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
  158. reg = (cpcon << PLL_CPCON_SHIFT);
  159. else
  160. reg = 0;
  161. /* Set dccon to PLLX_MISC if freq > 600MHz */
  162. if (divn > 600)
  163. reg |= (1 << PLL_DCCON_SHIFT);
  164. writel(reg, &pll->pll_misc);
  165. /* Disable BYPASS */
  166. reg = readl(&pll->pll_base);
  167. reg &= ~PLL_BYPASS_MASK;
  168. writel(reg, &pll->pll_base);
  169. debug("pllx_set_rate: base = 0x%08X\n", reg);
  170. /* Set lock_enable to PLLX_MISC */
  171. reg = readl(&pll->pll_misc);
  172. reg |= PLL_LOCK_ENABLE_MASK;
  173. writel(reg, &pll->pll_misc);
  174. debug("pllx_set_rate: misc = 0x%08X\n", reg);
  175. /* Enable PLLX last, once it's all configured */
  176. reg = readl(&pll->pll_base);
  177. reg |= PLL_ENABLE_MASK;
  178. writel(reg, &pll->pll_base);
  179. debug("pllx_set_rate: base final = 0x%08X\n", reg);
  180. return 0;
  181. }
  182. void init_pllx(void)
  183. {
  184. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  185. struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
  186. int soc_type, sku_info, chip_sku;
  187. enum clock_osc_freq osc;
  188. struct clk_pll_table *sel;
  189. debug("init_pllx entry\n");
  190. /* get SOC (chip) type */
  191. soc_type = tegra_get_chip();
  192. debug(" init_pllx: SoC = 0x%02X\n", soc_type);
  193. /* get SKU info */
  194. sku_info = tegra_get_sku_info();
  195. debug(" init_pllx: SKU info byte = 0x%02X\n", sku_info);
  196. /* get chip SKU, combo of the above info */
  197. chip_sku = tegra_get_chip_sku();
  198. debug(" init_pllx: Chip SKU = %d\n", chip_sku);
  199. /* get osc freq */
  200. osc = clock_get_osc_freq();
  201. debug(" init_pllx: osc = %d\n", osc);
  202. /* set pllx */
  203. sel = &tegra_pll_x_table[chip_sku][osc];
  204. pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
  205. }
  206. void enable_cpu_clock(int enable)
  207. {
  208. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  209. u32 clk;
  210. /*
  211. * NOTE:
  212. * Regardless of whether the request is to enable or disable the CPU
  213. * clock, every processor in the CPU complex except the master (CPU 0)
  214. * will have it's clock stopped because the AVP only talks to the
  215. * master.
  216. */
  217. if (enable) {
  218. /* Initialize PLLX */
  219. init_pllx();
  220. /* Wait until all clocks are stable */
  221. udelay(PLL_STABILIZATION_DELAY);
  222. writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
  223. writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
  224. }
  225. /*
  226. * Read the register containing the individual CPU clock enables and
  227. * always stop the clocks to CPUs > 0.
  228. */
  229. clk = readl(&clkrst->crc_clk_cpu_cmplx);
  230. clk |= 1 << CPU1_CLK_STP_SHIFT;
  231. if (get_num_cpus() == 4)
  232. clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
  233. /* Stop/Unstop the CPU clock */
  234. clk &= ~CPU0_CLK_STP_MASK;
  235. clk |= !enable << CPU0_CLK_STP_SHIFT;
  236. writel(clk, &clkrst->crc_clk_cpu_cmplx);
  237. clock_enable(PERIPH_ID_CPU);
  238. }
  239. static int is_cpu_powered(void)
  240. {
  241. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  242. return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
  243. }
  244. static void remove_cpu_io_clamps(void)
  245. {
  246. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  247. u32 reg;
  248. /* Remove the clamps on the CPU I/O signals */
  249. reg = readl(&pmc->pmc_remove_clamping);
  250. reg |= CPU_CLMP;
  251. writel(reg, &pmc->pmc_remove_clamping);
  252. /* Give I/O signals time to stabilize */
  253. udelay(IO_STABILIZATION_DELAY);
  254. }
  255. void powerup_cpu(void)
  256. {
  257. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  258. u32 reg;
  259. int timeout = IO_STABILIZATION_DELAY;
  260. if (!is_cpu_powered()) {
  261. /* Toggle the CPU power state (OFF -> ON) */
  262. reg = readl(&pmc->pmc_pwrgate_toggle);
  263. reg &= PARTID_CP;
  264. reg |= START_CP;
  265. writel(reg, &pmc->pmc_pwrgate_toggle);
  266. /* Wait for the power to come up */
  267. while (!is_cpu_powered()) {
  268. if (timeout-- == 0)
  269. printf("CPU failed to power up!\n");
  270. else
  271. udelay(10);
  272. }
  273. /*
  274. * Remove the I/O clamps from CPU power partition.
  275. * Recommended only on a Warm boot, if the CPU partition gets
  276. * power gated. Shouldn't cause any harm when called after a
  277. * cold boot according to HW, probably just redundant.
  278. */
  279. remove_cpu_io_clamps();
  280. }
  281. }
  282. void reset_A9_cpu(int reset)
  283. {
  284. /*
  285. * NOTE: Regardless of whether the request is to hold the CPU in reset
  286. * or take it out of reset, every processor in the CPU complex
  287. * except the master (CPU 0) will be held in reset because the
  288. * AVP only talks to the master. The AVP does not know that there
  289. * are multiple processors in the CPU complex.
  290. */
  291. int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
  292. int num_cpus = get_num_cpus();
  293. int cpu;
  294. debug("reset_a9_cpu entry\n");
  295. /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
  296. for (cpu = 1; cpu < num_cpus; cpu++)
  297. reset_cmplx_set_enable(cpu, mask, 1);
  298. reset_cmplx_set_enable(0, mask, reset);
  299. /* Enable/Disable master CPU reset */
  300. reset_set_enable(PERIPH_ID_CPU, reset);
  301. }
  302. void clock_enable_coresight(int enable)
  303. {
  304. u32 rst, src = 2;
  305. debug("clock_enable_coresight entry\n");
  306. clock_set_enable(PERIPH_ID_CORESIGHT, enable);
  307. reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
  308. if (enable) {
  309. /*
  310. * Put CoreSight on PLLP_OUT0 and divide it down as per
  311. * PLLP base frequency based on SoC type (T20/T30+).
  312. * Clock divider request would setup CSITE clock as 144MHz
  313. * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
  314. */
  315. src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ);
  316. clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
  317. /* Unlock the CPU CoreSight interfaces */
  318. rst = CORESIGHT_UNLOCK;
  319. writel(rst, CSITE_CPU_DBG0_LAR);
  320. writel(rst, CSITE_CPU_DBG1_LAR);
  321. if (get_num_cpus() == 4) {
  322. writel(rst, CSITE_CPU_DBG2_LAR);
  323. writel(rst, CSITE_CPU_DBG3_LAR);
  324. }
  325. }
  326. }
  327. void halt_avp(void)
  328. {
  329. for (;;) {
  330. writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
  331. | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
  332. FLOW_CTLR_HALT_COP_EVENTS);
  333. }
  334. }