[U-Boot] [PATCH 16/22] dm: gpio: Refactor to prepare for live tree support

Simon Glass sjg at chromium.org
Wed Jan 18 06:51:52 CET 2017


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.

TODO(sjg at chromium.org): Update the other GPIO drivers

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/gpio/gpio-uclass.c | 56 ++++++++++++++++++++++++++++------------------
 drivers/gpio/sandbox.c     |  4 +++-
 include/asm-generic/gpio.h |  6 +++--
 3 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 9ab9df4ce7a..721e95cd929 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -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 of_ref_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 of_ref_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, of_node_ref node_ref,
+			     struct of_ref_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;
-
+	if (ret)
+		goto err;
 	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__);
-		goto err;
-	}
 
-	ret = uclass_get_device_by_of_offset(UCLASS_GPIO, args.node,
-					     &desc->dev);
+	ret = uclass_get_device_by_of_ref(UCLASS_GPIO, args->node_ref,
+					  &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),
+			       of_ref_get_name(node_ref),
 			       list_name, index);
 	if (ret) {
 		debug("%s: dm_gpio_requestf failed\n", __func__);
@@ -687,10 +679,30 @@ 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__, of_ref_get_name(node_ref), 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 fdtdec_phandle_args fdtdec_args;
+	struct of_ref_phandle_args args;
+	int ret;
+
+	ret = fdtdec_parse_phandle_with_args(blob, node, list_name,
+					"#gpio-cells", 0, index, &fdtdec_args);
+	if (ret)
+		debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
+	else
+		of_ref_from_fdtdec_phandle_args(&fdtdec_args, &args);
+
+	return gpio_request_tail(ret, of_offset_to_ref(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)
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index ae6d93013f7..5bf6bb127d1 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -8,6 +8,8 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
+#include <dm/of.h>
+#include <dm/of_dev.h>
 #include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -165,7 +167,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 of_ref_phandle_args *args)
 {
 	desc->offset = args->args[0];
 	if (args->args_count < 2)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 4aa0004fab4..f3341e51359 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -7,6 +7,8 @@
 #ifndef _ASM_GENERIC_GPIO_H_
 #define _ASM_GENERIC_GPIO_H_
 
+struct of_ref_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 of_ref_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 of_ref_phandle_args *args);
 };
 
 /**
-- 
2.11.0.483.g087da7b7c-goog



More information about the U-Boot mailing list