[PATCH v2 net-next 03/15] net: mdio: add generic driver for NXP SJA1110 100BASE-TX embedded PHYs

Vladimir Oltean posted 15 patches 2 weeks, 4 days ago
[PATCH v2 net-next 03/15] net: mdio: add generic driver for NXP SJA1110 100BASE-TX embedded PHYs
Posted by Vladimir Oltean 2 weeks, 4 days ago
This is the standalone variant of drivers/net/dsa/sja1105/sja1105_mdio.c.
Same kind of differences between this driver and the embedded DSA one
apply: regmap is being used for register access, and addresses are
multiplied by 4 with regmap.

In fact this is so generic that there is nothing NXP SJA1110 specific
about it at all, and just instantiates mdio-regmap. I decided to name it
mdio-regmap-simple.c in the style of drivers/mfd/simple-mfd-i2c.c which
has support for various vendor compatible strings.

Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2:
- reorder MAINTAINERS entry to be alphabetic
- clarify that platform_get_resource() is optional (thanks to Maxime)
- update copyright to 2026

 MAINTAINERS                           |  1 +
 drivers/net/mdio/Kconfig              | 15 ++++-
 drivers/net/mdio/Makefile             |  1 +
 drivers/net/mdio/mdio-regmap-simple.c | 80 +++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/mdio/mdio-regmap-simple.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d3fec699c577..2b910fdd1122 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15671,6 +15671,7 @@ MDIO REGMAP DRIVER
 M:	Maxime Chevallier <maxime.chevallier@bootlin.com>
 L:	netdev@vger.kernel.org
 S:	Maintained
+F:	drivers/net/mdio/mdio-regmap-simple.c
 F:	drivers/net/mdio/mdio-regmap.c
 F:	include/linux/mdio/mdio-regmap.h
 
diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig
index 9819d1dc18de..c6e824baf228 100644
--- a/drivers/net/mdio/Kconfig
+++ b/drivers/net/mdio/Kconfig
@@ -179,14 +179,23 @@ config MDIO_REALTEK_RTL9300
 config MDIO_REGMAP
 	tristate
 	help
-	  This driver allows using MDIO devices that are not sitting on a
-	  regular MDIO bus, but still exposes the standard 802.3 register
+	  This support module allows using MDIO devices that are not sitting on
+	  a regular MDIO bus, but still exposes the standard 802.3 register
 	  layout. It's regmap-based so that it can be used on integrated,
 	  memory-mapped PHYs, SPI PHYs and so on. A new virtual MDIO bus is
 	  created, and its read/write operations are mapped to the underlying
-	  regmap. Users willing to use this driver must explicitly select
+	  regmap. Users willing to use this module must explicitly select
 	  REGMAP.
 
+config MDIO_REGMAP_SIMPLE
+	tristate
+	select MDIO_REGMAP
+	help
+	  Generic platform driver for MDIO buses with a linear address space
+	  that can be directly accessed using the MDIO_REGMAP support code and
+	  need no special handling. The regmap is provided by the parent
+	  device.
+
 config MDIO_THUNDER
 	tristate "ThunderX SOCs MDIO buses"
 	depends on 64BIT
diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile
index 9abf20d1b030..95f201b73a7d 100644
--- a/drivers/net/mdio/Makefile
+++ b/drivers/net/mdio/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_MDIO_MVUSB)		+= mdio-mvusb.o
 obj-$(CONFIG_MDIO_OCTEON)		+= mdio-octeon.o
 obj-$(CONFIG_MDIO_REALTEK_RTL9300)	+= mdio-realtek-rtl9300.o
 obj-$(CONFIG_MDIO_REGMAP)		+= mdio-regmap.o
+obj-$(CONFIG_MDIO_REGMAP_SIMPLE)	+= mdio-regmap-simple.o
 obj-$(CONFIG_MDIO_SJA1110_CBT1)		+= mdio-sja1110-cbt1.o
 obj-$(CONFIG_MDIO_SUN4I)		+= mdio-sun4i.o
 obj-$(CONFIG_MDIO_THUNDER)		+= mdio-thunder.o
diff --git a/drivers/net/mdio/mdio-regmap-simple.c b/drivers/net/mdio/mdio-regmap-simple.c
new file mode 100644
index 000000000000..5db1ca50c374
--- /dev/null
+++ b/drivers/net/mdio/mdio-regmap-simple.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2025-2026 NXP
+ *
+ * Generic MDIO bus driver for simple regmap-based MDIO devices
+ *
+ * This driver creates MDIO buses for devices that expose their internal
+ * PHYs or PCS through a regmap interface. It's intended to be a simple,
+ * generic driver similar to simple-mfd-i2c.c.
+ */
+#include <linux/module.h>
+#include <linux/of_mdio.h>
+#include <linux/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/mdio/mdio-regmap.h>
+
+struct mdio_regmap_simple_data {
+	u8 valid_addr;
+	bool autoscan;
+};
+
+static const struct mdio_regmap_simple_data nxp_sja1110_base_tx = {
+	.valid_addr = 0,
+	.autoscan = false,
+};
+
+static int mdio_regmap_simple_probe(struct platform_device *pdev)
+{
+	const struct mdio_regmap_simple_data *data;
+	struct mdio_regmap_config config = {};
+	struct device *dev = &pdev->dev;
+	struct regmap *regmap;
+	struct mii_bus *bus;
+
+	if (!dev->of_node || !dev->parent)
+		return -ENODEV;
+
+	regmap = dev_get_regmap(dev->parent, NULL);
+	if (!regmap)
+		return -ENODEV;
+
+	data = device_get_match_data(dev);
+
+	config.regmap = regmap;
+	config.parent = dev;
+	config.name = dev_name(dev);
+	/* The resource is optional, provided for finding the registers
+	 * within a device-wide non-MMIO regmap
+	 */
+	config.resource = platform_get_resource(pdev, IORESOURCE_REG, 0);
+	if (data) {
+		config.valid_addr = data->valid_addr;
+		config.autoscan = data->autoscan;
+	}
+
+	return PTR_ERR_OR_ZERO(devm_mdio_regmap_register(dev, &config));
+}
+
+static const struct of_device_id mdio_regmap_simple_match[] = {
+	{
+		.compatible = "nxp,sja1110-base-tx-mdio",
+		.data = &nxp_sja1110_base_tx,
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, mdio_regmap_simple_match);
+
+static struct platform_driver mdio_regmap_simple_driver = {
+	.probe = mdio_regmap_simple_probe,
+	.driver = {
+		.name = "mdio-regmap-simple",
+		.of_match_table = mdio_regmap_simple_match,
+	},
+};
+
+module_platform_driver(mdio_regmap_simple_driver);
+
+MODULE_DESCRIPTION("Generic MDIO bus driver for simple regmap-based devices");
+MODULE_AUTHOR("Vladimir Oltean <vladimir.oltean@nxp.com>");
+MODULE_LICENSE("GPL");
-- 
2.34.1
Re: [PATCH v2 net-next 03/15] net: mdio: add generic driver for NXP SJA1110 100BASE-TX embedded PHYs
Posted by Andy Shevchenko 2 weeks, 4 days ago
On Thu, Jan 22, 2026 at 12:56:42PM +0200, Vladimir Oltean wrote:
> This is the standalone variant of drivers/net/dsa/sja1105/sja1105_mdio.c.
> Same kind of differences between this driver and the embedded DSA one
> apply: regmap is being used for register access, and addresses are
> multiplied by 4 with regmap.
> 
> In fact this is so generic that there is nothing NXP SJA1110 specific
> about it at all, and just instantiates mdio-regmap. I decided to name it
> mdio-regmap-simple.c in the style of drivers/mfd/simple-mfd-i2c.c which
> has support for various vendor compatible strings.

...

> +#include <linux/module.h>
> +#include <linux/of_mdio.h>
> +#include <linux/phy.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/mdio/mdio-regmap.h>

...

> +static const struct mdio_regmap_simple_data nxp_sja1110_base_tx = {
> +	.valid_addr = 0,
> +	.autoscan = false,
> +};

Actually the  { } is enough to initialise that. But if you want to be super
explicit... :-)

...

> +static int mdio_regmap_simple_probe(struct platform_device *pdev)
> +{
> +	const struct mdio_regmap_simple_data *data;
> +	struct mdio_regmap_config config = {};
> +	struct device *dev = &pdev->dev;
> +	struct regmap *regmap;
> +	struct mii_bus *bus;
> +
> +	if (!dev->of_node || !dev->parent)

dev->of_node check is not needed, see below.

> +		return -ENODEV;
> +
> +	regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!regmap)
> +		return -ENODEV;
> +
> +	data = device_get_match_data(dev);
> +
> +	config.regmap = regmap;
> +	config.parent = dev;
> +	config.name = dev_name(dev);
> +	/* The resource is optional, provided for finding the registers
> +	 * within a device-wide non-MMIO regmap
> +	 */
> +	config.resource = platform_get_resource(pdev, IORESOURCE_REG, 0);

> +	if (data) {

We may always require data to be present. As you use a default one anyway.

> +		config.valid_addr = data->valid_addr;
> +		config.autoscan = data->autoscan;
> +	}

And if it is not provided we will have a crash which is fine. It will just
point that the code was not ever been run on real HW.

> +	return PTR_ERR_OR_ZERO(devm_mdio_regmap_register(dev, &config));
> +}

...

> +static struct platform_driver mdio_regmap_simple_driver = {
> +	.probe = mdio_regmap_simple_probe,
> +	.driver = {
> +		.name = "mdio-regmap-simple",
> +		.of_match_table = mdio_regmap_simple_match,
> +	},
> +};

> +

Unneeded blank line.

> +module_platform_driver(mdio_regmap_simple_driver);

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 net-next 03/15] net: mdio: add generic driver for NXP SJA1110 100BASE-TX embedded PHYs
Posted by Vladimir Oltean 2 weeks, 4 days ago
On Thu, Jan 22, 2026 at 02:20:22PM +0200, Andy Shevchenko wrote:
> On Thu, Jan 22, 2026 at 12:56:42PM +0200, Vladimir Oltean wrote:
> > This is the standalone variant of drivers/net/dsa/sja1105/sja1105_mdio.c.
> > Same kind of differences between this driver and the embedded DSA one
> > apply: regmap is being used for register access, and addresses are
> > multiplied by 4 with regmap.
> > 
> > In fact this is so generic that there is nothing NXP SJA1110 specific
> > about it at all, and just instantiates mdio-regmap. I decided to name it
> > mdio-regmap-simple.c in the style of drivers/mfd/simple-mfd-i2c.c which
> > has support for various vendor compatible strings.
> 
> ...
> 
> > +#include <linux/module.h>
> > +#include <linux/of_mdio.h>
> > +#include <linux/phy.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/mdio/mdio-regmap.h>
> 
> ...
> 
> > +static const struct mdio_regmap_simple_data nxp_sja1110_base_tx = {
> > +	.valid_addr = 0,
> > +	.autoscan = false,
> > +};
> 
> Actually the  { } is enough to initialise that. But if you want to be super
> explicit... :-)
> ...

Yes, I guess I do.

> > +static int mdio_regmap_simple_probe(struct platform_device *pdev)
> > +{
> > +	const struct mdio_regmap_simple_data *data;
> > +	struct mdio_regmap_config config = {};
> > +	struct device *dev = &pdev->dev;
> > +	struct regmap *regmap;
> > +	struct mii_bus *bus;
> > +
> > +	if (!dev->of_node || !dev->parent)
> 
> dev->of_node check is not needed, see below.

Oh.... this is a bug. dev->of_node should have been propagated to
devm_mdio_regmap_register() -> devm_mdiobus_register(), turning it into
devm_of_mdiobus_register().

It shows that my SJA1110 testing platform (Bluebox 3) doesn't have the
CBTX PHY routed to pinout, since I didn't catch this... I'll fix this
for v3.

> > +		return -ENODEV;
> > +
> > +	regmap = dev_get_regmap(dev->parent, NULL);
> > +	if (!regmap)
> > +		return -ENODEV;
> > +
> > +	data = device_get_match_data(dev);
> > +
> > +	config.regmap = regmap;
> > +	config.parent = dev;
> > +	config.name = dev_name(dev);
> > +	/* The resource is optional, provided for finding the registers
> > +	 * within a device-wide non-MMIO regmap
> > +	 */
> > +	config.resource = platform_get_resource(pdev, IORESOURCE_REG, 0);
> 
> > +	if (data) {
> 
> We may always require data to be present. As you use a default one anyway.
> 
> > +		config.valid_addr = data->valid_addr;
> > +		config.autoscan = data->autoscan;
> > +	}
> 
> And if it is not provided we will have a crash which is fine. It will just
> point that the code was not ever been run on real HW.

Hmm. This patch is super old, so I'm revisiting it with foreign eyes,
same as you.

I think the case with .valid_addr = 0 and .autoscan = false will
constitute the vast majority of instantiations of this driver.
I would like to avoid the proliferation of the same basic config with
100 different names (nxp_sja1110_base_tx, etc).

So for v3 I'm planning to:
- rename nxp_sja1110_base_tx to mdio_regmap_simple_default_data
- delete the "if (data)" conditional and directly assign from
  device_get_match_data() to the config structure

Thanks for taking a look.

> > +	return PTR_ERR_OR_ZERO(devm_mdio_regmap_register(dev, &config));
> > +}
> 
> ...
> 
> > +static struct platform_driver mdio_regmap_simple_driver = {
> > +	.probe = mdio_regmap_simple_probe,
> > +	.driver = {
> > +		.name = "mdio-regmap-simple",
> > +		.of_match_table = mdio_regmap_simple_match,
> > +	},
> > +};
> 
> > +
> 
> Unneeded blank line.

Ok.

> > +module_platform_driver(mdio_regmap_simple_driver);
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Re: [PATCH v2 net-next 03/15] net: mdio: add generic driver for NXP SJA1110 100BASE-TX embedded PHYs
Posted by Andy Shevchenko 2 weeks, 4 days ago
On Thu, Jan 22, 2026 at 03:31:23PM +0200, Vladimir Oltean wrote:
> On Thu, Jan 22, 2026 at 02:20:22PM +0200, Andy Shevchenko wrote:
> > On Thu, Jan 22, 2026 at 12:56:42PM +0200, Vladimir Oltean wrote:

...

> > > +static int mdio_regmap_simple_probe(struct platform_device *pdev)
> > > +{
> > > +	const struct mdio_regmap_simple_data *data;
> > > +	struct mdio_regmap_config config = {};
> > > +	struct device *dev = &pdev->dev;
> > > +	struct regmap *regmap;
> > > +	struct mii_bus *bus;
> > > +
> > > +	if (!dev->of_node || !dev->parent)
> > 
> > dev->of_node check is not needed, see below.
> 
> Oh.... this is a bug. dev->of_node should have been propagated to
> devm_mdio_regmap_register() -> devm_mdiobus_register(), turning it into
> devm_of_mdiobus_register().
> 
> It shows that my SJA1110 testing platform (Bluebox 3) doesn't have the
> CBTX PHY routed to pinout, since I didn't catch this... I'll fix this
> for v3.

Same Q, why not using fwnode APIs to begin with?

> > > +		return -ENODEV;
> > > +
> > > +	regmap = dev_get_regmap(dev->parent, NULL);
> > > +	if (!regmap)
> > > +		return -ENODEV;
> > > +
> > > +	data = device_get_match_data(dev);
> > > +
> > > +	config.regmap = regmap;
> > > +	config.parent = dev;
> > > +	config.name = dev_name(dev);
> > > +	/* The resource is optional, provided for finding the registers
> > > +	 * within a device-wide non-MMIO regmap
> > > +	 */
> > > +	config.resource = platform_get_resource(pdev, IORESOURCE_REG, 0);
> > 
> > > +	if (data) {
> > 
> > We may always require data to be present. As you use a default one anyway.
> > 
> > > +		config.valid_addr = data->valid_addr;
> > > +		config.autoscan = data->autoscan;
> > > +	}
> > 
> > And if it is not provided we will have a crash which is fine. It will just
> > point that the code was not ever been run on real HW.
> 
> Hmm. This patch is super old, so I'm revisiting it with foreign eyes,
> same as you.
> 
> I think the case with .valid_addr = 0 and .autoscan = false will
> constitute the vast majority of instantiations of this driver.
> I would like to avoid the proliferation of the same basic config with
> 100 different names (nxp_sja1110_base_tx, etc).

But you name it as default_blablalbla. That will be just assigned to each
currently "NULL" driver_data. We have examples in the kernel that do this.
IIRC 8250_dw cases, stmmac driver (PCI glue part of it?), et cetera...

> So for v3 I'm planning to:
> - rename nxp_sja1110_base_tx to mdio_regmap_simple_default_data
> - delete the "if (data)" conditional and directly assign from
>   device_get_match_data() to the config structure
> 
> Thanks for taking a look.

You're welcome!

> > > +	return PTR_ERR_OR_ZERO(devm_mdio_regmap_register(dev, &config));
> > > +}

-- 
With Best Regards,
Andy Shevchenko