aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/Kconfig4
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/of_net.c48
3 files changed, 53 insertions, 0 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index aa675ebd8eb3..e4b93a0a15d2 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -49,6 +49,10 @@ config OF_I2C
49 help 49 help
50 OpenFirmware I2C accessors 50 OpenFirmware I2C accessors
51 51
52config OF_NET
53 depends on NETDEVICES
54 def_bool y
55
52config OF_SPI 56config OF_SPI
53 def_tristate SPI 57 def_tristate SPI
54 depends on SPI && !SPARC 58 depends on SPI && !SPARC
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 7888155bea08..3ab21a0a4907 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_OF_IRQ) += irq.o
6obj-$(CONFIG_OF_DEVICE) += device.o platform.o 6obj-$(CONFIG_OF_DEVICE) += device.o platform.o
7obj-$(CONFIG_OF_GPIO) += gpio.o 7obj-$(CONFIG_OF_GPIO) += gpio.o
8obj-$(CONFIG_OF_I2C) += of_i2c.o 8obj-$(CONFIG_OF_I2C) += of_i2c.o
9obj-$(CONFIG_OF_NET) += of_net.o
9obj-$(CONFIG_OF_SPI) += of_spi.o 10obj-$(CONFIG_OF_SPI) += of_spi.o
10obj-$(CONFIG_OF_MDIO) += of_mdio.o 11obj-$(CONFIG_OF_MDIO) += of_mdio.o
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
new file mode 100644
index 000000000000..86f334a2769c
--- /dev/null
+++ b/drivers/of/of_net.c
@@ -0,0 +1,48 @@
1/*
2 * OF helpers for network devices.
3 *
4 * This file is released under the GPLv2
5 *
6 * Initially copied out of arch/powerpc/kernel/prom_parse.c
7 */
8#include <linux/etherdevice.h>
9#include <linux/kernel.h>
10#include <linux/of_net.h>
11
12/**
13 * Search the device tree for the best MAC address to use. 'mac-address' is
14 * checked first, because that is supposed to contain to "most recent" MAC
15 * address. If that isn't set, then 'local-mac-address' is checked next,
16 * because that is the default address. If that isn't set, then the obsolete
17 * 'address' is checked, just in case we're using an old device tree.
18 *
19 * Note that the 'address' property is supposed to contain a virtual address of
20 * the register set, but some DTS files have redefined that property to be the
21 * MAC address.
22 *
23 * All-zero MAC addresses are rejected, because those could be properties that
24 * exist in the device tree, but were not set by U-Boot. For example, the
25 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
26 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
27 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
28 * but is all zeros.
29*/
30const void *of_get_mac_address(struct device_node *np)
31{
32 struct property *pp;
33
34 pp = of_find_property(np, "mac-address", NULL);
35 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
36 return pp->value;
37
38 pp = of_find_property(np, "local-mac-address", NULL);
39 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
40 return pp->value;
41
42 pp = of_find_property(np, "address", NULL);
43 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
44 return pp->value;
45
46 return NULL;
47}
48EXPORT_SYMBOL(of_get_mac_address);