Skip to content

Commit 91492a4

Browse files
vitkyrkalinusw
authored andcommitted
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 <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 1296fba commit 91492a4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

drivers/gpio/gpio-generic.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
153153
return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));
154154
}
155155

156+
static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
157+
{
158+
}
159+
156160
static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
157161
{
158162
struct bgpio_chip *bgc = to_bgpio_chip(gc);
@@ -279,6 +283,12 @@ static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio)
279283
return 0;
280284
}
281285

286+
static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio,
287+
int val)
288+
{
289+
return -EINVAL;
290+
}
291+
282292
static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio,
283293
int val)
284294
{
@@ -460,6 +470,9 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
460470
bgc->reg_set = set;
461471
bgc->gc.set = bgpio_set_set;
462472
bgc->gc.set_multiple = bgpio_set_multiple_set;
473+
} else if (flags & BGPIOF_NO_OUTPUT) {
474+
bgc->gc.set = bgpio_set_none;
475+
bgc->gc.set_multiple = NULL;
463476
} else {
464477
bgc->gc.set = bgpio_set;
465478
bgc->gc.set_multiple = bgpio_set_multiple;
@@ -476,7 +489,8 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
476489

477490
static int bgpio_setup_direction(struct bgpio_chip *bgc,
478491
void __iomem *dirout,
479-
void __iomem *dirin)
492+
void __iomem *dirin,
493+
unsigned long flags)
480494
{
481495
if (dirout && dirin) {
482496
return -EINVAL;
@@ -491,7 +505,10 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
491505
bgc->gc.direction_input = bgpio_dir_in_inv;
492506
bgc->gc.get_direction = bgpio_get_dir_inv;
493507
} else {
494-
bgc->gc.direction_output = bgpio_simple_dir_out;
508+
if (flags & BGPIOF_NO_OUTPUT)
509+
bgc->gc.direction_output = bgpio_dir_out_err;
510+
else
511+
bgc->gc.direction_output = bgpio_simple_dir_out;
495512
bgc->gc.direction_input = bgpio_simple_dir_in;
496513
}
497514

@@ -543,7 +560,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
543560
if (ret)
544561
return ret;
545562

546-
ret = bgpio_setup_direction(bgc, dirout, dirin);
563+
ret = bgpio_setup_direction(bgc, dirout, dirin, flags);
547564
if (ret)
548565
return ret;
549566

include/linux/basic_mmio_gpio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
7575
#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
7676
#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
7777
#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
78+
#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
7879

7980
#endif /* __BASIC_MMIO_GPIO_H */

0 commit comments

Comments
 (0)