189b765c7SSudhakar Rajashekhara /* 289b765c7SSudhakar Rajashekhara * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 389b765c7SSudhakar Rajashekhara * 489b765c7SSudhakar Rajashekhara * Based on da830evm.c. Original Copyrights follow: 589b765c7SSudhakar Rajashekhara * 689b765c7SSudhakar Rajashekhara * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com> 789b765c7SSudhakar Rajashekhara * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> 889b765c7SSudhakar Rajashekhara * 989b765c7SSudhakar Rajashekhara * This program is free software; you can redistribute it and/or modify 1089b765c7SSudhakar Rajashekhara * it under the terms of the GNU General Public License as published by 1189b765c7SSudhakar Rajashekhara * the Free Software Foundation; either version 2 of the License, or 1289b765c7SSudhakar Rajashekhara * (at your option) any later version. 1389b765c7SSudhakar Rajashekhara * 1489b765c7SSudhakar Rajashekhara * This program is distributed in the hope that it will be useful, 1589b765c7SSudhakar Rajashekhara * but WITHOUT ANY WARRANTY; without even the implied warranty of 1689b765c7SSudhakar Rajashekhara * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1789b765c7SSudhakar Rajashekhara * GNU General Public License for more details. 1889b765c7SSudhakar Rajashekhara * 1989b765c7SSudhakar Rajashekhara * You should have received a copy of the GNU General Public License 2089b765c7SSudhakar Rajashekhara * along with this program; if not, write to the Free Software 2189b765c7SSudhakar Rajashekhara * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 2289b765c7SSudhakar Rajashekhara */ 2389b765c7SSudhakar Rajashekhara 2489b765c7SSudhakar Rajashekhara #include <common.h> 2589b765c7SSudhakar Rajashekhara #include <i2c.h> 263d248d37SBen Gardiner #include <net.h> 273d248d37SBen Gardiner #include <netdev.h> 2838fed6eeSHadli, Manjunath #include <spi.h> 2938fed6eeSHadli, Manjunath #include <spi_flash.h> 3089b765c7SSudhakar Rajashekhara #include <asm/arch/hardware.h> 31a3f88293SBen Gardiner #include <asm/arch/emif_defs.h> 323d248d37SBen Gardiner #include <asm/arch/emac_defs.h> 3352b0f877SChristian Riesch #include <asm/arch/pinmux_defs.h> 3489b765c7SSudhakar Rajashekhara #include <asm/io.h> 35d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h> 3638fed6eeSHadli, Manjunath #include <asm/errno.h> 37cf2c24e3SNagabhushana Netagunte #include <hwconfig.h> 3889b765c7SSudhakar Rajashekhara 3989b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR; 4089b765c7SSudhakar Rajashekhara 413d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 42d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 43d2607401SSudhakar Rajashekhara #define HAS_RMII 1 44d2607401SSudhakar Rajashekhara #else 45d2607401SSudhakar Rajashekhara #define HAS_RMII 0 46d2607401SSudhakar Rajashekhara #endif 47d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */ 48d2607401SSudhakar Rajashekhara 4938fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_BUS 0 5038fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_CS 0 5138fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED 5238fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3 5338fed6eeSHadli, Manjunath 5438fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K) 5538fed6eeSHadli, Manjunath 5638fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH 5738fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr) 5838fed6eeSHadli, Manjunath { 5938fed6eeSHadli, Manjunath struct spi_flash *flash; 6038fed6eeSHadli, Manjunath int ret; 6138fed6eeSHadli, Manjunath 6238fed6eeSHadli, Manjunath flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS, 6338fed6eeSHadli, Manjunath CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE); 6438fed6eeSHadli, Manjunath if (!flash) { 6538fed6eeSHadli, Manjunath printf("Error - unable to probe SPI flash.\n"); 6638fed6eeSHadli, Manjunath return -1; 6738fed6eeSHadli, Manjunath } 6838fed6eeSHadli, Manjunath 6938fed6eeSHadli, Manjunath ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr); 7038fed6eeSHadli, Manjunath if (ret) { 7138fed6eeSHadli, Manjunath printf("Error - unable to read MAC address from SPI flash.\n"); 7238fed6eeSHadli, Manjunath return -1; 7338fed6eeSHadli, Manjunath } 7438fed6eeSHadli, Manjunath 7538fed6eeSHadli, Manjunath return ret; 7638fed6eeSHadli, Manjunath } 7738fed6eeSHadli, Manjunath #endif 7838fed6eeSHadli, Manjunath 79cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id) 80cf2c24e3SNagabhushana Netagunte { 81cf2c24e3SNagabhushana Netagunte dv_reg_p mdstat, mdctl, ptstat, ptcmd; 82cf2c24e3SNagabhushana Netagunte struct davinci_psc_regs *psc_regs; 83cf2c24e3SNagabhushana Netagunte 84cf2c24e3SNagabhushana Netagunte psc_regs = davinci_psc0_regs; 85cf2c24e3SNagabhushana Netagunte mdstat = &psc_regs->psc0.mdstat[id]; 86cf2c24e3SNagabhushana Netagunte mdctl = &psc_regs->psc0.mdctl[id]; 87cf2c24e3SNagabhushana Netagunte ptstat = &psc_regs->ptstat; 88cf2c24e3SNagabhushana Netagunte ptcmd = &psc_regs->ptcmd; 89cf2c24e3SNagabhushana Netagunte 90cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain)) 91cf2c24e3SNagabhushana Netagunte ; 92cf2c24e3SNagabhushana Netagunte 93cf2c24e3SNagabhushana Netagunte if ((*mdstat & 0x1f) == 0x03) 94cf2c24e3SNagabhushana Netagunte return; /* Already on and enabled */ 95cf2c24e3SNagabhushana Netagunte 96cf2c24e3SNagabhushana Netagunte *mdctl |= 0x03; 97cf2c24e3SNagabhushana Netagunte 98cf2c24e3SNagabhushana Netagunte *ptcmd = 0x1 << domain; 99cf2c24e3SNagabhushana Netagunte 100cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain)) 101cf2c24e3SNagabhushana Netagunte ; 102cf2c24e3SNagabhushana Netagunte while ((*mdstat & 0x1f) != 0x03) 103cf2c24e3SNagabhushana Netagunte ; /* Probably an overkill... */ 104cf2c24e3SNagabhushana Netagunte } 105cf2c24e3SNagabhushana Netagunte 106cf2c24e3SNagabhushana Netagunte static void dspwake(void) 107cf2c24e3SNagabhushana Netagunte { 108cf2c24e3SNagabhushana Netagunte unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE; 109cf2c24e3SNagabhushana Netagunte u32 val; 110cf2c24e3SNagabhushana Netagunte 111cf2c24e3SNagabhushana Netagunte /* if the device is ARM only, return */ 112cf2c24e3SNagabhushana Netagunte if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10) 113cf2c24e3SNagabhushana Netagunte return; 114cf2c24e3SNagabhushana Netagunte 115cf2c24e3SNagabhushana Netagunte if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL)) 116cf2c24e3SNagabhushana Netagunte return; 117cf2c24e3SNagabhushana Netagunte 118cf2c24e3SNagabhushana Netagunte *resetvect++ = 0x1E000; /* DSP Idle */ 119cf2c24e3SNagabhushana Netagunte /* clear out the next 10 words as NOP */ 120cf2c24e3SNagabhushana Netagunte memset(resetvect, 0, sizeof(unsigned) *10); 121cf2c24e3SNagabhushana Netagunte 122cf2c24e3SNagabhushana Netagunte /* setup the DSP reset vector */ 123cf2c24e3SNagabhushana Netagunte writel(DAVINCI_L3CBARAM_BASE, HOST1CFG); 124cf2c24e3SNagabhushana Netagunte 125cf2c24e3SNagabhushana Netagunte dsp_lpsc_on(1, DAVINCI_LPSC_GEM); 126cf2c24e3SNagabhushana Netagunte val = readl(PSC0_MDCTL + (15 * 4)); 127cf2c24e3SNagabhushana Netagunte val |= 0x100; 128cf2c24e3SNagabhushana Netagunte writel(val, (PSC0_MDCTL + (15 * 4))); 129cf2c24e3SNagabhushana Netagunte } 130cf2c24e3SNagabhushana Netagunte 131cf2c24e3SNagabhushana Netagunte int misc_init_r(void) 132cf2c24e3SNagabhushana Netagunte { 133cf2c24e3SNagabhushana Netagunte dspwake(); 13438fed6eeSHadli, Manjunath 135*206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM) 136*206a1038SHadli, Manjunath 13738fed6eeSHadli, Manjunath uchar env_enetaddr[6]; 13838fed6eeSHadli, Manjunath int enetaddr_found; 139*206a1038SHadli, Manjunath 140*206a1038SHadli, Manjunath enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr); 141*206a1038SHadli, Manjunath 142*206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH 14338fed6eeSHadli, Manjunath int spi_mac_read; 14438fed6eeSHadli, Manjunath uchar buff[6]; 14538fed6eeSHadli, Manjunath 14638fed6eeSHadli, Manjunath spi_mac_read = get_mac_addr(buff); 14738fed6eeSHadli, Manjunath 14838fed6eeSHadli, Manjunath /* 14938fed6eeSHadli, Manjunath * MAC address not present in the environment 15038fed6eeSHadli, Manjunath * try and read the MAC address from SPI flash 15138fed6eeSHadli, Manjunath * and set it. 15238fed6eeSHadli, Manjunath */ 15338fed6eeSHadli, Manjunath if (!enetaddr_found) { 15438fed6eeSHadli, Manjunath if (!spi_mac_read) { 15538fed6eeSHadli, Manjunath if (is_valid_ether_addr(buff)) { 15638fed6eeSHadli, Manjunath if (eth_setenv_enetaddr("ethaddr", buff)) { 15738fed6eeSHadli, Manjunath printf("Warning: Failed to " 15838fed6eeSHadli, Manjunath "set MAC address from SPI flash\n"); 15938fed6eeSHadli, Manjunath } 16038fed6eeSHadli, Manjunath } else { 16138fed6eeSHadli, Manjunath printf("Warning: Invalid " 16238fed6eeSHadli, Manjunath "MAC address read from SPI flash\n"); 16338fed6eeSHadli, Manjunath } 16438fed6eeSHadli, Manjunath } 16538fed6eeSHadli, Manjunath } else { 16638fed6eeSHadli, Manjunath /* 16738fed6eeSHadli, Manjunath * MAC address present in environment compare it with 16838fed6eeSHadli, Manjunath * the MAC address in SPI flash and warn on mismatch 16938fed6eeSHadli, Manjunath */ 17038fed6eeSHadli, Manjunath if (!spi_mac_read && is_valid_ether_addr(buff) && 17138fed6eeSHadli, Manjunath memcmp(env_enetaddr, buff, 6)) 17238fed6eeSHadli, Manjunath printf("Warning: MAC address in SPI flash don't match " 17338fed6eeSHadli, Manjunath "with the MAC address in the environment\n"); 17438fed6eeSHadli, Manjunath printf("Default using MAC address from environment\n"); 17538fed6eeSHadli, Manjunath } 17638fed6eeSHadli, Manjunath #endif 177*206a1038SHadli, Manjunath uint8_t enetaddr[8]; 178*206a1038SHadli, Manjunath int eeprom_mac_read; 179*206a1038SHadli, Manjunath 180*206a1038SHadli, Manjunath /* Read Ethernet MAC address from EEPROM */ 181*206a1038SHadli, Manjunath eeprom_mac_read = dvevm_read_mac_address(enetaddr); 182*206a1038SHadli, Manjunath 183*206a1038SHadli, Manjunath /* 184*206a1038SHadli, Manjunath * MAC address not present in the environment 185*206a1038SHadli, Manjunath * try and read the MAC address from EEPROM flash 186*206a1038SHadli, Manjunath * and set it. 187*206a1038SHadli, Manjunath */ 188*206a1038SHadli, Manjunath if (!enetaddr_found) { 189*206a1038SHadli, Manjunath if (eeprom_mac_read) 190*206a1038SHadli, Manjunath /* Set Ethernet MAC address from EEPROM */ 191*206a1038SHadli, Manjunath davinci_sync_env_enetaddr(enetaddr); 192*206a1038SHadli, Manjunath } else { 193*206a1038SHadli, Manjunath /* 194*206a1038SHadli, Manjunath * MAC address present in environment compare it with 195*206a1038SHadli, Manjunath * the MAC address in EEPROM and warn on mismatch 196*206a1038SHadli, Manjunath */ 197*206a1038SHadli, Manjunath if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6)) 198*206a1038SHadli, Manjunath printf("Warning: MAC address in EEPROM don't match " 199*206a1038SHadli, Manjunath "with the MAC address in the environment\n"); 200*206a1038SHadli, Manjunath printf("Default using MAC address from environment\n"); 201*206a1038SHadli, Manjunath } 202*206a1038SHadli, Manjunath 203*206a1038SHadli, Manjunath #endif 204cf2c24e3SNagabhushana Netagunte return 0; 205cf2c24e3SNagabhushana Netagunte } 206cf2c24e3SNagabhushana Netagunte 20752b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = { 20852b0f877SChristian Riesch #ifdef CONFIG_USE_NOR 20952b0f877SChristian Riesch /* GP0[11] is required for NOR to work on Rev 3 EVMs */ 21052b0f877SChristian Riesch { pinmux(0), 8, 4 }, /* GP0[11] */ 21152b0f877SChristian Riesch #endif 21252b0f877SChristian Riesch }; 21352b0f877SChristian Riesch 2143d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = { 215591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC 21652b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mdio), 21752b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 21852b0f877SChristian Riesch PINMUX_ITEM(emac_pins_rmii), 21952b0f877SChristian Riesch #else 22052b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mii), 22152b0f877SChristian Riesch #endif 222591d8019SChristian Riesch #endif 22389b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH 22452b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_base), 22552b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_scs0), 22689b765c7SSudhakar Rajashekhara #endif 22752b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_txrx), 22852b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_rtscts), 22952b0f877SChristian Riesch PINMUX_ITEM(i2c0_pins), 230756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI 23152b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs3), 23252b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs4), 23352b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nand), 2341506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR) 23552b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs2), 23652b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nor), 237756d1fe7SBen Gardiner #endif 23852b0f877SChristian Riesch PINMUX_ITEM(gpio_pins), 23989b765c7SSudhakar Rajashekhara }; 24089b765c7SSudhakar Rajashekhara 2413d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes); 2423d2c8e6cSChristian Riesch 2436b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = { 24489b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ 24589b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_SPI1 }, /* Serial Flash */ 24689b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_EMAC }, /* image download */ 24789b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_UART2 }, /* console */ 24889b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_GPIO }, 24989b765c7SSudhakar Rajashekhara }; 25089b765c7SSudhakar Rajashekhara 2516b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc); 2526b873dcaSSughosh Ganu 2534f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK 2544f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000 2554f6fc15bSSekhar Nori #endif 2564f6fc15bSSekhar Nori 257754f8cb6SManjunath Hadli #define REV_AM18X_EVM 0x100 258754f8cb6SManjunath Hadli 2594f6fc15bSSekhar Nori /* 2604f6fc15bSSekhar Nori * get_board_rev() - setup to pass kernel board revision information 2614f6fc15bSSekhar Nori * Returns: 2624f6fc15bSSekhar Nori * bit[0-3] Maximum cpu clock rate supported by onboard SoC 2634f6fc15bSSekhar Nori * 0000b - 300 MHz 2644f6fc15bSSekhar Nori * 0001b - 372 MHz 2654f6fc15bSSekhar Nori * 0010b - 408 MHz 2664f6fc15bSSekhar Nori * 0011b - 456 MHz 2674f6fc15bSSekhar Nori */ 2684f6fc15bSSekhar Nori u32 get_board_rev(void) 2694f6fc15bSSekhar Nori { 2704f6fc15bSSekhar Nori char *s; 2714f6fc15bSSekhar Nori u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK; 2724f6fc15bSSekhar Nori u32 rev = 0; 2734f6fc15bSSekhar Nori 2744f6fc15bSSekhar Nori s = getenv("maxcpuclk"); 2754f6fc15bSSekhar Nori if (s) 2764f6fc15bSSekhar Nori maxcpuclk = simple_strtoul(s, NULL, 10); 2774f6fc15bSSekhar Nori 2784f6fc15bSSekhar Nori if (maxcpuclk >= 456000000) 2794f6fc15bSSekhar Nori rev = 3; 2804f6fc15bSSekhar Nori else if (maxcpuclk >= 408000000) 2814f6fc15bSSekhar Nori rev = 2; 2824f6fc15bSSekhar Nori else if (maxcpuclk >= 372000000) 2834f6fc15bSSekhar Nori rev = 1; 284754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM 285754f8cb6SManjunath Hadli rev |= REV_AM18X_EVM; 286754f8cb6SManjunath Hadli #endif 2874f6fc15bSSekhar Nori return rev; 2884f6fc15bSSekhar Nori } 2894f6fc15bSSekhar Nori 290ae5c77ddSChristian Riesch int board_early_init_f(void) 291ae5c77ddSChristian Riesch { 292ae5c77ddSChristian Riesch /* 293ae5c77ddSChristian Riesch * Power on required peripherals 294ae5c77ddSChristian Riesch * ARM does not have access by default to PSC0 and PSC1 295ae5c77ddSChristian Riesch * assuming here that the DSP bootloader has set the IOPU 296ae5c77ddSChristian Riesch * such that PSC access is available to ARM 297ae5c77ddSChristian Riesch */ 298ae5c77ddSChristian Riesch if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) 299ae5c77ddSChristian Riesch return 1; 300ae5c77ddSChristian Riesch 301ae5c77ddSChristian Riesch return 0; 302ae5c77ddSChristian Riesch } 303ae5c77ddSChristian Riesch 30489b765c7SSudhakar Rajashekhara int board_init(void) 30589b765c7SSudhakar Rajashekhara { 3066f0d7ae2SWolfgang Denk #ifdef CONFIG_USE_NOR 3070f3d6b06SNagabhushana Netagunte u32 val; 3086f0d7ae2SWolfgang Denk #endif 3096f0d7ae2SWolfgang Denk 31089b765c7SSudhakar Rajashekhara #ifndef CONFIG_USE_IRQ 31189b765c7SSudhakar Rajashekhara irq_init(); 31289b765c7SSudhakar Rajashekhara #endif 31389b765c7SSudhakar Rajashekhara 314a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI 315a3f88293SBen Gardiner /* 316a3f88293SBen Gardiner * NAND CS setup - cycle counts based on da850evm NAND timings in the 317a3f88293SBen Gardiner * Linux kernel @ 25MHz EMIFA 318a3f88293SBen Gardiner */ 319a3f88293SBen Gardiner writel((DAVINCI_ABCR_WSETUP(0) | 32024a514c4SBen Gardiner DAVINCI_ABCR_WSTROBE(1) | 321a3f88293SBen Gardiner DAVINCI_ABCR_WHOLD(0) | 322a3f88293SBen Gardiner DAVINCI_ABCR_RSETUP(0) | 323a3f88293SBen Gardiner DAVINCI_ABCR_RSTROBE(1) | 324a3f88293SBen Gardiner DAVINCI_ABCR_RHOLD(0) | 32524a514c4SBen Gardiner DAVINCI_ABCR_TA(1) | 326a3f88293SBen Gardiner DAVINCI_ABCR_ASIZE_8BIT), 327a3f88293SBen Gardiner &davinci_emif_regs->ab2cr); /* CS3 */ 328a3f88293SBen Gardiner #endif 329a3f88293SBen Gardiner 33089b765c7SSudhakar Rajashekhara /* arch number of the board */ 33189b765c7SSudhakar Rajashekhara gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM; 33289b765c7SSudhakar Rajashekhara 33389b765c7SSudhakar Rajashekhara /* address of boot parameters */ 33489b765c7SSudhakar Rajashekhara gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; 33589b765c7SSudhakar Rajashekhara 33689b765c7SSudhakar Rajashekhara /* setup the SUSPSRC for ARM to control emulation suspend */ 33789b765c7SSudhakar Rajashekhara writel(readl(&davinci_syscfg_regs->suspsrc) & 33889b765c7SSudhakar Rajashekhara ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | 33989b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | 34089b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_UART2), 34189b765c7SSudhakar Rajashekhara &davinci_syscfg_regs->suspsrc); 34289b765c7SSudhakar Rajashekhara 34389b765c7SSudhakar Rajashekhara /* configure pinmux settings */ 34489b765c7SSudhakar Rajashekhara if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) 34589b765c7SSudhakar Rajashekhara return 1; 34689b765c7SSudhakar Rajashekhara 3470f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR 3480f3d6b06SNagabhushana Netagunte /* Set the GPIO direction as output */ 3490f3d6b06SNagabhushana Netagunte clrbits_be32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11)); 3500f3d6b06SNagabhushana Netagunte 3510f3d6b06SNagabhushana Netagunte /* Set the output as low */ 3520f3d6b06SNagabhushana Netagunte val = readl(GPIO_BANK0_REG_SET_ADDR); 3530f3d6b06SNagabhushana Netagunte val |= (0x01 << 11); 3540f3d6b06SNagabhushana Netagunte writel(val, GPIO_BANK0_REG_CLR_ADDR); 3550f3d6b06SNagabhushana Netagunte #endif 3560f3d6b06SNagabhushana Netagunte 3573d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 3586d1c649fSStefano Babic davinci_emac_mii_mode_sel(HAS_RMII); 3593d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */ 3603d248d37SBen Gardiner 36189b765c7SSudhakar Rajashekhara /* enable the console UART */ 36289b765c7SSudhakar Rajashekhara writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | 36389b765c7SSudhakar Rajashekhara DAVINCI_UART_PWREMU_MGMT_UTRST), 36489b765c7SSudhakar Rajashekhara &davinci_uart2_ctrl_regs->pwremu_mgmt); 36589b765c7SSudhakar Rajashekhara 36689b765c7SSudhakar Rajashekhara return 0; 36789b765c7SSudhakar Rajashekhara } 3683d248d37SBen Gardiner 3693d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 3703d248d37SBen Gardiner 371d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 372d2607401SSudhakar Rajashekhara /** 373d2607401SSudhakar Rajashekhara * rmii_hw_init 374d2607401SSudhakar Rajashekhara * 375d2607401SSudhakar Rajashekhara * DA850/OMAP-L138 EVM can interface to a daughter card for 376d2607401SSudhakar Rajashekhara * additional features. This card has an I2C GPIO Expander TCA6416 377d2607401SSudhakar Rajashekhara * to select the required functions like camera, RMII Ethernet, 378d2607401SSudhakar Rajashekhara * character LCD, video. 379d2607401SSudhakar Rajashekhara * 380d2607401SSudhakar Rajashekhara * Initialization of the expander involves configuring the 381d2607401SSudhakar Rajashekhara * polarity and direction of the ports. P07-P05 are used here. 382d2607401SSudhakar Rajashekhara * These ports are connected to a Mux chip which enables only one 383d2607401SSudhakar Rajashekhara * functionality at a time. 384d2607401SSudhakar Rajashekhara * 385d2607401SSudhakar Rajashekhara * For RMII phy to respond, the MII MDIO clock has to be disabled 386d2607401SSudhakar Rajashekhara * since both the PHY devices have address as zero. The MII MDIO 387d2607401SSudhakar Rajashekhara * clock is controlled via GPIO2[6]. 388d2607401SSudhakar Rajashekhara * 389d2607401SSudhakar Rajashekhara * This code is valid for Beta version of the hardware 390d2607401SSudhakar Rajashekhara */ 391d2607401SSudhakar Rajashekhara int rmii_hw_init(void) 392d2607401SSudhakar Rajashekhara { 393d2607401SSudhakar Rajashekhara const struct pinmux_config gpio_pins[] = { 394d2607401SSudhakar Rajashekhara { pinmux(6), 8, 1 } 395d2607401SSudhakar Rajashekhara }; 396d2607401SSudhakar Rajashekhara u_int8_t buf[2]; 397d2607401SSudhakar Rajashekhara unsigned int temp; 398d2607401SSudhakar Rajashekhara int ret; 399d2607401SSudhakar Rajashekhara 400d2607401SSudhakar Rajashekhara /* PinMux for GPIO */ 401d2607401SSudhakar Rajashekhara if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0) 402d2607401SSudhakar Rajashekhara return 1; 403d2607401SSudhakar Rajashekhara 404d2607401SSudhakar Rajashekhara /* I2C Exapnder configuration */ 405d2607401SSudhakar Rajashekhara /* Set polarity to non-inverted */ 406d2607401SSudhakar Rajashekhara buf[0] = 0x0; 407d2607401SSudhakar Rajashekhara buf[1] = 0x0; 408d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2); 409d2607401SSudhakar Rajashekhara if (ret) { 410d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 411d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 412d2607401SSudhakar Rajashekhara return ret; 413d2607401SSudhakar Rajashekhara } 414d2607401SSudhakar Rajashekhara 415d2607401SSudhakar Rajashekhara /* Configure P07-P05 as outputs */ 416d2607401SSudhakar Rajashekhara buf[0] = 0x1f; 417d2607401SSudhakar Rajashekhara buf[1] = 0xff; 418d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2); 419d2607401SSudhakar Rajashekhara if (ret) { 420d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 421d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 422d2607401SSudhakar Rajashekhara } 423d2607401SSudhakar Rajashekhara 424d2607401SSudhakar Rajashekhara /* For Ethernet RMII selection 425d2607401SSudhakar Rajashekhara * P07(SelA)=0 426d2607401SSudhakar Rajashekhara * P06(SelB)=1 427d2607401SSudhakar Rajashekhara * P05(SelC)=1 428d2607401SSudhakar Rajashekhara */ 429d2607401SSudhakar Rajashekhara if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) { 430d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x read FAILED!!!\n", 431d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 432d2607401SSudhakar Rajashekhara } 433d2607401SSudhakar Rajashekhara 434d2607401SSudhakar Rajashekhara buf[0] &= 0x1f; 435d2607401SSudhakar Rajashekhara buf[0] |= (0 << 7) | (1 << 6) | (1 << 5); 436d2607401SSudhakar Rajashekhara if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) { 437d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 438d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 439d2607401SSudhakar Rajashekhara } 440d2607401SSudhakar Rajashekhara 441d2607401SSudhakar Rajashekhara /* Set the output as high */ 442d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_SET_ADDR); 443d2607401SSudhakar Rajashekhara temp |= (0x01 << 6); 444d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_SET_ADDR) = temp; 445d2607401SSudhakar Rajashekhara 446d2607401SSudhakar Rajashekhara /* Set the GPIO direction as output */ 447d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_DIR_ADDR); 448d2607401SSudhakar Rajashekhara temp &= ~(0x01 << 6); 449d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_DIR_ADDR) = temp; 450d2607401SSudhakar Rajashekhara 451d2607401SSudhakar Rajashekhara return 0; 452d2607401SSudhakar Rajashekhara } 453d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */ 454d2607401SSudhakar Rajashekhara 4553d248d37SBen Gardiner /* 4563d248d37SBen Gardiner * Initializes on-board ethernet controllers. 4573d248d37SBen Gardiner */ 4583d248d37SBen Gardiner int board_eth_init(bd_t *bis) 4593d248d37SBen Gardiner { 460d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 461d2607401SSudhakar Rajashekhara /* Select RMII fucntion through the expander */ 462d2607401SSudhakar Rajashekhara if (rmii_hw_init()) 463d2607401SSudhakar Rajashekhara printf("RMII hardware init failed!!!\n"); 464d2607401SSudhakar Rajashekhara #endif 4653d248d37SBen Gardiner if (!davinci_emac_initialize()) { 4663d248d37SBen Gardiner printf("Error: Ethernet init failed!\n"); 4673d248d37SBen Gardiner return -1; 4683d248d37SBen Gardiner } 4693d248d37SBen Gardiner 4703d248d37SBen Gardiner return 0; 4713d248d37SBen Gardiner } 4723d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */ 473