dm: Use driver_info index instead of pointer

At present we use a 'node' pointer in the of-platadata phandle_n_arg
structs. This is a pointer to the struct driver_info for a particular
device, and we can use it to obtain the struct udevice pointer itself.

Since we don't know the struct udevice pointer until it is allocated in
memory, we have to fix up the phandle_n_arg.node at runtime. This is
annoying since it requires that SPL's data is writable and adds a small
amount of extra (generated) code in the dm_populate_phandle_data()
function.

Now that we can find a driver_info by its index, it is easier to put the
index in the phandle_n_arg structures.

Update dtoc to do this, add a new device_get_by_driver_info_idx() to look
up a device by drive_info index and update the tests to match.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/include/dm/device.h b/include/dm/device.h
index 993c9e6..5bef484 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -554,6 +554,20 @@
 			      struct udevice **devp);
 
 /**
+ * device_get_by_driver_info_idx() - Get a device based on driver_info index
+ *
+ * Locates a device by its struct driver_info, by using its index number which
+ * is written into the idx field of struct phandle_1_arg, etc.
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @idx: Index number of the driver_info structure (0=first)
+ * @devp: Returns pointer to device if found, otherwise this is set to NULL
+ * @return 0 if OK, -ve on error
+ */
+int device_get_by_driver_info_idx(uint idx, struct udevice **devp);
+
+/**
  * device_find_first_child() - Find the first child of a device
  *
  * @parent: Parent device to search
diff --git a/include/dt-structs.h b/include/dt-structs.h
index eed8273..f0e1c9c 100644
--- a/include/dt-structs.h
+++ b/include/dt-structs.h
@@ -11,17 +11,17 @@
 struct driver_info;
 
 struct phandle_0_arg {
-	const struct driver_info *node;
+	uint idx;
 	int arg[0];
 };
 
 struct phandle_1_arg {
-	const struct driver_info *node;
+	uint idx;
 	int arg[1];
 };
 
 struct phandle_2_arg {
-	const struct driver_info *node;
+	uint idx;
 	int arg[2];
 };
 #include <generated/dt-structs-gen.h>