blob: 0f16021c201f9832b0782367efc00a4c81c65382 [file] [log] [blame]
Chandan Nath5289e832011-10-14 02:58:26 +00001/*
2 * board.c
3 *
4 * Common board functions for AM33XX based boards
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
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.
12 *
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.
17 */
18
19#include <common.h>
Tom Rini973b6632012-07-30 16:13:10 -070020#include <errno.h>
Chandan Nath5289e832011-10-14 02:58:26 +000021#include <asm/arch/cpu.h>
22#include <asm/arch/hardware.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000023#include <asm/arch/omap.h>
Chandan Nath5289e832011-10-14 02:58:26 +000024#include <asm/arch/ddr_defs.h>
25#include <asm/arch/clock.h>
Steve Sakoman3b971522012-06-04 05:35:34 +000026#include <asm/arch/gpio.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000027#include <asm/arch/mmc_host_def.h>
28#include <asm/arch/common_def.h>
Chandan Nath5289e832011-10-14 02:58:26 +000029#include <asm/io.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000030#include <asm/omap_common.h>
Tom Rinifda35eb2012-07-03 08:51:34 -070031#include <asm/emif.h>
Tom Rini65d750b2012-07-31 08:55:01 -070032#include <asm/gpio.h>
Tom Rini973b6632012-07-30 16:13:10 -070033#include <i2c.h>
34#include <miiphy.h>
35#include <cpsw.h>
Chandan Nath5289e832011-10-14 02:58:26 +000036
37DECLARE_GLOBAL_DATA_PTR;
38
39struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
Chandan Nathfb072a32012-01-09 20:38:56 +000040struct gptimer *timer_base = (struct gptimer *)CONFIG_SYS_TIMERBASE;
Chandan Nath8a8f0842012-01-09 20:38:59 +000041struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
42
Steve Sakoman3b971522012-06-04 05:35:34 +000043static const struct gpio_bank gpio_bank_am33xx[4] = {
44 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
45 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
46 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
47 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
48};
49
50const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
51
Tom Rini973b6632012-07-30 16:13:10 -070052/* MII mode defines */
53#define MII_MODE_ENABLE 0x0
54#define RGMII_MODE_ENABLE 0xA
55
Tom Rini65d750b2012-07-31 08:55:01 -070056/* GPIO that controls power to DDR on EVM-SK */
57#define GPIO_DDR_VTT_EN 7
58
Tom Rini973b6632012-07-30 16:13:10 -070059static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
60
Tom Rini973b6632012-07-30 16:13:10 -070061#define NO_OF_MAC_ADDR 3
62#define ETH_ALEN 6
63#define NAME_LEN 8
64
65struct am335x_baseboard_id {
66 unsigned int magic;
67 char name[NAME_LEN];
68 char version[4];
69 char serial[12];
70 char config[32];
71 char mac_addr[NO_OF_MAC_ADDR][ETH_ALEN];
72};
73
Tom Rini65d750b2012-07-31 08:55:01 -070074static struct am335x_baseboard_id __attribute__((section (".data"))) header;
Tom Rini973b6632012-07-30 16:13:10 -070075
76static inline int board_is_bone(void)
77{
78 return !strncmp(header.name, "A335BONE", NAME_LEN);
79}
80
Tom Rini65d750b2012-07-31 08:55:01 -070081static inline int board_is_evm_sk(void)
82{
83 return !strncmp("A335X_SK", header.name, NAME_LEN);
84}
85
Tom Rini973b6632012-07-30 16:13:10 -070086/*
87 * Read header information from EEPROM into global structure.
88 */
89static int read_eeprom(void)
90{
91 /* Check if baseboard eeprom is available */
Tom Rini726c05d2012-07-31 09:37:08 -070092 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
Tom Rini973b6632012-07-30 16:13:10 -070093 puts("Could not probe the EEPROM; something fundamentally "
94 "wrong on the I2C bus.\n");
95 return -ENODEV;
96 }
97
98 /* read the eeprom using i2c */
Tom Rini726c05d2012-07-31 09:37:08 -070099 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
Tom Rini973b6632012-07-30 16:13:10 -0700100 sizeof(header))) {
101 puts("Could not read the EEPROM; something fundamentally"
102 " wrong on the I2C bus.\n");
103 return -EIO;
104 }
105
106 if (header.magic != 0xEE3355AA) {
107 /*
108 * read the eeprom using i2c again,
109 * but use only a 1 byte address
110 */
Tom Rini726c05d2012-07-31 09:37:08 -0700111 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
112 (uchar *)&header, sizeof(header))) {
Tom Rini973b6632012-07-30 16:13:10 -0700113 puts("Could not read the EEPROM; something "
114 "fundamentally wrong on the I2C bus.\n");
115 return -EIO;
116 }
117
118 if (header.magic != 0xEE3355AA) {
119 printf("Incorrect magic number (0x%x) in EEPROM\n",
120 header.magic);
121 return -EINVAL;
122 }
123 }
124
125 return 0;
126}
127
Chandan Nath8a8f0842012-01-09 20:38:59 +0000128/* UART Defines */
129#ifdef CONFIG_SPL_BUILD
130#define UART_RESET (0x1 << 1)
131#define UART_CLK_RUNNING_MASK 0x1
132#define UART_SMART_IDLE_EN (0x1 << 0x3)
133#endif
Chandan Nath5289e832011-10-14 02:58:26 +0000134
Tom Rini2ab28102012-05-14 12:38:18 +0000135#ifdef CONFIG_SPL_BUILD
136/* Initialize timer */
137static void init_timer(void)
138{
139 /* Reset the Timer */
140 writel(0x2, (&timer_base->tscir));
141
142 /* Wait until the reset is done */
143 while (readl(&timer_base->tiocp_cfg) & 1)
144 ;
145
146 /* Start the Timer */
147 writel(0x1, (&timer_base->tclr));
148}
149#endif
150
Chandan Nath5289e832011-10-14 02:58:26 +0000151/*
Tom Rini65d750b2012-07-31 08:55:01 -0700152 * Determine what type of DDR we have.
153 */
154static short inline board_memory_type(void)
155{
156 /* The following boards are known to use DDR3. */
157 if (board_is_evm_sk())
158 return EMIF_REG_SDRAM_TYPE_DDR3;
159
160 return EMIF_REG_SDRAM_TYPE_DDR2;
161}
162
163/*
Chandan Nath5289e832011-10-14 02:58:26 +0000164 * early system init of muxing and clocks.
165 */
Chandan Nath8a8f0842012-01-09 20:38:59 +0000166void s_init(void)
Chandan Nath5289e832011-10-14 02:58:26 +0000167{
168 /* WDT1 is already running when the bootloader gets control
169 * Disable it to avoid "random" resets
170 */
171 writel(0xAAAA, &wdtimer->wdtwspr);
172 while (readl(&wdtimer->wdtwwps) != 0x0)
173 ;
174 writel(0x5555, &wdtimer->wdtwspr);
175 while (readl(&wdtimer->wdtwwps) != 0x0)
176 ;
177
Chandan Nath8a8f0842012-01-09 20:38:59 +0000178#ifdef CONFIG_SPL_BUILD
Chandan Nath5289e832011-10-14 02:58:26 +0000179 /* Setup the PLLs and the clocks for the peripherals */
Chandan Nath5289e832011-10-14 02:58:26 +0000180 pll_init();
Chandan Nath8a8f0842012-01-09 20:38:59 +0000181
182 /* UART softreset */
183 u32 regVal;
184
185 enable_uart0_pin_mux();
186
187 regVal = readl(&uart_base->uartsyscfg);
188 regVal |= UART_RESET;
189 writel(regVal, &uart_base->uartsyscfg);
190 while ((readl(&uart_base->uartsyssts) &
191 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
192 ;
193
194 /* Disable smart idle */
195 regVal = readl(&uart_base->uartsyscfg);
196 regVal |= UART_SMART_IDLE_EN;
197 writel(regVal, &uart_base->uartsyscfg);
198
199 /* Initialize the Timer */
200 init_timer();
201
202 preloader_console_init();
203
Tom Rini65d750b2012-07-31 08:55:01 -0700204 /* Initalize the board header */
205 enable_i2c0_pin_mux();
206 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
207 if (read_eeprom() < 0)
208 puts("Could not get board ID.\n");
209
210 if (board_is_evm_sk()) {
211 /*
212 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
213 * This is safe enough to do on older revs.
214 */
215 enable_gpio0_7_pin_mux();
216 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
217 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
218 }
219
220 config_ddr(board_memory_type());
Chandan Nath5289e832011-10-14 02:58:26 +0000221#endif
Chandan Nath8a8f0842012-01-09 20:38:59 +0000222
223 /* Enable MMC0 */
224 enable_mmc0_pin_mux();
Chandan Nath5289e832011-10-14 02:58:26 +0000225}
226
Chandan Nath876bdd62012-01-09 20:38:58 +0000227#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
228int board_mmc_init(bd_t *bis)
229{
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +0000230 return omap_mmc_init(0, 0, 0);
Chandan Nath876bdd62012-01-09 20:38:58 +0000231}
232#endif
Chandan Nath8a8f0842012-01-09 20:38:59 +0000233
234void setup_clocks_for_console(void)
235{
236 /* Not yet implemented */
237 return;
238}
Tom Rini973b6632012-07-30 16:13:10 -0700239
240/*
241 * Basic board specific setup
242 */
243int board_init(void)
244{
245 enable_uart0_pin_mux();
246
247 enable_i2c0_pin_mux();
248 enable_i2c1_pin_mux();
249 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
250 if (read_eeprom() < 0)
251 puts("Could not get board ID.\n");
252
253 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
254
255 return 0;
256}
257
258#ifdef CONFIG_DRIVER_TI_CPSW
259static void cpsw_control(int enabled)
260{
261 /* VTP can be added here */
262
263 return;
264}
265
266static struct cpsw_slave_data cpsw_slaves[] = {
267 {
268 .slave_reg_ofs = 0x208,
269 .sliver_reg_ofs = 0xd80,
270 .phy_id = 0,
271 },
272 {
273 .slave_reg_ofs = 0x308,
274 .sliver_reg_ofs = 0xdc0,
275 .phy_id = 1,
276 },
277};
278
279static struct cpsw_platform_data cpsw_data = {
280 .mdio_base = AM335X_CPSW_MDIO_BASE,
281 .cpsw_base = AM335X_CPSW_BASE,
282 .mdio_div = 0xff,
283 .channels = 8,
284 .cpdma_reg_ofs = 0x800,
285 .slaves = 1,
286 .slave_data = cpsw_slaves,
287 .ale_reg_ofs = 0xd00,
288 .ale_entries = 1024,
289 .host_port_reg_ofs = 0x108,
290 .hw_stats_reg_ofs = 0x900,
291 .mac_control = (1 << 5),
292 .control = cpsw_control,
293 .host_port_num = 0,
294 .version = CPSW_CTRL_VERSION_2,
295};
296
297int board_eth_init(bd_t *bis)
298{
299 uint8_t mac_addr[6];
300 uint32_t mac_hi, mac_lo;
301
302 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
303 debug("<ethaddr> not set. Reading from E-fuse\n");
304 /* try reading mac address from efuse */
305 mac_lo = readl(&cdev->macid0l);
306 mac_hi = readl(&cdev->macid0h);
307 mac_addr[0] = mac_hi & 0xFF;
308 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
309 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
310 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
311 mac_addr[4] = mac_lo & 0xFF;
312 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
313
314 if (is_valid_ether_addr(mac_addr))
315 eth_setenv_enetaddr("ethaddr", mac_addr);
316 else
317 return -1;
318 }
319
320 if (board_is_bone()) {
321 enable_mii1_pin_mux();
322 writel(MII_MODE_ENABLE, &cdev->miisel);
323 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
324 PHY_INTERFACE_MODE_MII;
325 } else {
326 enable_rgmii1_pin_mux();
327 writel(RGMII_MODE_ENABLE, &cdev->miisel);
328 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
329 PHY_INTERFACE_MODE_RGMII;
330 }
331
332 return cpsw_register(&cpsw_data);
333}
334#endif