Re: [U-Boot] [PATCH v2 11/17] dm: i2c: Add a sandbox I2C driver

2014-11-16 Thread Tom Rini
On Tue, Nov 11, 2014 at 10:46:27AM -0700, Simon Glass wrote:

 This driver includes some test features such as only supporting certain
 bus speeds. It passes its I2C traffic through to an emulator.
 
 Signed-off-by: Simon Glass s...@chromium.org

Reviewed-by: Tom Rini tr...@ti.com

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 11/17] dm: i2c: Add a sandbox I2C driver

2014-11-16 Thread Heiko Schocher

Hello Simon,

Am 11.11.2014 18:46, schrieb Simon Glass:

This driver includes some test features such as only supporting certain
bus speeds. It passes its I2C traffic through to an emulator.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2: None

  drivers/i2c/Makefile  |   2 +-
  drivers/i2c/sandbox_i2c.c | 148 ++
  2 files changed, 149 insertions(+), 1 deletion(-)
  create mode 100644 drivers/i2c/sandbox_i2c.c


Acked-by: Heiko Schocher h...@denx.de

bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 11/17] dm: i2c: Add a sandbox I2C driver

2014-11-11 Thread Simon Glass
This driver includes some test features such as only supporting certain
bus speeds. It passes its I2C traffic through to an emulator.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2: None

 drivers/i2c/Makefile  |   2 +-
 drivers/i2c/sandbox_i2c.c | 148 ++
 2 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i2c/sandbox_i2c.c

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 4c9db51..eba3a71 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -27,7 +27,7 @@ obj-$(CONFIG_SYS_I2C_OMAP34XX) += omap24xx_i2c.o
 obj-$(CONFIG_SYS_I2C_PPC4XX) += ppc4xx_i2c.o
 obj-$(CONFIG_SYS_I2C_RCAR) += rcar_i2c.o
 obj-$(CONFIG_SYS_I2C_S3C24X0) += s3c24x0_i2c.o
-obj-$(CONFIG_SYS_I2C_SANDBOX) += i2c-emul-uclass.o
+obj-$(CONFIG_SYS_I2C_SANDBOX) += sandbox_i2c.o i2c-emul-uclass.o
 obj-$(CONFIG_SYS_I2C_SH) += sh_i2c.o
 obj-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o
 obj-$(CONFIG_SYS_I2C_TEGRA) += tegra_i2c.o
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
new file mode 100644
index 000..3beb0f9
--- /dev/null
+++ b/drivers/i2c/sandbox_i2c.c
@@ -0,0 +1,148 @@
+/*
+ * 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 dm/lists.h
+#include dm/device-internal.h
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct dm_sandbox_i2c_emul_priv {
+   struct udevice *emul;
+};
+
+static int get_emul(struct udevice *bus, uint chip_addr, struct udevice **devp,
+   struct dm_i2c_ops **opsp)
+{
+   const void *blob = gd-fdt_blob;
+   struct dm_i2c_chip *priv;
+   struct udevice *dev;
+   int ret;
+
+   ret = i2c_get_chip(bus, chip_addr, dev);
+   if (ret)
+   return ret;
+   priv = dev_get_parentdata(dev);
+   if (!priv-emul) {
+   int node;
+
+   debug(Scanning i2c bus '%s' for devices\n, dev-name);
+   for (node = fdt_first_subnode(blob, dev-of_offset);
+   node = 0;
+   node = fdt_next_subnode(blob, node)) {
+   int ret;
+
+   ret = lists_bind_fdt(dev, blob, node, priv-emul);
+   if (ret)
+   return ret;
+   debug(Found emul '%s' for i2c device '%s'\n,
+ priv-emul-name, dev-name);
+   break;
+   }
+   }
+
+   if (!priv-emul)
+   return -ENODEV;
+   ret = device_probe(priv-emul);
+   if (ret)
+   return ret;
+   *devp = priv-emul;
+   *opsp = i2c_get_ops(priv-emul);
+
+   return 0;
+}
+
+static int sandbox_i2c_probe_chip(struct udevice *bus, uint chip_addr)
+{
+   struct dm_i2c_ops *ops;
+   struct udevice *emul;
+   int ret;
+
+   ret = get_emul(bus, chip_addr, emul, ops);
+   if (ret)
+   return ret;
+
+   return ops-probe(emul, chip_addr);
+}
+
+static int sandbox_i2c_read(struct udevice *bus, uint chip_addr, uint addr,
+   uint alen, uint8_t *buffer, int len)
+{
+   struct dm_i2c_bus *i2c = bus-uclass_priv;
+   struct dm_i2c_ops *ops;
+   struct udevice *emul;
+   int ret;
+
+   ret = get_emul(bus, chip_addr, emul, ops);
+   if (ret)
+   return ret;
+
+   /* For testing, don't allow reading above 400KHz */
+   if (i2c-speed_hz  40 || alen != 1)
+   return -EINVAL;
+   return ops-read(emul, chip_addr, addr, alen, buffer, len);
+}
+
+static int sandbox_i2c_write(struct udevice *bus, uint chip_addr, uint addr,
+uint alen, const uint8_t *buffer, int len)
+{
+   struct dm_i2c_bus *i2c = bus-uclass_priv;
+   struct dm_i2c_ops *ops;
+   struct udevice *emul;
+   int ret;
+
+   ret = get_emul(bus, chip_addr, emul, ops);
+   if (ret)
+   return ret;
+
+   /* For testing, don't allow writing above 100KHz */
+   if (i2c-speed_hz  10 || alen != 1)
+   return -EINVAL;
+   return ops-write(emul, chip_addr, addr, alen, buffer, len);
+}
+
+static int sandbox_i2c_set_addr_len(struct udevice *dev, uint addr_len)
+{
+   if (addr_len == 3)
+   return -EINVAL;
+
+   return 0;
+}
+
+static const struct dm_i2c_ops sandbox_i2c_ops = {
+   .probe  = sandbox_i2c_probe_chip,
+   .read   = sandbox_i2c_read,
+   .write  = sandbox_i2c_write,
+   .set_addr_len   = sandbox_i2c_set_addr_len,
+};
+
+static int sandbox_i2c_child_pre_probe(struct udevice *dev)
+{
+   struct dm_i2c_chip *i2c_chip = dev_get_parentdata(dev);
+
+   return i2c_chip_ofdata_to_platdata(gd-fdt_blob, dev-of_offset,
+  i2c_chip);
+}
+
+static const struct