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 * 14649a33e4SStefano Babic * This program is free software; you can redistribute it and/or modify 15649a33e4SStefano Babic * it under the terms of the GNU General Public License as published by 16649a33e4SStefano Babic * the Free Software Foundation; either version 2 of the License, or 17649a33e4SStefano Babic * (at your option) any later version. 18649a33e4SStefano Babic * 19649a33e4SStefano Babic * This program is distributed in the hope that it will be useful, 20649a33e4SStefano Babic * but WITHOUT ANY WARRANTY; without even the implied warranty of 21649a33e4SStefano Babic * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22649a33e4SStefano Babic * GNU General Public License for more details. 23649a33e4SStefano Babic * 24649a33e4SStefano Babic * You should have received a copy of the GNU General Public License 25649a33e4SStefano Babic * along with this program; if not, write to the Free Software 26649a33e4SStefano Babic * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27649a33e4SStefano Babic */ 28649a33e4SStefano Babic 29649a33e4SStefano Babic #include <common.h> 30649a33e4SStefano Babic #include <i2c.h> 31649a33e4SStefano Babic #include <net.h> 32649a33e4SStefano Babic #include <netdev.h> 33649a33e4SStefano Babic #include <asm/arch/hardware.h> 34649a33e4SStefano Babic #include <asm/arch/emif_defs.h> 35649a33e4SStefano Babic #include <asm/arch/emac_defs.h> 36649a33e4SStefano Babic #include <asm/io.h> 37649a33e4SStefano Babic #include <asm/arch/davinci_misc.h> 38ca1646b8SBastian Ruppert #include <asm/arch/gpio.h> 39649a33e4SStefano Babic 40649a33e4SStefano Babic DECLARE_GLOBAL_DATA_PTR; 41649a33e4SStefano Babic 42649a33e4SStefano Babic #define pinmux(x) (&davinci_syscfg_regs->pinmux[x]) 43649a33e4SStefano Babic 44649a33e4SStefano Babic /* SPI0 pin muxer settings */ 45649a33e4SStefano Babic static const struct pinmux_config spi1_pins[] = { 46649a33e4SStefano Babic { pinmux(5), 1, 1 }, 47649a33e4SStefano Babic { pinmux(5), 1, 2 }, 48649a33e4SStefano Babic { pinmux(5), 1, 4 }, 49649a33e4SStefano Babic { pinmux(5), 1, 5 } 50649a33e4SStefano Babic }; 51649a33e4SStefano Babic 52f9fc237fSBastian Ruppert /* UART0 pin muxer settings */ 53649a33e4SStefano Babic static const struct pinmux_config uart_pins[] = { 54f9fc237fSBastian Ruppert { pinmux(3), 2, 7 }, 55f9fc237fSBastian Ruppert { pinmux(3), 2, 6 }, 56f9fc237fSBastian Ruppert { pinmux(3), 2, 4 }, 57f9fc237fSBastian Ruppert { pinmux(3), 2, 5 } 58649a33e4SStefano Babic }; 59649a33e4SStefano Babic 60649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 61649a33e4SStefano Babic #define HAS_RMII 1 62649a33e4SStefano Babic static const struct pinmux_config emac_pins[] = { 63649a33e4SStefano Babic { pinmux(14), 8, 2 }, 64649a33e4SStefano Babic { pinmux(14), 8, 3 }, 65649a33e4SStefano Babic { pinmux(14), 8, 4 }, 66649a33e4SStefano Babic { pinmux(14), 8, 5 }, 67649a33e4SStefano Babic { pinmux(14), 8, 6 }, 68649a33e4SStefano Babic { pinmux(14), 8, 7 }, 69649a33e4SStefano Babic { pinmux(15), 8, 1 }, 70649a33e4SStefano Babic { pinmux(4), 8, 0 }, 71649a33e4SStefano Babic { pinmux(4), 8, 1 } 72649a33e4SStefano Babic }; 73649a33e4SStefano Babic #endif 74649a33e4SStefano Babic 75649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI 76649a33e4SStefano Babic const struct pinmux_config nand_pins[] = { 7717a8904bSStefano Babic { pinmux(7), 1, 0}, /* CS2 */ 7817a8904bSStefano Babic { pinmux(7), 0, 1}, /* CS3 in three state*/ 7917a8904bSStefano Babic { pinmux(7), 1, 4 }, /* EMA_WE */ 8017a8904bSStefano Babic { pinmux(7), 1, 5 }, /* EMA_OE */ 8117a8904bSStefano Babic { pinmux(9), 1, 0 }, /* EMA_D[7] */ 8217a8904bSStefano Babic { pinmux(9), 1, 1 }, /* EMA_D[6] */ 8317a8904bSStefano Babic { pinmux(9), 1, 2 }, /* EMA_D[5] */ 8417a8904bSStefano Babic { pinmux(9), 1, 3 }, /* EMA_D[4] */ 8517a8904bSStefano Babic { pinmux(9), 1, 4 }, /* EMA_D[3] */ 8617a8904bSStefano Babic { pinmux(9), 1, 5 }, /* EMA_D[2] */ 8717a8904bSStefano Babic { pinmux(9), 1, 6 }, /* EMA_D[1] */ 8817a8904bSStefano Babic { pinmux(9), 1, 7 }, /* EMA_D[0] */ 8917a8904bSStefano Babic { pinmux(12), 1, 5 }, /* EMA_A[2] */ 9017a8904bSStefano Babic { pinmux(12), 1, 6 }, /* EMA_A[1] */ 9117a8904bSStefano Babic { pinmux(6), 1, 0 } /* EMA_CLK */ 92649a33e4SStefano Babic }; 93649a33e4SStefano Babic #endif 94649a33e4SStefano Babic 95ca1646b8SBastian Ruppert const struct pinmux_config gpio_pins[] = { 96ca1646b8SBastian Ruppert { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/ 97ca1646b8SBastian Ruppert { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/ 98*8540b169SBastian Ruppert { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/ 99*8540b169SBastian Ruppert { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */ 100*8540b169SBastian Ruppert { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/ 101ca1646b8SBastian Ruppert }; 102ca1646b8SBastian Ruppert 103e5ee9125SBastian Ruppert const struct pinmux_config halten_pin[] = { 104e5ee9125SBastian Ruppert { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */ 105e5ee9125SBastian Ruppert }; 106e5ee9125SBastian Ruppert 107649a33e4SStefano Babic static const struct pinmux_resource pinmuxes[] = { 108649a33e4SStefano Babic #ifdef CONFIG_SPI_FLASH 109649a33e4SStefano Babic PINMUX_ITEM(spi1_pins), 110649a33e4SStefano Babic #endif 111649a33e4SStefano Babic PINMUX_ITEM(uart_pins), 112649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI 113649a33e4SStefano Babic PINMUX_ITEM(nand_pins), 114649a33e4SStefano Babic #endif 115649a33e4SStefano Babic }; 116649a33e4SStefano Babic 117649a33e4SStefano Babic static const struct lpsc_resource lpsc[] = { 118649a33e4SStefano Babic { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ 119649a33e4SStefano Babic { DAVINCI_LPSC_SPI1 }, /* Serial Flash */ 120649a33e4SStefano Babic { DAVINCI_LPSC_EMAC }, /* image download */ 121f9fc237fSBastian Ruppert { DAVINCI_LPSC_UART0 }, /* console */ 122649a33e4SStefano Babic { DAVINCI_LPSC_GPIO }, 123649a33e4SStefano Babic }; 124649a33e4SStefano Babic 1251c6ec6ddSStefano Babic int board_early_init_f(void) 126649a33e4SStefano Babic { 127ca1646b8SBastian Ruppert struct davinci_gpio *gpio6_base = 128ca1646b8SBastian Ruppert (struct davinci_gpio *)DAVINCI_GPIO_BANK67; 129ca1646b8SBastian Ruppert 130ca1646b8SBastian Ruppert /* PinMux for GPIO */ 131ca1646b8SBastian Ruppert if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0) 132ca1646b8SBastian Ruppert return 1; 133ca1646b8SBastian Ruppert 134ca1646b8SBastian Ruppert /* Set the RESETOUTn low */ 135ca1646b8SBastian Ruppert writel((readl(&gpio6_base->set_data) & ~(1 << 15)), 136ca1646b8SBastian Ruppert &gpio6_base->set_data); 137ca1646b8SBastian Ruppert writel((readl(&gpio6_base->dir) & ~(1 << 15)), &gpio6_base->dir); 138ca1646b8SBastian Ruppert 139ca1646b8SBastian Ruppert /* Set U0_SW0 low for UART0 as console*/ 140ca1646b8SBastian Ruppert writel((readl(&gpio6_base->set_data) & ~(1 << 10)), 141ca1646b8SBastian Ruppert &gpio6_base->set_data); 142ca1646b8SBastian Ruppert writel((readl(&gpio6_base->dir) & ~(1 << 10)), &gpio6_base->dir); 143ca1646b8SBastian Ruppert 144ca1646b8SBastian Ruppert /* Set U0_SW1 low for UART0 as console*/ 145ca1646b8SBastian Ruppert writel((readl(&gpio6_base->set_data) & ~(1 << 12)), 146ca1646b8SBastian Ruppert &gpio6_base->set_data); 147ca1646b8SBastian Ruppert writel((readl(&gpio6_base->dir) & ~(1 << 12)), &gpio6_base->dir); 148ca1646b8SBastian Ruppert 149*8540b169SBastian Ruppert /* Set LCD_B_PWR low to power down LCD Backlight*/ 150*8540b169SBastian Ruppert writel((readl(&gpio6_base->set_data) & ~(1 << 6)), 151*8540b169SBastian Ruppert &gpio6_base->set_data); 152*8540b169SBastian Ruppert writel((readl(&gpio6_base->dir) & ~(1 << 6)), &gpio6_base->dir); 153*8540b169SBastian Ruppert 154*8540b169SBastian Ruppert /* Set DISP_ON low to disable LCD output*/ 155*8540b169SBastian Ruppert writel((readl(&gpio6_base->set_data) & ~(1 << 1)), 156*8540b169SBastian Ruppert &gpio6_base->set_data); 157*8540b169SBastian Ruppert writel((readl(&gpio6_base->dir) & ~(1 << 1)), &gpio6_base->dir); 158*8540b169SBastian Ruppert 159649a33e4SStefano Babic #ifndef CONFIG_USE_IRQ 160649a33e4SStefano Babic irq_init(); 161649a33e4SStefano Babic #endif 162649a33e4SStefano Babic 163649a33e4SStefano Babic /* 164649a33e4SStefano Babic * NAND CS setup - cycle counts based on da850evm NAND timings in the 165649a33e4SStefano Babic * Linux kernel @ 25MHz EMIFA 166649a33e4SStefano Babic */ 16717a8904bSStefano Babic #ifdef CONFIG_NAND_DAVINCI 168649a33e4SStefano Babic writel((DAVINCI_ABCR_WSETUP(0) | 16917a8904bSStefano Babic DAVINCI_ABCR_WSTROBE(1) | 170649a33e4SStefano Babic DAVINCI_ABCR_WHOLD(0) | 171649a33e4SStefano Babic DAVINCI_ABCR_RSETUP(0) | 172649a33e4SStefano Babic DAVINCI_ABCR_RSTROBE(1) | 173649a33e4SStefano Babic DAVINCI_ABCR_RHOLD(0) | 174649a33e4SStefano Babic DAVINCI_ABCR_TA(0) | 175649a33e4SStefano Babic DAVINCI_ABCR_ASIZE_8BIT), 17617a8904bSStefano Babic &davinci_emif_regs->ab1cr); /* CS2 */ 177649a33e4SStefano Babic #endif 178649a33e4SStefano Babic 179649a33e4SStefano Babic /* 180649a33e4SStefano Babic * Power on required peripherals 181649a33e4SStefano Babic * ARM does not have access by default to PSC0 and PSC1 182649a33e4SStefano Babic * assuming here that the DSP bootloader has set the IOPU 183649a33e4SStefano Babic * such that PSC access is available to ARM 184649a33e4SStefano Babic */ 185649a33e4SStefano Babic if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) 186649a33e4SStefano Babic return 1; 187649a33e4SStefano Babic 188649a33e4SStefano Babic /* setup the SUSPSRC for ARM to control emulation suspend */ 189649a33e4SStefano Babic writel(readl(&davinci_syscfg_regs->suspsrc) & 190649a33e4SStefano Babic ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | 191649a33e4SStefano Babic DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | 192f9fc237fSBastian Ruppert DAVINCI_SYSCFG_SUSPSRC_UART0), 193649a33e4SStefano Babic &davinci_syscfg_regs->suspsrc); 194649a33e4SStefano Babic 195649a33e4SStefano Babic /* configure pinmux settings */ 196649a33e4SStefano Babic if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) 197649a33e4SStefano Babic return 1; 198649a33e4SStefano Babic 199649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 200649a33e4SStefano Babic if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0) 201649a33e4SStefano Babic return 1; 202649a33e4SStefano Babic 203649a33e4SStefano Babic davinci_emac_mii_mode_sel(HAS_RMII); 204649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */ 205649a33e4SStefano Babic 206649a33e4SStefano Babic /* enable the console UART */ 207649a33e4SStefano Babic writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | 208649a33e4SStefano Babic DAVINCI_UART_PWREMU_MGMT_UTRST), 209f9fc237fSBastian Ruppert &davinci_uart0_ctrl_regs->pwremu_mgmt); 210649a33e4SStefano Babic 211649a33e4SStefano Babic return 0; 212649a33e4SStefano Babic } 213649a33e4SStefano Babic 2141c6ec6ddSStefano Babic int board_init(void) 2151c6ec6ddSStefano Babic { 2161c6ec6ddSStefano Babic /* arch number of the board */ 2171c6ec6ddSStefano Babic gd->bd->bi_arch_number = MACH_TYPE_EA20; 2181c6ec6ddSStefano Babic 2191c6ec6ddSStefano Babic /* address of boot parameters */ 2201c6ec6ddSStefano Babic gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; 2211c6ec6ddSStefano Babic 2221c6ec6ddSStefano Babic return 0; 2231c6ec6ddSStefano Babic } 224e5ee9125SBastian Ruppert 225e5ee9125SBastian Ruppert #ifdef BOARD_LATE_INIT 226e5ee9125SBastian Ruppert 227e5ee9125SBastian Ruppert int board_late_init(void) 228e5ee9125SBastian Ruppert { 229e5ee9125SBastian Ruppert struct davinci_gpio *gpio8_base = 230e5ee9125SBastian Ruppert (struct davinci_gpio *)DAVINCI_GPIO_BANK8; 231e5ee9125SBastian Ruppert 232e5ee9125SBastian Ruppert /* PinMux for HALTEN */ 233e5ee9125SBastian Ruppert if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0) 234e5ee9125SBastian Ruppert return 1; 235e5ee9125SBastian Ruppert 236e5ee9125SBastian Ruppert /* Set HALTEN to high */ 237e5ee9125SBastian Ruppert writel((readl(&gpio8_base->set_data) | (1 << 6)), 238e5ee9125SBastian Ruppert &gpio8_base->set_data); 239e5ee9125SBastian Ruppert writel((readl(&gpio8_base->dir) & ~(1 << 6)), &gpio8_base->dir); 240e5ee9125SBastian Ruppert 241e5ee9125SBastian Ruppert return 0; 242e5ee9125SBastian Ruppert } 243e5ee9125SBastian Ruppert #endif /* BOARD_LATE_INIT */ 244e5ee9125SBastian Ruppert 245649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC 246649a33e4SStefano Babic 247649a33e4SStefano Babic /* 248649a33e4SStefano Babic * Initializes on-board ethernet controllers. 249649a33e4SStefano Babic */ 250649a33e4SStefano Babic int board_eth_init(bd_t *bis) 251649a33e4SStefano Babic { 252649a33e4SStefano Babic if (!davinci_emac_initialize()) { 253649a33e4SStefano Babic printf("Error: Ethernet init failed!\n"); 254649a33e4SStefano Babic return -1; 255649a33e4SStefano Babic } 256649a33e4SStefano Babic 257649a33e4SStefano Babic /* 258649a33e4SStefano Babic * This board has a RMII PHY. However, the MDC line on the SOM 259649a33e4SStefano Babic * must not be disabled (there is no MII PHY on the 260649a33e4SStefano Babic * baseboard) via the GPIO2[6], because this pin 261649a33e4SStefano Babic * disables at the same time the SPI flash. 262649a33e4SStefano Babic */ 263649a33e4SStefano Babic 264649a33e4SStefano Babic return 0; 265649a33e4SStefano Babic } 266649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */ 267