* [PATCH v2 0/2] regulator: richtek,rt4801: use existing ena_gpiod feature
@ 2022-04-23 18:14 Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 1/2] regulator: dt-bindings: " Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 2/2] regulator: " Krzysztof Kozlowski
0 siblings, 2 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-23 18:14 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
ChiYuan Huang, linux-kernel, devicetree
Cc: Krzysztof Kozlowski
Hi,
Not tested.
Follow up of discussion:
https://lore.kernel.org/all/2d124d53-1f36-5315-3877-af8f8ad5f824@linaro.org/#t
Changes since v1
================
Patch 1: add review tag.
Patch 2: Check for ena_gpio_state before accessing I2C (issue pointed out by
ChiYuan Huang).
Best regards,
Krzysztof
Krzysztof Kozlowski (2):
regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature
regulator: richtek,rt4801: use existing ena_gpiod feature
.../regulator/richtek,rt4801-regulator.yaml | 14 +++-
drivers/regulator/rt4801-regulator.c | 68 ++++++++++++++++---
2 files changed, 71 insertions(+), 11 deletions(-)
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature
2022-04-23 18:14 [PATCH v2 0/2] regulator: richtek,rt4801: use existing ena_gpiod feature Krzysztof Kozlowski
@ 2022-04-23 18:14 ` Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 2/2] regulator: " Krzysztof Kozlowski
1 sibling, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-23 18:14 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
ChiYuan Huang, linux-kernel, devicetree
Cc: Krzysztof Kozlowski, Rob Herring
The binding and driver duplicated regulator core feature of controlling
regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own
enable-gpios property with multiple GPIOs.
This is a less preferred way, because enable-gpios should enable only one
element, not multiple. It also duplicates existing solution.
Deprecate the original 'enable-gpios' and add per-regulator property.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
---
.../regulator/richtek,rt4801-regulator.yaml | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.yaml b/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.yaml
index 4a4dfa7d9d09..091150c4e579 100644
--- a/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.yaml
+++ b/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.yaml
@@ -32,8 +32,11 @@ properties:
If only one gpio is specified, only one gpio used to control ENP/ENM.
Else if both are specified, DSVP/DSVN could be controlled individually.
If this property not specified, treat both as always-on regulators.
+
+ Property is deprecated. Use enable-gpios in each regulator.
minItems: 1
maxItems: 2
+ deprecated: true
patternProperties:
"^DSV(P|N)$":
@@ -42,6 +45,14 @@ patternProperties:
description:
Properties for single display bias regulator.
+ properties:
+ enable-gpios:
+ description:
+ GPIO to use to enable DSVP/DSVN regulator. One GPIO can be configured
+ for controlling both regulators. If this property not specified for
+ any regulator, treat both as always-on regulators.
+ maxItems: 1
+
required:
- compatible
- reg
@@ -57,19 +68,20 @@ examples:
rt4801@73 {
compatible = "richtek,rt4801";
reg = <0x73>;
- enable-gpios = <&gpio26 2 0>, <&gpio26 3 0>;
dsvp: DSVP {
regulator-name = "rt4801,dsvp";
regulator-min-microvolt = <4000000>;
regulator-max-microvolt = <6000000>;
regulator-boot-on;
+ enable-gpios = <&gpio26 2 0>;
};
dsvn: DSVN {
regulator-name = "rt4801,dsvn";
regulator-min-microvolt = <4000000>;
regulator-max-microvolt = <6000000>;
regulator-boot-on;
+ enable-gpios = <&gpio26 3 0>;
};
};
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] regulator: richtek,rt4801: use existing ena_gpiod feature
2022-04-23 18:14 [PATCH v2 0/2] regulator: richtek,rt4801: use existing ena_gpiod feature Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 1/2] regulator: dt-bindings: " Krzysztof Kozlowski
@ 2022-04-23 18:14 ` Krzysztof Kozlowski
2022-04-25 5:49 ` ChiYuan Huang
1 sibling, 1 reply; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-23 18:14 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
ChiYuan Huang, linux-kernel, devicetree
Cc: Krzysztof Kozlowski
The driver duplicated regulator core feature of controlling
regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own
enable-gpios property with multiple GPIOs.
The core already does it. Keep old method for backwards compatibility.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/regulator/rt4801-regulator.c | 68 ++++++++++++++++++++++++----
1 file changed, 58 insertions(+), 10 deletions(-)
diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c
index 7a87788d3f09..22efe44cd3a0 100644
--- a/drivers/regulator/rt4801-regulator.c
+++ b/drivers/regulator/rt4801-regulator.c
@@ -29,17 +29,71 @@
struct rt4801_priv {
struct device *dev;
+ /*
+ * Driver supports enable GPIOs in two ways:
+ * 1. Legacy enable-gpios property with multiple entries and enable
+ * control handled by the driver.
+ * 2. Per-regulator enable-gpios property with enable control handled by
+ * the regulator core.
+ *
+ * The enable_gpios and enable_flag properties are for the (1) case.
+ */
struct gpio_descs *enable_gpios;
unsigned int enable_flag;
unsigned int volt_sel[DSV_OUT_MAX];
};
+static int rt4801_of_parse_cb(struct device_node *np,
+ const struct regulator_desc *desc,
+ struct regulator_config *config)
+{
+ struct rt4801_priv *priv = config->driver_data;
+
+ if (priv->enable_gpios) {
+ dev_warn(priv->dev, "duplicated enable-gpios property\n");
+ return 0;
+ }
+ config->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np),
+ "enable-gpios",
+ 0,
+ GPIOD_OUT_HIGH |
+ GPIOD_FLAGS_BIT_NONEXCLUSIVE,
+ "rt4801");
+ if (IS_ERR(config->ena_gpiod))
+ config->ena_gpiod = NULL;
+
+ return 0;
+}
+
+/*
+ * regulator_ops->is_enabled() implementation
+ */
+static int rt4801_is_enabled(struct regulator_dev *rdev)
+{
+ struct rt4801_priv *priv = rdev_get_drvdata(rdev);
+ int id = rdev_get_id(rdev);
+
+ return !!(priv->enable_flag & BIT(id));
+}
+
+/*
+ * Internally used only is_enabled() implementation using also ena_pin from
+ * regulator core.
+ */
+static bool rt4801_is_enabled_ena_pin(struct regulator_dev *rdev)
+{
+ if (rdev->ena_pin)
+ return rdev->ena_gpio_state;
+
+ return rt4801_is_enabled(rdev);
+}
+
static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
{
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev), ret;
- if (priv->enable_flag & BIT(id)) {
+ if (rt4801_is_enabled_ena_pin(rdev)) {
ret = regulator_set_voltage_sel_regmap(rdev, selector);
if (ret)
return ret;
@@ -54,7 +108,7 @@ static int rt4801_get_voltage_sel(struct regulator_dev *rdev)
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
- if (priv->enable_flag & BIT(id))
+ if (rt4801_is_enabled_ena_pin(rdev))
return regulator_get_voltage_sel_regmap(rdev);
return priv->volt_sel[id];
@@ -100,14 +154,6 @@ static int rt4801_disable(struct regulator_dev *rdev)
return 0;
}
-static int rt4801_is_enabled(struct regulator_dev *rdev)
-{
- struct rt4801_priv *priv = rdev_get_drvdata(rdev);
- int id = rdev_get_id(rdev);
-
- return !!(priv->enable_flag & BIT(id));
-}
-
static const struct regulator_ops rt4801_regulator_ops = {
.list_voltage = regulator_list_voltage_linear,
.set_voltage_sel = rt4801_set_voltage_sel,
@@ -122,6 +168,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
.name = "DSVP",
.ops = &rt4801_regulator_ops,
.of_match = of_match_ptr("DSVP"),
+ .of_parse_cb = rt4801_of_parse_cb,
.type = REGULATOR_VOLTAGE,
.id = DSV_OUT_POS,
.min_uV = MIN_UV,
@@ -135,6 +182,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
.name = "DSVN",
.ops = &rt4801_regulator_ops,
.of_match = of_match_ptr("DSVN"),
+ .of_parse_cb = rt4801_of_parse_cb,
.type = REGULATOR_VOLTAGE,
.id = DSV_OUT_NEG,
.min_uV = MIN_UV,
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] regulator: richtek,rt4801: use existing ena_gpiod feature
2022-04-23 18:14 ` [PATCH v2 2/2] regulator: " Krzysztof Kozlowski
@ 2022-04-25 5:49 ` ChiYuan Huang
2022-04-25 6:40 ` Krzysztof Kozlowski
0 siblings, 1 reply; 5+ messages in thread
From: ChiYuan Huang @ 2022-04-25 5:49 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
ChiYuan Huang, linux-kernel, devicetree
On Sat, Apr 23, 2022 at 08:14:19PM +0200, Krzysztof Kozlowski wrote:
> The driver duplicated regulator core feature of controlling
> regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own
> enable-gpios property with multiple GPIOs.
>
> The core already does it. Keep old method for backwards compatibility.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> drivers/regulator/rt4801-regulator.c | 68 ++++++++++++++++++++++++----
> 1 file changed, 58 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c
> index 7a87788d3f09..22efe44cd3a0 100644
> --- a/drivers/regulator/rt4801-regulator.c
> +++ b/drivers/regulator/rt4801-regulator.c
> @@ -29,17 +29,71 @@
>
> struct rt4801_priv {
> struct device *dev;
> + /*
> + * Driver supports enable GPIOs in two ways:
> + * 1. Legacy enable-gpios property with multiple entries and enable
> + * control handled by the driver.
> + * 2. Per-regulator enable-gpios property with enable control handled by
> + * the regulator core.
> + *
> + * The enable_gpios and enable_flag properties are for the (1) case.
> + */
> struct gpio_descs *enable_gpios;
> unsigned int enable_flag;
> unsigned int volt_sel[DSV_OUT_MAX];
> };
>
> +static int rt4801_of_parse_cb(struct device_node *np,
> + const struct regulator_desc *desc,
> + struct regulator_config *config)
> +{
> + struct rt4801_priv *priv = config->driver_data;
> +
> + if (priv->enable_gpios) {
> + dev_warn(priv->dev, "duplicated enable-gpios property\n");
> + return 0;
> + }
> + config->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np),
> + "enable-gpios",
'enable' only, gpiod API will automatically concat it to 'enable-gpios'.
> + 0,
> + GPIOD_OUT_HIGH |
> + GPIOD_FLAGS_BIT_NONEXCLUSIVE,
> + "rt4801");
> + if (IS_ERR(config->ena_gpiod))
> + config->ena_gpiod = NULL;
> +
> + return 0;
> +}
> +
> +/*
> + * regulator_ops->is_enabled() implementation
> + */
> +static int rt4801_is_enabled(struct regulator_dev *rdev)
> +{
> + struct rt4801_priv *priv = rdev_get_drvdata(rdev);
> + int id = rdev_get_id(rdev);
> +
> + return !!(priv->enable_flag & BIT(id));
> +}
> +
> +/*
> + * Internally used only is_enabled() implementation using also ena_pin from
> + * regulator core.
> + */
> +static bool rt4801_is_enabled_ena_pin(struct regulator_dev *rdev)
> +{
> + if (rdev->ena_pin)
> + return rdev->ena_gpio_state;
> +
> + return rt4801_is_enabled(rdev);
> +}
> +
> static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
> {
> struct rt4801_priv *priv = rdev_get_drvdata(rdev);
> int id = rdev_get_id(rdev), ret;
>
> - if (priv->enable_flag & BIT(id)) {
> + if (rt4801_is_enabled_ena_pin(rdev)) {
> ret = regulator_set_voltage_sel_regmap(rdev, selector);
> if (ret)
> return ret;
> @@ -54,7 +108,7 @@ static int rt4801_get_voltage_sel(struct regulator_dev *rdev)
> struct rt4801_priv *priv = rdev_get_drvdata(rdev);
> int id = rdev_get_id(rdev);
>
> - if (priv->enable_flag & BIT(id))
> + if (rt4801_is_enabled_ena_pin(rdev))
> return regulator_get_voltage_sel_regmap(rdev);
>
> return priv->volt_sel[id];
> @@ -100,14 +154,6 @@ static int rt4801_disable(struct regulator_dev *rdev)
> return 0;
> }
>
> -static int rt4801_is_enabled(struct regulator_dev *rdev)
> -{
> - struct rt4801_priv *priv = rdev_get_drvdata(rdev);
> - int id = rdev_get_id(rdev);
> -
> - return !!(priv->enable_flag & BIT(id));
> -}
> -
> static const struct regulator_ops rt4801_regulator_ops = {
> .list_voltage = regulator_list_voltage_linear,
> .set_voltage_sel = rt4801_set_voltage_sel,
> @@ -122,6 +168,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
> .name = "DSVP",
> .ops = &rt4801_regulator_ops,
> .of_match = of_match_ptr("DSVP"),
> + .of_parse_cb = rt4801_of_parse_cb,
> .type = REGULATOR_VOLTAGE,
> .id = DSV_OUT_POS,
> .min_uV = MIN_UV,
> @@ -135,6 +182,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
> .name = "DSVN",
> .ops = &rt4801_regulator_ops,
> .of_match = of_match_ptr("DSVN"),
> + .of_parse_cb = rt4801_of_parse_cb,
> .type = REGULATOR_VOLTAGE,
> .id = DSV_OUT_NEG,
> .min_uV = MIN_UV,
There's one problem.
If 'ena_gpiod' is specified, it cannot be conexisted with ops
'enable/disable/is_enabled' by regulator framework.
It will cause no one to recover the voltage back.
You can check the original 'enable' ops.
How about to only parse gpio in 'of_parse_cb' and put it all into the
driver data, not to use regulator framework 'ena_gpiod'?
Best regards,
ChiYuan Huang.
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] regulator: richtek,rt4801: use existing ena_gpiod feature
2022-04-25 5:49 ` ChiYuan Huang
@ 2022-04-25 6:40 ` Krzysztof Kozlowski
0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-25 6:40 UTC (permalink / raw)
To: ChiYuan Huang
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
ChiYuan Huang, linux-kernel, devicetree
On 25/04/2022 07:49, ChiYuan Huang wrote:
>> +static int rt4801_of_parse_cb(struct device_node *np,
>> + const struct regulator_desc *desc,
>> + struct regulator_config *config)
>> +{
>> + struct rt4801_priv *priv = config->driver_data;
>> +
>> + if (priv->enable_gpios) {
>> + dev_warn(priv->dev, "duplicated enable-gpios property\n");
>> + return 0;
>> + }
>> + config->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np),
>> + "enable-gpios",
> 'enable' only, gpiod API will automatically concat it to 'enable-gpios'.
Right.
>> + 0,
>> + GPIOD_OUT_HIGH |
>> + GPIOD_FLAGS_BIT_NONEXCLUSIVE,
>> + "rt4801");
(...)
>> static const struct regulator_ops rt4801_regulator_ops = {
>> .list_voltage = regulator_list_voltage_linear,
>> .set_voltage_sel = rt4801_set_voltage_sel,
>> @@ -122,6 +168,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
>> .name = "DSVP",
>> .ops = &rt4801_regulator_ops,
>> .of_match = of_match_ptr("DSVP"),
>> + .of_parse_cb = rt4801_of_parse_cb,
>> .type = REGULATOR_VOLTAGE,
>> .id = DSV_OUT_POS,
>> .min_uV = MIN_UV,
>> @@ -135,6 +182,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
>> .name = "DSVN",
>> .ops = &rt4801_regulator_ops,
>> .of_match = of_match_ptr("DSVN"),
>> + .of_parse_cb = rt4801_of_parse_cb,
>> .type = REGULATOR_VOLTAGE,
>> .id = DSV_OUT_NEG,
>> .min_uV = MIN_UV,
>
> There's one problem.
> If 'ena_gpiod' is specified, it cannot be conexisted with ops
> 'enable/disable/is_enabled' by regulator framework.
> It will cause no one to recover the voltage back.
> You can check the original 'enable' ops.
You mean that regulator voltage is being reset after disabling it?
>
> How about to only parse gpio in 'of_parse_cb' and put it all into the
> driver data, not to use regulator framework 'ena_gpiod'?
In such case that's the only option. Thanks for the review.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-25 6:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23 18:14 [PATCH v2 0/2] regulator: richtek,rt4801: use existing ena_gpiod feature Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 1/2] regulator: dt-bindings: " Krzysztof Kozlowski
2022-04-23 18:14 ` [PATCH v2 2/2] regulator: " Krzysztof Kozlowski
2022-04-25 5:49 ` ChiYuan Huang
2022-04-25 6:40 ` Krzysztof Kozlowski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.