summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@bootlin.com>2019-02-07 11:28:58 -0500
committerLinus Walleij <linus.walleij@linaro.org>2019-02-13 03:10:14 -0500
commitd449991c4d1d0663b42db7648510a9911de21298 (patch)
tree3506a0caec0f680a87edf2404ab5f79cd6a40ff6 /drivers
parent6581eaf0e890756e093e2f44916edb5e7e6558ca (diff)
gpio: add core support for pull-up/pull-down configuration
This commit adds support for configuring the pull-up and pull-down resistors available in some GPIO controllers. While configuring pull-up/pull-down is already possible through the pinctrl subsystem, some GPIO controllers, especially simple ones such as GPIO expanders on I2C, don't have any pinmuxing capability and therefore do not use the pinctrl subsystem. This commit implements the GPIO_PULL_UP and GPIO_PULL_DOWN flags, which can be used from the Device Tree, to enable a pull-up or pull-down resistor on a given GPIO. The flag is simply propagated all the way to the core GPIO subsystem, where it is used to call the gpio_chip ->set_config callback with the appropriate existing PIN_CONFIG_BIAS_* values. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpiolib-of.c5
-rw-r--r--drivers/gpio/gpiolib.c18
-rw-r--r--drivers/gpio/gpiolib.h2
3 files changed, 25 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index a6e1891217e2..9a8b78477f79 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -345,6 +345,11 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
345 if (of_flags & OF_GPIO_TRANSITORY) 345 if (of_flags & OF_GPIO_TRANSITORY)
346 *flags |= GPIO_TRANSITORY; 346 *flags |= GPIO_TRANSITORY;
347 347
348 if (of_flags & OF_GPIO_PULL_UP)
349 *flags |= GPIO_PULL_UP;
350 if (of_flags & OF_GPIO_PULL_DOWN)
351 *flags |= GPIO_PULL_DOWN;
352
348 return desc; 353 return desc;
349} 354}
350 355
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1f239aac43df..22d8b37f5319 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2573,6 +2573,13 @@ int gpiod_direction_input(struct gpio_desc *desc)
2573 if (status == 0) 2573 if (status == 0)
2574 clear_bit(FLAG_IS_OUT, &desc->flags); 2574 clear_bit(FLAG_IS_OUT, &desc->flags);
2575 2575
2576 if (test_bit(FLAG_PULL_UP, &desc->flags))
2577 gpio_set_config(chip, gpio_chip_hwgpio(desc),
2578 PIN_CONFIG_BIAS_PULL_UP);
2579 else if (test_bit(FLAG_PULL_DOWN, &desc->flags))
2580 gpio_set_config(chip, gpio_chip_hwgpio(desc),
2581 PIN_CONFIG_BIAS_PULL_DOWN);
2582
2576 trace_gpio_direction(desc_to_gpio(desc), 1, status); 2583 trace_gpio_direction(desc_to_gpio(desc), 1, status);
2577 2584
2578 return status; 2585 return status;
@@ -4050,6 +4057,17 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
4050 if (lflags & GPIO_OPEN_SOURCE) 4057 if (lflags & GPIO_OPEN_SOURCE)
4051 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 4058 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
4052 4059
4060 if ((lflags & GPIO_PULL_UP) && (lflags & GPIO_PULL_DOWN)) {
4061 gpiod_err(desc,
4062 "both pull-up and pull-down enabled, invalid configuration\n");
4063 return -EINVAL;
4064 }
4065
4066 if (lflags & GPIO_PULL_UP)
4067 set_bit(FLAG_PULL_UP, &desc->flags);
4068 else if (lflags & GPIO_PULL_DOWN)
4069 set_bit(FLAG_PULL_DOWN, &desc->flags);
4070
4053 status = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY)); 4071 status = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY));
4054 if (status < 0) 4072 if (status < 0)
4055 return status; 4073 return status;
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index bc57f0dc5953..078ab17b96bf 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -219,6 +219,8 @@ struct gpio_desc {
219#define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */ 219#define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */
220#define FLAG_IS_HOGGED 11 /* GPIO is hogged */ 220#define FLAG_IS_HOGGED 11 /* GPIO is hogged */
221#define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */ 221#define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */
222#define FLAG_PULL_UP 13 /* GPIO has pull up enabled */
223#define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */
222 224
223 /* Connection label */ 225 /* Connection label */
224 const char *label; 226 const char *label;