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,
27 #include <asm/arch/tegra2.h>
28 #include <asm/arch/sys_proto.h>
30 #include <asm/arch/clk_rst.h>
31 #include <asm/arch/clock.h>
32 #include <asm/arch/pinmux.h>
33 #include <asm/arch/uart.h>
36 #ifdef CONFIG_TEGRA2_MMC
40 DECLARE_GLOBAL_DATA_PTR;
42 const struct tegra2_sysinfo sysinfo = {
43 CONFIG_TEGRA2_BOARD_STRING
46 #ifdef CONFIG_BOARD_EARLY_INIT_F
47 int board_early_init_f(void)
49 /* Initialize periph clocks */
52 /* Initialize periph pinmuxes */
55 /* Initialize periph GPIOs */
58 /* Init UART, scratch regs, and start CPU */
62 #endif /* EARLY_INIT */
66 * Description: init the timestamp and lastinc value
74 * Routine: clock_init_uart
75 * Description: init the PLL and clock for the UART(s)
77 static void clock_init_uart(void)
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_PERIPH];
83 reg = readl(&pll->pll_base);
84 if (!(reg & PLL_BASE_OVRRIDE_MASK)) {
85 /* Override pllp setup for 216MHz operation. */
86 reg = PLL_BYPASS_MASK | PLL_BASE_OVRRIDE_MASK |
87 (1 << PLL_DIVP_SHIFT) | (0xc << PLL_DIVM_SHIFT);
88 reg |= (NVRM_PLLP_FIXED_FREQ_KHZ / 500) << PLL_DIVN_SHIFT;
89 writel(reg, &pll->pll_base);
91 reg |= PLL_ENABLE_MASK;
92 writel(reg, &pll->pll_base);
94 reg &= ~PLL_BYPASS_MASK;
95 writel(reg, &pll->pll_base);
98 #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
99 /* Assert UART reset and enable clock */
100 reset_set_enable(PERIPH_ID_UART1, 1);
101 clock_enable(PERIPH_ID_UART1);
103 /* Enable pllp_out0 to UART */
104 reg = readl(&clkrst->crc_clk_src_uarta);
105 reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */
106 writel(reg, &clkrst->crc_clk_src_uarta);
111 /* De-assert reset to UART */
112 reset_set_enable(PERIPH_ID_UART1, 0);
113 #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
114 #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
115 /* Assert UART reset and enable clock */
116 reset_set_enable(PERIPH_ID_UART4, 1);
117 clock_enable(PERIPH_ID_UART4);
119 /* Enable pllp_out0 to UART */
120 reg = readl(&clkrst->crc_clk_src_uartd);
121 reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */
122 writel(reg, &clkrst->crc_clk_src_uartd);
127 /* De-assert reset to UART */
128 reset_set_enable(PERIPH_ID_UART4, 0);
129 #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
133 * Routine: pin_mux_uart
134 * Description: setup the pin muxes/tristate values for the UART(s)
136 static void pin_mux_uart(void)
138 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
141 #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
142 reg = readl(&pmt->pmt_ctl_c);
143 reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
144 writel(reg, &pmt->pmt_ctl_c);
146 pinmux_tristate_disable(PIN_IRRX);
147 pinmux_tristate_disable(PIN_IRTX);
148 #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
149 #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
150 reg = readl(&pmt->pmt_ctl_b);
151 reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
152 writel(reg, &pmt->pmt_ctl_b);
154 pinmux_tristate_disable(PIN_GMC);
155 #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
159 * Routine: clock_init_mmc
160 * Description: init the PLL and clocks for the SDMMC controllers
162 static void clock_init_mmc(void)
164 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
167 /* Do the SDMMC resets/clock enables */
168 reset_set_enable(PERIPH_ID_SDMMC4, 1);
169 clock_enable(PERIPH_ID_SDMMC4);
171 /* Enable pllp_out0 to SDMMC4 */
172 reg = readl(&clkrst->crc_clk_src_sdmmc4);
173 reg &= 0x3FFFFF00; /* SDMMC4_CLK_SRC = 00, PLLP_OUT0 */
174 reg |= (10 << 1); /* n-1, 11-1 shl 1 */
175 writel(reg, &clkrst->crc_clk_src_sdmmc4);
178 * As per the Tegra2 TRM, section 5.3.4:
179 * 'Wait 2 us for the clock to flush through the pipe/logic'
183 reset_set_enable(PERIPH_ID_SDMMC4, 1);
185 reset_set_enable(PERIPH_ID_SDMMC3, 1);
186 clock_enable(PERIPH_ID_SDMMC3);
188 /* Enable pllp_out0 to SDMMC4, set divisor to 11 for 20MHz */
189 reg = readl(&clkrst->crc_clk_src_sdmmc3);
190 reg &= 0x3FFFFF00; /* SDMMC3_CLK_SRC = 00, PLLP_OUT0 */
191 reg |= (10 << 1); /* n-1, 11-1 shl 1 */
192 writel(reg, &clkrst->crc_clk_src_sdmmc3);
197 reset_set_enable(PERIPH_ID_SDMMC3, 0);
201 * Routine: pin_mux_mmc
202 * Description: setup the pin muxes/tristate values for the SDMMC(s)
204 static void pin_mux_mmc(void)
206 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
210 /* config 2, x8 on 2nd set of pins */
211 reg = readl(&pmt->pmt_ctl_a);
212 reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */
213 writel(reg, &pmt->pmt_ctl_a);
214 reg = readl(&pmt->pmt_ctl_b);
215 reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */
216 writel(reg, &pmt->pmt_ctl_b);
217 reg = readl(&pmt->pmt_ctl_d);
218 reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */
219 writel(reg, &pmt->pmt_ctl_d);
221 pinmux_tristate_disable(PIN_ATB);
222 pinmux_tristate_disable(PIN_GMA);
223 pinmux_tristate_disable(PIN_GME);
226 /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
227 reg = readl(&pmt->pmt_ctl_d);
229 reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */
230 reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */
231 reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */
232 writel(reg, &pmt->pmt_ctl_d);
234 pinmux_tristate_disable(PIN_SDC);
235 pinmux_tristate_disable(PIN_SDD);
236 pinmux_tristate_disable(PIN_SDB);
240 * Routine: clock_init
241 * Description: Do individual peripheral clock reset/enables
243 void clock_init(void)
249 * Routine: pinmux_init
250 * Description: Do individual peripheral pinmux configs
252 void pinmux_init(void)
259 * Description: Do individual peripheral GPIO configs
267 * Routine: board_init
268 * Description: Early hardware init.
272 /* boot param addr */
273 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
278 #ifdef CONFIG_TEGRA2_MMC
279 /* this is a weak define that we are overriding */
280 int board_mmc_init(bd_t *bd)
282 debug("board_mmc_init called\n");
283 /* Enable clocks, muxes, etc. for SDMMC controllers */
287 debug("board_mmc_init: init eMMC\n");
288 /* init dev 0, eMMC chip, with 4-bit bus */
289 tegra2_mmc_init(0, 4);
291 debug("board_mmc_init: init SD slot\n");
292 /* init dev 1, SD slot, with 4-bit bus */
293 tegra2_mmc_init(1, 4);
298 /* this is a weak define that we are overriding */
299 int board_mmc_getcd(u8 *cd, struct mmc *mmc)
301 debug("board_mmc_getcd called\n");
303 * Hard-code CD presence for now. Need to add GPIO inputs
304 * for Seaboard & Harmony (& Kaen/Aebl/Wario?)