Skip to content

Commit 9fb137a

Browse files
pfink-christdavem330
authored andcommitted
net: usb: ax88179_178a: allow optionally getting mac address from device 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 <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0d7982c commit 9fb137a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

drivers/net/usb/ax88179_178a.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,29 @@ static int ax88179_led_setting(struct usbnet *dev)
12141214
return 0;
12151215
}
12161216

1217+
static void ax88179_get_mac_addr(struct usbnet *dev)
1218+
{
1219+
u8 mac[ETH_ALEN];
1220+
1221+
/* Maybe the boot loader passed the MAC address via device tree */
1222+
if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) {
1223+
netif_dbg(dev, ifup, dev->net,
1224+
"MAC address read from device tree");
1225+
} else {
1226+
ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
1227+
ETH_ALEN, mac);
1228+
netif_dbg(dev, ifup, dev->net,
1229+
"MAC address read from ASIX chip");
1230+
}
1231+
1232+
if (is_valid_ether_addr(mac)) {
1233+
memcpy(dev->net->dev_addr, mac, ETH_ALEN);
1234+
} else {
1235+
netdev_info(dev->net, "invalid MAC address, using random\n");
1236+
eth_hw_addr_random(dev->net);
1237+
}
1238+
}
1239+
12171240
static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
12181241
{
12191242
u8 buf[5];
@@ -1240,8 +1263,8 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
12401263
ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
12411264
msleep(100);
12421265

1243-
ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
1244-
ETH_ALEN, dev->net->dev_addr);
1266+
/* Read MAC address from DTB or asix chip */
1267+
ax88179_get_mac_addr(dev);
12451268
memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
12461269

12471270
/* RX bulk configuration */
@@ -1541,8 +1564,8 @@ static int ax88179_reset(struct usbnet *dev)
15411564
/* Ethernet PHY Auto Detach*/
15421565
ax88179_auto_detach(dev, 0);
15431566

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

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

0 commit comments

Comments
 (0)