summaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/phy-c45.c
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2019-02-18 21:27:18 +0100
committerDavid S. Miller <davem@davemloft.net>2019-02-21 22:03:06 +0100
commit1af9f16840e920c6193490ae58371fc5cc28bb01 (patch)
tree4c19c623bf88f17e404ca52d7650c96c6691e21a /drivers/net/phy/phy-c45.c
parentnet: phy: use genphy_config_eee_advert in genphy_c45_an_config_aneg (diff)
downloadlinux-1af9f16840e920c6193490ae58371fc5cc28bb01.tar.xz
linux-1af9f16840e920c6193490ae58371fc5cc28bb01.zip
net: phy: add genphy_c45_check_and_restart_aneg
This function will be used by config_aneg callback implementations of PHY drivers and allows to reduce boilerplate code. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/phy-c45.c')
-rw-r--r--drivers/net/phy/phy-c45.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 2f5721430e05..fc3173cc078b 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -157,6 +157,36 @@ int genphy_c45_restart_aneg(struct phy_device *phydev)
EXPORT_SYMBOL_GPL(genphy_c45_restart_aneg);
/**
+ * genphy_c45_check_and_restart_aneg - Enable and restart auto-negotiation
+ * @phydev: target phy_device struct
+ * @restart: whether aneg restart is requested
+ *
+ * This assumes that the auto-negotiation MMD is present.
+ *
+ * Check, and restart auto-negotiation if needed.
+ */
+int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart)
+{
+ int ret = 0;
+
+ if (!restart) {
+ /* Configure and restart aneg if it wasn't set before */
+ ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
+ if (ret < 0)
+ return ret;
+
+ if (!(ret & MDIO_AN_CTRL1_ENABLE))
+ restart = true;
+ }
+
+ if (restart)
+ ret = genphy_c45_restart_aneg(phydev);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(genphy_c45_check_and_restart_aneg);
+
+/**
* genphy_c45_aneg_done - return auto-negotiation complete status
* @phydev: target phy_device struct
*