linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Philipp Zabel <philipp.zabel@gmail.com>
Subject: [PATCH 03/21] regulator: gpio: Get enable GPIO using GPIO descriptor
Date: Mon, 12 Feb 2018 14:16:59 +0100	[thread overview]
Message-ID: <20180212131717.27193-4-linus.walleij@linaro.org> (raw)
In-Reply-To: <20180212131717.27193-1-linus.walleij@linaro.org>

We augment the GPIO regulator to get the *enable* regulator
GPIO line (not the other lines) using a descriptor rather than
a global number.

We then pass this into the regulator core which has been
prepared to hande enable descriptors in a separate patch.

Switch over the two boardfiles using this facility and clean
up so we only pass descriptors around.

Cc: Philipp Zabel <philipp.zabel@gmail.com> # HX4700/Magician maintainer
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/mach-pxa/hx4700.c               | 12 +++++++++++-
 arch/arm/mach-pxa/magician.c             | 11 ++++++++++-
 drivers/regulator/gpio-regulator.c       | 23 +++++++++++------------
 include/linux/regulator/gpio-regulator.h |  3 ---
 4 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c
index e2e7f247a645..6717a10180eb 100644
--- a/arch/arm/mach-pxa/hx4700.c
+++ b/arch/arm/mach-pxa/hx4700.c
@@ -20,6 +20,7 @@
 #include <linux/delay.h>
 #include <linux/fb.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 #include <linux/input/navpoint.h>
@@ -711,7 +712,6 @@ static struct gpio_regulator_state bq24022_states[] = {
 static struct gpio_regulator_config bq24022_info = {
 	.supply_name = "bq24022",
 
-	.enable_gpio = GPIO72_HX4700_BQ24022_nCHARGE_EN,
 	.enable_high = 0,
 	.enabled_at_boot = 0,
 
@@ -733,6 +733,15 @@ static struct platform_device bq24022 = {
 	},
 };
 
+static struct gpiod_lookup_table bq24022_gpiod_table = {
+	.dev_id = "gpio-regulator",
+	.table = {
+		GPIO_LOOKUP("gpio-pxa", GPIO72_HX4700_BQ24022_nCHARGE_EN,
+			    "enable", GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 /*
  * StrataFlash
  */
@@ -875,6 +884,7 @@ static void __init hx4700_init(void)
 	pxa_set_btuart_info(NULL);
 	pxa_set_stuart_info(NULL);
 
+	gpiod_add_lookup_table(&bq24022_gpiod_table);
 	platform_add_devices(devices, ARRAY_SIZE(devices));
 	pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup));
 
diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c
index 14c0f80bc9e7..9a5bda3ea194 100644
--- a/arch/arm/mach-pxa/magician.c
+++ b/arch/arm/mach-pxa/magician.c
@@ -657,7 +657,6 @@ static struct gpio_regulator_state bq24022_states[] = {
 static struct gpio_regulator_config bq24022_info = {
 	.supply_name		= "bq24022",
 
-	.enable_gpio		= GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
 	.enable_high		= 0,
 	.enabled_at_boot	= 1,
 
@@ -679,6 +678,15 @@ static struct platform_device bq24022 = {
 	},
 };
 
+static struct gpiod_lookup_table bq24022_gpiod_table = {
+	.dev_id = "gpio-regulator",
+	.table = {
+		GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
+			    "enable", GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 /*
  * fixed regulator for ads7846
  */
@@ -1007,6 +1015,7 @@ static void __init magician_init(void)
 	regulator_register_always_on(0, "power", pwm_backlight_supply,
 		ARRAY_SIZE(pwm_backlight_supply), 5000000);
 
+	gpiod_add_lookup_table(&bq24022_gpiod_table);
 	platform_add_devices(ARRAY_AND_SIZE(devices));
 }
 
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 0fce06acfaec..172ca4c578b2 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -31,6 +31,7 @@
 #include <linux/regulator/of_regulator.h>
 #include <linux/regulator/gpio-regulator.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/of_gpio.h>
@@ -161,10 +162,6 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
 
 	of_property_read_u32(np, "startup-delay-us", &config->startup_delay);
 
-	config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
-	if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT)
-		return ERR_PTR(config->enable_gpio);
-
 	/* Fetch GPIOs. - optional property*/
 	ret = of_gpio_count(np);
 	if ((ret < 0) && (ret != -ENOENT))
@@ -254,6 +251,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct gpio_regulator_data *drvdata;
 	struct regulator_config cfg = { };
+	enum gpiod_flags gflags;
 	int ptr, ret, state;
 
 	drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data),
@@ -340,21 +338,22 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 	cfg.driver_data = drvdata;
 	cfg.of_node = np;
 
-	if (gpio_is_valid(config->enable_gpio)) {
-		cfg.ena_gpio = config->enable_gpio;
-		cfg.ena_gpio_initialized = true;
-	}
 	cfg.ena_gpio_invert = !config->enable_high;
 	if (config->enabled_at_boot) {
 		if (config->enable_high)
-			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
+			gflags = GPIOD_OUT_HIGH;
 		else
-			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
+			gflags = GPIOD_OUT_LOW;
 	} else {
 		if (config->enable_high)
-			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
+			gflags = GPIOD_OUT_LOW;
 		else
-			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
+			gflags = GPIOD_OUT_HIGH;
+	}
+	cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags);
+	if (IS_ERR(cfg.ena_gpiod)) {
+		ret = PTR_ERR(cfg.ena_gpiod);
+		goto err_stategpio;
 	}
 
 	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h
index 19fbd267406d..536cab86f2d5 100644
--- a/include/linux/regulator/gpio-regulator.h
+++ b/include/linux/regulator/gpio-regulator.h
@@ -44,8 +44,6 @@ struct gpio_regulator_state {
 /**
  * struct gpio_regulator_config - config structure
  * @supply_name:	Name of the regulator supply
- * @enable_gpio:	GPIO to use for enable control
- *			set to -EINVAL if not used
  * @enable_high:	Polarity of enable GPIO
  *			1 = Active high, 0 = Active low
  * @enabled_at_boot:	Whether regulator has been enabled at
@@ -69,7 +67,6 @@ struct gpio_regulator_state {
 struct gpio_regulator_config {
 	const char *supply_name;
 
-	int enable_gpio;
 	unsigned enable_high:1;
 	unsigned enabled_at_boot:1;
 	unsigned startup_delay;
-- 
2.14.3

  parent reply	other threads:[~2018-02-12 13:17 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 13:16 [PATCH 00/21] regulator: switch core to GPIO descriptors Linus Walleij
2018-02-12 13:16 ` [PATCH 01/21] regulator: core: Support passing an initialized GPIO enable descriptor Linus Walleij
2018-02-16 17:12   ` Applied "regulator: core: Support passing an initialized GPIO enable descriptor" to the regulator tree Mark Brown
2018-02-12 13:16 ` [PATCH 02/21] regulator: fixed: Convert to use GPIO descriptor only Linus Walleij
2018-02-12 15:13   ` Andy Shevchenko
2018-04-19 12:36     ` Linus Walleij
2018-02-12 13:16 ` Linus Walleij [this message]
2018-05-29 14:59   ` Applied "regulator: gpio: Get enable GPIO using GPIO descriptor" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 04/21] regulator: da9055: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 14:59   ` Lee Jones
2018-02-16 17:12   ` Applied "regulator: da9055: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 05/21] regulator: arizona-ldo1: Look up a descriptor and pass to the core Linus Walleij
2018-02-13 11:06   ` Charles Keepax
2018-04-19 13:43     ` Linus Walleij
2018-04-19 15:02       ` Charles Keepax
2018-02-13 11:51   ` Charles Keepax
2018-02-12 13:17 ` [PATCH 06/21] regulator: da9211: Pass descriptors instead of GPIO numbers Linus Walleij
2018-02-16 17:12   ` Applied "regulator: da9211: Pass descriptors instead of GPIO numbers" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 07/21] regulator: max8973: Pass descriptor instead of GPIO number Linus Walleij
2018-05-24 19:14   ` Applied "regulator: max8973: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 08/21] regulator: max77686: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 13:37   ` Krzysztof Kozlowski
2018-02-12 13:17 ` [PATCH 09/21] regulator: lm363x: " Linus Walleij
2018-05-24 19:14   ` Applied "regulator: lm363x: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 10/21] regulator: lp8788-ldo: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 14:59   ` Lee Jones
2018-05-24 19:14   ` Applied "regulator: lp8788-ldo: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 11/21] regulator: max8952: Pass descriptor instead of GPIO number Linus Walleij
2018-05-24 19:14   ` Applied "regulator: max8952: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 12/21] regulator: pfuze100: Delete reference to ena_gpio Linus Walleij
2018-05-24 19:14   ` Applied "regulator: pfuze100: Delete reference to ena_gpio" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 13/21] regulator: s2mps11: Pass descriptor instead of GPIO number Linus Walleij
2018-05-17 16:41   ` Applied "regulator: s2mps11: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 14/21] regulator: s5m8767: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 14:58   ` Lee Jones
2018-05-24 19:13   ` Applied "regulator: s5m8767: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 15/21] regulator: tps65090: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 14:58   ` Lee Jones
2018-05-24 19:13   ` Applied "regulator: tps65090: Pass descriptor instead of GPIO number" to the regulator tree Mark Brown
2018-02-12 13:17 ` [PATCH 16/21] regulator: wm8994: Pass descriptor instead of GPIO number Linus Walleij
2018-02-12 14:58   ` Lee Jones
2018-02-13 11:11   ` Charles Keepax
2018-04-19 13:55     ` Linus Walleij
2018-04-19 14:05       ` Mark Brown
2018-04-19 15:01       ` [PATCH] ARM: s3c64xx: Tidy up handling of regulator GPIO lookups Charles Keepax
2018-05-14  5:54         ` Linus Walleij
2018-02-13 11:52   ` [PATCH 16/21] regulator: wm8994: Pass descriptor instead of GPIO number Charles Keepax
2018-02-12 13:17 ` [PATCH 17/21] regulator: core: Only support passing enable GPIO descriptors Linus Walleij
2018-02-12 13:17 ` [PATCH 18/21] regulator: fixed/gpio: Pull inversion/OD into gpiolib Linus Walleij
2018-02-17  9:59   ` Robert Jarzmik
2018-02-12 13:17 ` [PATCH 19/21] regulator: fixed/gpio: Update device tree bindings Linus Walleij
2018-02-19  2:41   ` Rob Herring
2018-02-12 13:17 ` [PATCH 20/21] regulator: gpio: Convert to fully use descriptors Linus Walleij
2018-02-12 13:17 ` [PATCH 21/21] regulator: gpio: Simplify probe path Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180212131717.27193-4-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philipp.zabel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).