diff mbox series

[RFC,v2,2/4] regulator: Add Renesas RZ/G2L USB VBUS regulator driver

Message ID 20240607113745.73934-3-biju.das.jz@bp.renesas.com
State Superseded
Headers show
Series Add USB VBUS regulator for RZ/G2L | expand

Commit Message

Biju Das June 7, 2024, 11:37 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 device will use the regulator regmap 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>
---
v1->v2:
 * New patch
---
 drivers/regulator/Kconfig                     |  9 +++
 drivers/regulator/Makefile                    |  1 +
 .../regulator/renesas-usb-vbus-regulator.c    | 65 +++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 drivers/regulator/renesas-usb-vbus-regulator.c

Comments

Mark Brown June 7, 2024, 3:31 p.m. UTC | #1
On Fri, Jun 07, 2024 at 12:37:43PM +0100, Biju Das wrote:

> +static const unsigned int vbus_voltages[] = {
> +	3300000, 0
> +};
> +
> +static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
> +	.list_voltage = regulator_list_voltage_table,
> +};

This is an enable control, not a voltage set control?
Biju Das June 7, 2024, 4:20 p.m. UTC | #2
Hi Mark Brown,

Thanks for the feedc

> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Friday, June 7, 2024 4:31 PM
> Subject: Re: [PATCH RFC v2 2/4] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
> 
> On Fri, Jun 07, 2024 at 12:37:43PM +0100, Biju Das wrote:
> 
> > +static const unsigned int vbus_voltages[] = {
> > +	3300000, 0
> > +};
> > +
> > +static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
> > +	.list_voltage = regulator_list_voltage_table, };
> 
> This is an enable control, not a voltage set control?

Yes, it is enable control(inverted logic). Disabling the bit supplies the Vbus voltage.

Is there any atomic regulator API's I can make use of enabling it?? VBUS detection
happens in interrupt context.

Cheers,
Biju
Mark Brown June 7, 2024, 4:47 p.m. UTC | #3
On Fri, Jun 07, 2024 at 04:20:10PM +0000, Biju Das wrote:

> Is there any atomic regulator API's I can make use of enabling it?? VBUS detection
> happens in interrupt context.

There are no atomic regulator APIs at all at the minute.
Biju Das June 10, 2024, 7:59 a.m. UTC | #4
Hi Mark Brown,

> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Friday, June 7, 2024 5:48 PM
> Subject: Re: [PATCH RFC v2 2/4] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
> 
> On Fri, Jun 07, 2024 at 04:20:10PM +0000, Biju Das wrote:
> 
> > Is there any atomic regulator API's I can make use of enabling it??
> > VBUS detection happens in interrupt context.
> 
> There are no atomic regulator APIs at all at the minute.

I will explore adding atomic regulator API's with my current use case
and later we can expand.

Cheers,
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..24582782ad40
--- /dev/null
+++ b/drivers/regulator/renesas-usb-vbus-regulator.c
@@ -0,0 +1,65 @@ 
+// 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/regulator/driver.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/regmap.h>
+
+static const unsigned int vbus_voltages[] = {
+	3300000, 0
+};
+
+static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
+	.list_voltage = regulator_list_voltage_table,
+};
+
+static const struct regulator_desc rzg2l_usb_vbus_rdesc = {
+	.name = "usb_vbus",
+	.ops = &rzg2l_usb_vbus_reg_ops,
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+	.volt_table = vbus_voltages,
+	.n_voltages = ARRAY_SIZE(vbus_voltages),
+};
+
+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 = dev->of_node;
+	rdev = devm_regulator_register(dev, &rzg2l_usb_vbus_rdesc, &config);
+	if (IS_ERR(rdev))
+		return dev_err_probe(dev, PTR_ERR(rdev),
+				     "not able to register vbus regulator\n");
+
+	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");