* [U-Boot] [PATCH v4 08/12] SPEAr : Support for HW mac id read/write from i2c mem
2010-01-11 11:15 ` [U-Boot] [PATCH v4 07/12] SPEAr : Support added for SPEAr600 board Vipin KUMAR
@ 2010-01-11 11:15 ` Vipin KUMAR
0 siblings, 0 replies; 2+ messages in thread
From: Vipin KUMAR @ 2010-01-11 11:15 UTC (permalink / raw)
To: u-boot
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 | 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);
+
+ /* 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;
+
+ i2c_read(0x50, 0x0, 1, buf, 2);
+
+ /* check if valid MAC address is saved in I2C EEPROM or not? */
+ if ((buf[0] == 0x55) && (buf[1] == 0xAA)) {
+ i2c_write(0x50, 0x2, 1, mac, 6);
+ puts("I2C EEPROM written with mac address \n");
+ return 0;
+ }
+
+ puts("I2C EEPROM writing failed \n");
+ return -1;
+}
+
#define CPU 0
#define DDR 1
@@ -103,7 +149,10 @@ 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 int frequency;
+ unsigned char mac[6];
+ unsigned int reg, frequency;
+ char *s, *e;
+ char i2c_mac[20];
if ((argc > 3) || (argc < 2)) {
cmd_usage(cmdtp);
@@ -134,6 +183,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], "display")) {
if (chip->cpufreq == -1)
@@ -153,6 +213,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;
--
1.6.0.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH v4 08/12] SPEAr : Support for HW mac id read/write from i2c mem
@ 2010-01-13 13:27 Tom
0 siblings, 0 replies; 2+ messages in thread
From: Tom @ 2010-01-13 13:27 UTC (permalink / raw)
To: u-boot
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 | 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-13 13:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-13 13:27 [U-Boot] [PATCH v4 08/12] SPEAr : Support for HW mac id read/write from i2c mem Tom
-- strict thread matches above, loose matches on Subject: below --
2010-01-11 11:15 [U-Boot] [PATCH v4 00/12] Support for SPEAr SoCs Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 01/12] SPEAr : Adding README.spear in doc Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 02/12] SPEAr : Adding basic SPEAr architecture support Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 03/12] SPEAr : i2c driver support added for SPEAr SoCs Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 04/12] SPEAr : smi driver support " Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 05/12] SPEAr : nand " Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 06/12] SPEAr : usbd " Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 07/12] SPEAr : Support added for SPEAr600 board Vipin KUMAR
2010-01-11 11:15 ` [U-Boot] [PATCH v4 08/12] SPEAr : Support for HW mac id read/write from i2c mem Vipin KUMAR
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.