diff options
author | Daniel Kurtz <djkurtz@chromium.org> | 2018-02-16 14:12:43 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2018-02-22 09:52:19 -0500 |
commit | 12b10f47e56ac94afa4d7ec5a22f67ccdfe2b90e (patch) | |
tree | 7bb41df37b000895a07049557a6ef09133a96dd4 | |
parent | b5520891a3491cd545e698c03874693aded56c1e (diff) |
pinctrl/amd: add get_direction handler
On boot, gpiochip_add_data() initializes the FLAG_IS_OUT bit in
desc->flags iff its gpio_chip does not have ->direction_input() handler,
else it is initialized to 0, which implies the GPIO is an "input".
Later, the sysfs "direction" handler will use gpiod_get_direction() to
get the current direction, but if no ->get_direction() handler is
installed, the result will just be the current (initial) value of flags,
which will always be OUT irregardless of the initial register value.
Add a get_direction() handler to pinctrl-amd to fix this and always
provide the correct value for direction.
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/pinctrl/pinctrl-amd.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c index 61d830c2bc17..281b700fe7e9 100644 --- a/drivers/pinctrl/pinctrl-amd.c +++ b/drivers/pinctrl/pinctrl-amd.c | |||
@@ -40,6 +40,19 @@ | |||
40 | #include "pinctrl-utils.h" | 40 | #include "pinctrl-utils.h" |
41 | #include "pinctrl-amd.h" | 41 | #include "pinctrl-amd.h" |
42 | 42 | ||
43 | static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset) | ||
44 | { | ||
45 | unsigned long flags; | ||
46 | u32 pin_reg; | ||
47 | struct amd_gpio *gpio_dev = gpiochip_get_data(gc); | ||
48 | |||
49 | raw_spin_lock_irqsave(&gpio_dev->lock, flags); | ||
50 | pin_reg = readl(gpio_dev->base + offset * 4); | ||
51 | raw_spin_unlock_irqrestore(&gpio_dev->lock, flags); | ||
52 | |||
53 | return !(pin_reg & BIT(OUTPUT_ENABLE_OFF)); | ||
54 | } | ||
55 | |||
43 | static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset) | 56 | static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset) |
44 | { | 57 | { |
45 | unsigned long flags; | 58 | unsigned long flags; |
@@ -845,6 +858,7 @@ static int amd_gpio_probe(struct platform_device *pdev) | |||
845 | #endif | 858 | #endif |
846 | 859 | ||
847 | gpio_dev->pdev = pdev; | 860 | gpio_dev->pdev = pdev; |
861 | gpio_dev->gc.get_direction = amd_gpio_get_direction; | ||
848 | gpio_dev->gc.direction_input = amd_gpio_direction_input; | 862 | gpio_dev->gc.direction_input = amd_gpio_direction_input; |
849 | gpio_dev->gc.direction_output = amd_gpio_direction_output; | 863 | gpio_dev->gc.direction_output = amd_gpio_direction_output; |
850 | gpio_dev->gc.get = amd_gpio_get_value; | 864 | gpio_dev->gc.get = amd_gpio_get_value; |