2 * (C) Copyright 2010-2011
3 * NVIDIA Corporation <www.nvidia.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/arch/tegra2.h>
27 #include <asm/arch/clk_rst.h>
28 #include <asm/arch/clock.h>
29 #include <asm/arch/pmc.h>
30 #include <asm/arch/pinmux.h>
31 #include <asm/arch/scu.h>
38 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
39 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_PLL_ID_XCPU];
42 /* If PLLX is already enabled, just return */
43 reg = readl(&pll->pll_base);
48 reg = CPCON; /* CPCON[11:8] = 0001 */
49 writel(reg, &pll->pll_misc);
51 /* Use 12MHz clock here */
52 reg = (PLL_BYPASS | PLL_DIVM_VALUE);
53 reg |= (1000 << 8); /* DIVN = 0x3E8 */
54 writel(reg, &pll->pll_base);
57 writel(reg, &pll->pll_base);
60 writel(reg, &pll->pll_base);
63 static void enable_cpu_clock(int enable)
65 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
70 * Regardless of whether the request is to enable or disable the CPU
71 * clock, every processor in the CPU complex except the master (CPU 0)
72 * will have it's clock stopped because the AVP only talks to the
73 * master. The AVP does not know (nor does it need to know) that there
74 * are multiple processors in the CPU complex.
81 /* Wait until all clocks are stable */
82 udelay(PLL_STABILIZATION_DELAY);
84 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
85 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
89 * Read the register containing the individual CPU clock enables and
90 * always stop the clock to CPU 1.
92 clk = readl(&clkrst->crc_clk_cpu_cmplx);
96 /* Unstop the CPU clock */
99 /* Stop the CPU clock */
103 writel(clk, &clkrst->crc_clk_cpu_cmplx);
105 clock_enable(PERIPH_ID_CPU);
108 static int is_cpu_powered(void)
110 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
112 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
115 static void remove_cpu_io_clamps(void)
117 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
120 /* Remove the clamps on the CPU I/O signals */
121 reg = readl(&pmc->pmc_remove_clamping);
123 writel(reg, &pmc->pmc_remove_clamping);
125 /* Give I/O signals time to stabilize */
126 udelay(IO_STABILIZATION_DELAY);
129 static void powerup_cpu(void)
131 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
133 int timeout = IO_STABILIZATION_DELAY;
135 if (!is_cpu_powered()) {
136 /* Toggle the CPU power state (OFF -> ON) */
137 reg = readl(&pmc->pmc_pwrgate_toggle);
140 writel(reg, &pmc->pmc_pwrgate_toggle);
142 /* Wait for the power to come up */
143 while (!is_cpu_powered()) {
145 printf("CPU failed to power up!\n");
151 * Remove the I/O clamps from CPU power partition.
152 * Recommended only on a Warm boot, if the CPU partition gets
153 * power gated. Shouldn't cause any harm when called after a
154 * cold boot according to HW, probably just redundant.
156 remove_cpu_io_clamps();
160 static void enable_cpu_power_rail(void)
162 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
165 reg = readl(&pmc->pmc_cntrl);
167 writel(reg, &pmc->pmc_cntrl);
170 * The TI PMU65861C needs a 3.75ms delay between enabling
171 * the power rail and enabling the CPU clock. This delay
172 * between SM1EN and SM1 is for switching time + the ramp
173 * up of the voltage to the CPU (VDD_CPU from PMU).
178 static void reset_A9_cpu(int reset)
180 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
184 * NOTE: Regardless of whether the request is to hold the CPU in reset
185 * or take it out of reset, every processor in the CPU complex
186 * except the master (CPU 0) will be held in reset because the
187 * AVP only talks to the master. The AVP does not know that there
188 * are multiple processors in the CPU complex.
191 /* Hold CPU 1 in reset */
192 cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
193 writel(cpu, &clkrst->crc_cpu_cmplx_set);
196 /* Now place CPU0 into reset */
197 cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
198 writel(cpu, &clkrst->crc_cpu_cmplx_set);
200 /* Take CPU0 out of reset */
201 cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
202 writel(cpu, &clkrst->crc_cpu_cmplx_clr);
205 /* Enable/Disable master CPU reset */
206 reset_set_enable(PERIPH_ID_CPU, reset);
209 static void clock_enable_coresight(int enable)
211 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
214 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
215 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
219 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
220 * 1.5, giving an effective frequency of 144MHz.
221 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
222 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
224 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
225 writel(src, &clkrst->crc_clk_src_csite);
227 /* Unlock the CPU CoreSight interfaces */
229 writel(rst, CSITE_CPU_DBG0_LAR);
230 writel(rst, CSITE_CPU_DBG1_LAR);
234 void start_cpu(u32 reset_vector)
237 enable_cpu_power_rail();
239 /* Hold the CPUs in reset */
242 /* Disable the CPU clock */
245 /* Enable CoreSight */
246 clock_enable_coresight(1);
249 * Set the entry point for CPU execution from reset,
250 * if it's a non-zero value.
253 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
255 /* Enable the CPU clock */
258 /* If the CPU doesn't already have power, power it up */
261 /* Take the CPU out of reset */
269 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
270 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
271 FLOW_CTLR_HALT_COP_EVENTS);
275 void enable_scu(void)
277 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
280 /* If SCU already setup/enabled, return */
281 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
284 /* Invalidate all ways for all processors */
285 writel(0xFFFF, &scu->scu_inv_all);
287 /* Enable SCU - bit 0 */
288 reg = readl(&scu->scu_ctrl);
289 reg |= SCU_CTRL_ENABLE;
290 writel(reg, &scu->scu_ctrl);
293 void init_pmc_scratch(void)
295 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
298 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
299 for (i = 0; i < 23; i++)
300 writel(0, &pmc->pmc_scratch1+i);
302 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
303 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
308 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
311 writel(0xC0, &pmt->pmt_cfg_ctl);
315 * Need to set this before cold-booting,
316 * otherwise we'll end up in an infinite loop.
326 /* Init Debug UART Port (115200 8n1) */
329 /* Init PMC scratch memory */
333 #ifdef CONFIG_ENABLE_CORTEXA9
334 /* take the mpcore out of reset */
337 /* configure cache */