]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: gpio: Refactor to prepare for live tree support
authorSimon Glass <sjg@chromium.org>
Fri, 19 May 2017 02:09:18 +0000 (20:09 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 1 Jun 2017 13:03:10 +0000 (07:03 -0600)
Move the main part of the GPIO request function into a separate function
so that it can be used by the live tree function when added. Update the
xlate method to use a node reference.

Update all GPIO drivers to handle the modified xlate() method.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/gpio/74x164_gpio.c
drivers/gpio/gpio-uclass.c
drivers/gpio/pca953x_gpio.c
drivers/gpio/sandbox.c
drivers/gpio/sunxi_gpio.c
drivers/gpio/tegra186_gpio.c
drivers/gpio/tegra_gpio.c
include/asm-generic/gpio.h

index 53a639ae65b14a992f6a181aecc775d14fb45f36..eb2c0b63d7be86e3f65c8dd8e583d690d900a5b1 100644 (file)
@@ -106,7 +106,7 @@ static int gen_74x164_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int gen_74x164_xlate(struct udevice *dev, struct gpio_desc *desc,
-                           struct fdtdec_phandle_args *args)
+                           struct ofnode_phandle_args *args)
 {
        desc->offset = args->args[0];
        desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
index ba4804083daa6c7c6619eeda9215022d26fe0623..92a1346aa28b9fafb056a44e029ddb5f31a19144 100644 (file)
@@ -114,9 +114,8 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
        return 0;
 }
 
-int gpio_xlate_offs_flags(struct udevice *dev,
-                                        struct gpio_desc *desc,
-                                        struct fdtdec_phandle_args *args)
+int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
+                         struct ofnode_phandle_args *args)
 {
        if (args->args_count < 1)
                return -EINVAL;
@@ -133,7 +132,7 @@ int gpio_xlate_offs_flags(struct udevice *dev,
 }
 
 static int gpio_find_and_xlate(struct gpio_desc *desc,
-                              struct fdtdec_phandle_args *args)
+                              struct ofnode_phandle_args *args)
 {
        struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
 
@@ -642,37 +641,30 @@ int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)
        return vector;
 }
 
-static int _gpio_request_by_name_nodev(const void *blob, int node,
-                                      const char *list_name, int index,
-                                      struct gpio_desc *desc, int flags,
-                                      bool add_index)
+static int gpio_request_tail(int ret, ofnode node,
+                            struct ofnode_phandle_args *args,
+                            const char *list_name, int index,
+                            struct gpio_desc *desc, int flags, bool add_index)
 {
-       struct fdtdec_phandle_args args;
-       int ret;
-
        desc->dev = NULL;
        desc->offset = 0;
        desc->flags = 0;
-       ret = fdtdec_parse_phandle_with_args(blob, node, list_name,
-                                            "#gpio-cells", 0, index, &args);
-       if (ret) {
-               debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
+       if (ret)
                goto err;
-       }
 
-       ret = uclass_get_device_by_of_offset(UCLASS_GPIO, args.node,
-                                            &desc->dev);
+       ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node,
+                                         &desc->dev);
        if (ret) {
                debug("%s: uclass_get_device_by_of_offset failed\n", __func__);
                goto err;
        }
-       ret = gpio_find_and_xlate(desc, &args);
+       ret = gpio_find_and_xlate(desc, args);
        if (ret) {
                debug("%s: gpio_find_and_xlate failed\n", __func__);
                goto err;
        }
        ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s",
-                              fdt_get_name(blob, node, NULL),
+                              ofnode_get_name(node),
                               list_name, index);
        if (ret) {
                debug("%s: dm_gpio_requestf failed\n", __func__);
@@ -687,10 +679,27 @@ static int _gpio_request_by_name_nodev(const void *blob, int node,
        return 0;
 err:
        debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n",
-             __func__, fdt_get_name(blob, node, NULL), list_name, index, ret);
+             __func__, ofnode_get_name(node), list_name, index, ret);
        return ret;
 }
 
+static int _gpio_request_by_name_nodev(const void *blob, int node,
+                                      const char *list_name, int index,
+                                      struct gpio_desc *desc, int flags,
+                                      bool add_index)
+{
+       struct ofnode_phandle_args args;
+       int ret;
+
+       ret = ofnode_parse_phandle_with_args(offset_to_ofnode(node), list_name,
+                                            "#gpio-cells", 0, index, &args);
+       if (ret)
+               debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
+
+       return gpio_request_tail(ret, offset_to_ofnode(node), &args, list_name,
+                                index, desc, flags, add_index);
+}
+
 int gpio_request_by_name_nodev(const void *blob, int node,
                               const char *list_name, int index,
                               struct gpio_desc *desc, int flags)
index b81f0fa90c2f04d98bce36ac2484ba43b5a1ed33..4962f25230808d3c7fffba3a2eda89936007d025 100644 (file)
@@ -228,7 +228,7 @@ static int pca953x_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int pca953x_xlate(struct udevice *dev, struct gpio_desc *desc,
-                        struct fdtdec_phandle_args *args)
+                        struct ofnode_phandle_args *args)
 {
        desc->offset = args->args[0];
        desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
index ae6d93013f7c79a4bc84ab6be9acd5fd052c736e..0f22acb0e677acfe209677bfe0d1aeed155bd0e9 100644 (file)
@@ -8,6 +8,7 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
+#include <dm/of.h>
 #include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -165,7 +166,7 @@ static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                        struct fdtdec_phandle_args *args)
+                        struct ofnode_phandle_args *args)
 {
        desc->offset = args->args[0];
        if (args->args_count < 2)
index f0c9ea0794879d80187801c5eb4e1f277307c759..b47cc66c583a2b1d22c00d408cfca0f03c0e5d82 100644 (file)
@@ -217,7 +217,7 @@ static int sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                           struct fdtdec_phandle_args *args)
+                           struct ofnode_phandle_args *args)
 {
        int ret;
 
index cb2524e9bfe71d30f792e3b1db30f48dcb691542..c5a7e13cceb8f88aba4d52f3a4920232c586738e 100644 (file)
@@ -139,7 +139,7 @@ static int tegra186_gpio_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int tegra186_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                           struct fdtdec_phandle_args *args)
+                              struct ofnode_phandle_args *args)
 {
        int gpio, port, ret;
 
index fb79f7fa5862fedebb3dc385e7395dfe81928819..687cd74fee6db36f53bd3acd1b49e4fdeb650744 100644 (file)
@@ -236,7 +236,7 @@ static int tegra_gpio_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int tegra_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                           struct fdtdec_phandle_args *args)
+                           struct ofnode_phandle_args *args)
 {
        int gpio, port, ret;
 
index 4aa0004fab4b2cc67e414b395ca38f9403e950c4..b073b391380c3fc616577b978906fedc66886f94 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef _ASM_GENERIC_GPIO_H_
 #define _ASM_GENERIC_GPIO_H_
 
+struct ofnode_phandle_args;
+
 /*
  * Generic GPIO API for U-Boot
  *
@@ -214,7 +216,7 @@ struct fdtdec_phandle_args;
  *
  */
 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
-                         struct fdtdec_phandle_args *args);
+                         struct ofnode_phandle_args *args);
 
 /**
  * struct struct dm_gpio_ops - Driver model GPIO operations
@@ -286,7 +288,7 @@ struct dm_gpio_ops {
         * @return 0 if OK, -ve on error
         */
        int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
-                    struct fdtdec_phandle_args *args);
+                    struct ofnode_phandle_args *args);
 };
 
 /**