4 * Common board functions for AM33XX 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>
37 DECLARE_GLOBAL_DATA_PTR;
39 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
40 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
42 static const struct gpio_bank gpio_bank_am33xx[4] = {
43 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
44 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
45 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
46 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
49 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
51 /* MII mode defines */
52 #define MII_MODE_ENABLE 0x0
53 #define RGMII_MODE_ENABLE 0xA
55 /* GPIO that controls power to DDR on EVM-SK */
56 #define GPIO_DDR_VTT_EN 7
58 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
60 static struct am335x_baseboard_id __attribute__((section (".data"))) header;
62 static inline int board_is_bone(void)
64 return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
67 static inline int board_is_bone_lt(void)
69 return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
72 static inline int board_is_evm_sk(void)
74 return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
78 * Read header information from EEPROM into global structure.
80 static int read_eeprom(void)
82 /* Check if baseboard eeprom is available */
83 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
84 puts("Could not probe the EEPROM; something fundamentally "
85 "wrong on the I2C bus.\n");
89 /* read the eeprom using i2c */
90 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
92 puts("Could not read the EEPROM; something fundamentally"
93 " wrong on the I2C bus.\n");
97 if (header.magic != 0xEE3355AA) {
99 * read the eeprom using i2c again,
100 * but use only a 1 byte address
102 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
103 (uchar *)&header, sizeof(header))) {
104 puts("Could not read the EEPROM; something "
105 "fundamentally wrong on the I2C bus.\n");
109 if (header.magic != 0xEE3355AA) {
110 printf("Incorrect magic number (0x%x) in EEPROM\n",
120 #ifdef CONFIG_SPL_BUILD
121 #define UART_RESET (0x1 << 1)
122 #define UART_CLK_RUNNING_MASK 0x1
123 #define UART_SMART_IDLE_EN (0x1 << 0x3)
127 * Determine what type of DDR we have.
129 static short inline board_memory_type(void)
131 /* The following boards are known to use DDR3. */
132 if (board_is_evm_sk() || board_is_bone_lt())
133 return EMIF_REG_SDRAM_TYPE_DDR3;
135 return EMIF_REG_SDRAM_TYPE_DDR2;
139 * early system init of muxing and clocks.
143 /* WDT1 is already running when the bootloader gets control
144 * Disable it to avoid "random" resets
146 writel(0xAAAA, &wdtimer->wdtwspr);
147 while (readl(&wdtimer->wdtwwps) != 0x0)
149 writel(0x5555, &wdtimer->wdtwspr);
150 while (readl(&wdtimer->wdtwwps) != 0x0)
153 #ifdef CONFIG_SPL_BUILD
154 /* Setup the PLLs and the clocks for the peripherals */
160 enable_uart0_pin_mux();
162 regVal = readl(&uart_base->uartsyscfg);
163 regVal |= UART_RESET;
164 writel(regVal, &uart_base->uartsyscfg);
165 while ((readl(&uart_base->uartsyssts) &
166 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
169 /* Disable smart idle */
170 regVal = readl(&uart_base->uartsyscfg);
171 regVal |= UART_SMART_IDLE_EN;
172 writel(regVal, &uart_base->uartsyscfg);
176 preloader_console_init();
178 /* Initalize the board header */
179 enable_i2c0_pin_mux();
180 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
181 if (read_eeprom() < 0)
182 puts("Could not get board ID.\n");
184 enable_board_pin_mux(&header);
185 if (board_is_evm_sk()) {
187 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
188 * This is safe enough to do on older revs.
190 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
191 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
194 config_ddr(board_memory_type());
198 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
199 int board_mmc_init(bd_t *bis)
203 ret = omap_mmc_init(0, 0, 0);
207 return omap_mmc_init(1, 0, 0);
211 void setup_clocks_for_console(void)
213 /* Not yet implemented */
218 * Basic board specific setup. Pinmux has been handled already.
222 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
223 if (read_eeprom() < 0)
224 puts("Could not get board ID.\n");
226 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
231 #ifdef CONFIG_DRIVER_TI_CPSW
232 static void cpsw_control(int enabled)
234 /* VTP can be added here */
239 static struct cpsw_slave_data cpsw_slaves[] = {
241 .slave_reg_ofs = 0x208,
242 .sliver_reg_ofs = 0xd80,
246 .slave_reg_ofs = 0x308,
247 .sliver_reg_ofs = 0xdc0,
252 static struct cpsw_platform_data cpsw_data = {
253 .mdio_base = AM335X_CPSW_MDIO_BASE,
254 .cpsw_base = AM335X_CPSW_BASE,
257 .cpdma_reg_ofs = 0x800,
259 .slave_data = cpsw_slaves,
260 .ale_reg_ofs = 0xd00,
262 .host_port_reg_ofs = 0x108,
263 .hw_stats_reg_ofs = 0x900,
264 .mac_control = (1 << 5),
265 .control = cpsw_control,
267 .version = CPSW_CTRL_VERSION_2,
270 int board_eth_init(bd_t *bis)
273 uint32_t mac_hi, mac_lo;
275 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
276 debug("<ethaddr> not set. Reading from E-fuse\n");
277 /* try reading mac address from efuse */
278 mac_lo = readl(&cdev->macid0l);
279 mac_hi = readl(&cdev->macid0h);
280 mac_addr[0] = mac_hi & 0xFF;
281 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
282 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
283 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
284 mac_addr[4] = mac_lo & 0xFF;
285 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
287 if (is_valid_ether_addr(mac_addr))
288 eth_setenv_enetaddr("ethaddr", mac_addr);
293 if (board_is_bone() || board_is_bone_lt()) {
294 writel(MII_MODE_ENABLE, &cdev->miisel);
295 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
296 PHY_INTERFACE_MODE_MII;
298 writel(RGMII_MODE_ENABLE, &cdev->miisel);
299 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
300 PHY_INTERFACE_MODE_RGMII;
303 return cpsw_register(&cpsw_data);