cpu.c 8.7 KB

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