summaryrefslogtreecommitdiff
path: root/drivers/i2c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-04-20 12:37:15 -0600
committerSimon Glass <sjg@chromium.org>2015-05-05 20:58:19 -0600
commit182bf92d19cf007c2d6b9a264107d6996ae9014f (patch)
treed73c8abc54efc11cf05e39f891dd57560448c8d9 /drivers/i2c
parentba3864f8037f58dd1f46cad3b76adc0a84bd33b3 (diff)
downloadu-boot-imx-182bf92d19cf007c2d6b9a264107d6996ae9014f.zip
u-boot-imx-182bf92d19cf007c2d6b9a264107d6996ae9014f.tar.gz
u-boot-imx-182bf92d19cf007c2d6b9a264107d6996ae9014f.tar.bz2
dm: i2c: Add an explicit test mode to the sandbox I2C driver
At present this driver has a few test features. They are needed for running the driver model unit tests but are confusing and unnecessary if using sandbox at the command line. Add a flag to enable the test mode, and don't enable it by default. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/sandbox_i2c.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
index 621caec..dd1c7e5 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -18,8 +18,8 @@
DECLARE_GLOBAL_DATA_PTR;
-struct dm_sandbox_i2c_emul_priv {
- struct udevice *emul;
+struct sandbox_i2c_priv {
+ bool test_mode;
};
static int get_emul(struct udevice *dev, struct udevice **devp,
@@ -47,17 +47,25 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
return 0;
}
+void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode)
+{
+ struct sandbox_i2c_priv *priv = dev_get_priv(bus);
+
+ priv->test_mode = test_mode;
+}
+
static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
int nmsgs)
{
struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
+ struct sandbox_i2c_priv *priv = dev_get_priv(bus);
struct dm_i2c_ops *ops;
struct udevice *emul, *dev;
bool is_read;
int ret;
/* Special test code to return success but with no emulation */
- if (msg->addr == SANDBOX_I2C_TEST_ADDR)
+ if (priv->test_mode && msg->addr == SANDBOX_I2C_TEST_ADDR)
return 0;
ret = i2c_get_chip(bus, msg->addr, 1, &dev);
@@ -68,15 +76,18 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
if (ret)
return ret;
- /*
- * For testing, don't allow writing above 100KHz for writes and
- * 400KHz for reads
- */
- is_read = nmsgs > 1;
- if (i2c->speed_hz > (is_read ? 400000 : 100000)) {
- debug("%s: Max speed exceeded\n", __func__);
- return -EINVAL;
+ if (priv->test_mode) {
+ /*
+ * For testing, don't allow writing above 100KHz for writes and
+ * 400KHz for reads.
+ */
+ is_read = nmsgs > 1;
+ if (i2c->speed_hz > (is_read ? 400000 : 100000)) {
+ debug("%s: Max speed exceeded\n", __func__);
+ return -EINVAL;
+ }
}
+
return ops->xfer(emul, msg, nmsgs);
}
@@ -94,4 +105,5 @@ U_BOOT_DRIVER(i2c_sandbox) = {
.id = UCLASS_I2C,
.of_match = sandbox_i2c_ids,
.ops = &sandbox_i2c_ops,
+ .priv_auto_alloc_size = sizeof(struct sandbox_i2c_priv),
};