[PATCH v4 06/22] mux: Add driver for Renesas RZ/V2H USB VBUS_SEL mux

Tommaso Merciai
2025-11-21T15:13:39Z

As per the RZ/V2H(P) HW manual, VBUSEN can be controlled by the VBUS_SEL
bit of the VBENCTL Control Register. This register is mapped in the
reset framework. The reset driver expose this register as mux-controller
and instantiates this driver. The consumer will use the mux API to
control the VBUS_SEL bit.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
v3->v4:
- Removed mux_chip->dev.of_node not needed.

v2->v3:
- Added mux_chip->dev.of_node = dev->of_node->child as the mux-controller
is an internal node.
- Fixed auxiliary_device_id name.
- Get rdev using from platform_data.
- Drop struct auxiliary_device adev from reset_rzv2h_usb2phy_adev
as it is needed.
- Drop to_reset_rzv2h_usb2phy_adev() as it is not needed.

v1->v2:
- New patch

drivers/mux/Kconfig | 10 +++
drivers/mux/Makefile | 2 +
drivers/mux/rzv2h-usb-vbus.c | 97 +++++++++++++++++++++++
include/linux/reset/reset_rzv2h_usb2phy.h | 11 +++
4 files changed, 120 insertions(+)
create mode 100644 drivers/mux/rzv2h-usb-vbus.c
create mode 100644 include/linux/reset/reset_rzv2h_usb2phy.h

diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
index c68132e38138..604f625544ed 100644
--- a/drivers/mux/Kconfig
+++ b/drivers/mux/Kconfig
@@ -59,4 +59,14 @@ config MUX_MMIO
To compile the driver as a module, choose M here: the module will
be called mux-mmio.

+config MUX_RZV2H_VBENCTL
+ tristate "Renesas RZ/V2H USB VBUS mux driver"
+ depends on RESET_RZV2H_USB2PHY || COMPILE_TEST
+ depends on OF
+ select REGMAP_MMIO
+ select AUXILIARY_BUS
+ default RESET_RZV2H_USB2PHY
+ help
+ Support for VBUS mux implemented on Renesas RZ/V2H SoCs.
+
endmenu
diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
index 6e9fa47daf56..9421660399af 100644
--- a/drivers/mux/Makefile
+++ b/drivers/mux/Makefile
@@ -8,9 +8,11 @@ mux-adg792a-objs := adg792a.o
mux-adgs1408-objs := adgs1408.o
mux-gpio-objs := gpio.o
mux-mmio-objs := mmio.o
+mux-rzv2h-usb-vbus-objs := rzv2h-usb-vbus.o

obj-$(CONFIG_MULTIPLEXER) += mux-core.o
obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o
obj-$(CONFIG_MUX_ADGS1408) += mux-adgs1408.o
obj-$(CONFIG_MUX_GPIO) += mux-gpio.o
obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
+obj-$(CONFIG_MUX_RZV2H_VBENCTL) += mux-rzv2h-usb-vbus.o
diff --git a/drivers/mux/rzv2h-usb-vbus.c b/drivers/mux/rzv2h-usb-vbus.c
new file mode 100644
index 000000000000..9513bc8f35ff
--- /dev/null
+++ b/drivers/mux/rzv2h-usb-vbus.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas RZ/V2H(P) USB2 VBUS_SEL mux driver
+ *
+ * Copyright (C) 2025 Renesas Electronics Corp.
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/mux/driver.h>
+#include <linux/of.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/reset/reset_rzv2h_usb2phy.h>
+
+#define RZV2H_VBENCTL 0xf0c
+
+struct mux_rzv2h_usb_vbus_priv {
+ struct regmap_field *field;
+};
+
+static int mux_rzv2h_usb_vbus_set(struct mux_control *mux, int state)
+{
+ struct mux_rzv2h_usb_vbus_priv *priv = mux_chip_priv(mux->chip);
+
+ return regmap_field_write(priv->field, state);
+}
+
+static const struct mux_control_ops mux_rzv2h_usb_vbus_ops = {
+ .set = mux_rzv2h_usb_vbus_set,
+};
+
+static const struct regmap_config rzv2h_usb_vbus_regconf = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = 4,
+ .max_register = RZV2H_VBENCTL,
+};
+
+static int mux_rzv2h_usb_vbus_probe(struct auxiliary_device *adev,
+ const struct auxiliary_device_id *id)
+{
+ struct reset_rzv2h_usb2phy_adev *rdev = adev->dev.platform_data;
+ struct mux_rzv2h_usb_vbus_priv *priv;
+ struct device *dev = &adev->dev;
+ struct mux_chip *mux_chip;
+ struct regmap *regmap;
+ struct reg_field reg_field = {
+ .reg = RZV2H_VBENCTL,
+ .lsb = 0,
+ .msb = 0,
+ };
+ int ret;
+
+ regmap = devm_regmap_init_mmio(dev, rdev->base, &rzv2h_usb_vbus_regconf);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*priv));
+ if (IS_ERR(mux_chip))
+ return PTR_ERR(mux_chip);
+
+ priv = mux_chip_priv(mux_chip);
+
+ priv->field = devm_regmap_field_alloc(dev, regmap, reg_field);
+ if (IS_ERR(priv->field))
+ return PTR_ERR(priv->field);
+
+ mux_chip->ops = &mux_rzv2h_usb_vbus_ops;
+ mux_chip->mux[0].states = 2;
+ mux_chip->mux[0].idle_state = MUX_IDLE_AS_IS;
+
+ ret = devm_mux_chip_register(dev, mux_chip);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to register mux chip\n");
+
+ return 0;
+}
+
+static const struct auxiliary_device_id mux_rzv2h_usb_vbus_ids[] = {
+ { .name = "rzv2h_usb2phy_reset.vbus-sel-mux" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(auxiliary, mux_rzv2h_usb_vbus_ids);
+
+static struct auxiliary_driver mux_rzv2h_usb_vbus_driver = {
+ .name = "vbus-sel-mux",
+ .probe = mux_rzv2h_usb_vbus_probe,
+ .id_table = mux_rzv2h_usb_vbus_ids,
+};
+module_auxiliary_driver(mux_rzv2h_usb_vbus_driver);
+
+MODULE_DESCRIPTION("RZ/V2H USB VBUS_SEL mux driver");
+MODULE_AUTHOR("Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/reset/reset_rzv2h_usb2phy.h b/include/linux/reset/reset_rzv2h_usb2phy.h
new file mode 100644
index 000000000000..06247080a66c
--- /dev/null
+++ b/include/linux/reset/reset_rzv2h_usb2phy.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _RESET_RZV2H_USB2PHY_H
+#define _RESET_RZV2H_USB2PHY_H
+
+#include <linux/auxiliary_bus.h>
+
+struct reset_rzv2h_usb2phy_adev {
+ void __iomem *base;
+};
+
+#endif
--
2.43.0