Skip to content

Commit 03fc5d4

Browse files
ziswilerdavem330
authored andcommitted
net: usb: asix: allow optionally getting mac address from device tree
For Embedded use where e.g. AX88772B chips may be used without external EEPROMs the boot loader may choose to pass the MAC address to be used via device tree. Therefore, allow for optionally getting the MAC address from device tree data e.g. as follows (excerpt from a T30 based board, local-mac-address to be filled in by boot loader): /* EHCI instance 1: USB2_DP/N -> AX88772B */ usb@7d004000 { status = "okay"; #address-cells = <1>; #size-cells = <0>; asix@1 { reg = <1>; local-mac-address = [00 00 00 00 00 00]; }; }; Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 30e99ed commit 03fc5d4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

drivers/net/usb/asix_devices.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -691,24 +691,32 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
691691
u32 phyid;
692692
struct asix_common_private *priv;
693693

694-
usbnet_get_endpoints(dev,intf);
694+
usbnet_get_endpoints(dev, intf);
695695

696-
/* Get the MAC address */
697-
if (dev->driver_info->data & FLAG_EEPROM_MAC) {
698-
for (i = 0; i < (ETH_ALEN >> 1); i++) {
699-
ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
700-
0, 2, buf + i * 2, 0);
701-
if (ret < 0)
702-
break;
703-
}
696+
/* Maybe the boot loader passed the MAC address via device tree */
697+
if (!eth_platform_get_mac_address(&dev->udev->dev, buf)) {
698+
netif_dbg(dev, ifup, dev->net,
699+
"MAC address read from device tree");
704700
} else {
705-
ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
706-
0, 0, ETH_ALEN, buf, 0);
707-
}
701+
/* Try getting the MAC address from EEPROM */
702+
if (dev->driver_info->data & FLAG_EEPROM_MAC) {
703+
for (i = 0; i < (ETH_ALEN >> 1); i++) {
704+
ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
705+
0x04 + i, 0, 2, buf + i * 2,
706+
0);
707+
if (ret < 0)
708+
break;
709+
}
710+
} else {
711+
ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
712+
0, 0, ETH_ALEN, buf, 0);
713+
}
708714

709-
if (ret < 0) {
710-
netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
711-
return ret;
715+
if (ret < 0) {
716+
netdev_dbg(dev->net, "Failed to read MAC address: %d\n",
717+
ret);
718+
return ret;
719+
}
712720
}
713721

714722
asix_set_netdev_dev_addr(dev, buf);

0 commit comments

Comments
 (0)