Skip to content

Commit

Permalink
regulator: core: Only support passing enable GPIO descriptors
Browse files Browse the repository at this point in the history
Now that we changed all providers to pass descriptors into the core
for enable GPIOs instead of a global GPIO number, delete the support
for passing GPIO numbers in, and we get a cleanup and size reduction
in the core, and from a GPIO point of view we use the modern, cleaner
interface.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
linusw authored and broonie committed Feb 6, 2019
1 parent d162d04 commit 541d052
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
32 changes: 6 additions & 26 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <linux/mutex.h>
#include <linux/suspend.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/regmap.h>
Expand Down Expand Up @@ -2236,35 +2235,19 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
{
struct regulator_enable_gpio *pin;
struct gpio_desc *gpiod;
int ret;

if (config->ena_gpiod)
gpiod = config->ena_gpiod;
else
gpiod = gpio_to_desc(config->ena_gpio);
gpiod = config->ena_gpiod;

list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
if (pin->gpiod == gpiod) {
rdev_dbg(rdev, "GPIO %d is already used\n",
config->ena_gpio);
rdev_dbg(rdev, "GPIO is already used\n");
goto update_ena_gpio_to_rdev;
}
}

if (!config->ena_gpiod) {
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
if (ret)
return ret;
}

pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
if (pin == NULL) {
if (!config->ena_gpiod)
gpio_free(config->ena_gpio);
if (pin == NULL)
return -ENOMEM;
}

pin->gpiod = gpiod;
list_add(&pin->list, &regulator_ena_gpio_list);
Expand All @@ -2287,7 +2270,6 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
if (pin->gpiod == rdev->ena_pin->gpiod) {
if (pin->request_count <= 1) {
pin->request_count = 0;
gpiod_put(pin->gpiod);
list_del(&pin->list);
kfree(pin);
rdev->ena_pin = NULL;
Expand Down Expand Up @@ -4971,15 +4953,13 @@ regulator_register(const struct regulator_desc *regulator_desc,
goto clean;
}

if (config->ena_gpiod ||
((config->ena_gpio || config->ena_gpio_initialized) &&
gpio_is_valid(config->ena_gpio))) {
if (config->ena_gpiod) {
mutex_lock(&regulator_list_mutex);
ret = regulator_ena_gpio_request(rdev, config);
mutex_unlock(&regulator_list_mutex);
if (ret != 0) {
rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
config->ena_gpio, ret);
rdev_err(rdev, "Failed to request enable GPIO: %d\n",
ret);
goto clean;
}
/* The regulator core took over the GPIO descriptor */
Expand Down
12 changes: 1 addition & 11 deletions include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,7 @@ struct regulator_desc {
* NULL).
* @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
* insufficient.
* @ena_gpio_initialized: GPIO controlling regulator enable was properly
* initialized, meaning that >= 0 is a valid gpio
* identifier and < 0 is a non existent gpio.
* @ena_gpio: GPIO controlling regulator enable.
* @ena_gpiod: GPIO descriptor controlling regulator enable.
* @ena_gpio_invert: Sense for GPIO enable control.
* @ena_gpio_flags: Flags to use when calling gpio_request_one()
* @ena_gpiod: GPIO controlling regulator enable.
*/
struct regulator_config {
struct device *dev;
Expand All @@ -416,11 +410,7 @@ struct regulator_config {
struct device_node *of_node;
struct regmap *regmap;

bool ena_gpio_initialized;
int ena_gpio;
struct gpio_desc *ena_gpiod;
unsigned int ena_gpio_invert:1;
unsigned int ena_gpio_flags;
};

/*
Expand Down

0 comments on commit 541d052

Please sign in to comment.