Skip to contentSkip to conversation

davinci: MityDSP-L138/MityARM-1808 read MAC address from I2C Prom

PATCH Superseded Michael Williamson 2 participants 2 messages Sep 16, 2010 – Sep 17, 2010

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 davinci: MityDSP-L138/MityARM-1808 read MAC address from I2C Prom

For the MityDSP-L138/MityARM-1808 SOMS, read the factory assigned MAC address from the onboard I2C EPROM and assign it to the emac device during platform initialization.

---
Patch is against e90c3a5344683351c7a37f097f1e17d50ee2063c of linux-davinci tree.

Changes since v1:
1) updated sdtint types to kernel types per comments
2) Added prefix to warning/info messages
3) Sanity check MAC address and issue warning if bad
4) replace hardcoded 6 with ETH_ALEN in memcpy

 arch/arm/mach-davinci/board-mityomapl138.c |   62 ++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-mityomapl138.c +62 -0
index 6f12a18..1fff0bb 100644
@@ -15,6 +15,8 @@
 #include <linux/mtd/partitions.h>
 #include <linux/regulator/machine.h>
 #include <linux/i2c.h>
+#include <linux/i2c/at24.h>
+#include <linux/etherdevice.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -25,6 +27,65 @@
 #include <mach/mux.h>
 
 #define MITYOMAPL138_PHY_ID		"0:03"
+
+#define FACTORY_CONFIG_MAGIC	0x012C0138
+#define FACTORY_CONFIG_VERSION	0x00010001
+
+/* Data Held in On-Board I2C device */
+struct factory_config {
+	u32	magic;
+	u32	version;
+	u8	mac[6];
+	u32	fpga_type;
+	u32	spare;
+	u32	serialnumber;
+	char	partnum[32];
+};
+
+static struct factory_config factory_config;
+
+static void read_factory_config(struct memory_accessor *a, void *context)
+{
+	int ret;
+	struct davinci_soc_info *soc_info = &davinci_soc_info;
+
+	ret = a->read(a, (char *)&factory_config, 0, sizeof(factory_config));
+	if (ret != sizeof(struct factory_config)) {
+		pr_warning("MityOMAPL138: Read Factory Config Failed: %d\n",
+				ret);
+		return;
+	}
+
+	if (factory_config.magic != FACTORY_CONFIG_MAGIC) {
+		pr_warning("MityOMAPL138: Factory Config Magic Wrong (%X)\n",
+				factory_config.magic);
+		return;
+	}
+
+	if (factory_config.version != FACTORY_CONFIG_VERSION) {
+		pr_warning("MityOMAPL138: Factory Config Version Wrong (%X)\n",
+				factory_config.version);
+		return;
+	}
+
+	pr_info("MityOMAPL138: Found MAC = %pM\n", factory_config.mac);
+	pr_info("MityOMAPL138: Part Number = %s\n", factory_config.partnum);
+	if (is_valid_ether_addr(factory_config.mac))
+		memcpy(&soc_info->emac_pdata->mac_addr[0],
+			&factory_config.mac[0], ETH_ALEN);
+	else
+		pr_warning("MityOMAPL138: Invalid MAC found "
+				"in factory config block\n");
+}
+
+static struct at24_platform_data mityomapl138_fd_chip = {
+	.byte_len	= 256,
+	.page_size	= 8,
+	.flags		= AT24_FLAG_READONLY | AT24_FLAG_IRUGO,
+	.setup		= read_factory_config,
+	.context	= NULL,
+};
+
 static struct davinci_i2c_platform_data mityomap_i2c_0_pdata = {
 	.bus_freq	= 100,	/* kHz */
 	.bus_delay	= 0,	/* usec */
@@ -151,6 +212,7 @@ static struct i2c_board_info __initdata mityomap_tps65023_info[] = {
 	},
 	{
 		I2C_BOARD_INFO("24c02", 0x50),
+		.platform_data = &mityomapl138_fd_chip,
 	},
 };
 
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 1/1 davinci: MityDSP-L138/MityARM-1808 read MAC address from I2C Prom

Hello.

Quoted 5 lines · Michael Williamson

For the MityDSP-L138/MityARM-1808 SOMS, read the factory assigned MAC address from the onboard I2C EPROM and assign it to the emac device during platform initialization.

[...]

Quoted 5 lines
arch/arm/mach-davinci/board-mityomapl138.c +0 -0
index 6f12a18..1fff0bb 100644
@@ -15,6 +15,8 @@

[...]

Quoted 2 lines
arch/arm/mach-davinci/board-mityomapl138.c +2 -0
+static void read_factory_config(struct memory_accessor *a, void *context)
+{

[...]

arch/arm/mach-davinci/board-mityomapl138.c line 74

Quoted 2 lines
arch/arm/mach-davinci/board-mityomapl138.c +2 -0
+	if (is_valid_ether_addr(factory_config.mac))
+		memcpy(&soc_info->emac_pdata->mac_addr[0],

& and [0] are not needed.

arch/arm/mach-davinci/board-mityomapl138.c line 75

Quoted 1 line
arch/arm/mach-davinci/board-mityomapl138.c +1 -0
+			&factory_config.mac[0], ETH_ALEN);

Same here.

WBR, Sergei