]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/sandbox_i2c.c
clk: rmobile: Add R8A77995 RPC clock
[u-boot] / drivers / i2c / sandbox_i2c.c
index dd1c7e59e4b886fcb638d7e270cdfc78dcf34f23..66578510849dbb770059136fd8cddb50b068296b 100644 (file)
@@ -1,22 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Simulate an I2C port
  *
  * Copyright (c) 2014 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <i2c.h>
 #include <asm/test.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
-#include <dm/root.h>
-
-DECLARE_GLOBAL_DATA_PTR;
 
 struct sandbox_i2c_priv {
        bool test_mode;
@@ -26,20 +21,33 @@ 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;
        *opsp = NULL;
        plat = dev_get_parent_platdata(dev);
        if (!plat->emul) {
-               ret = dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset,
-                                      false);
+               ret = dm_scan_fdt_dev(dev);
                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);