summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-09-04 20:29:25 +0900
committerLinus Walleij <linus.walleij@linaro.org>2013-09-20 10:30:18 +0200
commitd8e0ac0824cd0868ea73f186d6511d710b068044 (patch)
tree39e856bbd34a65fdf54b1879d8f14e33f5986ece /drivers/gpio/gpiolib.c
parentb59278548e2383976f7db5fd3389f9116a6f240d (diff)
downloadlinux-d8e0ac0824cd0868ea73f186d6511d710b068044.tar.gz
linux-d8e0ac0824cd0868ea73f186d6511d710b068044.tar.bz2
linux-d8e0ac0824cd0868ea73f186d6511d710b068044.zip
gpiolib: factorize gpiod_get/set functions
gpiod_get/set functions share common code between their regular and cansleep variants. The exporting of the gpiod interface will make the situation worse. This patch factorizes the common code to avoid code redundancy. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c72
1 files changed, 33 insertions, 39 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8048c3dbb8ad..4fc28603a742 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1869,6 +1869,19 @@ EXPORT_SYMBOL_GPL(gpio_set_debounce);
* that the GPIO was actually requested.
*/
+static int _gpiod_get_value(const struct gpio_desc *desc)
+{
+ struct gpio_chip *chip;
+ int value;
+ int offset;
+
+ chip = desc->chip;
+ offset = gpio_chip_hwgpio(desc);
+ value = chip->get ? chip->get(chip, offset) : 0;
+ trace_gpio_value(desc_to_gpio(desc), 1, value);
+ return value;
+}
+
/**
* __gpio_get_value() - return a gpio's value
* @gpio: gpio whose value will be returned
@@ -1880,19 +1893,11 @@ EXPORT_SYMBOL_GPL(gpio_set_debounce);
*/
static int gpiod_get_value(const struct gpio_desc *desc)
{
- struct gpio_chip *chip;
- int value;
- int offset;
-
if (!desc)
return 0;
- chip = desc->chip;
- offset = gpio_chip_hwgpio(desc);
/* Should be using gpio_get_value_cansleep() */
- WARN_ON(chip->can_sleep);
- value = chip->get ? chip->get(chip, offset) : 0;
- trace_gpio_value(desc_to_gpio(desc), 1, value);
- return value;
+ WARN_ON(desc->chip->can_sleep);
+ return _gpiod_get_value(desc);
}
int __gpio_get_value(unsigned gpio)
@@ -1957,6 +1962,20 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, int value)
__func__, err);
}
+static void _gpiod_set_value(struct gpio_desc *desc, int value)
+{
+ struct gpio_chip *chip;
+
+ chip = desc->chip;
+ trace_gpio_value(desc_to_gpio(desc), 0, value);
+ if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
+ _gpio_set_open_drain_value(desc, value);
+ else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
+ _gpio_set_open_source_value(desc, value);
+ else
+ chip->set(chip, gpio_chip_hwgpio(desc), value);
+}
+
/**
* __gpio_set_value() - assign a gpio's value
* @gpio: gpio whose value will be assigned
@@ -1968,20 +1987,12 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, int value)
*/
static void gpiod_set_value(struct gpio_desc *desc, int value)
{
- struct gpio_chip *chip;
if (!desc)
return;
- chip = desc->chip;
/* Should be using gpio_set_value_cansleep() */
- WARN_ON(chip->can_sleep);
- trace_gpio_value(desc_to_gpio(desc), 0, value);
- if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
- _gpio_set_open_drain_value(desc, value);
- else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
- _gpio_set_open_source_value(desc, value);
- else
- chip->set(chip, gpio_chip_hwgpio(desc), value);
+ WARN_ON(desc->chip->can_sleep);
+ _gpiod_set_value(desc, value);
}
void __gpio_set_value(unsigned gpio, int value)
@@ -2046,18 +2057,10 @@ EXPORT_SYMBOL_GPL(__gpio_to_irq);
static int gpiod_get_value_cansleep(const struct gpio_desc *desc)
{
- struct gpio_chip *chip;
- int value;
- int offset;
-
might_sleep_if(extra_checks);
if (!desc)
return 0;
- chip = desc->chip;
- offset = gpio_chip_hwgpio(desc);
- value = chip->get ? chip->get(chip, offset) : 0;
- trace_gpio_value(desc_to_gpio(desc), 1, value);
- return value;
+ return _gpiod_get_value(desc);
}
int gpio_get_value_cansleep(unsigned gpio)
@@ -2068,19 +2071,10 @@ EXPORT_SYMBOL_GPL(gpio_get_value_cansleep);
static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
{
- struct gpio_chip *chip;
-
might_sleep_if(extra_checks);
if (!desc)
return;
- chip = desc->chip;
- trace_gpio_value(desc_to_gpio(desc), 0, value);
- if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
- _gpio_set_open_drain_value(desc, value);
- else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
- _gpio_set_open_source_value(desc, value);
- else
- chip->set(chip, gpio_chip_hwgpio(desc), value);
+ _gpiod_set_value(desc, value);
}
void gpio_set_value_cansleep(unsigned gpio, int value)