]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: i2c: Add functions to read and write a register
authorSimon Glass <sjg@chromium.org>
Mon, 20 Apr 2015 18:37:14 +0000 (12:37 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:37:13 +0000 (22:37 +0200)
Add driver model versions of the legacy functions to read and write a
single byte register. These are a useful shortcut in many cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Heiko Schocher <hs@denx.de>
drivers/i2c/i2c-uclass.c
include/i2c.h

index f2e95c0881a76d82436df7f3114e67a2d5632457..b8eb2d613f2fb33a896d35668e4605b0bd15c4b9 100644 (file)
@@ -186,6 +186,25 @@ int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer,
        }
 }
 
+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
  *
index 6fd73fae4ccc01c3c1aa5a45023b04dd22e24b37..d794057f4b9f77bfcef5b8fff5814ea7643538e8 100644 (file)
@@ -123,6 +123,27 @@ int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer,
 int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,
                 struct udevice **devp);
 
+/**
+ * dm_i2c_reg_read() - Read a value from an I2C register
+ *
+ * This reads a single value from the given address in an I2C chip
+ *
+ * @addr:      Address to read from
+ * @return value read, or -ve on error
+ */
+int dm_i2c_reg_read(struct udevice *dev, uint offset);
+
+/**
+ * dm_i2c_reg_write() - Write a value to an I2C register
+ *
+ * This writes a single value to the given address in an I2C chip
+ *
+ * @addr:      Address to write to
+ * @val:       Value to write (normally a byte)
+ * @return 0 on success, -ve on error
+ */
+int dm_i2c_reg_write(struct udevice *dev, uint offset, unsigned int val);
+
 /**
  * dm_i2c_set_bus_speed() - set the speed of a bus
  *