]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: mmio: add BGPIOF_NO_INPUT flag for GPO gpiochip
authorClément Le Goffic <clement.legoffic@foss.st.com>
Fri, 13 Jun 2025 10:14:12 +0000 (12:14 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 19 Jun 2025 07:05:33 +0000 (09:05 +0200)
When using bgpio_init with a gpiochip acting as a GPO (output only), the
gpiochip ops `direction_input` was set to `bgpio_simple_dir_in` by
default but we have no input ability.

Adding this flag allows to set a valid ops for the `direction_output`
ops without setting a valid ops for `direction_input` by default.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
Link: https://lore.kernel.org/r/20250613-hdp-upstream-v5-1-6fd6f0dc527c@foss.st.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-mmio.c
include/linux/gpio/driver.h

index 4841e4ebe7a67d0f954e9a6f995ec5758f124edd..09b9e1275e7ee8fffb797295c2de2144c1647c39 100644 (file)
@@ -335,6 +335,11 @@ static int bgpio_dir_return(struct gpio_chip *gc, unsigned int gpio, bool dir_ou
                return pinctrl_gpio_direction_input(gc, gpio);
 }
 
+static int bgpio_dir_in_err(struct gpio_chip *gc, unsigned int gpio)
+{
+       return -EINVAL;
+}
+
 static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio)
 {
        return bgpio_dir_return(gc, gpio, false);
@@ -566,7 +571,11 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
                        gc->direction_output = bgpio_dir_out_err;
                else
                        gc->direction_output = bgpio_simple_dir_out;
-               gc->direction_input = bgpio_simple_dir_in;
+
+               if (flags & BGPIOF_NO_INPUT)
+                       gc->direction_input = bgpio_dir_in_err;
+               else
+                       gc->direction_input = bgpio_simple_dir_in;
        }
 
        return 0;
index b53233051beed0c6b927a951669ae5cf17d88a68..97cc75623261917e9b3624e1e636d2432c0db205 100644 (file)
@@ -750,6 +750,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 #define BGPIOF_NO_OUTPUT               BIT(5) /* only input */
 #define BGPIOF_NO_SET_ON_INPUT         BIT(6)
 #define BGPIOF_PINCTRL_BACKEND         BIT(7) /* Call pinctrl direction setters */
+#define BGPIOF_NO_INPUT                        BIT(8) /* only output */
 
 #ifdef CONFIG_GPIOLIB_IRQCHIP
 int gpiochip_irqchip_add_domain(struct gpio_chip *gc,