]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/am33xx/board.c
772203fe5b128bc7e6a929adbff7f7005c85f239
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / am33xx / board.c
1 /*
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>
20 #include <errno.h>
21 #include <spl.h>
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>
30 #include <asm/io.h>
31 #include <asm/emif.h>
32 #include <asm/gpio.h>
33 #include <i2c.h>
34 #include <miiphy.h>
35 #include <cpsw.h>
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
40 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
41
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 },
47 };
48
49 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
50
51 /* MII mode defines */
52 #define MII_MODE_ENABLE         0x0
53 #define RGMII_MODE_ENABLE       0xA
54
55 /* GPIO that controls power to DDR on EVM-SK */
56 #define GPIO_DDR_VTT_EN         7
57
58 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
59
60 static struct am335x_baseboard_id __attribute__((section (".data"))) header;
61
62 static inline int board_is_bone(void)
63 {
64         return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
65 }
66
67 static inline int board_is_bone_lt(void)
68 {
69         return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
70 }
71
72 static inline int board_is_evm_sk(void)
73 {
74         return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
75 }
76
77 /*
78  * Read header information from EEPROM into global structure.
79  */
80 static int read_eeprom(void)
81 {
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");
86                 return -ENODEV;
87         }
88
89         /* read the eeprom using i2c */
90         if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
91                                                         sizeof(header))) {
92                 puts("Could not read the EEPROM; something fundamentally"
93                         " wrong on the I2C bus.\n");
94                 return -EIO;
95         }
96
97         if (header.magic != 0xEE3355AA) {
98                 /*
99                  * read the eeprom using i2c again,
100                  * but use only a 1 byte address
101                  */
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");
106                         return -EIO;
107                 }
108
109                 if (header.magic != 0xEE3355AA) {
110                         printf("Incorrect magic number (0x%x) in EEPROM\n",
111                                         header.magic);
112                         return -EINVAL;
113                 }
114         }
115
116         return 0;
117 }
118
119 #ifdef CONFIG_SPL_BUILD
120 /* UART Defines */
121 #define UART_RESET              (0x1 << 1)
122 #define UART_CLK_RUNNING_MASK   0x1
123 #define UART_SMART_IDLE_EN      (0x1 << 0x3)
124
125 static void rtc32k_enable(void)
126 {
127         struct rtc_regs *rtc = (struct rtc_regs *)AM335X_RTC_BASE;
128
129         /*
130          * Unlock the RTC's registers.  For more details please see the
131          * RTC_SS section of the TRM.  In order to unlock we need to
132          * write these specific values (keys) in this order.
133          */
134         writel(0x83e70b13, &rtc->kick0r);
135         writel(0x95a4f1e0, &rtc->kick1r);
136
137         /* Enable the RTC 32K OSC by setting bits 3 and 6. */
138         writel((1 << 3) | (1 << 6), &rtc->osc);
139 }
140 #endif
141
142 /*
143  * Determine what type of DDR we have.
144  */
145 static short inline board_memory_type(void)
146 {
147         /* The following boards are known to use DDR3. */
148         if (board_is_evm_sk() || board_is_bone_lt())
149                 return EMIF_REG_SDRAM_TYPE_DDR3;
150
151         return EMIF_REG_SDRAM_TYPE_DDR2;
152 }
153
154 /*
155  * early system init of muxing and clocks.
156  */
157 void s_init(void)
158 {
159         /* WDT1 is already running when the bootloader gets control
160          * Disable it to avoid "random" resets
161          */
162         writel(0xAAAA, &wdtimer->wdtwspr);
163         while (readl(&wdtimer->wdtwwps) != 0x0)
164                 ;
165         writel(0x5555, &wdtimer->wdtwspr);
166         while (readl(&wdtimer->wdtwwps) != 0x0)
167                 ;
168
169 #ifdef CONFIG_SPL_BUILD
170         /* Setup the PLLs and the clocks for the peripherals */
171         pll_init();
172
173         /* Enable RTC32K clock */
174         rtc32k_enable();
175
176         /* UART softreset */
177         u32 regVal;
178
179         enable_uart0_pin_mux();
180
181         regVal = readl(&uart_base->uartsyscfg);
182         regVal |= UART_RESET;
183         writel(regVal, &uart_base->uartsyscfg);
184         while ((readl(&uart_base->uartsyssts) &
185                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
186                 ;
187
188         /* Disable smart idle */
189         regVal = readl(&uart_base->uartsyscfg);
190         regVal |= UART_SMART_IDLE_EN;
191         writel(regVal, &uart_base->uartsyscfg);
192
193         gd = &gdata;
194
195         preloader_console_init();
196
197         /* Initalize the board header */
198         enable_i2c0_pin_mux();
199         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
200         if (read_eeprom() < 0)
201                 puts("Could not get board ID.\n");
202
203         enable_board_pin_mux(&header);
204         if (board_is_evm_sk()) {
205                 /*
206                  * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
207                  * This is safe enough to do on older revs.
208                  */
209                 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
210                 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
211         }
212
213         config_ddr(board_memory_type());
214 #endif
215 }
216
217 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
218 int board_mmc_init(bd_t *bis)
219 {
220         int ret;
221         
222         ret = omap_mmc_init(0, 0, 0);
223         if (ret)
224                 return ret;
225
226         return omap_mmc_init(1, 0, 0);
227 }
228 #endif
229
230 void setup_clocks_for_console(void)
231 {
232         /* Not yet implemented */
233         return;
234 }
235
236 /*
237  * Basic board specific setup.  Pinmux has been handled already.
238  */
239 int board_init(void)
240 {
241         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
242         if (read_eeprom() < 0)
243                 puts("Could not get board ID.\n");
244
245         gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
246
247         return 0;
248 }
249
250 #ifdef CONFIG_DRIVER_TI_CPSW
251 static void cpsw_control(int enabled)
252 {
253         /* VTP can be added here */
254
255         return;
256 }
257
258 static struct cpsw_slave_data cpsw_slaves[] = {
259         {
260                 .slave_reg_ofs  = 0x208,
261                 .sliver_reg_ofs = 0xd80,
262                 .phy_id         = 0,
263         },
264         {
265                 .slave_reg_ofs  = 0x308,
266                 .sliver_reg_ofs = 0xdc0,
267                 .phy_id         = 1,
268         },
269 };
270
271 static struct cpsw_platform_data cpsw_data = {
272         .mdio_base              = AM335X_CPSW_MDIO_BASE,
273         .cpsw_base              = AM335X_CPSW_BASE,
274         .mdio_div               = 0xff,
275         .channels               = 8,
276         .cpdma_reg_ofs          = 0x800,
277         .slaves                 = 1,
278         .slave_data             = cpsw_slaves,
279         .ale_reg_ofs            = 0xd00,
280         .ale_entries            = 1024,
281         .host_port_reg_ofs      = 0x108,
282         .hw_stats_reg_ofs       = 0x900,
283         .mac_control            = (1 << 5),
284         .control                = cpsw_control,
285         .host_port_num          = 0,
286         .version                = CPSW_CTRL_VERSION_2,
287 };
288
289 int board_eth_init(bd_t *bis)
290 {
291         uint8_t mac_addr[6];
292         uint32_t mac_hi, mac_lo;
293
294         if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
295                 debug("<ethaddr> not set. Reading from E-fuse\n");
296                 /* try reading mac address from efuse */
297                 mac_lo = readl(&cdev->macid0l);
298                 mac_hi = readl(&cdev->macid0h);
299                 mac_addr[0] = mac_hi & 0xFF;
300                 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
301                 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
302                 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
303                 mac_addr[4] = mac_lo & 0xFF;
304                 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
305
306                 if (is_valid_ether_addr(mac_addr))
307                         eth_setenv_enetaddr("ethaddr", mac_addr);
308                 else
309                         return -1;
310         }
311
312         if (board_is_bone() || board_is_bone_lt()) {
313                 writel(MII_MODE_ENABLE, &cdev->miisel);
314                 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
315                                 PHY_INTERFACE_MODE_MII;
316         } else {
317                 writel(RGMII_MODE_ENABLE, &cdev->miisel);
318                 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
319                                 PHY_INTERFACE_MODE_RGMII;
320         }
321
322         return cpsw_register(&cpsw_data);
323 }
324 #endif