]> git.sur5r.net Git - u-boot/blobdiff - drivers/core/uclass.c
dm: core: Replace of_offset with accessor
[u-boot] / drivers / core / uclass.c
index 1141ce1ba3ccd0d22a081674e2f038b9a1b93c81..7de370644d72c6ff9232b9f1f6337495ae318aae 100644 (file)
@@ -148,6 +148,15 @@ int uclass_get(enum uclass_id id, struct uclass **ucp)
        return 0;
 }
 
+const char *uclass_get_name(enum uclass_id id)
+{
+       struct uclass *uc;
+
+       if (uclass_get(id, &uc))
+               return NULL;
+       return uc->uc_drv->name;
+}
+
 int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
 {
        struct uclass *uc;
@@ -269,7 +278,7 @@ int uclass_find_device_by_of_offset(enum uclass_id id, int node,
                return ret;
 
        list_for_each_entry(dev, &uc->dev_head, uclass_node) {
-               if (dev->of_offset == node) {
+               if (dev_of_offset(dev) == node) {
                        *devp = dev;
                        return 0;
                }
@@ -290,7 +299,7 @@ static int uclass_find_device_by_phandle(enum uclass_id id,
        int ret;
 
        *devp = NULL;
-       find_phandle = fdtdec_get_int(gd->fdt_blob, parent->of_offset, name,
+       find_phandle = fdtdec_get_int(gd->fdt_blob, dev_of_offset(parent), name,
                                      -1);
        if (find_phandle <= 0)
                return -ENOENT;
@@ -299,7 +308,9 @@ static int uclass_find_device_by_phandle(enum uclass_id id,
                return ret;
 
        list_for_each_entry(dev, &uc->dev_head, uclass_node) {
-               uint phandle = fdt_get_phandle(gd->fdt_blob, dev->of_offset);
+               uint phandle;
+
+               phandle = fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
 
                if (phandle == find_phandle) {
                        *devp = dev;
@@ -311,6 +322,26 @@ static int uclass_find_device_by_phandle(enum uclass_id id,
 }
 #endif
 
+int uclass_get_device_by_driver(enum uclass_id id,
+                               const struct driver *find_drv,
+                               struct udevice **devp)
+{
+       struct udevice *dev;
+       struct uclass *uc;
+       int ret;
+
+       ret = uclass_get(id, &uc);
+       if (ret)
+               return ret;
+
+       list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+               if (dev->driver == find_drv)
+                       return uclass_get_device_tail(dev, 0, devp);
+       }
+
+       return -ENODEV;
+}
+
 int uclass_get_device_tail(struct udevice *dev, int ret,
                                  struct udevice **devp)
 {