Skip to content

Commit

Permalink
lan743x: replace devicetree phy parse code with library function
Browse files Browse the repository at this point in the history
The code in this driver which parses the devicetree to determine
the phy/fixed link setup, can be replaced by a single library
function: of_phy_get_and_connect().

Behaviour is identical, except that the library function will
complain when 'phy-connection-type' is omitted, instead of
blindly using PHY_INTERFACE_MODE_NA, which would result in an
invalid phy configuration.

The library function no longer brings out the exact phy_mode,
but the driver doesn't need this, because phy_interface_is_rgmii()
queries the phydev directly. Remove 'phy_mode' from the private
adapter struct.

While we're here, log info about the attached phy on connect,
this is useful because the phy type and connection method is now
fully configurable via the devicetree.

Tested on a lan7430 chip with built-in phy. Verified that adding
fixed-link/phy-connection-type in the devicetree results in a
fixed-link setup. Used ethtool to verify that the devicetree
settings are used.

Tested-by: Sven Van Asbroeck <thesven73@gmail.com> # lan7430
Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20201116170155.26967-1-TheSven73@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Sven Van Asbroeck authored and Jakub Kicinski committed Nov 17, 2020
1 parent a98cabd commit 7c3e2b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
35 changes: 8 additions & 27 deletions drivers/net/ethernet/microchip/lan743x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ static void lan743x_phy_link_status_change(struct net_device *netdev)
data = lan743x_csr_read(adapter, MAC_CR);

/* set interface mode */
if (phy_interface_mode_is_rgmii(adapter->phy_mode))
if (phy_interface_is_rgmii(phydev))
/* RGMII */
data &= ~MAC_CR_MII_EN_;
else
Expand Down Expand Up @@ -1012,44 +1012,24 @@ static void lan743x_phy_close(struct lan743x_adapter *adapter)

static int lan743x_phy_open(struct lan743x_adapter *adapter)
{
struct net_device *netdev = adapter->netdev;
struct lan743x_phy *phy = &adapter->phy;
struct phy_device *phydev = NULL;
struct device_node *phynode;
struct net_device *netdev;
struct phy_device *phydev;
int ret = -EIO;

netdev = adapter->netdev;
phynode = of_node_get(adapter->pdev->dev.of_node);

if (phynode) {
/* try devicetree phy, or fixed link */
of_get_phy_mode(phynode, &adapter->phy_mode);

if (of_phy_is_fixed_link(phynode)) {
ret = of_phy_register_fixed_link(phynode);
if (ret) {
netdev_err(netdev,
"cannot register fixed PHY\n");
of_node_put(phynode);
goto return_error;
}
}
phydev = of_phy_connect(netdev, phynode,
lan743x_phy_link_status_change, 0,
adapter->phy_mode);
of_node_put(phynode);
}
/* try devicetree phy, or fixed link */
phydev = of_phy_get_and_connect(netdev, adapter->pdev->dev.of_node,
lan743x_phy_link_status_change);

if (!phydev) {
/* try internal phy */
phydev = phy_find_first(adapter->mdiobus);
if (!phydev)
goto return_error;

adapter->phy_mode = PHY_INTERFACE_MODE_GMII;
ret = phy_connect_direct(netdev, phydev,
lan743x_phy_link_status_change,
adapter->phy_mode);
PHY_INTERFACE_MODE_GMII);
if (ret)
goto return_error;
}
Expand All @@ -1064,6 +1044,7 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)

phy_start(phydev);
phy_start_aneg(phydev);
phy_attached_info(phydev);
return 0;

return_error:
Expand Down
1 change: 0 additions & 1 deletion drivers/net/ethernet/microchip/lan743x_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ struct lan743x_rx {
struct lan743x_adapter {
struct net_device *netdev;
struct mii_bus *mdiobus;
phy_interface_t phy_mode;
int msg_enable;
#ifdef CONFIG_PM
u32 wolopts;
Expand Down

0 comments on commit 7c3e2b7

Please sign in to comment.