[U-Boot,v2,50/53] reset: Get the RESET by index without device

Message ID 20180810060711.6547-51-jagan@amarulasolutions.com
State New
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series
  • clk: Add Allwinner CLK, RESET support
Related show

Commit Message

Jagan Teki Aug. 10, 2018, 6:07 a.m.
Getting a RESET by index with device is not straight forward
for some use-cases like handling clock operations for child
node in parent driver. So we need to process the child node
in parent probe via ofnode and process RESET operation for child
without udevice but with ofnode.

So add reset_get_by_index_nodev() and move the common code
in reset_get_by_index_tail() to use for reset_get_by_index()

Cc: Simon Glass <sjg@chromium.org>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 drivers/reset/reset-uclass.c | 53 ++++++++++++++++++++++++------------
 include/reset.h              | 16 +++++++++++
 2 files changed, 52 insertions(+), 17 deletions(-)

Patch

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index 6320efcb49..755bbf7a5e 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -34,41 +34,34 @@  static int reset_of_xlate_default(struct reset_ctl *reset_ctl,
 	return 0;
 }
 
-int reset_get_by_index(struct udevice *dev, int index,
-		       struct reset_ctl *reset_ctl)
+static int reset_get_by_index_tail(int ret, ofnode node,
+				   struct ofnode_phandle_args *args,
+				   const char *list_name, int index,
+				   struct reset_ctl *reset_ctl)
 {
-	struct ofnode_phandle_args args;
-	int ret;
 	struct udevice *dev_reset;
 	struct reset_ops *ops;
 
-	debug("%s(dev=%p, index=%d, reset_ctl=%p)\n", __func__, dev, index,
-	      reset_ctl);
+	assert(reset_ctl);
 	reset_ctl->dev = NULL;
-
-	ret = dev_read_phandle_with_args(dev, "resets", "#reset-cells", 0,
-					  index, &args);
-	if (ret) {
-		debug("%s: fdtdec_parse_phandle_with_args() failed: %d\n",
-		      __func__, ret);
+	if (ret)
 		return ret;
-	}
 
-	ret = uclass_get_device_by_ofnode(UCLASS_RESET, args.node,
+	ret = uclass_get_device_by_ofnode(UCLASS_RESET, args->node,
 					  &dev_reset);
 	if (ret) {
 		debug("%s: uclass_get_device_by_ofnode() failed: %d\n",
 		      __func__, ret);
-		debug("%s %d\n", ofnode_get_name(args.node), args.args[0]);
+		debug("%s %d\n", ofnode_get_name(args->node), args->args[0]);
 		return ret;
 	}
 	ops = reset_dev_ops(dev_reset);
 
 	reset_ctl->dev = dev_reset;
 	if (ops->of_xlate)
-		ret = ops->of_xlate(reset_ctl, &args);
+		ret = ops->of_xlate(reset_ctl, args);
 	else
-		ret = reset_of_xlate_default(reset_ctl, &args);
+		ret = reset_of_xlate_default(reset_ctl, args);
 	if (ret) {
 		debug("of_xlate() failed: %d\n", ret);
 		return ret;
@@ -86,6 +79,32 @@  int reset_get_by_index(struct udevice *dev, int index,
 	return 0;
 }
 
+int reset_get_by_index(struct udevice *dev, int index,
+		       struct reset_ctl *reset_ctl)
+{
+	struct ofnode_phandle_args args;
+	int ret;
+
+	ret = dev_read_phandle_with_args(dev, "resets", "#reset-cells", 0,
+					 index, &args);
+
+	return reset_get_by_index_tail(ret, dev_ofnode(dev), &args, "resets",
+				       index > 0, reset_ctl);
+}
+
+int reset_get_by_index_nodev(ofnode node, int index,
+			     struct reset_ctl *reset_ctl)
+{
+	struct ofnode_phandle_args args;
+	int ret;
+
+	ret = ofnode_parse_phandle_with_args(node, "resets", "#reset-cells", 0,
+					     index > 0, &args);
+
+	return reset_get_by_index_tail(ret, node, &args, "resets",
+				       index > 0, reset_ctl);
+}
+
 int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
 {
 	int i, ret, err, count;
diff --git a/include/reset.h b/include/reset.h
index 70130bb886..581cc2579b 100644
--- a/include/reset.h
+++ b/include/reset.h
@@ -6,6 +6,7 @@ 
 #ifndef _RESET_H
 #define _RESET_H
 
+#include <dm/ofnode.h>
 #include <linux/errno.h>
 
 /**
@@ -97,6 +98,21 @@  struct reset_ctl_bulk {
 int reset_get_by_index(struct udevice *dev, int index,
 		       struct reset_ctl *reset_ctl);
 
+/**
+ * reset_get_by_index_nodev - Get/request a reset signal by integer index
+ * without a device.
+ *
+ * This is a version of reset_get_by_index() that does not use a device.
+ *
+ * @node:	The client ofnode.
+ * @index:	The index of the reset signal to request, within the client's
+ *		list of reset signals.
+ * @reset_ctl	A pointer to a reset control struct to initialize.
+ * @return 0 if OK, or a negative error code.
+ */
+int reset_get_by_index_nodev(ofnode node, int index,
+			     struct reset_ctl *reset_ctl);
+
 /**
  * reset_get_bulk - Get/request all reset signals of a device.
  *