Netdev List
 help / color / mirror / Atom feed
From: Rustam Adilov <adilov@disroot.org>
To: "Linus Walleij" <linusw@kernel.org>,
	"Luiz Angelo Daros de Luca" <luizluca@gmail.com>,
	"Alvin Šipraga" <alvin.sipraga@analog.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Willem de Bruijn" <willemb@google.com>,
	"Simon Horman" <horms@kernel.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Rustam Adilov <adilov@disroot.org>
Subject: [RFC PATCH net-next 2/6] net: dsa: realtek: add new mmio interface for drivers
Date: Fri,  4 Dec 2026 23:25:16 +0500	[thread overview]
Message-ID: <20261204182553.33952-3-adilov@disroot.org> (raw)
In-Reply-To: <20261204182553.33952-1-adilov@disroot.org>

Add a new interface driver for MMIO connected realtek switches.
That is platform driver just like realtek-smi but uses the syscon
to get its regmap.

Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
 drivers/net/dsa/realtek/Kconfig        |  7 +++
 drivers/net/dsa/realtek/Makefile       |  1 +
 drivers/net/dsa/realtek/realtek-mmio.c | 84 ++++++++++++++++++++++++++
 drivers/net/dsa/realtek/realtek-mmio.h | 29 +++++++++
 drivers/net/dsa/realtek/rtl83xx.c      | 38 +++++++-----
 drivers/net/dsa/realtek/rtl83xx.h      |  1 +
 6 files changed, 145 insertions(+), 15 deletions(-)
 create mode 100644 drivers/net/dsa/realtek/realtek-mmio.c
 create mode 100644 drivers/net/dsa/realtek/realtek-mmio.h

diff --git a/drivers/net/dsa/realtek/Kconfig b/drivers/net/dsa/realtek/Kconfig
index f1530ba0db61..aa4955fef4aa 100644
--- a/drivers/net/dsa/realtek/Kconfig
+++ b/drivers/net/dsa/realtek/Kconfig
@@ -30,6 +30,13 @@ config NET_DSA_REALTEK_SMI
 	  Select to enable support for registering switches connected
 	  through SMI.
 
+config NET_DSA_REALTEK_MMIO
+	bool "Realtek MMIO interface support"
+	depends on MFD_SYSCON
+	help
+	  Select to enable support for registering switches connected
+	  through MMIO.
+
 config NET_DSA_REALTEK_RTL8365MB
 	tristate "Realtek RTL8365MB switch driver"
 	depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO
diff --git a/drivers/net/dsa/realtek/Makefile b/drivers/net/dsa/realtek/Makefile
index 600a20911c1d..0d3287952b31 100644
--- a/drivers/net/dsa/realtek/Makefile
+++ b/drivers/net/dsa/realtek/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_NET_DSA_REALTEK)		+= realtek_dsa.o
 realtek_dsa-y				:= rtl83xx.o rtl83xx-qos.o
 realtek_dsa-$(CONFIG_NET_DSA_REALTEK_MDIO)	+= realtek-mdio.o
 realtek_dsa-$(CONFIG_NET_DSA_REALTEK_SMI)	+= realtek-smi.o
+realtek_dsa-$(CONFIG_NET_DSA_REALTEK_MMIO)	+= realtek-mmio.o
 
 obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o
 rtl8366-y				:= rtl8366-core.o rtl8366rb.o
diff --git a/drivers/net/dsa/realtek/realtek-mmio.c b/drivers/net/dsa/realtek/realtek-mmio.c
new file mode 100644
index 000000000000..ec68c982120f
--- /dev/null
+++ b/drivers/net/dsa/realtek/realtek-mmio.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "realtek.h"
+#include "realtek-mmio.h"
+#include "rtl83xx.h"
+
+static const struct realtek_interface_info realtek_mmio_info = {
+	.syscon = true,
+};
+
+/**
+ * realtek_mmio_probe() - Probe a platform device for an MMIO-connected switch
+ * @pdev: platform_device to probe on.
+ *
+ * This function should be used as the .probe in a platform_driver. After
+ * calling the common probe function for both interfaces, it calls a common
+ * function to register the DSA switch.
+ *
+ * Context: Can sleep. Takes and releases priv->map_lock.
+ * Return: Returns 0 on success, a negative error on failure.
+ */
+int realtek_mmio_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct realtek_priv *priv;
+	int ret;
+
+	priv = rtl83xx_probe(dev, &realtek_mmio_info);
+	if (IS_ERR(priv))
+		return PTR_ERR(priv);
+
+	ret = rtl83xx_register_switch(priv);
+	if (ret) {
+		rtl83xx_remove(priv);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(realtek_mmio_probe, "REALTEK_DSA");
+
+/**
+ * realtek_mmio_remove() - Remove the driver of a MMIO-connected switch
+ * @pdev: platform_device to be removed.
+ *
+ * This function should be used as the .remove in a platform_driver. First
+ * it unregisters the DSA switch and then it calls the common remove function.
+ *
+ * Context: Can sleep.
+ * Return: Nothing.
+ */
+void realtek_mmio_remove(struct platform_device *pdev)
+{
+	struct realtek_priv *priv = platform_get_drvdata(pdev);
+
+	if (!priv)
+		return;
+
+	rtl83xx_unregister_switch(priv);
+
+	rtl83xx_remove(priv);
+}
+EXPORT_SYMBOL_NS_GPL(realtek_mmio_remove, "REALTEK_DSA");
+
+/**
+ * realtek_mmio_shutdown() - Shutdown the driver of a MMIO-connected switch
+ * @pdev: platform_device shutting down.
+ *
+ * This function should be used as the .shutdown in a platform_driver. It calls
+ * the common shutdown function.
+ *
+ * Context: Can sleep.
+ * Return: Nothing.
+ */
+void realtek_mmio_shutdown(struct platform_device *pdev)
+{
+	struct realtek_priv *priv = platform_get_drvdata(pdev);
+
+	if (!priv)
+		return;
+
+	rtl83xx_shutdown(priv);
+}
+EXPORT_SYMBOL_NS_GPL(realtek_mmio_shutdown, "REALTEK_DSA");
diff --git a/drivers/net/dsa/realtek/realtek-mmio.h b/drivers/net/dsa/realtek/realtek-mmio.h
new file mode 100644
index 000000000000..e10e535f6b20
--- /dev/null
+++ b/drivers/net/dsa/realtek/realtek-mmio.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef _REALTEK_MMIO_H
+#define _REALTEK_MMIO_H
+
+#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_MMIO)
+
+int realtek_mmio_probe(struct platform_device *pdev);
+void realtek_mmio_remove(struct platform_device *pdev);
+void realtek_mmio_shutdown(struct platform_device *pdev);
+
+#else /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_MMIO) */
+
+static inline int realtek_mmio_probe(struct platform_device *pdev)
+{
+	return -ENOENT;
+}
+
+static inline void realtek_mmio_remove(struct platform_device *pdev)
+{
+}
+
+static inline void realtek_mmio_shutdown(struct platform_device *pdev)
+{
+}
+
+#endif /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_MMIO) */
+
+#endif  /* _REALTEK_MMIO_H */
diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
index ad42c05d0a88..f8b8d16003a9 100644
--- a/drivers/net/dsa/realtek/rtl83xx.c
+++ b/drivers/net/dsa/realtek/rtl83xx.c
@@ -6,6 +6,7 @@
 #include <linux/of_mdio.h>
 #include <linux/if_bridge.h>
 #include <linux/etherdevice.h>
+#include <linux/mfd/syscon.h>
 
 #include "realtek.h"
 #include "rtl83xx.h"
@@ -160,8 +161,6 @@ rtl83xx_probe(struct device *dev,
 		.reg_stride = 1,
 		.max_register = 0xffff,
 		.reg_format_endian = REGMAP_ENDIAN_BIG,
-		.reg_read = interface_info->reg_read,
-		.reg_write = interface_info->reg_write,
 		.cache_type = REGCACHE_NONE,
 		.lock = rtl83xx_lock,
 		.unlock = rtl83xx_unlock,
@@ -189,20 +188,29 @@ rtl83xx_probe(struct device *dev,
 	if (ret)
 		return ERR_PTR(ret);
 
-	rc.lock_arg = priv;
-	priv->map = devm_regmap_init(dev, NULL, priv, &rc);
-	if (IS_ERR(priv->map)) {
-		ret = PTR_ERR(priv->map);
-		dev_err(dev, "regmap init failed: %d\n", ret);
-		return ERR_PTR(ret);
-	}
+	if (interface_info->syscon) {
+		priv->map = syscon_node_to_regmap(dev->of_node);
+		if (IS_ERR(priv->map))
+			return dev_err_cast_probe(dev, priv->map,
+						  "regmap init failed\n");
+	} else {
+		rc.reg_read = interface_info->reg_read;
+		rc.reg_write = interface_info->reg_write;
+		rc.lock_arg = priv;
+		priv->map = devm_regmap_init(dev, NULL, priv, &rc);
+		if (IS_ERR(priv->map)) {
+			ret = PTR_ERR(priv->map);
+			ev_err(dev, "regmap init failed: %d\n", ret);
+			return ERR_PTR(ret);
+		}
 
-	rc.disable_locking = true;
-	priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc);
-	if (IS_ERR(priv->map_nolock)) {
-		ret = PTR_ERR(priv->map_nolock);
-		dev_err(dev, "regmap init failed: %d\n", ret);
-		return ERR_PTR(ret);
+		rc.disable_locking = true;
+		priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc);
+		if (IS_ERR(priv->map_nolock)) {
+			ret = PTR_ERR(priv->map_nolock);
+			dev_err(dev, "regmap init failed: %d\n", ret);
+			return ERR_PTR(ret);
+		}
 	}
 
 	/* Link forward and backward */
diff --git a/drivers/net/dsa/realtek/rtl83xx.h b/drivers/net/dsa/realtek/rtl83xx.h
index d86447121276..c727e772ff14 100644
--- a/drivers/net/dsa/realtek/rtl83xx.h
+++ b/drivers/net/dsa/realtek/rtl83xx.h
@@ -6,6 +6,7 @@
 struct realtek_interface_info {
 	int (*reg_read)(void *ctx, u32 reg, u32 *val);
 	int (*reg_write)(void *ctx, u32 reg, u32 val);
+	bool syscon;
 };
 
 void rtl83xx_lock(void *ctx);
-- 
2.56.1


  parent reply	other threads:[~2026-12-04 18:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:25 [RFC PATCH net-next 0/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 1/6] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Rustam Adilov
2026-12-04 18:25 ` Rustam Adilov [this message]
2026-12-04 18:25 ` [RFC PATCH net-next 3/6] dt-bindings: net: dsa: realtek: add new rtl9607c switch compatible Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 4/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 5/6] net: phy: realtek: use mdio.addr instead of 0 in rtlgen_read/write_vend2 Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 6/6] net: phy: realtek: add support for RTL9607C internal PHYs Rustam Adilov

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=20261204182553.33952-3-adilov@disroot.org \
    --to=adilov@disroot.org \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --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