Skip to contentSkip to conversation

net: phy: DP83TC811: Introduce support for the DP83TC811 phy

PATCH Superseded Dan Murphy 2 participants 5 messages May 9, 2018

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

PATCH 1/1 net: phy: DP83TC811: Introduce support for the DP83TC811 phy

Add support for the DP83811 phy.

The DP83811 supports both rgmii and sgmii interfaces. There are 2 part numbers for this the DP83TC811R does not reliably support the SGMII interface but the DP83TC811S will.

There is not a way to differentiate these parts from the hardware or register set. So this is controlled via the DT to indicate which phy mode is required. Or the part can be strapped to a certain interface.

Data sheet can be found here:
http://www.ti.com/product/DP83TC811S-Q1/description
http://www.ti.com/product/DP83TC811R-Q1/description

---
 drivers/net/phy/Kconfig     |   5 +
 drivers/net/phy/Makefile    |   1 +
 drivers/net/phy/dp83tc811.c | 350 ++++++++++++++++++++++++++++++++++++
 3 files changed, 356 insertions(+)
 create mode 100644 drivers/net/phy/dp83tc811.c
drivers/net/phy/Kconfig +5 -0
index bdfbabb86ee0..810140a9e114 100644
@@ -285,6 +285,11 @@ config DP83822_PHY
 	---help---
 	  Supports the DP83822 PHY.
 
+config DP83TC811_PHY
+	tristate "Texas Instruments DP83TC822 PHY"
+	---help---
+	  Supports the DP83TC822 PHY.
+
 config DP83848_PHY
 	tristate "Texas Instruments DP83848 PHY"
 	---help---
drivers/net/phy/Makefile +1 -0
index 01acbcb2c798..00445b61a9a8 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_CORTINA_PHY)	+= cortina.o
 obj-$(CONFIG_DAVICOM_PHY)	+= davicom.o
 obj-$(CONFIG_DP83640_PHY)	+= dp83640.o
 obj-$(CONFIG_DP83822_PHY)	+= dp83822.o
+obj-$(CONFIG_DP83TC811_PHY)	+= dp83tc811.o
 obj-$(CONFIG_DP83848_PHY)	+= dp83848.o
 obj-$(CONFIG_DP83867_PHY)	+= dp83867.o
 obj-$(CONFIG_FIXED_PHY)		+= fixed_phy.o
drivers/net/phy/dp83tc811.c new file +350 -0

350 lines not on this page · raw message

Signature · 1 line
2.17.0.582.gccdcbd54c
maintainer
#1 lore raw
Quoted 8 lines
drivers/net/phy/dp83tc811.c new file +8 -0
+static int dp83811_config_aneg(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+	if (phydev->autoneg == AUTONEG_ENABLE) {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,

drivers/net/phy/dp83tc811.c line 249

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+				(DP83811_SGMII_AUTO_NEG_EN | value));
+		if (err < 0)
+			return err;
+	} else {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_AUTO_NEG_EN & value));
+		if (err < 0)
+			return err;
+	}
+

Hi Dan

You say SGMII is unreliable on one of these devices. Should you check phydev->interface before enabling SGMII autoneg?

Quoted 15 lines
drivers/net/phy/dp83tc811.c new file +15 -0
+	return genphy_config_aneg(phydev);
+}
+
+static int dp83811_config_init(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	err = genphy_config_init(phydev);
+	if (err < 0)
+		return err;
+
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+		if (!(value & DP83811_SGMII_EN)) {

drivers/net/phy/dp83tc811.c line 274

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+					(DP83811_SGMII_EN | value));
+			if (err < 0)
+				return err;
+		} else {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_EN & value));
+			if (err < 0)
+				return err;
+		}

This looks to be a duplicate of dp83811_config_aneg()?

Quoted 7 lines
drivers/net/phy/dp83tc811.c new file +7 -0
+	}
+
+	value = DP83811_WOL_MAGIC_EN | DP83811_WOL_SECURE_ON | DP83811_WOL_EN;
+
+	return phy_write_mmd(phydev, DP83811_DEVADDR, MII_DP83811_WOL_CFG,
+	      value);
+}

drivers/net/phy/dp83tc811.c line 291

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+
+static int dp83811_phy_reset(struct phy_device *phydev)
+{
+	int err;
+
+	err = phy_write(phydev, MII_DP83811_RESET_CTRL, DP83811_HW_RESET);
+	if (err < 0)
+		return err;
+
+	dp83811_config_init(phydev);

I don't think you need to initialize it here. phylib should call that soon after the reset.

drivers/net/phy/dp83tc811.c line 329

Quoted 13 lines
drivers/net/phy/dp83tc811.c new file +12 -0
+
+	return 0;
+}
+
 
+static struct phy_driver dp83811_driver[] = {
+	{
+		.phy_id = DP83TC811_PHY_ID,
+		.phy_id_mask = 0xfffffff0,
+		.name = "TI DP83TC811",
+		.features = PHY_BASIC_FEATURES,
+		.flags = PHY_HAS_INTERRUPT,
+		.config_init = genphy_config_init,

????

Andrew

author
#2 lore raw

Andrew

Thanks for the review

Quoted 21 lines · Andrew Lunn
Quoted 8 lines
drivers/net/phy/dp83tc811.c new file +8 -0
+static int dp83811_config_aneg(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+	if (phydev->autoneg == AUTONEG_ENABLE) {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,

drivers/net/phy/dp83tc811.c line 249

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+				(DP83811_SGMII_AUTO_NEG_EN | value));
+		if (err < 0)
+			return err;
+	} else {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_AUTO_NEG_EN & value));
+		if (err < 0)
+			return err;
+	}
+

Hi Dan

Quoted 2 lines

You say SGMII is unreliable on one of these devices. Should you check phydev->interface before enabling SGMII autoneg?

If SGMII enable bit(12) is not set in the device then setting auto neg has no affect on the device.
Only the SGMII has auto negotiation capability so if we set this with other MII interfaces then it is ignored by the device.

If we want to protect this with the SGMII check I can add it but it may be over kill.

Let me know what is preferred.

Quoted 20 lines
Quoted 20 lines
drivers/net/phy/dp83tc811.c new file +19 -0
+	return genphy_config_aneg(phydev);
+}
+
+static int dp83811_config_init(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	err = genphy_config_init(phydev);
+	if (err < 0)
+		return err;
+
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+		if (!(value & DP83811_SGMII_EN)) {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+					(DP83811_SGMII_EN | value));
+			if (err < 0)
+				return err;
Quoted 8 lines

drivers/net/phy/dp83tc811.c line 274

Quoted 6 lines
drivers/net/phy/dp83tc811.c new file +6 -0
+		} else {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_EN & value));
+			if (err < 0)
+				return err;
+		}

This looks to be a duplicate of dp83811_config_aneg()?

It is almost the same but this function sets bit 12 and aneg function sets bit 13. We can have SGMII with or without auto neg.

Quoted 13 lines
Quoted 13 lines
drivers/net/phy/dp83tc811.c new file +12 -0
+	}
+
+	value = DP83811_WOL_MAGIC_EN | DP83811_WOL_SECURE_ON | DP83811_WOL_EN;
+
+	return phy_write_mmd(phydev, DP83811_DEVADDR, MII_DP83811_WOL_CFG,
+	      value);
+}
+
+static int dp83811_phy_reset(struct phy_device *phydev)
+{
+	int err;
+
Quoted 8 lines

drivers/net/phy/dp83tc811.c line 291

Quoted 5 lines
drivers/net/phy/dp83tc811.c new file +5 -0
+	err = phy_write(phydev, MII_DP83811_RESET_CTRL, DP83811_HW_RESET);
+	if (err < 0)
+		return err;
+
+	dp83811_config_init(phydev);

I don't think you need to initialize it here. phylib should call that soon after the reset.

OK I will remove it.

Quoted 6 lines
Quoted 5 lines
drivers/net/phy/dp83tc811.c new file +4 -0
+
+	return 0;
+}
+
Quoted 11 lines

drivers/net/phy/dp83tc811.c line 329

Quoted 8 lines
drivers/net/phy/dp83tc811.c new file +8 -0
+static struct phy_driver dp83811_driver[] = {
+	{
+		.phy_id = DP83TC811_PHY_ID,
+		.phy_id_mask = 0xfffffff0,
+		.name = "TI DP83TC811",
+		.features = PHY_BASIC_FEATURES,
+		.flags = PHY_HAS_INTERRUPT,
+		.config_init = genphy_config_init,

????

I missed that I must have had the config init being called in my testing through the reset function. I will update.

Quoted 2 lines

Andrew

Signature · 2 lines
------------------
Dan Murphy
maintainer
#3 lore raw
Quoted 26 lines · Dan Murphy

Andrew

Thanks for the review

Quoted 21 lines · Andrew Lunn
Quoted 8 lines
drivers/net/phy/dp83tc811.c new file +8 -0
+static int dp83811_config_aneg(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+	if (phydev->autoneg == AUTONEG_ENABLE) {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,

drivers/net/phy/dp83tc811.c line 249

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+				(DP83811_SGMII_AUTO_NEG_EN | value));
+		if (err < 0)
+			return err;
+	} else {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_AUTO_NEG_EN & value));
+		if (err < 0)
+			return err;
+	}
+

Hi Dan

Quoted 5 lines
Quoted 2 lines

You say SGMII is unreliable on one of these devices. Should you check phydev->interface before enabling SGMII autoneg?

If SGMII enable bit(12) is not set in the device then setting auto neg has no affect on the device.

Ah, O.K. Maybe add a comment about this.

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/phy/dp83tc811.c new file +17 -0
+
+static int dp83811_config_init(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	err = genphy_config_init(phydev);
+	if (err < 0)
+		return err;
+
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+		if (!(value & DP83811_SGMII_EN)) {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+					(DP83811_SGMII_EN | value));
+			if (err < 0)
+				return err;
Quoted 8 lines

drivers/net/phy/dp83tc811.c line 274

Quoted 6 lines
drivers/net/phy/dp83tc811.c new file +6 -0
+		} else {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_EN & value));
+			if (err < 0)
+				return err;
+		}

This looks to be a duplicate of dp83811_config_aneg()?

Quoted 2 lines

It is almost the same but this function sets bit 12 and aneg function sets bit 13. We can have SGMII with or without auto neg.

Yep, i missed the difference.

Andrew

author
#4 lore raw

Andrew

Quoted 27 lines · Andrew Lunn
Quoted 26 lines · Dan Murphy

Andrew

Thanks for the review

Quoted 21 lines · Andrew Lunn
Quoted 8 lines
drivers/net/phy/dp83tc811.c new file +8 -0
+static int dp83811_config_aneg(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+	if (phydev->autoneg == AUTONEG_ENABLE) {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,

drivers/net/phy/dp83tc811.c line 249

Quoted 10 lines
drivers/net/phy/dp83tc811.c new file +10 -0
+				(DP83811_SGMII_AUTO_NEG_EN | value));
+		if (err < 0)
+			return err;
+	} else {
+		err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_AUTO_NEG_EN & value));
+		if (err < 0)
+			return err;
+	}
+

Hi Dan

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

You say SGMII is unreliable on one of these devices. Should you check phydev->interface before enabling SGMII autoneg?

If SGMII enable bit(12) is not set in the device then setting auto neg has no affect on the device.

Ah, O.K. Maybe add a comment about this.

I will add the check it will be clearer if written in code and explicit as opposed to explaining it.

Dan

Quoted 33 lines
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/phy/dp83tc811.c new file +17 -0
+
+static int dp83811_config_init(struct phy_device *phydev)
+{
+	int err;
+	int value;
+
+	err = genphy_config_init(phydev);
+	if (err < 0)
+		return err;
+
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		value = phy_read(phydev, MII_DP83811_SGMII_CTRL);
+		if (!(value & DP83811_SGMII_EN)) {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+					(DP83811_SGMII_EN | value));
+			if (err < 0)
+				return err;
Quoted 8 lines

drivers/net/phy/dp83tc811.c line 274

Quoted 6 lines
drivers/net/phy/dp83tc811.c new file +6 -0
+		} else {
+			err = phy_write(phydev, MII_DP83811_SGMII_CTRL,
+				(~DP83811_SGMII_EN & value));
+			if (err < 0)
+				return err;
+		}

This looks to be a duplicate of dp83811_config_aneg()?

Quoted 2 lines

It is almost the same but this function sets bit 12 and aneg function sets bit 13. We can have SGMII with or without auto neg.

Yep, i missed the difference.

Andrew

Signature · 2 lines
------------------
Dan Murphy