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,
25 #include <asm/arch/tegra2.h>
26 #include <asm/arch/ap20.h>
27 #include <asm/arch/clk_rst.h>
28 #include <asm/arch/clock.h>
29 #include <asm/arch/fuse.h>
30 #include <asm/arch/gp_padctrl.h>
31 #include <asm/arch/pmc.h>
32 #include <asm/arch/pinmux.h>
33 #include <asm/arch/scu.h>
36 int tegra_get_chip_type(void)
38 struct apb_misc_gp_ctlr *gp;
39 struct fuse_regs *fuse = (struct fuse_regs *)TEGRA2_FUSE_BASE;
40 uint tegra_sku_id, rev;
43 * This is undocumented, Chip ID is bits 15:8 of the register
44 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
47 gp = (struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
48 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
50 tegra_sku_id = readl(&fuse->sku_info) & 0xff;
54 switch (tegra_sku_id) {
67 return TEGRA_SOC_UNKNOWN;
70 /* Returns 1 if the current CPU executing is a Cortex-A9, else 0 */
71 static int ap20_cpu_is_cortexa9(void)
73 u32 id = readb(NV_PA_PG_UP_BASE + PG_UP_TAG_0);
74 return id == (PG_UP_TAG_0_PID_CPU & 0xff);
79 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
80 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_XCPU];
83 /* If PLLX is already enabled, just return */
84 if (readl(&pll->pll_base) & PLL_ENABLE_MASK)
88 writel(1 << PLL_CPCON_SHIFT, &pll->pll_misc);
90 /* Use 12MHz clock here */
91 reg = PLL_BYPASS_MASK | (12 << PLL_DIVM_SHIFT);
92 reg |= 1000 << PLL_DIVN_SHIFT;
93 writel(reg, &pll->pll_base);
95 reg |= PLL_ENABLE_MASK;
96 writel(reg, &pll->pll_base);
98 reg &= ~PLL_BYPASS_MASK;
99 writel(reg, &pll->pll_base);
102 static void enable_cpu_clock(int enable)
104 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
109 * Regardless of whether the request is to enable or disable the CPU
110 * clock, every processor in the CPU complex except the master (CPU 0)
111 * will have it's clock stopped because the AVP only talks to the
112 * master. The AVP does not know (nor does it need to know) that there
113 * are multiple processors in the CPU complex.
117 /* Initialize PLLX */
120 /* Wait until all clocks are stable */
121 udelay(PLL_STABILIZATION_DELAY);
123 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
124 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
128 * Read the register containing the individual CPU clock enables and
129 * always stop the clock to CPU 1.
131 clk = readl(&clkrst->crc_clk_cpu_cmplx);
132 clk |= 1 << CPU1_CLK_STP_SHIFT;
134 /* Stop/Unstop the CPU clock */
135 clk &= ~CPU0_CLK_STP_MASK;
136 clk |= !enable << CPU0_CLK_STP_SHIFT;
137 writel(clk, &clkrst->crc_clk_cpu_cmplx);
139 clock_enable(PERIPH_ID_CPU);
142 static int is_cpu_powered(void)
144 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
146 return (readl(&pmc->pmc_pwrgate_status) & CPU_PWRED) ? 1 : 0;
149 static void remove_cpu_io_clamps(void)
151 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
154 /* Remove the clamps on the CPU I/O signals */
155 reg = readl(&pmc->pmc_remove_clamping);
157 writel(reg, &pmc->pmc_remove_clamping);
159 /* Give I/O signals time to stabilize */
160 udelay(IO_STABILIZATION_DELAY);
163 static void powerup_cpu(void)
165 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
167 int timeout = IO_STABILIZATION_DELAY;
169 if (!is_cpu_powered()) {
170 /* Toggle the CPU power state (OFF -> ON) */
171 reg = readl(&pmc->pmc_pwrgate_toggle);
174 writel(reg, &pmc->pmc_pwrgate_toggle);
176 /* Wait for the power to come up */
177 while (!is_cpu_powered()) {
179 printf("CPU failed to power up!\n");
185 * Remove the I/O clamps from CPU power partition.
186 * Recommended only on a Warm boot, if the CPU partition gets
187 * power gated. Shouldn't cause any harm when called after a
188 * cold boot according to HW, probably just redundant.
190 remove_cpu_io_clamps();
194 static void enable_cpu_power_rail(void)
196 struct pmc_ctlr *pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
199 reg = readl(&pmc->pmc_cntrl);
201 writel(reg, &pmc->pmc_cntrl);
204 * The TI PMU65861C needs a 3.75ms delay between enabling
205 * the power rail and enabling the CPU clock. This delay
206 * between SM1EN and SM1 is for switching time + the ramp
207 * up of the voltage to the CPU (VDD_CPU from PMU).
212 static void reset_A9_cpu(int reset)
215 * NOTE: Regardless of whether the request is to hold the CPU in reset
216 * or take it out of reset, every processor in the CPU complex
217 * except the master (CPU 0) will be held in reset because the
218 * AVP only talks to the master. The AVP does not know that there
219 * are multiple processors in the CPU complex.
222 /* Hold CPU 1 in reset, and CPU 0 if asked */
223 reset_cmplx_set_enable(1, crc_rst_cpu | crc_rst_de | crc_rst_debug, 1);
224 reset_cmplx_set_enable(0, crc_rst_cpu | crc_rst_de | crc_rst_debug,
227 /* Enable/Disable master CPU reset */
228 reset_set_enable(PERIPH_ID_CPU, reset);
231 static void clock_enable_coresight(int enable)
235 clock_set_enable(PERIPH_ID_CORESIGHT, enable);
236 reset_set_enable(PERIPH_ID_CORESIGHT, !enable);
240 * Put CoreSight on PLLP_OUT0 (216 MHz) and divide it down by
241 * 1.5, giving an effective frequency of 144MHz.
242 * Set PLLP_OUT0 [bits31:30 = 00], and use a 7.1 divisor
243 * (bits 7:0), so 00000001b == 1.5 (n+1 + .5)
245 src = CLK_DIVIDER(NVBL_PLLP_KHZ, 144000);
246 clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src);
248 /* Unlock the CPU CoreSight interfaces */
250 writel(rst, CSITE_CPU_DBG0_LAR);
251 writel(rst, CSITE_CPU_DBG1_LAR);
255 void start_cpu(u32 reset_vector)
258 enable_cpu_power_rail();
260 /* Hold the CPUs in reset */
263 /* Disable the CPU clock */
266 /* Enable CoreSight */
267 clock_enable_coresight(1);
270 * Set the entry point for CPU execution from reset,
271 * if it's a non-zero value.
274 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
276 /* Enable the CPU clock */
279 /* If the CPU doesn't already have power, power it up */
282 /* Take the CPU out of reset */
290 writel((HALT_COP_EVENT_JTAG | HALT_COP_EVENT_IRQ_1 \
291 | HALT_COP_EVENT_FIQ_1 | (FLOW_MODE_STOP<<29)),
292 FLOW_CTLR_HALT_COP_EVENTS);
296 void enable_scu(void)
298 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
301 /* If SCU already setup/enabled, return */
302 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
305 /* Invalidate all ways for all processors */
306 writel(0xFFFF, &scu->scu_inv_all);
308 /* Enable SCU - bit 0 */
309 reg = readl(&scu->scu_ctrl);
310 reg |= SCU_CTRL_ENABLE;
311 writel(reg, &scu->scu_ctrl);
314 void init_pmc_scratch(void)
316 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
319 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
320 for (i = 0; i < 23; i++)
321 writel(0, &pmc->pmc_scratch1+i);
323 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
324 writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
327 void tegra2_start(void)
329 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
331 /* If we are the AVP, start up the first Cortex-A9 */
332 if (!ap20_cpu_is_cortexa9()) {
334 writel(0xC0, &pmt->pmt_cfg_ctl);
337 * If we are ARM7 - give it a different stack. We are about to
338 * start up the A9 which will want to use this one.
340 asm volatile("mov sp, %0\n"
341 : : "r"(AVP_EARLY_BOOT_STACK_LIMIT));
343 start_cpu((u32)_start);
348 /* Init PMC scratch memory */
353 /* enable SMP mode and FW for CPU0, by writing to Auxiliary Ctl reg */
355 "mrc p15, 0, r0, c1, c0, 1\n"
356 "orr r0, r0, #0x41\n"
357 "mcr p15, 0, r0, c1, c0, 1\n");
359 /* FIXME: should have ap20's L2 disabled too? */