Merge git://www.denx.de/git/u-boot-cfi-flash
[oweals/u-boot.git] / drivers / i2c / sandbox_i2c.c
index dd1c7e59e4b886fcb638d7e270cdfc78dcf34f23..2c84c41643c8b442dea3634ac36367b97903b917 100644 (file)
@@ -26,6 +26,7 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
                    struct dm_i2c_ops **opsp)
 {
        struct dm_i2c_chip *plat;
+       struct udevice *child;
        int ret;
 
        *devp = NULL;
@@ -37,9 +38,22 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
                if (ret)
                        return ret;
 
-               ret = device_get_child(dev, 0, &plat->emul);
-               if (ret)
-                       return ret;
+               for (device_find_first_child(dev, &child); child;
+                    device_find_next_child(&child)) {
+                       if (device_get_uclass_id(child) != UCLASS_I2C_EMUL)
+                               continue;
+
+                       ret = device_probe(child);
+                       if (ret)
+                               return ret;
+
+                       break;
+               }
+
+               if (child)
+                       plat->emul = child;
+               else
+                       return -ENODEV;
        }
        *devp = plat->emul;
        *opsp = i2c_get_ops(plat->emul);