diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2018-05-14 04:06:23 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-05-29 10:55:12 -0400 |
commit | 37bed97f00734ce329495823d9682181028b51e4 (patch) | |
tree | d320f47ce4a7a7c657cc87a79e3953a7928a9869 /drivers/regulator | |
parent | 6059577cb28d8b15d2b7dad51eb90d885f1ed9ab (diff) |
regulator: gpio: Get enable GPIO using GPIO descriptor
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>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index a86b8997bb54..9d6094c4d71c 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/regulator/of_regulator.h> | 31 | #include <linux/regulator/of_regulator.h> |
32 | #include <linux/regulator/gpio-regulator.h> | 32 | #include <linux/regulator/gpio-regulator.h> |
33 | #include <linux/gpio.h> | 33 | #include <linux/gpio.h> |
34 | #include <linux/gpio/consumer.h> | ||
34 | #include <linux/slab.h> | 35 | #include <linux/slab.h> |
35 | #include <linux/of.h> | 36 | #include <linux/of.h> |
36 | #include <linux/of_gpio.h> | 37 | #include <linux/of_gpio.h> |
@@ -161,10 +162,6 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, | |||
161 | 162 | ||
162 | of_property_read_u32(np, "startup-delay-us", &config->startup_delay); | 163 | of_property_read_u32(np, "startup-delay-us", &config->startup_delay); |
163 | 164 | ||
164 | config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); | ||
165 | if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) | ||
166 | return ERR_PTR(config->enable_gpio); | ||
167 | |||
168 | /* Fetch GPIOs. - optional property*/ | 165 | /* Fetch GPIOs. - optional property*/ |
169 | ret = of_gpio_count(np); | 166 | ret = of_gpio_count(np); |
170 | if ((ret < 0) && (ret != -ENOENT)) | 167 | if ((ret < 0) && (ret != -ENOENT)) |
@@ -255,6 +252,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
255 | struct device_node *np = pdev->dev.of_node; | 252 | struct device_node *np = pdev->dev.of_node; |
256 | struct gpio_regulator_data *drvdata; | 253 | struct gpio_regulator_data *drvdata; |
257 | struct regulator_config cfg = { }; | 254 | struct regulator_config cfg = { }; |
255 | enum gpiod_flags gflags; | ||
258 | int ptr, ret, state; | 256 | int ptr, ret, state; |
259 | 257 | ||
260 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), | 258 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), |
@@ -340,21 +338,22 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
340 | cfg.driver_data = drvdata; | 338 | cfg.driver_data = drvdata; |
341 | cfg.of_node = np; | 339 | cfg.of_node = np; |
342 | 340 | ||
343 | if (gpio_is_valid(config->enable_gpio)) { | ||
344 | cfg.ena_gpio = config->enable_gpio; | ||
345 | cfg.ena_gpio_initialized = true; | ||
346 | } | ||
347 | cfg.ena_gpio_invert = !config->enable_high; | 341 | cfg.ena_gpio_invert = !config->enable_high; |
348 | if (config->enabled_at_boot) { | 342 | if (config->enabled_at_boot) { |
349 | if (config->enable_high) | 343 | if (config->enable_high) |
350 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | 344 | gflags = GPIOD_OUT_HIGH; |
351 | else | 345 | else |
352 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | 346 | gflags = GPIOD_OUT_LOW; |
353 | } else { | 347 | } else { |
354 | if (config->enable_high) | 348 | if (config->enable_high) |
355 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | 349 | gflags = GPIOD_OUT_LOW; |
356 | else | 350 | else |
357 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | 351 | gflags = GPIOD_OUT_HIGH; |
352 | } | ||
353 | cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags); | ||
354 | if (IS_ERR(cfg.ena_gpiod)) { | ||
355 | ret = PTR_ERR(cfg.ena_gpiod); | ||
356 | goto err_stategpio; | ||
358 | } | 357 | } |
359 | 358 | ||
360 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); | 359 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); |