]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: gpio: Add a driver GPIO translation method
authorSimon Glass <sjg@chromium.org>
Tue, 6 Jan 2015 03:05:28 +0000 (20:05 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 30 Jan 2015 00:09:50 +0000 (17:09 -0700)
Only the GPIO driver knows about the full GPIO device tree binding used by
a device. Add a method to allow the driver to provide this information to the
uclass, including the GPIO offset within the device and flags such as the
polarity.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/gpio/gpio-uclass.c
include/asm-generic/gpio.h

index 2f3c36b48ff652d4f81a169a67f97c6a45acfab5..0a4d9e421781cd1b7eedf7707cc347e2cf36f23c 100644 (file)
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
 #include <linux/ctype.h>
@@ -91,6 +92,21 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
        return 0;
 }
 
+int gpio_find_and_xlate(struct gpio_desc *desc,
+                       struct fdtdec_phandle_args *args)
+{
+       struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
+
+       /* Use the first argument as the offset by default */
+       if (args->args_count > 0)
+               desc->offset = args->args[0];
+       else
+               desc->offset = -1;
+       desc->flags = 0;
+
+       return ops->xlate ? ops->xlate(desc->dev, desc, args) : 0;
+}
+
 static int dm_gpio_request(struct gpio_desc *desc, const char *label)
 {
        struct udevice *dev = desc->dev;
index a827a56f5e11679002caeb0ec48e1052d357aa15..c08c96340af000a863b0b42c643779e581b99074 100644 (file)
@@ -171,6 +171,8 @@ int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
 int gpio_requestf(unsigned gpio, const char *fmt, ...)
                __attribute__ ((format (__printf__, 2, 3)));
 
+struct fdtdec_phandle_args;
+
 /**
  * struct struct dm_gpio_ops - Driver model GPIO operations
  *
@@ -214,6 +216,33 @@ struct dm_gpio_ops {
         * @return current function - GPIOF_...
         */
        int (*get_function)(struct udevice *dev, unsigned offset);
+
+       /**
+        * xlate() - Translate phandle arguments into a GPIO description
+        *
+        * This function should set up the fields in desc according to the
+        * information in the arguments. The uclass will have set up:
+        *
+        *   @desc->dev to @dev
+        *   @desc->flags to 0
+        *   @desc->offset to the value of the first argument in args, if any,
+        *              otherwise -1 (which is invalid)
+        *
+        * This method is optional so if the above defaults suit it can be
+        * omitted. Typical behaviour is to set up the GPIOD_ACTIVE_LOW flag
+        * in desc->flags.
+        *
+        * Note that @dev is passed in as a parameter to follow driver model
+        * uclass conventions, even though it is already available as
+        * desc->dev.
+        *
+        * @dev:        GPIO device
+        * @desc:       Place to put GPIO description
+        * @args:       Arguments provided in descripion
+        * @return 0 if OK, -ve on error
+        */
+       int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
+                    struct fdtdec_phandle_args *args);
 };
 
 /**