blob: 35ff2ef03cbf33930d37faa89c01cb76b8427db8 [file] [log] [blame]
Tom Warren3f82b1d2011-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 Glassb4ba2be2011-08-30 06:23:13 +000031#include <asm/arch/clock.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000032#include <asm/arch/pinmux.h>
33#include <asm/arch/uart.h>
Tom Warren74652cf2011-04-14 12:18:06 +000034#include "board.h"
Tom Warren3f82b1d2011-01-27 10:58:05 +000035
Tom Warren21ef6a12011-05-31 10:30:37 +000036#ifdef CONFIG_TEGRA2_MMC
37#include <mmc.h>
38#endif
39
Tom Warren3f82b1d2011-01-27 10:58:05 +000040DECLARE_GLOBAL_DATA_PTR;
41
42const struct tegra2_sysinfo sysinfo = {
43 CONFIG_TEGRA2_BOARD_STRING
44};
45
46/*
47 * Routine: timer_init
48 * Description: init the timestamp and lastinc value
49 */
50int timer_init(void)
51{
Tom Warren3f82b1d2011-01-27 10:58:05 +000052 return 0;
53}
54
Simon Glass4ed59e72011-09-21 12:40:04 +000055static void enable_uart(enum periph_id pid)
56{
57 /* Assert UART reset and enable clock */
58 reset_set_enable(pid, 1);
59 clock_enable(pid);
60 clock_ll_set_source(pid, 0); /* UARTx_CLK_SRC = 00, PLLP_OUT0 */
61
62 /* wait for 2us */
63 udelay(2);
64
65 /* De-assert reset to UART */
66 reset_set_enable(pid, 0);
67}
68
Tom Warren3f82b1d2011-01-27 10:58:05 +000069/*
70 * Routine: clock_init_uart
71 * Description: init the PLL and clock for the UART(s)
72 */
73static void clock_init_uart(void)
74{
Tom Warren3f82b1d2011-01-27 10:58:05 +000075#if defined(CONFIG_TEGRA2_ENABLE_UARTA)
Simon Glass4ed59e72011-09-21 12:40:04 +000076 enable_uart(PERIPH_ID_UART1);
Tom Warren3f82b1d2011-01-27 10:58:05 +000077#endif /* CONFIG_TEGRA2_ENABLE_UARTA */
78#if defined(CONFIG_TEGRA2_ENABLE_UARTD)
Simon Glass4ed59e72011-09-21 12:40:04 +000079 enable_uart(PERIPH_ID_UART4);
Tom Warren3f82b1d2011-01-27 10:58:05 +000080#endif /* CONFIG_TEGRA2_ENABLE_UARTD */
81}
82
83/*
84 * Routine: pin_mux_uart
85 * Description: setup the pin muxes/tristate values for the UART(s)
86 */
87static void pin_mux_uart(void)
88{
89 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
90 u32 reg;
91
92#if defined(CONFIG_TEGRA2_ENABLE_UARTA)
93 reg = readl(&pmt->pmt_ctl_c);
94 reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
95 writel(reg, &pmt->pmt_ctl_c);
96
Simon Glassc3cf49d2011-09-21 12:40:05 +000097 pinmux_tristate_disable(PINGRP_IRRX);
98 pinmux_tristate_disable(PINGRP_IRTX);
Tom Warren3f82b1d2011-01-27 10:58:05 +000099#endif /* CONFIG_TEGRA2_ENABLE_UARTA */
100#if defined(CONFIG_TEGRA2_ENABLE_UARTD)
101 reg = readl(&pmt->pmt_ctl_b);
102 reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
103 writel(reg, &pmt->pmt_ctl_b);
104
Simon Glassc3cf49d2011-09-21 12:40:05 +0000105 pinmux_tristate_disable(PINGRP_GMC);
Tom Warren3f82b1d2011-01-27 10:58:05 +0000106#endif /* CONFIG_TEGRA2_ENABLE_UARTD */
107}
108
Simon Glass3e00dbd2011-09-21 12:40:03 +0000109#ifdef CONFIG_TEGRA2_MMC
Tom Warren3f82b1d2011-01-27 10:58:05 +0000110/*
Tom Warren21ef6a12011-05-31 10:30:37 +0000111 * Routine: clock_init_mmc
112 * Description: init the PLL and clocks for the SDMMC controllers
113 */
114static void clock_init_mmc(void)
115{
Simon Glass4ed59e72011-09-21 12:40:04 +0000116 clock_start_periph_pll(PERIPH_ID_SDMMC4, CLOCK_ID_PERIPH, 20000000);
117 clock_start_periph_pll(PERIPH_ID_SDMMC3, CLOCK_ID_PERIPH, 20000000);
Tom Warren21ef6a12011-05-31 10:30:37 +0000118}
119
120/*
121 * Routine: pin_mux_mmc
122 * Description: setup the pin muxes/tristate values for the SDMMC(s)
123 */
124static void pin_mux_mmc(void)
125{
126 struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
127 u32 reg;
128
129 /* SDMMC4 */
130 /* config 2, x8 on 2nd set of pins */
131 reg = readl(&pmt->pmt_ctl_a);
132 reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */
133 writel(reg, &pmt->pmt_ctl_a);
134 reg = readl(&pmt->pmt_ctl_b);
135 reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */
136 writel(reg, &pmt->pmt_ctl_b);
137 reg = readl(&pmt->pmt_ctl_d);
138 reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */
139 writel(reg, &pmt->pmt_ctl_d);
140
Simon Glassc3cf49d2011-09-21 12:40:05 +0000141 pinmux_tristate_disable(PINGRP_ATB);
142 pinmux_tristate_disable(PINGRP_GMA);
143 pinmux_tristate_disable(PINGRP_GME);
Tom Warren21ef6a12011-05-31 10:30:37 +0000144
145 /* SDMMC3 */
146 /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
147 reg = readl(&pmt->pmt_ctl_d);
148 reg &= 0xFFFF03FF;
149 reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */
150 reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */
151 reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */
152 writel(reg, &pmt->pmt_ctl_d);
153
Simon Glassc3cf49d2011-09-21 12:40:05 +0000154 pinmux_tristate_disable(PINGRP_SDC);
155 pinmux_tristate_disable(PINGRP_SDD);
156 pinmux_tristate_disable(PINGRP_SDB);
Tom Warren21ef6a12011-05-31 10:30:37 +0000157}
Simon Glass3e00dbd2011-09-21 12:40:03 +0000158#endif
Tom Warrenf4ef6662011-04-14 12:09:41 +0000159
160/*
Tom Warren3f82b1d2011-01-27 10:58:05 +0000161 * Routine: board_init
162 * Description: Early hardware init.
163 */
164int board_init(void)
165{
Simon Glass4ed59e72011-09-21 12:40:04 +0000166 clock_init();
167 clock_verify();
168
Tom Warren3f82b1d2011-01-27 10:58:05 +0000169 /* boot param addr */
170 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
Tom Warren3f82b1d2011-01-27 10:58:05 +0000171
Tom Warren3f82b1d2011-01-27 10:58:05 +0000172 return 0;
173}
Tom Warren21ef6a12011-05-31 10:30:37 +0000174
175#ifdef CONFIG_TEGRA2_MMC
176/* this is a weak define that we are overriding */
177int board_mmc_init(bd_t *bd)
178{
179 debug("board_mmc_init called\n");
180 /* Enable clocks, muxes, etc. for SDMMC controllers */
181 clock_init_mmc();
182 pin_mux_mmc();
183
184 debug("board_mmc_init: init eMMC\n");
185 /* init dev 0, eMMC chip, with 4-bit bus */
186 tegra2_mmc_init(0, 4);
187
188 debug("board_mmc_init: init SD slot\n");
189 /* init dev 1, SD slot, with 4-bit bus */
190 tegra2_mmc_init(1, 4);
191
192 return 0;
193}
194
195/* this is a weak define that we are overriding */
196int board_mmc_getcd(u8 *cd, struct mmc *mmc)
197{
198 debug("board_mmc_getcd called\n");
199 /*
200 * Hard-code CD presence for now. Need to add GPIO inputs
201 * for Seaboard & Harmony (& Kaen/Aebl/Wario?)
202 */
203 *cd = 1;
204 return 0;
205}
206#endif
Simon Glass3e00dbd2011-09-21 12:40:03 +0000207
208#ifdef CONFIG_BOARD_EARLY_INIT_F
209int board_early_init_f(void)
210{
Simon Glass4ed59e72011-09-21 12:40:04 +0000211 /* Initialize essential common plls */
212 clock_early_init();
213
Simon Glass3e00dbd2011-09-21 12:40:03 +0000214 /* Initialize UART clocks */
215 clock_init_uart();
216
217 /* Initialize periph pinmuxes */
218 pin_mux_uart();
219
220 /* Initialize periph GPIOs */
221 gpio_config_uart();
222
223 /* Init UART, scratch regs, and start CPU */
224 tegra2_start();
225 return 0;
226}
227#endif /* EARLY_INIT */