All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/2] da850evm: add board specific functions
@ 2012-02-10  6:22 Manjunath Hadli
  2012-02-10  6:22 ` [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash Manjunath Hadli
  2012-02-10  6:22 ` [U-Boot] [PATCH v2 2/2] da850evm: read mac address from I2C EEPROM on AM18x EVM Manjunath Hadli
  0 siblings, 2 replies; 5+ messages in thread
From: Manjunath Hadli @ 2012-02-10  6:22 UTC (permalink / raw)
  To: u-boot

There are two da850 SOC based EVMs, one from Spectrum digital
and other from Logic PD. Boards from Spectrum digital have mac
address stored in I2C EEPROM and they have spi flash manufactured
by WINBOND. Boards from Logic PD store mac address in ST
Microelectronics SPI flash. This patch series adds support to
read mac address from the appropriate device.

Changes for v2:
1: Fixed a comment from Wolfgang, comparing MAC address if present in
   different locations and raising a warning on mismatch.
2: Fixed a comment from Mike, removed return -EINVAL statement,
   just issuing a warning in case of error in misc_init_r() function
   while reading MAC address.

Manjunath Hadli (2):
  da850evm: add support to read mac address from SPI flash
  da850evm: read mac address from I2C EEPROM on AM18x EVM

 board/davinci/da8xxevm/da850evm.c |  103 +++++++++++++++++++++++++++++++++++++
 boards.cfg                        |    4 +-
 2 files changed, 105 insertions(+), 2 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash
  2012-02-10  6:22 [U-Boot] [PATCH v2 0/2] da850evm: add board specific functions Manjunath Hadli
@ 2012-02-10  6:22 ` Manjunath Hadli
  2012-02-10 21:49   ` Mike Frysinger
  2012-02-10  6:22 ` [U-Boot] [PATCH v2 2/2] da850evm: read mac address from I2C EEPROM on AM18x EVM Manjunath Hadli
  1 sibling, 1 reply; 5+ messages in thread
From: Manjunath Hadli @ 2012-02-10  6:22 UTC (permalink / raw)
  To: u-boot

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 |   72 +++++++++++++++++++++++++++++++++++++
 boards.cfg                        |    2 +-
 2 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index 9bd3e71..2651ccf 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -25,12 +25,15 @@
 #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;
 }
 
diff --git a/boards.cfg b/boards.cfg
index 2f90dbf..ad6c5b8 100644
--- a/boards.cfg
+++ b/boards.cfg
@@ -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
-- 
1.6.2.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 2/2] da850evm: read mac address from I2C EEPROM on AM18x EVM
  2012-02-10  6:22 [U-Boot] [PATCH v2 0/2] da850evm: add board specific functions Manjunath Hadli
  2012-02-10  6:22 ` [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash Manjunath Hadli
@ 2012-02-10  6:22 ` Manjunath Hadli
  1 sibling, 0 replies; 5+ messages in thread
From: Manjunath Hadli @ 2012-02-10  6:22 UTC (permalink / raw)
  To: u-boot

add support to read mac address for AM18x EVM manufactured from
Spectrum digital which have mac address stored in I2C EEPROM manufactured
by WINBOND. This patch reads mac address from I2C EEPROM and sets the
environment variable if not set, If mac address is already present in
environment compare it with the mac address in EEPROM and warn on
mismatch.Introduced a config option CONFIG_MAC_ADDR_IN_EEPROM to where
to look for the mac address.

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 |   35 +++++++++++++++++++++++++++++++++--
 boards.cfg                        |    2 +-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index 2651ccf..6598e35 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -132,13 +132,17 @@ int misc_init_r(void)
 {
 	dspwake();
 
-#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
+#if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)
+
 	uchar env_enetaddr[6];
 	int enetaddr_found;
+
+	enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr);
+
+#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
 	int spi_mac_read;
 	uchar buff[6];
 
-	enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr);
 	spi_mac_read = get_mac_addr(buff);
 
 	/*
@@ -170,6 +174,33 @@ int misc_init_r(void)
 			printf("Default using MAC address from environment\n");
 	}
 #endif
+	uint8_t enetaddr[8];
+	int eeprom_mac_read;
+
+	/* Read Ethernet MAC address from EEPROM */
+	eeprom_mac_read = dvevm_read_mac_address(enetaddr);
+
+	/*
+	 * MAC address not present in the environment
+	 * try and read the MAC address from EEPROM flash
+	 * and set it.
+	 */
+	if (!enetaddr_found) {
+		if (eeprom_mac_read)
+			/* Set Ethernet MAC address from EEPROM */
+			davinci_sync_env_enetaddr(enetaddr);
+	} else {
+		/*
+		 * MAC address present in environment compare it with
+		 * the MAC address in EEPROM and warn on mismatch
+		 */
+		if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
+			printf("Warning: MAC address in EEPROM don't match "
+					"with the MAC address in the environment\n");
+			printf("Default using MAC address from environment\n");
+	}
+
+#endif
 	return 0;
 }
 
diff --git a/boards.cfg b/boards.cfg
index ad6c5b8..2e6d267 100644
--- a/boards.cfg
+++ b/boards.cfg
@@ -120,7 +120,7 @@ pm9263                       arm         arm926ejs   pm9263              ronetix
 pm9g45                       arm         arm926ejs   pm9g45              ronetix        at91        pm9g45:AT91SAM9G45
 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
+da850_am18xxevm              arm         arm926ejs   da8xxevm            davinci        davinci     da850evm:DA850_AM18X_EVM,MAC_ADDR_IN_EEPROM,SYS_I2C_EEPROM_ADDR_LEN=2,SYS_I2C_EEPROM_ADDR=0x50
 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
-- 
1.6.2.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash
  2012-02-10  6:22 ` [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash Manjunath Hadli
@ 2012-02-10 21:49   ` Mike Frysinger
  2012-02-13  4:44     ` Hadli, Manjunath
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Frysinger @ 2012-02-10 21:49 UTC (permalink / raw)
  To: u-boot

On Friday 10 February 2012 01:22:24 Manjunath Hadli wrote:
> --- a/board/davinci/da8xxevm/da850evm.c
> +++ b/board/davinci/da8xxevm/da850evm.c
> 
> +#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

these defines get used only once below, so doesn't seem terribly useful to have 
as defines.  up to you.

>  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);

you always read the SPI flash even if the env is available.  that sounds like a 
waste of time to me.  i'd expect the logic to simply be:

	if (!eth_getenv_enetaddr("ethaddr", env_enetaddr)) {
		if (get_mac_addr(buff) == 0)
			eth_setenv_enetaddr("ethaddr", buff);
	}

no need to warn in misc_init_r() since your get_mac_addr() already issues a 
warning
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120210/729ea09a/attachment.pgp>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash
  2012-02-10 21:49   ` Mike Frysinger
@ 2012-02-13  4:44     ` Hadli, Manjunath
  0 siblings, 0 replies; 5+ messages in thread
From: Hadli, Manjunath @ 2012-02-13  4:44 UTC (permalink / raw)
  To: u-boot

Mike,

On Sat, Feb 11, 2012 at 03:19:24, Mike Frysinger wrote:
> On Friday 10 February 2012 01:22:24 Manjunath Hadli wrote:
> > --- a/board/davinci/da8xxevm/da850evm.c
> > +++ b/board/davinci/da8xxevm/da850evm.c
> > 
> > +#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
> 
> these defines get used only once below, so doesn't seem terribly useful to have as defines.  up to you.
I would like to have these :), If you still insist I'll get rid of these.
> 
> >  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);
> 
> you always read the SPI flash even if the env is available.  that sounds like a waste of time to me.  i'd expect the logic to simply be:
> 
> 	if (!eth_getenv_enetaddr("ethaddr", env_enetaddr)) {
> 		if (get_mac_addr(buff) == 0)
> 			eth_setenv_enetaddr("ethaddr", buff);
> 	}
> 
> no need to warn in misc_init_r() since your get_mac_addr() already issues a warning -mike
> 
My earlier patch series did the same thing, but Wolfgang suggested,
"If we have multiple storage for the MAC address, we should always
raise a warning if these contain different information."
http://www.mail-archive.com/u-boot at lists.denx.de/msg76666.html
the above link should sort out things clearer.

Regards,
--Manju

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-13  4:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10  6:22 [U-Boot] [PATCH v2 0/2] da850evm: add board specific functions Manjunath Hadli
2012-02-10  6:22 ` [U-Boot] [PATCH v2 1/2] da850evm: add support to read mac address from SPI flash Manjunath Hadli
2012-02-10 21:49   ` Mike Frysinger
2012-02-13  4:44     ` Hadli, Manjunath
2012-02-10  6:22 ` [U-Boot] [PATCH v2 2/2] da850evm: read mac address from I2C EEPROM on AM18x EVM Manjunath Hadli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.