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