public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vipin KUMAR <vipin.kumar@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 08/12] SPEAr : Support for HW mac id read/write from i2c mem
Date: Fri, 15 Jan 2010 19:15:49 +0530	[thread overview]
Message-ID: <1263563153-408-9-git-send-email-vipin.kumar@st.com> (raw)
In-Reply-To: <1263563153-408-8-git-send-email-vipin.kumar@st.com>

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@st.com>
---
 board/spear/common/spr_misc.c         |   68 ++++++++++++++++++++++++++++++++-
 include/asm-arm/arch-spear/spr_defs.h |    8 ++++
 2 files changed, 75 insertions(+), 1 deletions(-)

diff --git a/board/spear/common/spr_misc.c b/board/spear/common/spr_misc.c
index dfa3ece..204ccf2 100755
--- a/board/spear/common/spr_misc.c
+++ b/board/spear/common/spr_misc.c
@@ -67,6 +67,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)
@@ -101,12 +107,54 @@ int spear_board_init(ulong mach_type)
 	return 0;
 }
 
+static int i2c_read_mac(uchar *buffer)
+{
+	u8 buf[2];
+
+	i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
+
+	/* Check if mac in i2c memory is valid */
+	if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
+		/* Valid mac address is saved in i2c eeprom */
+		i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int write_mac(uchar *mac)
+{
+	u8 buf[2];
+
+	buf[0] = (u8)MAGIC_BYTE0;
+	buf[1] = (u8)MAGIC_BYTE1;
+	i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
+
+	buf[0] = (u8)~MAGIC_BYTE0;
+	buf[1] = (u8)~MAGIC_BYTE1;
+
+	i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
+
+	/* check if valid MAC address is saved in I2C EEPROM or not? */
+	if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
+		i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
+		puts("I2C EEPROM written with mac address \n");
+		return 0;
+	}
+
+	puts("I2C EEPROM writing failed \n");
+	return -1;
+}
+
 int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	void (*sram_setfreq) (unsigned int, unsigned int);
 	struct chip_data *chip = &chip_data;
 	unsigned char mac[6];
-	unsigned int frequency;
+	unsigned int reg, frequency;
+	char *s, *e;
+	char i2c_mac[20];
 
 	if ((argc > 3) || (argc < 2)) {
 		cmd_usage(cmdtp);
@@ -137,6 +185,17 @@ int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		}
 
 		return 0;
+	} else if (!strcmp(argv[1], "ethaddr")) {
+
+		s = argv[2];
+		for (reg = 0; reg < 6; ++reg) {
+			mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
+			if (s)
+				s = (*e) ? e + 1 : e;
+		}
+		write_mac(mac);
+
+		return 0;
 	} else if (!strcmp(argv[1], "print")) {
 
 		if (chip->cpufreq == -1)
@@ -156,6 +215,13 @@ int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		else
 			printf("DDR Type    = Not Known\n");
 
+		if (!i2c_read_mac(mac)) {
+			sprintf(i2c_mac, "%pM", mac);
+			printf("Ethaddr (from i2c mem) = %s\n", i2c_mac);
+		} else {
+			printf("Ethaddr (from i2c mem) = Not set\n");
+		}
+
 		printf("Xloader Rev = %s\n", chip->version);
 
 		return 0;
diff --git a/include/asm-arm/arch-spear/spr_defs.h b/include/asm-arm/arch-spear/spr_defs.h
index 9dde54a..fa8412c 100644
--- a/include/asm-arm/arch-spear/spr_defs.h
+++ b/include/asm-arm/arch-spear/spr_defs.h
@@ -35,4 +35,12 @@ struct chip_data {
 	uchar version[32];
 };
 
+/* HW mac id in i2c memory definitions */
+#define MAGIC_OFF	0x0
+#define MAGIC_LEN	0x2
+#define MAGIC_BYTE0	0x55
+#define MAGIC_BYTE1	0xAA
+#define MAC_OFF		0x2
+#define MAC_LEN		0x6
+
 #endif
-- 
1.6.0.2

  reply	other threads:[~2010-01-15 13:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-15 13:45 [U-Boot] [PATCH v5 00/12] Support for SPEAr SoCs Vipin KUMAR
2010-01-15 13:45 ` [U-Boot] [PATCH v5 01/12] SPEAr : Adding README.spear in doc Vipin KUMAR
2010-01-15 13:45   ` [U-Boot] [PATCH v5 02/12] SPEAr : Adding basic SPEAr architecture support Vipin KUMAR
2010-01-15 13:45     ` [U-Boot] [PATCH v5 03/12] SPEAr : i2c driver support added for SPEAr SoCs Vipin KUMAR
2010-01-15 13:45       ` [U-Boot] [PATCH v5 04/12] SPEAr : smi driver support " Vipin KUMAR
2010-01-15 13:45         ` [U-Boot] [PATCH v5 05/12] SPEAr : nand " Vipin KUMAR
2010-01-15 13:45           ` [U-Boot] [PATCH v5 06/12] SPEAr : usbd " Vipin KUMAR
2010-01-15 13:45             ` [U-Boot] [PATCH v5 07/12] SPEAr : Support added for SPEAr600 board Vipin KUMAR
2010-01-15 13:45               ` Vipin KUMAR [this message]
2010-01-15 13:45                 ` [U-Boot] [PATCH v5 09/12] SPEAr : Support added for SPEAr300 board Vipin KUMAR
2010-01-15 13:45                   ` [U-Boot] [PATCH v5 10/12] SPEAr : emi controller initialization for CFI driver support Vipin KUMAR
2010-01-15 13:45                     ` [U-Boot] [PATCH v5 11/12] SPEAr : Support added for SPEAr310 board Vipin KUMAR
2010-01-15 13:45                       ` [U-Boot] [PATCH v5 12/12] SPEAr : Support added for SPEAr320 board Vipin KUMAR
2010-01-18  6:15                 ` [U-Boot] [PATCH v5 08/12] SPEAr : Support for HW mac id read/write from i2c mem Ben Warren
2010-01-18  7:05                   ` Vipin KUMAR
2010-01-18  7:19                     ` Ben Warren
2010-01-18  7:24                       ` Vipin KUMAR
2010-01-18 12:59                         ` Tom
2010-01-18  7:08                   ` Mike Frysinger
2010-02-01  5:15                 ` Ben Warren
2010-02-01 13:55                   ` Tom
2010-01-18 18:02           ` [U-Boot] [PATCH v5 05/12] SPEAr : nand driver support for SPEAr SoCs Scott Wood
2010-01-17 20:12 ` [U-Boot] [PATCH v5 00/12] Support " Tom
2010-01-18  4:39   ` Vipin KUMAR
2010-01-18 12:51     ` Tom
2010-01-18 19:19       ` Remy Bohmer
2010-01-19 11:52         ` Armando VISCONTI
2010-01-21 21:30 ` Tom
2010-01-22  3:33   ` Vipin KUMAR

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263563153-408-9-git-send-email-vipin.kumar@st.com \
    --to=vipin.kumar@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox