summaryrefslogtreecommitdiffstats
path: root/drivers/i2c/sandbox_i2c.c
diff options
context:
space:
mode:
authorPrzemyslaw Marczak <p.marczak@samsung.com>2015-05-13 13:38:31 +0200
committerSimon Glass <sjg@chromium.org>2015-05-14 19:58:34 -0600
commita989ec8dd4bb548708220146391d5ed7b575331f (patch)
tree81daf490b4083fa4da0eb347844b2aab793d56b0 /drivers/i2c/sandbox_i2c.c
parent769c94865a4bb4b86e763ccd2a95c1bb3f0fe837 (diff)
downloadblackbird-obmc-uboot-a989ec8dd4bb548708220146391d5ed7b575331f.tar.gz
blackbird-obmc-uboot-a989ec8dd4bb548708220146391d5ed7b575331f.zip
sandbox: i2c: search child emul dev and check its uclass id
The function get_emul() in sandbox i2c bus driver, always returns first child as i2c emul device. This may only work for i2c devices with a single child, which is an only i2c emul device. In case when i2c device has more than one child (e.g. PMIC), and one is i2c emul, then the function should search it by check uclass id for each child. This patch add this change to the get_emul(). Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org> Tested on sandbox: Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/i2c/sandbox_i2c.c')
-rw-r--r--drivers/i2c/sandbox_i2c.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
index dd1c7e59e4..2c84c41643 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -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);
OpenPOWER on IntegriCloud