Mark A. Greer wrote:

Several of davinci platforms have their mac address
at the same location in the same type of i2c eeprom
so factor out the code to extract that mac address.
Also factor out the code that fixes up a bogus mac
address.

   This patch didn't seem to me really worth it...

Signed-off-by: Mark A. Greer <[email protected]>

[...]

diff --git a/arch/arm/mach-davinci/mac_addr.c b/arch/arm/mach-davinci/mac_addr.c
new file mode 100644
index 0000000..ff05e04
--- /dev/null
+++ b/arch/arm/mach-davinci/mac_addr.c
@@ -0,0 +1,45 @@
+/*
+ * Helper routines for setting the EMAC MAC address
+ *
+ * Author: Kevin Hilman, MontaVista Software, Inc. <[email protected]>
+ *
+ * 2007 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+#include <linux/kernel.h>
+#include <linux/etherdevice.h>
+#include <linux/i2c/at24.h>
+
+#include <mach/emac.h>
+#include <mach/common.h>
+
+/* Use a random mac addr if one passed in is invalid */
+void davinci_fixup_mac_addr(char *mac_addr)
+{
+       DECLARE_MAC_BUF(mac_str);
+
+       if (!is_valid_ether_addr(mac_addr)) {
+               random_ether_addr(mac_addr);
+
+               printk(KERN_WARNING "%s: using random MAC addr: %s\n",
+                               __func__, print_mac(mac_str, mac_addr));
+       }
+}
+
+/* Ethernet MAC addr is at 0x7f00 in i2c eeprom (at24c256). */
+int davinci_i2c_get_mac_addr(struct at24_iface *iface, void *context)
+{
+       DECLARE_MAC_BUF(mac_str);
+       char *mac_addr = davinci_soc_info->emac_pdata->mac_addr;
+
+       /* Read MAC addr from EEPROM */
+       if (iface->read(iface, mac_addr, 0x7f00, 6) == 6) {
+               printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
+                               print_mac(mac_str, mac_addr));
+               davinci_fixup_mac_addr(mac_addr);
+       }
+
+       return 0;
+}

I'd really prefer this to be left in the board-specific files given that the functions you've factored out are not at all big...

WBR, Sergei

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to