|
@@ -28,13 +28,21 @@
|
|
#include <i2c.h>
|
|
#include <i2c.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/ctype.h>
|
|
|
|
|
|
|
|
+#ifdef CONFIG_SYS_I2C_EEPROM_CCID
|
|
#include "../common/eeprom.h"
|
|
#include "../common/eeprom.h"
|
|
|
|
+#define MAX_NUM_PORTS 8
|
|
|
|
+#endif
|
|
|
|
|
|
-#if !defined(CONFIG_SYS_I2C_EEPROM_CCID) && !defined(CONFIG_SYS_I2C_EEPROM_NXID)
|
|
|
|
-#error "Please define either CONFIG_SYS_I2C_EEPROM_CCID or CONFIG_SYS_I2C_EEPROM_NXID"
|
|
|
|
|
|
+#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
+#define MAX_NUM_PORTS 8
|
|
|
|
+#define NXID_VERSION 0
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-#define MAX_NUM_PORTS 8 /* This value must be 8 as defined in doc */
|
|
|
|
|
|
+#ifdef CONFIG_SYS_I2C_EEPROM_NXID_1
|
|
|
|
+#define CONFIG_SYS_I2C_EEPROM_NXID
|
|
|
|
+#define MAX_NUM_PORTS 23
|
|
|
|
+#define NXID_VERSION 1
|
|
|
|
+#endif
|
|
|
|
|
|
/**
|
|
/**
|
|
* static eeprom: EEPROM layout for CCID or NXID formats
|
|
* static eeprom: EEPROM layout for CCID or NXID formats
|
|
@@ -68,8 +76,8 @@ static struct __attribute__ ((__packed__)) eeprom {
|
|
u8 res_1[21]; /* 0x2b - 0x3f Reserved */
|
|
u8 res_1[21]; /* 0x2b - 0x3f Reserved */
|
|
u8 mac_count; /* 0x40 Number of MAC addresses */
|
|
u8 mac_count; /* 0x40 Number of MAC addresses */
|
|
u8 mac_flag; /* 0x41 MAC table flags */
|
|
u8 mac_flag; /* 0x41 MAC table flags */
|
|
- u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
|
|
|
|
- u32 crc; /* 0x72 CRC32 checksum */
|
|
|
|
|
|
+ u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - x MAC addresses */
|
|
|
|
+ u32 crc; /* x+1 CRC32 checksum */
|
|
#endif
|
|
#endif
|
|
} e;
|
|
} e;
|
|
|
|
|
|
@@ -204,7 +212,7 @@ static void update_crc(void)
|
|
*/
|
|
*/
|
|
static int prog_eeprom(void)
|
|
static int prog_eeprom(void)
|
|
{
|
|
{
|
|
- int ret = 0; /* shut up gcc */
|
|
|
|
|
|
+ int ret = 0;
|
|
int i;
|
|
int i;
|
|
void *p;
|
|
void *p;
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
|
@@ -225,6 +233,11 @@ static int prog_eeprom(void)
|
|
i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
|
|
i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * The AT24C02 datasheet says that data can only be written in page
|
|
|
|
+ * mode, which means 8 bytes at a time, and it takes up to 5ms to
|
|
|
|
+ * complete a given write.
|
|
|
|
+ */
|
|
for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
|
|
for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
|
|
ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
|
|
ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
|
|
p, min((sizeof(e) - i), 8));
|
|
p, min((sizeof(e) - i), 8));
|
|
@@ -233,12 +246,23 @@ static int prog_eeprom(void)
|
|
udelay(5000); /* 5ms write cycle timing */
|
|
udelay(5000); /* 5ms write cycle timing */
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (!ret) {
|
|
|
|
+ /* Verify the write by reading back the EEPROM and comparing */
|
|
|
|
+ struct eeprom e2;
|
|
|
|
+
|
|
|
|
+ ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
|
|
|
|
+ CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (void *)&e2, sizeof(e2));
|
|
|
|
+ if (!ret && memcmp(&e, &e2, sizeof(e)))
|
|
|
|
+ ret = -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
|
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
|
|
i2c_set_bus_num(bus);
|
|
i2c_set_bus_num(bus);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
if (ret) {
|
|
if (ret) {
|
|
printf("Programming failed.\n");
|
|
printf("Programming failed.\n");
|
|
|
|
+ has_been_read = 0;
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -300,7 +324,7 @@ static void set_mac_address(unsigned int index, const char *string)
|
|
char *p = (char *) string;
|
|
char *p = (char *) string;
|
|
unsigned int i;
|
|
unsigned int i;
|
|
|
|
|
|
- if (!string) {
|
|
|
|
|
|
+ if ((index >= MAX_NUM_PORTS) || !string) {
|
|
printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
|
|
printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -333,7 +357,7 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
if (cmd == 'i') {
|
|
if (cmd == 'i') {
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
|
|
memcpy(e.id, "NXID", sizeof(e.id));
|
|
memcpy(e.id, "NXID", sizeof(e.id));
|
|
- e.version = 0;
|
|
|
|
|
|
+ e.version = NXID_VERSION;
|
|
#else
|
|
#else
|
|
memcpy(e.id, "CCID", sizeof(e.id));
|
|
memcpy(e.id, "CCID", sizeof(e.id));
|
|
#endif
|
|
#endif
|
|
@@ -382,8 +406,8 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
e.mac_count = simple_strtoul(argv[2], NULL, 16);
|
|
e.mac_count = simple_strtoul(argv[2], NULL, 16);
|
|
update_crc();
|
|
update_crc();
|
|
break;
|
|
break;
|
|
- case '0' ... '7': /* "mac 0" through "mac 7" */
|
|
|
|
- set_mac_address(cmd - '0', argv[2]);
|
|
|
|
|
|
+ case '0' ... '9': /* "mac 0" through "mac 22" */
|
|
|
|
+ set_mac_address(simple_strtoul(argv[1], NULL, 10), argv[2]);
|
|
break;
|
|
break;
|
|
case 'h': /* help */
|
|
case 'h': /* help */
|
|
default:
|
|
default:
|