Skip to content

Commit

Permalink
i2c-designware: i2c_dw_xfer_msg: Fix i2c_msg search bug
Browse files Browse the repository at this point in the history
In case a work-in-progress i2c_msg has more bytes to be written, we
need to set STATUS_WRITE_IN_PROGRESS and exit from the msg_write_idx-
searching loop.  Otherwise, we will overtake the current msg_write_idx
without waiting for its transmission to be processed.

Signed-off-by: Shinya Kuribayashi <shinya.kuribayashi@necel.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
  • Loading branch information
Shinya Kuribayashi authored and Ben Dooks committed Dec 9, 2009
1 parent d60c7e8 commit c70c5cd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions drivers/i2c/busses/i2c-designware.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
u32 addr = msgs[dev->msg_write_idx].addr;
u32 buf_len = dev->tx_buf_len;

intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;

if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
/* Disable the adapter */
writel(0, dev->base + DW_IC_ENABLE);
Expand Down Expand Up @@ -387,17 +389,19 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
dev->base + DW_IC_DATA_CMD);
tx_limit--; buf_len--;
}

dev->tx_buf_len = buf_len;

if (buf_len > 0) {
/* more bytes to be written */
intr_mask |= DW_IC_INTR_TX_EMPTY;
dev->status |= STATUS_WRITE_IN_PROGRESS;
break;
} else
dev->status &= ~STATUS_WRITE_IN_PROGRESS;
}

intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;
if (buf_len > 0) { /* more bytes to be written */
intr_mask |= DW_IC_INTR_TX_EMPTY;
dev->status |= STATUS_WRITE_IN_PROGRESS;
} else
dev->status &= ~STATUS_WRITE_IN_PROGRESS;
writel(intr_mask, dev->base + DW_IC_INTR_MASK);

dev->tx_buf_len = buf_len;
}

static void
Expand Down

0 comments on commit c70c5cd

Please sign in to comment.