diff options
author | Philipp Zabel <p.zabel@pengutronix.de> | 2015-06-12 12:20:35 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-07-15 18:11:02 -0400 |
commit | db3b0fcc5adbda0c7060c9298c2514778547fee2 (patch) | |
tree | 39e1ee04c0979833fc2cc09156857cfba9fd8c44 /drivers/gpio/gpio-generic.c | |
parent | bc0195aad0daa2ad5b0d76cce22b167bc3435590 (diff) |
gpio: generic: add get_direction support
Allow to determine the current direction configuration by
reading back from the direction register.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-generic.c')
-rw-r--r-- | drivers/gpio/gpio-generic.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index 9bda3727fac1..802e6d2c64e9 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c | |||
@@ -302,6 +302,14 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | |||
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |
304 | 304 | ||
305 | static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) | ||
306 | { | ||
307 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
308 | |||
309 | return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? | ||
310 | GPIOF_DIR_OUT : GPIOF_DIR_IN; | ||
311 | } | ||
312 | |||
305 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | 313 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) |
306 | { | 314 | { |
307 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 315 | struct bgpio_chip *bgc = to_bgpio_chip(gc); |
@@ -351,6 +359,14 @@ static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) | |||
351 | return 0; | 359 | return 0; |
352 | } | 360 | } |
353 | 361 | ||
362 | static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) | ||
363 | { | ||
364 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
365 | |||
366 | return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? | ||
367 | GPIOF_DIR_IN : GPIOF_DIR_OUT; | ||
368 | } | ||
369 | |||
354 | static int bgpio_setup_accessors(struct device *dev, | 370 | static int bgpio_setup_accessors(struct device *dev, |
355 | struct bgpio_chip *bgc, | 371 | struct bgpio_chip *bgc, |
356 | bool bit_be, | 372 | bool bit_be, |
@@ -468,10 +484,12 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc, | |||
468 | bgc->reg_dir = dirout; | 484 | bgc->reg_dir = dirout; |
469 | bgc->gc.direction_output = bgpio_dir_out; | 485 | bgc->gc.direction_output = bgpio_dir_out; |
470 | bgc->gc.direction_input = bgpio_dir_in; | 486 | bgc->gc.direction_input = bgpio_dir_in; |
487 | bgc->gc.get_direction = bgpio_get_dir; | ||
471 | } else if (dirin) { | 488 | } else if (dirin) { |
472 | bgc->reg_dir = dirin; | 489 | bgc->reg_dir = dirin; |
473 | bgc->gc.direction_output = bgpio_dir_out_inv; | 490 | bgc->gc.direction_output = bgpio_dir_out_inv; |
474 | bgc->gc.direction_input = bgpio_dir_in_inv; | 491 | bgc->gc.direction_input = bgpio_dir_in_inv; |
492 | bgc->gc.get_direction = bgpio_get_dir_inv; | ||
475 | } else { | 493 | } else { |
476 | bgc->gc.direction_output = bgpio_simple_dir_out; | 494 | bgc->gc.direction_output = bgpio_simple_dir_out; |
477 | bgc->gc.direction_input = bgpio_simple_dir_in; | 495 | bgc->gc.direction_input = bgpio_simple_dir_in; |