4 * Board functions for TI AM335X based boards
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
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.
22 #include <asm/arch/cpu.h>
23 #include <asm/arch/hardware.h>
24 #include <asm/arch/omap.h>
25 #include <asm/arch/ddr_defs.h>
26 #include <asm/arch/clock.h>
27 #include <asm/arch/gpio.h>
28 #include <asm/arch/mmc_host_def.h>
29 #include <asm/arch/sys_proto.h>
38 DECLARE_GLOBAL_DATA_PTR;
40 static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
41 #ifdef CONFIG_SPL_BUILD
42 static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
45 /* MII mode defines */
46 #define MII_MODE_ENABLE 0x0
47 #define RGMII_MODE_ENABLE 0x3A
49 /* GPIO that controls power to DDR on EVM-SK */
50 #define GPIO_DDR_VTT_EN 7
52 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
54 static struct am335x_baseboard_id __attribute__((section (".data"))) header;
56 static inline int board_is_bone(void)
58 return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
61 static inline int board_is_bone_lt(void)
63 return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
66 static inline int board_is_evm_sk(void)
68 return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
71 static inline int board_is_idk(void)
73 return !strncmp(header.config, "SKU#02", 6);
76 int board_is_evm_15_or_later(void)
78 return (!strncmp("A33515BB", header.name, 8) &&
79 strncmp("1.5", header.version, 3) <= 0);
83 * Read header information from EEPROM into global structure.
85 static int read_eeprom(void)
87 /* Check if baseboard eeprom is available */
88 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
89 puts("Could not probe the EEPROM; something fundamentally "
90 "wrong on the I2C bus.\n");
94 /* read the eeprom using i2c */
95 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
97 puts("Could not read the EEPROM; something fundamentally"
98 " wrong on the I2C bus.\n");
102 if (header.magic != 0xEE3355AA) {
104 * read the eeprom using i2c again,
105 * but use only a 1 byte address
107 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
108 (uchar *)&header, sizeof(header))) {
109 puts("Could not read the EEPROM; something "
110 "fundamentally wrong on the I2C bus.\n");
114 if (header.magic != 0xEE3355AA) {
115 printf("Incorrect magic number (0x%x) in EEPROM\n",
125 #ifdef CONFIG_SPL_BUILD
126 #define UART_RESET (0x1 << 1)
127 #define UART_CLK_RUNNING_MASK 0x1
128 #define UART_SMART_IDLE_EN (0x1 << 0x3)
130 static void rtc32k_enable(void)
132 struct rtc_regs *rtc = (struct rtc_regs *)AM335X_RTC_BASE;
135 * Unlock the RTC's registers. For more details please see the
136 * RTC_SS section of the TRM. In order to unlock we need to
137 * write these specific values (keys) in this order.
139 writel(0x83e70b13, &rtc->kick0r);
140 writel(0x95a4f1e0, &rtc->kick1r);
142 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
143 writel((1 << 3) | (1 << 6), &rtc->osc);
146 static const struct ddr_data ddr2_data = {
147 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
148 (MT47H128M16RT25E_RD_DQS<<20) |
149 (MT47H128M16RT25E_RD_DQS<<10) |
150 (MT47H128M16RT25E_RD_DQS<<0)),
151 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
152 (MT47H128M16RT25E_WR_DQS<<20) |
153 (MT47H128M16RT25E_WR_DQS<<10) |
154 (MT47H128M16RT25E_WR_DQS<<0)),
155 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
156 (MT47H128M16RT25E_PHY_WRLVL<<20) |
157 (MT47H128M16RT25E_PHY_WRLVL<<10) |
158 (MT47H128M16RT25E_PHY_WRLVL<<0)),
159 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
160 (MT47H128M16RT25E_PHY_GATELVL<<20) |
161 (MT47H128M16RT25E_PHY_GATELVL<<10) |
162 (MT47H128M16RT25E_PHY_GATELVL<<0)),
163 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
164 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
165 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
166 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
167 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
168 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
169 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
170 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
171 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
172 .datadldiff0 = PHY_DLL_LOCK_DIFF,
175 static const struct cmd_control ddr2_cmd_ctrl_data = {
176 .cmd0csratio = MT47H128M16RT25E_RATIO,
177 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
178 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
180 .cmd1csratio = MT47H128M16RT25E_RATIO,
181 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
182 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
184 .cmd2csratio = MT47H128M16RT25E_RATIO,
185 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
186 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
189 static const struct emif_regs ddr2_emif_reg_data = {
190 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
191 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
192 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
193 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
194 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
195 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
198 static const struct ddr_data ddr3_data = {
199 .datardsratio0 = MT41J128MJT125_RD_DQS,
200 .datawdsratio0 = MT41J128MJT125_WR_DQS,
201 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
202 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
203 .datadldiff0 = PHY_DLL_LOCK_DIFF,
206 static const struct ddr_data ddr3_evm_data = {
207 .datardsratio0 = MT41J512M8RH125_RD_DQS,
208 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
209 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
210 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
211 .datadldiff0 = PHY_DLL_LOCK_DIFF,
214 static const struct cmd_control ddr3_cmd_ctrl_data = {
215 .cmd0csratio = MT41J128MJT125_RATIO,
216 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
217 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
219 .cmd1csratio = MT41J128MJT125_RATIO,
220 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
221 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
223 .cmd2csratio = MT41J128MJT125_RATIO,
224 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
225 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
228 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
229 .cmd0csratio = MT41J512M8RH125_RATIO,
230 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
231 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
233 .cmd1csratio = MT41J512M8RH125_RATIO,
234 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
235 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
237 .cmd2csratio = MT41J512M8RH125_RATIO,
238 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
239 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
242 static struct emif_regs ddr3_emif_reg_data = {
243 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
244 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
245 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
246 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
247 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
248 .zq_config = MT41J128MJT125_ZQ_CFG,
249 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY,
252 static struct emif_regs ddr3_evm_emif_reg_data = {
253 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
254 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
255 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
256 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
257 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
258 .zq_config = MT41J512M8RH125_ZQ_CFG,
259 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY,
264 * early system init of muxing and clocks.
268 /* WDT1 is already running when the bootloader gets control
269 * Disable it to avoid "random" resets
271 writel(0xAAAA, &wdtimer->wdtwspr);
272 while (readl(&wdtimer->wdtwwps) != 0x0)
274 writel(0x5555, &wdtimer->wdtwspr);
275 while (readl(&wdtimer->wdtwwps) != 0x0)
278 #ifdef CONFIG_SPL_BUILD
279 /* Setup the PLLs and the clocks for the peripherals */
282 /* Enable RTC32K clock */
288 #ifdef CONFIG_SERIAL1
289 enable_uart0_pin_mux();
290 #endif /* CONFIG_SERIAL1 */
291 #ifdef CONFIG_SERIAL2
292 enable_uart1_pin_mux();
293 #endif /* CONFIG_SERIAL2 */
294 #ifdef CONFIG_SERIAL3
295 enable_uart2_pin_mux();
296 #endif /* CONFIG_SERIAL3 */
297 #ifdef CONFIG_SERIAL4
298 enable_uart3_pin_mux();
299 #endif /* CONFIG_SERIAL4 */
300 #ifdef CONFIG_SERIAL5
301 enable_uart4_pin_mux();
302 #endif /* CONFIG_SERIAL5 */
303 #ifdef CONFIG_SERIAL6
304 enable_uart5_pin_mux();
305 #endif /* CONFIG_SERIAL6 */
307 regVal = readl(&uart_base->uartsyscfg);
308 regVal |= UART_RESET;
309 writel(regVal, &uart_base->uartsyscfg);
310 while ((readl(&uart_base->uartsyssts) &
311 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
314 /* Disable smart idle */
315 regVal = readl(&uart_base->uartsyscfg);
316 regVal |= UART_SMART_IDLE_EN;
317 writel(regVal, &uart_base->uartsyscfg);
321 preloader_console_init();
323 /* Initalize the board header */
324 enable_i2c0_pin_mux();
325 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
326 if (read_eeprom() < 0)
327 puts("Could not get board ID.\n");
329 enable_board_pin_mux(&header);
330 if (board_is_evm_sk()) {
332 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
333 * This is safe enough to do on older revs.
335 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
336 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
339 if (board_is_evm_sk() || board_is_bone_lt())
340 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
341 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data);
342 else if (board_is_evm_15_or_later())
343 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
344 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data);
346 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
347 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data);
352 * Basic board specific setup. Pinmux has been handled already.
356 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
357 if (read_eeprom() < 0)
358 puts("Could not get board ID.\n");
360 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
367 #ifdef CONFIG_BOARD_LATE_INIT
368 int board_late_init(void)
370 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
371 char safe_string[HDR_NAME_LEN + 1];
373 /* Now set variables based on the header. */
374 strncpy(safe_string, (char *)header.name, sizeof(header.name));
375 safe_string[sizeof(header.name)] = 0;
376 setenv("board_name", safe_string);
378 strncpy(safe_string, (char *)header.version, sizeof(header.version));
379 safe_string[sizeof(header.version)] = 0;
380 setenv("board_rev", safe_string);
387 #ifdef CONFIG_DRIVER_TI_CPSW
388 static void cpsw_control(int enabled)
390 /* VTP can be added here */
395 static struct cpsw_slave_data cpsw_slaves[] = {
397 .slave_reg_ofs = 0x208,
398 .sliver_reg_ofs = 0xd80,
402 .slave_reg_ofs = 0x308,
403 .sliver_reg_ofs = 0xdc0,
408 static struct cpsw_platform_data cpsw_data = {
409 .mdio_base = AM335X_CPSW_MDIO_BASE,
410 .cpsw_base = AM335X_CPSW_BASE,
413 .cpdma_reg_ofs = 0x800,
415 .slave_data = cpsw_slaves,
416 .ale_reg_ofs = 0xd00,
418 .host_port_reg_ofs = 0x108,
419 .hw_stats_reg_ofs = 0x900,
420 .mac_control = (1 << 5),
421 .control = cpsw_control,
423 .version = CPSW_CTRL_VERSION_2,
427 #if defined(CONFIG_DRIVER_TI_CPSW) || \
428 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
429 int board_eth_init(bd_t *bis)
432 #ifdef CONFIG_DRIVER_TI_CPSW
434 uint32_t mac_hi, mac_lo;
436 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
437 printf("<ethaddr> not set. Reading from E-fuse\n");
438 /* try reading mac address from efuse */
439 mac_lo = readl(&cdev->macid0l);
440 mac_hi = readl(&cdev->macid0h);
441 mac_addr[0] = mac_hi & 0xFF;
442 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
443 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
444 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
445 mac_addr[4] = mac_lo & 0xFF;
446 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
448 if (is_valid_ether_addr(mac_addr))
449 eth_setenv_enetaddr("ethaddr", mac_addr);
454 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
455 writel(MII_MODE_ENABLE, &cdev->miisel);
456 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
457 PHY_INTERFACE_MODE_MII;
459 writel(RGMII_MODE_ENABLE, &cdev->miisel);
460 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
461 PHY_INTERFACE_MODE_RGMII;
464 rv = cpsw_register(&cpsw_data);
466 printf("Error %d registering CPSW switch\n", rv);
471 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
472 rv = usb_eth_initialize(bis);
474 printf("Error %d registering USB_ETHER\n", rv);