* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
@ 2012-10-15 13:16 Lee Jones
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
2012-10-16 5:14 ` [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Mark Brown
0 siblings, 2 replies; 13+ messages in thread
From: Lee Jones @ 2012-10-15 13:16 UTC (permalink / raw)
To: linux-arm-kernel
Here we provide the GPIO Regulator driver with Device Tree capability, so
that when a platform is booting with DT instead of platform data we can
still make full use of it.
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/regulator/gpio-regulator.c | 94 ++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 8b5944f..e467d0a 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -28,9 +28,12 @@
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
#include <linux/regulator/gpio-regulator.h>
#include <linux/gpio.h>
#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
struct gpio_regulator_data {
struct regulator_desc desc;
@@ -129,6 +132,84 @@ static struct regulator_ops gpio_regulator_voltage_ops = {
.list_voltage = gpio_regulator_list_voltage,
};
+struct gpio_regulator_config *
+of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
+{
+ struct gpio_regulator_config *config;
+ struct property *prop;
+ const char *regtype;
+ int proplen, gpio, i;
+
+ config = devm_kzalloc(dev,
+ sizeof(struct gpio_regulator_config),
+ GFP_KERNEL);
+ if (!config)
+ return ERR_PTR(-ENOMEM);
+
+ config->init_data = of_get_regulator_init_data(dev, np);
+ if (!config->init_data)
+ return ERR_PTR(-EINVAL);
+
+ config->supply_name = config->init_data->constraints.name;
+
+ if (of_property_read_bool(np, "enable-active-high"))
+ config->enable_high = true;
+
+ if (of_property_read_bool(np, "enable-at-boot"))
+ config->enabled_at_boot = true;
+
+ of_property_read_u32(np, "startup-delay-us", &config->startup_delay);
+
+ config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
+
+ /* Fetch GPIOs. */
+ for (i = 0; ; i++)
+ if (of_get_named_gpio(np, "gpios", i) < 0)
+ break;
+ config->nr_gpios = i;
+
+ config->gpios = devm_kzalloc(dev,
+ sizeof(struct gpio) * config->nr_gpios,
+ GFP_KERNEL);
+ if (!config->gpios)
+ return ERR_PTR(-ENOMEM);
+
+ for (i = 0; config->nr_gpios; i++) {
+ gpio = of_get_named_gpio(np, "gpios", i);
+ if (gpio < 0)
+ break;
+ config->gpios[i].gpio = gpio;
+ }
+
+ /* Fetch states. */
+ prop = of_find_property(np, "states", NULL);
+ proplen = prop->length / sizeof(int);
+
+ config->states = devm_kzalloc(dev,
+ sizeof(struct gpio_regulator_state)
+ * (proplen / 2),
+ GFP_KERNEL);
+ if (!config->states)
+ return ERR_PTR(-ENOMEM);
+
+ for (i = 0; i < proplen / 2; i++) {
+ config->states[i].value =
+ be32_to_cpup((int *)prop->value + (i * 2));
+ config->states[i].gpios =
+ be32_to_cpup((int *)prop->value + (i * 2 + 1));
+ }
+ config->nr_states = i;
+
+ of_property_read_string(np, "regulator-type", ®type);
+
+ if (!strncmp("voltage", regtype, 7))
+ config->type = REGULATOR_VOLTAGE;
+ else if (!strncmp("current", regtype, 7))
+ config->type = REGULATOR_CURRENT;
+
+ return config;
+}
+
static struct regulator_ops gpio_regulator_current_ops = {
.get_current_limit = gpio_regulator_get_value,
.set_current_limit = gpio_regulator_set_current_limit,
@@ -137,10 +218,17 @@ static struct regulator_ops gpio_regulator_current_ops = {
static int __devinit gpio_regulator_probe(struct platform_device *pdev)
{
struct gpio_regulator_config *config = pdev->dev.platform_data;
+ struct device_node *np = pdev->dev.of_node;
struct gpio_regulator_data *drvdata;
struct regulator_config cfg = { };
int ptr, ret, state;
+ if (np) {
+ config = of_get_gpio_regulator_config(&pdev->dev, np);
+ if (IS_ERR(config))
+ return PTR_ERR(config);
+ }
+
drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data),
GFP_KERNEL);
if (drvdata == NULL) {
@@ -270,12 +358,18 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id regulator_gpio_of_match[] __devinitconst = {
+ { .compatible = "regulator-gpio", },
+ {},
+};
+
static struct platform_driver gpio_regulator_driver = {
.probe = gpio_regulator_probe,
.remove = __devexit_p(gpio_regulator_remove),
.driver = {
.name = "gpio-regulator",
.owner = THIS_MODULE,
+ .of_match_table = regulator_gpio_of_match,
},
};
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver
2012-10-15 13:16 [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Lee Jones
@ 2012-10-15 13:17 ` Lee Jones
2012-10-15 14:10 ` Arnd Bergmann
` (2 more replies)
2012-10-16 5:14 ` [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Mark Brown
1 sibling, 3 replies; 13+ messages in thread
From: Lee Jones @ 2012-10-15 13:17 UTC (permalink / raw)
To: linux-arm-kernel
Here we specify all non-standard bindings which can be used when
requesting the use of an GPIO controlled regulator from Device Tree.
Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
.../bindings/regulator/gpio-regulator.txt | 25 ++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 Documentation/devicetree/bindings/regulator/gpio-regulator.txt
diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
new file mode 100644
index 0000000..5f77ee0
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
@@ -0,0 +1,25 @@
+GPIO controlled regulators
+
+Required properties:
+- compatible : Must be "regulator-gpio".
+
+Optional properties:
+- gpio-enable : GPIO to use to enable/disable the regulator.
+- startup-delay-us : Startup time in microseconds.
+- enable-active-high : Polarity of GPIO is active high (default is low).
+
+Any property defined as part of the core regulator binding defined in
+regulator.txt can also be used.
+
+Example:
+
+ mmciv: gpio-regulator {
+ compatible = "regulator-gpio";
+ regulator-name = "mmci-gpio-supply";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <2600000>;
+ gpio = <&gpio0 24 0x4>;
+ startup-delay-us = <100000>;
+ enable-active-high;
+ regulator-boot-on;
+ };
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
@ 2012-10-15 14:10 ` Arnd Bergmann
2012-10-15 14:58 ` Lee Jones
2012-10-23 9:45 ` Mark Brown
2 siblings, 0 replies; 13+ messages in thread
From: Arnd Bergmann @ 2012-10-15 14:10 UTC (permalink / raw)
To: linux-arm-kernel
On Monday 15 October 2012, Lee Jones wrote:
> diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
> new file mode 100644
> index 0000000..5f77ee0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
> @@ -0,0 +1,25 @@
> +GPIO controlled regulators
> +
> +Required properties:
> +- compatible : Must be "regulator-gpio".
> +
> +Optional properties:
> +- gpio-enable : GPIO to use to enable/disable the regulator.
> +- startup-delay-us : Startup time in microseconds.
> +- enable-active-high : Polarity of GPIO is active high (default is low).
> +
> +Any property defined as part of the core regulator binding defined in
> +regulator.txt can also be used.
> +
> +Example:
> +
> + mmciv: gpio-regulator {
> + compatible = "regulator-gpio";
> + regulator-name = "mmci-gpio-supply";
> + regulator-min-microvolt = <1800000>;
> + regulator-max-microvolt = <2600000>;
> + gpio = <&gpio0 24 0x4>;
> + startup-delay-us = <100000>;
> + enable-active-high;
> + regulator-boot-on;
> + };
The example doesn't match the documentation for the name of the gpio property
("gpio" vs. "gpio-enable"). I think the convention is to use "gpios".
Shouldn't this property be mandatory? I think there is little point in
defining a gpio-regulator without a gpio line attached to it.
Finally, the "enable-active-high" looks redundant, as that is something
that is normally encoded in the "gpios" property.
Arnd
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
2012-10-15 14:10 ` Arnd Bergmann
@ 2012-10-15 14:58 ` Lee Jones
2012-10-23 9:45 ` Mark Brown
2 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2012-10-15 14:58 UTC (permalink / raw)
To: linux-arm-kernel
Author: Lee Jones <lee.jones@linaro.org>
Date: Mon Oct 15 13:12:08 2012 +0100
Documentation: Describe Device Tree bindings for GPIO Regulator driver
Here we specify all non-standard bindings which can be used when
requesting the use of an GPIO controlled regulator from Device Tree.
Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
new file mode 100644
index 0000000..a7cdb6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
@@ -0,0 +1,36 @@
+GPIO controlled regulators
+
+Required properties:
+- compatible : Must be "regulator-gpio".
+
+Optional properties:
+- gpio-enable : GPIO to use to enable/disable the regulator.
+- gpios : GPIO group used to control voltage.
+- states : Selection of available voltages and GPIO configs.
+- startup-delay-us : Startup time in microseconds.
+- enable-active-high : Polarity of GPIO is active high (default is low).
+
+Any property defined as part of the core regulator binding defined in
+regulator.txt can also be used.
+
+Example:
+
+ mmciv: gpio-regulator {
+ compatible = "regulator-gpio";
+
+ regulator-name = "mmci-gpio-supply";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <2600000>;
+
+ gpio-enable = <&gpio0 23 0x4
+ gpios = <&gpio0 24 0x4
+ &gpio0 25 0x4>;
+ states = <1800000 0x3
+ 2200000 0x2
+ 2600000 0x1
+ 2900000 0x0>;
+
+ startup-delay-us = <100000>;
+ enable-active-high;
+ regulator-boot-on;
+ };
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-15 13:16 [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Lee Jones
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
@ 2012-10-16 5:14 ` Mark Brown
2012-10-16 7:29 ` Lee Jones
1 sibling, 1 reply; 13+ messages in thread
From: Mark Brown @ 2012-10-16 5:14 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 15, 2012 at 02:16:59PM +0100, Lee Jones wrote:
> Here we provide the GPIO Regulator driver with Device Tree capability, so
> that when a platform is booting with DT instead of platform data we can
> still make full use of it.
Not looked at the patch yet but patch 2 doesn't seem to have appeared?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-16 5:14 ` [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Mark Brown
@ 2012-10-16 7:29 ` Lee Jones
2012-10-16 7:46 ` Mark Brown
0 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2012-10-16 7:29 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, 16 Oct 2012, Mark Brown wrote:
> On Mon, Oct 15, 2012 at 02:16:59PM +0100, Lee Jones wrote:
> > Here we provide the GPIO Regulator driver with Device Tree capability, so
> > that when a platform is booting with DT instead of platform data we can
> > still make full use of it.
>
> Not looked at the patch yet but patch 2 doesn't seem to have appeared?
Has it arrived yet?
Arnd responded to it, so it hit the list.
Since Arnd's comments I've also fired v2 up - do you see it/them?
--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-16 7:29 ` Lee Jones
@ 2012-10-16 7:46 ` Mark Brown
2012-10-16 8:01 ` Lee Jones
0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2012-10-16 7:46 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Oct 16, 2012 at 08:29:56AM +0100, Lee Jones wrote:
> On Tue, 16 Oct 2012, Mark Brown wrote:
> > Not looked at the patch yet but patch 2 doesn't seem to have appeared?
> Has it arrived yet?
> Arnd responded to it, so it hit the list.
> Since Arnd's comments I've also fired v2 up - do you see it/them?
Not in my inbox, I'm not looking at the list right now.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-16 7:46 ` Mark Brown
@ 2012-10-16 8:01 ` Lee Jones
2012-10-17 7:41 ` Mark Brown
0 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2012-10-16 8:01 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, 16 Oct 2012, Mark Brown wrote:
> On Tue, Oct 16, 2012 at 08:29:56AM +0100, Lee Jones wrote:
> > On Tue, 16 Oct 2012, Mark Brown wrote:
>
> > > Not looked at the patch yet but patch 2 doesn't seem to have appeared?
>
> > Has it arrived yet?
>
> > Arnd responded to it, so it hit the list.
>
> > Since Arnd's comments I've also fired v2 up - do you see it/them?
>
> Not in my inbox, I'm not looking at the list right now.
Strange, both emails had you in CC.
I'm assuming it's just the documentation patch you're missing.
Let me resend it as a single patch.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-16 8:01 ` Lee Jones
@ 2012-10-17 7:41 ` Mark Brown
2012-10-22 9:13 ` Lee Jones
0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2012-10-17 7:41 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Oct 16, 2012 at 09:01:09AM +0100, Lee Jones wrote:
> I'm assuming it's just the documentation patch you're missing.
> Let me resend it as a single patch.
This should really be part of the patch adding the bindings...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121017/1d91450f/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-17 7:41 ` Mark Brown
@ 2012-10-22 9:13 ` Lee Jones
2012-10-22 9:44 ` Mark Brown
0 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2012-10-22 9:13 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, 17 Oct 2012, Mark Brown wrote:
> On Tue, Oct 16, 2012 at 09:01:09AM +0100, Lee Jones wrote:
>
> > I'm assuming it's just the documentation patch you're missing.
>
> > Let me resend it as a single patch.
>
> This should really be part of the patch adding the bindings...
Would you like me to send the patch-set again?
--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT
2012-10-22 9:13 ` Lee Jones
@ 2012-10-22 9:44 ` Mark Brown
0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2012-10-22 9:44 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 22, 2012 at 10:13:55AM +0100, Lee Jones wrote:
> On Wed, 17 Oct 2012, Mark Brown wrote:
> > This should really be part of the patch adding the bindings...
> Would you like me to send the patch-set again?
When I said I'd applied the patch that was what I meant.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121022/f75a7fe2/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
2012-10-15 14:10 ` Arnd Bergmann
2012-10-15 14:58 ` Lee Jones
@ 2012-10-23 9:45 ` Mark Brown
2012-10-23 9:55 ` Lee Jones
2 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2012-10-23 9:45 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 15, 2012 at 02:17:00PM +0100, Lee Jones wrote:
> Here we specify all non-standard bindings which can be used when
> requesting the use of an GPIO controlled regulator from Device Tree.
>
> Mark Brown <broonie@opensource.wolfsonmicro.com>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
The reason I didn't get this patch is that you didn't CC me on it...
notice what you've done above.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver
2012-10-23 9:45 ` Mark Brown
@ 2012-10-23 9:55 ` Lee Jones
0 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2012-10-23 9:55 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, 23 Oct 2012, Mark Brown wrote:
> On Mon, Oct 15, 2012 at 02:17:00PM +0100, Lee Jones wrote:
> > Here we specify all non-standard bindings which can be used when
> > requesting the use of an GPIO controlled regulator from Device Tree.
> >
> > Mark Brown <broonie@opensource.wolfsonmicro.com>
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
>
> The reason I didn't get this patch is that you didn't CC me on it...
> notice what you've done above.
Yes, I saw it and corrected it in the end, hence why you received
it when I resent - my bad.
--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2012-10-23 9:55 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15 13:16 [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Lee Jones
2012-10-15 13:17 ` [PATCH 2/2] Documentation: Describe Device Tree bindings for GPIO Regulator driver Lee Jones
2012-10-15 14:10 ` Arnd Bergmann
2012-10-15 14:58 ` Lee Jones
2012-10-23 9:45 ` Mark Brown
2012-10-23 9:55 ` Lee Jones
2012-10-16 5:14 ` [PATCH 1/2] regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT Mark Brown
2012-10-16 7:29 ` Lee Jones
2012-10-16 7:46 ` Mark Brown
2012-10-16 8:01 ` Lee Jones
2012-10-17 7:41 ` Mark Brown
2012-10-22 9:13 ` Lee Jones
2012-10-22 9:44 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).