diff options
author | Haoran Wang <elven.wang@nxp.com> | 2016-12-21 15:48:06 +0800 |
---|---|---|
committer | David Pursell <dpursell@google.com> | 2017-03-23 19:05:26 -0700 |
commit | a215a8c8c275fec5e9cd98c571a1990a597d2c19 (patch) | |
tree | 1cf95158b7525a1d9988ee5c9ebaaedffee86644 | |
parent | c270f56c59749d16aa81ef57a421d2501d0407b7 (diff) | |
download | imx-v4.1-a215a8c8c275fec5e9cd98c571a1990a597d2c19.tar.gz |
gpio-generic: read output pin value from reg_set
Cherry-pick patch from Andy Duan <fugang.duan@nxp.com>.
Read output pin value from reg_set register when reg_set is readable.
This patch fixed the bug i.MX GPIO cannot get the value that set by upper
layer when GPIO work in output mode.
Change-Id: I1227cbcefa6cde2f0bc7e64f8ab1ec7878e94ae2
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Haoran Wang <elven.wang@nxp.com>
(cherry picked from commit 607eb19d40d096305f61250442b30e54250b23cb)
-rw-r--r-- | drivers/gpio/gpio-generic.c | 11 | ||||
-rw-r--r-- | include/linux/basic_mmio_gpio.h | 1 |
2 files changed, 11 insertions, 1 deletions
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index b92a690f5765..fb623340aacf 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c @@ -138,8 +138,15 @@ static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc, static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) { struct bgpio_chip *bgc = to_bgpio_chip(gc); + int val; - return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); + if (!(bgc->flags & BGPIOF_UNREADABLE_REG_DIR) && + (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio))) + val = !!(bgc->read_reg(bgc->reg_set) & bgc->pin2mask(bgc, gpio)); + else + val = !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); + + return val; } static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) @@ -520,6 +527,8 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev, if (bgc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) bgc->dir = bgc->read_reg(bgc->reg_dir); + bgc->flags = flags; + return ret; } EXPORT_SYMBOL_GPL(bgpio_init); diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h index 0e97856b2cff..6106909cf6c1 100644 --- a/include/linux/basic_mmio_gpio.h +++ b/include/linux/basic_mmio_gpio.h @@ -57,6 +57,7 @@ struct bgpio_chip { /* Shadowed direction registers to clear/set direction safely. */ unsigned long dir; + unsigned long flags; }; static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc) |