diff mbox

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

Message ID 1284061257-9017-1-git-send-email-michael.williamson@criticallink.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Michael Williamson Sept. 9, 2010, 7:40 p.m. UTC
None
diff mbox

Patch

diff --git a/arch/arm/mach-davinci/board-mityomapl138.c b/arch/arm/mach-davinci/board-mityomapl138.c
index e872fcc..e1cffb8 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -15,6 +15,7 @@ 
 #include <linux/mtd/partitions.h>
 #include <linux/regulator/machine.h>
 #include <linux/i2c.h>
+#include <linux/i2c/at24.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -24,6 +25,59 @@ 
 #include <mach/nand.h>
 #include <mach/mux.h>
 
+#define FACTORY_CONFIG_MAGIC	0x012C0138
+#define FACTORY_CONFIG_VERSION	0x00010001
+
+/* Data Held in On-Board I2C device */
+struct factory_config {
+	uint32_t	magic;
+	uint32_t	version;
+	uint8_t		mac[6];
+	uint32_t	fpga_type;
+	uint32_t	spare;
+	uint32_t	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("Read Factory Config Failed: %d\n", ret);
+		return;
+	}
+
+	if (factory_config.magic != FACTORY_CONFIG_MAGIC) {
+		pr_warning("Factory Config Magic Wrong (%X)\n",
+				factory_config.magic);
+		return;
+	}
+
+	if (factory_config.version != FACTORY_CONFIG_VERSION) {
+		pr_warning("Factory Config Version Wrong (%X)\n",
+				factory_config.version);
+		return;
+	}
+
+	pr_info("Found MAC = %pM\n", factory_config.mac);
+	pr_info("Part Number = %s\n", factory_config.partnum);
+	memcpy(&soc_info->emac_pdata->mac_addr[0],
+		&factory_config.mac[0], 6);
+}
+
+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 */
@@ -150,6 +204,7 @@  static struct i2c_board_info __initdata mityomap_tps65023_info[] = {
 	},
 	{
 		I2C_BOARD_INFO("24c02", 0x50),
+		.platform_data = &mityomapl138_fd_chip,
 	},
 };