blob: d581cddcf9b8ac9d1a9a613bbc33c8d28d1f3eee [file] [log] [blame]
Stefano Babic649a33e2010-11-30 11:46:56 -05001/*
2 * (C) Copyright 2010
3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de
4 *
5 * Based on da850evm.c, original Copyrights follow:
6 *
7 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * Based on da830evm.c. Original Copyrights follow:
10 *
11 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
12 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#include <common.h>
30#include <i2c.h>
31#include <net.h>
32#include <netdev.h>
33#include <asm/arch/hardware.h>
34#include <asm/arch/emif_defs.h>
35#include <asm/arch/emac_defs.h>
36#include <asm/io.h>
37#include <asm/arch/davinci_misc.h>
Bastian Ruppertca1646b2011-10-04 23:43:29 +000038#include <asm/arch/gpio.h>
Stefano Babic3c891012011-10-04 23:43:37 +000039#include <asm/arch/da8xx-fb.h>
Stefano Babic649a33e2010-11-30 11:46:56 -050040
41DECLARE_GLOBAL_DATA_PTR;
42
43#define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
44
Stefano Babic3c891012011-10-04 23:43:37 +000045static const struct da8xx_panel lcd_panel = {
46 /* Casio COM57H531x */
47 .name = "Casio_COM57H531x",
48 .width = 640,
49 .height = 480,
50 .hfp = 12,
51 .hbp = 144,
52 .hsw = 30,
53 .vfp = 10,
54 .vbp = 35,
55 .vsw = 3,
56 .pxl_clk = 25000000,
57 .invert_pxl_clk = 0,
58};
59
Stefano Babic649a33e2010-11-30 11:46:56 -050060/* SPI0 pin muxer settings */
61static const struct pinmux_config spi1_pins[] = {
62 { pinmux(5), 1, 1 },
63 { pinmux(5), 1, 2 },
64 { pinmux(5), 1, 4 },
65 { pinmux(5), 1, 5 }
66};
67
Bastian Ruppertf9fc2372011-10-04 23:43:28 +000068/* UART0 pin muxer settings */
Stefano Babic649a33e2010-11-30 11:46:56 -050069static const struct pinmux_config uart_pins[] = {
Bastian Ruppertf9fc2372011-10-04 23:43:28 +000070 { pinmux(3), 2, 7 },
71 { pinmux(3), 2, 6 },
72 { pinmux(3), 2, 4 },
73 { pinmux(3), 2, 5 }
Stefano Babic649a33e2010-11-30 11:46:56 -050074};
75
76#ifdef CONFIG_DRIVER_TI_EMAC
77#define HAS_RMII 1
78static const struct pinmux_config emac_pins[] = {
79 { pinmux(14), 8, 2 },
80 { pinmux(14), 8, 3 },
81 { pinmux(14), 8, 4 },
82 { pinmux(14), 8, 5 },
83 { pinmux(14), 8, 6 },
84 { pinmux(14), 8, 7 },
85 { pinmux(15), 8, 1 },
86 { pinmux(4), 8, 0 },
87 { pinmux(4), 8, 1 }
88};
89#endif
90
91#ifdef CONFIG_NAND_DAVINCI
92const struct pinmux_config nand_pins[] = {
Stefano Babic17a89042011-10-04 23:43:30 +000093 { pinmux(7), 1, 0}, /* CS2 */
94 { pinmux(7), 0, 1}, /* CS3 in three state*/
95 { pinmux(7), 1, 4 }, /* EMA_WE */
96 { pinmux(7), 1, 5 }, /* EMA_OE */
97 { pinmux(9), 1, 0 }, /* EMA_D[7] */
98 { pinmux(9), 1, 1 }, /* EMA_D[6] */
99 { pinmux(9), 1, 2 }, /* EMA_D[5] */
100 { pinmux(9), 1, 3 }, /* EMA_D[4] */
101 { pinmux(9), 1, 4 }, /* EMA_D[3] */
102 { pinmux(9), 1, 5 }, /* EMA_D[2] */
103 { pinmux(9), 1, 6 }, /* EMA_D[1] */
104 { pinmux(9), 1, 7 }, /* EMA_D[0] */
105 { pinmux(12), 1, 5 }, /* EMA_A[2] */
106 { pinmux(12), 1, 6 }, /* EMA_A[1] */
107 { pinmux(6), 1, 0 } /* EMA_CLK */
Stefano Babic649a33e2010-11-30 11:46:56 -0500108};
109#endif
110
Bastian Ruppertca1646b2011-10-04 23:43:29 +0000111const struct pinmux_config gpio_pins[] = {
112 { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/
113 { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/
Bastian Ruppert8540b162011-10-04 23:43:34 +0000114 { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/
115 { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */
116 { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/
Bastian Ruppertca1646b2011-10-04 23:43:29 +0000117};
118
Stefano Babic3c891012011-10-04 23:43:37 +0000119const struct pinmux_config lcd_pins[] = {
120 { pinmux(17), 2, 1 }, /* LCD_D_0 */
121 { pinmux(17), 2, 0 }, /* LCD_D_1 */
122 { pinmux(16), 2, 7 }, /* LCD_D_2 */
123 { pinmux(16), 2, 6 }, /* LCD_D_3 */
124 { pinmux(16), 2, 5 }, /* LCD_D_4 */
125 { pinmux(16), 2, 4 }, /* LCD_D_5 */
126 { pinmux(16), 2, 3 }, /* LCD_D_6 */
127 { pinmux(16), 2, 2 }, /* LCD_D_7 */
128 { pinmux(18), 2, 1 }, /* LCD_D_8 */
129 { pinmux(18), 2, 0 }, /* LCD_D_9 */
130 { pinmux(17), 2, 7 }, /* LCD_D_10 */
131 { pinmux(17), 2, 6 }, /* LCD_D_11 */
132 { pinmux(17), 2, 5 }, /* LCD_D_12 */
133 { pinmux(17), 2, 4 }, /* LCD_D_13 */
134 { pinmux(17), 2, 3 }, /* LCD_D_14 */
135 { pinmux(17), 2, 2 }, /* LCD_D_15 */
136 { pinmux(18), 2, 6 }, /* LCD_PCLK */
137 { pinmux(19), 2, 0 }, /* LCD_HSYNC */
138 { pinmux(19), 2, 1 }, /* LCD_VSYNC */
139 { pinmux(19), 2, 6 }, /* DA850_NLCD_AC_ENB_CS */
140};
141
Bastian Rupperte5ee9122011-10-04 23:43:33 +0000142const struct pinmux_config halten_pin[] = {
143 { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */
144};
145
Stefano Babic649a33e2010-11-30 11:46:56 -0500146static const struct pinmux_resource pinmuxes[] = {
147#ifdef CONFIG_SPI_FLASH
148 PINMUX_ITEM(spi1_pins),
149#endif
150 PINMUX_ITEM(uart_pins),
151#ifdef CONFIG_NAND_DAVINCI
152 PINMUX_ITEM(nand_pins),
153#endif
Stefano Babic3c891012011-10-04 23:43:37 +0000154#ifdef CONFIG_VIDEO
155 PINMUX_ITEM(lcd_pins),
156#endif
Stefano Babic649a33e2010-11-30 11:46:56 -0500157};
158
159static const struct lpsc_resource lpsc[] = {
160 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
161 { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
162 { DAVINCI_LPSC_EMAC }, /* image download */
Bastian Ruppertf9fc2372011-10-04 23:43:28 +0000163 { DAVINCI_LPSC_UART0 }, /* console */
Stefano Babic649a33e2010-11-30 11:46:56 -0500164 { DAVINCI_LPSC_GPIO },
Stefano Babic3c891012011-10-04 23:43:37 +0000165 { DAVINCI_LPSC_LCDC }, /* LCD */
Stefano Babic649a33e2010-11-30 11:46:56 -0500166};
167
Stefano Babic1c6ec6d2011-10-04 23:43:31 +0000168int board_early_init_f(void)
Stefano Babic649a33e2010-11-30 11:46:56 -0500169{
Bastian Ruppertca1646b2011-10-04 23:43:29 +0000170 struct davinci_gpio *gpio6_base =
171 (struct davinci_gpio *)DAVINCI_GPIO_BANK67;
172
173 /* PinMux for GPIO */
174 if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
175 return 1;
176
177 /* Set the RESETOUTn low */
178 writel((readl(&gpio6_base->set_data) & ~(1 << 15)),
179 &gpio6_base->set_data);
180 writel((readl(&gpio6_base->dir) & ~(1 << 15)), &gpio6_base->dir);
181
182 /* Set U0_SW0 low for UART0 as console*/
183 writel((readl(&gpio6_base->set_data) & ~(1 << 10)),
184 &gpio6_base->set_data);
185 writel((readl(&gpio6_base->dir) & ~(1 << 10)), &gpio6_base->dir);
186
187 /* Set U0_SW1 low for UART0 as console*/
188 writel((readl(&gpio6_base->set_data) & ~(1 << 12)),
189 &gpio6_base->set_data);
190 writel((readl(&gpio6_base->dir) & ~(1 << 12)), &gpio6_base->dir);
191
Bastian Ruppert8540b162011-10-04 23:43:34 +0000192 /* Set LCD_B_PWR low to power down LCD Backlight*/
193 writel((readl(&gpio6_base->set_data) & ~(1 << 6)),
194 &gpio6_base->set_data);
195 writel((readl(&gpio6_base->dir) & ~(1 << 6)), &gpio6_base->dir);
196
197 /* Set DISP_ON low to disable LCD output*/
198 writel((readl(&gpio6_base->set_data) & ~(1 << 1)),
199 &gpio6_base->set_data);
200 writel((readl(&gpio6_base->dir) & ~(1 << 1)), &gpio6_base->dir);
201
Stefano Babic649a33e2010-11-30 11:46:56 -0500202#ifndef CONFIG_USE_IRQ
203 irq_init();
204#endif
205
Stefano Babic649a33e2010-11-30 11:46:56 -0500206 /*
207 * NAND CS setup - cycle counts based on da850evm NAND timings in the
208 * Linux kernel @ 25MHz EMIFA
209 */
Stefano Babic17a89042011-10-04 23:43:30 +0000210#ifdef CONFIG_NAND_DAVINCI
Stefano Babic649a33e2010-11-30 11:46:56 -0500211 writel((DAVINCI_ABCR_WSETUP(0) |
Stefano Babic17a89042011-10-04 23:43:30 +0000212 DAVINCI_ABCR_WSTROBE(1) |
Stefano Babic649a33e2010-11-30 11:46:56 -0500213 DAVINCI_ABCR_WHOLD(0) |
214 DAVINCI_ABCR_RSETUP(0) |
215 DAVINCI_ABCR_RSTROBE(1) |
216 DAVINCI_ABCR_RHOLD(0) |
217 DAVINCI_ABCR_TA(0) |
218 DAVINCI_ABCR_ASIZE_8BIT),
Stefano Babic17a89042011-10-04 23:43:30 +0000219 &davinci_emif_regs->ab1cr); /* CS2 */
Stefano Babic649a33e2010-11-30 11:46:56 -0500220#endif
221
Stefano Babic649a33e2010-11-30 11:46:56 -0500222 /*
223 * Power on required peripherals
224 * ARM does not have access by default to PSC0 and PSC1
225 * assuming here that the DSP bootloader has set the IOPU
226 * such that PSC access is available to ARM
227 */
228 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
229 return 1;
230
231 /* setup the SUSPSRC for ARM to control emulation suspend */
232 writel(readl(&davinci_syscfg_regs->suspsrc) &
233 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
234 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
Bastian Ruppertf9fc2372011-10-04 23:43:28 +0000235 DAVINCI_SYSCFG_SUSPSRC_UART0),
Stefano Babic649a33e2010-11-30 11:46:56 -0500236 &davinci_syscfg_regs->suspsrc);
237
238 /* configure pinmux settings */
239 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
240 return 1;
241
242#ifdef CONFIG_DRIVER_TI_EMAC
243 if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
244 return 1;
245
246 davinci_emac_mii_mode_sel(HAS_RMII);
247#endif /* CONFIG_DRIVER_TI_EMAC */
248
249 /* enable the console UART */
250 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
251 DAVINCI_UART_PWREMU_MGMT_UTRST),
Bastian Ruppertf9fc2372011-10-04 23:43:28 +0000252 &davinci_uart0_ctrl_regs->pwremu_mgmt);
Stefano Babic649a33e2010-11-30 11:46:56 -0500253
Stefano Babic3c891012011-10-04 23:43:37 +0000254 /*
255 * Reconfigure the LCDC priority to the highest to ensure that
256 * the throughput/latency requirements for the LCDC are met.
257 */
258 writel(readl(&davinci_syscfg_regs->mstpri[2]) & 0x0fffffff,
259 &davinci_syscfg_regs->mstpri[2]);
260
261 /* Set LCD_B_PWR low to power up LCD Backlight*/
262 writel((readl(&gpio6_base->set_data) | (1 << 6)),
263 &gpio6_base->set_data);
264
265 /* Set DISP_ON low to disable LCD output*/
266 writel((readl(&gpio6_base->set_data) | (1 << 1)),
267 &gpio6_base->set_data);
268
Stefano Babic649a33e2010-11-30 11:46:56 -0500269 return 0;
270}
271
Stefano Babic1c6ec6d2011-10-04 23:43:31 +0000272int board_init(void)
273{
274 /* arch number of the board */
275 gd->bd->bi_arch_number = MACH_TYPE_EA20;
276
277 /* address of boot parameters */
278 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
279
Stefano Babic3c891012011-10-04 23:43:37 +0000280 da8xx_video_init(&lcd_panel, 16);
281
Stefano Babic1c6ec6d2011-10-04 23:43:31 +0000282 return 0;
283}
Bastian Rupperte5ee9122011-10-04 23:43:33 +0000284
285#ifdef BOARD_LATE_INIT
286
287int board_late_init(void)
288{
289 struct davinci_gpio *gpio8_base =
290 (struct davinci_gpio *)DAVINCI_GPIO_BANK8;
291
292 /* PinMux for HALTEN */
293 if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0)
294 return 1;
295
296 /* Set HALTEN to high */
297 writel((readl(&gpio8_base->set_data) | (1 << 6)),
298 &gpio8_base->set_data);
299 writel((readl(&gpio8_base->dir) & ~(1 << 6)), &gpio8_base->dir);
300
Stefano Babic3c891012011-10-04 23:43:37 +0000301 setenv("stdout", "serial");
302
Bastian Rupperte5ee9122011-10-04 23:43:33 +0000303 return 0;
304}
305#endif /* BOARD_LATE_INIT */
306
Stefano Babic649a33e2010-11-30 11:46:56 -0500307#ifdef CONFIG_DRIVER_TI_EMAC
308
309/*
310 * Initializes on-board ethernet controllers.
311 */
312int board_eth_init(bd_t *bis)
313{
314 if (!davinci_emac_initialize()) {
315 printf("Error: Ethernet init failed!\n");
316 return -1;
317 }
318
319 /*
320 * This board has a RMII PHY. However, the MDC line on the SOM
321 * must not be disabled (there is no MII PHY on the
322 * baseboard) via the GPIO2[6], because this pin
323 * disables at the same time the SPI flash.
324 */
325
326 return 0;
327}
328#endif /* CONFIG_DRIVER_TI_EMAC */