From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382504; b=hJBIpfHY6OQzKRhC9nPpkNHZP7Mn4qXVkFJbM/mMqbBRkLVHOWwg7x1i8tgRu7t9Prx8 zp3LQYdq6tZcS4ZCBBGcte0ZXXHb06AJQWpNJsBQXa2ErcWdzHh8YsjEZ7DzS0pM0f6tm a105rPxff/tH0MzrkPQOd0KkfAR/HFubO9KpLVyUz/+RZpWfuTkv3x04eF02kHOTR3zZa p67MwYMxqAWjtM6Ea/n7/ckkLIQ/NXviUdnGS9oPAMUOD0zhDZdjToFBlOIaZkGShHzQt hc2o/lEMfwSHi7N+Sy1a+UViAs66XWqtX2Sjp/QVrK4ZBT3OQZCTBgu8EIYUEnxxc4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382504; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=wCsy0Yyu4UPDssEaRPz625yoPhKHJoib15Axlfjm8HI=; b=0Ob1nEikpVeMgj/w14g6yfZq2tPQFpXHGgBU0cbWYKUWBV6LngI1LGi3o35hi8QTDgRJ 0cBP9/fVleHaHcAmzZM02wyGVssoeANLXQq4rhziAP/HanttEBTF/Fy6NYSiaRRYjqLxT kGZL1N/EG9vK1csM1w+OIy6UkOBI4ZVnCRYAxUCj5TslWbcgqUBqTLJZyPAW3kqlWpde5 5fi1ZUbJZzQab5qxwOk7tw9mlTpXVrfjpSlSbzFbm0vOL3iwauvh/MjpJ57oMJEDQIaQB Z5HFrxlnYKbQPlU7AJLxotP+ZCNG9/ndmz4AwrcRQsN1Rz5Wa30JXlqlXof3HJ5KvdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b="Et/3MeY8"; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 074B1606A334; Fri, 4 Dec 2026 11:08:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 074B1606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Et/3MeY8 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B3DC61A1947; 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-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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