X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=board%2Fdavinci%2Fda8xxevm%2Fda850evm.c;fp=board%2Fdavinci%2Fda8xxevm%2Fda850evm.c;h=beb56575e3bffe4e5b5382b24687517bd259d756;hb=38fed6ee95ee5b0dba9f91380267ed998cee2f62;hp=34ef53df2bca699c375852d0504bbd5750ad0322;hpb=4258aa62fbf4e001314624d09bcc94b3027c5670;p=karo-tx-uboot.git diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c index 34ef53df2b..beb56575e3 100644 --- a/board/davinci/da8xxevm/da850evm.c +++ b/board/davinci/da8xxevm/da850evm.c @@ -25,12 +25,15 @@ #include #include #include +#include +#include #include #include #include #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -43,6 +46,36 @@ DECLARE_GLOBAL_DATA_PTR; #endif #endif /* CONFIG_DRIVER_TI_EMAC */ +#define CFG_MAC_ADDR_SPI_BUS 0 +#define CFG_MAC_ADDR_SPI_CS 0 +#define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED +#define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3 + +#define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K) + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH +static int get_mac_addr(u8 *addr) +{ + struct spi_flash *flash; + int ret; + + flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS, + CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE); + if (!flash) { + printf("Error - unable to probe SPI flash.\n"); + return -1; + } + + ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr); + if (ret) { + printf("Error - unable to read MAC address from SPI flash.\n"); + return -1; + } + + return ret; +} +#endif + void dsp_lpsc_on(unsigned domain, unsigned int id) { dv_reg_p mdstat, mdctl, ptstat, ptcmd; @@ -98,6 +131,45 @@ static void dspwake(void) int misc_init_r(void) { dspwake(); + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH + uchar env_enetaddr[6]; + int enetaddr_found; + int spi_mac_read; + uchar buff[6]; + + enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr); + spi_mac_read = get_mac_addr(buff); + + /* + * MAC address not present in the environment + * try and read the MAC address from SPI flash + * and set it. + */ + if (!enetaddr_found) { + if (!spi_mac_read) { + if (is_valid_ether_addr(buff)) { + if (eth_setenv_enetaddr("ethaddr", buff)) { + printf("Warning: Failed to " + "set MAC address from SPI flash\n"); + } + } else { + printf("Warning: Invalid " + "MAC address read from SPI flash\n"); + } + } + } else { + /* + * MAC address present in environment compare it with + * the MAC address in SPI flash and warn on mismatch + */ + if (!spi_mac_read && is_valid_ether_addr(buff) && + memcmp(env_enetaddr, buff, 6)) + printf("Warning: MAC address in SPI flash don't match " + "with the MAC address in the environment\n"); + printf("Default using MAC address from environment\n"); + } +#endif return 0; }