aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2012-11-14 09:22:45 -0500
committerWolfram Sang <w.sang@pengutronix.de>2012-11-14 11:43:03 -0500
commitaedc256dd032fe9b0691fdd0f67b5e65e3e7bc0d (patch)
treebd50f331923de6ae14eedb6874e066dc1bb41f6b /drivers/i2c
parent9aadd70aed60b47e367e7a1a6b9068daba04fe05 (diff)
i2c: omap: ensure writes to dev->buf_len are ordered
if we allow compiler reorder our writes, we could fall into a situation where dev->buf_len is reset for no apparent reason. This bug was found with a simple script which would transfer data to an i2c client from 1 to 1024 bytes (a simple for loop), when we got to transfer sizes bigger than the fifo size, dev->buf_len was reset to zero before we had an oportunity to handle XDR Interrupt. Because dev->buf_len was zero, we entered omap_i2c_transmit_data() to transfer zero bytes, which would mean we would just silently exit omap_i2c_transmit_data() without actually writing anything to DATA register. That would cause XDR IRQ to trigger forever and we would never transfer the remaining bytes. After adding the memory barrier, we also drop resetting dev->buf_len to zero in omap_i2c_xfer_msg() because both omap_i2c_transmit_data() and omap_i2c_receive_data() will act until dev->buf_len reaches zero, rendering the other write in omap_i2c_xfer_msg() redundant. This patch has been tested with pandaboard for a few iterations of the script mentioned above. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-omap.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 0b0254312d21..3525c9e62cb0 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -524,6 +524,9 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
524 dev->buf = msg->buf; 524 dev->buf = msg->buf;
525 dev->buf_len = msg->len; 525 dev->buf_len = msg->len;
526 526
527 /* make sure writes to dev->buf_len are ordered */
528 barrier();
529
527 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 530 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len);
528 531
529 /* Clear the FIFO Buffers */ 532 /* Clear the FIFO Buffers */
@@ -581,7 +584,6 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
581 */ 584 */
582 timeout = wait_for_completion_timeout(&dev->cmd_complete, 585 timeout = wait_for_completion_timeout(&dev->cmd_complete,
583 OMAP_I2C_TIMEOUT); 586 OMAP_I2C_TIMEOUT);
584 dev->buf_len = 0;
585 if (timeout == 0) { 587 if (timeout == 0) {
586 dev_err(dev->dev, "controller timed out\n"); 588 dev_err(dev->dev, "controller timed out\n");
587 omap_i2c_init(dev); 589 omap_i2c_init(dev);