Skip to content

Commit

Permalink
net: usb: ax88179_178a: allow optionally getting mac address from dev…
Browse files Browse the repository at this point in the history
…ice tree

Adopt and integrate the feature to pass the MAC address via device tree
from asix_device.c (03fc5d4) also to other ax88179 based asix chips.
E.g. the bootloader fills in local-mac-address and the driver will then
pick up and use this MAC address.

Signed-off-by: Peter Fink <pfink@christ-es.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Peter Fink authored and David S. Miller committed Oct 1, 2019
1 parent 0d7982c commit 9fb137a
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions drivers/net/usb/ax88179_178a.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,29 @@ static int ax88179_led_setting(struct usbnet *dev)
return 0;
}

static void ax88179_get_mac_addr(struct usbnet *dev)
{
u8 mac[ETH_ALEN];

/* Maybe the boot loader passed the MAC address via device tree */
if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) {
netif_dbg(dev, ifup, dev->net,
"MAC address read from device tree");
} else {
ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
ETH_ALEN, mac);
netif_dbg(dev, ifup, dev->net,
"MAC address read from ASIX chip");
}

if (is_valid_ether_addr(mac)) {
memcpy(dev->net->dev_addr, mac, ETH_ALEN);
} else {
netdev_info(dev->net, "invalid MAC address, using random\n");
eth_hw_addr_random(dev->net);
}
}

static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
{
u8 buf[5];
Expand All @@ -1240,8 +1263,8 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
msleep(100);

ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
ETH_ALEN, dev->net->dev_addr);
/* Read MAC address from DTB or asix chip */
ax88179_get_mac_addr(dev);
memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);

/* RX bulk configuration */
Expand Down Expand Up @@ -1541,8 +1564,8 @@ static int ax88179_reset(struct usbnet *dev)
/* Ethernet PHY Auto Detach*/
ax88179_auto_detach(dev, 0);

ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN,
dev->net->dev_addr);
/* Read MAC address from DTB or asix chip */
ax88179_get_mac_addr(dev);

/* RX bulk configuration */
memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
Expand Down

0 comments on commit 9fb137a

Please sign in to comment.