]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
gpio: generic: support input-only chips
authorRabin Vincent <rabin@rab.in>
Wed, 22 Jul 2015 13:05:18 +0000 (15:05 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 27 Jul 2015 13:01:05 +0000 (15:01 +0200)
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>
drivers/gpio/gpio-generic.c
include/linux/basic_mmio_gpio.h

index 802e6d2c64e9ea4b74ff2fdda5f0d2eb8924185f..a3f07537fe6250864e7e829b97821555e79bf426 100644 (file)
@@ -153,6 +153,10 @@ static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
        return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));
 }
 
+static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+}
+
 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 {
        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)
        return 0;
 }
 
+static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio,
+                               int val)
+{
+       return -EINVAL;
+}
+
 static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio,
                                int val)
 {
@@ -460,6 +470,9 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
                bgc->reg_set = set;
                bgc->gc.set = bgpio_set_set;
                bgc->gc.set_multiple = bgpio_set_multiple_set;
+       } else if (flags & BGPIOF_NO_OUTPUT) {
+               bgc->gc.set = bgpio_set_none;
+               bgc->gc.set_multiple = NULL;
        } else {
                bgc->gc.set = bgpio_set;
                bgc->gc.set_multiple = bgpio_set_multiple;
@@ -476,7 +489,8 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
 
 static int bgpio_setup_direction(struct bgpio_chip *bgc,
                                 void __iomem *dirout,
-                                void __iomem *dirin)
+                                void __iomem *dirin,
+                                unsigned long flags)
 {
        if (dirout && dirin) {
                return -EINVAL;
@@ -491,7 +505,10 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
                bgc->gc.direction_input = bgpio_dir_in_inv;
                bgc->gc.get_direction = bgpio_get_dir_inv;
        } else {
-               bgc->gc.direction_output = bgpio_simple_dir_out;
+               if (flags & BGPIOF_NO_OUTPUT)
+                       bgc->gc.direction_output = bgpio_dir_out_err;
+               else
+                       bgc->gc.direction_output = bgpio_simple_dir_out;
                bgc->gc.direction_input = bgpio_simple_dir_in;
        }
 
@@ -543,7 +560,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
        if (ret)
                return ret;
 
-       ret = bgpio_setup_direction(bgc, dirout, dirin);
+       ret = bgpio_setup_direction(bgc, dirout, dirin, flags);
        if (ret)
                return ret;
 
index 14eea946e6401cde3880cafc4e7c11e1264d918a..ed3768f4ecc70f7554ed4eeee53fb79615e0a05f 100644 (file)
@@ -75,5 +75,6 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
 #define BGPIOF_UNREADABLE_REG_DIR      BIT(2) /* reg_dir is unreadable */
 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER   BIT(3)
 #define BGPIOF_READ_OUTPUT_REG_SET     BIT(4) /* reg_set stores output value */
+#define BGPIOF_NO_OUTPUT               BIT(5) /* only input */
 
 #endif /* __BASIC_MMIO_GPIO_H */