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 * 91a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 1089b765c7SSudhakar Rajashekhara */ 1189b765c7SSudhakar Rajashekhara 1289b765c7SSudhakar Rajashekhara #include <common.h> 1389b765c7SSudhakar Rajashekhara #include <i2c.h> 143d248d37SBen Gardiner #include <net.h> 153d248d37SBen Gardiner #include <netdev.h> 1638fed6eeSHadli, Manjunath #include <spi.h> 1738fed6eeSHadli, Manjunath #include <spi_flash.h> 1889b765c7SSudhakar Rajashekhara #include <asm/arch/hardware.h> 193e01ed00SKhoronzhuk, Ivan #include <asm/ti-common/davinci_nand.h> 203d248d37SBen Gardiner #include <asm/arch/emac_defs.h> 2152b0f877SChristian Riesch #include <asm/arch/pinmux_defs.h> 2289b765c7SSudhakar Rajashekhara #include <asm/io.h> 23d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h> 241221ce45SMasahiro Yamada #include <linux/errno.h> 25cf2c24e3SNagabhushana Netagunte #include <hwconfig.h> 26c62db35dSSimon Glass #include <asm/mach-types.h> 2789b765c7SSudhakar Rajashekhara 281d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 29ecc98ec1SLad, Prabhakar #include <mmc.h> 30ecc98ec1SLad, Prabhakar #include <asm/arch/sdmmc_defs.h> 31ecc98ec1SLad, Prabhakar #endif 32ecc98ec1SLad, Prabhakar 3389b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR; 3489b765c7SSudhakar Rajashekhara 353d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 36d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 37d2607401SSudhakar Rajashekhara #define HAS_RMII 1 38d2607401SSudhakar Rajashekhara #else 39d2607401SSudhakar Rajashekhara #define HAS_RMII 0 40d2607401SSudhakar Rajashekhara #endif 41d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */ 42d2607401SSudhakar Rajashekhara 4338fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_BUS 0 4438fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_CS 0 4538fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED 4638fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3 4738fed6eeSHadli, Manjunath 4838fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K) 4938fed6eeSHadli, Manjunath 5038fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH 5138fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr) 5238fed6eeSHadli, Manjunath { 5338fed6eeSHadli, Manjunath struct spi_flash *flash; 5438fed6eeSHadli, Manjunath int ret; 5538fed6eeSHadli, Manjunath 5638fed6eeSHadli, Manjunath flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS, 5738fed6eeSHadli, Manjunath CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE); 5838fed6eeSHadli, Manjunath if (!flash) { 5938fed6eeSHadli, Manjunath printf("Error - unable to probe SPI flash.\n"); 6038fed6eeSHadli, Manjunath return -1; 6138fed6eeSHadli, Manjunath } 6238fed6eeSHadli, Manjunath 6338fed6eeSHadli, Manjunath ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr); 6438fed6eeSHadli, Manjunath if (ret) { 6538fed6eeSHadli, Manjunath printf("Error - unable to read MAC address from SPI flash.\n"); 6638fed6eeSHadli, Manjunath return -1; 6738fed6eeSHadli, Manjunath } 6838fed6eeSHadli, Manjunath 6938fed6eeSHadli, Manjunath return ret; 7038fed6eeSHadli, Manjunath } 7138fed6eeSHadli, Manjunath #endif 7238fed6eeSHadli, Manjunath 73cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id) 74cf2c24e3SNagabhushana Netagunte { 75cf2c24e3SNagabhushana Netagunte dv_reg_p mdstat, mdctl, ptstat, ptcmd; 76cf2c24e3SNagabhushana Netagunte struct davinci_psc_regs *psc_regs; 77cf2c24e3SNagabhushana Netagunte 78cf2c24e3SNagabhushana Netagunte psc_regs = davinci_psc0_regs; 79cf2c24e3SNagabhushana Netagunte mdstat = &psc_regs->psc0.mdstat[id]; 80cf2c24e3SNagabhushana Netagunte mdctl = &psc_regs->psc0.mdctl[id]; 81cf2c24e3SNagabhushana Netagunte ptstat = &psc_regs->ptstat; 82cf2c24e3SNagabhushana Netagunte ptcmd = &psc_regs->ptcmd; 83cf2c24e3SNagabhushana Netagunte 84cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain)) 85cf2c24e3SNagabhushana Netagunte ; 86cf2c24e3SNagabhushana Netagunte 87cf2c24e3SNagabhushana Netagunte if ((*mdstat & 0x1f) == 0x03) 88cf2c24e3SNagabhushana Netagunte return; /* Already on and enabled */ 89cf2c24e3SNagabhushana Netagunte 90cf2c24e3SNagabhushana Netagunte *mdctl |= 0x03; 91cf2c24e3SNagabhushana Netagunte 92cf2c24e3SNagabhushana Netagunte *ptcmd = 0x1 << domain; 93cf2c24e3SNagabhushana Netagunte 94cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain)) 95cf2c24e3SNagabhushana Netagunte ; 96cf2c24e3SNagabhushana Netagunte while ((*mdstat & 0x1f) != 0x03) 97cf2c24e3SNagabhushana Netagunte ; /* Probably an overkill... */ 98cf2c24e3SNagabhushana Netagunte } 99cf2c24e3SNagabhushana Netagunte 100cf2c24e3SNagabhushana Netagunte static void dspwake(void) 101cf2c24e3SNagabhushana Netagunte { 102cf2c24e3SNagabhushana Netagunte unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE; 103cf2c24e3SNagabhushana Netagunte u32 val; 104cf2c24e3SNagabhushana Netagunte 105cf2c24e3SNagabhushana Netagunte /* if the device is ARM only, return */ 106cf2c24e3SNagabhushana Netagunte if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10) 107cf2c24e3SNagabhushana Netagunte return; 108cf2c24e3SNagabhushana Netagunte 109cf2c24e3SNagabhushana Netagunte if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL)) 110cf2c24e3SNagabhushana Netagunte return; 111cf2c24e3SNagabhushana Netagunte 112cf2c24e3SNagabhushana Netagunte *resetvect++ = 0x1E000; /* DSP Idle */ 113cf2c24e3SNagabhushana Netagunte /* clear out the next 10 words as NOP */ 114cf2c24e3SNagabhushana Netagunte memset(resetvect, 0, sizeof(unsigned) *10); 115cf2c24e3SNagabhushana Netagunte 116cf2c24e3SNagabhushana Netagunte /* setup the DSP reset vector */ 117cf2c24e3SNagabhushana Netagunte writel(DAVINCI_L3CBARAM_BASE, HOST1CFG); 118cf2c24e3SNagabhushana Netagunte 119cf2c24e3SNagabhushana Netagunte dsp_lpsc_on(1, DAVINCI_LPSC_GEM); 120cf2c24e3SNagabhushana Netagunte val = readl(PSC0_MDCTL + (15 * 4)); 121cf2c24e3SNagabhushana Netagunte val |= 0x100; 122cf2c24e3SNagabhushana Netagunte writel(val, (PSC0_MDCTL + (15 * 4))); 123cf2c24e3SNagabhushana Netagunte } 124cf2c24e3SNagabhushana Netagunte 125cf2c24e3SNagabhushana Netagunte int misc_init_r(void) 126cf2c24e3SNagabhushana Netagunte { 127cf2c24e3SNagabhushana Netagunte dspwake(); 12838fed6eeSHadli, Manjunath 129206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM) 130206a1038SHadli, Manjunath 13138fed6eeSHadli, Manjunath uchar env_enetaddr[6]; 13238fed6eeSHadli, Manjunath int enetaddr_found; 133206a1038SHadli, Manjunath 134206a1038SHadli, Manjunath enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr); 135206a1038SHadli, Manjunath 136206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH 13738fed6eeSHadli, Manjunath int spi_mac_read; 13838fed6eeSHadli, Manjunath uchar buff[6]; 13938fed6eeSHadli, Manjunath 14038fed6eeSHadli, Manjunath spi_mac_read = get_mac_addr(buff); 14138fed6eeSHadli, Manjunath 14238fed6eeSHadli, Manjunath /* 14338fed6eeSHadli, Manjunath * MAC address not present in the environment 14438fed6eeSHadli, Manjunath * try and read the MAC address from SPI flash 14538fed6eeSHadli, Manjunath * and set it. 14638fed6eeSHadli, Manjunath */ 14738fed6eeSHadli, Manjunath if (!enetaddr_found) { 14838fed6eeSHadli, Manjunath if (!spi_mac_read) { 1490adb5b76SJoe Hershberger if (is_valid_ethaddr(buff)) { 150*fd1e959eSSimon Glass if (eth_env_set_enetaddr("ethaddr", buff)) { 15138fed6eeSHadli, Manjunath printf("Warning: Failed to " 15238fed6eeSHadli, Manjunath "set MAC address from SPI flash\n"); 15338fed6eeSHadli, Manjunath } 15438fed6eeSHadli, Manjunath } else { 15538fed6eeSHadli, Manjunath printf("Warning: Invalid " 15638fed6eeSHadli, Manjunath "MAC address read from SPI flash\n"); 15738fed6eeSHadli, Manjunath } 15838fed6eeSHadli, Manjunath } 15938fed6eeSHadli, Manjunath } else { 16038fed6eeSHadli, Manjunath /* 16138fed6eeSHadli, Manjunath * MAC address present in environment compare it with 16238fed6eeSHadli, Manjunath * the MAC address in SPI flash and warn on mismatch 16338fed6eeSHadli, Manjunath */ 1640adb5b76SJoe Hershberger if (!spi_mac_read && is_valid_ethaddr(buff) && 16538fed6eeSHadli, Manjunath memcmp(env_enetaddr, buff, 6)) 16638fed6eeSHadli, Manjunath printf("Warning: MAC address in SPI flash don't match " 16738fed6eeSHadli, Manjunath "with the MAC address in the environment\n"); 16838fed6eeSHadli, Manjunath printf("Default using MAC address from environment\n"); 16938fed6eeSHadli, Manjunath } 17038fed6eeSHadli, Manjunath #endif 171206a1038SHadli, Manjunath uint8_t enetaddr[8]; 172206a1038SHadli, Manjunath int eeprom_mac_read; 173206a1038SHadli, Manjunath 174206a1038SHadli, Manjunath /* Read Ethernet MAC address from EEPROM */ 175206a1038SHadli, Manjunath eeprom_mac_read = dvevm_read_mac_address(enetaddr); 176206a1038SHadli, Manjunath 177206a1038SHadli, Manjunath /* 178206a1038SHadli, Manjunath * MAC address not present in the environment 179206a1038SHadli, Manjunath * try and read the MAC address from EEPROM flash 180206a1038SHadli, Manjunath * and set it. 181206a1038SHadli, Manjunath */ 182206a1038SHadli, Manjunath if (!enetaddr_found) { 183206a1038SHadli, Manjunath if (eeprom_mac_read) 184206a1038SHadli, Manjunath /* Set Ethernet MAC address from EEPROM */ 185206a1038SHadli, Manjunath davinci_sync_env_enetaddr(enetaddr); 186206a1038SHadli, Manjunath } else { 187206a1038SHadli, Manjunath /* 188206a1038SHadli, Manjunath * MAC address present in environment compare it with 189206a1038SHadli, Manjunath * the MAC address in EEPROM and warn on mismatch 190206a1038SHadli, Manjunath */ 191206a1038SHadli, Manjunath if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6)) 192206a1038SHadli, Manjunath printf("Warning: MAC address in EEPROM don't match " 193206a1038SHadli, Manjunath "with the MAC address in the environment\n"); 194206a1038SHadli, Manjunath printf("Default using MAC address from environment\n"); 195206a1038SHadli, Manjunath } 196206a1038SHadli, Manjunath 197206a1038SHadli, Manjunath #endif 198cf2c24e3SNagabhushana Netagunte return 0; 199cf2c24e3SNagabhushana Netagunte } 200cf2c24e3SNagabhushana Netagunte 2011d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 202ecc98ec1SLad, Prabhakar static struct davinci_mmc mmc_sd0 = { 203ecc98ec1SLad, Prabhakar .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE, 204ecc98ec1SLad, Prabhakar .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */ 205ecc98ec1SLad, Prabhakar .voltages = MMC_VDD_32_33 | MMC_VDD_33_34, 206ecc98ec1SLad, Prabhakar .version = MMC_CTLR_VERSION_2, 207ecc98ec1SLad, Prabhakar }; 208ecc98ec1SLad, Prabhakar 209ecc98ec1SLad, Prabhakar int board_mmc_init(bd_t *bis) 210ecc98ec1SLad, Prabhakar { 211ecc98ec1SLad, Prabhakar mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID); 212ecc98ec1SLad, Prabhakar 213ecc98ec1SLad, Prabhakar /* Add slot-0 to mmc subsystem */ 214ecc98ec1SLad, Prabhakar return davinci_mmc_init(bis, &mmc_sd0); 215ecc98ec1SLad, Prabhakar } 216ecc98ec1SLad, Prabhakar #endif 217ecc98ec1SLad, Prabhakar 21852b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = { 21952b0f877SChristian Riesch #ifdef CONFIG_USE_NOR 22052b0f877SChristian Riesch /* GP0[11] is required for NOR to work on Rev 3 EVMs */ 22152b0f877SChristian Riesch { pinmux(0), 8, 4 }, /* GP0[11] */ 22252b0f877SChristian Riesch #endif 2231d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 224ecc98ec1SLad, Prabhakar /* GP0[11] is required for SD to work on Rev 3 EVMs */ 225ecc98ec1SLad, Prabhakar { pinmux(0), 8, 4 }, /* GP0[11] */ 226ecc98ec1SLad, Prabhakar #endif 22752b0f877SChristian Riesch }; 22852b0f877SChristian Riesch 2293d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = { 230591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC 23152b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mdio), 23252b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 23352b0f877SChristian Riesch PINMUX_ITEM(emac_pins_rmii), 23452b0f877SChristian Riesch #else 23552b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mii), 23652b0f877SChristian Riesch #endif 237591d8019SChristian Riesch #endif 23889b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH 23952b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_base), 24052b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_scs0), 24189b765c7SSudhakar Rajashekhara #endif 24252b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_txrx), 24352b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_rtscts), 24452b0f877SChristian Riesch PINMUX_ITEM(i2c0_pins), 245756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI 24652b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs3), 24752b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs4), 24852b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nand), 2491506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR) 25052b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs2), 25152b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nor), 252756d1fe7SBen Gardiner #endif 25352b0f877SChristian Riesch PINMUX_ITEM(gpio_pins), 2541d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 255ecc98ec1SLad, Prabhakar PINMUX_ITEM(mmc0_pins), 256ecc98ec1SLad, Prabhakar #endif 25789b765c7SSudhakar Rajashekhara }; 25889b765c7SSudhakar Rajashekhara 2593d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes); 2603d2c8e6cSChristian Riesch 2616b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = { 26289b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ 26389b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_SPI1 }, /* Serial Flash */ 26489b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_EMAC }, /* image download */ 26589b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_UART2 }, /* console */ 26689b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_GPIO }, 2671d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 268ecc98ec1SLad, Prabhakar { DAVINCI_LPSC_MMC_SD }, 269ecc98ec1SLad, Prabhakar #endif 27089b765c7SSudhakar Rajashekhara }; 27189b765c7SSudhakar Rajashekhara 2726b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc); 2736b873dcaSSughosh Ganu 2744f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK 2754f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000 2764f6fc15bSSekhar Nori #endif 2774f6fc15bSSekhar Nori 278754f8cb6SManjunath Hadli #define REV_AM18X_EVM 0x100 279754f8cb6SManjunath Hadli 2804f6fc15bSSekhar Nori /* 2814f6fc15bSSekhar Nori * get_board_rev() - setup to pass kernel board revision information 2824f6fc15bSSekhar Nori * Returns: 2834f6fc15bSSekhar Nori * bit[0-3] Maximum cpu clock rate supported by onboard SoC 2844f6fc15bSSekhar Nori * 0000b - 300 MHz 2854f6fc15bSSekhar Nori * 0001b - 372 MHz 2864f6fc15bSSekhar Nori * 0010b - 408 MHz 2874f6fc15bSSekhar Nori * 0011b - 456 MHz 2884f6fc15bSSekhar Nori */ 2894f6fc15bSSekhar Nori u32 get_board_rev(void) 2904f6fc15bSSekhar Nori { 2914f6fc15bSSekhar Nori char *s; 2924f6fc15bSSekhar Nori u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK; 2934f6fc15bSSekhar Nori u32 rev = 0; 2944f6fc15bSSekhar Nori 2954f6fc15bSSekhar Nori s = getenv("maxcpuclk"); 2964f6fc15bSSekhar Nori if (s) 2974f6fc15bSSekhar Nori maxcpuclk = simple_strtoul(s, NULL, 10); 2984f6fc15bSSekhar Nori 2994f6fc15bSSekhar Nori if (maxcpuclk >= 456000000) 3004f6fc15bSSekhar Nori rev = 3; 3014f6fc15bSSekhar Nori else if (maxcpuclk >= 408000000) 3024f6fc15bSSekhar Nori rev = 2; 3034f6fc15bSSekhar Nori else if (maxcpuclk >= 372000000) 3044f6fc15bSSekhar Nori rev = 1; 305754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM 306754f8cb6SManjunath Hadli rev |= REV_AM18X_EVM; 307754f8cb6SManjunath Hadli #endif 3084f6fc15bSSekhar Nori return rev; 3094f6fc15bSSekhar Nori } 3104f6fc15bSSekhar Nori 311ae5c77ddSChristian Riesch int board_early_init_f(void) 312ae5c77ddSChristian Riesch { 313ae5c77ddSChristian Riesch /* 314ae5c77ddSChristian Riesch * Power on required peripherals 315ae5c77ddSChristian Riesch * ARM does not have access by default to PSC0 and PSC1 316ae5c77ddSChristian Riesch * assuming here that the DSP bootloader has set the IOPU 317ae5c77ddSChristian Riesch * such that PSC access is available to ARM 318ae5c77ddSChristian Riesch */ 319ae5c77ddSChristian Riesch if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) 320ae5c77ddSChristian Riesch return 1; 321ae5c77ddSChristian Riesch 322ae5c77ddSChristian Riesch return 0; 323ae5c77ddSChristian Riesch } 324ae5c77ddSChristian Riesch 32589b765c7SSudhakar Rajashekhara int board_init(void) 32689b765c7SSudhakar Rajashekhara { 32789b765c7SSudhakar Rajashekhara irq_init(); 32889b765c7SSudhakar Rajashekhara 329a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI 330a3f88293SBen Gardiner /* 331a3f88293SBen Gardiner * NAND CS setup - cycle counts based on da850evm NAND timings in the 332a3f88293SBen Gardiner * Linux kernel @ 25MHz EMIFA 333a3f88293SBen Gardiner */ 334de94b80dSLad, Prabhakar writel((DAVINCI_ABCR_WSETUP(2) | 335de94b80dSLad, Prabhakar DAVINCI_ABCR_WSTROBE(2) | 336de94b80dSLad, Prabhakar DAVINCI_ABCR_WHOLD(1) | 337de94b80dSLad, Prabhakar DAVINCI_ABCR_RSETUP(1) | 338de94b80dSLad, Prabhakar DAVINCI_ABCR_RSTROBE(4) | 339a3f88293SBen Gardiner DAVINCI_ABCR_RHOLD(0) | 34024a514c4SBen Gardiner DAVINCI_ABCR_TA(1) | 341a3f88293SBen Gardiner DAVINCI_ABCR_ASIZE_8BIT), 342a3f88293SBen Gardiner &davinci_emif_regs->ab2cr); /* CS3 */ 343a3f88293SBen Gardiner #endif 344a3f88293SBen Gardiner 34589b765c7SSudhakar Rajashekhara /* arch number of the board */ 34689b765c7SSudhakar Rajashekhara gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM; 34789b765c7SSudhakar Rajashekhara 34889b765c7SSudhakar Rajashekhara /* address of boot parameters */ 34989b765c7SSudhakar Rajashekhara gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; 35089b765c7SSudhakar Rajashekhara 35189b765c7SSudhakar Rajashekhara /* setup the SUSPSRC for ARM to control emulation suspend */ 35289b765c7SSudhakar Rajashekhara writel(readl(&davinci_syscfg_regs->suspsrc) & 35389b765c7SSudhakar Rajashekhara ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | 35489b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | 35589b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_UART2), 35689b765c7SSudhakar Rajashekhara &davinci_syscfg_regs->suspsrc); 35789b765c7SSudhakar Rajashekhara 35889b765c7SSudhakar Rajashekhara /* configure pinmux settings */ 35989b765c7SSudhakar Rajashekhara if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) 36089b765c7SSudhakar Rajashekhara return 1; 36189b765c7SSudhakar Rajashekhara 3620f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR 3630f3d6b06SNagabhushana Netagunte /* Set the GPIO direction as output */ 3643864cb21SChristian Riesch clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11)); 3650f3d6b06SNagabhushana Netagunte 3660f3d6b06SNagabhushana Netagunte /* Set the output as low */ 3673864cb21SChristian Riesch writel(0x01 << 11, GPIO_BANK0_REG_CLR_ADDR); 3680f3d6b06SNagabhushana Netagunte #endif 3690f3d6b06SNagabhushana Netagunte 3701d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI 3716652c62eSRajashekhara, Sudhakar /* Set the GPIO direction as output */ 3726652c62eSRajashekhara, Sudhakar clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11)); 3736652c62eSRajashekhara, Sudhakar 3746652c62eSRajashekhara, Sudhakar /* Set the output as high */ 3753864cb21SChristian Riesch writel(0x01 << 11, GPIO_BANK0_REG_SET_ADDR); 3766652c62eSRajashekhara, Sudhakar #endif 3776652c62eSRajashekhara, Sudhakar 3783d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 3796d1c649fSStefano Babic davinci_emac_mii_mode_sel(HAS_RMII); 3803d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */ 3813d248d37SBen Gardiner 38289b765c7SSudhakar Rajashekhara /* enable the console UART */ 38389b765c7SSudhakar Rajashekhara writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | 38489b765c7SSudhakar Rajashekhara DAVINCI_UART_PWREMU_MGMT_UTRST), 38589b765c7SSudhakar Rajashekhara &davinci_uart2_ctrl_regs->pwremu_mgmt); 38689b765c7SSudhakar Rajashekhara 38789b765c7SSudhakar Rajashekhara return 0; 38889b765c7SSudhakar Rajashekhara } 3893d248d37SBen Gardiner 3903d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC 3913d248d37SBen Gardiner 392d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 393d2607401SSudhakar Rajashekhara /** 394d2607401SSudhakar Rajashekhara * rmii_hw_init 395d2607401SSudhakar Rajashekhara * 396d2607401SSudhakar Rajashekhara * DA850/OMAP-L138 EVM can interface to a daughter card for 397d2607401SSudhakar Rajashekhara * additional features. This card has an I2C GPIO Expander TCA6416 398d2607401SSudhakar Rajashekhara * to select the required functions like camera, RMII Ethernet, 399d2607401SSudhakar Rajashekhara * character LCD, video. 400d2607401SSudhakar Rajashekhara * 401d2607401SSudhakar Rajashekhara * Initialization of the expander involves configuring the 402d2607401SSudhakar Rajashekhara * polarity and direction of the ports. P07-P05 are used here. 403d2607401SSudhakar Rajashekhara * These ports are connected to a Mux chip which enables only one 404d2607401SSudhakar Rajashekhara * functionality at a time. 405d2607401SSudhakar Rajashekhara * 406d2607401SSudhakar Rajashekhara * For RMII phy to respond, the MII MDIO clock has to be disabled 407d2607401SSudhakar Rajashekhara * since both the PHY devices have address as zero. The MII MDIO 408d2607401SSudhakar Rajashekhara * clock is controlled via GPIO2[6]. 409d2607401SSudhakar Rajashekhara * 410d2607401SSudhakar Rajashekhara * This code is valid for Beta version of the hardware 411d2607401SSudhakar Rajashekhara */ 412d2607401SSudhakar Rajashekhara int rmii_hw_init(void) 413d2607401SSudhakar Rajashekhara { 414d2607401SSudhakar Rajashekhara const struct pinmux_config gpio_pins[] = { 415d2607401SSudhakar Rajashekhara { pinmux(6), 8, 1 } 416d2607401SSudhakar Rajashekhara }; 417d2607401SSudhakar Rajashekhara u_int8_t buf[2]; 418d2607401SSudhakar Rajashekhara unsigned int temp; 419d2607401SSudhakar Rajashekhara int ret; 420d2607401SSudhakar Rajashekhara 421d2607401SSudhakar Rajashekhara /* PinMux for GPIO */ 422d2607401SSudhakar Rajashekhara if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0) 423d2607401SSudhakar Rajashekhara return 1; 424d2607401SSudhakar Rajashekhara 425d2607401SSudhakar Rajashekhara /* I2C Exapnder configuration */ 426d2607401SSudhakar Rajashekhara /* Set polarity to non-inverted */ 427d2607401SSudhakar Rajashekhara buf[0] = 0x0; 428d2607401SSudhakar Rajashekhara buf[1] = 0x0; 429d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2); 430d2607401SSudhakar Rajashekhara if (ret) { 431d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 432d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 433d2607401SSudhakar Rajashekhara return ret; 434d2607401SSudhakar Rajashekhara } 435d2607401SSudhakar Rajashekhara 436d2607401SSudhakar Rajashekhara /* Configure P07-P05 as outputs */ 437d2607401SSudhakar Rajashekhara buf[0] = 0x1f; 438d2607401SSudhakar Rajashekhara buf[1] = 0xff; 439d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2); 440d2607401SSudhakar Rajashekhara if (ret) { 441d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 442d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 443d2607401SSudhakar Rajashekhara } 444d2607401SSudhakar Rajashekhara 445d2607401SSudhakar Rajashekhara /* For Ethernet RMII selection 446d2607401SSudhakar Rajashekhara * P07(SelA)=0 447d2607401SSudhakar Rajashekhara * P06(SelB)=1 448d2607401SSudhakar Rajashekhara * P05(SelC)=1 449d2607401SSudhakar Rajashekhara */ 450d2607401SSudhakar Rajashekhara if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) { 451d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x read FAILED!!!\n", 452d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 453d2607401SSudhakar Rajashekhara } 454d2607401SSudhakar Rajashekhara 455d2607401SSudhakar Rajashekhara buf[0] &= 0x1f; 456d2607401SSudhakar Rajashekhara buf[0] |= (0 << 7) | (1 << 6) | (1 << 5); 457d2607401SSudhakar Rajashekhara if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) { 458d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n", 459d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR); 460d2607401SSudhakar Rajashekhara } 461d2607401SSudhakar Rajashekhara 462d2607401SSudhakar Rajashekhara /* Set the output as high */ 463d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_SET_ADDR); 464d2607401SSudhakar Rajashekhara temp |= (0x01 << 6); 465d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_SET_ADDR) = temp; 466d2607401SSudhakar Rajashekhara 467d2607401SSudhakar Rajashekhara /* Set the GPIO direction as output */ 468d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_DIR_ADDR); 469d2607401SSudhakar Rajashekhara temp &= ~(0x01 << 6); 470d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_DIR_ADDR) = temp; 471d2607401SSudhakar Rajashekhara 472d2607401SSudhakar Rajashekhara return 0; 473d2607401SSudhakar Rajashekhara } 474d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */ 475d2607401SSudhakar Rajashekhara 4763d248d37SBen Gardiner /* 4773d248d37SBen Gardiner * Initializes on-board ethernet controllers. 4783d248d37SBen Gardiner */ 4793d248d37SBen Gardiner int board_eth_init(bd_t *bis) 4803d248d37SBen Gardiner { 481d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII 482d2607401SSudhakar Rajashekhara /* Select RMII fucntion through the expander */ 483d2607401SSudhakar Rajashekhara if (rmii_hw_init()) 484d2607401SSudhakar Rajashekhara printf("RMII hardware init failed!!!\n"); 485d2607401SSudhakar Rajashekhara #endif 4863d248d37SBen Gardiner if (!davinci_emac_initialize()) { 4873d248d37SBen Gardiner printf("Error: Ethernet init failed!\n"); 4883d248d37SBen Gardiner return -1; 4893d248d37SBen Gardiner } 4903d248d37SBen Gardiner 4913d248d37SBen Gardiner return 0; 4923d248d37SBen Gardiner } 4933d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */ 494