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/pmc.h>
29 #include <asm/arch/pinmux.h>
30 #include <asm/arch/scu.h>
37 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
40 /* If PLLX is already enabled, just return */
41 reg = readl(&clkrst->crc_pllx_base);
46 reg = CPCON; /* CPCON[11:8] = 0001 */
47 writel(reg, &clkrst->crc_pllx_misc);
49 /* Use 12MHz clock here */
50 reg = (PLL_BYPASS | PLL_DIVM);
51 reg |= (1000 << 8); /* DIVN = 0x3E8 */
52 writel(reg, &clkrst->crc_pllx_base);
55 writel(reg, &clkrst->crc_pllx_base);
58 writel(reg, &clkrst->crc_pllx_base);
61 static void enable_cpu_clock(int enable)
63 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
68 * Regardless of whether the request is to enable or disable the CPU
69 * clock, every processor in the CPU complex except the master (CPU 0)
70 * will have it's clock stopped because the AVP only talks to the
71 * master. The AVP does not know (nor does it need to know) that there
72 * are multiple processors in the CPU complex.
79 /* Wait until all clocks are stable */
80 udelay(PLL_STABILIZATION_DELAY);
82 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
83 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
86 /* Fetch the register containing the main CPU complex clock enable */
87 reg = readl(&clkrst->crc_clk_out_enb_l);
91 * Read the register containing the individual CPU clock enables and
92 * always stop the clock to CPU 1.
94 clk = readl(&clkrst->crc_clk_cpu_cmplx);
98 /* Unstop the CPU clock */
101 /* Stop the CPU clock */
105 writel(clk, &clkrst->crc_clk_cpu_cmplx);
106 writel(reg, &clkrst->crc_clk_out_enb_l);
109 static int is_cpu_powered(void)
111 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
113 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
116 static void remove_cpu_io_clamps(void)
118 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
121 /* Remove the clamps on the CPU I/O signals */
122 reg = readl(&pmc->pmc_remove_clamping);
124 writel(reg, &pmc->pmc_remove_clamping);
126 /* Give I/O signals time to stabilize */
127 udelay(IO_STABILIZATION_DELAY);
130 static void powerup_cpu(void)
132 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
134 int timeout = IO_STABILIZATION_DELAY;
136 if (!is_cpu_powered()) {
137 /* Toggle the CPU power state (OFF -> ON) */
138 reg = readl(&pmc->pmc_pwrgate_toggle);
141 writel(reg, &pmc->pmc_pwrgate_toggle);
143 /* Wait for the power to come up */
144 while (!is_cpu_powered()) {
146 printf("CPU failed to power up!\n");
152 * Remove the I/O clamps from CPU power partition.
153 * Recommended only on a Warm boot, if the CPU partition gets
154 * power gated. Shouldn't cause any harm when called after a
155 * cold boot according to HW, probably just redundant.
157 remove_cpu_io_clamps();
161 static void enable_cpu_power_rail(void)
163 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
166 reg = readl(&pmc->pmc_cntrl);
168 writel(reg, &pmc->pmc_cntrl);
171 * The TI PMU65861C needs a 3.75ms delay between enabling
172 * the power rail and enabling the CPU clock. This delay
173 * between SM1EN and SM1 is for switching time + the ramp
174 * up of the voltage to the CPU (VDD_CPU from PMU).
179 static void reset_A9_cpu(int reset)
181 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
185 * NOTE: Regardless of whether the request is to hold the CPU in reset
186 * or take it out of reset, every processor in the CPU complex
187 * except the master (CPU 0) will be held in reset because the
188 * AVP only talks to the master. The AVP does not know that there
189 * are multiple processors in the CPU complex.
192 /* Hold CPU 1 in reset */
193 cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
194 writel(cpu, &clkrst->crc_cpu_cmplx_set);
196 reg = readl(&clkrst->crc_rst_dev_l);
198 /* Now place CPU0 into reset */
199 cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
200 writel(cpu, &clkrst->crc_cpu_cmplx_set);
202 /* Enable master CPU reset */
205 /* Take CPU0 out of reset */
206 cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
207 writel(cpu, &clkrst->crc_cpu_cmplx_clr);
209 /* Disable master CPU reset */
213 writel(reg, &clkrst->crc_rst_dev_l);
216 static void clock_enable_coresight(int enable)
218 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
221 rst = readl(&clkrst->crc_rst_dev_u);
222 clk = readl(&clkrst->crc_clk_out_enb_u);
225 rst &= ~SWR_CSITE_RST;
226 clk |= CLK_ENB_CSITE;
228 rst |= SWR_CSITE_RST;
229 clk &= ~CLK_ENB_CSITE;
232 writel(clk, &clkrst->crc_clk_out_enb_u);
233 writel(rst, &clkrst->crc_rst_dev_u);
237 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
238 * 1.5, giving an effective frequency of 144MHz.
239 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
240 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
242 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
243 writel(src, &clkrst->crc_clk_src_csite);
245 /* Unlock the CPU CoreSight interfaces */
247 writel(rst, CSITE_CPU_DBG0_LAR);
248 writel(rst, CSITE_CPU_DBG1_LAR);
252 void start_cpu(u32 reset_vector)
255 enable_cpu_power_rail();
257 /* Hold the CPUs in reset */
260 /* Disable the CPU clock */
263 /* Enable CoreSight */
264 clock_enable_coresight(1);
267 * Set the entry point for CPU execution from reset,
268 * if it's a non-zero value.
271 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
273 /* Enable the CPU clock */
276 /* If the CPU doesn't already have power, power it up */
279 /* Take the CPU out of reset */
287 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
288 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
289 FLOW_CTLR_HALT_COP_EVENTS);
293 void enable_scu(void)
295 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
298 /* If SCU already setup/enabled, return */
299 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
302 /* Invalidate all ways for all processors */
303 writel(0xFFFF, &scu->scu_inv_all);
305 /* Enable SCU - bit 0 */
306 reg = readl(&scu->scu_ctrl);
307 reg |= SCU_CTRL_ENABLE;
308 writel(reg, &scu->scu_ctrl);
311 void init_pmc_scratch(void)
313 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
316 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
317 for (i = 0; i < 23; i++)
318 writel(0, &pmc->pmc_scratch1+i);
320 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
321 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
326 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
329 writel(0xC0, &pmt->pmt_cfg_ctl);
333 * Need to set this before cold-booting,
334 * otherwise we'll end up in an infinite loop.
344 /* Init Debug UART Port (115200 8n1) */
347 /* Init PMC scratch memory */
351 #ifdef CONFIG_ENABLE_CORTEXA9
352 /* take the mpcore out of reset */
355 /* configure cache */