blob: 0edd9102106d927c3a4d14f9d3bb1aeb8e6d7c5c [file] [log] [blame]
Stefano Babicf57fd342010-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>
Stefano Babic562b7b92011-10-05 03:08:24 +000038#include <asm/gpio.h>
Stefano Babic16f61842011-10-04 23:43:37 +000039#include <asm/arch/da8xx-fb.h>
Stefano Babicf57fd342010-11-30 11:46:56 -050040
41DECLARE_GLOBAL_DATA_PTR;
42
Stefano Babic16f61842011-10-04 23:43:37 +000043static const struct da8xx_panel lcd_panel = {
44 /* Casio COM57H531x */
45 .name = "Casio_COM57H531x",
46 .width = 640,
47 .height = 480,
48 .hfp = 12,
49 .hbp = 144,
50 .hsw = 30,
51 .vfp = 10,
52 .vbp = 35,
53 .vsw = 3,
54 .pxl_clk = 25000000,
55 .invert_pxl_clk = 0,
56};
57
Stefano Babicf57fd342010-11-30 11:46:56 -050058/* SPI0 pin muxer settings */
59static const struct pinmux_config spi1_pins[] = {
60 { pinmux(5), 1, 1 },
61 { pinmux(5), 1, 2 },
62 { pinmux(5), 1, 4 },
63 { pinmux(5), 1, 5 }
64};
65
Stefano Babic0a00a172011-10-04 23:43:38 +000066/* I2C pin muxer settings */
67static const struct pinmux_config i2c_pins[] = {
68 { pinmux(4), 2, 2 },
69 { pinmux(4), 2, 3 }
70};
71
Bastian Rupperteb98e9d2011-10-04 23:43:28 +000072/* UART0 pin muxer settings */
Stefano Babicf57fd342010-11-30 11:46:56 -050073static const struct pinmux_config uart_pins[] = {
Bastian Rupperteb98e9d2011-10-04 23:43:28 +000074 { pinmux(3), 2, 7 },
75 { pinmux(3), 2, 6 },
76 { pinmux(3), 2, 4 },
77 { pinmux(3), 2, 5 }
Stefano Babicf57fd342010-11-30 11:46:56 -050078};
79
80#ifdef CONFIG_DRIVER_TI_EMAC
81#define HAS_RMII 1
82static const struct pinmux_config emac_pins[] = {
83 { pinmux(14), 8, 2 },
84 { pinmux(14), 8, 3 },
85 { pinmux(14), 8, 4 },
86 { pinmux(14), 8, 5 },
87 { pinmux(14), 8, 6 },
88 { pinmux(14), 8, 7 },
89 { pinmux(15), 8, 1 },
90 { pinmux(4), 8, 0 },
91 { pinmux(4), 8, 1 }
92};
93#endif
94
95#ifdef CONFIG_NAND_DAVINCI
96const struct pinmux_config nand_pins[] = {
Stefano Babicc9ab5c02011-10-04 23:43:30 +000097 { pinmux(7), 1, 0}, /* CS2 */
98 { pinmux(7), 0, 1}, /* CS3 in three state*/
99 { pinmux(7), 1, 4 }, /* EMA_WE */
100 { pinmux(7), 1, 5 }, /* EMA_OE */
101 { pinmux(9), 1, 0 }, /* EMA_D[7] */
102 { pinmux(9), 1, 1 }, /* EMA_D[6] */
103 { pinmux(9), 1, 2 }, /* EMA_D[5] */
104 { pinmux(9), 1, 3 }, /* EMA_D[4] */
105 { pinmux(9), 1, 4 }, /* EMA_D[3] */
106 { pinmux(9), 1, 5 }, /* EMA_D[2] */
107 { pinmux(9), 1, 6 }, /* EMA_D[1] */
108 { pinmux(9), 1, 7 }, /* EMA_D[0] */
109 { pinmux(12), 1, 5 }, /* EMA_A[2] */
110 { pinmux(12), 1, 6 }, /* EMA_A[1] */
111 { pinmux(6), 1, 0 } /* EMA_CLK */
Stefano Babicf57fd342010-11-30 11:46:56 -0500112};
113#endif
114
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000115const struct pinmux_config gpio_pins[] = {
116 { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/
117 { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/
Bastian Ruppert01875b62011-10-04 23:43:34 +0000118 { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/
119 { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */
120 { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000121};
122
Stefano Babic16f61842011-10-04 23:43:37 +0000123const struct pinmux_config lcd_pins[] = {
124 { pinmux(17), 2, 1 }, /* LCD_D_0 */
125 { pinmux(17), 2, 0 }, /* LCD_D_1 */
126 { pinmux(16), 2, 7 }, /* LCD_D_2 */
127 { pinmux(16), 2, 6 }, /* LCD_D_3 */
128 { pinmux(16), 2, 5 }, /* LCD_D_4 */
129 { pinmux(16), 2, 4 }, /* LCD_D_5 */
130 { pinmux(16), 2, 3 }, /* LCD_D_6 */
131 { pinmux(16), 2, 2 }, /* LCD_D_7 */
132 { pinmux(18), 2, 1 }, /* LCD_D_8 */
133 { pinmux(18), 2, 0 }, /* LCD_D_9 */
134 { pinmux(17), 2, 7 }, /* LCD_D_10 */
135 { pinmux(17), 2, 6 }, /* LCD_D_11 */
136 { pinmux(17), 2, 5 }, /* LCD_D_12 */
137 { pinmux(17), 2, 4 }, /* LCD_D_13 */
138 { pinmux(17), 2, 3 }, /* LCD_D_14 */
139 { pinmux(17), 2, 2 }, /* LCD_D_15 */
140 { pinmux(18), 2, 6 }, /* LCD_PCLK */
141 { pinmux(19), 2, 0 }, /* LCD_HSYNC */
142 { pinmux(19), 2, 1 }, /* LCD_VSYNC */
143 { pinmux(19), 2, 6 }, /* DA850_NLCD_AC_ENB_CS */
144};
145
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000146const struct pinmux_config halten_pin[] = {
147 { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */
148};
149
Stefano Babicf57fd342010-11-30 11:46:56 -0500150static const struct pinmux_resource pinmuxes[] = {
151#ifdef CONFIG_SPI_FLASH
152 PINMUX_ITEM(spi1_pins),
153#endif
154 PINMUX_ITEM(uart_pins),
Stefano Babic0a00a172011-10-04 23:43:38 +0000155 PINMUX_ITEM(i2c_pins),
Stefano Babicf57fd342010-11-30 11:46:56 -0500156#ifdef CONFIG_NAND_DAVINCI
157 PINMUX_ITEM(nand_pins),
158#endif
Stefano Babic16f61842011-10-04 23:43:37 +0000159#ifdef CONFIG_VIDEO
160 PINMUX_ITEM(lcd_pins),
161#endif
Stefano Babicf57fd342010-11-30 11:46:56 -0500162};
163
164static const struct lpsc_resource lpsc[] = {
165 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
166 { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
167 { DAVINCI_LPSC_EMAC }, /* image download */
Bastian Rupperteb98e9d2011-10-04 23:43:28 +0000168 { DAVINCI_LPSC_UART0 }, /* console */
Stefano Babicf57fd342010-11-30 11:46:56 -0500169 { DAVINCI_LPSC_GPIO },
Stefano Babic16f61842011-10-04 23:43:37 +0000170 { DAVINCI_LPSC_LCDC }, /* LCD */
Stefano Babicf57fd342010-11-30 11:46:56 -0500171};
172
Stefano Babic758c2272011-10-04 23:43:31 +0000173int board_early_init_f(void)
Stefano Babicf57fd342010-11-30 11:46:56 -0500174{
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000175 /* PinMux for GPIO */
176 if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
177 return 1;
178
Bastian Ruppert00951792012-09-13 22:28:59 +0000179 /* Set DISP_ON high to enable LCD output*/
180 gpio_direction_output(97, 1);
181
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000182 /* Set the RESETOUTn low */
Stefano Babic562b7b92011-10-05 03:08:24 +0000183 gpio_direction_output(111, 0);
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000184
185 /* Set U0_SW0 low for UART0 as console*/
Stefano Babic562b7b92011-10-05 03:08:24 +0000186 gpio_direction_output(106, 0);
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000187
188 /* Set U0_SW1 low for UART0 as console*/
Stefano Babic562b7b92011-10-05 03:08:24 +0000189 gpio_direction_output(108, 0);
Bastian Ruppert84aa0802011-10-04 23:43:29 +0000190
Bastian Ruppert01875b62011-10-04 23:43:34 +0000191 /* Set LCD_B_PWR low to power down LCD Backlight*/
Stefano Babic562b7b92011-10-05 03:08:24 +0000192 gpio_direction_output(102, 0);
Bastian Ruppert01875b62011-10-04 23:43:34 +0000193
Stefano Babicf57fd342010-11-30 11:46:56 -0500194#ifndef CONFIG_USE_IRQ
195 irq_init();
196#endif
197
Stefano Babicf57fd342010-11-30 11:46:56 -0500198 /*
199 * NAND CS setup - cycle counts based on da850evm NAND timings in the
200 * Linux kernel @ 25MHz EMIFA
201 */
Stefano Babicc9ab5c02011-10-04 23:43:30 +0000202#ifdef CONFIG_NAND_DAVINCI
Stefano Babicf57fd342010-11-30 11:46:56 -0500203 writel((DAVINCI_ABCR_WSETUP(0) |
Stefano Babicc9ab5c02011-10-04 23:43:30 +0000204 DAVINCI_ABCR_WSTROBE(1) |
Stefano Babicf57fd342010-11-30 11:46:56 -0500205 DAVINCI_ABCR_WHOLD(0) |
206 DAVINCI_ABCR_RSETUP(0) |
207 DAVINCI_ABCR_RSTROBE(1) |
208 DAVINCI_ABCR_RHOLD(0) |
209 DAVINCI_ABCR_TA(0) |
210 DAVINCI_ABCR_ASIZE_8BIT),
Stefano Babicc9ab5c02011-10-04 23:43:30 +0000211 &davinci_emif_regs->ab1cr); /* CS2 */
Stefano Babicf57fd342010-11-30 11:46:56 -0500212#endif
213
Stefano Babicf57fd342010-11-30 11:46:56 -0500214 /*
215 * Power on required peripherals
216 * ARM does not have access by default to PSC0 and PSC1
217 * assuming here that the DSP bootloader has set the IOPU
218 * such that PSC access is available to ARM
219 */
220 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
221 return 1;
222
223 /* setup the SUSPSRC for ARM to control emulation suspend */
224 writel(readl(&davinci_syscfg_regs->suspsrc) &
225 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
226 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
Bastian Rupperteb98e9d2011-10-04 23:43:28 +0000227 DAVINCI_SYSCFG_SUSPSRC_UART0),
Stefano Babicf57fd342010-11-30 11:46:56 -0500228 &davinci_syscfg_regs->suspsrc);
229
230 /* configure pinmux settings */
231 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
232 return 1;
233
234#ifdef CONFIG_DRIVER_TI_EMAC
235 if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
236 return 1;
237
238 davinci_emac_mii_mode_sel(HAS_RMII);
239#endif /* CONFIG_DRIVER_TI_EMAC */
240
241 /* enable the console UART */
242 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
243 DAVINCI_UART_PWREMU_MGMT_UTRST),
Bastian Rupperteb98e9d2011-10-04 23:43:28 +0000244 &davinci_uart0_ctrl_regs->pwremu_mgmt);
Stefano Babicf57fd342010-11-30 11:46:56 -0500245
Stefano Babic16f61842011-10-04 23:43:37 +0000246 /*
247 * Reconfigure the LCDC priority to the highest to ensure that
248 * the throughput/latency requirements for the LCDC are met.
249 */
250 writel(readl(&davinci_syscfg_regs->mstpri[2]) & 0x0fffffff,
251 &davinci_syscfg_regs->mstpri[2]);
252
Stefano Babic16f61842011-10-04 23:43:37 +0000253
Stefano Babicf57fd342010-11-30 11:46:56 -0500254 return 0;
255}
256
Bastian Ruppertcf525372012-09-13 22:29:00 +0000257/*
258 * Do not overwrite the console
259 * Use always serial for U-Boot console
260 */
261int overwrite_console(void)
262{
263 return 1;
264}
265
Stefano Babic758c2272011-10-04 23:43:31 +0000266int board_init(void)
267{
268 /* arch number of the board */
269 gd->bd->bi_arch_number = MACH_TYPE_EA20;
270
271 /* address of boot parameters */
272 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
273
Stefano Babic16f61842011-10-04 23:43:37 +0000274 da8xx_video_init(&lcd_panel, 16);
275
Stefano Babic758c2272011-10-04 23:43:31 +0000276 return 0;
277}
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000278
Nobuhiro Iwamatsue3c071a2012-04-17 16:41:54 +0000279#ifdef CONFIG_BOARD_LATE_INIT
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000280
281int board_late_init(void)
282{
Bastian Ruppert00951792012-09-13 22:28:59 +0000283 unsigned char buf[2];
284 int ret;
285
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000286 /* PinMux for HALTEN */
287 if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0)
288 return 1;
289
290 /* Set HALTEN to high */
Stefano Babic562b7b92011-10-05 03:08:24 +0000291 gpio_direction_output(134, 1);
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000292
Bastian Ruppert00951792012-09-13 22:28:59 +0000293 /* Set fixed contrast settings for LCD via I2C potentiometer */
294 buf[0] = 0x00;
295 buf[1] = 0xd7;
296 ret = i2c_write(0x2e, 6, 1, buf, 2);
297 if (ret)
298 puts("\nContrast Settings FAILED\n");
299
300 /* Set LCD_B_PWR high to power up LCD Backlight*/
301 gpio_set_value(102, 1);
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000302 return 0;
303}
Nobuhiro Iwamatsue3c071a2012-04-17 16:41:54 +0000304#endif /* CONFIG_BOARD_LATE_INIT */
Bastian Ruppertaf974a12011-10-04 23:43:33 +0000305
Stefano Babicf57fd342010-11-30 11:46:56 -0500306#ifdef CONFIG_DRIVER_TI_EMAC
307
308/*
309 * Initializes on-board ethernet controllers.
310 */
311int board_eth_init(bd_t *bis)
312{
313 if (!davinci_emac_initialize()) {
314 printf("Error: Ethernet init failed!\n");
315 return -1;
316 }
317
318 /*
319 * This board has a RMII PHY. However, the MDC line on the SOM
320 * must not be disabled (there is no MII PHY on the
321 * baseboard) via the GPIO2[6], because this pin
322 * disables at the same time the SPI flash.
323 */
324
325 return 0;
326}
327#endif /* CONFIG_DRIVER_TI_EMAC */