diff mbox series

[12/16] net: phy: adin: read EEE setting from device-tree

Message ID 20190805165453.3989-13-alexandru.ardelean@analog.com
State Changes Requested
Delegated to: David Miller
Headers show
Series net: phy: adin: add support for Analog Devices PHYs | expand

Commit Message

Alexandru Ardelean Aug. 5, 2019, 4:54 p.m. UTC
By default, EEE is not advertised on system init. This change allows the
user to specify a device property to enable EEE advertisements when the PHY
initializes.

Also, before resetting the PHY, the EEE settings are read, so that after
the reset is complete, they are written back into the EEE advertisement
register.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/net/phy/adin.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Andrew Lunn Aug. 5, 2019, 3:19 p.m. UTC | #1
On Mon, Aug 05, 2019 at 07:54:49PM +0300, Alexandru Ardelean wrote:
> By default, EEE is not advertised on system init. This change allows the
> user to specify a device property to enable EEE advertisements when the PHY
> initializes.
 
This patch is not required. If EEE is not being advertised when it
should, it means there is a MAC driver bug.

	Andrew
Alexandru Ardelean Aug. 6, 2019, 6:52 a.m. UTC | #2
On Mon, 2019-08-05 at 17:19 +0200, Andrew Lunn wrote:
> [External]
> 
> On Mon, Aug 05, 2019 at 07:54:49PM +0300, Alexandru Ardelean wrote:
> > By default, EEE is not advertised on system init. This change allows the
> > user to specify a device property to enable EEE advertisements when the PHY
> > initializes.
>  
> This patch is not required. If EEE is not being advertised when it
> should, it means there is a MAC driver bug.

ack;
same thing about PHY specifics ignoring MAC specifics

thanks

> 
> 	Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c
index 476a81ce9341..cf99ccacfeeb 100644
--- a/drivers/net/phy/adin.c
+++ b/drivers/net/phy/adin.c
@@ -94,9 +94,11 @@  static struct clause22_mmd_map clause22_mmd_map[] = {
 /**
  * struct adin_priv - ADIN PHY driver private data
  * gpiod_reset		optional reset GPIO, to be used in soft_reset() cb
+ * eee_modes		EEE modes to advertise after reset
  */
 struct adin_priv {
 	struct gpio_desc	*gpiod_reset;
+	u8			eee_modes;
 };
 
 static int adin_get_phy_internal_mode(struct phy_device *phydev)
@@ -216,6 +218,23 @@  static int adin_config_rmii_mode(struct phy_device *phydev,
 			     ADIN1300_GE_RMII_CFG_REG, reg);
 }
 
+static int adin_config_init_eee(struct phy_device *phydev)
+{
+	struct adin_priv *priv = phydev->priv;
+	int reg;
+
+	reg = phy_read_mmd(phydev, MDIO_MMD_VEND1, ADIN1300_EEE_ADV_REG);
+	if (reg < 0)
+		return reg;
+
+	if (priv->eee_modes)
+		reg |= priv->eee_modes;
+	else
+		reg &= ~(MDIO_EEE_100TX | MDIO_EEE_1000T);
+
+	return phy_write_mmd(phydev, MDIO_MMD_VEND1, ADIN1300_EEE_ADV_REG, reg);
+}
+
 static int adin_config_init(struct phy_device *phydev)
 {
 	phy_interface_t interface, rc;
@@ -238,6 +257,10 @@  static int adin_config_init(struct phy_device *phydev)
 	if (rc < 0)
 		return rc;
 
+	rc = adin_config_init_eee(phydev);
+	if (rc < 0)
+		return rc;
+
 	if (phydev->interface == interface)
 		dev_info(&phydev->mdio.dev, "PHY is using mode '%s'\n",
 			 phy_modes(phydev->interface));
@@ -473,6 +496,12 @@  static int adin_reset(struct phy_device *phydev)
 	struct adin_priv *priv = phydev->priv;
 	int ret;
 
+	/* Update EEE settings before resetting, in case ethtool changed them */
+	ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, ADIN1300_EEE_ADV_REG);
+	if (ret < 0)
+		return ret;
+	priv->eee_modes = (ret & (MDIO_EEE_100TX | MDIO_EEE_1000T));
+
 	if (priv->gpiod_reset) {
 		/* GPIO reset requires min 10 uS low,
 		 * 5 msecs max before we know that the interface is up again
@@ -504,6 +533,8 @@  static int adin_probe(struct phy_device *phydev)
 		gpiod_reset = NULL;
 
 	priv->gpiod_reset = gpiod_reset;
+	if (device_property_read_bool(dev, "adi,eee-enabled"))
+		priv->eee_modes = (MDIO_EEE_100TX | MDIO_EEE_1000T);
 	phydev->priv = priv;
 
 	return adin_reset(phydev);