Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net, "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Willem de Bruijn" <willemb@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Marek Behún" <kabel@kernel.org>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Gregory Clement" <gregory.clement@bootlin.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	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" <conor+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Herve Codina" <herve.codina@bootlin.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vladimir Oltean" <vladimir.oltean@nxp.com>,
	"Köry Maincent" <kory.maincent@bootlin.com>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Nicolò Veronese" <nicveronese@gmail.com>,
	"Simon Horman" <horms@kernel.org>,
	marcin.s.wojtas@gmail.com, "Daniel Golle" <daniel@makrotopia.org>,
	"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>,
	"Frank Wunderlich" <frank.wunderlich@linux.dev>,
	"Pietro Ameruoso" <p.ameruoso@live.it>,
	"Aleksei Sviridkin" <f@lex.la>
Subject: [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver
Date: Fri,  4 Dec 2026 12:06:20 +0100	[thread overview]
Message-ID: <20261204110622.1106492-12-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20261204110622.1106492-1-maxime.chevallier@bootlin.com>

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 <maxime.chevallier@bootlin.com>
---
 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 <maxime.chevallier@bootlin.com>
 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 <linux/module.h>
+#include <linux/phy_mux.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+
+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 <maxime.chevallier@bootlin.com>");
+MODULE_LICENSE("GPL");
-- 
2.56.1



  parent reply	other threads:[~2026-12-04 11:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 08/12] net: phy: phy_mux: Add phy_mux_set_mac_managed_pm() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
2026-12-04 11:06 ` Maxime Chevallier [this message]
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204110622.1106492-12-maxime.chevallier@bootlin.com \
    --to=maxime.chevallier@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=christophe.leroy@csgroup.eu \
    --cc=conor+dt@kernel.org \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dimitri.fedrau@liebherr.com \
    --cc=edumazet@kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=f@lex.la \
    --cc=frank.wunderlich@linux.dev \
    --cc=gregory.clement@bootlin.com \
    --cc=herve.codina@bootlin.com \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=kabel@kernel.org \
    --cc=kory.maincent@bootlin.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=marcin.s.wojtas@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicveronese@gmail.com \
    --cc=o.rempel@pengutronix.de \
    --cc=p.ameruoso@live.it \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox