Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 1 | /* |
| 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 Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 31 | #include <asm/arch/clock.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 32 | #include <asm/arch/pinmux.h> |
| 33 | #include <asm/arch/uart.h> |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 34 | #include "board.h" |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 35 | |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_TEGRA2_MMC |
| 37 | #include <mmc.h> |
| 38 | #endif |
| 39 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | const 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 | */ |
| 50 | int timer_init(void) |
| 51 | { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Routine: clock_init_uart |
| 57 | * Description: init the PLL and clock for the UART(s) |
| 58 | */ |
| 59 | static void clock_init_uart(void) |
| 60 | { |
| 61 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
Simon Glass | 069784e | 2011-09-21 12:40:02 +0000 | [diff] [blame] | 62 | struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_PERIPH]; |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 63 | u32 reg; |
| 64 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 65 | reg = readl(&pll->pll_base); |
Simon Glass | e2deddd | 2011-08-30 06:23:15 +0000 | [diff] [blame] | 66 | if (!(reg & PLL_BASE_OVRRIDE_MASK)) { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 67 | /* Override pllp setup for 216MHz operation. */ |
Simon Glass | e2deddd | 2011-08-30 06:23:15 +0000 | [diff] [blame] | 68 | reg = PLL_BYPASS_MASK | PLL_BASE_OVRRIDE_MASK | |
| 69 | (1 << PLL_DIVP_SHIFT) | (0xc << PLL_DIVM_SHIFT); |
| 70 | reg |= (NVRM_PLLP_FIXED_FREQ_KHZ / 500) << PLL_DIVN_SHIFT; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 71 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 72 | |
Simon Glass | e2deddd | 2011-08-30 06:23:15 +0000 | [diff] [blame] | 73 | reg |= PLL_ENABLE_MASK; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 74 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 75 | |
Simon Glass | e2deddd | 2011-08-30 06:23:15 +0000 | [diff] [blame] | 76 | reg &= ~PLL_BYPASS_MASK; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 77 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 80 | #if defined(CONFIG_TEGRA2_ENABLE_UARTA) |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 81 | /* Assert UART reset and enable clock */ |
| 82 | reset_set_enable(PERIPH_ID_UART1, 1); |
| 83 | clock_enable(PERIPH_ID_UART1); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 84 | |
| 85 | /* Enable pllp_out0 to UART */ |
| 86 | reg = readl(&clkrst->crc_clk_src_uarta); |
| 87 | reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */ |
| 88 | writel(reg, &clkrst->crc_clk_src_uarta); |
| 89 | |
| 90 | /* wait for 2us */ |
| 91 | udelay(2); |
| 92 | |
| 93 | /* De-assert reset to UART */ |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 94 | reset_set_enable(PERIPH_ID_UART1, 0); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 95 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 96 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 97 | /* Assert UART reset and enable clock */ |
| 98 | reset_set_enable(PERIPH_ID_UART4, 1); |
| 99 | clock_enable(PERIPH_ID_UART4); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 100 | |
| 101 | /* Enable pllp_out0 to UART */ |
| 102 | reg = readl(&clkrst->crc_clk_src_uartd); |
| 103 | reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */ |
| 104 | writel(reg, &clkrst->crc_clk_src_uartd); |
| 105 | |
| 106 | /* wait for 2us */ |
| 107 | udelay(2); |
| 108 | |
| 109 | /* De-assert reset to UART */ |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 110 | reset_set_enable(PERIPH_ID_UART4, 0); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 111 | #endif /* CONFIG_TEGRA2_ENABLE_UARTD */ |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Routine: pin_mux_uart |
| 116 | * Description: setup the pin muxes/tristate values for the UART(s) |
| 117 | */ |
| 118 | static void pin_mux_uart(void) |
| 119 | { |
| 120 | struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE; |
| 121 | u32 reg; |
| 122 | |
| 123 | #if defined(CONFIG_TEGRA2_ENABLE_UARTA) |
| 124 | reg = readl(&pmt->pmt_ctl_c); |
| 125 | reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */ |
| 126 | writel(reg, &pmt->pmt_ctl_c); |
| 127 | |
Simon Glass | fa516f6 | 2011-08-30 06:23:14 +0000 | [diff] [blame] | 128 | pinmux_tristate_disable(PIN_IRRX); |
| 129 | pinmux_tristate_disable(PIN_IRTX); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 130 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 131 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
| 132 | reg = readl(&pmt->pmt_ctl_b); |
| 133 | reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */ |
| 134 | writel(reg, &pmt->pmt_ctl_b); |
| 135 | |
Simon Glass | fa516f6 | 2011-08-30 06:23:14 +0000 | [diff] [blame] | 136 | pinmux_tristate_disable(PIN_GMC); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 137 | #endif /* CONFIG_TEGRA2_ENABLE_UARTD */ |
| 138 | } |
| 139 | |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame^] | 140 | #ifdef CONFIG_TEGRA2_MMC |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 141 | /* |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 142 | * Routine: clock_init_mmc |
| 143 | * Description: init the PLL and clocks for the SDMMC controllers |
| 144 | */ |
| 145 | static void clock_init_mmc(void) |
| 146 | { |
| 147 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 148 | u32 reg; |
| 149 | |
| 150 | /* Do the SDMMC resets/clock enables */ |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 151 | reset_set_enable(PERIPH_ID_SDMMC4, 1); |
| 152 | clock_enable(PERIPH_ID_SDMMC4); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 153 | |
| 154 | /* Enable pllp_out0 to SDMMC4 */ |
| 155 | reg = readl(&clkrst->crc_clk_src_sdmmc4); |
| 156 | reg &= 0x3FFFFF00; /* SDMMC4_CLK_SRC = 00, PLLP_OUT0 */ |
| 157 | reg |= (10 << 1); /* n-1, 11-1 shl 1 */ |
| 158 | writel(reg, &clkrst->crc_clk_src_sdmmc4); |
| 159 | |
| 160 | /* |
| 161 | * As per the Tegra2 TRM, section 5.3.4: |
| 162 | * 'Wait 2 us for the clock to flush through the pipe/logic' |
| 163 | */ |
| 164 | udelay(2); |
| 165 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 166 | reset_set_enable(PERIPH_ID_SDMMC4, 1); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 167 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 168 | reset_set_enable(PERIPH_ID_SDMMC3, 1); |
| 169 | clock_enable(PERIPH_ID_SDMMC3); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 170 | |
| 171 | /* Enable pllp_out0 to SDMMC4, set divisor to 11 for 20MHz */ |
| 172 | reg = readl(&clkrst->crc_clk_src_sdmmc3); |
| 173 | reg &= 0x3FFFFF00; /* SDMMC3_CLK_SRC = 00, PLLP_OUT0 */ |
| 174 | reg |= (10 << 1); /* n-1, 11-1 shl 1 */ |
| 175 | writel(reg, &clkrst->crc_clk_src_sdmmc3); |
| 176 | |
| 177 | /* wait for 2us */ |
| 178 | udelay(2); |
| 179 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 180 | reset_set_enable(PERIPH_ID_SDMMC3, 0); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Routine: pin_mux_mmc |
| 185 | * Description: setup the pin muxes/tristate values for the SDMMC(s) |
| 186 | */ |
| 187 | static void pin_mux_mmc(void) |
| 188 | { |
| 189 | struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE; |
| 190 | u32 reg; |
| 191 | |
| 192 | /* SDMMC4 */ |
| 193 | /* config 2, x8 on 2nd set of pins */ |
| 194 | reg = readl(&pmt->pmt_ctl_a); |
| 195 | reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */ |
| 196 | writel(reg, &pmt->pmt_ctl_a); |
| 197 | reg = readl(&pmt->pmt_ctl_b); |
| 198 | reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */ |
| 199 | writel(reg, &pmt->pmt_ctl_b); |
| 200 | reg = readl(&pmt->pmt_ctl_d); |
| 201 | reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */ |
| 202 | writel(reg, &pmt->pmt_ctl_d); |
| 203 | |
Simon Glass | fa516f6 | 2011-08-30 06:23:14 +0000 | [diff] [blame] | 204 | pinmux_tristate_disable(PIN_ATB); |
| 205 | pinmux_tristate_disable(PIN_GMA); |
| 206 | pinmux_tristate_disable(PIN_GME); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 207 | |
| 208 | /* SDMMC3 */ |
| 209 | /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */ |
| 210 | reg = readl(&pmt->pmt_ctl_d); |
| 211 | reg &= 0xFFFF03FF; |
| 212 | reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */ |
| 213 | reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */ |
| 214 | reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */ |
| 215 | writel(reg, &pmt->pmt_ctl_d); |
| 216 | |
Simon Glass | fa516f6 | 2011-08-30 06:23:14 +0000 | [diff] [blame] | 217 | pinmux_tristate_disable(PIN_SDC); |
| 218 | pinmux_tristate_disable(PIN_SDD); |
| 219 | pinmux_tristate_disable(PIN_SDB); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 220 | } |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame^] | 221 | #endif |
Tom Warren | e149558 | 2011-04-14 12:09:41 +0000 | [diff] [blame] | 222 | |
| 223 | /* |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 224 | * Routine: board_init |
| 225 | * Description: Early hardware init. |
| 226 | */ |
| 227 | int board_init(void) |
| 228 | { |
| 229 | /* boot param addr */ |
| 230 | gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 231 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | } |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 234 | |
| 235 | #ifdef CONFIG_TEGRA2_MMC |
| 236 | /* this is a weak define that we are overriding */ |
| 237 | int board_mmc_init(bd_t *bd) |
| 238 | { |
| 239 | debug("board_mmc_init called\n"); |
| 240 | /* Enable clocks, muxes, etc. for SDMMC controllers */ |
| 241 | clock_init_mmc(); |
| 242 | pin_mux_mmc(); |
| 243 | |
| 244 | debug("board_mmc_init: init eMMC\n"); |
| 245 | /* init dev 0, eMMC chip, with 4-bit bus */ |
| 246 | tegra2_mmc_init(0, 4); |
| 247 | |
| 248 | debug("board_mmc_init: init SD slot\n"); |
| 249 | /* init dev 1, SD slot, with 4-bit bus */ |
| 250 | tegra2_mmc_init(1, 4); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* this is a weak define that we are overriding */ |
| 256 | int board_mmc_getcd(u8 *cd, struct mmc *mmc) |
| 257 | { |
| 258 | debug("board_mmc_getcd called\n"); |
| 259 | /* |
| 260 | * Hard-code CD presence for now. Need to add GPIO inputs |
| 261 | * for Seaboard & Harmony (& Kaen/Aebl/Wario?) |
| 262 | */ |
| 263 | *cd = 1; |
| 264 | return 0; |
| 265 | } |
| 266 | #endif |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame^] | 267 | |
| 268 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 269 | int board_early_init_f(void) |
| 270 | { |
| 271 | /* Initialize UART clocks */ |
| 272 | clock_init_uart(); |
| 273 | |
| 274 | /* Initialize periph pinmuxes */ |
| 275 | pin_mux_uart(); |
| 276 | |
| 277 | /* Initialize periph GPIOs */ |
| 278 | gpio_config_uart(); |
| 279 | |
| 280 | /* Init UART, scratch regs, and start CPU */ |
| 281 | tegra2_start(); |
| 282 | return 0; |
| 283 | } |
| 284 | #endif /* EARLY_INIT */ |