xref: /openbmc/u-boot/board/davinci/ea20/ea20.c (revision e11ef3d2)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2010
4  * Stefano Babic, DENX Software Engineering, sbabic@denx.de
5  *
6  * Based on da850evm.c, original Copyrights follow:
7  *
8  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
9  *
10  * Based on da830evm.c. Original Copyrights follow:
11  *
12  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
13  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
14  */
15 
16 #include <common.h>
17 #include <i2c.h>
18 #include <net.h>
19 #include <netdev.h>
20 #include <asm/mach-types.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/ti-common/davinci_nand.h>
23 #include <asm/arch/emac_defs.h>
24 #include <asm/io.h>
25 #include <asm/arch/davinci_misc.h>
26 #include <asm/gpio.h>
27 #include "../../../drivers/video/da8xx-fb.h"
28 
29 DECLARE_GLOBAL_DATA_PTR;
30 
31 static const struct da8xx_panel lcd_panel = {
32 	/* Casio COM57H531x */
33 	.name = "Casio_COM57H531x",
34 	.width = 640,
35 	.height = 480,
36 	.hfp = 12,
37 	.hbp = 144,
38 	.hsw = 30,
39 	.vfp = 10,
40 	.vbp = 35,
41 	.vsw = 3,
42 	.pxl_clk = 25000000,
43 	.invert_pxl_clk = 0,
44 };
45 
46 static const struct display_panel disp_panel = {
47 	QVGA,
48 	16,
49 	16,
50 	COLOR_ACTIVE,
51 };
52 
53 static const struct lcd_ctrl_config lcd_cfg = {
54 	&disp_panel,
55 	.ac_bias		= 255,
56 	.ac_bias_intrpt		= 0,
57 	.dma_burst_sz		= 16,
58 	.bpp			= 16,
59 	.fdd			= 255,
60 	.tft_alt_mode		= 0,
61 	.stn_565_mode		= 0,
62 	.mono_8bit_mode		= 0,
63 	.invert_line_clock	= 1,
64 	.invert_frm_clock	= 1,
65 	.sync_edge		= 0,
66 	.sync_ctrl		= 1,
67 	.raster_order		= 0,
68 };
69 
70 /* SPI0 pin muxer settings */
71 static const struct pinmux_config spi1_pins[] = {
72 	{ pinmux(5), 1, 1 },
73 	{ pinmux(5), 1, 2 },
74 	{ pinmux(5), 1, 4 },
75 	{ pinmux(5), 1, 5 }
76 };
77 
78 /* I2C pin muxer settings */
79 static const struct pinmux_config i2c_pins[] = {
80 	{ pinmux(4), 2, 2 },
81 	{ pinmux(4), 2, 3 }
82 };
83 
84 /* UART0 pin muxer settings */
85 static const struct pinmux_config uart_pins[] = {
86 	{ pinmux(3), 2, 7 },
87 	{ pinmux(3), 2, 6 },
88 	{ pinmux(3), 2, 4 },
89 	{ pinmux(3), 2, 5 }
90 };
91 
92 #ifdef CONFIG_DRIVER_TI_EMAC
93 #define HAS_RMII 1
94 static const struct pinmux_config emac_pins[] = {
95 	{ pinmux(14), 8, 2 },
96 	{ pinmux(14), 8, 3 },
97 	{ pinmux(14), 8, 4 },
98 	{ pinmux(14), 8, 5 },
99 	{ pinmux(14), 8, 6 },
100 	{ pinmux(14), 8, 7 },
101 	{ pinmux(15), 8, 1 },
102 	{ pinmux(4), 8, 0 },
103 	{ pinmux(4), 8, 1 }
104 };
105 #endif
106 
107 #ifdef CONFIG_NAND_DAVINCI
108 const struct pinmux_config nand_pins[] = {
109 	{ pinmux(7), 1, 0},	/* CS2 */
110 	{ pinmux(7), 0, 1},	/* CS3  in three state*/
111 	{ pinmux(7), 1, 4 },	/* EMA_WE */
112 	{ pinmux(7), 1, 5 },	/* EMA_OE */
113 	{ pinmux(9), 1, 0 },	/* EMA_D[7] */
114 	{ pinmux(9), 1, 1 },	/* EMA_D[6] */
115 	{ pinmux(9), 1, 2 },	/* EMA_D[5] */
116 	{ pinmux(9), 1, 3 },	/* EMA_D[4] */
117 	{ pinmux(9), 1, 4 },	/* EMA_D[3] */
118 	{ pinmux(9), 1, 5 },	/* EMA_D[2] */
119 	{ pinmux(9), 1, 6 },	/* EMA_D[1] */
120 	{ pinmux(9), 1, 7 },	/* EMA_D[0] */
121 	{ pinmux(12), 1, 5 },	/* EMA_A[2] */
122 	{ pinmux(12), 1, 6 },	/* EMA_A[1] */
123 	{ pinmux(6), 1, 0 }	/* EMA_CLK */
124 };
125 #endif
126 
127 const struct pinmux_config gpio_pins[] = {
128 	{ pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/
129 	{ pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/
130 	{ pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/
131 	{ pinmux(19), 8, 5 }, /* GPIO6[1]  DISP_ON */
132 	{ pinmux(14), 8, 1 }  /* GPIO6[6]  LCD_B_PWR*/
133 };
134 
135 const struct pinmux_config lcd_pins[] = {
136 	{ pinmux(17), 2, 1 }, /* LCD_D_0 */
137 	{ pinmux(17), 2, 0 }, /* LCD_D_1 */
138 	{ pinmux(16), 2, 7 }, /* LCD_D_2 */
139 	{ pinmux(16), 2, 6 }, /* LCD_D_3 */
140 	{ pinmux(16), 2, 5 }, /* LCD_D_4 */
141 	{ pinmux(16), 2, 4 }, /* LCD_D_5 */
142 	{ pinmux(16), 2, 3 }, /* LCD_D_6 */
143 	{ pinmux(16), 2, 2 }, /* LCD_D_7 */
144 	{ pinmux(18), 2, 1 }, /* LCD_D_8 */
145 	{ pinmux(18), 2, 0 }, /* LCD_D_9 */
146 	{ pinmux(17), 2, 7 }, /* LCD_D_10 */
147 	{ pinmux(17), 2, 6 }, /* LCD_D_11 */
148 	{ pinmux(17), 2, 5 }, /* LCD_D_12 */
149 	{ pinmux(17), 2, 4 }, /* LCD_D_13 */
150 	{ pinmux(17), 2, 3 }, /* LCD_D_14 */
151 	{ pinmux(17), 2, 2 }, /* LCD_D_15 */
152 	{ pinmux(18), 2, 6 }, /* LCD_PCLK */
153 	{ pinmux(19), 2, 0 }, /* LCD_HSYNC */
154 	{ pinmux(19), 2, 1 }, /* LCD_VSYNC */
155 	{ pinmux(19), 2, 6 }, /* DA850_NLCD_AC_ENB_CS */
156 };
157 
158 const struct pinmux_config halten_pin[] = {
159 	{ pinmux(3),  4, 2 } /* GPIO8[6] HALTEN */
160 };
161 
162 static const struct pinmux_resource pinmuxes[] = {
163 #ifdef CONFIG_SPI_FLASH
164 	PINMUX_ITEM(spi1_pins),
165 #endif
166 	PINMUX_ITEM(uart_pins),
167 	PINMUX_ITEM(i2c_pins),
168 #ifdef CONFIG_NAND_DAVINCI
169 	PINMUX_ITEM(nand_pins),
170 #endif
171 #ifdef CONFIG_VIDEO
172 	PINMUX_ITEM(lcd_pins),
173 #endif
174 };
175 
176 static const struct lpsc_resource lpsc[] = {
177 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
178 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
179 	{ DAVINCI_LPSC_EMAC },	/* image download */
180 	{ DAVINCI_LPSC_UART0 },	/* console */
181 	{ DAVINCI_LPSC_GPIO },
182 	{ DAVINCI_LPSC_LCDC }, /* LCD */
183 };
184 
185 int board_early_init_f(void)
186 {
187 	/* PinMux for GPIO */
188 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
189 		return 1;
190 
191 	/* Set DISP_ON high to enable LCD output*/
192 	gpio_direction_output(97, 1);
193 
194 	/* Set the RESETOUTn low */
195 	gpio_direction_output(111, 0);
196 
197 	/* Set U0_SW0 low for UART0 as console*/
198 	gpio_direction_output(106, 0);
199 
200 	/* Set U0_SW1 low for UART0 as console*/
201 	gpio_direction_output(108, 0);
202 
203 	/* Set LCD_B_PWR low to power down LCD Backlight*/
204 	gpio_direction_output(102, 0);
205 
206 	irq_init();
207 
208 	/*
209 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
210 	 * Linux kernel @ 25MHz EMIFA
211 	 */
212 #ifdef CONFIG_NAND_DAVINCI
213 	writel((DAVINCI_ABCR_WSETUP(0) |
214 		DAVINCI_ABCR_WSTROBE(1) |
215 		DAVINCI_ABCR_WHOLD(0) |
216 		DAVINCI_ABCR_RSETUP(0) |
217 		DAVINCI_ABCR_RSTROBE(1) |
218 		DAVINCI_ABCR_RHOLD(0) |
219 		DAVINCI_ABCR_TA(0) |
220 		DAVINCI_ABCR_ASIZE_8BIT),
221 	       &davinci_emif_regs->ab1cr); /* CS2 */
222 #endif
223 
224 	/*
225 	 * Power on required peripherals
226 	 * ARM does not have access by default to PSC0 and PSC1
227 	 * assuming here that the DSP bootloader has set the IOPU
228 	 * such that PSC access is available to ARM
229 	 */
230 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
231 		return 1;
232 
233 	/* setup the SUSPSRC for ARM to control emulation suspend */
234 	writel(readl(&davinci_syscfg_regs->suspsrc) &
235 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
236 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
237 		 DAVINCI_SYSCFG_SUSPSRC_UART0),
238 	       &davinci_syscfg_regs->suspsrc);
239 
240 	/* configure pinmux settings */
241 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
242 		return 1;
243 
244 #ifdef CONFIG_DRIVER_TI_EMAC
245 	if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
246 		return 1;
247 
248 	davinci_emac_mii_mode_sel(HAS_RMII);
249 #endif /* CONFIG_DRIVER_TI_EMAC */
250 
251 	/* enable the console UART */
252 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
253 		DAVINCI_UART_PWREMU_MGMT_UTRST),
254 	       &davinci_uart0_ctrl_regs->pwremu_mgmt);
255 
256 	/*
257 	 * Reconfigure the LCDC priority to the highest to ensure that
258 	 * the throughput/latency requirements for the LCDC are met.
259 	 */
260 	writel(readl(&davinci_syscfg_regs->mstpri[2]) & 0x0fffffff,
261 	       &davinci_syscfg_regs->mstpri[2]);
262 
263 
264 	return 0;
265 }
266 
267 /*
268  * Do not overwrite the console
269  * Use always serial for U-Boot console
270  */
271 int overwrite_console(void)
272 {
273 	return 1;
274 }
275 
276 int board_init(void)
277 {
278 	/* arch number of the board */
279 	gd->bd->bi_arch_number = MACH_TYPE_EA20;
280 
281 	/* address of boot parameters */
282 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
283 
284 	da8xx_video_init(&lcd_panel, &lcd_cfg, 16);
285 
286 	return 0;
287 }
288 
289 #ifdef CONFIG_BOARD_LATE_INIT
290 
291 int board_late_init(void)
292 {
293 	unsigned char buf[2];
294 	int ret;
295 
296 	/* PinMux for HALTEN */
297 	if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0)
298 		return 1;
299 
300 	/* Set HALTEN to high */
301 	gpio_direction_output(134, 1);
302 
303 	/* Set fixed contrast settings for LCD via I2C potentiometer */
304 	buf[0] = 0x00;
305 	buf[1] = 0xd7;
306 	ret = i2c_write(0x2e, 6, 1, buf, 2);
307 	if (ret)
308 		puts("\nContrast Settings FAILED\n");
309 
310 	/* Set LCD_B_PWR high to power up LCD Backlight*/
311 	gpio_set_value(102, 1);
312 	return 0;
313 }
314 #endif /* CONFIG_BOARD_LATE_INIT */
315 
316 #ifdef CONFIG_DRIVER_TI_EMAC
317 
318 /*
319  * Initializes on-board ethernet controllers.
320  */
321 int board_eth_init(bd_t *bis)
322 {
323 	if (!davinci_emac_initialize()) {
324 		printf("Error: Ethernet init failed!\n");
325 		return -1;
326 	}
327 
328 	/*
329 	 * This board has a RMII PHY. However, the MDC line on the SOM
330 	 * must not be disabled (there is no MII PHY on the
331 	 * baseboard) via the GPIO2[6], because this pin
332 	 * disables at the same time the SPI flash.
333 	 */
334 
335 	return 0;
336 }
337 #endif /* CONFIG_DRIVER_TI_EMAC */
338