986a9f3
From 0b608345e114681f66ca0a3cf9d9434728da62ce Mon Sep 17 00:00:00 2001
986a9f3
From: Ken Cox <ken@coxcampers.net>
986a9f3
Date: Thu, 23 Jun 2011 10:36:43 -0500
986a9f3
Subject: [PATCH] Support reading mac address from device tree.
986a9f3
986a9f3
If CONFIG_OF is enabled, we will try to read the mac address from the device tree.  This enables us the ability to have a "static" mac address on arm boards such as the pandaboard and beagleboard which generate random mac addresses.
986a9f3
---
986a9f3
 drivers/net/usb/smsc75xx.c |   17 +++++++++++++++++
986a9f3
 drivers/net/usb/smsc95xx.c |   18 +++++++++++++++++-
986a9f3
 2 files changed, 34 insertions(+), 1 deletions(-)
986a9f3
986a9f3
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
986a9f3
index 753ee6e..ac0a200 100644
986a9f3
--- a/drivers/net/usb/smsc75xx.c
986a9f3
+++ b/drivers/net/usb/smsc75xx.c
986a9f3
@@ -29,6 +29,7 @@
986a9f3
 #include <linux/crc32.h>
986a9f3
 #include <linux/usb/usbnet.h>
986a9f3
 #include <linux/slab.h>
986a9f3
+#include <linux/of_device.h>
986a9f3
 #include "smsc75xx.h"
986a9f3
 
986a9f3
 #define SMSC_CHIPNAME			"smsc75xx"
986a9f3
@@ -658,6 +659,22 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
986a9f3
 
986a9f3
 static void smsc75xx_init_mac_address(struct usbnet *dev)
986a9f3
 {
986a9f3
+	void *address;
986a9f3
+#ifdef CONFIG_OF
986a9f3
+	struct device_node *np;
986a9f3
+
986a9f3
+	/* try the device tree */
986a9f3
+	np = of_find_node_by_name(NULL, "smsc75xx");
986a9f3
+	if (np) {
986a9f3
+		address = of_get_property(np, "local-mac-address", NULL);
986a9f3
+		if (address) {
986a9f3
+			memcpy(dev->net->dev_addr, address, ETH_ALEN);
986a9f3
+			netif_dbg(dev, ifup, dev->net, "MAC address read from device tree\n");
986a9f3
+			return;
986a9f3
+		}
986a9f3
+	}
986a9f3
+#endif
986a9f3
+
986a9f3
 	/* try reading mac address from EEPROM */
986a9f3
 	if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
986a9f3
 			dev->net->dev_addr) == 0) {
986a9f3
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
986a9f3
index bc86f4b..c83942d 100644
986a9f3
--- a/drivers/net/usb/smsc95xx.c
986a9f3
+++ b/drivers/net/usb/smsc95xx.c
986a9f3
@@ -29,6 +29,7 @@
986a9f3
 #include <linux/crc32.h>
986a9f3
 #include <linux/usb/usbnet.h>
986a9f3
 #include <linux/slab.h>
986a9f3
+#include <linux/of_device.h>
986a9f3
 #include "smsc95xx.h"
986a9f3
 
986a9f3
 #define SMSC_CHIPNAME			"smsc95xx"
986a9f3
@@ -639,6 +640,22 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
986a9f3
 
986a9f3
 static void smsc95xx_init_mac_address(struct usbnet *dev)
986a9f3
 {
986a9f3
+	void *address;
986a9f3
+#ifdef CONFIG_OF
986a9f3
+	struct device_node *np;
986a9f3
+
986a9f3
+	/* try the device tree */
986a9f3
+	np = of_find_node_by_name(NULL, "smsc95xx");
986a9f3
+	if (np) {
986a9f3
+		address = of_get_property(np, "local-mac-address", NULL);
986a9f3
+		if (address) {
986a9f3
+			memcpy(dev->net->dev_addr, address, ETH_ALEN);
986a9f3
+			netif_dbg(dev, ifup, dev->net, "MAC address read from device tree\n");
986a9f3
+			return;
986a9f3
+		}
986a9f3
+	}
986a9f3
+#endif
986a9f3
+
986a9f3
 	/* try reading mac address from EEPROM */
986a9f3
 	if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
986a9f3
 			dev->net->dev_addr) == 0) {
986a9f3
@@ -648,7 +665,6 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
986a9f3
 			return;
986a9f3
 		}
986a9f3
 	}
986a9f3
-
986a9f3
 	/* no eeprom, or eeprom values are invalid. generate random MAC */
986a9f3
 	random_ether_addr(dev->net->dev_addr);
986a9f3
 	netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n");
986a9f3
-- 
986a9f3
1.7.2.3
986a9f3