2 * Copyright (c) 2010-2012, 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] = {
54 {{ 1000, 13, 0, 12}, /* OSC 13M */
55 { 625, 12, 0, 8}, /* OSC 19.2M */
56 { 1000, 12, 0, 12}, /* OSC 12M */
57 { 1000, 26, 0, 12}, /* OSC 26M */
82 void adjust_pllp_out_freqs(void)
84 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
85 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_PERIPH];
88 /* Set T30 PLLP_OUT1, 2, 3 & 4 freqs to 9.6, 48, 102 & 204MHz */
89 reg = readl(&pll->pll_out[0]); /* OUTA, contains OUT2 / OUT1 */
90 reg |= (IN_408_OUT_48_DIVISOR << PLLP_OUT2_RATIO) | PLLP_OUT2_OVR
91 | (IN_408_OUT_9_6_DIVISOR << PLLP_OUT1_RATIO) | PLLP_OUT1_OVR;
92 writel(reg, &pll->pll_out[0]);
94 reg = readl(&pll->pll_out[1]); /* OUTB, contains OUT4 / OUT3 */
95 reg |= (IN_408_OUT_204_DIVISOR << PLLP_OUT4_RATIO) | PLLP_OUT4_OVR
96 | (IN_408_OUT_102_DIVISOR << PLLP_OUT3_RATIO) | PLLP_OUT3_OVR;
97 writel(reg, &pll->pll_out[1]);
100 int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm,
105 /* If PLLX is already enabled, just return */
106 if (readl(&pll->pll_base) & PLL_ENABLE_MASK) {
107 debug("pllx_set_rate: PLLX already enabled, returning\n");
111 debug(" pllx_set_rate entry\n");
113 /* Set BYPASS, m, n and p to PLLX_BASE */
114 reg = PLL_BYPASS_MASK | (divm << PLL_DIVM_SHIFT);
115 reg |= ((divn << PLL_DIVN_SHIFT) | (divp << PLL_DIVP_SHIFT));
116 writel(reg, &pll->pll_base);
118 /* Set cpcon to PLLX_MISC */
119 reg = (cpcon << PLL_CPCON_SHIFT);
121 /* Set dccon to PLLX_MISC if freq > 600MHz */
123 reg |= (1 << PLL_DCCON_SHIFT);
124 writel(reg, &pll->pll_misc);
127 reg = readl(&pll->pll_base);
128 reg |= PLL_ENABLE_MASK;
131 reg &= ~PLL_BYPASS_MASK;
132 writel(reg, &pll->pll_base);
134 /* Set lock_enable to PLLX_MISC */
135 reg = readl(&pll->pll_misc);
136 reg |= PLL_LOCK_ENABLE_MASK;
137 writel(reg, &pll->pll_misc);
144 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
145 struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX];
147 enum clock_osc_freq osc;
148 struct clk_pll_table *sel;
150 debug("init_pllx entry\n");
153 chip_type = tegra_get_chip_type();
154 debug(" init_pllx: chip_type = %d\n", chip_type);
157 osc = clock_get_osc_freq();
158 debug(" init_pllx: osc = %d\n", osc);
161 sel = &tegra_pll_x_table[chip_type][osc];
162 pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon);
164 /* adjust PLLP_out1-4 on T30/T114 */
165 if (chip_type == TEGRA_SOC_T30 || chip_type == TEGRA_SOC_T114) {
166 debug(" init_pllx: adjusting PLLP out freqs\n");
167 adjust_pllp_out_freqs();
171 void enable_cpu_clock(int enable)
173 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
178 * Regardless of whether the request is to enable or disable the CPU
179 * clock, every processor in the CPU complex except the master (CPU 0)
180 * will have it's clock stopped because the AVP only talks to the
185 /* Initialize PLLX */
188 /* Wait until all clocks are stable */
189 udelay(PLL_STABILIZATION_DELAY);
191 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
192 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
196 * Read the register containing the individual CPU clock enables and
197 * always stop the clocks to CPUs > 0.
199 clk = readl(&clkrst->crc_clk_cpu_cmplx);
200 clk |= 1 << CPU1_CLK_STP_SHIFT;
201 if (get_num_cpus() == 4)
202 clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT);
204 /* Stop/Unstop the CPU clock */
205 clk &= ~CPU0_CLK_STP_MASK;
206 clk |= !enable << CPU0_CLK_STP_SHIFT;
207 writel(clk, &clkrst->crc_clk_cpu_cmplx);
209 clock_enable(PERIPH_ID_CPU);
212 static int is_cpu_powered(void)
214 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
216 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
219 static void remove_cpu_io_clamps(void)
221 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
224 /* Remove the clamps on the CPU I/O signals */
225 reg = readl(&pmc->pmc_remove_clamping);
227 writel(reg, &pmc->pmc_remove_clamping);
229 /* Give I/O signals time to stabilize */
230 udelay(IO_STABILIZATION_DELAY);
233 void powerup_cpu(void)
235 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
237 int timeout = IO_STABILIZATION_DELAY;
239 if (!is_cpu_powered()) {
240 /* Toggle the CPU power state (OFF -> ON) */
241 reg = readl(&pmc->pmc_pwrgate_toggle);
244 writel(reg, &pmc->pmc_pwrgate_toggle);
246 /* Wait for the power to come up */
247 while (!is_cpu_powered()) {
249 printf("CPU failed to power up!\n");
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.
260 remove_cpu_io_clamps();
264 void reset_A9_cpu(int reset)
267 * NOTE: Regardless of whether the request is to hold the CPU in reset
268 * or take it out of reset, every processor in the CPU complex
269 * except the master (CPU 0) will be held in reset because the
270 * AVP only talks to the master. The AVP does not know that there
271 * are multiple processors in the CPU complex.
273 int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug;
274 int num_cpus = get_num_cpus();
277 debug("reset_a9_cpu entry\n");
278 /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */
279 for (cpu = 1; cpu < num_cpus; cpu++)
280 reset_cmplx_set_enable(cpu, mask, 1);
281 reset_cmplx_set_enable(0, mask, reset);
283 /* Enable/Disable master CPU reset */
284 reset_set_enable(PERIPH_ID_CPU, reset);
287 void clock_enable_coresight(int enable)
292 debug("clock_enable_coresight entry\n");
293 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
294 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
298 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
299 * 1.5, giving an effective frequency of 144MHz.
300 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
301 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
303 * Clock divider request for 204MHz would setup CSITE clock as
304 * 144MHz for PLLP base 216MHz and 204MHz for PLLP base 408MHz
306 chip = tegra_get_chip_type();
307 if (chip == TEGRA_SOC_T30 || chip == TEGRA_SOC_T114)
308 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 204000);
309 else if (chip == TEGRA_SOC_T20 || chip == TEGRA_SOC_T25)
310 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
312 printf("%s: Unknown chip type %X!\n", __func__, chip);
313 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
315 /* Unlock the CPU CoreSight interfaces */
316 rst = CORESIGHT_UNLOCK;
317 writel(rst, CSITE_CPU_DBG0_LAR);
318 writel(rst, CSITE_CPU_DBG1_LAR);
319 if (get_num_cpus() == 4) {
320 writel(rst, CSITE_CPU_DBG2_LAR);
321 writel(rst, CSITE_CPU_DBG3_LAR);
329 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
330 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
331 FLOW_CTLR_HALT_COP_EVENTS);