* [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator
2024-06-11 11:03 [PATCH v3 0/6] Add support for USB VBUS control for RZ/G2L SoCs Biju Das
@ 2024-06-11 11:03 ` Biju Das
2024-06-12 6:37 ` Krzysztof Kozlowski
2024-06-11 11:03 ` [PATCH v3 2/6] reset: renesas: Add USB VBUS regulator device as child Biju Das
` (3 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: Biju Das @ 2024-06-11 11:03 UTC (permalink / raw)
To: Philipp Zabel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Biju Das, Liam Girdwood, Mark Brown, Vinod Koul,
Kishon Vijay Abraham I, Geert Uytterhoeven, Magnus Damm,
devicetree, linux-phy, linux-renesas-soc, Prabhakar Mahadev Lad,
Biju Das
The VBUS enable can be controlled by the VBOUT bit of the VBUS control
register. This register is part of usbphy-ctrl IP.
Document the USB VBUS regulator object.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3:
* New patch
---
.../bindings/reset/renesas,rzg2l-usbphy-ctrl.yaml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/Documentation/devicetree/bindings/reset/renesas,rzg2l-usbphy-ctrl.yaml b/Documentation/devicetree/bindings/reset/renesas,rzg2l-usbphy-ctrl.yaml
index 03c18611e42d..cfe479df0f41 100644
--- a/Documentation/devicetree/bindings/reset/renesas,rzg2l-usbphy-ctrl.yaml
+++ b/Documentation/devicetree/bindings/reset/renesas,rzg2l-usbphy-ctrl.yaml
@@ -42,6 +42,12 @@ properties:
0 = Port 1 Phy reset
1 = Port 2 Phy reset
+ regulator-vbus:
+ type: object
+ description: USB VBUS regulator
+ $ref: /schemas/regulator/regulator.yaml#
+ unevaluatedProperties: false
+
required:
- compatible
- reg
@@ -49,6 +55,7 @@ required:
- resets
- power-domains
- '#reset-cells'
+ - regulator-vbus
additionalProperties: false
@@ -64,4 +71,9 @@ examples:
resets = <&cpg R9A07G044_USB_PRESETN>;
power-domains = <&cpg>;
#reset-cells = <1>;
+ regulator-vbus {
+ regulator-name = "vbus";
+ regulator-min-microvolt = <5000000>;
+ regulator-max-microvolt = <5000000>;
+ };
};
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator
2024-06-11 11:03 ` [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator Biju Das
@ 2024-06-12 6:37 ` Krzysztof Kozlowski
2024-06-12 6:51 ` Biju Das
0 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-06-12 6:37 UTC (permalink / raw)
To: Biju Das, Philipp Zabel, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Liam Girdwood, Mark Brown, Vinod Koul, Kishon Vijay Abraham I,
Geert Uytterhoeven, Magnus Damm, devicetree, linux-phy,
linux-renesas-soc, Prabhakar Mahadev Lad, Biju Das
On 11/06/2024 13:03, Biju Das wrote:
> The VBUS enable can be controlled by the VBOUT bit of the VBUS control
> register. This register is part of usbphy-ctrl IP.
>
> Document the USB VBUS regulator object.
>
>
> additionalProperties: false
>
> @@ -64,4 +71,9 @@ examples:
> resets = <&cpg R9A07G044_USB_PRESETN>;
> power-domains = <&cpg>;
> #reset-cells = <1>;
> + regulator-vbus {
> + regulator-name = "vbus";
Messed indentation. What is the indentation of the rest?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 17+ messages in thread* RE: [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator
2024-06-12 6:37 ` Krzysztof Kozlowski
@ 2024-06-12 6:51 ` Biju Das
0 siblings, 0 replies; 17+ messages in thread
From: Biju Das @ 2024-06-12 6:51 UTC (permalink / raw)
To: Krzysztof Kozlowski, Philipp Zabel, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: Liam Girdwood, Mark Brown, Vinod Koul, Kishon Vijay Abraham I,
Geert Uytterhoeven, Magnus Damm, devicetree@vger.kernel.org,
linux-phy@lists.infradead.org, linux-renesas-soc@vger.kernel.org,
Prabhakar Mahadev Lad, biju.das.au
Hi Krzysztof Kozlowski,
Thanks for the feedback.
> -----Original Message-----
> From: Krzysztof Kozlowski <krzk@kernel.org>
> Sent: Wednesday, June 12, 2024 7:37 AM
> Subject: Re: [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS
> regulator
>
> On 11/06/2024 13:03, Biju Das wrote:
> > The VBUS enable can be controlled by the VBOUT bit of the VBUS control
> > register. This register is part of usbphy-ctrl IP.
> >
> > Document the USB VBUS regulator object.
> >
>
>
> >
> > additionalProperties: false
> >
> > @@ -64,4 +71,9 @@ examples:
> > resets = <&cpg R9A07G044_USB_PRESETN>;
> > power-domains = <&cpg>;
> > #reset-cells = <1>;
> > + regulator-vbus {
> > + regulator-name = "vbus";
>
> Messed indentation. What is the indentation of the rest?
OK, will indent with 4 spaces instead of 3.
Others have indentation with 4 space chars.
Cheers,
Biju
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 2/6] reset: renesas: Add USB VBUS regulator device as child
2024-06-11 11:03 [PATCH v3 0/6] Add support for USB VBUS control for RZ/G2L SoCs Biju Das
2024-06-11 11:03 ` [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator Biju Das
@ 2024-06-11 11:03 ` Biju Das
2024-06-11 11:03 ` [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register Biju Das
` (2 subsequent siblings)
4 siblings, 0 replies; 17+ messages in thread
From: Biju Das @ 2024-06-11 11:03 UTC (permalink / raw)
To: Philipp Zabel
Cc: Biju Das, Liam Girdwood, Mark Brown, Vinod Koul,
Kishon Vijay Abraham I, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Geert Uytterhoeven, Prabhakar Mahadev Lad, Biju Das,
devicetree, linux-phy, linux-renesas-soc
As per RZ/G2L HW manual, VBUS enable can be controlled by the VBOUT bit
of the VBUS Control Register(VBENCTL) register in the USBPHY Control.
Expose this register as regmap and instantiate the USB VBUS regulator
device, so that consumer can control the vbus using regulator API's
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v2->v3:
* Updated commit description and header
* Moved regulator device creation and instantiation at the end of probe().
v1->v2:
* Instantiated regulator driver
---
drivers/reset/reset-rzg2l-usbphy-ctrl.c | 37 +++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/reset/reset-rzg2l-usbphy-ctrl.c b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
index 8f6fbd978591..c740b3b9599d 100644
--- a/drivers/reset/reset-rzg2l-usbphy-ctrl.c
+++ b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
@@ -10,10 +10,12 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/reset-controller.h>
#define RESET 0x000
+#define VBENCTL 0x03c
#define RESET_SEL_PLLRESET BIT(12)
#define RESET_PLLRESET BIT(8)
@@ -32,6 +34,7 @@ struct rzg2l_usbphy_ctrl_priv {
struct reset_controller_dev rcdev;
struct reset_control *rstc;
void __iomem *base;
+ struct platform_device *vdev;
spinlock_t lock;
};
@@ -100,10 +103,19 @@ static const struct reset_control_ops rzg2l_usbphy_ctrl_reset_ops = {
.status = rzg2l_usbphy_ctrl_status,
};
+static const struct regmap_config rzg2l_usb_regconf = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = 4,
+ .max_register = 1,
+};
+
static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct rzg2l_usbphy_ctrl_priv *priv;
+ struct platform_device *vdev;
+ struct regmap *regmap;
unsigned long flags;
int error;
u32 val;
@@ -116,6 +128,10 @@ static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev)
if (IS_ERR(priv->base))
return PTR_ERR(priv->base);
+ regmap = devm_regmap_init_mmio(dev, priv->base + VBENCTL, &rzg2l_usb_regconf);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
if (IS_ERR(priv->rstc))
return dev_err_probe(dev, PTR_ERR(priv->rstc),
@@ -153,13 +169,34 @@ static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev)
writel(val, priv->base + RESET);
spin_unlock_irqrestore(&priv->lock, flags);
+ vdev = platform_device_alloc("rzg2l-usb-vbus-regulator", pdev->id);
+ if (!vdev) {
+ error = -ENOMEM;
+ goto err_pm_runtime_put;
+ }
+ vdev->dev.parent = dev;
+ priv->vdev = vdev;
+
+ error = platform_device_add(vdev);
+ if (error)
+ goto err_device_put;
+
return 0;
+
+err_device_put:
+ platform_device_put(vdev);
+err_pm_runtime_put:
+ pm_runtime_put(&pdev->dev);
+ pm_runtime_disable(&pdev->dev);
+ reset_control_assert(priv->rstc);
+ return error;
}
static void rzg2l_usbphy_ctrl_remove(struct platform_device *pdev)
{
struct rzg2l_usbphy_ctrl_priv *priv = dev_get_drvdata(&pdev->dev);
+ platform_device_unregister(priv->vdev);
pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev);
reset_control_assert(priv->rstc);
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-11 11:03 [PATCH v3 0/6] Add support for USB VBUS control for RZ/G2L SoCs Biju Das
2024-06-11 11:03 ` [PATCH v3 1/6] dt-bindings: reset: renesas,rzg2l-usbphy-ctrl: Document USB VBUS regulator Biju Das
2024-06-11 11:03 ` [PATCH v3 2/6] reset: renesas: Add USB VBUS regulator device as child Biju Das
@ 2024-06-11 11:03 ` Biju Das
2024-06-11 14:59 ` Mark Brown
2024-06-11 11:04 ` [PATCH v3 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver Biju Das
2024-06-11 11:04 ` [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS Biju Das
4 siblings, 1 reply; 17+ messages in thread
From: Biju Das @ 2024-06-11 11:03 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown
Cc: Biju Das, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm, Geert Uytterhoeven,
Prabhakar Mahadev Lad, Biju Das, devicetree, linux-phy,
linux-renesas-soc
Add a helper function that allow regulator consumers to allow low-level
enable register access, in order to enable/disable regulator in atomic
context.
The use-case for RZ/G2L SoC is to enable VBUS selection register based
on vbus detection that happens in interrupt context.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3:
* New patch.
---
Documentation/power/regulator/consumer.rst | 5 ++++
drivers/regulator/core.c | 32 ++++++++++++++++++++++
include/linux/regulator/consumer.h | 8 ++++++
3 files changed, 45 insertions(+)
diff --git a/Documentation/power/regulator/consumer.rst b/Documentation/power/regulator/consumer.rst
index 85c2bf5ac07e..b5502f4ffe46 100644
--- a/Documentation/power/regulator/consumer.rst
+++ b/Documentation/power/regulator/consumer.rst
@@ -227,3 +227,8 @@ directly written to the voltage selector register, use::
int regulator_list_hardware_vsel(struct regulator *regulator,
unsigned selector);
+
+To access the hardware register for enabling/disabling the regulator, use::
+
+ int regulator_set_hardware_enable_register(struct regulator *regulator,
+ bool enable);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5794f4e9dd52..19df42868bbd 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3407,6 +3407,38 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
}
EXPORT_SYMBOL_GPL(regulator_list_hardware_vsel);
+/**
+ * regulator_set_hardware_enable_register - set the HW enable register
+ * @regulator: regulator source
+ * @enable: true for enable, false for disable
+ *
+ * Request that the regulator be enabled/disabled with the regulator output at
+ * the predefined voltage or current value.
+ *
+ * On success 0 is returned, otherwise a negative errno is returned.
+ */
+int regulator_set_hardware_enable_register(struct regulator *regulator,
+ bool enable)
+{
+ struct regulator_dev *rdev = regulator->rdev;
+ const struct regulator_ops *ops = rdev->desc->ops;
+ int ret = -EOPNOTSUPP;
+
+ if (!ops)
+ return ret;
+
+ if (enable) {
+ if (ops->enable == regulator_enable_regmap)
+ ret = ops->enable(rdev);
+ } else {
+ if (ops->disable == regulator_disable_regmap)
+ ret = rdev->desc->ops->disable(rdev);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_set_hardware_enable_register);
+
/**
* regulator_get_linear_step - return the voltage step size between VSEL values
* @regulator: regulator source
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index e6f81fc1fb17..4aa5c57de052 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -250,6 +250,8 @@ int regulator_get_hardware_vsel_register(struct regulator *regulator,
unsigned *vsel_mask);
int regulator_list_hardware_vsel(struct regulator *regulator,
unsigned selector);
+int regulator_set_hardware_enable_register(struct regulator *regulator,
+ bool enable);
/* regulator notifier block */
int regulator_register_notifier(struct regulator *regulator,
@@ -571,6 +573,12 @@ static inline int regulator_list_hardware_vsel(struct regulator *regulator,
return -EOPNOTSUPP;
}
+static inline int regulator_set_hardware_enable_register(struct regulator *regulator,
+ bool enable)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int regulator_register_notifier(struct regulator *regulator,
struct notifier_block *nb)
{
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-11 11:03 ` [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register Biju Das
@ 2024-06-11 14:59 ` Mark Brown
2024-06-11 16:28 ` Biju Das
0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2024-06-11 14:59 UTC (permalink / raw)
To: Biju Das
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm, Geert Uytterhoeven,
Prabhakar Mahadev Lad, Biju Das, devicetree, linux-phy,
linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 893 bytes --]
On Tue, Jun 11, 2024 at 12:03:59PM +0100, Biju Das wrote:
> Add a helper function that allow regulator consumers to allow low-level
> enable register access, in order to enable/disable regulator in atomic
> context.
> +To access the hardware register for enabling/disabling the regulator, use::
> +
> + int regulator_set_hardware_enable_register(struct regulator *regulator,
> + bool enable);
So, it'll doubtless not be a surprise that I'm not thrilled with this -
it's basically just punching a hole straight through all the locking and
reference counting in a way that's just begging for abuse. At the very
least we should have a check for exclusive access in there.
Also it's not sure about that name, if we were doing this it should be
more describing the effect on the regulator rather than this happening
to be done via a register write (this should also work for GPIOs...).
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-11 14:59 ` Mark Brown
@ 2024-06-11 16:28 ` Biju Das
2024-06-12 15:50 ` Mark Brown
0 siblings, 1 reply; 17+ messages in thread
From: Biju Das @ 2024-06-11 16:28 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm@vger.kernel.org,
Geert Uytterhoeven, Prabhakar Mahadev Lad, biju.das.au,
devicetree@vger.kernel.org, linux-phy@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
Hi Mark Brown,
Thanks for the feedback.
> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Tuesday, June 11, 2024 4:00 PM
> Subject: Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
>
> On Tue, Jun 11, 2024 at 12:03:59PM +0100, Biju Das wrote:
> > Add a helper function that allow regulator consumers to allow
> > low-level enable register access, in order to enable/disable regulator
> > in atomic context.
>
> > +To access the hardware register for enabling/disabling the regulator, use::
> > +
> > + int regulator_set_hardware_enable_register(struct regulator *regulator,
> > + bool enable);
>
> So, it'll doubtless not be a surprise that I'm not thrilled with this - it's basically just
> punching a hole straight through all the locking and reference counting in a way that's just
> begging for abuse. At the very least we should have a check for exclusive access in there.
Do you mean exclusive access by means of spinlock to avoid race between enable/disable()?
If that is the case
Option1:
Add a spin_lock in struct regulator_dev and add locking in regulator_xxx_hardware_enable_xxx()
Option 2:
Core calls the callback for enable()/disable() and driver handles the exclusive access by
spin lock
or
Please share, if you have any other options?
>
> Also it's not sure about that name, if we were doing this it should be more describing the effect
What about the name regulator_hardware_enable() to make it generic??
> on the regulator rather than this happening to be done via a register write (this should also work
> for GPIOs...).
Do you mean to make it generic, so that it works for both regmap based enable/disable() as well as
gpio based enable()/disable()??
Cheers,
Biju
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-11 16:28 ` Biju Das
@ 2024-06-12 15:50 ` Mark Brown
2024-06-14 11:43 ` Biju Das
0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2024-06-12 15:50 UTC (permalink / raw)
To: Biju Das
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm@vger.kernel.org,
Geert Uytterhoeven, Prabhakar Mahadev Lad, biju.das.au,
devicetree@vger.kernel.org, linux-phy@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]
On Tue, Jun 11, 2024 at 04:28:37PM +0000, Biju Das wrote:
> > So, it'll doubtless not be a surprise that I'm not thrilled with this - it's basically just
> > punching a hole straight through all the locking and reference counting in a way that's just
> > begging for abuse. At the very least we should have a check for exclusive access in there.
> Do you mean exclusive access by means of spinlock to avoid race between enable/disable()?
> If that is the case
No, I mean regulator_get_exclusive(), this clearly can't work if there's
more than one consumer.
> > Also it's not sure about that name, if we were doing this it should be more describing the effect
> What about the name regulator_hardware_enable() to make it generic??
Possibly.
> > on the regulator rather than this happening to be done via a register write (this should also work
> > for GPIOs...).
> Do you mean to make it generic, so that it works for both regmap based enable/disable() as well as
> gpio based enable()/disable()??
That too, I was mainly thinking about the name here though.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-12 15:50 ` Mark Brown
@ 2024-06-14 11:43 ` Biju Das
2024-06-14 14:31 ` Mark Brown
0 siblings, 1 reply; 17+ messages in thread
From: Biju Das @ 2024-06-14 11:43 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm@vger.kernel.org,
Geert Uytterhoeven, Prabhakar Mahadev Lad, biju.das.au,
devicetree@vger.kernel.org, linux-phy@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
Hi Mark Brown,
Thanks for the feedback.
> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Wednesday, June 12, 2024 4:50 PM
> Subject: Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
>
> On Tue, Jun 11, 2024 at 04:28:37PM +0000, Biju Das wrote:
>
> > > So, it'll doubtless not be a surprise that I'm not thrilled with
> > > this - it's basically just punching a hole straight through all the
> > > locking and reference counting in a way that's just begging for abuse. At the very least we
> should have a check for exclusive access in there.
>
> > Do you mean exclusive access by means of spinlock to avoid race between enable/disable()?
> > If that is the case
>
> No, I mean regulator_get_exclusive(), this clearly can't work if there's more than one consumer.
OK, I will document like below
To access the hardware register for enabling/disabling the regulator,
consumers must use regulator_get_exclusive(), as it can't work if there's
more than one consumer. To enable/disable regulator use::
int regulator_hardware_enable(struct regulator *regulator, bool enable);
>
> > > Also it's not sure about that name, if we were doing this it should
> > > be more describing the effect
>
> > What about the name regulator_hardware_enable() to make it generic??
>
> Possibly.
>
> > > on the regulator rather than this happening to be done via a
> > > register write (this should also work for GPIOs...).
>
> > Do you mean to make it generic, so that it works for both regmap based
> > enable/disable() as well as gpio based enable()/disable()??
>
> That too, I was mainly thinking about the name here though.
OK, will remove the restriction
- if (enable) {
- if (ops->enable == regulator_enable_regmap)
- ret = ops->enable(rdev);
- } else {
- if (ops->disable == regulator_disable_regmap)
- ret = rdev->desc->ops->disable(rdev);
- }
+ if (enable)
+ ret = ops->enable(rdev);
+ else
+ ret = ops->disable(rdev);
Please let me know if anything wrong.
Cheers,
Biju
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-14 11:43 ` Biju Das
@ 2024-06-14 14:31 ` Mark Brown
2024-06-14 15:52 ` Biju Das
0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2024-06-14 14:31 UTC (permalink / raw)
To: Biju Das
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm@vger.kernel.org,
Geert Uytterhoeven, Prabhakar Mahadev Lad, biju.das.au,
devicetree@vger.kernel.org, linux-phy@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 884 bytes --]
On Fri, Jun 14, 2024 at 11:43:39AM +0000, Biju Das wrote:
> To access the hardware register for enabling/disabling the regulator,
> consumers must use regulator_get_exclusive(), as it can't work if there's
> more than one consumer. To enable/disable regulator use::
> int regulator_hardware_enable(struct regulator *regulator, bool enable);
We should also enforce this.
> OK, will remove the restriction
> - if (enable) {
> - if (ops->enable == regulator_enable_regmap)
> - ret = ops->enable(rdev);
> - } else {
> - if (ops->disable == regulator_disable_regmap)
> - ret = rdev->desc->ops->disable(rdev);
> - }
> + if (enable)
> + ret = ops->enable(rdev);
> + else
> + ret = ops->disable(rdev);
> Please let me know if anything wrong.
Sure.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread* RE: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
2024-06-14 14:31 ` Mark Brown
@ 2024-06-14 15:52 ` Biju Das
0 siblings, 0 replies; 17+ messages in thread
From: Biju Das @ 2024-06-14 15:52 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Philipp Zabel, Vinod Koul, Kishon Vijay Abraham I,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
Len Brown, Pavel Machek, linux-pm@vger.kernel.org,
Geert Uytterhoeven, Prabhakar Mahadev Lad, biju.das.au,
devicetree@vger.kernel.org, linux-phy@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
Hi Mark Brown,
Thanks for the feedback.
> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Friday, June 14, 2024 3:32 PM
> Subject: Re: [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register
>
> On Fri, Jun 14, 2024 at 11:43:39AM +0000, Biju Das wrote:
>
> > To access the hardware register for enabling/disabling the regulator,
> > consumers must use regulator_get_exclusive(), as it can't work if
> > there's more than one consumer. To enable/disable regulator use::
>
> > int regulator_hardware_enable(struct regulator *regulator, bool
> > enable);
>
> We should also enforce this.
OK, will enforce and return error
int ret = -EOPNOTSUPP;
if (!ops || !ops->enable || !ops->disable || !regulator->exclusive)
return ret;
Cheers,
Biju
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver
2024-06-11 11:03 [PATCH v3 0/6] Add support for USB VBUS control for RZ/G2L SoCs Biju Das
` (2 preceding siblings ...)
2024-06-11 11:03 ` [PATCH v3 3/6] regulator: core: Add helper for allow access to enable register Biju Das
@ 2024-06-11 11:04 ` Biju Das
2024-06-11 11:04 ` [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS Biju Das
4 siblings, 0 replies; 17+ messages in thread
From: Biju Das @ 2024-06-11 11:04 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown
Cc: Biju Das, Vinod Koul, Kishon Vijay Abraham I, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Philipp Zabel,
Geert Uytterhoeven, Prabhakar Mahadev Lad, Biju Das, devicetree,
linux-phy, linux-renesas-soc
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>
---
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 | 67 +++++++++++++++++++
3 files changed, 77 insertions(+)
create mode 100644 drivers/regulator/renesas-usb-vbus-regulator.c
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..d53e243d25b7
--- /dev/null
+++ b/drivers/regulator/renesas-usb-vbus-regulator.c
@@ -0,0 +1,67 @@
+// 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");
+ 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");
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS
2024-06-11 11:03 [PATCH v3 0/6] Add support for USB VBUS control for RZ/G2L SoCs Biju Das
` (3 preceding siblings ...)
2024-06-11 11:04 ` [PATCH v3 4/6] regulator: Add Renesas RZ/G2L USB VBUS regulator driver Biju Das
@ 2024-06-11 11:04 ` Biju Das
2024-06-12 6:38 ` Krzysztof Kozlowski
4 siblings, 1 reply; 17+ messages in thread
From: Biju Das @ 2024-06-11 11:04 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Biju Das, Liam Girdwood, Mark Brown, Vinod Koul,
Kishon Vijay Abraham I, Geert Uytterhoeven, Magnus Damm,
linux-renesas-soc, linux-phy, devicetree, Prabhakar Mahadev Lad,
Biju Das
Replace the fixed regulator for USB VBUS.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v2->v3:
* Upated label name
* Updated node and regulator name that matches with the bindings.
v1->v2:
* New patch.
---
arch/arm64/boot/dts/renesas/rz-smarc-common.dtsi | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/boot/dts/renesas/rz-smarc-common.dtsi b/arch/arm64/boot/dts/renesas/rz-smarc-common.dtsi
index b7a3e6caa386..a444cb6507d3 100644
--- a/arch/arm64/boot/dts/renesas/rz-smarc-common.dtsi
+++ b/arch/arm64/boot/dts/renesas/rz-smarc-common.dtsi
@@ -54,14 +54,6 @@ codec_dai: simple-audio-card,codec {
};
};
- usb0_vbus_otg: regulator-usb0-vbus-otg {
- compatible = "regulator-fixed";
-
- regulator-name = "USB0_VBUS_OTG";
- regulator-min-microvolt = <5000000>;
- regulator-max-microvolt = <5000000>;
- };
-
vccq_sdhi1: regulator-vccq-sdhi1 {
compatible = "regulator-gpio";
regulator-name = "SDHI1 VccQ";
@@ -139,6 +131,11 @@ &ohci1 {
&phyrst {
status = "okay";
+ usb0_vbus_otg: regulator-vbus {
+ regulator-name = "vbus";
+ regulator-min-microvolt = <5000000>;
+ regulator-max-microvolt = <5000000>;
+ };
};
&scif0 {
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS
2024-06-11 11:04 ` [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS Biju Das
@ 2024-06-12 6:38 ` Krzysztof Kozlowski
2024-06-12 6:52 ` Biju Das
0 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-06-12 6:38 UTC (permalink / raw)
To: Biju Das, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Liam Girdwood, Mark Brown, Vinod Koul, Kishon Vijay Abraham I,
Geert Uytterhoeven, Magnus Damm, linux-renesas-soc, linux-phy,
devicetree, Prabhakar Mahadev Lad, Biju Das
On 11/06/2024 13:04, Biju Das wrote:
> &phyrst {
> status = "okay";
> + usb0_vbus_otg: regulator-vbus {
> + regulator-name = "vbus";
> + regulator-min-microvolt = <5000000>;
> + regulator-max-microvolt = <5000000>;
These two voltages look unnecessary. You know the voltage of your LDO,
don't you? It's fixed, cannot be anything else.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 17+ messages in thread* RE: [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS
2024-06-12 6:38 ` Krzysztof Kozlowski
@ 2024-06-12 6:52 ` Biju Das
0 siblings, 0 replies; 17+ messages in thread
From: Biju Das @ 2024-06-12 6:52 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Liam Girdwood, Mark Brown, Vinod Koul, Kishon Vijay Abraham I,
Geert Uytterhoeven, Magnus Damm,
linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org,
devicetree@vger.kernel.org, Prabhakar Mahadev Lad, biju.das.au
Hi Krzysztof Kozlowski,
Thanks for the feedback.
> -----Original Message-----
> From: Krzysztof Kozlowski <krzk@kernel.org>
> Sent: Wednesday, June 12, 2024 7:38 AM
> Subject: Re: [PATCH v3 6/6] arm64: dts: renesas: rz-smarc: Replace fixed regulator for USB VBUS
>
> On 11/06/2024 13:04, Biju Das wrote:
> > &phyrst {
> > status = "okay";
> > + usb0_vbus_otg: regulator-vbus {
> > + regulator-name = "vbus";
> > + regulator-min-microvolt = <5000000>;
> > + regulator-max-microvolt = <5000000>;
>
> These two voltages look unnecessary. You know the voltage of your LDO, don't you? It's fixed,
> cannot be anything else.
Agreed, Will drop the same.
Cheers,
Biju
^ permalink raw reply [flat|nested] 17+ messages in thread