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>
35 static void enable_cpu_clock(int enable)
37 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
42 * Regardless of whether the request is to enable or disable the CPU
43 * clock, every processor in the CPU complex except the master (CPU 0)
44 * will have it's clock stopped because the AVP only talks to the
45 * master. The AVP does not know (nor does it need to know) that there
46 * are multiple processors in the CPU complex.
50 /* Wait until all clocks are stable */
51 udelay(PLL_STABILIZATION_DELAY);
53 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
54 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
57 /* Fetch the register containing the main CPU complex clock enable */
58 reg = readl(&clkrst->crc_clk_out_enb_l);
62 * Read the register containing the individual CPU clock enables and
63 * always stop the clock to CPU 1.
65 clk = readl(&clkrst->crc_clk_cpu_cmplx);
69 /* Unstop the CPU clock */
72 /* Stop the CPU clock */
76 writel(clk, &clkrst->crc_clk_cpu_cmplx);
77 writel(reg, &clkrst->crc_clk_out_enb_l);
80 static int is_cpu_powered(void)
82 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
84 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
87 static void remove_cpu_io_clamps(void)
89 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
92 /* Remove the clamps on the CPU I/O signals */
93 reg = readl(&pmc->pmc_remove_clamping);
95 writel(reg, &pmc->pmc_remove_clamping);
97 /* Give I/O signals time to stabilize */
98 udelay(IO_STABILIZATION_DELAY);
101 static void powerup_cpu(void)
103 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
105 int timeout = IO_STABILIZATION_DELAY;
107 if (!is_cpu_powered()) {
108 /* Toggle the CPU power state (OFF -> ON) */
109 reg = readl(&pmc->pmc_pwrgate_toggle);
112 writel(reg, &pmc->pmc_pwrgate_toggle);
114 /* Wait for the power to come up */
115 while (!is_cpu_powered()) {
117 printf("CPU failed to power up!\n");
123 * Remove the I/O clamps from CPU power partition.
124 * Recommended only on a Warm boot, if the CPU partition gets
125 * power gated. Shouldn't cause any harm when called after a
126 * cold boot according to HW, probably just redundant.
128 remove_cpu_io_clamps();
132 static void enable_cpu_power_rail(void)
134 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
137 reg = readl(&pmc->pmc_cntrl);
139 writel(reg, &pmc->pmc_cntrl);
142 * The TI PMU65861C needs a 3.75ms delay between enabling
143 * the power rail and enabling the CPU clock. This delay
144 * between SM1EN and SM1 is for switching time + the ramp
145 * up of the voltage to the CPU (VDD_CPU from PMU).
150 static void reset_A9_cpu(int reset)
152 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
156 * NOTE: Regardless of whether the request is to hold the CPU in reset
157 * or take it out of reset, every processor in the CPU complex
158 * except the master (CPU 0) will be held in reset because the
159 * AVP only talks to the master. The AVP does not know that there
160 * are multiple processors in the CPU complex.
163 /* Hold CPU 1 in reset */
164 cpu = SET_DBGRESET1 | SET_DERESET1 | SET_CPURESET1;
165 writel(cpu, &clkrst->crc_cpu_cmplx_set);
167 reg = readl(&clkrst->crc_rst_dev_l);
169 /* Now place CPU0 into reset */
170 cpu |= SET_DBGRESET0 | SET_DERESET0 | SET_CPURESET0;
171 writel(cpu, &clkrst->crc_cpu_cmplx_set);
173 /* Enable master CPU reset */
176 /* Take CPU0 out of reset */
177 cpu = CLR_DBGRESET0 | CLR_DERESET0 | CLR_CPURESET0;
178 writel(cpu, &clkrst->crc_cpu_cmplx_clr);
180 /* Disable master CPU reset */
184 writel(reg, &clkrst->crc_rst_dev_l);
187 static void clock_enable_coresight(int enable)
189 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
192 rst = readl(&clkrst->crc_rst_dev_u);
193 clk = readl(&clkrst->crc_clk_out_enb_u);
196 rst &= ~SWR_CSITE_RST;
197 clk |= CLK_ENB_CSITE;
199 rst |= SWR_CSITE_RST;
200 clk &= ~CLK_ENB_CSITE;
203 writel(clk, &clkrst->crc_clk_out_enb_u);
204 writel(rst, &clkrst->crc_rst_dev_u);
208 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
209 * 1.5, giving an effective frequency of 144MHz.
210 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
211 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
213 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
214 writel(src, &clkrst->crc_clk_src_csite);
216 /* Unlock the CPU CoreSight interfaces */
218 writel(rst, CSITE_CPU_DBG0_LAR);
219 writel(rst, CSITE_CPU_DBG1_LAR);
223 void start_cpu(u32 reset_vector)
226 enable_cpu_power_rail();
228 /* Hold the CPUs in reset */
231 /* Disable the CPU clock */
234 /* Enable CoreSight */
235 clock_enable_coresight(1);
238 * Set the entry point for CPU execution from reset,
239 * if it's a non-zero value.
242 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
244 /* Enable the CPU clock */
247 /* If the CPU doesn't already have power, power it up */
250 /* Take the CPU out of reset */
258 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
259 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
260 FLOW_CTLR_HALT_COP_EVENTS);
264 void enable_scu(void)
266 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
269 /* If SCU already setup/enabled, return */
270 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
273 /* Invalidate all ways for all processors */
274 writel(0xFFFF, &scu->scu_inv_all);
276 /* Enable SCU - bit 0 */
277 reg = readl(&scu->scu_ctrl);
278 reg |= SCU_CTRL_ENABLE;
279 writel(reg, &scu->scu_ctrl);
282 void init_pmc_scratch(void)
284 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
287 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
288 for (i = 0; i < 23; i++)
289 writel(0, &pmc->pmc_scratch1+i);
291 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
292 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
297 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
300 writel(0xC0, &pmt->pmt_cfg_ctl);
304 * Need to set this before cold-booting,
305 * otherwise we'll end up in an infinite loop.
315 /* Init Debug UART Port (115200 8n1) */
318 /* Init PMC scratch memory */
322 #ifdef CONFIG_ENABLE_CORTEXA9
323 /* take the mpcore out of reset */
326 /* configure cache */