1 From: Tim Harvey <tharvey@gateworks.com>
2 Subject: [PATCH] sky2: allow mac to come from dt
4 The driver reads the mac address from the device registers which would
5 need to have been programmed by the bootloader. This patch adds
6 the ability to pull the mac from devicetree via the aliases/sky2 node.
8 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
10 drivers/net/ethernet/marvell/sky2.c | 33 ++++++++++++++++++++++++++++++++-
11 1 file changed, 32 insertions(+), 1 deletion(-)
13 --- a/drivers/net/ethernet/marvell/sky2.c
14 +++ b/drivers/net/ethernet/marvell/sky2.c
16 #include <linux/prefetch.h>
17 #include <linux/debugfs.h>
18 #include <linux/mii.h>
19 +#include <linux/of_device.h>
20 +#include <linux/of_net.h>
24 @@ -4748,6 +4750,7 @@ static struct net_device *sky2_init_netd
26 struct sky2_port *sky2;
27 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
28 + unsigned char *iap, tmpaddr[ETH_ALEN];
32 @@ -4802,8 +4805,36 @@ static struct net_device *sky2_init_netd
34 dev->features |= dev->hw_features;
37 + * try to get mac address in the following order:
38 + * 1) from device tree data
39 + * 2) from internal registers set by bootloader
42 + if (IS_ENABLED(CONFIG_OF)) {
43 + struct device_node *np;
44 + np = of_find_node_by_path("/aliases");
46 + const char *path = of_get_property(np, "sky2", NULL);
48 + np = of_find_node_by_path(path);
50 + path = of_get_mac_address(np);
52 + iap = (unsigned char *) path;
57 + * 2) mac registers set by bootloader
59 + if (!iap || !is_valid_ether_addr(iap)) {
60 + memcpy_fromio(&tmpaddr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
64 /* read the mac address */
65 - memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
66 + memcpy(dev->dev_addr, iap, ETH_ALEN);