From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796408947; b=gayca3yIpMUrk5vVT/FFFEJdIVbQuSyqBGravIqj55NiB2hdaXnRlU/cYyXuh6iddrzg MCbspRNsXaobmOng80oNpOhO1n11AlmiWlZOukuRu/9GWSP2kIDVbG9/fqdg0b9wiET+f FNhLmOp8Ipr3r7/dPrIxjiKtZoXUNrGnvYRCSRAOKgX0fz5xBqUHb6u0SpOLmc7uMiSvi 1FKNR4deRvogmlfnJ30tVBjmBBAcwF+b25ipegqv1s90eMhxy4lShHe+ix7ojj3Wc/dpW DnEwuW80T07tz/4GYgleRBZr5FsxtHU1jj0PB8gxGJjc+MXg6JLzLVd9746OzPK4dBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408947; h=DMARC-Filter:Received:X-Virus-Scanned:Received:DKIM-Signature:From: To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=cOKoNtbew5dwIuplBtGOdenUSZAhEeinMz9ZNccjpB8=; b=CZ/EKXU/26L1D8XfP7hngCsZq2T6kAsc3s5FTrWHzM96C0moRqh/NEXGSEDXKF32A2JB J5lIXjneICmCZmXBErPX8aokMl3jvERG/450E526NE86QmTpTfzSlFSVYkmvQV4wVmlxa aRSOyaXllxJq/+LwL16NXpalJ4W3tXh9wD/JAm9hE0vTb0q01FZ8GqNn+z0bc56PmfuGY XerI692FwXzUn6hfgmqvSH6GogZ+5lHVzC7/URHQKA+w26Lo454825yEKj6szebuNtYzs t6YTXA2pgjjgsikewYV+fBz6DQXL4e7MhgIopsO4Uqwvb7b1HmSsIE9aY1UQhH7U+jg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=QmJucy+q; arc=none smtp.remote-ip=178.21.23.139 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0394C606A32D; Fri, 4 Dec 2026 18:29:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0394C606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=QmJucy+q Received: from mail01.layka.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 8AA1682F9C; Fri, 04 Dec 2026 19:29:05 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id D_gGsbGYuBJA; Fri, 4 Dec 2026 19:29:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1796408944; bh=tStDKlyjroYutCOMq88rTLeZbO1mJ4IeJ8lcLGTGYKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QmJucy+qND0VjvVkdfaOy5FZCwMH1DzTeMLsAgVjPTK+WaCwo6B8hzse4I+ZU3Wtj z38MHIJjfY5hRbM7x4hxRB58tfUyUR7kyW1/4Ul964XW69FkOwlKa7nQNr5HYBJFAn gs9OskFBlQHhc0ItfwS8U/MpOrA7fIIGqhGdxxgm1XOhP6kjcIN7owUfuqotidKjs/ Ji3DdXn7r2OXqIgh4RdqE1/ui7GtGuKrH0KChoFd6OR3XQ1C1g8r6bvbAj8IWCg81I 3ngMfW5vq/7oANMF5i2sGwqJ3NpbeiFiXQsGL/TNo1c9h4H9qk3c/itoDHNy2JjW2F qePCBm8i3kzpA== From: Rustam Adilov To: Linus Walleij , Luiz Angelo Daros de Luca , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Willem de Bruijn , Simon Horman , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rustam Adilov 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 Message-ID: <20261204182553.33952-3-adilov@disroot.org> In-Reply-To: <20261204182553.33952-1-adilov@disroot.org> References: <20261204182553.33952-1-adilov@disroot.org> 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 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 --- 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 #include #include +#include #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