Initial implementation invokes device_bind_with_driver_data()
with driver_data parameter equal to 0.
For driver with driver data, the bind command can't bind
correctly this driver or even worse causes data abort.

Add find_udevice_id() to parse the driver's of_match list
and return the entry corresponding to the driver compatible string.
This allows to get access to driver_data and to use it as
parameters of device_bind_with_driver_data().

Signed-off-by: Patrice Chotard <patrice.chot...@st.com>
Cc: Jean-Jacques Hiblot <jjhib...@ti.com>

---

 cmd/bind.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/cmd/bind.c b/cmd/bind.c
index 44a5f17f0d..ab1844c855 100644
--- a/cmd/bind.c
+++ b/cmd/bind.c
@@ -118,6 +118,29 @@ static int unbind_child_by_class_index(const char *uclass, 
int index,
        return ret;
 }
 
+static const struct udevice_id *find_udevice_id(struct driver *drv,
+                                               ofnode ofnode)
+{
+       const char *compat_list, *compat;
+       const struct udevice_id *id;
+       int ret, compat_length, i;
+
+       compat_list = ofnode_get_property(ofnode, "compatible", &compat_length);
+       /*
+        * Walk through the compatible string list and find the corresponding
+        * udevice_id entry
+        */
+       for (i = 0; i < compat_length; i += strlen(compat) + 1) {
+               compat = compat_list + i;
+
+               ret = driver_check_compatible(drv->of_match, &id, compat);
+               if (!ret)
+                       break;
+       }
+
+       return id;
+}
+
 static int bind_by_node_path(const char *path, const char *drv_name)
 {
        struct udevice *dev;
@@ -125,6 +148,7 @@ static int bind_by_node_path(const char *path, const char 
*drv_name)
        int ret;
        ofnode ofnode;
        struct driver *drv;
+       const struct udevice_id *id;
 
        drv = lists_driver_lookup_name(drv_name);
        if (!drv) {
@@ -150,8 +174,11 @@ static int bind_by_node_path(const char *path, const char 
*drv_name)
        }
 
        ofnode = ofnode_path(path);
+       id = find_udevice_id(drv, ofnode);
+
        ret = device_bind_with_driver_data(parent, drv, ofnode_get_name(ofnode),
-                                          0, ofnode, &dev);
+                                          id->data, ofnode, &dev);
+
        if (!dev || ret) {
                printf("Unable to bind. err:%d\n", ret);
                return ret;
-- 
2.17.1

Reply via email to