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;
42 /* MII mode defines */
43 #define MII_MODE_ENABLE 0x0
44 #define RGMII_MODE_ENABLE 0x3A
46 /* GPIO that controls power to DDR on EVM-SK */
47 #define GPIO_DDR_VTT_EN 7
49 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
51 static struct am335x_baseboard_id __attribute__((section (".data"))) header;
53 static inline int board_is_bone(void)
55 return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
58 static inline int board_is_bone_lt(void)
60 return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
63 static inline int board_is_evm_sk(void)
65 return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
68 static inline int board_is_idk(void)
70 return !strncmp(header.config, "SKU#02", 6);
73 static int __maybe_unused board_is_gp_evm(void)
75 return !strncmp("A33515BB", header.name, 8);
78 int board_is_evm_15_or_later(void)
80 return (!strncmp("A33515BB", header.name, 8) &&
81 strncmp("1.5", header.version, 3) <= 0);
85 * Read header information from EEPROM into global structure.
87 static int read_eeprom(void)
89 /* Check if baseboard eeprom is available */
90 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
91 puts("Could not probe the EEPROM; something fundamentally "
92 "wrong on the I2C bus.\n");
96 /* read the eeprom using i2c */
97 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
99 puts("Could not read the EEPROM; something fundamentally"
100 " wrong on the I2C bus.\n");
104 if (header.magic != 0xEE3355AA) {
106 * read the eeprom using i2c again,
107 * but use only a 1 byte address
109 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
110 (uchar *)&header, sizeof(header))) {
111 puts("Could not read the EEPROM; something "
112 "fundamentally wrong on the I2C bus.\n");
116 if (header.magic != 0xEE3355AA) {
117 printf("Incorrect magic number (0x%x) in EEPROM\n",
126 #ifdef CONFIG_SPL_BUILD
127 static const struct ddr_data ddr2_data = {
128 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
129 (MT47H128M16RT25E_RD_DQS<<20) |
130 (MT47H128M16RT25E_RD_DQS<<10) |
131 (MT47H128M16RT25E_RD_DQS<<0)),
132 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
133 (MT47H128M16RT25E_WR_DQS<<20) |
134 (MT47H128M16RT25E_WR_DQS<<10) |
135 (MT47H128M16RT25E_WR_DQS<<0)),
136 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
137 (MT47H128M16RT25E_PHY_WRLVL<<20) |
138 (MT47H128M16RT25E_PHY_WRLVL<<10) |
139 (MT47H128M16RT25E_PHY_WRLVL<<0)),
140 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
141 (MT47H128M16RT25E_PHY_GATELVL<<20) |
142 (MT47H128M16RT25E_PHY_GATELVL<<10) |
143 (MT47H128M16RT25E_PHY_GATELVL<<0)),
144 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
145 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
146 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
147 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
148 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
149 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
150 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
151 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
152 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
153 .datadldiff0 = PHY_DLL_LOCK_DIFF,
156 static const struct cmd_control ddr2_cmd_ctrl_data = {
157 .cmd0csratio = MT47H128M16RT25E_RATIO,
158 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
159 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
161 .cmd1csratio = MT47H128M16RT25E_RATIO,
162 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
163 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
165 .cmd2csratio = MT47H128M16RT25E_RATIO,
166 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
167 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
170 static const struct emif_regs ddr2_emif_reg_data = {
171 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
172 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
173 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
174 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
175 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
176 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
179 static const struct ddr_data ddr3_data = {
180 .datardsratio0 = MT41J128MJT125_RD_DQS,
181 .datawdsratio0 = MT41J128MJT125_WR_DQS,
182 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
183 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
184 .datadldiff0 = PHY_DLL_LOCK_DIFF,
187 static const struct ddr_data ddr3_beagleblack_data = {
188 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
189 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
190 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
191 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
192 .datadldiff0 = PHY_DLL_LOCK_DIFF,
195 static const struct ddr_data ddr3_evm_data = {
196 .datardsratio0 = MT41J512M8RH125_RD_DQS,
197 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
198 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
199 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
200 .datadldiff0 = PHY_DLL_LOCK_DIFF,
203 static const struct cmd_control ddr3_cmd_ctrl_data = {
204 .cmd0csratio = MT41J128MJT125_RATIO,
205 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
206 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
208 .cmd1csratio = MT41J128MJT125_RATIO,
209 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
210 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
212 .cmd2csratio = MT41J128MJT125_RATIO,
213 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
214 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
217 static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
218 .cmd0csratio = MT41K256M16HA125E_RATIO,
219 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
220 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
222 .cmd1csratio = MT41K256M16HA125E_RATIO,
223 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
224 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
226 .cmd2csratio = MT41K256M16HA125E_RATIO,
227 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
228 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
231 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
232 .cmd0csratio = MT41J512M8RH125_RATIO,
233 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
234 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
236 .cmd1csratio = MT41J512M8RH125_RATIO,
237 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
238 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
240 .cmd2csratio = MT41J512M8RH125_RATIO,
241 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
242 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
245 static struct emif_regs ddr3_emif_reg_data = {
246 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
247 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
248 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
249 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
250 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
251 .zq_config = MT41J128MJT125_ZQ_CFG,
252 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
256 static struct emif_regs ddr3_beagleblack_emif_reg_data = {
257 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
258 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
259 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
260 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
261 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
262 .zq_config = MT41K256M16HA125E_ZQ_CFG,
263 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
266 static struct emif_regs ddr3_evm_emif_reg_data = {
267 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
268 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
269 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
270 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
271 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
272 .zq_config = MT41J512M8RH125_ZQ_CFG,
273 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
279 * early system init of muxing and clocks.
284 * Save the boot parameters passed from romcode.
285 * We cannot delay the saving further than this,
286 * to prevent overwrites.
288 #ifdef CONFIG_SPL_BUILD
289 save_omap_boot_params();
292 /* WDT1 is already running when the bootloader gets control
293 * Disable it to avoid "random" resets
295 writel(0xAAAA, &wdtimer->wdtwspr);
296 while (readl(&wdtimer->wdtwwps) != 0x0)
298 writel(0x5555, &wdtimer->wdtwspr);
299 while (readl(&wdtimer->wdtwwps) != 0x0)
302 #ifdef CONFIG_SPL_BUILD
303 /* Setup the PLLs and the clocks for the peripherals */
306 /* Enable RTC32K clock */
309 #ifdef CONFIG_SERIAL1
310 enable_uart0_pin_mux();
311 #endif /* CONFIG_SERIAL1 */
312 #ifdef CONFIG_SERIAL2
313 enable_uart1_pin_mux();
314 #endif /* CONFIG_SERIAL2 */
315 #ifdef CONFIG_SERIAL3
316 enable_uart2_pin_mux();
317 #endif /* CONFIG_SERIAL3 */
318 #ifdef CONFIG_SERIAL4
319 enable_uart3_pin_mux();
320 #endif /* CONFIG_SERIAL4 */
321 #ifdef CONFIG_SERIAL5
322 enable_uart4_pin_mux();
323 #endif /* CONFIG_SERIAL5 */
324 #ifdef CONFIG_SERIAL6
325 enable_uart5_pin_mux();
326 #endif /* CONFIG_SERIAL6 */
332 preloader_console_init();
334 /* Initalize the board header */
335 enable_i2c0_pin_mux();
336 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
337 if (read_eeprom() < 0)
338 puts("Could not get board ID.\n");
340 enable_board_pin_mux(&header);
341 if (board_is_evm_sk()) {
343 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
344 * This is safe enough to do on older revs.
346 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
347 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
350 if (board_is_evm_sk())
351 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
352 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
353 else if (board_is_bone_lt())
354 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
355 &ddr3_beagleblack_data,
356 &ddr3_beagleblack_cmd_ctrl_data,
357 &ddr3_beagleblack_emif_reg_data, 0);
358 else if (board_is_evm_15_or_later())
359 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
360 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
362 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
363 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
368 * Basic board specific setup. Pinmux has been handled already.
372 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
373 if (read_eeprom() < 0)
374 puts("Could not get board ID.\n");
376 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
383 #ifdef CONFIG_BOARD_LATE_INIT
384 int board_late_init(void)
386 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
387 char safe_string[HDR_NAME_LEN + 1];
389 /* Now set variables based on the header. */
390 strncpy(safe_string, (char *)header.name, sizeof(header.name));
391 safe_string[sizeof(header.name)] = 0;
392 setenv("board_name", safe_string);
394 strncpy(safe_string, (char *)header.version, sizeof(header.version));
395 safe_string[sizeof(header.version)] = 0;
396 setenv("board_rev", safe_string);
403 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
404 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
405 static void cpsw_control(int enabled)
407 /* VTP can be added here */
412 static struct cpsw_slave_data cpsw_slaves[] = {
414 .slave_reg_ofs = 0x208,
415 .sliver_reg_ofs = 0xd80,
419 .slave_reg_ofs = 0x308,
420 .sliver_reg_ofs = 0xdc0,
425 static struct cpsw_platform_data cpsw_data = {
426 .mdio_base = CPSW_MDIO_BASE,
427 .cpsw_base = CPSW_BASE,
430 .cpdma_reg_ofs = 0x800,
432 .slave_data = cpsw_slaves,
433 .ale_reg_ofs = 0xd00,
435 .host_port_reg_ofs = 0x108,
436 .hw_stats_reg_ofs = 0x900,
437 .mac_control = (1 << 5),
438 .control = cpsw_control,
440 .version = CPSW_CTRL_VERSION_2,
444 #if defined(CONFIG_DRIVER_TI_CPSW) || \
445 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
446 int board_eth_init(bd_t *bis)
450 uint32_t mac_hi, mac_lo;
452 /* try reading mac address from efuse */
453 mac_lo = readl(&cdev->macid0l);
454 mac_hi = readl(&cdev->macid0h);
455 mac_addr[0] = mac_hi & 0xFF;
456 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
457 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
458 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
459 mac_addr[4] = mac_lo & 0xFF;
460 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
462 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
463 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
464 if (!getenv("ethaddr")) {
465 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
467 if (is_valid_ether_addr(mac_addr))
468 eth_setenv_enetaddr("ethaddr", mac_addr);
471 #ifdef CONFIG_DRIVER_TI_CPSW
472 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
473 writel(MII_MODE_ENABLE, &cdev->miisel);
474 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
475 PHY_INTERFACE_MODE_MII;
477 writel(RGMII_MODE_ENABLE, &cdev->miisel);
478 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
479 PHY_INTERFACE_MODE_RGMII;
482 rv = cpsw_register(&cpsw_data);
484 printf("Error %d registering CPSW switch\n", rv);
491 * CPSW RGMII Internal Delay Mode is not supported in all PVT
492 * operating points. So we must set the TX clock delay feature
493 * in the AR8051 PHY. Since we only support a single ethernet
494 * device in U-Boot, we only do this for the first instance.
496 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
497 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
498 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
499 #define AR8051_RGMII_TX_CLK_DLY 0x100
501 if (board_is_evm_sk() || board_is_gp_evm()) {
503 devname = miiphy_get_current_dev();
505 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
506 AR8051_DEBUG_RGMII_CLK_DLY_REG);
507 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
508 AR8051_RGMII_TX_CLK_DLY);
511 #if defined(CONFIG_USB_ETHER) && \
512 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
513 if (is_valid_ether_addr(mac_addr))
514 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
516 rv = usb_eth_initialize(bis);
518 printf("Error %d registering USB_ETHER\n", rv);