]> git.ipfire.org Git - people/arne_f/ipfire-3.x.git/blob - kernel/patches/arm-smsc-support-reading-mac-address-from-device-tree.patch
a36c68369de8764543951c1c22fb1e7eed23b9ea
[people/arne_f/ipfire-3.x.git] / kernel / patches / arm-smsc-support-reading-mac-address-from-device-tree.patch
1 From 0b608345e114681f66ca0a3cf9d9434728da62ce Mon Sep 17 00:00:00 2001
2 From: Ken Cox <ken@coxcampers.net>
3 Date: Thu, 23 Jun 2011 10:36:43 -0500
4 Subject: [PATCH] Support reading mac address from device tree.
5
6 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.
7 ---
8 drivers/net/usb/smsc75xx.c | 17 +++++++++++++++++
9 drivers/net/usb/smsc95xx.c | 18 +++++++++++++++++-
10 2 files changed, 34 insertions(+), 1 deletions(-)
11
12 diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
13 index 753ee6e..ac0a200 100644
14 --- a/drivers/net/usb/smsc75xx.c
15 +++ b/drivers/net/usb/smsc75xx.c
16 @@ -29,6 +29,7 @@
17 #include <linux/crc32.h>
18 #include <linux/usb/usbnet.h>
19 #include <linux/slab.h>
20 +#include <linux/of_device.h>
21 #include "smsc75xx.h"
22
23 #define SMSC_CHIPNAME "smsc75xx"
24 @@ -658,6 +659,22 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
25
26 static void smsc75xx_init_mac_address(struct usbnet *dev)
27 {
28 + void *address;
29 +#ifdef CONFIG_OF
30 + struct device_node *np;
31 +
32 + /* try the device tree */
33 + np = of_find_node_by_name(NULL, "smsc75xx");
34 + if (np) {
35 + address = of_get_property(np, "local-mac-address", NULL);
36 + if (address) {
37 + memcpy(dev->net->dev_addr, address, ETH_ALEN);
38 + netif_dbg(dev, ifup, dev->net, "MAC address read from device tree\n");
39 + return;
40 + }
41 + }
42 +#endif
43 +
44 /* try reading mac address from EEPROM */
45 if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
46 dev->net->dev_addr) == 0) {
47 diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
48 index bc86f4b..c83942d 100644
49 --- a/drivers/net/usb/smsc95xx.c
50 +++ b/drivers/net/usb/smsc95xx.c
51 @@ -29,6 +29,7 @@
52 #include <linux/crc32.h>
53 #include <linux/usb/usbnet.h>
54 #include <linux/slab.h>
55 +#include <linux/of_device.h>
56 #include "smsc95xx.h"
57
58 #define SMSC_CHIPNAME "smsc95xx"
59 @@ -639,6 +640,22 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
60
61 static void smsc95xx_init_mac_address(struct usbnet *dev)
62 {
63 + void *address;
64 +#ifdef CONFIG_OF
65 + struct device_node *np;
66 +
67 + /* try the device tree */
68 + np = of_find_node_by_name(NULL, "smsc95xx");
69 + if (np) {
70 + address = of_get_property(np, "local-mac-address", NULL);
71 + if (address) {
72 + memcpy(dev->net->dev_addr, address, ETH_ALEN);
73 + netif_dbg(dev, ifup, dev->net, "MAC address read from device tree\n");
74 + return;
75 + }
76 + }
77 +#endif
78 +
79 /* try reading mac address from EEPROM */
80 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
81 dev->net->dev_addr) == 0) {
82 @@ -648,7 +665,6 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
83 return;
84 }
85 }
86 -
87 /* no eeprom, or eeprom values are invalid. generate random MAC */
88 random_ether_addr(dev->net->dev_addr);
89 netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n");
90 --
91 1.7.2.3
92