diff mbox series

[v3] net: mv643xx_eth: support MII/GMII/RGMII modes for Kirkwood

Message ID 20220930213534.962336-1-mmyangfl@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v3] net: mv643xx_eth: support MII/GMII/RGMII modes for Kirkwood | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6 this patch: 6
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 88 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

David Yang Sept. 30, 2022, 9:35 p.m. UTC
Support mode switch properly, which is not available before.

If SoC has two Ethernet controllers, by setting both of them into MII
mode, the first controller enters GMII mode, while the second
controller is effectively disabled. This requires configuring (and
maybe enabling) the second controller in the device tree, even though
it cannot be used.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v2: clarify modes work on controllers, read default value from PSC1
v3: Kirkwood only
 drivers/net/ethernet/marvell/mv643xx_eth.c | 48 ++++++++++++++++++++--
 1 file changed, 44 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index b6be0552a..355bb8ba7 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -108,6 +108,7 @@  static char mv643xx_eth_driver_version[] = "1.4";
 #define TXQ_COMMAND			0x0048
 #define TXQ_FIX_PRIO_CONF		0x004c
 #define PORT_SERIAL_CONTROL1		0x004c
+#define  RGMII_EN			0x00000008
 #define  CLK125_BYPASS_EN		0x00000010
 #define TX_BW_RATE			0x0050
 #define TX_BW_MTU			0x0058
@@ -367,6 +368,7 @@  struct mv643xx_eth_private {
 	struct mv643xx_eth_shared_private *shared;
 	void __iomem *base;
 	int port_num;
+	bool kirkwood;
 
 	struct net_device *dev;
 
@@ -1215,6 +1217,7 @@  static void mv643xx_eth_adjust_link(struct net_device *dev)
 	             DISABLE_AUTO_NEG_SPEED_GMII |
 		     DISABLE_AUTO_NEG_FOR_FLOW_CTRL |
 		     DISABLE_AUTO_NEG_FOR_DUPLEX;
+	u32 psc1r;
 
 	if (dev->phydev->autoneg == AUTONEG_ENABLE) {
 		/* enable auto negotiation */
@@ -1245,6 +1248,36 @@  static void mv643xx_eth_adjust_link(struct net_device *dev)
 
 out_write:
 	wrlp(mp, PORT_SERIAL_CONTROL, pscr);
+
+	if (mp->kirkwood) {
+		psc1r = rdlp(mp, PORT_SERIAL_CONTROL1);
+		/* On Kirkwood with two Ethernet controllers, if both of them
+		 * have RGMII_EN disabled, the first controller will be in GMII
+		 * mode and the second one is effectively disabled, instead of
+		 * two MII interfaces.
+		 *
+		 * To enable GMII in the first controller, the second one must
+		 * also be configured (and may be enabled) with RGMII_EN
+		 * disabled too, even though it cannot be used at all.
+		 */
+		switch (dev->phydev->interface) {
+		case PHY_INTERFACE_MODE_MII:
+		case PHY_INTERFACE_MODE_GMII:
+			psc1r &= ~RGMII_EN;
+			break;
+		case PHY_INTERFACE_MODE_RGMII:
+		case PHY_INTERFACE_MODE_RGMII_ID:
+		case PHY_INTERFACE_MODE_RGMII_RXID:
+		case PHY_INTERFACE_MODE_RGMII_TXID:
+			psc1r |= RGMII_EN;
+			break;
+		default:
+			/* Unknown; don't touch */
+			break;
+		}
+
+		wrlp(mp, PORT_SERIAL_CONTROL1, psc1r);
+	}
 }
 
 /* statistics ***************************************************************/
@@ -2975,11 +3008,16 @@  static int get_phy_mode(struct mv643xx_eth_private *mp)
 	if (dev->of_node)
 		err = of_get_phy_mode(dev->of_node, &iface);
 
-	/* Historical default if unspecified. We could also read/write
-	 * the interface state in the PSC1
+	/* Read the interface state in the PSC1.
+	 *
+	 * Modes of two devices may interact on Kirkwood. Currently there is no
+	 * way to detect another device within this scope; blindly set MII
+	 * here.
 	 */
 	if (!dev->of_node || err)
-		iface = PHY_INTERFACE_MODE_GMII;
+		iface = rdlp(mp, PORT_SERIAL_CONTROL1) & RGMII_EN ?
+			PHY_INTERFACE_MODE_RGMII : mp->kirkwood ?
+			PHY_INTERFACE_MODE_MII : PHY_INTERFACE_MODE_GMII;
 	return iface;
 }
 
@@ -3124,9 +3162,11 @@  static int mv643xx_eth_probe(struct platform_device *pdev)
 	 * all other SoCs/System Controllers using this driver.
 	 */
 	if (of_device_is_compatible(pdev->dev.of_node,
-				    "marvell,kirkwood-eth-port"))
+				    "marvell,kirkwood-eth-port")) {
 		wrlp(mp, PORT_SERIAL_CONTROL1,
 		     rdlp(mp, PORT_SERIAL_CONTROL1) & ~CLK125_BYPASS_EN);
+		mp->kirkwood = 1;
+	}
 
 	/*
 	 * Start with a default rate, and if there is a clock, allow