1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2649a33e4SStefano Babic /*
3649a33e4SStefano Babic * (C) Copyright 2010
4649a33e4SStefano Babic * Stefano Babic, DENX Software Engineering, sbabic@denx.de
5649a33e4SStefano Babic *
6649a33e4SStefano Babic * Based on da850evm.c, original Copyrights follow:
7649a33e4SStefano Babic *
8649a33e4SStefano Babic * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
9649a33e4SStefano Babic *
10649a33e4SStefano Babic * Based on da830evm.c. Original Copyrights follow:
11649a33e4SStefano Babic *
12649a33e4SStefano Babic * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
13649a33e4SStefano Babic * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
14649a33e4SStefano Babic */
15649a33e4SStefano Babic
16649a33e4SStefano Babic #include <common.h>
17649a33e4SStefano Babic #include <i2c.h>
18649a33e4SStefano Babic #include <net.h>
19649a33e4SStefano Babic #include <netdev.h>
20c62db35dSSimon Glass #include <asm/mach-types.h>
21649a33e4SStefano Babic #include <asm/arch/hardware.h>
223e01ed00SKhoronzhuk, Ivan #include <asm/ti-common/davinci_nand.h>
23649a33e4SStefano Babic #include <asm/arch/emac_defs.h>
24649a33e4SStefano Babic #include <asm/io.h>
25649a33e4SStefano Babic #include <asm/arch/davinci_misc.h>
261441aa6aSStefano Babic #include <asm/gpio.h>
270017f9eeSHeiko Schocher #include "../../../drivers/video/da8xx-fb.h"
28649a33e4SStefano Babic
29649a33e4SStefano Babic DECLARE_GLOBAL_DATA_PTR;
30649a33e4SStefano Babic
313c891011SStefano Babic static const struct da8xx_panel lcd_panel = {
323c891011SStefano Babic /* Casio COM57H531x */
333c891011SStefano Babic .name = "Casio_COM57H531x",
343c891011SStefano Babic .width = 640,
353c891011SStefano Babic .height = 480,
363c891011SStefano Babic .hfp = 12,
373c891011SStefano Babic .hbp = 144,
383c891011SStefano Babic .hsw = 30,
393c891011SStefano Babic .vfp = 10,
403c891011SStefano Babic .vbp = 35,
413c891011SStefano Babic .vsw = 3,
423c891011SStefano Babic .pxl_clk = 25000000,
433c891011SStefano Babic .invert_pxl_clk = 0,
443c891011SStefano Babic };
453c891011SStefano Babic
46765f2f08SHeiko Schocher static const struct display_panel disp_panel = {
47765f2f08SHeiko Schocher QVGA,
48765f2f08SHeiko Schocher 16,
49765f2f08SHeiko Schocher 16,
50765f2f08SHeiko Schocher COLOR_ACTIVE,
51765f2f08SHeiko Schocher };
52765f2f08SHeiko Schocher
53765f2f08SHeiko Schocher static const struct lcd_ctrl_config lcd_cfg = {
54765f2f08SHeiko Schocher &disp_panel,
55765f2f08SHeiko Schocher .ac_bias = 255,
56765f2f08SHeiko Schocher .ac_bias_intrpt = 0,
57765f2f08SHeiko Schocher .dma_burst_sz = 16,
58765f2f08SHeiko Schocher .bpp = 16,
59765f2f08SHeiko Schocher .fdd = 255,
60765f2f08SHeiko Schocher .tft_alt_mode = 0,
61765f2f08SHeiko Schocher .stn_565_mode = 0,
62765f2f08SHeiko Schocher .mono_8bit_mode = 0,
63765f2f08SHeiko Schocher .invert_line_clock = 1,
64765f2f08SHeiko Schocher .invert_frm_clock = 1,
65765f2f08SHeiko Schocher .sync_edge = 0,
66765f2f08SHeiko Schocher .sync_ctrl = 1,
67765f2f08SHeiko Schocher .raster_order = 0,
68765f2f08SHeiko Schocher };
69765f2f08SHeiko Schocher
70649a33e4SStefano Babic /* SPI0 pin muxer settings */
71649a33e4SStefano Babic static const struct pinmux_config spi1_pins[] = {
72649a33e4SStefano Babic { pinmux(5), 1, 1 },
73649a33e4SStefano Babic { pinmux(5), 1, 2 },
74649a33e4SStefano Babic { pinmux(5), 1, 4 },
75649a33e4SStefano Babic { pinmux(5), 1, 5 }
76649a33e4SStefano Babic };
77649a33e4SStefano Babic
784205987aSStefano Babic /* I2C pin muxer settings */
794205987aSStefano Babic static const struct pinmux_config i2c_pins[] = {
804205987aSStefano Babic { pinmux(4), 2, 2 },
814205987aSStefano Babic { pinmux(4), 2, 3 }
824205987aSStefano Babic };
834205987aSStefano Babic
84f9fc237fSBastian Ruppert /* UART0 pin muxer settings */
85649a33e4SStefano Babic static const struct pinmux_config uart_pins[] = {
86f9fc237fSBastian Ruppert { pinmux(3), 2, 7 },
87f9fc237fSBastian Ruppert { pinmux(3), 2, 6 },
88f9fc237fSBastian Ruppert { pinmux(3), 2, 4 },
89f9fc237fSBastian Ruppert { pinmux(3), 2, 5 }
90649a33e4SStefano Babic };
91649a33e4SStefano Babic
92649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
93649a33e4SStefano Babic #define HAS_RMII 1
94649a33e4SStefano Babic static const struct pinmux_config emac_pins[] = {
95649a33e4SStefano Babic { pinmux(14), 8, 2 },
96649a33e4SStefano Babic { pinmux(14), 8, 3 },
97649a33e4SStefano Babic { pinmux(14), 8, 4 },
98649a33e4SStefano Babic { pinmux(14), 8, 5 },
99649a33e4SStefano Babic { pinmux(14), 8, 6 },
100649a33e4SStefano Babic { pinmux(14), 8, 7 },
101649a33e4SStefano Babic { pinmux(15), 8, 1 },
102649a33e4SStefano Babic { pinmux(4), 8, 0 },
103649a33e4SStefano Babic { pinmux(4), 8, 1 }
104649a33e4SStefano Babic };
105649a33e4SStefano Babic #endif
106649a33e4SStefano Babic
107649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI
108649a33e4SStefano Babic const struct pinmux_config nand_pins[] = {
10917a8904bSStefano Babic { pinmux(7), 1, 0}, /* CS2 */
11017a8904bSStefano Babic { pinmux(7), 0, 1}, /* CS3 in three state*/
11117a8904bSStefano Babic { pinmux(7), 1, 4 }, /* EMA_WE */
11217a8904bSStefano Babic { pinmux(7), 1, 5 }, /* EMA_OE */
11317a8904bSStefano Babic { pinmux(9), 1, 0 }, /* EMA_D[7] */
11417a8904bSStefano Babic { pinmux(9), 1, 1 }, /* EMA_D[6] */
11517a8904bSStefano Babic { pinmux(9), 1, 2 }, /* EMA_D[5] */
11617a8904bSStefano Babic { pinmux(9), 1, 3 }, /* EMA_D[4] */
11717a8904bSStefano Babic { pinmux(9), 1, 4 }, /* EMA_D[3] */
11817a8904bSStefano Babic { pinmux(9), 1, 5 }, /* EMA_D[2] */
11917a8904bSStefano Babic { pinmux(9), 1, 6 }, /* EMA_D[1] */
12017a8904bSStefano Babic { pinmux(9), 1, 7 }, /* EMA_D[0] */
12117a8904bSStefano Babic { pinmux(12), 1, 5 }, /* EMA_A[2] */
12217a8904bSStefano Babic { pinmux(12), 1, 6 }, /* EMA_A[1] */
12317a8904bSStefano Babic { pinmux(6), 1, 0 } /* EMA_CLK */
124649a33e4SStefano Babic };
125649a33e4SStefano Babic #endif
126649a33e4SStefano Babic
127ca1646b8SBastian Ruppert const struct pinmux_config gpio_pins[] = {
128ca1646b8SBastian Ruppert { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/
129ca1646b8SBastian Ruppert { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/
1308540b169SBastian Ruppert { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/
1318540b169SBastian Ruppert { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */
1328540b169SBastian Ruppert { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/
133ca1646b8SBastian Ruppert };
134ca1646b8SBastian Ruppert
1353c891011SStefano Babic const struct pinmux_config lcd_pins[] = {
1363c891011SStefano Babic { pinmux(17), 2, 1 }, /* LCD_D_0 */
1373c891011SStefano Babic { pinmux(17), 2, 0 }, /* LCD_D_1 */
1383c891011SStefano Babic { pinmux(16), 2, 7 }, /* LCD_D_2 */
1393c891011SStefano Babic { pinmux(16), 2, 6 }, /* LCD_D_3 */
1403c891011SStefano Babic { pinmux(16), 2, 5 }, /* LCD_D_4 */
1413c891011SStefano Babic { pinmux(16), 2, 4 }, /* LCD_D_5 */
1423c891011SStefano Babic { pinmux(16), 2, 3 }, /* LCD_D_6 */
1433c891011SStefano Babic { pinmux(16), 2, 2 }, /* LCD_D_7 */
1443c891011SStefano Babic { pinmux(18), 2, 1 }, /* LCD_D_8 */
1453c891011SStefano Babic { pinmux(18), 2, 0 }, /* LCD_D_9 */
1463c891011SStefano Babic { pinmux(17), 2, 7 }, /* LCD_D_10 */
1473c891011SStefano Babic { pinmux(17), 2, 6 }, /* LCD_D_11 */
1483c891011SStefano Babic { pinmux(17), 2, 5 }, /* LCD_D_12 */
1493c891011SStefano Babic { pinmux(17), 2, 4 }, /* LCD_D_13 */
1503c891011SStefano Babic { pinmux(17), 2, 3 }, /* LCD_D_14 */
1513c891011SStefano Babic { pinmux(17), 2, 2 }, /* LCD_D_15 */
1523c891011SStefano Babic { pinmux(18), 2, 6 }, /* LCD_PCLK */
1533c891011SStefano Babic { pinmux(19), 2, 0 }, /* LCD_HSYNC */
1543c891011SStefano Babic { pinmux(19), 2, 1 }, /* LCD_VSYNC */
1553c891011SStefano Babic { pinmux(19), 2, 6 }, /* DA850_NLCD_AC_ENB_CS */
1563c891011SStefano Babic };
1573c891011SStefano Babic
158e5ee9125SBastian Ruppert const struct pinmux_config halten_pin[] = {
159e5ee9125SBastian Ruppert { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */
160e5ee9125SBastian Ruppert };
161e5ee9125SBastian Ruppert
162649a33e4SStefano Babic static const struct pinmux_resource pinmuxes[] = {
163649a33e4SStefano Babic #ifdef CONFIG_SPI_FLASH
164649a33e4SStefano Babic PINMUX_ITEM(spi1_pins),
165649a33e4SStefano Babic #endif
166649a33e4SStefano Babic PINMUX_ITEM(uart_pins),
1674205987aSStefano Babic PINMUX_ITEM(i2c_pins),
168649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI
169649a33e4SStefano Babic PINMUX_ITEM(nand_pins),
170649a33e4SStefano Babic #endif
1713c891011SStefano Babic #ifdef CONFIG_VIDEO
1723c891011SStefano Babic PINMUX_ITEM(lcd_pins),
1733c891011SStefano Babic #endif
174649a33e4SStefano Babic };
175649a33e4SStefano Babic
176649a33e4SStefano Babic static const struct lpsc_resource lpsc[] = {
177649a33e4SStefano Babic { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
178649a33e4SStefano Babic { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
179649a33e4SStefano Babic { DAVINCI_LPSC_EMAC }, /* image download */
180f9fc237fSBastian Ruppert { DAVINCI_LPSC_UART0 }, /* console */
181649a33e4SStefano Babic { DAVINCI_LPSC_GPIO },
1823c891011SStefano Babic { DAVINCI_LPSC_LCDC }, /* LCD */
183649a33e4SStefano Babic };
184649a33e4SStefano Babic
board_early_init_f(void)1851c6ec6ddSStefano Babic int board_early_init_f(void)
186649a33e4SStefano Babic {
187ca1646b8SBastian Ruppert /* PinMux for GPIO */
188ca1646b8SBastian Ruppert if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
189ca1646b8SBastian Ruppert return 1;
190ca1646b8SBastian Ruppert
191bdb04abeSBastian Ruppert /* Set DISP_ON high to enable LCD output*/
192bdb04abeSBastian Ruppert gpio_direction_output(97, 1);
193bdb04abeSBastian Ruppert
194ca1646b8SBastian Ruppert /* Set the RESETOUTn low */
1951441aa6aSStefano Babic gpio_direction_output(111, 0);
196ca1646b8SBastian Ruppert
197ca1646b8SBastian Ruppert /* Set U0_SW0 low for UART0 as console*/
1981441aa6aSStefano Babic gpio_direction_output(106, 0);
199ca1646b8SBastian Ruppert
200ca1646b8SBastian Ruppert /* Set U0_SW1 low for UART0 as console*/
2011441aa6aSStefano Babic gpio_direction_output(108, 0);
202ca1646b8SBastian Ruppert
2038540b169SBastian Ruppert /* Set LCD_B_PWR low to power down LCD Backlight*/
2041441aa6aSStefano Babic gpio_direction_output(102, 0);
2058540b169SBastian Ruppert
206649a33e4SStefano Babic irq_init();
207649a33e4SStefano Babic
208649a33e4SStefano Babic /*
209649a33e4SStefano Babic * NAND CS setup - cycle counts based on da850evm NAND timings in the
210649a33e4SStefano Babic * Linux kernel @ 25MHz EMIFA
211649a33e4SStefano Babic */
21217a8904bSStefano Babic #ifdef CONFIG_NAND_DAVINCI
213649a33e4SStefano Babic writel((DAVINCI_ABCR_WSETUP(0) |
21417a8904bSStefano Babic DAVINCI_ABCR_WSTROBE(1) |
215649a33e4SStefano Babic DAVINCI_ABCR_WHOLD(0) |
216649a33e4SStefano Babic DAVINCI_ABCR_RSETUP(0) |
217649a33e4SStefano Babic DAVINCI_ABCR_RSTROBE(1) |
218649a33e4SStefano Babic DAVINCI_ABCR_RHOLD(0) |
219649a33e4SStefano Babic DAVINCI_ABCR_TA(0) |
220649a33e4SStefano Babic DAVINCI_ABCR_ASIZE_8BIT),
22117a8904bSStefano Babic &davinci_emif_regs->ab1cr); /* CS2 */
222649a33e4SStefano Babic #endif
223649a33e4SStefano Babic
224649a33e4SStefano Babic /*
225649a33e4SStefano Babic * Power on required peripherals
226649a33e4SStefano Babic * ARM does not have access by default to PSC0 and PSC1
227649a33e4SStefano Babic * assuming here that the DSP bootloader has set the IOPU
228649a33e4SStefano Babic * such that PSC access is available to ARM
229649a33e4SStefano Babic */
230649a33e4SStefano Babic if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
231649a33e4SStefano Babic return 1;
232649a33e4SStefano Babic
233649a33e4SStefano Babic /* setup the SUSPSRC for ARM to control emulation suspend */
234649a33e4SStefano Babic writel(readl(&davinci_syscfg_regs->suspsrc) &
235649a33e4SStefano Babic ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
236649a33e4SStefano Babic DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
237f9fc237fSBastian Ruppert DAVINCI_SYSCFG_SUSPSRC_UART0),
238649a33e4SStefano Babic &davinci_syscfg_regs->suspsrc);
239649a33e4SStefano Babic
240649a33e4SStefano Babic /* configure pinmux settings */
241649a33e4SStefano Babic if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
242649a33e4SStefano Babic return 1;
243649a33e4SStefano Babic
244649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
245649a33e4SStefano Babic if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
246649a33e4SStefano Babic return 1;
247649a33e4SStefano Babic
248649a33e4SStefano Babic davinci_emac_mii_mode_sel(HAS_RMII);
249649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */
250649a33e4SStefano Babic
251649a33e4SStefano Babic /* enable the console UART */
252649a33e4SStefano Babic writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
253649a33e4SStefano Babic DAVINCI_UART_PWREMU_MGMT_UTRST),
254f9fc237fSBastian Ruppert &davinci_uart0_ctrl_regs->pwremu_mgmt);
255649a33e4SStefano Babic
2563c891011SStefano Babic /*
2573c891011SStefano Babic * Reconfigure the LCDC priority to the highest to ensure that
2583c891011SStefano Babic * the throughput/latency requirements for the LCDC are met.
2593c891011SStefano Babic */
2603c891011SStefano Babic writel(readl(&davinci_syscfg_regs->mstpri[2]) & 0x0fffffff,
2613c891011SStefano Babic &davinci_syscfg_regs->mstpri[2]);
2623c891011SStefano Babic
2633c891011SStefano Babic
264649a33e4SStefano Babic return 0;
265649a33e4SStefano Babic }
266649a33e4SStefano Babic
26739e133d1SBastian Ruppert /*
26839e133d1SBastian Ruppert * Do not overwrite the console
26939e133d1SBastian Ruppert * Use always serial for U-Boot console
27039e133d1SBastian Ruppert */
overwrite_console(void)27139e133d1SBastian Ruppert int overwrite_console(void)
27239e133d1SBastian Ruppert {
27339e133d1SBastian Ruppert return 1;
27439e133d1SBastian Ruppert }
27539e133d1SBastian Ruppert
board_init(void)2761c6ec6ddSStefano Babic int board_init(void)
2771c6ec6ddSStefano Babic {
27894ba26f2STom Rini /* arch number of the board */
27994ba26f2STom Rini gd->bd->bi_arch_number = MACH_TYPE_EA20;
28094ba26f2STom Rini
2811c6ec6ddSStefano Babic /* address of boot parameters */
2821c6ec6ddSStefano Babic gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
2831c6ec6ddSStefano Babic
284765f2f08SHeiko Schocher da8xx_video_init(&lcd_panel, &lcd_cfg, 16);
2853c891011SStefano Babic
2861c6ec6ddSStefano Babic return 0;
2871c6ec6ddSStefano Babic }
288e5ee9125SBastian Ruppert
2892d594fd5SNobuhiro Iwamatsu #ifdef CONFIG_BOARD_LATE_INIT
290e5ee9125SBastian Ruppert
board_late_init(void)291e5ee9125SBastian Ruppert int board_late_init(void)
292e5ee9125SBastian Ruppert {
293bdb04abeSBastian Ruppert unsigned char buf[2];
294bdb04abeSBastian Ruppert int ret;
295bdb04abeSBastian Ruppert
296e5ee9125SBastian Ruppert /* PinMux for HALTEN */
297e5ee9125SBastian Ruppert if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0)
298e5ee9125SBastian Ruppert return 1;
299e5ee9125SBastian Ruppert
300e5ee9125SBastian Ruppert /* Set HALTEN to high */
3011441aa6aSStefano Babic gpio_direction_output(134, 1);
302e5ee9125SBastian Ruppert
303bdb04abeSBastian Ruppert /* Set fixed contrast settings for LCD via I2C potentiometer */
304bdb04abeSBastian Ruppert buf[0] = 0x00;
305bdb04abeSBastian Ruppert buf[1] = 0xd7;
306bdb04abeSBastian Ruppert ret = i2c_write(0x2e, 6, 1, buf, 2);
307bdb04abeSBastian Ruppert if (ret)
308bdb04abeSBastian Ruppert puts("\nContrast Settings FAILED\n");
309bdb04abeSBastian Ruppert
310bdb04abeSBastian Ruppert /* Set LCD_B_PWR high to power up LCD Backlight*/
311bdb04abeSBastian Ruppert gpio_set_value(102, 1);
312e5ee9125SBastian Ruppert return 0;
313e5ee9125SBastian Ruppert }
3142d594fd5SNobuhiro Iwamatsu #endif /* CONFIG_BOARD_LATE_INIT */
315e5ee9125SBastian Ruppert
316649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
317649a33e4SStefano Babic
318649a33e4SStefano Babic /*
319649a33e4SStefano Babic * Initializes on-board ethernet controllers.
320649a33e4SStefano Babic */
board_eth_init(bd_t * bis)321649a33e4SStefano Babic int board_eth_init(bd_t *bis)
322649a33e4SStefano Babic {
323649a33e4SStefano Babic if (!davinci_emac_initialize()) {
324649a33e4SStefano Babic printf("Error: Ethernet init failed!\n");
325649a33e4SStefano Babic return -1;
326649a33e4SStefano Babic }
327649a33e4SStefano Babic
328649a33e4SStefano Babic /*
329649a33e4SStefano Babic * This board has a RMII PHY. However, the MDC line on the SOM
330649a33e4SStefano Babic * must not be disabled (there is no MII PHY on the
331649a33e4SStefano Babic * baseboard) via the GPIO2[6], because this pin
332649a33e4SStefano Babic * disables at the same time the SPI flash.
333649a33e4SStefano Babic */
334649a33e4SStefano Babic
335649a33e4SStefano Babic return 0;
336649a33e4SStefano Babic }
337649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */
338