[U-Boot] [PATCH v4 08/12] SPEAr : Support for HW mac id read/write from i2c mem

Tom Tom.Rix at windriver.com
Wed Jan 13 14:27:39 CET 2010



This patch adds the  support to read and write mac id from i2c
memory.
For reading:
	if (env contains ethaddr)
		pick env ethaddr
	else
		pick ethaddr from i2c memory
For writing:
	chip_config ethaddr XX:XX:XX:XX:XX:XX writes the mac id
	in i2c memory

Signed-off-by: Vipin <vipin.kumar at st.com>
---
  board/spear/common/spr_misc.c |   69 ++++++++++++++++++++++++++++++++++++++++-
  1 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/board/spear/common/spr_misc.c b/board/spear/common/spr_misc.c
index d70252b..9a6260f 100755
--- a/board/spear/common/spr_misc.c
+++ b/board/spear/common/spr_misc.c
@@ -62,6 +62,12 @@ int dram_init(void)

  int misc_init_r(void)
  {
+#if defined(CONFIG_CMD_NET)
+	uchar mac_id[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
+		eth_setenv_enetaddr("ethaddr", mac_id);
+#endif
  	setenv("verify", "n");

  #if defined(CONFIG_SPEAR_USBTTY)
@@ -96,6 +102,46 @@ int spear_board_init(ulong mach_type)
  	return 0;
  }

+static int i2c_read_mac(uchar *buffer)
+{
+	u8 buf[2];
+
+	i2c_read(0x50, 0x0, 1, buf, 2);

Change 0x50 to #define board/soc specific i2c address for MAC
Apply gobally

+
+	/* Check if mac in i2c memory is valid */
+	if ((buf[0] == 0x55) && (buf[1] == 0xAA)) {
+		/* Valid mac address is saved in i2c eeprom */
+		i2c_read(0x50, 0x2, 1, buffer, 6);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int write_mac(uchar *mac)
+{
+	unsigned char buf[2];
+
+	buf[0] = 0x55;
+	buf[1] = 0xAA;
+	i2c_write(0x50, 0x0, 1, buf, 2);
+
+	buf[0] = 0x44;
+	buf[1] = 0x66;

May want to change these to #defines

Tom


More information about the U-Boot mailing list