]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/i2c-uclass.c
omap24xx_i2c: Implement CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
[u-boot] / drivers / i2c / i2c-uclass.c
index f2e95c0881a76d82436df7f3114e67a2d5632457..50b99ead3d9fb4179940d2c6566a698d954028f5 100644 (file)
@@ -18,6 +18,22 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define I2C_MAX_OFFSET_LEN     4
 
+/* Useful debugging function */
+void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs)
+{
+       int i;
+
+       for (i = 0; i < nmsgs; i++) {
+               struct i2c_msg *m = &msg[i];
+
+               printf("   %s %x len=%x", m->flags & I2C_M_RD ? "R" : "W",
+                      msg->addr, msg->len);
+               if (!(m->flags & I2C_M_RD))
+                       printf(": %x", m->buf[0]);
+               printf("\n");
+       }
+}
+
 /**
  * i2c_setup_offset() - Set up a new message with a chip offset
  *
@@ -186,6 +202,36 @@ int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer,
        }
 }
 
+int dm_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs)
+{
+       struct udevice *bus = dev_get_parent(dev);
+       struct dm_i2c_ops *ops = i2c_get_ops(bus);
+
+       if (!ops->xfer)
+               return -ENOSYS;
+
+       return ops->xfer(bus, msg, nmsgs);
+}
+
+int dm_i2c_reg_read(struct udevice *dev, uint offset)
+{
+       uint8_t val;
+       int ret;
+
+       ret = dm_i2c_read(dev, offset, &val, 1);
+       if (ret < 0)
+               return ret;
+
+       return val;
+}
+
+int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value)
+{
+       uint8_t val = value;
+
+       return dm_i2c_write(dev, offset, &val, 1);
+}
+
 /**
  * i2c_probe_chip() - probe for a chip on a bus
  *
@@ -396,6 +442,13 @@ int i2c_set_chip_offset_len(struct udevice *dev, uint offset_len)
        return 0;
 }
 
+int i2c_get_chip_offset_len(struct udevice *dev)
+{
+       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
+
+       return chip->offset_len;
+}
+
 int i2c_deblock(struct udevice *bus)
 {
        struct dm_i2c_ops *ops = i2c_get_ops(bus);