blob: 160dac8e1c2831108edca5121490470a7d14fb96 [file] [log] [blame]
Tom Warren41b68382011-01-27 10:58:05 +00001/*
2 * (C) Copyright 2010,2011
3 * NVIDIA Corporation <www.nvidia.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <ns16550.h>
26#include <asm/io.h>
27#include <asm/arch/tegra2.h>
28#include <asm/arch/sys_proto.h>
29
30#include <asm/arch/clk_rst.h>
Simon Glass16134fd2011-08-30 06:23:13 +000031#include <asm/arch/clock.h>
Tom Warren41b68382011-01-27 10:58:05 +000032#include <asm/arch/pinmux.h>
33#include <asm/arch/uart.h>
Tom Warren112a1882011-04-14 12:18:06 +000034#include "board.h"
Tom Warren41b68382011-01-27 10:58:05 +000035
Tom Warren85f0ee42011-05-31 10:30:37 +000036#ifdef CONFIG_TEGRA2_MMC
37#include <mmc.h>
38#endif
39
Tom Warren41b68382011-01-27 10:58:05 +000040DECLARE_GLOBAL_DATA_PTR;
41
42const struct tegra2_sysinfo sysinfo = {
43 CONFIG_TEGRA2_BOARD_STRING
44};
45
Tom Warren112a1882011-04-14 12:18:06 +000046#ifdef CONFIG_BOARD_EARLY_INIT_F
47int board_early_init_f(void)
48{
Tom Warrene1495582011-04-14 12:09:41 +000049 /* Initialize periph clocks */
50 clock_init();
51
52 /* Initialize periph pinmuxes */
53 pinmux_init();
54
55 /* Initialize periph GPIOs */
56 gpio_init();
57
58 /* Init UART, scratch regs, and start CPU */
Tom Warren112a1882011-04-14 12:18:06 +000059 tegra2_start();
60 return 0;
61}
62#endif /* EARLY_INIT */
63
Tom Warren41b68382011-01-27 10:58:05 +000064/*
65 * Routine: timer_init
66 * Description: init the timestamp and lastinc value
67 */
68int timer_init(void)
69{
Tom Warren41b68382011-01-27 10:58:05 +000070 return 0;
71}
72
73/*
74 * Routine: clock_init_uart
75 * Description: init the PLL and clock for the UART(s)
76 */
77static void clock_init_uart(void)
78{
79 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Simon Glass16134fd2011-08-30 06:23:13 +000080 struct clk_pll *pll = &clkrst->crc_pll[CLOCK_PLL_ID_PERIPH];
Tom Warren41b68382011-01-27 10:58:05 +000081 u32 reg;
82
Simon Glass16134fd2011-08-30 06:23:13 +000083 reg = readl(&pll->pll_base);
Simon Glasse2deddd2011-08-30 06:23:15 +000084 if (!(reg & PLL_BASE_OVRRIDE_MASK)) {
Tom Warren41b68382011-01-27 10:58:05 +000085 /* Override pllp setup for 216MHz operation. */
Simon Glasse2deddd2011-08-30 06:23:15 +000086 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;
Simon Glass16134fd2011-08-30 06:23:13 +000089 writel(reg, &pll->pll_base);
Tom Warren41b68382011-01-27 10:58:05 +000090
Simon Glasse2deddd2011-08-30 06:23:15 +000091 reg |= PLL_ENABLE_MASK;
Simon Glass16134fd2011-08-30 06:23:13 +000092 writel(reg, &pll->pll_base);
Tom Warren41b68382011-01-27 10:58:05 +000093
Simon Glasse2deddd2011-08-30 06:23:15 +000094 reg &= ~PLL_BYPASS_MASK;
Simon Glass16134fd2011-08-30 06:23:13 +000095 writel(reg, &pll->pll_base);
Tom Warren41b68382011-01-27 10:58:05 +000096 }
97
Tom Warren41b68382011-01-27 10:58:05 +000098#if defined(CONFIG_TEGRA2_ENABLE_UARTA)
Simon Glass16134fd2011-08-30 06:23:13 +000099 /* Assert UART reset and enable clock */
100 reset_set_enable(PERIPH_ID_UART1, 1);
101 clock_enable(PERIPH_ID_UART1);
Tom Warren41b68382011-01-27 10:58:05 +0000102
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);
107
108 /* wait for 2us */
109 udelay(2);
110
111 /* De-assert reset to UART */
Simon Glass16134fd2011-08-30 06:23:13 +0000112 reset_set_enable(PERIPH_ID_UART1, 0);
Tom Warren41b68382011-01-27 10:58:05 +0000113#endif /* CONFIG_TEGRA2_ENABLE_UARTA */
114#if defined(CONFIG_TEGRA2_ENABLE_UARTD)
Simon Glass16134fd2011-08-30 06:23:13 +0000115 /* Assert UART reset and enable clock */
116 reset_set_enable(PERIPH_ID_UART4, 1);
117 clock_enable(PERIPH_ID_UART4);
Tom Warren41b68382011-01-27 10:58:05 +0000118
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);
123
124 /* wait for 2us */
125 udelay(2);
126
127 /* De-assert reset to UART */
Simon Glass16134fd2011-08-30 06:23:13 +0000128 reset_set_enable(PERIPH_ID_UART4, 0);
Tom Warren41b68382011-01-27 10:58:05 +0000129#endif /* CONFIG_TEGRA2_ENABLE_UARTD */
130}
131
132/*
133 * Routine: pin_mux_uart
134 * Description: setup the pin muxes/tristate values for the UART(s)
135 */
136static void pin_mux_uart(void)
137{
138 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
139 u32 reg;
140
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);
145
Simon Glassfa516f62011-08-30 06:23:14 +0000146 pinmux_tristate_disable(PIN_IRRX);
147 pinmux_tristate_disable(PIN_IRTX);
Tom Warren41b68382011-01-27 10:58:05 +0000148#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);
153
Simon Glassfa516f62011-08-30 06:23:14 +0000154 pinmux_tristate_disable(PIN_GMC);
Tom Warren41b68382011-01-27 10:58:05 +0000155#endif /* CONFIG_TEGRA2_ENABLE_UARTD */
156}
157
158/*
Tom Warren85f0ee42011-05-31 10:30:37 +0000159 * Routine: clock_init_mmc
160 * Description: init the PLL and clocks for the SDMMC controllers
161 */
162static void clock_init_mmc(void)
163{
164 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
165 u32 reg;
166
167 /* Do the SDMMC resets/clock enables */
Simon Glass16134fd2011-08-30 06:23:13 +0000168 reset_set_enable(PERIPH_ID_SDMMC4, 1);
169 clock_enable(PERIPH_ID_SDMMC4);
Tom Warren85f0ee42011-05-31 10:30:37 +0000170
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);
176
177 /*
178 * As per the Tegra2 TRM, section 5.3.4:
179 * 'Wait 2 us for the clock to flush through the pipe/logic'
180 */
181 udelay(2);
182
Simon Glass16134fd2011-08-30 06:23:13 +0000183 reset_set_enable(PERIPH_ID_SDMMC4, 1);
Tom Warren85f0ee42011-05-31 10:30:37 +0000184
Simon Glass16134fd2011-08-30 06:23:13 +0000185 reset_set_enable(PERIPH_ID_SDMMC3, 1);
186 clock_enable(PERIPH_ID_SDMMC3);
Tom Warren85f0ee42011-05-31 10:30:37 +0000187
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);
193
194 /* wait for 2us */
195 udelay(2);
196
Simon Glass16134fd2011-08-30 06:23:13 +0000197 reset_set_enable(PERIPH_ID_SDMMC3, 0);
Tom Warren85f0ee42011-05-31 10:30:37 +0000198}
199
200/*
201 * Routine: pin_mux_mmc
202 * Description: setup the pin muxes/tristate values for the SDMMC(s)
203 */
204static void pin_mux_mmc(void)
205{
206 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
207 u32 reg;
208
209 /* SDMMC4 */
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);
220
Simon Glassfa516f62011-08-30 06:23:14 +0000221 pinmux_tristate_disable(PIN_ATB);
222 pinmux_tristate_disable(PIN_GMA);
223 pinmux_tristate_disable(PIN_GME);
Tom Warren85f0ee42011-05-31 10:30:37 +0000224
225 /* SDMMC3 */
226 /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
227 reg = readl(&pmt->pmt_ctl_d);
228 reg &= 0xFFFF03FF;
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);
233
Simon Glassfa516f62011-08-30 06:23:14 +0000234 pinmux_tristate_disable(PIN_SDC);
235 pinmux_tristate_disable(PIN_SDD);
236 pinmux_tristate_disable(PIN_SDB);
Tom Warren85f0ee42011-05-31 10:30:37 +0000237}
238
239/*
Tom Warren41b68382011-01-27 10:58:05 +0000240 * Routine: clock_init
241 * Description: Do individual peripheral clock reset/enables
242 */
243void clock_init(void)
244{
245 clock_init_uart();
246}
247
248/*
249 * Routine: pinmux_init
250 * Description: Do individual peripheral pinmux configs
251 */
252void pinmux_init(void)
253{
254 pin_mux_uart();
255}
256
257/*
Tom Warrene1495582011-04-14 12:09:41 +0000258 * Routine: gpio_init
259 * Description: Do individual peripheral GPIO configs
260 */
261void gpio_init(void)
262{
263 gpio_config_uart();
264}
265
266/*
Tom Warren41b68382011-01-27 10:58:05 +0000267 * Routine: board_init
268 * Description: Early hardware init.
269 */
270int board_init(void)
271{
272 /* boot param addr */
273 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
Tom Warren41b68382011-01-27 10:58:05 +0000274
Tom Warren41b68382011-01-27 10:58:05 +0000275 return 0;
276}
Tom Warren85f0ee42011-05-31 10:30:37 +0000277
278#ifdef CONFIG_TEGRA2_MMC
279/* this is a weak define that we are overriding */
280int board_mmc_init(bd_t *bd)
281{
282 debug("board_mmc_init called\n");
283 /* Enable clocks, muxes, etc. for SDMMC controllers */
284 clock_init_mmc();
285 pin_mux_mmc();
286
287 debug("board_mmc_init: init eMMC\n");
288 /* init dev 0, eMMC chip, with 4-bit bus */
289 tegra2_mmc_init(0, 4);
290
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);
294
295 return 0;
296}
297
298/* this is a weak define that we are overriding */
299int board_mmc_getcd(u8 *cd, struct mmc *mmc)
300{
301 debug("board_mmc_getcd called\n");
302 /*
303 * Hard-code CD presence for now. Need to add GPIO inputs
304 * for Seaboard & Harmony (& Kaen/Aebl/Wario?)
305 */
306 *cd = 1;
307 return 0;
308}
309#endif