Skip to content

Commit

Permalink
Fixes i2c_bcm2708: Write to FIFO correctly - v2 (#1574)
Browse files Browse the repository at this point in the history
* i2c: fix i2c_bcm2708: Clear FIFO before sending data

Make sure FIFO gets cleared before trying to send
data in case of a repeated start (COMBINED=Y).

* i2c: fix i2c_bcm2708: Only write to FIFO when not full

Check if FIFO can accept data before writing.
To avoid a peripheral read on the last iteration of a loop,
both bcm2708_bsc_fifo_fill and ~drain are changed as well.
  • Loading branch information
SimonMaes authored and popcornmix committed Aug 30, 2016
1 parent 8013ed5 commit 82ef2db
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/i2c/busses/i2c-bcm2708.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)

static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
{
while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_RXD))
bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
}

static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
{
while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_TXD))
bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
}

Expand Down Expand Up @@ -155,6 +155,10 @@ static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
if ( (bi->nmsgs > 1) &&
!(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
(bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {

/* Clear FIFO */
bcm2708_wr(bi, BSC_C, BSC_C_CLEAR_1);

/* Fill FIFO with entire write message (16 byte FIFO) */
while (bi->pos < bi->msg->len) {
bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
Expand Down

0 comments on commit 82ef2db

Please sign in to comment.