From c589fc977669a99ddbd3416611d83375b21385f4 Mon Sep 17 00:00:00 2001 From: Simon Maes Date: Mon, 25 Jul 2016 14:39:08 +0100 Subject: [PATCH] i2c: fix i2c_bcm2708: avoid extra peripheral read 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. --- drivers/i2c/busses/i2c-bcm2708.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c index 2d469479930df..962f2e5c7455d 100644 --- a/drivers/i2c/busses/i2c-bcm2708.c +++ b/drivers/i2c/busses/i2c-bcm2708.c @@ -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++]); }