Skip to contentSkip to conversation

Add DM driver for KSZ9477/KSZ9897/KSZ9567 GbE Switch

RFC PATCH New Tim Harvey 1 participant 3 messages Nov 13, 2020

Subsystems (2)
lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

cover Add DM driver for KSZ9477/KSZ9897/KSZ9567 GbE Switch

This patch series adds a driver for the Microchip 7-port KSZ9477/KSZ9897/KSZ9567 GbE Switch.

This was tested on an IMX8MM board that has its FEC MAC RGMII connected to the CPU uplink port of a KSZ9897 and I2C controlling the KSZ9897 registers.

I found that the UCLASS_ETH_PHY class appears appropriate for binding an mii bus to a eth device however I had to remove some restrictions in the eth_phy_get_mdio_bus() and eth_phy_set_mdio_bus() in order to accomplish this as they only allowed binding a phy to an eth if it was a child node of the eth device.

Specific comments I'm looking for here are:
- Please verify that I'm using the correct class or if there is a better way to register such that the phy would be bound with a mac.
- I'm hoping Peng and Yi Li can review and test my changes to eth-phy-uclass to make sure it still works with whatever boards they added that class
- I'm not quite clear how best to handle the configuration of the LED mode. I feel like this should be a dt property honored by both the u-boot driver and the linux driver (ksz9477.c) as the linux driver does a reset on the phy and clobbers the LED configuration.

Best Regards,

Tim

Tim Harvey (2):
net: eth-phy-uclass: allow flexible mii to eth bindings
net: add support for KSZ9477/KSZ9897/KSZ9567 GbE switch

 MAINTAINERS                  |   5 +
 drivers/net/eth-phy-uclass.c |  41 ++--
 drivers/net/phy/Kconfig      |  15 ++
 drivers/net/phy/Makefile     |   1 +
 drivers/net/phy/ksz9477.c    | 533 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 573 insertions(+), 23 deletions(-)
 create mode 100644 drivers/net/phy/ksz9477.c
Signature · 1 line
2.7.4
author
#1 lore raw

RFC PATCH 1/2 net: eth-phy-uclass: allow flexible mii to eth bindings

commit 5fe419ef2a61 ("net: Add eth phy generic driver for shared MDIO") added a UCLASS_ETH_PHY for Ethernet PHY devices to aid in connecting eth devices to mii bus drivers. However the binding was only allowed for a phy that was a child of the ethernet device which is fairly restrictive.

For a device such as an Ethernet switch the phy can be from a different bus and driver such as an I2C or SPI register controlled device.

Remove the restiction of the phy being a child of the eth device. Additionally add some debugging, remove some unnecessary prints on successes, and remove FEC from a failure print.

---
 drivers/net/eth-phy-uclass.c | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)
drivers/net/eth-phy-uclass.c +18 -23
index b383f45..fb1b92b 100644
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <dm.h>
 #include <net.h>
+#include <phy.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
 #include <dm/lists.h>
@@ -51,13 +52,12 @@ int eth_phy_set_mdio_bus(struct udevice *eth_dev, struct mii_dev *mdio_bus)
 	struct udevice *dev;
 	struct eth_phy_device_priv *uc_priv;
 
-	for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev;
-	     uclass_next_device(&dev)) {
-		if (dev->parent == eth_dev) {
-			uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv);
-
-			if (!uc_priv->mdio_bus)
-				uc_priv->mdio_bus = mdio_bus;
+	debug("%s eth_dev:%s mdio_bus:%s\n", __func__, eth_dev->name, mdio_bus->name);
+	for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev; uclass_next_device(&dev)) {
+		uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv);
+		if (!uc_priv->mdio_bus) {
+			debug("%s setting to bus=%p:%s\n", __func__, mdio_bus, mdio_bus->name);
+			uc_priv->mdio_bus = mdio_bus;
 		}
 	}
 
@@ -70,25 +70,20 @@ struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev)
 	struct udevice *phy_dev;
 	struct eth_phy_device_priv *uc_priv;
 
+	debug("%s eth_dev:%s\n", __func__, eth_dev->name);
 	/* Will probe the parent of phy device, then phy device */
-	ret = uclass_get_device_by_phandle(UCLASS_ETH_PHY, eth_dev,
-					   "phy-handle", &phy_dev);
+	ret = uclass_get_device_by_phandle(UCLASS_ETH_PHY, eth_dev, "phy-handle", &phy_dev);
 	if (!ret) {
-		if (eth_dev != phy_dev->parent) {
-			/*
-			 * phy_dev is shared and controlled by
-			 * other eth controller
-			 */
-			uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv);
-			if (uc_priv->mdio_bus)
-				printf("Get shared mii bus on %s\n", eth_dev->name);
-			else
-				printf("Can't get shared mii bus on %s\n", eth_dev->name);
-
-			return uc_priv->mdio_bus;
-		}
+		debug("%s phy_dev:%s\n", __func__, phy_dev->name);
+		uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv);
+		if (uc_priv->mdio_bus)
+			debug("%s got mii bus for %s: %s\n", __func__,
+			      eth_dev->name, uc_priv->mdio_bus->name);
+		else
+			printf("no mii bus for %s\n", phy_dev->name);
+		return uc_priv->mdio_bus;
 	} else {
-		printf("FEC: can't find phy-handle\n");
+		printf("can't find phy-handle\n");
 	}
 
 	return NULL;
Signature · 1 line
2.7.4
author
#2 lore raw

RFC PATCH 2/2 net: add support for KSZ9477/KSZ9897/KSZ9567 GbE switch

In reply to Tim Harvey

The Microchip KSZ9477/KSZ9897/KSZ9567 7-Port Gigabit Ethernet Switches support SGMII/RGMII/MII/RMII with register access via SPI or I2C.

This driver currently supports I2C register access but SPI register access can be easily added at a later time.

This was tested with a KSZ9897S switch with an IMX8MM FEC MAC connected via RGMII_ID to the cpu port.

---
 MAINTAINERS               |   5 +
 drivers/net/phy/Kconfig   |  15 ++
 drivers/net/phy/Makefile  |   1 +
 drivers/net/phy/ksz9477.c | 533 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 555 insertions(+)
 create mode 100644 drivers/net/phy/ksz9477.c
MAINTAINERS +5 -0
index 874cf2c..10a12f9 100644
@@ -784,6 +784,11 @@ F:	drivers/sysreset/sysreset_gpio.c
 F:	drivers/watchdog/xilinx_tb_wdt.c
 N:	xilinx
 
+MICROCHIP KSZ9477
+M:	Tim Harvey <[email protected]>
+S:	Maintained
+F:	drivers/net/phy/ksz9477.c
+
 MIPS
 M:	Daniel Schwierzeck <[email protected]>
 S:	Maintained
drivers/net/phy/Kconfig +15 -0
index 4e1a93b..9567d679 100644
@@ -2,6 +2,21 @@
 config BITBANGMII
 	bool "Bit-banged ethernet MII management channel support"
 
+config KSZ9477_SWITCH
+	bool "Microchip KSZ9477 GbE Switch support"
+	depends on DM_ETH_PHY
+	help
+	  Enable support for the I2C GbE Switches manufactured by Microchip
+	  including the KSZ9477, KSZ9897, KSZ9893, KSZ9567.
+
+if KSZ9477_SWITCH
+
+config KSZ9477_LED_SINGLE_MODE
+	bool "Single-LED mode"
+	default y
+
+endif # KSZ9477_SWITCH
+
 config MV88E6352_SWITCH
 	bool "Marvell 88E6352 switch support"
 
drivers/net/phy/Makefile +1 -0
index 6e72233..68db3b6 100644
@@ -5,6 +5,7 @@
 
 obj-$(CONFIG_BITBANGMII) += miiphybb.o
 obj-$(CONFIG_B53_SWITCH) += b53.o
+obj-$(CONFIG_KSZ9477_SWITCH) += ksz9477.o
 obj-$(CONFIG_MV88E61XX_SWITCH) += mv88e61xx.o
 obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o
 
drivers/net/phy/ksz9477.c new file +533 -0

533 lines not on this page · raw message

Signature · 1 line
2.7.4