]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
da850evm: add support to read mac address from SPI flash
authorHadli, Manjunath <manjunath.hadli@ti.com>
Thu, 9 Feb 2012 20:22:24 +0000 (20:22 +0000)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Mon, 27 Feb 2012 20:19:24 +0000 (21:19 +0100)
add support to read mac address for da850/L138 evm manufactured by
Logic PD which store mac address in SPI flash manufactured by ST
Microelectronics. This patch adds support to read mac address from
SPI flash and set the mac address if it hasn't been set in environment,
If it has been set in the environment it compares the value one with
SPI flash and warns on mismatch. Introduced a config option
CONFIG_MAC_ADDR_IN_SPIFLASH indicating where to look mac address for.

Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
Cc: Tom Rini <trini@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Wolfgang Denk <wd@denx.de>
board/davinci/da8xxevm/da850evm.c
boards.cfg

index 34ef53df2bca699c375852d0504bbd5750ad0322..beb56575e3bffe4e5b5382b24687517bd259d756 100644 (file)
 #include <i2c.h>
 #include <net.h>
 #include <netdev.h>
+#include <spi.h>
+#include <spi_flash.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/emif_defs.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/arch/pinmux_defs.h>
 #include <asm/io.h>
 #include <asm/arch/davinci_misc.h>
+#include <asm/errno.h>
 #include <hwconfig.h>
 
 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;
 }
 
index 05ce1ae06fa37caf1832f13f9d0c9069b12bff05..5610dafac60817694fd5b35ec990368bee9a37c7 100644 (file)
@@ -121,7 +121,7 @@ pm9g45                       arm         arm926ejs   pm9g45              ronetix
 cam_enc_4xx                  arm         arm926ejs   cam_enc_4xx         ait            davinci     cam_enc_4xx
 da830evm                     arm         arm926ejs   da8xxevm            davinci        davinci
 da850_am18xxevm              arm         arm926ejs   da8xxevm            davinci        davinci     da850evm:DA850_AM18X_EVM
-da850evm                     arm         arm926ejs   da8xxevm            davinci        davinci
+da850evm                     arm         arm926ejs   da8xxevm            davinci        davinci     da850evm:MAC_ADDR_IN_SPIFLASH
 davinci_dm355evm             arm         arm926ejs   dm355evm            davinci        davinci
 davinci_dm355leopard         arm         arm926ejs   dm355leopard        davinci        davinci
 davinci_dm365evm             arm         arm926ejs   dm365evm            davinci        davinci