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 | |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 47 | int board_early_init_f(void) |
| 48 | { |
Tom Warren | e149558 | 2011-04-14 12:09:41 +0000 | [diff] [blame] | 49 | /* 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 Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 59 | tegra2_start(); |
| 60 | return 0; |
| 61 | } |
| 62 | #endif /* EARLY_INIT */ |
| 63 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Routine: timer_init |
| 66 | * Description: init the timestamp and lastinc value |
| 67 | */ |
| 68 | int timer_init(void) |
| 69 | { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Routine: clock_init_uart |
| 75 | * Description: init the PLL and clock for the UART(s) |
| 76 | */ |
| 77 | static void clock_init_uart(void) |
| 78 | { |
| 79 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 80 | struct clk_pll *pll = &clkrst->crc_pll[CLOCK_PLL_ID_PERIPH]; |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 81 | u32 reg; |
| 82 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 83 | reg = readl(&pll->pll_base); |
Tom Warren | e149558 | 2011-04-14 12:09:41 +0000 | [diff] [blame] | 84 | if (!(reg & PLL_BASE_OVRRIDE)) { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 85 | /* Override pllp setup for 216MHz operation. */ |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 86 | reg = (PLL_BYPASS | PLL_BASE_OVRRIDE | PLL_DIVP_VALUE); |
| 87 | reg |= (((NVRM_PLLP_FIXED_FREQ_KHZ/500) << 8) | PLL_DIVM_VALUE); |
| 88 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 89 | |
| 90 | reg |= PLL_ENABLE; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 91 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 92 | |
| 93 | reg &= ~PLL_BYPASS; |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 94 | writel(reg, &pll->pll_base); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* Now do the UART reset/clock enable */ |
| 98 | #if defined(CONFIG_TEGRA2_ENABLE_UARTA) |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 99 | /* Assert UART reset and enable clock */ |
| 100 | reset_set_enable(PERIPH_ID_UART1, 1); |
| 101 | clock_enable(PERIPH_ID_UART1); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 102 | |
| 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 Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 112 | reset_set_enable(PERIPH_ID_UART1, 0); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 113 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 114 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 115 | /* Assert UART reset and enable clock */ |
| 116 | reset_set_enable(PERIPH_ID_UART4, 1); |
| 117 | clock_enable(PERIPH_ID_UART4); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 118 | |
| 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 Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 128 | reset_set_enable(PERIPH_ID_UART4, 0); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 129 | #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 | */ |
| 136 | static 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 | |
| 146 | reg = readl(&pmt->pmt_tri_a); |
| 147 | reg &= ~Z_IRRX; /* Z_IRRX = normal (0) */ |
| 148 | reg &= ~Z_IRTX; /* Z_IRTX = normal (0) */ |
| 149 | writel(reg, &pmt->pmt_tri_a); |
| 150 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 151 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
| 152 | reg = readl(&pmt->pmt_ctl_b); |
| 153 | reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */ |
| 154 | writel(reg, &pmt->pmt_ctl_b); |
| 155 | |
| 156 | reg = readl(&pmt->pmt_tri_a); |
| 157 | reg &= ~Z_GMC; /* Z_GMC = normal (0) */ |
| 158 | writel(reg, &pmt->pmt_tri_a); |
| 159 | #endif /* CONFIG_TEGRA2_ENABLE_UARTD */ |
| 160 | } |
| 161 | |
| 162 | /* |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 163 | * Routine: clock_init_mmc |
| 164 | * Description: init the PLL and clocks for the SDMMC controllers |
| 165 | */ |
| 166 | static void clock_init_mmc(void) |
| 167 | { |
| 168 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 169 | u32 reg; |
| 170 | |
| 171 | /* Do the SDMMC resets/clock enables */ |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 172 | reset_set_enable(PERIPH_ID_SDMMC4, 1); |
| 173 | clock_enable(PERIPH_ID_SDMMC4); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 174 | |
| 175 | /* Enable pllp_out0 to SDMMC4 */ |
| 176 | reg = readl(&clkrst->crc_clk_src_sdmmc4); |
| 177 | reg &= 0x3FFFFF00; /* SDMMC4_CLK_SRC = 00, PLLP_OUT0 */ |
| 178 | reg |= (10 << 1); /* n-1, 11-1 shl 1 */ |
| 179 | writel(reg, &clkrst->crc_clk_src_sdmmc4); |
| 180 | |
| 181 | /* |
| 182 | * As per the Tegra2 TRM, section 5.3.4: |
| 183 | * 'Wait 2 us for the clock to flush through the pipe/logic' |
| 184 | */ |
| 185 | udelay(2); |
| 186 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 187 | reset_set_enable(PERIPH_ID_SDMMC4, 1); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 188 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 189 | reset_set_enable(PERIPH_ID_SDMMC3, 1); |
| 190 | clock_enable(PERIPH_ID_SDMMC3); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 191 | |
| 192 | /* Enable pllp_out0 to SDMMC4, set divisor to 11 for 20MHz */ |
| 193 | reg = readl(&clkrst->crc_clk_src_sdmmc3); |
| 194 | reg &= 0x3FFFFF00; /* SDMMC3_CLK_SRC = 00, PLLP_OUT0 */ |
| 195 | reg |= (10 << 1); /* n-1, 11-1 shl 1 */ |
| 196 | writel(reg, &clkrst->crc_clk_src_sdmmc3); |
| 197 | |
| 198 | /* wait for 2us */ |
| 199 | udelay(2); |
| 200 | |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame^] | 201 | reset_set_enable(PERIPH_ID_SDMMC3, 0); |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Routine: pin_mux_mmc |
| 206 | * Description: setup the pin muxes/tristate values for the SDMMC(s) |
| 207 | */ |
| 208 | static void pin_mux_mmc(void) |
| 209 | { |
| 210 | struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE; |
| 211 | u32 reg; |
| 212 | |
| 213 | /* SDMMC4 */ |
| 214 | /* config 2, x8 on 2nd set of pins */ |
| 215 | reg = readl(&pmt->pmt_ctl_a); |
| 216 | reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */ |
| 217 | writel(reg, &pmt->pmt_ctl_a); |
| 218 | reg = readl(&pmt->pmt_ctl_b); |
| 219 | reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */ |
| 220 | writel(reg, &pmt->pmt_ctl_b); |
| 221 | reg = readl(&pmt->pmt_ctl_d); |
| 222 | reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */ |
| 223 | writel(reg, &pmt->pmt_ctl_d); |
| 224 | |
| 225 | reg = readl(&pmt->pmt_tri_a); |
| 226 | reg &= ~Z_ATB; /* Z_ATB = normal (0) */ |
| 227 | reg &= ~Z_GMA; /* Z_GMA = normal (0) */ |
| 228 | writel(reg, &pmt->pmt_tri_a); |
| 229 | reg = readl(&pmt->pmt_tri_b); |
| 230 | reg &= ~Z_GME; /* Z_GME = normal (0) */ |
| 231 | writel(reg, &pmt->pmt_tri_b); |
| 232 | |
| 233 | /* SDMMC3 */ |
| 234 | /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */ |
| 235 | reg = readl(&pmt->pmt_ctl_d); |
| 236 | reg &= 0xFFFF03FF; |
| 237 | reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */ |
| 238 | reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */ |
| 239 | reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */ |
| 240 | writel(reg, &pmt->pmt_ctl_d); |
| 241 | |
| 242 | reg = readl(&pmt->pmt_tri_b); |
| 243 | reg &= ~Z_SDC; /* Z_SDC = normal (0) */ |
| 244 | reg &= ~Z_SDD; /* Z_SDD = normal (0) */ |
| 245 | writel(reg, &pmt->pmt_tri_b); |
| 246 | reg = readl(&pmt->pmt_tri_d); |
| 247 | reg &= ~Z_SDB; /* Z_SDB = normal (0) */ |
| 248 | writel(reg, &pmt->pmt_tri_d); |
| 249 | } |
| 250 | |
| 251 | /* |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 252 | * Routine: clock_init |
| 253 | * Description: Do individual peripheral clock reset/enables |
| 254 | */ |
| 255 | void clock_init(void) |
| 256 | { |
| 257 | clock_init_uart(); |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Routine: pinmux_init |
| 262 | * Description: Do individual peripheral pinmux configs |
| 263 | */ |
| 264 | void pinmux_init(void) |
| 265 | { |
| 266 | pin_mux_uart(); |
| 267 | } |
| 268 | |
| 269 | /* |
Tom Warren | e149558 | 2011-04-14 12:09:41 +0000 | [diff] [blame] | 270 | * Routine: gpio_init |
| 271 | * Description: Do individual peripheral GPIO configs |
| 272 | */ |
| 273 | void gpio_init(void) |
| 274 | { |
| 275 | gpio_config_uart(); |
| 276 | } |
| 277 | |
| 278 | /* |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 279 | * Routine: board_init |
| 280 | * Description: Early hardware init. |
| 281 | */ |
| 282 | int board_init(void) |
| 283 | { |
| 284 | /* boot param addr */ |
| 285 | gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 286 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 287 | return 0; |
| 288 | } |
Tom Warren | 85f0ee4 | 2011-05-31 10:30:37 +0000 | [diff] [blame] | 289 | |
| 290 | #ifdef CONFIG_TEGRA2_MMC |
| 291 | /* this is a weak define that we are overriding */ |
| 292 | int board_mmc_init(bd_t *bd) |
| 293 | { |
| 294 | debug("board_mmc_init called\n"); |
| 295 | /* Enable clocks, muxes, etc. for SDMMC controllers */ |
| 296 | clock_init_mmc(); |
| 297 | pin_mux_mmc(); |
| 298 | |
| 299 | debug("board_mmc_init: init eMMC\n"); |
| 300 | /* init dev 0, eMMC chip, with 4-bit bus */ |
| 301 | tegra2_mmc_init(0, 4); |
| 302 | |
| 303 | debug("board_mmc_init: init SD slot\n"); |
| 304 | /* init dev 1, SD slot, with 4-bit bus */ |
| 305 | tegra2_mmc_init(1, 4); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /* this is a weak define that we are overriding */ |
| 311 | int board_mmc_getcd(u8 *cd, struct mmc *mmc) |
| 312 | { |
| 313 | debug("board_mmc_getcd called\n"); |
| 314 | /* |
| 315 | * Hard-code CD presence for now. Need to add GPIO inputs |
| 316 | * for Seaboard & Harmony (& Kaen/Aebl/Wario?) |
| 317 | */ |
| 318 | *cd = 1; |
| 319 | return 0; |
| 320 | } |
| 321 | #endif |