diff mbox series

[v4,4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver

Message ID 20240616105402.45211-5-biju.das.jz@bp.renesas.com (mailing list archive)
State Accepted
Delegated to: Geert Uytterhoeven
Headers show
Series Add USB VBUS regulator for RZ/G2L | expand

Commit Message

Biju Das June 16, 2024, 10:53 a.m. UTC
As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT
bit of the VBUS Control Register. This register is mapped in the reset
framework. The reset driver expose this register as regmap and instantiates
this driver. The consumer will use the regulator API to control the VBOUT
bit as the control need to be done in the atomic context.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3->v4:
 * Added check for of_get_child_by_name().
 * Released the resource by of_node_put()
v2->v3:
 * Dropped vbus_voltages table
 * Added support for enabling/disabling regulator through regmap API's
 * Updated rzg2l_usb_vbus_rdesc with enable_{reg,mask}, fixed_uV and
   n_voltages
 * Updated of_node with child node of the parent device.
v1->v2:
 * New patch
---
 drivers/regulator/Kconfig                     |  9 +++
 drivers/regulator/Makefile                    |  1 +
 .../regulator/renesas-usb-vbus-regulator.c    | 74 +++++++++++++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 drivers/regulator/renesas-usb-vbus-regulator.c

Comments

Geert Uytterhoeven July 11, 2024, 2:40 p.m. UTC | #1
Hi Biju,

On Sun, Jun 16, 2024 at 12:54 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT
> bit of the VBUS Control Register. This register is mapped in the reset
> framework. The reset driver expose this register as regmap and instantiates
> this driver. The consumer will use the regulator API to control the VBOUT
> bit as the control need to be done in the atomic context.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Thanks for your patch, which is now commit 84fbd6198766336f
("regulator: Add Renesas RZ/G2L USB VBUS regulator driver")
in regulator/for-next.

> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -1634,6 +1634,15 @@ config REGULATOR_UNIPHIER
>         help
>           Support for regulators implemented on Socionext UniPhier SoCs.
>
> +config REGULATOR_RZG2L_VBCTRL
> +       tristate "Renesas RZ/G2L USB VBUS regulator driver"
> +       depends on ARCH_RZG2L || COMPILE_TEST
> +       depends on OF
> +       select REGMAP_MMIO
> +       default ARCH_RZG2L

As the "rzg2l-usb-vbus-regulator" platform device is only created by
drivers/reset/reset-rzg2l-usbphy-ctrl.c, perhaps this should be made
stricter by using "default RESET_RZG2L_USBPHY_CTRL"?

Alternatively, RESET_RZG2L_USBPHY_CTRL could select
RESET_RZG2L_USBPHY_CTRL if REGULATOR.  Can RESET_RZG2L_USBPHY_CTRL
work without REGULATOR_RZG2L_VBCTRL?  If not, RESET_RZG2L_USBPHY_CTRL
should depend on REGULATOR, too.

Gr{oetje,eeting}s,

                        Geert
Biju Das July 11, 2024, 2:57 p.m. UTC | #2
Hi Geert,

Thanks for the feedback.

> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: Thursday, July 11, 2024 3:40 PM
> Subject: Re: [PATCH v4 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
> 
> Hi Biju,
> 
> On Sun, Jun 16, 2024 at 12:54 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT bit
> > of the VBUS Control Register. This register is mapped in the reset
> > framework. The reset driver expose this register as regmap and
> > instantiates this driver. The consumer will use the regulator API to
> > control the VBOUT bit as the control need to be done in the atomic context.
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> 
> Thanks for your patch, which is now commit 84fbd6198766336f
> ("regulator: Add Renesas RZ/G2L USB VBUS regulator driver") in regulator/for-next.

OK.

> 
> > --- a/drivers/regulator/Kconfig
> > +++ b/drivers/regulator/Kconfig
> > @@ -1634,6 +1634,15 @@ config REGULATOR_UNIPHIER
> >         help
> >           Support for regulators implemented on Socionext UniPhier SoCs.
> >
> > +config REGULATOR_RZG2L_VBCTRL
> > +       tristate "Renesas RZ/G2L USB VBUS regulator driver"
> > +       depends on ARCH_RZG2L || COMPILE_TEST
> > +       depends on OF
> > +       select REGMAP_MMIO
> > +       default ARCH_RZG2L
> 
> As the "rzg2l-usb-vbus-regulator" platform device is only created by drivers/reset/reset-rzg2l-
> usbphy-ctrl.c, perhaps this should be made stricter by using "default RESET_RZG2L_USBPHY_CTRL"?

OK.
> 
> Alternatively, RESET_RZG2L_USBPHY_CTRL could select RESET_RZG2L_USBPHY_CTRL if REGULATOR.  Can
> RESET_RZG2L_USBPHY_CTRL work without REGULATOR_RZG2L_VBCTRL?  If not, RESET_RZG2L_USBPHY_CTRL should
> depend on REGULATOR, too.

Yes, from functionality point it works for both host and device mode without REGULATOR_RZG2L_VBCTRL.
From specification point, some customers reported on device mode, VBUS is showing 5V.
So, by adding vbus regulator, I am controlling this voltage and forcing to 0 for device mode
and 5V for host mode.

Please share your input how to proceed.

Cheers,
Biju
Geert Uytterhoeven July 11, 2024, 3:14 p.m. UTC | #3
Hi Biju,

On Thu, Jul 11, 2024 at 4:58 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > -----Original Message-----
> > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > Sent: Thursday, July 11, 2024 3:40 PM
> > Subject: Re: [PATCH v4 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
> >
> > Hi Biju,
> >
> > On Sun, Jun 16, 2024 at 12:54 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT bit
> > > of the VBUS Control Register. This register is mapped in the reset
> > > framework. The reset driver expose this register as regmap and
> > > instantiates this driver. The consumer will use the regulator API to
> > > control the VBOUT bit as the control need to be done in the atomic context.
> > >
> > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> >
> > Thanks for your patch, which is now commit 84fbd6198766336f
> > ("regulator: Add Renesas RZ/G2L USB VBUS regulator driver") in regulator/for-next.

> > > --- a/drivers/regulator/Kconfig
> > > +++ b/drivers/regulator/Kconfig
> > > @@ -1634,6 +1634,15 @@ config REGULATOR_UNIPHIER
> > >         help
> > >           Support for regulators implemented on Socionext UniPhier SoCs.
> > >
> > > +config REGULATOR_RZG2L_VBCTRL
> > > +       tristate "Renesas RZ/G2L USB VBUS regulator driver"
> > > +       depends on ARCH_RZG2L || COMPILE_TEST
> > > +       depends on OF
> > > +       select REGMAP_MMIO
> > > +       default ARCH_RZG2L
> >
> > As the "rzg2l-usb-vbus-regulator" platform device is only created by drivers/reset/reset-rzg2l-
> > usbphy-ctrl.c, perhaps this should be made stricter by using "default RESET_RZG2L_USBPHY_CTRL"?
>
> OK.
> >
> > Alternatively, RESET_RZG2L_USBPHY_CTRL could select RESET_RZG2L_USBPHY_CTRL if REGULATOR.  Can
> > RESET_RZG2L_USBPHY_CTRL work without REGULATOR_RZG2L_VBCTRL?  If not, RESET_RZG2L_USBPHY_CTRL should
> > depend on REGULATOR, too.
>
> Yes, from functionality point it works for both host and device mode without REGULATOR_RZG2L_VBCTRL.
> From specification point, some customers reported on device mode, VBUS is showing 5V.
> So, by adding vbus regulator, I am controlling this voltage and forcing to 0 for device mode
> and 5V for host mode.
>
> Please share your input how to proceed.

As it works without, I think changing the default of
REGULATOR_RZG2L_VBCTRL from ARCH_RZG2L to RESET_RZG2L_USBPHY_CTRL is
the most appropriate option.

Gr{oetje,eeting}s,

                        Geert
Biju Das July 12, 2024, 1:45 p.m. UTC | #4
Hi Geert,

> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: Thursday, July 11, 2024 4:14 PM
> Subject: Re: [PATCH v4 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
> 
> Hi Biju,
> 
> On Thu, Jul 11, 2024 at 4:58 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > -----Original Message-----
> > > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > > Sent: Thursday, July 11, 2024 3:40 PM
> > > Subject: Re: [PATCH v4 4/6] regulator: Add Renesas RZ/G2L USB VBUS
> > > regulator driver
> > >
> > > Hi Biju,
> > >
> > > On Sun, Jun 16, 2024 at 12:54 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > > As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT
> > > > bit of the VBUS Control Register. This register is mapped in the
> > > > reset framework. The reset driver expose this register as regmap
> > > > and instantiates this driver. The consumer will use the regulator
> > > > API to control the VBOUT bit as the control need to be done in the atomic context.
> > > >
> > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > >
> > > Thanks for your patch, which is now commit 84fbd6198766336f
> > > ("regulator: Add Renesas RZ/G2L USB VBUS regulator driver") in regulator/for-next.
> 
> > > > --- a/drivers/regulator/Kconfig
> > > > +++ b/drivers/regulator/Kconfig
> > > > @@ -1634,6 +1634,15 @@ config REGULATOR_UNIPHIER
> > > >         help
> > > >           Support for regulators implemented on Socionext UniPhier SoCs.
> > > >
> > > > +config REGULATOR_RZG2L_VBCTRL
> > > > +       tristate "Renesas RZ/G2L USB VBUS regulator driver"
> > > > +       depends on ARCH_RZG2L || COMPILE_TEST
> > > > +       depends on OF
> > > > +       select REGMAP_MMIO
> > > > +       default ARCH_RZG2L
> > >
> > > As the "rzg2l-usb-vbus-regulator" platform device is only created by
> > > drivers/reset/reset-rzg2l- usbphy-ctrl.c, perhaps this should be made stricter by using "default
> RESET_RZG2L_USBPHY_CTRL"?
> >
> > OK.
> > >
> > > Alternatively, RESET_RZG2L_USBPHY_CTRL could select
> > > RESET_RZG2L_USBPHY_CTRL if REGULATOR.  Can RESET_RZG2L_USBPHY_CTRL
> > > work without REGULATOR_RZG2L_VBCTRL?  If not, RESET_RZG2L_USBPHY_CTRL should depend on REGULATOR,
> too.
> >
> > Yes, from functionality point it works for both host and device mode without
> REGULATOR_RZG2L_VBCTRL.
> > From specification point, some customers reported on device mode, VBUS is showing 5V.
> > So, by adding vbus regulator, I am controlling this voltage and
> > forcing to 0 for device mode and 5V for host mode.
> >
> > Please share your input how to proceed.
> 
> As it works without, I think changing the default of REGULATOR_RZG2L_VBCTRL from ARCH_RZG2L to
> RESET_RZG2L_USBPHY_CTRL is the most appropriate option.

OK.

Thanks,
Biju
diff mbox series

Patch

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index d333be2bea3b..0281a9a6f4ce 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1634,6 +1634,15 @@  config REGULATOR_UNIPHIER
 	help
 	  Support for regulators implemented on Socionext UniPhier SoCs.
 
+config REGULATOR_RZG2L_VBCTRL
+	tristate "Renesas RZ/G2L USB VBUS regulator driver"
+	depends on ARCH_RZG2L || COMPILE_TEST
+	depends on OF
+	select REGMAP_MMIO
+	default ARCH_RZG2L
+	help
+	  Support for VBUS regulators implemented on Renesas RZ/G2L SoCs.
+
 config REGULATOR_VCTRL
 	tristate "Voltage controlled regulators"
 	depends on OF
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ba15fa5f30ad..6127ffb4b011 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -189,6 +189,7 @@  obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
 obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
 obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o
+obj-$(CONFIG_REGULATOR_RZG2L_VBCTRL) += renesas-usb-vbus-regulator.o
 obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
 obj-$(CONFIG_REGULATOR_VQMMC_IPQ4019) += vqmmc-ipq4019-regulator.o
diff --git a/drivers/regulator/renesas-usb-vbus-regulator.c b/drivers/regulator/renesas-usb-vbus-regulator.c
new file mode 100644
index 000000000000..4eceb6b54497
--- /dev/null
+++ b/drivers/regulator/renesas-usb-vbus-regulator.c
@@ -0,0 +1,74 @@ 
+// SPDX-License-Identifier: GPL-2.0
+//
+// Renesas USB VBUS output regulator driver
+//
+// Copyright (C) 2024 Renesas Electronics Corporation
+//
+
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/of_regulator.h>
+
+static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
+	.enable     = regulator_enable_regmap,
+	.disable    = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+};
+
+static const struct regulator_desc rzg2l_usb_vbus_rdesc = {
+	.name = "vbus",
+	.of_match = of_match_ptr("regulator-vbus"),
+	.ops = &rzg2l_usb_vbus_reg_ops,
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+	.enable_reg  = 0,
+	.enable_mask = BIT(0),
+	.enable_is_inverted = true,
+	.fixed_uV	= 5000000,
+	.n_voltages	= 1,
+};
+
+static int rzg2l_usb_vbus_regulator_probe(struct platform_device *pdev)
+{
+	struct regulator_config config = { };
+	struct device *dev = &pdev->dev;
+	struct regulator_dev *rdev;
+
+	config.regmap = dev_get_regmap(dev->parent, NULL);
+	if (!config.regmap)
+		return dev_err_probe(dev, -ENOENT, "Failed to get regmap\n");
+
+	config.dev = dev;
+	config.of_node = of_get_child_by_name(dev->parent->of_node, "regulator-vbus");
+	if (!config.of_node)
+		return dev_err_probe(dev, -ENODEV, "regulator node not found\n");
+
+	rdev = devm_regulator_register(dev, &rzg2l_usb_vbus_rdesc, &config);
+	if (IS_ERR(rdev)) {
+		of_node_put(config.of_node);
+		return dev_err_probe(dev, PTR_ERR(rdev),
+				     "not able to register vbus regulator\n");
+	}
+
+	of_node_put(config.of_node);
+
+	return 0;
+}
+
+static struct platform_driver rzg2l_usb_vbus_regulator_driver = {
+	.probe = rzg2l_usb_vbus_regulator_probe,
+	.driver	= {
+		.name = "rzg2l-usb-vbus-regulator",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+};
+module_platform_driver(rzg2l_usb_vbus_regulator_driver);
+
+MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
+MODULE_DESCRIPTION("Renesas RZ/G2L USB Vbus Regulator Driver");
+MODULE_LICENSE("GPL");