* [PATCH V1] regulator: da9211: fix unmatched of_node and add gpio control
@ 2015-01-15 1:29 James Ban
2015-01-15 11:21 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: James Ban @ 2015-01-15 1:29 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Support Opensource, LKML; +Cc: David Dajun Chen
This is a patch for fixing unmatched of_node and adding gpio control.
Signed-off-by: James Ban <james.ban.opensource@diasemi.com>
---
This patch is relative to linux-next repository tag next-20150113.
Changes in V1:
- fix unmatched of_node.
- add gpio control for buck eanble/disable.
.../devicetree/bindings/regulator/da9211.txt | 24 +++++++++-
drivers/regulator/da9211-regulator.c | 49 ++++++++++++++++++--
drivers/regulator/da9211-regulator.h | 1 +
include/linux/regulator/da9211.h | 9 ++++
4 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/regulator/da9211.txt b/Documentation/devicetree/bindings/regulator/da9211.txt
index 240019a..b53a246 100644
--- a/Documentation/devicetree/bindings/regulator/da9211.txt
+++ b/Documentation/devicetree/bindings/regulator/da9211.txt
@@ -11,6 +11,12 @@ Required properties:
BUCKA and BUCKB.
Optional properties:
+- bucka-uses-gpio: BUCKA can be controlled by gpio.
+- bucka-enable-platform-gpio: platform gpio for control of BUCKA.
+- bucka-enable-init-state: initial state of gpio for BUCKA
+- buckb-uses-gpio: BUCKB can be controlled by gpio.
+- buckb-enable-platform-gpio: platform gpio for control of BUCKB.
+- buckb-enable-init-state: initial state of gpio for BUCKB
- Any optional property defined in regulator.txt
Example 1) DA9211
@@ -20,6 +26,14 @@ Example 1) DA9211
reg = <0x68>;
interrupts = <3 27>;
+ bucka-uses-gpio;
+ bucka-enable-platform-gpio = <&gpio 27 0>;
+ bucka-enable-init-state = <0>;
+
+ buckb-uses-gpio;
+ buckb-enable-platform-gpio = <&gpio 17 0>;
+ buckb-enable-init-state = <0>;
+
regulators {
BUCKA {
regulator-name = "VBUCKA";
@@ -38,12 +52,20 @@ Example 1) DA9211
};
};
-Example 2) DA92113
+Example 2) DA9213
pmic: da9213@68 {
compatible = "dlg,da9213";
reg = <0x68>;
interrupts = <3 27>;
+ bucka-uses-gpio;
+ bucka-enable-platform-gpio = <&gpio 27 0>;
+ bucka-enable-init-state = <0>;
+
+ buckb-uses-gpio;
+ buckb-enable-platform-gpio = <&gpio 17 0>;
+ buckb-enable-init-state = <0>;
+
regulators {
BUCKA {
regulator-name = "VBUCKA";
diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c
index c78d210..2d9a38a 100644
--- a/drivers/regulator/da9211-regulator.c
+++ b/drivers/regulator/da9211-regulator.c
@@ -24,6 +24,7 @@
#include <linux/regmap.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
+#include <linux/of_gpio.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regulator/da9211.h>
#include "da9211-regulator.h"
@@ -248,7 +249,7 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
{
struct da9211_pdata *pdata;
struct device_node *node;
- int i, num, n;
+ int i, num, n, gpio;
node = of_get_child_by_name(dev->of_node, "regulators");
if (!node) {
@@ -276,10 +277,42 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
continue;
pdata->init_data[n] = da9211_matches[i].init_data;
-
+ pdata->reg_node[n] = da9211_matches[i].of_node;
n++;
}
+ if (of_get_property(dev->of_node, "bucka-uses-gpio", NULL)) {
+ gpio = of_get_named_gpio(dev->of_node,
+ "bucka-enable-platform-gpio", 0);
+ if (!gpio_is_valid(gpio)) {
+ dev_err(dev, "invalid gpio: %d\n", gpio);
+ return ERR_PTR(-EINVAL);
+ }
+ pdata->buck_data[0].gpio_ren = gpio;
+
+ if (of_property_read_u32(dev->of_node,
+ "bucka-enable-init-state",
+ &pdata->buck_data[0].ena_init_state)) {
+ pdata->buck_data[0].ena_init_state = 0;
+ }
+ }
+
+ if (of_get_property(dev->of_node, "buckb-uses-gpio", NULL)) {
+ gpio = of_get_named_gpio(dev->of_node,
+ "buckb-enable-platform-gpio", 0);
+ if (!gpio_is_valid(gpio)) {
+ dev_err(dev, "invalid gpio: %d\n", gpio);
+ return ERR_PTR(-EINVAL);
+ }
+ pdata->buck_data[1].gpio_ren = gpio;
+
+ if (of_property_read_u32(dev->of_node,
+ "buckb-enable-init-state",
+ &pdata->buck_data[1].ena_init_state)) {
+ pdata->buck_data[1].ena_init_state = 0;
+ }
+ }
+
return pdata;
}
#else
@@ -364,7 +397,17 @@ static int da9211_regulator_init(struct da9211 *chip)
config.dev = chip->dev;
config.driver_data = chip;
config.regmap = chip->regmap;
- config.of_node = chip->dev->of_node;
+ config.of_node = chip->pdata->reg_node[i];
+
+ if (chip->pdata->buck_data[i].gpio_ren) {
+ config.ena_gpio = chip->pdata->buck_data[i].gpio_ren;
+
+ if (chip->pdata->buck_data[i].ena_init_state == 0)
+ config.ena_gpio_flags = GPIOF_OUT_INIT_LOW;
+ else
+ config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
+ config.ena_gpio_invert = 0;
+ }
chip->rdev[i] = devm_regulator_register(chip->dev,
&da9211_regulators[i], &config);
diff --git a/drivers/regulator/da9211-regulator.h b/drivers/regulator/da9211-regulator.h
index 93fa9df..2a88190 100644
--- a/drivers/regulator/da9211-regulator.h
+++ b/drivers/regulator/da9211-regulator.h
@@ -182,6 +182,7 @@
#define DA9211_BUCKA_GPI_GPIO3 0x06
#define DA9211_BUCKA_PD_DIS 0x08
#define DA9211_VBUCKA_SEL 0x10
+#define DA9211_VBUCKA_SEL_MASK 0x10
#define DA9211_VBUCKA_SEL_A 0x00
#define DA9211_VBUCKA_SEL_B 0x10
#define DA9211_VBUCKA_GPI_SHIFT 5
diff --git a/include/linux/regulator/da9211.h b/include/linux/regulator/da9211.h
index 5479394..8748423 100644
--- a/include/linux/regulator/da9211.h
+++ b/include/linux/regulator/da9211.h
@@ -25,6 +25,13 @@ enum da9211_chip_id {
DA9213,
};
+struct da9211_buck_data {
+ /* gpio of platform for buck eanble/disable */
+ int gpio_ren;
+ /* init state of gpio_ren */
+ int ena_init_state;
+};
+
struct da9211_pdata {
/*
* Number of buck
@@ -32,6 +39,8 @@ struct da9211_pdata {
* 2 : 2 phase 2 buck
*/
int num_buck;
+ struct da9211_buck_data buck_data[DA9211_MAX_REGULATORS];
+ struct device_node *reg_node[DA9211_MAX_REGULATORS];
struct regulator_init_data *init_data[DA9211_MAX_REGULATORS];
};
#endif
--
end-of-patch for regulator: da9211: fix unmatched of_node and add gpio control V1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH V1] regulator: da9211: fix unmatched of_node and add gpio control
2015-01-15 1:29 [PATCH V1] regulator: da9211: fix unmatched of_node and add gpio control James Ban
@ 2015-01-15 11:21 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2015-01-15 11:21 UTC (permalink / raw)
To: James Ban; +Cc: Liam Girdwood, Support Opensource, LKML, David Dajun Chen
[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]
On Thu, Jan 15, 2015 at 10:29:08AM +0900, James Ban wrote:
> This is a patch for fixing unmatched of_node and adding gpio control.
That sounds like two separate changes to me...
> Optional properties:
> +- bucka-uses-gpio: BUCKA can be controlled by gpio.
> +- bucka-enable-platform-gpio: platform gpio for control of BUCKA.
> +- bucka-enable-init-state: initial state of gpio for BUCKA
Even for a single GPIO specifiers are usually called -gpios. It also
seems redundant to have the -uses property, if there is a GPIO specifier
for the enable then we can just assume it's supposed to be used without
the extra property.
> + bucka-uses-gpio;
> + bucka-enable-platform-gpio = <&gpio 27 0>;
> + bucka-enable-init-state = <0>;
> +
> + buckb-uses-gpio;
> + buckb-enable-platform-gpio = <&gpio 17 0>;
> + buckb-enable-init-state = <0>;
> +
> regulators {
> BUCKA {
> regulator-name = "VBUCKA";
Would it not be more natural to have the properties in the node for the
regulator (the recently added of_parse_cb will help with that)?
> + if (of_get_property(dev->of_node, "bucka-uses-gpio", NULL)) {
> + gpio = of_get_named_gpio(dev->of_node,
> + "bucka-enable-platform-gpio", 0);
> + if (!gpio_is_valid(gpio)) {
> + dev_err(dev, "invalid gpio: %d\n", gpio);
> + return ERR_PTR(-EINVAL);
> + }
This will be broken for deferred probe, it's better to pass through any
errors.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-15 11:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-15 1:29 [PATCH V1] regulator: da9211: fix unmatched of_node and add gpio control James Ban
2015-01-15 11:21 ` Mark Brown
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.