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

gpio: generic: support input-only chips

Allow chips to indicates that they are input-only and thus cannot set
the output value. This will be used by the gpio-etraxfs driver.

Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Rabin Vincent and committed by
Linus Walleij
91492a44 1296fba1

+21 -3
+20 -3
drivers/gpio/gpio-generic.c
··· 153 153 return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 154 154 } 155 155 156 + static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) 157 + { 158 + } 159 + 156 160 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 157 161 { 158 162 struct bgpio_chip *bgc = to_bgpio_chip(gc); ··· 281 277 static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) 282 278 { 283 279 return 0; 280 + } 281 + 282 + static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, 283 + int val) 284 + { 285 + return -EINVAL; 284 286 } 285 287 286 288 static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, ··· 470 460 bgc->reg_set = set; 471 461 bgc->gc.set = bgpio_set_set; 472 462 bgc->gc.set_multiple = bgpio_set_multiple_set; 463 + } else if (flags & BGPIOF_NO_OUTPUT) { 464 + bgc->gc.set = bgpio_set_none; 465 + bgc->gc.set_multiple = NULL; 473 466 } else { 474 467 bgc->gc.set = bgpio_set; 475 468 bgc->gc.set_multiple = bgpio_set_multiple; ··· 489 476 490 477 static int bgpio_setup_direction(struct bgpio_chip *bgc, 491 478 void __iomem *dirout, 492 - void __iomem *dirin) 479 + void __iomem *dirin, 480 + unsigned long flags) 493 481 { 494 482 if (dirout && dirin) { 495 483 return -EINVAL; ··· 505 491 bgc->gc.direction_input = bgpio_dir_in_inv; 506 492 bgc->gc.get_direction = bgpio_get_dir_inv; 507 493 } else { 508 - bgc->gc.direction_output = bgpio_simple_dir_out; 494 + if (flags & BGPIOF_NO_OUTPUT) 495 + bgc->gc.direction_output = bgpio_dir_out_err; 496 + else 497 + bgc->gc.direction_output = bgpio_simple_dir_out; 509 498 bgc->gc.direction_input = bgpio_simple_dir_in; 510 499 } 511 500 ··· 560 543 if (ret) 561 544 return ret; 562 545 563 - ret = bgpio_setup_direction(bgc, dirout, dirin); 546 + ret = bgpio_setup_direction(bgc, dirout, dirin, flags); 564 547 if (ret) 565 548 return ret; 566 549
+1
include/linux/basic_mmio_gpio.h
··· 75 75 #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 76 76 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 77 77 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 78 + #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 78 79 79 80 #endif /* __BASIC_MMIO_GPIO_H */