aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>2015-04-29 11:34:59 -0400
committerLinus Walleij <linus.walleij@linaro.org>2015-05-11 05:49:02 -0400
commitb19e7f51a55fe740c18038d1d6957aedfc078d07 (patch)
tree69601960687fdab39deb1e3ac2b3cc809e356c52
parentff71880006795290f371caae13e740491ec76956 (diff)
gpio: gpio-generic: add flag to read out output value from reg_set
The change introduces BGPIOF_READ_OUTPUT_REG_SET flag for gpio-generic GPIO chip implementation, which allows to get correct configured value from reg_set register, input value is still get from reg_dat. Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpio-generic.c22
-rw-r--r--include/linux/basic_mmio_gpio.h1
2 files changed, 20 insertions, 3 deletions
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index b92a690f5765..9bda3727fac1 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -135,6 +135,17 @@ static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc,
135 return 1 << (bgc->bits - 1 - pin); 135 return 1 << (bgc->bits - 1 - pin);
136} 136}
137 137
138static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
139{
140 struct bgpio_chip *bgc = to_bgpio_chip(gc);
141 unsigned long pinmask = bgc->pin2mask(bgc, gpio);
142
143 if (bgc->dir & pinmask)
144 return bgc->read_reg(bgc->reg_set) & pinmask;
145 else
146 return bgc->read_reg(bgc->reg_dat) & pinmask;
147}
148
138static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 149static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
139{ 150{
140 struct bgpio_chip *bgc = to_bgpio_chip(gc); 151 struct bgpio_chip *bgc = to_bgpio_chip(gc);
@@ -416,7 +427,8 @@ static int bgpio_setup_accessors(struct device *dev,
416static int bgpio_setup_io(struct bgpio_chip *bgc, 427static int bgpio_setup_io(struct bgpio_chip *bgc,
417 void __iomem *dat, 428 void __iomem *dat,
418 void __iomem *set, 429 void __iomem *set,
419 void __iomem *clr) 430 void __iomem *clr,
431 unsigned long flags)
420{ 432{
421 433
422 bgc->reg_dat = dat; 434 bgc->reg_dat = dat;
@@ -437,7 +449,11 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
437 bgc->gc.set_multiple = bgpio_set_multiple; 449 bgc->gc.set_multiple = bgpio_set_multiple;
438 } 450 }
439 451
440 bgc->gc.get = bgpio_get; 452 if (!(flags & BGPIOF_UNREADABLE_REG_SET) &&
453 (flags & BGPIOF_READ_OUTPUT_REG_SET))
454 bgc->gc.get = bgpio_get_set;
455 else
456 bgc->gc.get = bgpio_get;
441 457
442 return 0; 458 return 0;
443} 459}
@@ -500,7 +516,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
500 bgc->gc.ngpio = bgc->bits; 516 bgc->gc.ngpio = bgc->bits;
501 bgc->gc.request = bgpio_request; 517 bgc->gc.request = bgpio_request;
502 518
503 ret = bgpio_setup_io(bgc, dat, set, clr); 519 ret = bgpio_setup_io(bgc, dat, set, clr, flags);
504 if (ret) 520 if (ret)
505 return ret; 521 return ret;
506 522
diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h
index 0e97856b2cff..14eea946e640 100644
--- a/include/linux/basic_mmio_gpio.h
+++ b/include/linux/basic_mmio_gpio.h
@@ -74,5 +74,6 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
74#define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 74#define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */
75#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 75#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
76#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 76#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
77#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
77 78
78#endif /* __BASIC_MMIO_GPIO_H */ 79#endif /* __BASIC_MMIO_GPIO_H */