imx6: refresh patches
[openwrt/openwrt.git] / target / linux / imx6 / patches-3.10 / 0050-sky2-allow-mac-to-come-from-dt.patch
1 From: Tim Harvey <tharvey@gateworks.com>
2 Subject: [PATCH] sky2: allow mac to come from dt
3
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.
7
8 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
9 ---
10 drivers/net/ethernet/marvell/sky2.c | 33 ++++++++++++++++++++++++++++++++-
11 1 file changed, 32 insertions(+), 1 deletion(-)
12
13 --- a/drivers/net/ethernet/marvell/sky2.c
14 +++ b/drivers/net/ethernet/marvell/sky2.c
15 @@ -44,6 +44,8 @@
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>
21
22 #include <asm/irq.h>
23
24 @@ -4748,6 +4750,7 @@ static struct net_device *sky2_init_netd
25 {
26 struct sky2_port *sky2;
27 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
28 + unsigned char *iap, tmpaddr[ETH_ALEN];
29
30 if (!dev)
31 return NULL;
32 @@ -4802,8 +4805,36 @@ static struct net_device *sky2_init_netd
33
34 dev->features |= dev->hw_features;
35
36 + /*
37 + * try to get mac address in the following order:
38 + * 1) from device tree data
39 + * 2) from internal registers set by bootloader
40 + */
41 + iap = NULL;
42 + if (IS_ENABLED(CONFIG_OF)) {
43 + struct device_node *np;
44 + np = of_find_node_by_path("/aliases");
45 + if (np) {
46 + const char *path = of_get_property(np, "sky2", NULL);
47 + if (path)
48 + np = of_find_node_by_path(path);
49 + if (np)
50 + path = of_get_mac_address(np);
51 + if (path)
52 + iap = (unsigned char *) path;
53 + }
54 + }
55 +
56 + /*
57 + * 2) mac registers set by bootloader
58 + */
59 + if (!iap || !is_valid_ether_addr(iap)) {
60 + memcpy_fromio(&tmpaddr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
61 + iap = &tmpaddr[0];
62 + }
63 +
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);
67
68 return dev;
69 }