]> git.sur5r.net Git - u-boot/blob - board/davinci/da8xxevm/da850evm.c
da850: add NOR boot mode support
[u-boot] / board / davinci / da8xxevm / da850evm.c
1 /*
2  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Based on da830evm.c. Original Copyrights follow:
5  *
6  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
7  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include <common.h>
25 #include <i2c.h>
26 #include <net.h>
27 #include <netdev.h>
28 #include <asm/arch/hardware.h>
29 #include <asm/arch/emif_defs.h>
30 #include <asm/arch/emac_defs.h>
31 #include <asm/io.h>
32 #include <asm/arch/davinci_misc.h>
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 #define pinmux(x)       (&davinci_syscfg_regs->pinmux[x])
37
38 /* SPI0 pin muxer settings */
39 static const struct pinmux_config spi1_pins[] = {
40         { pinmux(5), 1, 1 },
41         { pinmux(5), 1, 2 },
42         { pinmux(5), 1, 4 },
43         { pinmux(5), 1, 5 }
44 };
45
46 /* UART pin muxer settings */
47 static const struct pinmux_config uart_pins[] = {
48         { pinmux(0), 4, 6 },
49         { pinmux(0), 4, 7 },
50         { pinmux(4), 2, 4 },
51         { pinmux(4), 2, 5 }
52 };
53
54 #ifdef CONFIG_DRIVER_TI_EMAC
55 static const struct pinmux_config emac_pins[] = {
56 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
57         { pinmux(14), 8, 2 },
58         { pinmux(14), 8, 3 },
59         { pinmux(14), 8, 4 },
60         { pinmux(14), 8, 5 },
61         { pinmux(14), 8, 6 },
62         { pinmux(14), 8, 7 },
63         { pinmux(15), 8, 1 },
64 #else /* ! CONFIG_DRIVER_TI_EMAC_USE_RMII */
65         { pinmux(2), 8, 1 },
66         { pinmux(2), 8, 2 },
67         { pinmux(2), 8, 3 },
68         { pinmux(2), 8, 4 },
69         { pinmux(2), 8, 5 },
70         { pinmux(2), 8, 6 },
71         { pinmux(2), 8, 7 },
72         { pinmux(3), 8, 0 },
73         { pinmux(3), 8, 1 },
74         { pinmux(3), 8, 2 },
75         { pinmux(3), 8, 3 },
76         { pinmux(3), 8, 4 },
77         { pinmux(3), 8, 5 },
78         { pinmux(3), 8, 6 },
79         { pinmux(3), 8, 7 },
80 #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
81         { pinmux(4), 8, 0 },
82         { pinmux(4), 8, 1 }
83 };
84
85 /* I2C pin muxer settings */
86 static const struct pinmux_config i2c_pins[] = {
87         { pinmux(4), 2, 2 },
88         { pinmux(4), 2, 3 }
89 };
90
91 #ifdef CONFIG_NAND_DAVINCI
92 const struct pinmux_config nand_pins[] = {
93         { pinmux(7), 1, 1 },
94         { pinmux(7), 1, 2 },
95         { pinmux(7), 1, 4 },
96         { pinmux(7), 1, 5 },
97         { pinmux(9), 1, 0 },
98         { pinmux(9), 1, 1 },
99         { pinmux(9), 1, 2 },
100         { pinmux(9), 1, 3 },
101         { pinmux(9), 1, 4 },
102         { pinmux(9), 1, 5 },
103         { pinmux(9), 1, 6 },
104         { pinmux(9), 1, 7 },
105         { pinmux(12), 1, 5 },
106         { pinmux(12), 1, 6 }
107 };
108 #elif defined(CONFIG_USE_NOR)
109 /* NOR pin muxer settings */
110 const struct pinmux_config nor_pins[] = {
111         { pinmux(5), 1, 6 },
112         { pinmux(6), 1, 6 },
113         { pinmux(7), 1, 0 },
114         { pinmux(7), 1, 4 },
115         { pinmux(7), 1, 5 },
116         { pinmux(8), 1, 0 },
117         { pinmux(8), 1, 1 },
118         { pinmux(8), 1, 2 },
119         { pinmux(8), 1, 3 },
120         { pinmux(8), 1, 4 },
121         { pinmux(8), 1, 5 },
122         { pinmux(8), 1, 6 },
123         { pinmux(8), 1, 7 },
124         { pinmux(9), 1, 0 },
125         { pinmux(9), 1, 1 },
126         { pinmux(9), 1, 2 },
127         { pinmux(9), 1, 3 },
128         { pinmux(9), 1, 4 },
129         { pinmux(9), 1, 5 },
130         { pinmux(9), 1, 6 },
131         { pinmux(9), 1, 7 },
132         { pinmux(10), 1, 0 },
133         { pinmux(10), 1, 1 },
134         { pinmux(10), 1, 2 },
135         { pinmux(10), 1, 3 },
136         { pinmux(10), 1, 4 },
137         { pinmux(10), 1, 5 },
138         { pinmux(10), 1, 6 },
139         { pinmux(10), 1, 7 },
140         { pinmux(11), 1, 0 },
141         { pinmux(11), 1, 1 },
142         { pinmux(11), 1, 2 },
143         { pinmux(11), 1, 3 },
144         { pinmux(11), 1, 4 },
145         { pinmux(11), 1, 5 },
146         { pinmux(11), 1, 6 },
147         { pinmux(11), 1, 7 },
148         { pinmux(12), 1, 0 },
149         { pinmux(12), 1, 1 },
150         { pinmux(12), 1, 2 },
151         { pinmux(12), 1, 3 },
152         { pinmux(12), 1, 4 },
153         { pinmux(12), 1, 5 },
154         { pinmux(12), 1, 6 },
155         { pinmux(12), 1, 7 }
156 };
157 #endif
158
159 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
160 #define HAS_RMII 1
161 #else
162 #define HAS_RMII 0
163 #endif
164 #endif /* CONFIG_DRIVER_TI_EMAC */
165
166 static const struct pinmux_resource pinmuxes[] = {
167 #ifdef CONFIG_SPI_FLASH
168         PINMUX_ITEM(spi1_pins),
169 #endif
170         PINMUX_ITEM(uart_pins),
171         PINMUX_ITEM(i2c_pins),
172 #ifdef CONFIG_NAND_DAVINCI
173         PINMUX_ITEM(nand_pins),
174 #elif defined(CONFIG_USE_NOR)
175         PINMUX_ITEM(nor_pins),
176 #endif
177 };
178
179 static const struct lpsc_resource lpsc[] = {
180         { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
181         { DAVINCI_LPSC_SPI1 },  /* Serial Flash */
182         { DAVINCI_LPSC_EMAC },  /* image download */
183         { DAVINCI_LPSC_UART2 }, /* console */
184         { DAVINCI_LPSC_GPIO },
185 };
186
187 #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
188 #define CONFIG_DA850_EVM_MAX_CPU_CLK    300000000
189 #endif
190
191 /*
192  * get_board_rev() - setup to pass kernel board revision information
193  * Returns:
194  * bit[0-3]     Maximum cpu clock rate supported by onboard SoC
195  *              0000b - 300 MHz
196  *              0001b - 372 MHz
197  *              0010b - 408 MHz
198  *              0011b - 456 MHz
199  */
200 u32 get_board_rev(void)
201 {
202         char *s;
203         u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
204         u32 rev = 0;
205
206         s = getenv("maxcpuclk");
207         if (s)
208                 maxcpuclk = simple_strtoul(s, NULL, 10);
209
210         if (maxcpuclk >= 456000000)
211                 rev = 3;
212         else if (maxcpuclk >= 408000000)
213                 rev = 2;
214         else if (maxcpuclk >= 372000000)
215                 rev = 1;
216
217         return rev;
218 }
219
220 int board_init(void)
221 {
222 #ifndef CONFIG_USE_IRQ
223         irq_init();
224 #endif
225
226
227 #ifdef CONFIG_NAND_DAVINCI
228         /*
229          * NAND CS setup - cycle counts based on da850evm NAND timings in the
230          * Linux kernel @ 25MHz EMIFA
231          */
232         writel((DAVINCI_ABCR_WSETUP(0) |
233                 DAVINCI_ABCR_WSTROBE(1) |
234                 DAVINCI_ABCR_WHOLD(0) |
235                 DAVINCI_ABCR_RSETUP(0) |
236                 DAVINCI_ABCR_RSTROBE(1) |
237                 DAVINCI_ABCR_RHOLD(0) |
238                 DAVINCI_ABCR_TA(1) |
239                 DAVINCI_ABCR_ASIZE_8BIT),
240                &davinci_emif_regs->ab2cr); /* CS3 */
241 #endif
242
243         /* arch number of the board */
244         gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
245
246         /* address of boot parameters */
247         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
248
249         /*
250          * Power on required peripherals
251          * ARM does not have access by default to PSC0 and PSC1
252          * assuming here that the DSP bootloader has set the IOPU
253          * such that PSC access is available to ARM
254          */
255         if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
256                 return 1;
257
258         /* setup the SUSPSRC for ARM to control emulation suspend */
259         writel(readl(&davinci_syscfg_regs->suspsrc) &
260                ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
261                  DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
262                  DAVINCI_SYSCFG_SUSPSRC_UART2),
263                &davinci_syscfg_regs->suspsrc);
264
265         /* configure pinmux settings */
266         if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
267                 return 1;
268
269 #ifdef CONFIG_DRIVER_TI_EMAC
270         if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
271                 return 1;
272
273         davinci_emac_mii_mode_sel(HAS_RMII);
274 #endif /* CONFIG_DRIVER_TI_EMAC */
275
276         /* enable the console UART */
277         writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
278                 DAVINCI_UART_PWREMU_MGMT_UTRST),
279                &davinci_uart2_ctrl_regs->pwremu_mgmt);
280
281         return 0;
282 }
283
284 #ifdef CONFIG_DRIVER_TI_EMAC
285
286 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
287 /**
288  * rmii_hw_init
289  *
290  * DA850/OMAP-L138 EVM can interface to a daughter card for
291  * additional features. This card has an I2C GPIO Expander TCA6416
292  * to select the required functions like camera, RMII Ethernet,
293  * character LCD, video.
294  *
295  * Initialization of the expander involves configuring the
296  * polarity and direction of the ports. P07-P05 are used here.
297  * These ports are connected to a Mux chip which enables only one
298  * functionality at a time.
299  *
300  * For RMII phy to respond, the MII MDIO clock has to be  disabled
301  * since both the PHY devices have address as zero. The MII MDIO
302  * clock is controlled via GPIO2[6].
303  *
304  * This code is valid for Beta version of the hardware
305  */
306 int rmii_hw_init(void)
307 {
308         const struct pinmux_config gpio_pins[] = {
309                 { pinmux(6), 8, 1 }
310         };
311         u_int8_t buf[2];
312         unsigned int temp;
313         int ret;
314
315         /* PinMux for GPIO */
316         if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
317                 return 1;
318
319         /* I2C Exapnder configuration */
320         /* Set polarity to non-inverted */
321         buf[0] = 0x0;
322         buf[1] = 0x0;
323         ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
324         if (ret) {
325                 printf("\nExpander @ 0x%02x write FAILED!!!\n",
326                                 CONFIG_SYS_I2C_EXPANDER_ADDR);
327                 return ret;
328         }
329
330         /* Configure P07-P05 as outputs */
331         buf[0] = 0x1f;
332         buf[1] = 0xff;
333         ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
334         if (ret) {
335                 printf("\nExpander @ 0x%02x write FAILED!!!\n",
336                                 CONFIG_SYS_I2C_EXPANDER_ADDR);
337         }
338
339         /* For Ethernet RMII selection
340          * P07(SelA)=0
341          * P06(SelB)=1
342          * P05(SelC)=1
343          */
344         if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
345                 printf("\nExpander @ 0x%02x read FAILED!!!\n",
346                                 CONFIG_SYS_I2C_EXPANDER_ADDR);
347         }
348
349         buf[0] &= 0x1f;
350         buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
351         if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
352                 printf("\nExpander @ 0x%02x write FAILED!!!\n",
353                                 CONFIG_SYS_I2C_EXPANDER_ADDR);
354         }
355
356         /* Set the output as high */
357         temp = REG(GPIO_BANK2_REG_SET_ADDR);
358         temp |= (0x01 << 6);
359         REG(GPIO_BANK2_REG_SET_ADDR) = temp;
360
361         /* Set the GPIO direction as output */
362         temp = REG(GPIO_BANK2_REG_DIR_ADDR);
363         temp &= ~(0x01 << 6);
364         REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
365
366         return 0;
367 }
368 #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
369
370 /*
371  * Initializes on-board ethernet controllers.
372  */
373 int board_eth_init(bd_t *bis)
374 {
375 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
376         /* Select RMII fucntion through the expander */
377         if (rmii_hw_init())
378                 printf("RMII hardware init failed!!!\n");
379 #endif
380         if (!davinci_emac_initialize()) {
381                 printf("Error: Ethernet init failed!\n");
382                 return -1;
383         }
384
385         return 0;
386 }
387 #endif /* CONFIG_DRIVER_TI_EMAC */