aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2007-02-16 13:01:29 -0500
committerPaul Mackerras <paulus@samba.org>2007-02-16 18:21:25 -0500
commit29cfe6f4fb7d187f65564764a0ecf2caf9d8ed58 (patch)
treeacd07e68e6c426d7fc21606acd27bf21c06df0aa /arch/powerpc
parenta32525449b30dfbae804f6b05cde041f35f5a811 (diff)
[POWERPC] add of_get_mac_address and update fsl_soc.c to use it
Add function of_get_mac_address(), which obtains the best MAC address to use from the device tree by checking various properties in order. The order is: 'mac-address', then 'local-mac-address', then 'address'. It skips properties that contain invalid MAC addresses, which were probably not initialized by U-Boot. Update gfar_of_init() and fs_enet_of_init() in fsl_soc.c to call of_get_mac_address(). Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/kernel/prom_parse.c40
-rw-r--r--arch/powerpc/sysdev/fsl_soc.c19
2 files changed, 47 insertions, 12 deletions
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 12c51e4ad2b4..ea6fd552c7ea 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -5,6 +5,7 @@
5#include <linux/pci_regs.h> 5#include <linux/pci_regs.h>
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/ioport.h> 7#include <linux/ioport.h>
8#include <linux/etherdevice.h>
8#include <asm/prom.h> 9#include <asm/prom.h>
9#include <asm/pci-bridge.h> 10#include <asm/pci-bridge.h>
10 11
@@ -1003,3 +1004,42 @@ int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq
1003 return res; 1004 return res;
1004} 1005}
1005EXPORT_SYMBOL_GPL(of_irq_map_one); 1006EXPORT_SYMBOL_GPL(of_irq_map_one);
1007
1008/**
1009 * Search the device tree for the best MAC address to use. 'mac-address' is
1010 * checked first, because that is supposed to contain to "most recent" MAC
1011 * address. If that isn't set, then 'local-mac-address' is checked next,
1012 * because that is the default address. If that isn't set, then the obsolete
1013 * 'address' is checked, just in case we're using an old device tree.
1014 *
1015 * Note that the 'address' property is supposed to contain a virtual address of
1016 * the register set, but some DTS files have redefined that property to be the
1017 * MAC address.
1018 *
1019 * All-zero MAC addresses are rejected, because those could be properties that
1020 * exist in the device tree, but were not set by U-Boot. For example, the
1021 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
1022 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
1023 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
1024 * but is all zeros.
1025*/
1026const void *of_get_mac_address(struct device_node *np)
1027{
1028 struct property *pp;
1029
1030 pp = of_find_property(np, "mac-address", NULL);
1031 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1032 return pp->value;
1033
1034 pp = of_find_property(np, "local-mac-address", NULL);
1035 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1036 return pp->value;
1037
1038 pp = of_find_property(np, "address", NULL);
1039 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
1040 return pp->value;
1041
1042 return NULL;
1043}
1044EXPORT_SYMBOL(of_get_mac_address);
1045
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 34161bc5a02f..d20f02927f72 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -233,14 +233,7 @@ static int __init gfar_of_init(void)
233 goto err; 233 goto err;
234 } 234 }
235 235
236 mac_addr = get_property(np, "local-mac-address", NULL); 236 mac_addr = of_get_mac_address(np);
237 if (mac_addr == NULL)
238 mac_addr = get_property(np, "mac-address", NULL);
239 if (mac_addr == NULL) {
240 /* Obsolete */
241 mac_addr = get_property(np, "address", NULL);
242 }
243
244 if (mac_addr) 237 if (mac_addr)
245 memcpy(gfar_data.mac_addr, mac_addr, 6); 238 memcpy(gfar_data.mac_addr, mac_addr, 6);
246 239
@@ -646,8 +639,9 @@ static int __init fs_enet_of_init(void)
646 goto unreg; 639 goto unreg;
647 } 640 }
648 641
649 mac_addr = get_property(np, "mac-address", NULL); 642 mac_addr = of_get_mac_address(np);
650 memcpy(fs_enet_data.macaddr, mac_addr, 6); 643 if (mac_addr)
644 memcpy(fs_enet_data.macaddr, mac_addr, 6);
651 645
652 ph = get_property(np, "phy-handle", NULL); 646 ph = get_property(np, "phy-handle", NULL);
653 phy = of_find_node_by_phandle(*ph); 647 phy = of_find_node_by_phandle(*ph);
@@ -931,8 +925,9 @@ static int __init fs_enet_of_init(void)
931 goto err; 925 goto err;
932 r[0].name = enet_regs; 926 r[0].name = enet_regs;
933 927
934 mac_addr = (void *)get_property(np, "mac-address", NULL); 928 mac_addr = of_get_mac_address(np);
935 memcpy(fs_enet_data.macaddr, mac_addr, 6); 929 if (mac_addr)
930 memcpy(fs_enet_data.macaddr, mac_addr, 6);
936 931
937 ph = (phandle *) get_property(np, "phy-handle", NULL); 932 ph = (phandle *) get_property(np, "phy-handle", NULL);
938 if (ph != NULL) 933 if (ph != NULL)