Skip to contentSkip to conversation

net: phy: mediatek: support MT7530 PHYs on EN71221 MCM

PATCH Superseded Caleb James DeLisle 2 participants 3 messages Sep 11 – Sep 15

Subsystems (5)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: phy: mediatek: support MT7530 PHYs on EN71221 MCM

The EcoNet EN751221 multi-chip module implementation of the MT7530 requires some additional configuration of the PHYs on startup. The reason for this is not known, but it is possible that it has to do with the fact that the EN751221 MCM implementation of the MT7530 runs at an abnormal PLL frequency (362.5Mhz).

Detect whether the MT7530 PHY is attached to the MDIO bus of an EcoNet EN751221 switch and if so, apply the necessary register updates. Additionally, never attempt to configure an MT7530 identified PHY which does not have gigabit support because the same ID is used for another (FE) PHY.

Of note: MDIO_AN_EEE_ADV must be zero at startup or else link will fail to connect. Setting MDIO_AN_EEE_ADV to 6 after link is brought up will make EEE work when cable is next plugged in, but link fails to downgrade to 100mb if gigabit is not possible, leaving a "connected" (nonfunctional) gigabit link.

---
 drivers/net/phy/mediatek/mtk-ge.c | 92 +++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
drivers/net/phy/mediatek/mtk-ge.c +92 -0
index 73d9b72f9d9e..587227d0f05c 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/of.h>
 #include <linux/bitfield.h>
 #include <linux/module.h>
 #include <linux/phy.h>
@@ -73,6 +74,81 @@ static int mt7530_phy_config_init(struct phy_device *phydev)
 	return 0;
 }
 
+/*
+ * The EcoNet EN751221 "G" multi-chip module MT7530 requires additional PHY
+ * configuration.
+ */
+static int en751221_mcm_phy_config_init(struct phy_device *phydev)
+{
+	int ret;
+
+	ret = genphy_soft_reset(phydev);
+	if (ret)
+		return ret;
+
+	/* Master/Slave negotiation does not work reliably */
+	ret = phy_write(phydev, MII_CTRL1000, ADVERTISE_1000FULL |
+			CTL1000_ENABLE_MASTER | CTL1000_PREFER_MASTER |
+			CTL1000_AS_MASTER);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_1,
+			      MTK_PHY_AUX_CTRL_AND_STATUS, 0x3a04);
+	if (ret < 0)
+		return ret;
+
+	/* Clause 45 global/local data from mt7530GePhyCfgLoad(E3.0). */
+	ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x0417, 0x7775);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00a6, 0x0350);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0012, 0xd210);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * MDIO_AN_EEE_ADV must be explicitly zeroed at initialization time or
+	 * the link will fail to establish - even if EEE is disabled later.
+	 */
+	phy_disable_eee(phydev);
+	ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
+	if (ret < 0)
+		return ret;
+
+	return mt7530_phy_config_init(phydev);
+}
+
+static bool en751221_is_mcm_phy(struct phy_device *phydev)
+{
+	struct device *parent = phydev->mdio.bus->parent;
+
+	return parent && parent->of_node &&
+	       of_device_is_compatible(parent->of_node, "econet,en751221");
+}
+
+/*
+ * MTK_GPHY_ID_MT7530 ID is also used for an EcoNet SoC FE phy, but that PHY
+ * does not advertise ESTATUS_1000_TFULL.
+ */
+static int mt7530_phy_match(struct phy_device *phydev,
+			    const struct phy_driver *phydrv)
+{
+	return (phy_read(phydev, MII_ESTATUS) & ESTATUS_1000_TFULL) != 0 &&
+		!en751221_is_mcm_phy(phydev);
+}
+
+static int en751221_phy_match(struct phy_device *phydev,
+			      const struct phy_driver *phydrv)
+{
+	return (phy_read(phydev, MII_ESTATUS) & ESTATUS_1000_TFULL) != 0 &&
+		en751221_is_mcm_phy(phydev);
+}
+
 static int mt7531_phy_config_init(struct phy_device *phydev)
 {
 	mtk_gephy_config_init(phydev);
@@ -106,6 +182,22 @@ static struct phy_driver mtk_gephy_driver[] = {
 		 */
 		.config_intr	= genphy_no_config_intr,
 		.handle_interrupt = genphy_handle_interrupt_no_ack,
+		.match_phy_device = mt7530_phy_match,
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
+	},
+	{
+		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530),
+		.name		= "EcoNet EN751221 MCM PHY",
+		.config_init	= en751221_mcm_phy_config_init,
+		/* Interrupts are handled by the switch, not the PHY
+		 * itself.
+		 */
+		.config_intr	= genphy_no_config_intr,
+		.handle_interrupt = genphy_handle_interrupt_no_ack,
+		.match_phy_device = en751221_phy_match,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
 		.read_page	= mtk_phy_read_page,
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 5 lines

+ * The EcoNet EN751221 "G" multi-chip module MT7530 requires additional PHY
+ * configuration.
+ */

drivers/net/phy/mediatek/mtk-ge.c +2 -0
+static int en751221_mcm_phy_config_init(struct phy_device *phydev)
+{

drivers/net/phy/mediatek/mtk-ge.c static int mt7530_phy_config_init(struct phy_device *phydev) · line 92

Quoted 10 lines
drivers/net/phy/mediatek/mtk-ge.c +10 -0
+	int ret;
+
+	ret = genphy_soft_reset(phydev);
+	if (ret)
+		return ret;
+
+	/* Master/Slave negotiation does not work reliably */
+	ret = phy_write(phydev, MII_CTRL1000, ADVERTISE_1000FULL |
+			CTL1000_ENABLE_MASTER | CTL1000_PREFER_MASTER |
+			CTL1000_AS_MASTER);

Is it sufficiently broken that we should stop the user changing it?

     ethtool     -s     devname    [speed N]    [lanes N]    [duplex half|full]
            [port tp|aui|bnc|mii] [mdix auto|on|off]  [autoneg on|off]  [adver‐
            tise N[/M]  |  advertise mode  on|off  ...]  [phyad N] [xcvr inter‐

nal|external] [wol N[/M] | wol p|u|m|b|a|g|s|f|d...]
[sopass xx:yy:zz:aa:bb:cc] [master-slave preferred-master|pre‐
ferred-slave|forced-master|forced-slave] [msglvl N[/M] | ms‐
glvl type on|off ...]

You don't appear to have a config_aneg, so genphy_config_aneg() will be used, which calls genphy_setup_master_slave.

Andrew

#2 lore raw
Quoted 8 lines · Andrew Lunn
Quoted 8 lines

+ * The EcoNet EN751221 "G" multi-chip module MT7530 requires additional PHY
+ * configuration.
+ */

drivers/net/phy/mediatek/mtk-ge.c +5 -0
+static int en751221_mcm_phy_config_init(struct phy_device *phydev)
+{
+	int ret;
+
+	ret = genphy_soft_reset(phydev);
Quoted 8 lines

drivers/net/phy/mediatek/mtk-ge.c static int mt7530_phy_config_init(struct phy_device *phydev) · line 92

Quoted 7 lines
drivers/net/phy/mediatek/mtk-ge.c +7 -0
+	if (ret)
+		return ret;
+
+	/* Master/Slave negotiation does not work reliably */
+	ret = phy_write(phydev, MII_CTRL1000, ADVERTISE_1000FULL |
+			CTL1000_ENABLE_MASTER | CTL1000_PREFER_MASTER |
+			CTL1000_AS_MASTER);

Is it sufficiently broken that we should stop the user changing it?

Well I must be going crazy because I tested this a second time and now it's working without forcing master at all. I guess when I was previously testing, I must have had some un-resetted state leftover from trying with EEE enabled. I will re-send without this command because it seems to work.

Thanks,

Caleb

Quoted 14 lines
      ethtool     -s     devname    [speed N]    [lanes N]    [duplex half|full]
             [port tp|aui|bnc|mii] [mdix auto|on|off]  [autoneg on|off]  [adver‐
             tise N[/M]  |  advertise mode  on|off  ...]  [phyad N] [xcvr inter‐

nal|external] [wol N[/M] | wol p|u|m|b|a|g|s|f|d...]
[sopass xx:yy:zz:aa:bb:cc] [master-slave preferred-master|pre‐
ferred-slave|forced-master|forced-slave] [msglvl N[/M] | ms‐
glvl type on|off ...]

You don't appear to have a config_aneg, so genphy_config_aneg() will be used, which calls genphy_setup_master_slave.

Andrew