Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: core: Support passing an initialized GPIO enable descriptor

We are currently passing a GPIO number from the global GPIO numberspace
into the regulator core for handling enable GPIOs. This is not good
since it ties into the global GPIO numberspace and uses gpio_to_desc()
to overcome this.

Start supporting passing an already initialized GPIO descriptor to the
core instead: leaf drivers pick their descriptors, associated directly
with the device node (or from ACPI or from a board descriptor table)
and use that directly without any roundtrip over the global GPIO
numberspace.

This looks messy since it adds a bunch of extra code in the core, but
at the end of the patch series we will delete the handling of the GPIO
number and only deal with descriptors so things end up neat.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
e45e290a 7928b2cb

+19 -9
+16 -9
drivers/regulator/core.c
··· 1937 1937 struct gpio_desc *gpiod; 1938 1938 int ret; 1939 1939 1940 - gpiod = gpio_to_desc(config->ena_gpio); 1940 + if (config->ena_gpiod) 1941 + gpiod = config->ena_gpiod; 1942 + else 1943 + gpiod = gpio_to_desc(config->ena_gpio); 1941 1944 1942 1945 list_for_each_entry(pin, &regulator_ena_gpio_list, list) { 1943 1946 if (pin->gpiod == gpiod) { ··· 1950 1947 } 1951 1948 } 1952 1949 1953 - ret = gpio_request_one(config->ena_gpio, 1954 - GPIOF_DIR_OUT | config->ena_gpio_flags, 1955 - rdev_get_name(rdev)); 1956 - if (ret) 1957 - return ret; 1950 + if (!config->ena_gpiod) { 1951 + ret = gpio_request_one(config->ena_gpio, 1952 + GPIOF_DIR_OUT | config->ena_gpio_flags, 1953 + rdev_get_name(rdev)); 1954 + if (ret) 1955 + return ret; 1956 + } 1958 1957 1959 1958 pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); 1960 1959 if (pin == NULL) { 1961 - gpio_free(config->ena_gpio); 1960 + if (!config->ena_gpiod) 1961 + gpio_free(config->ena_gpio); 1962 1962 return -ENOMEM; 1963 1963 } 1964 1964 ··· 4160 4154 goto clean; 4161 4155 } 4162 4156 4163 - if ((config->ena_gpio || config->ena_gpio_initialized) && 4164 - gpio_is_valid(config->ena_gpio)) { 4157 + if (config->ena_gpiod || 4158 + ((config->ena_gpio || config->ena_gpio_initialized) && 4159 + gpio_is_valid(config->ena_gpio))) { 4165 4160 mutex_lock(&regulator_list_mutex); 4166 4161 ret = regulator_ena_gpio_request(rdev, config); 4167 4162 mutex_unlock(&regulator_list_mutex);
+3
include/linux/regulator/driver.h
··· 19 19 #include <linux/notifier.h> 20 20 #include <linux/regulator/consumer.h> 21 21 22 + struct gpio_desc; 22 23 struct regmap; 23 24 struct regulator_dev; 24 25 struct regulator_config; ··· 388 387 * initialized, meaning that >= 0 is a valid gpio 389 388 * identifier and < 0 is a non existent gpio. 390 389 * @ena_gpio: GPIO controlling regulator enable. 390 + * @ena_gpiod: GPIO descriptor controlling regulator enable. 391 391 * @ena_gpio_invert: Sense for GPIO enable control. 392 392 * @ena_gpio_flags: Flags to use when calling gpio_request_one() 393 393 */ ··· 401 399 402 400 bool ena_gpio_initialized; 403 401 int ena_gpio; 402 + struct gpio_desc *ena_gpiod; 404 403 unsigned int ena_gpio_invert:1; 405 404 unsigned int ena_gpio_flags; 406 405 };