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 0xA
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);
77 * Read header information from EEPROM into global structure.
79 static int read_eeprom(void)
81 /* Check if baseboard eeprom is available */
82 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
83 puts("Could not probe the EEPROM; something fundamentally "
84 "wrong on the I2C bus.\n");
88 /* read the eeprom using i2c */
89 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
91 puts("Could not read the EEPROM; something fundamentally"
92 " wrong on the I2C bus.\n");
96 if (header.magic != 0xEE3355AA) {
98 * read the eeprom using i2c again,
99 * but use only a 1 byte address
101 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
102 (uchar *)&header, sizeof(header))) {
103 puts("Could not read the EEPROM; something "
104 "fundamentally wrong on the I2C bus.\n");
108 if (header.magic != 0xEE3355AA) {
109 printf("Incorrect magic number (0x%x) in EEPROM\n",
119 #ifdef CONFIG_SPL_BUILD
120 #define UART_RESET (0x1 << 1)
121 #define UART_CLK_RUNNING_MASK 0x1
122 #define UART_SMART_IDLE_EN (0x1 << 0x3)
124 static void rtc32k_enable(void)
126 struct rtc_regs *rtc = (struct rtc_regs *)AM335X_RTC_BASE;
129 * Unlock the RTC's registers. For more details please see the
130 * RTC_SS section of the TRM. In order to unlock we need to
131 * write these specific values (keys) in this order.
133 writel(0x83e70b13, &rtc->kick0r);
134 writel(0x95a4f1e0, &rtc->kick1r);
136 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
137 writel((1 << 3) | (1 << 6), &rtc->osc);
140 static const struct ddr_data ddr2_data = {
141 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
142 (MT47H128M16RT25E_RD_DQS<<20) |
143 (MT47H128M16RT25E_RD_DQS<<10) |
144 (MT47H128M16RT25E_RD_DQS<<0)),
145 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
146 (MT47H128M16RT25E_WR_DQS<<20) |
147 (MT47H128M16RT25E_WR_DQS<<10) |
148 (MT47H128M16RT25E_WR_DQS<<0)),
149 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
150 (MT47H128M16RT25E_PHY_WRLVL<<20) |
151 (MT47H128M16RT25E_PHY_WRLVL<<10) |
152 (MT47H128M16RT25E_PHY_WRLVL<<0)),
153 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
154 (MT47H128M16RT25E_PHY_GATELVL<<20) |
155 (MT47H128M16RT25E_PHY_GATELVL<<10) |
156 (MT47H128M16RT25E_PHY_GATELVL<<0)),
157 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
158 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
159 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
160 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
161 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
162 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
163 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
164 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
165 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
166 .datadldiff0 = PHY_DLL_LOCK_DIFF,
169 static const struct cmd_control ddr2_cmd_ctrl_data = {
170 .cmd0csratio = MT47H128M16RT25E_RATIO,
171 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
172 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
174 .cmd1csratio = MT47H128M16RT25E_RATIO,
175 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
176 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
178 .cmd2csratio = MT47H128M16RT25E_RATIO,
179 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
180 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
183 static const struct emif_regs ddr2_emif_reg_data = {
184 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
185 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
186 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
187 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
188 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
189 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
192 static const struct ddr_data ddr3_data = {
193 .datardsratio0 = MT41J128MJT125_RD_DQS,
194 .datawdsratio0 = MT41J128MJT125_WR_DQS,
195 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
196 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
197 .datadldiff0 = PHY_DLL_LOCK_DIFF,
200 static const struct cmd_control ddr3_cmd_ctrl_data = {
201 .cmd0csratio = MT41J128MJT125_RATIO,
202 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
203 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
205 .cmd1csratio = MT41J128MJT125_RATIO,
206 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
207 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
209 .cmd2csratio = MT41J128MJT125_RATIO,
210 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
211 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
214 static struct emif_regs ddr3_emif_reg_data = {
215 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
216 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
217 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
218 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
219 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
220 .zq_config = MT41J128MJT125_ZQ_CFG,
221 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY,
226 * early system init of muxing and clocks.
230 /* WDT1 is already running when the bootloader gets control
231 * Disable it to avoid "random" resets
233 writel(0xAAAA, &wdtimer->wdtwspr);
234 while (readl(&wdtimer->wdtwwps) != 0x0)
236 writel(0x5555, &wdtimer->wdtwspr);
237 while (readl(&wdtimer->wdtwwps) != 0x0)
240 #ifdef CONFIG_SPL_BUILD
241 /* Setup the PLLs and the clocks for the peripherals */
244 /* Enable RTC32K clock */
250 #ifdef CONFIG_SERIAL1
251 enable_uart0_pin_mux();
252 #endif /* CONFIG_SERIAL1 */
253 #ifdef CONFIG_SERIAL2
254 enable_uart1_pin_mux();
255 #endif /* CONFIG_SERIAL2 */
256 #ifdef CONFIG_SERIAL3
257 enable_uart2_pin_mux();
258 #endif /* CONFIG_SERIAL3 */
259 #ifdef CONFIG_SERIAL4
260 enable_uart3_pin_mux();
261 #endif /* CONFIG_SERIAL4 */
262 #ifdef CONFIG_SERIAL5
263 enable_uart4_pin_mux();
264 #endif /* CONFIG_SERIAL5 */
265 #ifdef CONFIG_SERIAL6
266 enable_uart5_pin_mux();
267 #endif /* CONFIG_SERIAL6 */
269 regVal = readl(&uart_base->uartsyscfg);
270 regVal |= UART_RESET;
271 writel(regVal, &uart_base->uartsyscfg);
272 while ((readl(&uart_base->uartsyssts) &
273 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
276 /* Disable smart idle */
277 regVal = readl(&uart_base->uartsyscfg);
278 regVal |= UART_SMART_IDLE_EN;
279 writel(regVal, &uart_base->uartsyscfg);
283 preloader_console_init();
285 /* Initalize the board header */
286 enable_i2c0_pin_mux();
287 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
288 if (read_eeprom() < 0)
289 puts("Could not get board ID.\n");
291 enable_board_pin_mux(&header);
292 if (board_is_evm_sk()) {
294 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
295 * This is safe enough to do on older revs.
297 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
298 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
301 if (board_is_evm_sk() || board_is_bone_lt())
302 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
303 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data);
305 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
306 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data);
311 * Basic board specific setup. Pinmux has been handled already.
315 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
316 if (read_eeprom() < 0)
317 puts("Could not get board ID.\n");
319 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
324 #ifdef CONFIG_DRIVER_TI_CPSW
325 static void cpsw_control(int enabled)
327 /* VTP can be added here */
332 static struct cpsw_slave_data cpsw_slaves[] = {
334 .slave_reg_ofs = 0x208,
335 .sliver_reg_ofs = 0xd80,
339 .slave_reg_ofs = 0x308,
340 .sliver_reg_ofs = 0xdc0,
345 static struct cpsw_platform_data cpsw_data = {
346 .mdio_base = AM335X_CPSW_MDIO_BASE,
347 .cpsw_base = AM335X_CPSW_BASE,
350 .cpdma_reg_ofs = 0x800,
352 .slave_data = cpsw_slaves,
353 .ale_reg_ofs = 0xd00,
355 .host_port_reg_ofs = 0x108,
356 .hw_stats_reg_ofs = 0x900,
357 .mac_control = (1 << 5),
358 .control = cpsw_control,
360 .version = CPSW_CTRL_VERSION_2,
363 int board_eth_init(bd_t *bis)
366 uint32_t mac_hi, mac_lo;
368 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
369 debug("<ethaddr> not set. Reading from E-fuse\n");
370 /* try reading mac address from efuse */
371 mac_lo = readl(&cdev->macid0l);
372 mac_hi = readl(&cdev->macid0h);
373 mac_addr[0] = mac_hi & 0xFF;
374 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
375 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
376 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
377 mac_addr[4] = mac_lo & 0xFF;
378 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
380 if (is_valid_ether_addr(mac_addr))
381 eth_setenv_enetaddr("ethaddr", mac_addr);
386 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
387 writel(MII_MODE_ENABLE, &cdev->miisel);
388 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
389 PHY_INTERFACE_MODE_MII;
391 writel(RGMII_MODE_ENABLE, &cdev->miisel);
392 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
393 PHY_INTERFACE_MODE_RGMII;
396 return cpsw_register(&cpsw_data);