diff mbox

[RFC,2/3] i2c: omap: implement handling for 'actual' bytes transferred

Message ID 1340967927-27354-3-git-send-email-shubhrajyoti@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shubhrajyoti Datta June 29, 2012, 11:05 a.m. UTC
From: Felipe Balbi <balbi@ti.com>

this is important in cases where client driver
wants to know how many bytes were actually
transferred.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
---
 drivers/i2c/busses/i2c-omap.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 266bba7..fc726a6 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -189,6 +189,7 @@  struct omap_i2c_dev {
 	u8			*buf;
 	u8			*regs;
 	size_t			buf_len;
+	u16			actual;
 	struct i2c_adapter	adapter;
 	u8			threshold;
 	u8			fifo_size;	/* use as flag and value
@@ -601,6 +602,7 @@  static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
 		omap_i2c_init(dev);
 		return -ETIMEDOUT;
 	}
+	msg->actual = dev->actual;
 
 	if (likely(!dev->cmd_err))
 		return 0;
@@ -828,6 +830,7 @@  static void omap_i2c_receive_data(struct omap_i2c_dev *dev, u8 num_bytes,
 		w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
 		*dev->buf++ = w;
 		dev->buf_len--;
+		dev->actual++;
 
 		/*
 		 * Data reg in 2430, omap3 and
@@ -848,6 +851,7 @@  static int omap_i2c_transmit_data(struct omap_i2c_dev *dev, u8 num_bytes,
 	while (num_bytes--) {
 		w = *dev->buf++;
 		dev->buf_len--;
+		dev->actual++;
 
 		/*
 		 * Data reg in 2430, omap3 and
@@ -908,6 +912,7 @@  omap_i2c_isr(int this_irq, void *dev_id)
 
 		if (stat & OMAP_I2C_STAT_NACK) {
 			err |= OMAP_I2C_STAT_NACK;
+			dev->actual--;
 			omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK);
 			goto out;
 		}