2 * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
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.
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
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/>.
19 #include <asm/arch/clock.h>
20 #include <asm/arch/gp_padctrl.h>
21 #include <asm/arch/pinmux.h>
22 #include <asm/arch/tegra.h>
23 #include <asm/arch-tegra/clk_rst.h>
24 #include <asm/arch-tegra/pmc.h>
25 #include <asm/arch-tegra/scu.h>
28 int get_num_cpus(void)
30 struct apb_misc_gp_ctlr *gp;
33 gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
34 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
49 * Timing tables for each SOC for all four oscillator options.
51 struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = {
55 * Register Field Bits Width
56 * ------------------------------
58 * PLLX_BASE n 17: 8 10
60 * PLLX_MISC cpcon 11: 8 4
63 { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
64 { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
65 { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
66 { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
71 * Register Field Bits Width
72 * ------------------------------
74 * PLLX_BASE n 17: 8 10
76 * PLLX_MISC cpcon 11: 8 4
79 { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */
80 { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */
81 { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */
82 { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */
87 * Register Field Bits Width
88 * ------------------------------
90 * PLLX_BASE n 17: 8 10
92 * PLLX_MISC cpcon 11: 8 4
95 { .n = 862, .m = 8, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */
96 { .n = 583, .m = 8, .p = 0, .cpcon = 4 }, /* OSC: 19.2 MHz */
97 { .n = 700, .m = 6, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */
98 { .n = 700, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */
103 * Register Field Bits Width
104 * ------------------------------
105 * PLLX_BASE p 23:20 4
106 * PLLX_BASE n 15: 8 8
110 { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */
111 { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */
112 { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */
113 { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */
117 int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
120 int chip = tegra_get_chip();
123 /* If PLLX is already enabled, just return */
124 if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
125 debug("pllx_set_rate: PLLX already enabled, returning\n");
129 debug(" pllx_set_rate entry\n");
131 /* Set BYPASS, m, n and p to PLLX_BASE */
132 reg = PLL_BYPASS_MASK | (divm << PLL_DIVM_SHIFT);
133 reg |= ((divn << PLL_DIVN_SHIFT) | (divp << PLL_DIVP_SHIFT));
134 writel(reg, &pll->pll_base);
136 /* Set cpcon to PLLX_MISC */
137 if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30)
138 reg = (cpcon << PLL_CPCON_SHIFT);
142 /* Set dccon to PLLX_MISC if freq > 600MHz */
144 reg |= (1 << PLL_DCCON_SHIFT);
145 writel(reg, &pll->pll_misc);
148 reg = readl(&pll->pll_base);
149 reg |= PLL_ENABLE_MASK;
152 reg &= ~PLL_BYPASS_MASK;
153 writel(reg, &pll->pll_base);
155 /* Set lock_enable to PLLX_MISC */
156 reg = readl(&pll->pll_misc);
157 reg |= PLL_LOCK_ENABLE_MASK;
158 writel(reg, &pll->pll_misc);
165 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
166 struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
167 int soc_type, sku_info, chip_sku;
168 enum clock_osc_freq osc;
169 struct clk_pll_table *sel;
171 debug("init_pllx entry\n");
173 /* get SOC (chip) type */
174 soc_type = tegra_get_chip();
175 debug(" init_pllx: SoC = 0x%02X\n", soc_type);
178 sku_info = tegra_get_sku_info();
179 debug(" init_pllx: SKU info byte = 0x%02X\n", sku_info);
181 /* get chip SKU, combo of the above info */
182 chip_sku = tegra_get_chip_sku();
183 debug(" init_pllx: Chip SKU = %d\n", chip_sku);
186 osc = clock_get_osc_freq();
187 debug(" init_pllx: osc = %d\n", osc);
190 sel = &tegra_pll_x_table[chip_sku][osc];
191 pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
194 void enable_cpu_clock(int enable)
196 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
201 * Regardless of whether the request is to enable or disable the CPU
202 * clock, every processor in the CPU complex except the master (CPU 0)
203 * will have it's clock stopped because the AVP only talks to the
208 /* Initialize PLLX */
211 /* Wait until all clocks are stable */
212 udelay(PLL_STABILIZATION_DELAY);
214 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
215 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
219 * Read the register containing the individual CPU clock enables and
220 * always stop the clocks to CPUs > 0.
222 clk = readl(&clkrst->crc_clk_cpu_cmplx);
223 clk |= 1 << CPU1_CLK_STP_SHIFT;
224 if (get_num_cpus() == 4)
225 clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
227 /* Stop/Unstop the CPU clock */
228 clk &= ~CPU0_CLK_STP_MASK;
229 clk |= !enable << CPU0_CLK_STP_SHIFT;
230 writel(clk, &clkrst->crc_clk_cpu_cmplx);
232 clock_enable(PERIPH_ID_CPU);
235 static int is_cpu_powered(void)
237 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
239 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
242 static void remove_cpu_io_clamps(void)
244 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
247 /* Remove the clamps on the CPU I/O signals */
248 reg = readl(&pmc->pmc_remove_clamping);
250 writel(reg, &pmc->pmc_remove_clamping);
252 /* Give I/O signals time to stabilize */
253 udelay(IO_STABILIZATION_DELAY);
256 void powerup_cpu(void)
258 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
260 int timeout = IO_STABILIZATION_DELAY;
262 if (!is_cpu_powered()) {
263 /* Toggle the CPU power state (OFF -> ON) */
264 reg = readl(&pmc->pmc_pwrgate_toggle);
267 writel(reg, &pmc->pmc_pwrgate_toggle);
269 /* Wait for the power to come up */
270 while (!is_cpu_powered()) {
272 printf("CPU failed to power up!\n");
278 * Remove the I/O clamps from CPU power partition.
279 * Recommended only on a Warm boot, if the CPU partition gets
280 * power gated. Shouldn't cause any harm when called after a
281 * cold boot according to HW, probably just redundant.
283 remove_cpu_io_clamps();
287 void reset_A9_cpu(int reset)
290 * NOTE: Regardless of whether the request is to hold the CPU in reset
291 * or take it out of reset, every processor in the CPU complex
292 * except the master (CPU 0) will be held in reset because the
293 * AVP only talks to the master. The AVP does not know that there
294 * are multiple processors in the CPU complex.
296 int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
297 int num_cpus = get_num_cpus();
300 debug("reset_a9_cpu entry\n");
301 /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
302 for (cpu = 1; cpu < num_cpus; cpu++)
303 reset_cmplx_set_enable(cpu, mask, 1);
304 reset_cmplx_set_enable(0, mask, reset);
306 /* Enable/Disable master CPU reset */
307 reset_set_enable(PERIPH_ID_CPU, reset);
310 void clock_enable_coresight(int enable)
315 debug("clock_enable_coresight entry\n");
316 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
317 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
321 * Put CoreSight on PLLP_OUT0 and divide it down as per
322 * PLLP base frequency based on SoC type (T20/T30/T114).
323 * Clock divider request would setup CSITE clock as 144MHz
324 * for PLLP base 216MHz and 204MHz for PLLP base 408MHz
327 soc_type = tegra_get_chip();
328 if (soc_type == CHIPID_TEGRA30 || soc_type == CHIPID_TEGRA114)
329 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 204000);
330 else if (soc_type == CHIPID_TEGRA20)
331 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
333 printf("%s: Unknown SoC type %X!\n",
336 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
338 /* Unlock the CPU CoreSight interfaces */
339 rst = CORESIGHT_UNLOCK;
340 writel(rst, CSITE_CPU_DBG0_LAR);
341 writel(rst, CSITE_CPU_DBG1_LAR);
342 if (get_num_cpus() == 4) {
343 writel(rst, CSITE_CPU_DBG2_LAR);
344 writel(rst, CSITE_CPU_DBG3_LAR);
352 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
353 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
354 FLOW_CTLR_HALT_COP_EVENTS);