Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vladimir Zapolskiy and committed by
Linus Walleij
b19e7f51 ff718800

+20 -3
+19 -3
drivers/gpio/gpio-generic.c
··· 135 135 return 1 << (bgc->bits - 1 - pin); 136 136 } 137 137 138 + static 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 + 138 149 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 139 150 { 140 151 struct bgpio_chip *bgc = to_bgpio_chip(gc); ··· 427 416 static int bgpio_setup_io(struct bgpio_chip *bgc, 428 417 void __iomem *dat, 429 418 void __iomem *set, 430 - void __iomem *clr) 419 + void __iomem *clr, 420 + unsigned long flags) 431 421 { 432 422 433 423 bgc->reg_dat = dat; ··· 449 437 bgc->gc.set_multiple = bgpio_set_multiple; 450 438 } 451 439 452 - bgc->gc.get = bgpio_get; 440 + if (!(flags & BGPIOF_UNREADABLE_REG_SET) && 441 + (flags & BGPIOF_READ_OUTPUT_REG_SET)) 442 + bgc->gc.get = bgpio_get_set; 443 + else 444 + bgc->gc.get = bgpio_get; 453 445 454 446 return 0; 455 447 } ··· 516 500 bgc->gc.ngpio = bgc->bits; 517 501 bgc->gc.request = bgpio_request; 518 502 519 - ret = bgpio_setup_io(bgc, dat, set, clr); 503 + ret = bgpio_setup_io(bgc, dat, set, clr, flags); 520 504 if (ret) 521 505 return ret; 522 506
+1
include/linux/basic_mmio_gpio.h
··· 74 74 #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 75 75 #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 76 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 79 #endif /* __BASIC_MMIO_GPIO_H */