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 static int __maybe_unused board_is_gp_evm(void)
78 return !strncmp("A33515BB", header.name, 8);
81 int board_is_evm_15_or_later(void)
83 return (!strncmp("A33515BB", header.name, 8) &&
84 strncmp("1.5", header.version, 3) <= 0);
88 * Read header information from EEPROM into global structure.
90 static int read_eeprom(void)
92 /* Check if baseboard eeprom is available */
93 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
94 puts("Could not probe the EEPROM; something fundamentally "
95 "wrong on the I2C bus.\n");
99 /* read the eeprom using i2c */
100 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
102 puts("Could not read the EEPROM; something fundamentally"
103 " wrong on the I2C bus.\n");
107 if (header.magic != 0xEE3355AA) {
109 * read the eeprom using i2c again,
110 * but use only a 1 byte address
112 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
113 (uchar *)&header, sizeof(header))) {
114 puts("Could not read the EEPROM; something "
115 "fundamentally wrong on the I2C bus.\n");
119 if (header.magic != 0xEE3355AA) {
120 printf("Incorrect magic number (0x%x) in EEPROM\n",
130 #ifdef CONFIG_SPL_BUILD
131 #define UART_RESET (0x1 << 1)
132 #define UART_CLK_RUNNING_MASK 0x1
133 #define UART_SMART_IDLE_EN (0x1 << 0x3)
135 static const struct ddr_data ddr2_data = {
136 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
137 (MT47H128M16RT25E_RD_DQS<<20) |
138 (MT47H128M16RT25E_RD_DQS<<10) |
139 (MT47H128M16RT25E_RD_DQS<<0)),
140 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
141 (MT47H128M16RT25E_WR_DQS<<20) |
142 (MT47H128M16RT25E_WR_DQS<<10) |
143 (MT47H128M16RT25E_WR_DQS<<0)),
144 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
145 (MT47H128M16RT25E_PHY_WRLVL<<20) |
146 (MT47H128M16RT25E_PHY_WRLVL<<10) |
147 (MT47H128M16RT25E_PHY_WRLVL<<0)),
148 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
149 (MT47H128M16RT25E_PHY_GATELVL<<20) |
150 (MT47H128M16RT25E_PHY_GATELVL<<10) |
151 (MT47H128M16RT25E_PHY_GATELVL<<0)),
152 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
153 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
154 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
155 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
156 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
157 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
158 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
159 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
160 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
161 .datadldiff0 = PHY_DLL_LOCK_DIFF,
164 static const struct cmd_control ddr2_cmd_ctrl_data = {
165 .cmd0csratio = MT47H128M16RT25E_RATIO,
166 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
167 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
169 .cmd1csratio = MT47H128M16RT25E_RATIO,
170 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
171 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
173 .cmd2csratio = MT47H128M16RT25E_RATIO,
174 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
175 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
178 static const struct emif_regs ddr2_emif_reg_data = {
179 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
180 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
181 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
182 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
183 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
184 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
187 static const struct ddr_data ddr3_data = {
188 .datardsratio0 = MT41J128MJT125_RD_DQS,
189 .datawdsratio0 = MT41J128MJT125_WR_DQS,
190 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
191 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
192 .datadldiff0 = PHY_DLL_LOCK_DIFF,
195 static const struct ddr_data ddr3_beagleblack_data = {
196 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
197 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
198 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
199 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
200 .datadldiff0 = PHY_DLL_LOCK_DIFF,
203 static const struct ddr_data ddr3_evm_data = {
204 .datardsratio0 = MT41J512M8RH125_RD_DQS,
205 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
206 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
207 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
208 .datadldiff0 = PHY_DLL_LOCK_DIFF,
211 static const struct cmd_control ddr3_cmd_ctrl_data = {
212 .cmd0csratio = MT41J128MJT125_RATIO,
213 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
214 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
216 .cmd1csratio = MT41J128MJT125_RATIO,
217 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
218 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
220 .cmd2csratio = MT41J128MJT125_RATIO,
221 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
222 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
225 static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
226 .cmd0csratio = MT41K256M16HA125E_RATIO,
227 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
228 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
230 .cmd1csratio = MT41K256M16HA125E_RATIO,
231 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
232 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
234 .cmd2csratio = MT41K256M16HA125E_RATIO,
235 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
236 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
239 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
240 .cmd0csratio = MT41J512M8RH125_RATIO,
241 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
242 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
244 .cmd1csratio = MT41J512M8RH125_RATIO,
245 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
246 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
248 .cmd2csratio = MT41J512M8RH125_RATIO,
249 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
250 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
253 static struct emif_regs ddr3_emif_reg_data = {
254 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
255 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
256 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
257 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
258 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
259 .zq_config = MT41J128MJT125_ZQ_CFG,
260 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
264 static struct emif_regs ddr3_beagleblack_emif_reg_data = {
265 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
266 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
267 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
268 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
269 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
270 .zq_config = MT41K256M16HA125E_ZQ_CFG,
271 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
274 static struct emif_regs ddr3_evm_emif_reg_data = {
275 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
276 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
277 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
278 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
279 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
280 .zq_config = MT41J512M8RH125_ZQ_CFG,
281 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
287 * early system init of muxing and clocks.
292 * Save the boot parameters passed from romcode.
293 * We cannot delay the saving further than this,
294 * to prevent overwrites.
296 #ifdef CONFIG_SPL_BUILD
297 save_omap_boot_params();
300 /* WDT1 is already running when the bootloader gets control
301 * Disable it to avoid "random" resets
303 writel(0xAAAA, &wdtimer->wdtwspr);
304 while (readl(&wdtimer->wdtwwps) != 0x0)
306 writel(0x5555, &wdtimer->wdtwspr);
307 while (readl(&wdtimer->wdtwwps) != 0x0)
310 #ifdef CONFIG_SPL_BUILD
311 /* Setup the PLLs and the clocks for the peripherals */
314 /* Enable RTC32K clock */
320 #ifdef CONFIG_SERIAL1
321 enable_uart0_pin_mux();
322 #endif /* CONFIG_SERIAL1 */
323 #ifdef CONFIG_SERIAL2
324 enable_uart1_pin_mux();
325 #endif /* CONFIG_SERIAL2 */
326 #ifdef CONFIG_SERIAL3
327 enable_uart2_pin_mux();
328 #endif /* CONFIG_SERIAL3 */
329 #ifdef CONFIG_SERIAL4
330 enable_uart3_pin_mux();
331 #endif /* CONFIG_SERIAL4 */
332 #ifdef CONFIG_SERIAL5
333 enable_uart4_pin_mux();
334 #endif /* CONFIG_SERIAL5 */
335 #ifdef CONFIG_SERIAL6
336 enable_uart5_pin_mux();
337 #endif /* CONFIG_SERIAL6 */
339 regVal = readl(&uart_base->uartsyscfg);
340 regVal |= UART_RESET;
341 writel(regVal, &uart_base->uartsyscfg);
342 while ((readl(&uart_base->uartsyssts) &
343 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
346 /* Disable smart idle */
347 regVal = readl(&uart_base->uartsyscfg);
348 regVal |= UART_SMART_IDLE_EN;
349 writel(regVal, &uart_base->uartsyscfg);
353 preloader_console_init();
355 /* Initalize the board header */
356 enable_i2c0_pin_mux();
357 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
358 if (read_eeprom() < 0)
359 puts("Could not get board ID.\n");
361 enable_board_pin_mux(&header);
362 if (board_is_evm_sk()) {
364 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
365 * This is safe enough to do on older revs.
367 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
368 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
371 if (board_is_evm_sk())
372 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
373 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
374 else if (board_is_bone_lt())
375 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
376 &ddr3_beagleblack_data,
377 &ddr3_beagleblack_cmd_ctrl_data,
378 &ddr3_beagleblack_emif_reg_data, 0);
379 else if (board_is_evm_15_or_later())
380 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
381 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
383 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
384 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
389 * Basic board specific setup. Pinmux has been handled already.
393 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
394 if (read_eeprom() < 0)
395 puts("Could not get board ID.\n");
397 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
404 #ifdef CONFIG_BOARD_LATE_INIT
405 int board_late_init(void)
407 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
408 char safe_string[HDR_NAME_LEN + 1];
410 /* Now set variables based on the header. */
411 strncpy(safe_string, (char *)header.name, sizeof(header.name));
412 safe_string[sizeof(header.name)] = 0;
413 setenv("board_name", safe_string);
415 strncpy(safe_string, (char *)header.version, sizeof(header.version));
416 safe_string[sizeof(header.version)] = 0;
417 setenv("board_rev", safe_string);
424 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
425 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
426 static void cpsw_control(int enabled)
428 /* VTP can be added here */
433 static struct cpsw_slave_data cpsw_slaves[] = {
435 .slave_reg_ofs = 0x208,
436 .sliver_reg_ofs = 0xd80,
440 .slave_reg_ofs = 0x308,
441 .sliver_reg_ofs = 0xdc0,
446 static struct cpsw_platform_data cpsw_data = {
447 .mdio_base = CPSW_MDIO_BASE,
448 .cpsw_base = CPSW_BASE,
451 .cpdma_reg_ofs = 0x800,
453 .slave_data = cpsw_slaves,
454 .ale_reg_ofs = 0xd00,
456 .host_port_reg_ofs = 0x108,
457 .hw_stats_reg_ofs = 0x900,
458 .mac_control = (1 << 5),
459 .control = cpsw_control,
461 .version = CPSW_CTRL_VERSION_2,
465 #if defined(CONFIG_DRIVER_TI_CPSW) || \
466 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
467 int board_eth_init(bd_t *bis)
471 uint32_t mac_hi, mac_lo;
473 /* try reading mac address from efuse */
474 mac_lo = readl(&cdev->macid0l);
475 mac_hi = readl(&cdev->macid0h);
476 mac_addr[0] = mac_hi & 0xFF;
477 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
478 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
479 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
480 mac_addr[4] = mac_lo & 0xFF;
481 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
483 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
484 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
485 if (!getenv("ethaddr")) {
486 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
488 if (is_valid_ether_addr(mac_addr))
489 eth_setenv_enetaddr("ethaddr", mac_addr);
492 #ifdef CONFIG_DRIVER_TI_CPSW
493 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
494 writel(MII_MODE_ENABLE, &cdev->miisel);
495 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
496 PHY_INTERFACE_MODE_MII;
498 writel(RGMII_MODE_ENABLE, &cdev->miisel);
499 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
500 PHY_INTERFACE_MODE_RGMII;
503 rv = cpsw_register(&cpsw_data);
505 printf("Error %d registering CPSW switch\n", rv);
512 * CPSW RGMII Internal Delay Mode is not supported in all PVT
513 * operating points. So we must set the TX clock delay feature
514 * in the AR8051 PHY. Since we only support a single ethernet
515 * device in U-Boot, we only do this for the first instance.
517 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
518 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
519 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
520 #define AR8051_RGMII_TX_CLK_DLY 0x100
522 if (board_is_evm_sk() || board_is_gp_evm()) {
524 devname = miiphy_get_current_dev();
526 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
527 AR8051_DEBUG_RGMII_CLK_DLY_REG);
528 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
529 AR8051_RGMII_TX_CLK_DLY);
532 #if defined(CONFIG_USB_ETHER) && \
533 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
534 if (is_valid_ether_addr(mac_addr))
535 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
537 rv = usb_eth_initialize(bis);
539 printf("Error %d registering USB_ETHER\n", rv);