[PATCH 1/3] regulator-core: support multiple enable GPIO

From: Kim, Milo
Date: Thu Jan 10 2013 - 04:46:27 EST


This patch fixes a limitation in case of multiple enable pin usages.
Several regulators can be enabled/disabled at the same time by one
shared GPIO pin.
If specific GPIO pin is already used, then skip requesting the GPIO.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@xxxxxx>
---
drivers/regulator/core.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index de47880..21b4247 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1456,6 +1456,23 @@ void devm_regulator_put(struct regulator *regulator)
}
EXPORT_SYMBOL_GPL(devm_regulator_put);

+static int regulator_enable_gpio_request(struct regulator_dev *rdev,
+ const struct regulator_config *config)
+{
+ struct regulator_dev *r;
+ int gpio = config->ena_gpio;
+
+ list_for_each_entry(r, &regulator_list, list) {
+ if (r->ena_gpio == gpio) {
+ rdev_info(rdev, "GPIO %d is already used\n", gpio);
+ return 0;
+ }
+ }
+
+ return gpio_request_one(gpio, GPIOF_DIR_OUT | config->ena_gpio_flags,
+ rdev_get_name(rdev));
+}
+
static int _regulator_do_enable(struct regulator_dev *rdev)
{
int ret, delay;
@@ -3420,9 +3437,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
dev_set_drvdata(&rdev->dev, rdev);

if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) {
- ret = gpio_request_one(config->ena_gpio,
- GPIOF_DIR_OUT | config->ena_gpio_flags,
- rdev_get_name(rdev));
+ ret = regulator_enable_gpio_request(rdev, config);
if (ret != 0) {
rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
config->ena_gpio, ret);
--
1.7.9.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/