imx6: use upstream gateworks board names
[openwrt.git] / target / linux / imx6 / patches-3.10 / 020-marvell-sky2-macdt.patch
1 --- a/drivers/net/ethernet/marvell/sky2.c
2 +++ b/drivers/net/ethernet/marvell/sky2.c
3 @@ -44,6 +44,8 @@
4  #include <linux/prefetch.h>
5  #include <linux/debugfs.h>
6  #include <linux/mii.h>
7 +#include <linux/of_device.h>
8 +#include <linux/of_net.h>
9  
10  #include <asm/irq.h>
11  
12 @@ -4748,6 +4750,7 @@ static struct net_device *sky2_init_netd
13  {
14         struct sky2_port *sky2;
15         struct net_device *dev = alloc_etherdev(sizeof(*sky2));
16 +       unsigned char *iap, tmpaddr[ETH_ALEN];
17  
18         if (!dev)
19                 return NULL;
20 @@ -4802,8 +4805,36 @@ static struct net_device *sky2_init_netd
21  
22         dev->features |= dev->hw_features;
23  
24 +       /*
25 +        * try to get mac address in the following order:
26 +        * 1) from device tree data
27 +        * 2) from internal registers set by bootloader
28 +        */
29 +       iap = NULL;
30 +#ifdef CONFIG_OF
31 +       struct device_node *np;
32 +       np = of_find_node_by_path("/aliases");
33 +       if (np) {
34 +               const char *path = of_get_property(np, "sky2", NULL);
35 +       if (path)
36 +               np = of_find_node_by_path(path);
37 +       if (np)
38 +               path = of_get_mac_address(np);
39 +       if (path)
40 +               iap = (unsigned char *) path;
41 +       }
42 +#endif
43 +
44 +       /*
45 +        * 2) mac registers set by bootloader
46 +        */
47 +       if (!iap || !is_valid_ether_addr(iap)) {
48 +               memcpy_fromio(&tmpaddr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
49 +               iap = &tmpaddr[0];
50 +       }
51 +
52         /* read the mac address */
53 -       memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN);
54 +       memcpy(dev->dev_addr, iap, ETH_ALEN);
55  
56         return dev;
57  }