1649a33e4SStefano Babic /* 2649a33e4SStefano Babic * (C) Copyright 2010 3649a33e4SStefano Babic * Stefano Babic, DENX Software Engineering, sbabic@denx.de 4649a33e4SStefano Babic * 5649a33e4SStefano Babic * Based on da850evm.c, original Copyrights follow: 6649a33e4SStefano Babic * 7649a33e4SStefano Babic * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 8649a33e4SStefano Babic * 9649a33e4SStefano Babic * Based on da830evm.c. Original Copyrights follow: 10649a33e4SStefano Babic * 11649a33e4SStefano Babic * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com> 12649a33e4SStefano Babic * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> 13649a33e4SStefano Babic * 141a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 15649a33e4SStefano Babic */ 16649a33e4SStefano Babic 17649a33e4SStefano Babic #include <common.h> 18649a33e4SStefano Babic #include <i2c.h> 19649a33e4SStefano Babic #include <net.h> 20649a33e4SStefano Babic #include <netdev.h> 21649a33e4SStefano Babic #include <asm/arch/hardware.h> 22649a33e4SStefano Babic #include <asm/arch/emif_defs.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> 27*0017f9eeSHeiko 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 46649a33e4SStefano Babic /* SPI0 pin muxer settings */ 47649a33e4SStefano Babic static const struct pinmux_config spi1_pins[] = { 48649a33e4SStefano Babic { pinmux(5), 1, 1 }, 49649a33e4SStefano Babic { pinmux(5), 1, 2 }, 50649a33e4SStefano Babic { pinmux(5), 1, 4 }, 51649a33e4SStefano Babic { pinmux(5), 1, 5 } 52649a33e4SStefano Babic }; 53649a33e4SStefano Babic 544205987aSStefano Babic /* I2C pin muxer settings */ 554205987aSStefano Babic static const struct pinmux_config i2c_pins[] = { 564205987aSStefano Babic { pinmux(4), 2, 2 }, 574205987aSStefano Babic { pinmux(4), 2, 3 } 584205987aSStefano Babic }; 594205987aSStefano Babic 60f9fc237fSBastian Ruppert /* UART0 pin muxer settings */ 61649a33e4SStefano Babic static const struct pinmux_config uart_pins[] = { 62f9fc237fSBastian Ruppert { pinmux(3), 2, 7 }, 63f9fc237fSBastian Ruppert { pinmux(3), 2, 6 }, 64f9fc237fSBastian Ruppert { pinmux(3), 2, 4 }, 65f9fc237fSBastian Ruppert { pinmux(3), 2, 5 } 66649a33e4SStefano Babic }; 67649a33e4SStefano Babic 68649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 69649a33e4SStefano Babic #define HAS_RMII 1 70649a33e4SStefano Babic static const struct pinmux_config emac_pins[] = { 71649a33e4SStefano Babic { pinmux(14), 8, 2 }, 72649a33e4SStefano Babic { pinmux(14), 8, 3 }, 73649a33e4SStefano Babic { pinmux(14), 8, 4 }, 74649a33e4SStefano Babic { pinmux(14), 8, 5 }, 75649a33e4SStefano Babic { pinmux(14), 8, 6 }, 76649a33e4SStefano Babic { pinmux(14), 8, 7 }, 77649a33e4SStefano Babic { pinmux(15), 8, 1 }, 78649a33e4SStefano Babic { pinmux(4), 8, 0 }, 79649a33e4SStefano Babic { pinmux(4), 8, 1 } 80649a33e4SStefano Babic }; 81649a33e4SStefano Babic #endif 82649a33e4SStefano Babic 83649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI 84649a33e4SStefano Babic const struct pinmux_config nand_pins[] = { 8517a8904bSStefano Babic { pinmux(7), 1, 0}, /* CS2 */ 8617a8904bSStefano Babic { pinmux(7), 0, 1}, /* CS3 in three state*/ 8717a8904bSStefano Babic { pinmux(7), 1, 4 }, /* EMA_WE */ 8817a8904bSStefano Babic { pinmux(7), 1, 5 }, /* EMA_OE */ 8917a8904bSStefano Babic { pinmux(9), 1, 0 }, /* EMA_D[7] */ 9017a8904bSStefano Babic { pinmux(9), 1, 1 }, /* EMA_D[6] */ 9117a8904bSStefano Babic { pinmux(9), 1, 2 }, /* EMA_D[5] */ 9217a8904bSStefano Babic { pinmux(9), 1, 3 }, /* EMA_D[4] */ 9317a8904bSStefano Babic { pinmux(9), 1, 4 }, /* EMA_D[3] */ 9417a8904bSStefano Babic { pinmux(9), 1, 5 }, /* EMA_D[2] */ 9517a8904bSStefano Babic { pinmux(9), 1, 6 }, /* EMA_D[1] */ 9617a8904bSStefano Babic { pinmux(9), 1, 7 }, /* EMA_D[0] */ 9717a8904bSStefano Babic { pinmux(12), 1, 5 }, /* EMA_A[2] */ 9817a8904bSStefano Babic { pinmux(12), 1, 6 }, /* EMA_A[1] */ 9917a8904bSStefano Babic { pinmux(6), 1, 0 } /* EMA_CLK */ 100649a33e4SStefano Babic }; 101649a33e4SStefano Babic #endif 102649a33e4SStefano Babic 103ca1646b8SBastian Ruppert const struct pinmux_config gpio_pins[] = { 104ca1646b8SBastian Ruppert { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/ 105ca1646b8SBastian Ruppert { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/ 1068540b169SBastian Ruppert { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/ 1078540b169SBastian Ruppert { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */ 1088540b169SBastian Ruppert { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/ 109ca1646b8SBastian Ruppert }; 110ca1646b8SBastian Ruppert 1113c891011SStefano Babic const struct pinmux_config lcd_pins[] = { 1123c891011SStefano Babic { pinmux(17), 2, 1 }, /* LCD_D_0 */ 1133c891011SStefano Babic { pinmux(17), 2, 0 }, /* LCD_D_1 */ 1143c891011SStefano Babic { pinmux(16), 2, 7 }, /* LCD_D_2 */ 1153c891011SStefano Babic { pinmux(16), 2, 6 }, /* LCD_D_3 */ 1163c891011SStefano Babic { pinmux(16), 2, 5 }, /* LCD_D_4 */ 1173c891011SStefano Babic { pinmux(16), 2, 4 }, /* LCD_D_5 */ 1183c891011SStefano Babic { pinmux(16), 2, 3 }, /* LCD_D_6 */ 1193c891011SStefano Babic { pinmux(16), 2, 2 }, /* LCD_D_7 */ 1203c891011SStefano Babic { pinmux(18), 2, 1 }, /* LCD_D_8 */ 1213c891011SStefano Babic { pinmux(18), 2, 0 }, /* LCD_D_9 */ 1223c891011SStefano Babic { pinmux(17), 2, 7 }, /* LCD_D_10 */ 1233c891011SStefano Babic { pinmux(17), 2, 6 }, /* LCD_D_11 */ 1243c891011SStefano Babic { pinmux(17), 2, 5 }, /* LCD_D_12 */ 1253c891011SStefano Babic { pinmux(17), 2, 4 }, /* LCD_D_13 */ 1263c891011SStefano Babic { pinmux(17), 2, 3 }, /* LCD_D_14 */ 1273c891011SStefano Babic { pinmux(17), 2, 2 }, /* LCD_D_15 */ 1283c891011SStefano Babic { pinmux(18), 2, 6 }, /* LCD_PCLK */ 1293c891011SStefano Babic { pinmux(19), 2, 0 }, /* LCD_HSYNC */ 1303c891011SStefano Babic { pinmux(19), 2, 1 }, /* LCD_VSYNC */ 1313c891011SStefano Babic { pinmux(19), 2, 6 }, /* DA850_NLCD_AC_ENB_CS */ 1323c891011SStefano Babic }; 1333c891011SStefano Babic 134e5ee9125SBastian Ruppert const struct pinmux_config halten_pin[] = { 135e5ee9125SBastian Ruppert { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */ 136e5ee9125SBastian Ruppert }; 137e5ee9125SBastian Ruppert 138649a33e4SStefano Babic static const struct pinmux_resource pinmuxes[] = { 139649a33e4SStefano Babic #ifdef CONFIG_SPI_FLASH 140649a33e4SStefano Babic PINMUX_ITEM(spi1_pins), 141649a33e4SStefano Babic #endif 142649a33e4SStefano Babic PINMUX_ITEM(uart_pins), 1434205987aSStefano Babic PINMUX_ITEM(i2c_pins), 144649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI 145649a33e4SStefano Babic PINMUX_ITEM(nand_pins), 146649a33e4SStefano Babic #endif 1473c891011SStefano Babic #ifdef CONFIG_VIDEO 1483c891011SStefano Babic PINMUX_ITEM(lcd_pins), 1493c891011SStefano Babic #endif 150649a33e4SStefano Babic }; 151649a33e4SStefano Babic 152649a33e4SStefano Babic static const struct lpsc_resource lpsc[] = { 153649a33e4SStefano Babic { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ 154649a33e4SStefano Babic { DAVINCI_LPSC_SPI1 }, /* Serial Flash */ 155649a33e4SStefano Babic { DAVINCI_LPSC_EMAC }, /* image download */ 156f9fc237fSBastian Ruppert { DAVINCI_LPSC_UART0 }, /* console */ 157649a33e4SStefano Babic { DAVINCI_LPSC_GPIO }, 1583c891011SStefano Babic { DAVINCI_LPSC_LCDC }, /* LCD */ 159649a33e4SStefano Babic }; 160649a33e4SStefano Babic 1611c6ec6ddSStefano Babic int board_early_init_f(void) 162649a33e4SStefano Babic { 163ca1646b8SBastian Ruppert /* PinMux for GPIO */ 164ca1646b8SBastian Ruppert if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0) 165ca1646b8SBastian Ruppert return 1; 166ca1646b8SBastian Ruppert 167bdb04abeSBastian Ruppert /* Set DISP_ON high to enable LCD output*/ 168bdb04abeSBastian Ruppert gpio_direction_output(97, 1); 169bdb04abeSBastian Ruppert 170ca1646b8SBastian Ruppert /* Set the RESETOUTn low */ 1711441aa6aSStefano Babic gpio_direction_output(111, 0); 172ca1646b8SBastian Ruppert 173ca1646b8SBastian Ruppert /* Set U0_SW0 low for UART0 as console*/ 1741441aa6aSStefano Babic gpio_direction_output(106, 0); 175ca1646b8SBastian Ruppert 176ca1646b8SBastian Ruppert /* Set U0_SW1 low for UART0 as console*/ 1771441aa6aSStefano Babic gpio_direction_output(108, 0); 178ca1646b8SBastian Ruppert 1798540b169SBastian Ruppert /* Set LCD_B_PWR low to power down LCD Backlight*/ 1801441aa6aSStefano Babic gpio_direction_output(102, 0); 1818540b169SBastian Ruppert 182649a33e4SStefano Babic #ifndef CONFIG_USE_IRQ 183649a33e4SStefano Babic irq_init(); 184649a33e4SStefano Babic #endif 185649a33e4SStefano Babic 186649a33e4SStefano Babic /* 187649a33e4SStefano Babic * NAND CS setup - cycle counts based on da850evm NAND timings in the 188649a33e4SStefano Babic * Linux kernel @ 25MHz EMIFA 189649a33e4SStefano Babic */ 19017a8904bSStefano Babic #ifdef CONFIG_NAND_DAVINCI 191649a33e4SStefano Babic writel((DAVINCI_ABCR_WSETUP(0) | 19217a8904bSStefano Babic DAVINCI_ABCR_WSTROBE(1) | 193649a33e4SStefano Babic DAVINCI_ABCR_WHOLD(0) | 194649a33e4SStefano Babic DAVINCI_ABCR_RSETUP(0) | 195649a33e4SStefano Babic DAVINCI_ABCR_RSTROBE(1) | 196649a33e4SStefano Babic DAVINCI_ABCR_RHOLD(0) | 197649a33e4SStefano Babic DAVINCI_ABCR_TA(0) | 198649a33e4SStefano Babic DAVINCI_ABCR_ASIZE_8BIT), 19917a8904bSStefano Babic &davinci_emif_regs->ab1cr); /* CS2 */ 200649a33e4SStefano Babic #endif 201649a33e4SStefano Babic 202649a33e4SStefano Babic /* 203649a33e4SStefano Babic * Power on required peripherals 204649a33e4SStefano Babic * ARM does not have access by default to PSC0 and PSC1 205649a33e4SStefano Babic * assuming here that the DSP bootloader has set the IOPU 206649a33e4SStefano Babic * such that PSC access is available to ARM 207649a33e4SStefano Babic */ 208649a33e4SStefano Babic if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) 209649a33e4SStefano Babic return 1; 210649a33e4SStefano Babic 211649a33e4SStefano Babic /* setup the SUSPSRC for ARM to control emulation suspend */ 212649a33e4SStefano Babic writel(readl(&davinci_syscfg_regs->suspsrc) & 213649a33e4SStefano Babic ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | 214649a33e4SStefano Babic DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | 215f9fc237fSBastian Ruppert DAVINCI_SYSCFG_SUSPSRC_UART0), 216649a33e4SStefano Babic &davinci_syscfg_regs->suspsrc); 217649a33e4SStefano Babic 218649a33e4SStefano Babic /* configure pinmux settings */ 219649a33e4SStefano Babic if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) 220649a33e4SStefano Babic return 1; 221649a33e4SStefano Babic 222649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 223649a33e4SStefano Babic if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0) 224649a33e4SStefano Babic return 1; 225649a33e4SStefano Babic 226649a33e4SStefano Babic davinci_emac_mii_mode_sel(HAS_RMII); 227649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */ 228649a33e4SStefano Babic 229649a33e4SStefano Babic /* enable the console UART */ 230649a33e4SStefano Babic writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | 231649a33e4SStefano Babic DAVINCI_UART_PWREMU_MGMT_UTRST), 232f9fc237fSBastian Ruppert &davinci_uart0_ctrl_regs->pwremu_mgmt); 233649a33e4SStefano Babic 2343c891011SStefano Babic /* 2353c891011SStefano Babic * Reconfigure the LCDC priority to the highest to ensure that 2363c891011SStefano Babic * the throughput/latency requirements for the LCDC are met. 2373c891011SStefano Babic */ 2383c891011SStefano Babic writel(readl(&davinci_syscfg_regs->mstpri[2]) & 0x0fffffff, 2393c891011SStefano Babic &davinci_syscfg_regs->mstpri[2]); 2403c891011SStefano Babic 2413c891011SStefano Babic 242649a33e4SStefano Babic return 0; 243649a33e4SStefano Babic } 244649a33e4SStefano Babic 24539e133d1SBastian Ruppert /* 24639e133d1SBastian Ruppert * Do not overwrite the console 24739e133d1SBastian Ruppert * Use always serial for U-Boot console 24839e133d1SBastian Ruppert */ 24939e133d1SBastian Ruppert int overwrite_console(void) 25039e133d1SBastian Ruppert { 25139e133d1SBastian Ruppert return 1; 25239e133d1SBastian Ruppert } 25339e133d1SBastian Ruppert 2541c6ec6ddSStefano Babic int board_init(void) 2551c6ec6ddSStefano Babic { 2561c6ec6ddSStefano Babic /* arch number of the board */ 2571c6ec6ddSStefano Babic gd->bd->bi_arch_number = MACH_TYPE_EA20; 2581c6ec6ddSStefano Babic 2591c6ec6ddSStefano Babic /* address of boot parameters */ 2601c6ec6ddSStefano Babic gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; 2611c6ec6ddSStefano Babic 2623c891011SStefano Babic da8xx_video_init(&lcd_panel, 16); 2633c891011SStefano Babic 2641c6ec6ddSStefano Babic return 0; 2651c6ec6ddSStefano Babic } 266e5ee9125SBastian Ruppert 2672d594fd5SNobuhiro Iwamatsu #ifdef CONFIG_BOARD_LATE_INIT 268e5ee9125SBastian Ruppert 269e5ee9125SBastian Ruppert int board_late_init(void) 270e5ee9125SBastian Ruppert { 271bdb04abeSBastian Ruppert unsigned char buf[2]; 272bdb04abeSBastian Ruppert int ret; 273bdb04abeSBastian Ruppert 274e5ee9125SBastian Ruppert /* PinMux for HALTEN */ 275e5ee9125SBastian Ruppert if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0) 276e5ee9125SBastian Ruppert return 1; 277e5ee9125SBastian Ruppert 278e5ee9125SBastian Ruppert /* Set HALTEN to high */ 2791441aa6aSStefano Babic gpio_direction_output(134, 1); 280e5ee9125SBastian Ruppert 281bdb04abeSBastian Ruppert /* Set fixed contrast settings for LCD via I2C potentiometer */ 282bdb04abeSBastian Ruppert buf[0] = 0x00; 283bdb04abeSBastian Ruppert buf[1] = 0xd7; 284bdb04abeSBastian Ruppert ret = i2c_write(0x2e, 6, 1, buf, 2); 285bdb04abeSBastian Ruppert if (ret) 286bdb04abeSBastian Ruppert puts("\nContrast Settings FAILED\n"); 287bdb04abeSBastian Ruppert 288bdb04abeSBastian Ruppert /* Set LCD_B_PWR high to power up LCD Backlight*/ 289bdb04abeSBastian Ruppert gpio_set_value(102, 1); 290e5ee9125SBastian Ruppert return 0; 291e5ee9125SBastian Ruppert } 2922d594fd5SNobuhiro Iwamatsu #endif /* CONFIG_BOARD_LATE_INIT */ 293e5ee9125SBastian Ruppert 294649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 295649a33e4SStefano Babic 296649a33e4SStefano Babic /* 297649a33e4SStefano Babic * Initializes on-board ethernet controllers. 298649a33e4SStefano Babic */ 299649a33e4SStefano Babic int board_eth_init(bd_t *bis) 300649a33e4SStefano Babic { 301649a33e4SStefano Babic if (!davinci_emac_initialize()) { 302649a33e4SStefano Babic printf("Error: Ethernet init failed!\n"); 303649a33e4SStefano Babic return -1; 304649a33e4SStefano Babic } 305649a33e4SStefano Babic 306649a33e4SStefano Babic /* 307649a33e4SStefano Babic * This board has a RMII PHY. However, the MDC line on the SOM 308649a33e4SStefano Babic * must not be disabled (there is no MII PHY on the 309649a33e4SStefano Babic * baseboard) via the GPIO2[6], because this pin 310649a33e4SStefano Babic * disables at the same time the SPI flash. 311649a33e4SStefano Babic */ 312649a33e4SStefano Babic 313649a33e4SStefano Babic return 0; 314649a33e4SStefano Babic } 315649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */ 316