cpu.c 8.5 KB

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