4 * Board functions for TI AM335X based boards
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/omap.h>
17 #include <asm/arch/ddr_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/mmc_host_def.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/mem.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
35 /* MII mode defines */
36 #define MII_MODE_ENABLE 0x0
37 #define RGMII_MODE_ENABLE 0x3A
39 /* GPIO that controls power to DDR on EVM-SK */
40 #define GPIO_DDR_VTT_EN 7
42 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
45 * Read header information from EEPROM into global structure.
47 static int read_eeprom(struct am335x_baseboard_id *header)
49 /* Check if baseboard eeprom is available */
50 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
51 puts("Could not probe the EEPROM; something fundamentally "
52 "wrong on the I2C bus.\n");
56 /* read the eeprom using i2c */
57 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
58 sizeof(struct am335x_baseboard_id))) {
59 puts("Could not read the EEPROM; something fundamentally"
60 " wrong on the I2C bus.\n");
64 if (header->magic != 0xEE3355AA) {
66 * read the eeprom using i2c again,
67 * but use only a 1 byte address
69 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
70 sizeof(struct am335x_baseboard_id))) {
71 puts("Could not read the EEPROM; something "
72 "fundamentally wrong on the I2C bus.\n");
76 if (header->magic != 0xEE3355AA) {
77 printf("Incorrect magic number (0x%x) in EEPROM\n",
86 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
87 static const struct ddr_data ddr2_data = {
88 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
89 (MT47H128M16RT25E_RD_DQS<<20) |
90 (MT47H128M16RT25E_RD_DQS<<10) |
91 (MT47H128M16RT25E_RD_DQS<<0)),
92 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
93 (MT47H128M16RT25E_WR_DQS<<20) |
94 (MT47H128M16RT25E_WR_DQS<<10) |
95 (MT47H128M16RT25E_WR_DQS<<0)),
96 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
97 (MT47H128M16RT25E_PHY_WRLVL<<20) |
98 (MT47H128M16RT25E_PHY_WRLVL<<10) |
99 (MT47H128M16RT25E_PHY_WRLVL<<0)),
100 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
101 (MT47H128M16RT25E_PHY_GATELVL<<20) |
102 (MT47H128M16RT25E_PHY_GATELVL<<10) |
103 (MT47H128M16RT25E_PHY_GATELVL<<0)),
104 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
105 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
106 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
107 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
108 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
109 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
110 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
111 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
112 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
113 .datadldiff0 = PHY_DLL_LOCK_DIFF,
116 static const struct cmd_control ddr2_cmd_ctrl_data = {
117 .cmd0csratio = MT47H128M16RT25E_RATIO,
118 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
119 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
121 .cmd1csratio = MT47H128M16RT25E_RATIO,
122 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
123 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
125 .cmd2csratio = MT47H128M16RT25E_RATIO,
126 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
127 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
130 static const struct emif_regs ddr2_emif_reg_data = {
131 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
132 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
133 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
134 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
135 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
136 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
139 static const struct ddr_data ddr3_data = {
140 .datardsratio0 = MT41J128MJT125_RD_DQS,
141 .datawdsratio0 = MT41J128MJT125_WR_DQS,
142 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
143 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
144 .datadldiff0 = PHY_DLL_LOCK_DIFF,
147 static const struct ddr_data ddr3_beagleblack_data = {
148 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
149 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
150 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
151 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
152 .datadldiff0 = PHY_DLL_LOCK_DIFF,
155 static const struct ddr_data ddr3_evm_data = {
156 .datardsratio0 = MT41J512M8RH125_RD_DQS,
157 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
158 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
159 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
160 .datadldiff0 = PHY_DLL_LOCK_DIFF,
163 static const struct cmd_control ddr3_cmd_ctrl_data = {
164 .cmd0csratio = MT41J128MJT125_RATIO,
165 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
166 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
168 .cmd1csratio = MT41J128MJT125_RATIO,
169 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
170 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
172 .cmd2csratio = MT41J128MJT125_RATIO,
173 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
174 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
177 static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
178 .cmd0csratio = MT41K256M16HA125E_RATIO,
179 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
180 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
182 .cmd1csratio = MT41K256M16HA125E_RATIO,
183 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
184 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
186 .cmd2csratio = MT41K256M16HA125E_RATIO,
187 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
188 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
191 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
192 .cmd0csratio = MT41J512M8RH125_RATIO,
193 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
194 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
196 .cmd1csratio = MT41J512M8RH125_RATIO,
197 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
198 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
200 .cmd2csratio = MT41J512M8RH125_RATIO,
201 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
202 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
205 static struct emif_regs ddr3_emif_reg_data = {
206 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
207 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
208 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
209 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
210 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
211 .zq_config = MT41J128MJT125_ZQ_CFG,
212 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
216 static struct emif_regs ddr3_beagleblack_emif_reg_data = {
217 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
218 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
219 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
220 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
221 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
222 .zq_config = MT41K256M16HA125E_ZQ_CFG,
223 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
226 static struct emif_regs ddr3_evm_emif_reg_data = {
227 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
228 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
229 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
230 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
231 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
232 .zq_config = MT41J512M8RH125_ZQ_CFG,
233 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
237 #ifdef CONFIG_SPL_OS_BOOT
238 int spl_start_uboot(void)
240 /* break into full u-boot on 'c' */
241 return (serial_tstc() && serial_getc() == 'c');
245 #define OSC (V_OSCK/1000000)
246 const struct dpll_params dpll_ddr = {
247 266, OSC-1, 1, -1, -1, -1, -1};
248 const struct dpll_params dpll_ddr_evm_sk = {
249 303, OSC-1, 1, -1, -1, -1, -1};
250 const struct dpll_params dpll_ddr_bone_black = {
251 400, OSC-1, 1, -1, -1, -1, -1};
253 const struct dpll_params *get_dpll_ddr_params(void)
255 struct am335x_baseboard_id header;
257 enable_i2c0_pin_mux();
258 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
259 if (read_eeprom(&header) < 0)
260 puts("Could not get board ID.\n");
262 if (board_is_evm_sk(&header))
263 return &dpll_ddr_evm_sk;
264 else if (board_is_bone_lt(&header))
265 return &dpll_ddr_bone_black;
266 else if (board_is_evm_15_or_later(&header))
267 return &dpll_ddr_evm_sk;
275 * early system init of muxing and clocks.
279 __maybe_unused struct am335x_baseboard_id header;
282 * The ROM will only have set up sufficient pinmux to allow for the
283 * first 4KiB NOR to be read, we must finish doing what we know of
284 * the NOR mux in this space in order to continue.
286 #ifdef CONFIG_NOR_BOOT
287 asm("stmfd sp!, {r2 - r4}");
288 asm("movw r4, #0x8A4");
289 asm("movw r3, #0x44E1");
290 asm("orr r4, r4, r3, lsl #16");
293 asm("gpmc_mux: str r2, [r4], #4");
294 asm("subs r3, r3, #1");
296 asm("ldmfd sp!, {r2 - r4}");
299 #ifdef CONFIG_SPL_BUILD
301 * Save the boot parameters passed from romcode.
302 * We cannot delay the saving further than this,
303 * to prevent overwrites.
305 save_omap_boot_params();
308 /* WDT1 is already running when the bootloader gets control
309 * Disable it to avoid "random" resets
311 writel(0xAAAA, &wdtimer->wdtwspr);
312 while (readl(&wdtimer->wdtwwps) != 0x0)
314 writel(0x5555, &wdtimer->wdtwspr);
315 while (readl(&wdtimer->wdtwwps) != 0x0)
318 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
319 /* Setup the PLLs and the clocks for the peripherals */
322 /* Enable RTC32K clock */
325 #ifdef CONFIG_SERIAL1
326 enable_uart0_pin_mux();
327 #endif /* CONFIG_SERIAL1 */
328 #ifdef CONFIG_SERIAL2
329 enable_uart1_pin_mux();
330 #endif /* CONFIG_SERIAL2 */
331 #ifdef CONFIG_SERIAL3
332 enable_uart2_pin_mux();
333 #endif /* CONFIG_SERIAL3 */
334 #ifdef CONFIG_SERIAL4
335 enable_uart3_pin_mux();
336 #endif /* CONFIG_SERIAL4 */
337 #ifdef CONFIG_SERIAL5
338 enable_uart4_pin_mux();
339 #endif /* CONFIG_SERIAL5 */
340 #ifdef CONFIG_SERIAL6
341 enable_uart5_pin_mux();
342 #endif /* CONFIG_SERIAL6 */
346 #if defined(CONFIG_NOR_BOOT)
347 /* We want our console now. */
348 gd->baudrate = CONFIG_BAUDRATE;
350 gd->have_console = 1;
354 preloader_console_init();
357 /* Initalize the board header */
358 enable_i2c0_pin_mux();
359 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
360 if (read_eeprom(&header) < 0)
361 puts("Could not get board ID.\n");
363 enable_board_pin_mux(&header);
364 if (board_is_evm_sk(&header)) {
366 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
367 * This is safe enough to do on older revs.
369 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
370 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
373 if (board_is_evm_sk(&header))
374 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
375 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
376 else if (board_is_bone_lt(&header))
377 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
378 &ddr3_beagleblack_data,
379 &ddr3_beagleblack_cmd_ctrl_data,
380 &ddr3_beagleblack_emif_reg_data, 0);
381 else if (board_is_evm_15_or_later(&header))
382 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
383 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
385 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
386 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
391 * Basic board specific setup. Pinmux has been handled already.
396 const u32 gpmc_nor[GPMC_MAX_REG] = { STNOR_GPMC_CONFIG1,
397 STNOR_GPMC_CONFIG2, STNOR_GPMC_CONFIG3, STNOR_GPMC_CONFIG4,
398 STNOR_GPMC_CONFIG5, STNOR_GPMC_CONFIG6, STNOR_GPMC_CONFIG7 };
401 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
406 /* Reconfigure CS0 for NOR instead of NAND. */
407 enable_gpmc_cs_config(gpmc_nor, &gpmc_cfg->cs[0],
408 CONFIG_SYS_FLASH_BASE, GPMC_SIZE_16M);
414 #ifdef CONFIG_BOARD_LATE_INIT
415 int board_late_init(void)
417 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
418 char safe_string[HDR_NAME_LEN + 1];
419 struct am335x_baseboard_id header;
421 if (read_eeprom(&header) < 0)
422 puts("Could not get board ID.\n");
424 /* Now set variables based on the header. */
425 strncpy(safe_string, (char *)header.name, sizeof(header.name));
426 safe_string[sizeof(header.name)] = 0;
427 setenv("board_name", safe_string);
429 strncpy(safe_string, (char *)header.version, sizeof(header.version));
430 safe_string[sizeof(header.version)] = 0;
431 setenv("board_rev", safe_string);
438 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
439 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
440 static void cpsw_control(int enabled)
442 /* VTP can be added here */
447 static struct cpsw_slave_data cpsw_slaves[] = {
449 .slave_reg_ofs = 0x208,
450 .sliver_reg_ofs = 0xd80,
454 .slave_reg_ofs = 0x308,
455 .sliver_reg_ofs = 0xdc0,
460 static struct cpsw_platform_data cpsw_data = {
461 .mdio_base = CPSW_MDIO_BASE,
462 .cpsw_base = CPSW_BASE,
465 .cpdma_reg_ofs = 0x800,
467 .slave_data = cpsw_slaves,
468 .ale_reg_ofs = 0xd00,
470 .host_port_reg_ofs = 0x108,
471 .hw_stats_reg_ofs = 0x900,
472 .bd_ram_ofs = 0x2000,
473 .mac_control = (1 << 5),
474 .control = cpsw_control,
476 .version = CPSW_CTRL_VERSION_2,
480 #if defined(CONFIG_DRIVER_TI_CPSW) || \
481 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
482 int board_eth_init(bd_t *bis)
486 uint32_t mac_hi, mac_lo;
487 __maybe_unused struct am335x_baseboard_id header;
489 /* try reading mac address from efuse */
490 mac_lo = readl(&cdev->macid0l);
491 mac_hi = readl(&cdev->macid0h);
492 mac_addr[0] = mac_hi & 0xFF;
493 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
494 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
495 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
496 mac_addr[4] = mac_lo & 0xFF;
497 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
499 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
500 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
501 if (!getenv("ethaddr")) {
502 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
504 if (is_valid_ether_addr(mac_addr))
505 eth_setenv_enetaddr("ethaddr", mac_addr);
508 #ifdef CONFIG_DRIVER_TI_CPSW
509 if (read_eeprom(&header) < 0)
510 puts("Could not get board ID.\n");
512 if (board_is_bone(&header) || board_is_bone_lt(&header) ||
513 board_is_idk(&header)) {
514 writel(MII_MODE_ENABLE, &cdev->miisel);
515 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
516 PHY_INTERFACE_MODE_MII;
518 writel(RGMII_MODE_ENABLE, &cdev->miisel);
519 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
520 PHY_INTERFACE_MODE_RGMII;
523 rv = cpsw_register(&cpsw_data);
525 printf("Error %d registering CPSW switch\n", rv);
532 * CPSW RGMII Internal Delay Mode is not supported in all PVT
533 * operating points. So we must set the TX clock delay feature
534 * in the AR8051 PHY. Since we only support a single ethernet
535 * device in U-Boot, we only do this for the first instance.
537 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
538 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
539 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
540 #define AR8051_RGMII_TX_CLK_DLY 0x100
542 if (board_is_evm_sk(&header) || board_is_gp_evm(&header)) {
544 devname = miiphy_get_current_dev();
546 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
547 AR8051_DEBUG_RGMII_CLK_DLY_REG);
548 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
549 AR8051_RGMII_TX_CLK_DLY);
552 #if defined(CONFIG_USB_ETHER) && \
553 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
554 if (is_valid_ether_addr(mac_addr))
555 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
557 rv = usb_eth_initialize(bis);
559 printf("Error %d registering USB_ETHER\n", rv);