]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
gpio: add helper GPIOD_FLAGS_OUTPUT
authorPatrick Delaunay <patrick.delaunay@st.com>
Mon, 13 Jan 2020 10:35:05 +0000 (11:35 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 17 Apr 2020 03:06:54 +0000 (23:06 -0400)
Add a macro to provide the GPIO output value according
the dir flags content.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/gpio/gpio-uclass.c
include/asm-generic/gpio.h

index b5cebfdbc6af9cf0e1bdd08954b3e70ff9e56ce5..29c8c0f57bbb8f447239112d92a8e3c8c34debd6 100644 (file)
@@ -542,12 +542,9 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
        }
 
        if (flags & GPIOD_IS_OUT) {
-               int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
-
-               if (flags & GPIOD_ACTIVE_LOW)
-                       value = !value;
-               ret = ops->direction_output(dev, desc->offset, value);
-       } else  if (flags & GPIOD_IS_IN) {
+               ret = ops->direction_output(dev, desc->offset,
+                                           GPIOD_FLAGS_OUTPUT(flags));
+       } else if (flags & GPIOD_IS_IN) {
                ret = ops->direction_input(dev, desc->offset);
        }
 
index 4d5348d8c8ec723ecca2e7319532d59b03f7cf22..5686df7cece8887ac7656fe19279f5766d73d991 100644 (file)
@@ -129,6 +129,12 @@ struct gpio_desc {
         */
 };
 
+/* helper to compute the value of the gpio output */
+#define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE)
+#define GPIOD_FLAGS_OUTPUT(flags) \
+       (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \
+         (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW)))
+
 /**
  * dm_gpio_is_valid() - Check if a GPIO is valid
  *