aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2021-09-11 17:05:53 -0500
committerTom Rini <trini@konsulko.com>2021-10-05 08:50:15 -0400
commit8a47982ed8d40595a83b82b2298753873e597708 (patch)
treea886c25653f2e6176773729cf2ed7a92d439b151
parent37c10bf7ef22ccaa349581984340a616fb1c6ffb (diff)
downloadu-boot-8a47982ed8d40595a83b82b2298753873e597708.zip
u-boot-8a47982ed8d40595a83b82b2298753873e597708.tar.gz
u-boot-8a47982ed8d40595a83b82b2298753873e597708.tar.bz2
gpio: Factor out DT flag translation
The generic GPIO flags binding is shared across many drivers, some of which need their own xlate function. Factor out the flag translation code from gpio_xlate_offs_flags so it does not need to be duplicated. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/gpio/gpio-uclass.c50
-rw-r--r--include/asm-generic/gpio.h8
2 files changed, 37 insertions, 21 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index fde046e..1c5e2e7 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -186,6 +186,34 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
return 0;
}
+unsigned long gpio_flags_xlate(uint32_t arg)
+{
+ unsigned long flags = 0;
+
+ if (arg & GPIO_ACTIVE_LOW)
+ flags |= GPIOD_ACTIVE_LOW;
+
+ /*
+ * need to test 2 bits for gpio output binding:
+ * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4)
+ * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0)
+ */
+ if (arg & GPIO_SINGLE_ENDED) {
+ if (arg & GPIO_LINE_OPEN_DRAIN)
+ flags |= GPIOD_OPEN_DRAIN;
+ else
+ flags |= GPIOD_OPEN_SOURCE;
+ }
+
+ if (arg & GPIO_PULL_UP)
+ flags |= GPIOD_PULL_UP;
+
+ if (arg & GPIO_PULL_DOWN)
+ flags |= GPIOD_PULL_DOWN;
+
+ return flags;
+}
+
int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
struct ofnode_phandle_args *args)
{
@@ -201,27 +229,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
if (args->args_count < 2)
return 0;
- desc->flags = 0;
- if (args->args[1] & GPIO_ACTIVE_LOW)
- desc->flags |= GPIOD_ACTIVE_LOW;
-
- /*
- * need to test 2 bits for gpio output binding:
- * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4)
- * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0)
- */
- if (args->args[1] & GPIO_SINGLE_ENDED) {
- if (args->args[1] & GPIO_LINE_OPEN_DRAIN)
- desc->flags |= GPIOD_OPEN_DRAIN;
- else
- desc->flags |= GPIOD_OPEN_SOURCE;
- }
-
- if (args->args[1] & GPIO_PULL_UP)
- desc->flags |= GPIOD_PULL_UP;
-
- if (args->args[1] & GPIO_PULL_DOWN)
- desc->flags |= GPIOD_PULL_DOWN;
+ desc->flags = gpio_flags_xlate(args->args[1]);
return 0;
}
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 6de13d9..fa9b807 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -222,6 +222,14 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)
struct fdtdec_phandle_args;
/**
+ * gpio_flags_xlate() - convert DT flags to internal flags
+ *
+ * This routine converts the GPIO_* flags from the generic DT binding to the
+ * GPIOD_* flags used internally. It can be called from driver xlate functions.
+ */
+unsigned long gpio_flags_xlate(uint32_t arg);
+
+/**
* gpio_xlate_offs_flags() - implementation for common use of dm_gpio_ops.xlate
*
* This routine sets the offset field to args[0] and the flags field to