Add a new regulator driver to control the USB VBUS supply on the Renesas
RZ/G2L and related SoCs.

Signed-off-by: Paul Barker <paul.barker...@bp.renesas.com>
---
 drivers/power/regulator/Kconfig               |  8 ++++
 drivers/power/regulator/Makefile              |  1 +
 .../power/regulator/rzg2l-usbphy-regulator.c  | 42 +++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 drivers/power/regulator/rzg2l-usbphy-regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 958f337c7e73..8f102a92c23b 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -478,3 +478,11 @@ config DM_REGULATOR_TPS65219
        features for REGULATOR TPS65219 and the family of TPS65219 PMICs.
        TPS65219 series of PMICs have 3 single phase BUCKs & 4 LDOs.
        The driver implements get/set api for value and enable.
+
+config REGULATOR_RZG2L_USBPHY
+       bool "Enable driver for RZ/G2L USB PHY VBUS supply"
+       depends on DM_REGULATOR
+       help
+         Enable this option to support controlling the VBUS supply in
+         the USB PHY peripheral of the Renesas RZ/G2L SoC. This option
+         is required in order to use the USB OTG port.
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index ca6c89d13b5c..4382d4b3ab9a 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -42,3 +42,4 @@ obj-$(CONFIG_DM_REGULATOR_TPS65941) += tps65941_regulator.o
 obj-$(CONFIG_DM_REGULATOR_SCMI) += scmi_regulator.o
 obj-$(CONFIG_$(XPL_)DM_REGULATOR_ANATOP) += anatop_regulator.o
 obj-$(CONFIG_DM_REGULATOR_TPS65219) += tps65219_regulator.o
+obj-$(CONFIG_REGULATOR_RZG2L_USBPHY) += rzg2l-usbphy-regulator.o
diff --git a/drivers/power/regulator/rzg2l-usbphy-regulator.c 
b/drivers/power/regulator/rzg2l-usbphy-regulator.c
new file mode 100644
index 000000000000..451f04c140e6
--- /dev/null
+++ b/drivers/power/regulator/rzg2l-usbphy-regulator.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2024 Renesas Electronics Corporation
+ */
+
+#include <asm/io.h>
+#include <dm.h>
+#include <power/regulator.h>
+#include <renesas/rzg2l-usbphy.h>
+
+#define VBENCTL                        0x03c
+#define VBENCTL_VBUS_SEL       BIT(0)
+
+static int rzg2l_usbphy_regulator_set_enable(struct udevice *dev, bool enable)
+{
+       struct rzg2l_usbphy_ctrl_priv *priv = dev_get_priv(dev->parent);
+
+       if (enable)
+               clrbits_le32(priv->regs + VBENCTL, VBENCTL_VBUS_SEL);
+       else
+               setbits_le32(priv->regs + VBENCTL, VBENCTL_VBUS_SEL);
+
+       return 0;
+}
+
+static int rzg2l_usbphy_regulator_get_enable(struct udevice *dev)
+{
+       struct rzg2l_usbphy_ctrl_priv *priv = dev_get_priv(dev->parent);
+
+       return !!readl(priv->regs + VBENCTL) & VBENCTL_VBUS_SEL;
+}
+
+static const struct dm_regulator_ops rzg2l_usbphy_regulator_ops = {
+       .get_enable = rzg2l_usbphy_regulator_get_enable,
+       .set_enable = rzg2l_usbphy_regulator_set_enable,
+};
+
+U_BOOT_DRIVER(rzg2l_usbphy_regulator) = {
+       .name = "rzg2l_usbphy_regulator",
+       .id = UCLASS_REGULATOR,
+       .ops = &rzg2l_usbphy_regulator_ops,
+};
-- 
2.43.0

Reply via email to