Re: [U-Boot] [PATCH v3 24/26] dm: cros_ec: Move cros_ec_i2c over to driver model

2015-01-26 Thread Simon Glass
On 25 January 2015 at 08:27, Simon Glass s...@chromium.org wrote:
 Update the driver model support, and remove the old code. Change snow to
 use this new support.

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

 Changes in v3: None
 Changes in v2:
 - Add patches to tidy up cros_ec using new I2C/SPI features

  drivers/misc/cros_ec_i2c.c | 107 
 +
  include/configs/snow.h |   5 +++
  2 files changed, 45 insertions(+), 67 deletions(-)

Applied to -u-boot-dm
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3 24/26] dm: cros_ec: Move cros_ec_i2c over to driver model

2015-01-26 Thread Simon Glass
On 26 January 2015 at 13:14, Simon Glass s...@chromium.org wrote:
 On 25 January 2015 at 08:27, Simon Glass s...@chromium.org wrote:
 Update the driver model support, and remove the old code. Change snow to
 use this new support.

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

 Changes in v3: None
 Changes in v2:
 - Add patches to tidy up cros_ec using new I2C/SPI features

  drivers/misc/cros_ec_i2c.c | 107 
 +
  include/configs/snow.h |   5 +++
  2 files changed, 45 insertions(+), 67 deletions(-)

 Applied to -u-boot-dm

Sorry, I'm getting ahead of myself. I cannot apply this until the
Samsung I2C driver is applied. So I'm leaving this patch out for now
and will revisit hopefully later in the week.

- Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 24/26] dm: cros_ec: Move cros_ec_i2c over to driver model

2015-01-25 Thread Simon Glass
Update the driver model support, and remove the old code. Change snow to
use this new support.

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

Changes in v3: None
Changes in v2:
- Add patches to tidy up cros_ec using new I2C/SPI features

 drivers/misc/cros_ec_i2c.c | 107 +
 include/configs/snow.h |   5 +++
 2 files changed, 45 insertions(+), 67 deletions(-)

diff --git a/drivers/misc/cros_ec_i2c.c b/drivers/misc/cros_ec_i2c.c
index 513cdb1..c9d1b49 100644
--- a/drivers/misc/cros_ec_i2c.c
+++ b/drivers/misc/cros_ec_i2c.c
@@ -14,20 +14,16 @@
  */
 
 #include common.h
+#include dm.h
+#include errno.h
 #include i2c.h
 #include cros_ec.h
 
-#ifdef DEBUG_TRACE
-#define debug_trace(fmt, b...) debug(fmt, #b)
-#else
-#define debug_trace(fmt, b...)
-#endif
-
-int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+int cros_ec_i2c_command(struct udevice *udev, uint8_t cmd, int cmd_version,
 const uint8_t *dout, int dout_len,
 uint8_t **dinp, int din_len)
 {
-   int old_bus = 0;
+   struct cros_ec_dev *dev = udev-uclass_priv;
/* version8, cmd8, arglen8, out8[dout_len], csum8 */
int out_bytes = dout_len + 4;
/* response8, arglen8, in8[din_len], checksum8 */
@@ -37,19 +33,17 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t 
cmd, int cmd_version,
uint8_t *in_ptr;
int len, csum, ret;
 
-   old_bus = i2c_get_bus_num();
-
/*
 * Sanity-check I/O sizes given transaction overhead in internal
 * buffers.
 */
if (out_bytes  sizeof(dev-dout)) {
debug(%s: Cannot send %d bytes\n, __func__, dout_len);
-   return -1;
+   return -ENOSPC;
}
if (in_bytes  sizeof(dev-din)) {
debug(%s: Cannot receive %d bytes\n, __func__, din_len);
-   return -1;
+   return -ENOSPC;
}
assert(dout_len = 0);
assert(dinp);
@@ -72,7 +66,7 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, 
int cmd_version,
/* Something we don't support */
debug(%s: Protocol version %d unsupported\n,
  __func__, dev-protocol_version);
-   return -1;
+   return -EPROTONOSUPPORT;
}
 
*ptr++ = EC_CMD_VERSION0 + cmd_version;
@@ -86,36 +80,18 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t 
cmd, int cmd_version,
*ptr++ = (uint8_t)
cros_ec_calc_checksum(dev-dout, dout_len + 3);
 
-   /* Set to the proper i2c bus */
-   if (i2c_set_bus_num(dev-bus_num)) {
-   debug(%s: Cannot change to I2C bus %d\n, __func__,
-   dev-bus_num);
-   return -1;
-   }
-
/* Send output data */
cros_ec_dump_data(out, -1, dev-dout, out_bytes);
-   ret = i2c_write(dev-addr, 0, 0, dev-dout, out_bytes);
-   if (ret) {
-   debug(%s: Cannot complete I2C write to 0x%x\n,
-   __func__, dev-addr);
-   ret = -1;
-   }
+   ret = dm_i2c_write(udev, 0, dev-dout, out_bytes);
+   if (ret)
+   debug(%s: Cannot complete I2C write\n, udev-name);
 
if (!ret) {
-   ret = i2c_read(dev-addr, 0, 0, in_ptr, in_bytes);
-   if (ret) {
-   debug(%s: Cannot complete I2C read from 0x%x\n,
-   __func__, dev-addr);
-   ret = -1;
-   }
+   ret = dm_i2c_read(udev, 0, in_ptr, in_bytes);
+   if (ret)
+   debug(%s: Cannot complete I2C read\n, udev-name);
}
 
-   /* Return to original bus number */
-   i2c_set_bus_num(old_bus);
-   if (ret)
-   return ret;
-
if (*in_ptr != EC_RES_SUCCESS) {
debug(%s: Received bad result code %d\n, __func__, *in_ptr);
return -(int)*in_ptr;
@@ -125,13 +101,13 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t 
cmd, int cmd_version,
if (len + 3  sizeof(dev-din)) {
debug(%s: Received length %#02x too large\n,
  __func__, len);
-   return -1;
+   return -ENOSPC;
}
csum = cros_ec_calc_checksum(in_ptr, 2 + len);
if (csum != in_ptr[2 + len]) {
debug(%s: Invalid checksum rx %#02x, calced %#02x\n,
  __func__, in_ptr[2 + din_len], csum);
-   return -1;
+   return -EBADMSG;
}
din_len = min(din_len, len);
cros_ec_dump_data(in, -1, in_ptr, din_len + 3);
@@ -142,35 +118,32 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t 
cmd, int cmd_version,
return din_len;
 }
 
-int cros_ec_i2c_decode_fdt(struct cros_ec_dev *dev, const void *blob)
+static int cros_ec_probe(struct udevice *dev)
 {