Commit b5375509 authored by Rafał Miłecki's avatar Rafał Miłecki Committed by David S. Miller
Browse files

net: bgmac: improve handling PHY



1. Use info from DT if available

It allows describing for example a fixed link. It's more accurate than
just guessing there may be one (depending on a chipset).

2. Verify PHY ID before trying to connect PHY

PHY addr 0x1e (30) is special in Broadcom routers and means a switch
connected as MDIO devices instead of a real PHY. Don't try connecting to
it.

Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ceca777d
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/bcma/bcma.h>
#include <linux/brcmphy.h>
#include <linux/etherdevice.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include "bgmac.h"

@@ -86,7 +87,14 @@ static int bcma_phy_connect(struct bgmac *bgmac)
	struct phy_device *phy_dev;
	char bus_id[MII_BUS_ID_SIZE + 3];

	/* DT info should be the most accurate */
	phy_dev = of_phy_get_and_connect(bgmac->net_dev, bgmac->dev->of_node,
					 bgmac_adjust_link);
	if (phy_dev)
		return 0;

	/* Connect to the PHY */
	if (bgmac->mii_bus && bgmac->phyaddr != BGMAC_PHY_NOREGS) {
		snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
			 bgmac->phyaddr);
		phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link,
@@ -99,6 +107,10 @@ static int bcma_phy_connect(struct bgmac *bgmac)
		return 0;
	}

	/* Assume a fixed link to the switch port */
	return bgmac_phy_connect_direct(bgmac);
}

static const struct bcma_device_id bgmac_bcma_tbl[] = {
	BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
		  BCMA_ANY_REV, BCMA_ANY_CLASS),
@@ -297,10 +309,7 @@ static int bgmac_probe(struct bcma_device *core)
	bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
	bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
	bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
	if (bgmac->mii_bus)
	bgmac->phy_connect = bcma_phy_connect;
	else
		bgmac->phy_connect = bgmac_phy_connect_direct;

	err = bgmac_enet_probe(bgmac);
	if (err)