Commit db3b0fcc authored by Philipp Zabel's avatar Philipp Zabel Committed by Linus Walleij

gpio: generic: add get_direction support

Allow to determine the current direction configuration by
reading back from the direction register.
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent bc0195aa
...@@ -302,6 +302,14 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) ...@@ -302,6 +302,14 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
return 0; return 0;
} }
static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);
return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ?
GPIOF_DIR_OUT : GPIOF_DIR_IN;
}
static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{ {
struct bgpio_chip *bgc = to_bgpio_chip(gc); 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,6 +359,14 @@ static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val)
return 0; return 0;
} }
static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);
return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ?
GPIOF_DIR_IN : GPIOF_DIR_OUT;
}
static int bgpio_setup_accessors(struct device *dev, static int bgpio_setup_accessors(struct device *dev,
struct bgpio_chip *bgc, struct bgpio_chip *bgc,
bool bit_be, bool bit_be,
...@@ -468,10 +484,12 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc, ...@@ -468,10 +484,12 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
bgc->reg_dir = dirout; bgc->reg_dir = dirout;
bgc->gc.direction_output = bgpio_dir_out; bgc->gc.direction_output = bgpio_dir_out;
bgc->gc.direction_input = bgpio_dir_in; bgc->gc.direction_input = bgpio_dir_in;
bgc->gc.get_direction = bgpio_get_dir;
} else if (dirin) { } else if (dirin) {
bgc->reg_dir = dirin; bgc->reg_dir = dirin;
bgc->gc.direction_output = bgpio_dir_out_inv; bgc->gc.direction_output = bgpio_dir_out_inv;
bgc->gc.direction_input = bgpio_dir_in_inv; bgc->gc.direction_input = bgpio_dir_in_inv;
bgc->gc.get_direction = bgpio_get_dir_inv;
} else { } else {
bgc->gc.direction_output = bgpio_simple_dir_out; bgc->gc.direction_output = bgpio_simple_dir_out;
bgc->gc.direction_input = bgpio_simple_dir_in; bgc->gc.direction_input = bgpio_simple_dir_in;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment