i2c: ihs: Improve error handling
[oweals/u-boot.git] / drivers / i2c / sandbox_i2c.c
index f5978fda29b14fd26a5c1e5bfe3be9b53240e832..0dbbaa0c44730b86370b928bd67efc71dfae9ea3 100644 (file)
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Simulate an I2C port
  *
  * Copyright (c) 2014 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -14,8 +13,6 @@
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sandbox_i2c_priv {
        bool test_mode;
 };
@@ -24,33 +21,15 @@ 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_dev(dev);
+               ret = i2c_emul_find(dev, &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);