From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D41F606A33C for ; Fri, 4 Dec 2026 11:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=tBNXhl7/; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Et/3MeY8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=wCsy0Yyu4UPDssEaRPz625yoPhKHJoib15Axlfjm8HI=; b=tBNXhl7/NpLZnA 5N5iuV9TsNgCMm1gBPAUwI8NHv5nTQ2mfLs3asofc4BWbfkuffVhsumNfDOS5n+6VDcZSMYvlTA9q U37QEoHxUyawu7FVvUrWMp3uubmS0VMVhF2V3rOXQMprKCgML/r9rVhzLgEwrk3UTaguMhl7rPyt6 ZAtquX9p8H0MzK6Ve84LHYJD6qVS4Uu4hMFa/Ome6cvBDzVFYs86+x4p5lE2qu3nXcY5ekI4ltzSn yvDYyZBgq6umUNrJGjghj5HaMpx1rRNo4kRTYFlLxbE/VnnUwEJz21WnIqrscLbsZrQCl/ISAnGox LMBDZOAnCRpEiIIFipdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR9a-000000004pC-2IyE; Fri, 04 Dec 2026 11:08:38 +0000 Received: from smtpout-03.galae.net ([185.246.85.4]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR9L-000000004dL-1R7e for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 11:08:29 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id B488B4E4185D; Fri, 4 Dec 2026 11:08:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 81667603C4; Fri, 4 Dec 2026 11:08:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C747411EA193F; Fri, 04 Dec 2026 12:08:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796382498; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=wCsy0Yyu4UPDssEaRPz625yoPhKHJoib15Axlfjm8HI=; b=Et/3MeY8QqRaYzGAAgUMPEqkuGvYdVFlJ2wAfXIheuLi+Pjb6ehrzAHOa/z/+jqCqMo+uC Y044nUdeOSstwlD1F/XPsbQ72tgiM2QvK5HVg8t32de4VOwXa667zOdGVWioyLHG2urIIz UH0SJTpwYl/z9WEhh98f00EeVsNaZPfnggQntacVC2umxfLjdMPozJB9C5vFizy1srFo3H 3BOtmD8M4GF3XGcds1yeBBpF5TO/Qp4QwMhyimqfgFR13lZWujMoAydZCNgM49xX0YIa6N WGUTn+jTAlpqlQJR8sEJiCs672HF5w6HwKZlVCzLIVzA94U8B8AAzdQOXb8Sdg== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Willem de Bruijn , Paolo Abeni , Russell King , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Sebastian Hesselbarth , Gregory Clement , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@bootlin.com, devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Christophe Leroy , Herve Codina , Florian Fainelli , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , marcin.s.wojtas@gmail.com, Daniel Golle , Dimitri Fedrau , Frank Wunderlich , Pietro Ameruoso , Aleksei Sviridkin Subject: [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Date: Fri, 4 Dec 2026 12:06:20 +0100 Message-ID: <20261204110622.1106492-12-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_030824_726291_A3EDCC27 X-CRM114-Status: GOOD ( 26.78 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add a driver for the simplest kind of mux, the ones that are switched by the hardware without any control from software, described with the mii-mux-auto binding. That's what we have on the Turris Omnia's WAN port, where the mux's select line is tied to the SFP cage's mod_def0 signal. There's not much to do in the driver: it registers the ports, and looks for the takes-precedence property to tell the core which port the hardware is going to switch to. Signed-off-by: Maxime Chevallier --- MAINTAINERS | 1 + drivers/net/phy/Kconfig | 2 + drivers/net/phy/Makefile | 1 + drivers/net/phy/mux/Kconfig | 18 ++++++ drivers/net/phy/mux/Makefile | 3 + drivers/net/phy/mux/mii_mux_auto.c | 99 ++++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 drivers/net/phy/mux/Kconfig create mode 100644 drivers/net/phy/mux/Makefile create mode 100644 drivers/net/phy/mux/mii_mux_auto.c diff --git a/MAINTAINERS b/MAINTAINERS index b2b02a1dbd3a..59017b0f9f86 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10086,6 +10086,7 @@ M: Maxime Chevallier L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/mii-mux*.yaml +F: drivers/net/phy/mux/ F: drivers/net/phy/phy_mux.c F: include/linux/phy_mux.h diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index d8a0131d2aa2..f6397dab2304 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -29,6 +29,8 @@ config PHY_MUX time. This adds the infrastructure to represent such multiplexers and to select which port carries the link. +source "drivers/net/phy/mux/Kconfig" + config SWPHY bool diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index b3ec2933fec4..b26b34c93dbc 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_PHYLINK) += phylink.o obj-$(CONFIG_PHYLIB) += libphy.o obj-$(CONFIG_PHYLIB) += mdio_devres.o obj-$(CONFIG_PHY_PACKAGE) += phy_package.o +obj-$(CONFIG_PHY_MUX) += mux/ obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o diff --git a/drivers/net/phy/mux/Kconfig b/drivers/net/phy/mux/Kconfig new file mode 100644 index 000000000000..cbfd49fab2ea --- /dev/null +++ b/drivers/net/phy/mux/Kconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only + +if PHY_MUX + +config MII_MUX_AUTO + tristate "MII multiplexer switched by the hardware" + help + Support for the two-port MII multiplexers that the hardware + switches by itself, without any software control. + + This is typically found on combo ports, where a MAC is wired to + either a PHY or an SFP cage depending on whether a module is + plugged in the cage. + + To compile this driver as a module, choose M here: the module + will be called mii_mux_auto. + +endif # PHY_MUX diff --git a/drivers/net/phy/mux/Makefile b/drivers/net/phy/mux/Makefile new file mode 100644 index 000000000000..23e8c5029507 --- /dev/null +++ b/drivers/net/phy/mux/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_MII_MUX_AUTO) += mii_mux_auto.o diff --git a/drivers/net/phy/mux/mii_mux_auto.c b/drivers/net/phy/mux/mii_mux_auto.c new file mode 100644 index 000000000000..980cc2c242ba --- /dev/null +++ b/drivers/net/phy/mux/mii_mux_auto.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include + +static int mii_mux_auto_init_port(struct phy_mux_port *port, + struct fwnode_handle *child) +{ + port->has_precedence = fwnode_property_read_bool(child, + "takes-precedence"); + + return 0; +} + +static int mii_mux_auto_check_ports(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *child; + int n_sfp = 0, n_phy = 0, n_prec = 0, n_sfp_prec = 0; + + fwnode_for_each_available_child_node(fwnode, child) { + if (fwnode_property_read_bool(child, "takes-precedence")) + n_prec++; + + if (!fwnode_property_present(child, "sfp")) { + n_phy++; + continue; + } + + n_sfp++; + if (fwnode_property_read_bool(child, "takes-precedence")) + n_sfp_prec++; + } + + if (n_sfp != 1 || n_phy != 1 || n_prec != 1 || n_sfp_prec != 1) + return -EOPNOTSUPP; + + return 0; +} + +static int mii_mux_auto_probe(struct platform_device *pdev) +{ + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); + struct phy_mux *mux; + int ret; + + ret = mii_mux_auto_check_ports(fwnode); + if (ret) + return ret; + + mux = phy_mux_alloc(&pdev->dev, 2); + if (IS_ERR(mux)) + return PTR_ERR(mux); + + ret = phy_mux_fwnode_add_ports(mux, fwnode, mii_mux_auto_init_port); + if (ret) + goto err_free; + + ret = phy_mux_register(mux); + if (ret) + goto err_free; + + platform_set_drvdata(pdev, mux); + + return 0; + +err_free: + phy_mux_free(mux); + return ret; +} + +static void mii_mux_auto_remove(struct platform_device *pdev) +{ + struct phy_mux *mux = platform_get_drvdata(pdev); + + phy_mux_unregister(mux); + phy_mux_free(mux); +} + +static const struct of_device_id mii_mux_auto_of_match[] = { + { .compatible = "mii-mux-auto" }, + { } +}; +MODULE_DEVICE_TABLE(of, mii_mux_auto_of_match); + +static struct platform_driver mii_mux_auto_driver = { + .probe = mii_mux_auto_probe, + .remove = mii_mux_auto_remove, + .driver = { + .name = "mii-mux-auto", + .of_match_table = mii_mux_auto_of_match, + }, +}; +module_platform_driver(mii_mux_auto_driver); + +MODULE_DESCRIPTION("Ethernet MII multiplexer switched by the hardware"); +MODULE_AUTHOR("Maxime Chevallier "); +MODULE_LICENSE("GPL"); -- 2.56.1