brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0495-Fixes-i2c_bcm2708-Write-to-FIFO-correctly-v2-1574.patch
1 From 8ef9146c4479db1a672d7a88099e052a409624fa Mon Sep 17 00:00:00 2001
2 From: Simon Maes <simonn.maes@gmail.com>
3 Date: Mon, 29 Aug 2016 21:11:01 +0200
4 Subject: [PATCH] Fixes i2c_bcm2708: Write to FIFO correctly - v2 (#1574)
5
6 * i2c: fix i2c_bcm2708: Clear FIFO before sending data
7
8 Make sure FIFO gets cleared before trying to send
9 data in case of a repeated start (COMBINED=Y).
10
11 * i2c: fix i2c_bcm2708: Only write to FIFO when not full
12
13 Check if FIFO can accept data before writing.
14 To avoid a peripheral read on the last iteration of a loop,
15 both bcm2708_bsc_fifo_fill and ~drain are changed as well.
16 ---
17 drivers/i2c/busses/i2c-bcm2708.c | 8 ++++++--
18 1 file changed, 6 insertions(+), 2 deletions(-)
19
20 --- a/drivers/i2c/busses/i2c-bcm2708.c
21 +++ b/drivers/i2c/busses/i2c-bcm2708.c
22 @@ -115,13 +115,13 @@ static inline void bcm2708_bsc_reset(str
23
24 static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
25 {
26 - while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
27 + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_RXD))
28 bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
29 }
30
31 static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
32 {
33 - while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
34 + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_TXD))
35 bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
36 }
37
38 @@ -155,6 +155,10 @@ static inline int bcm2708_bsc_setup(stru
39 if ( (bi->nmsgs > 1) &&
40 !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
41 (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
42 +
43 + /* Clear FIFO */
44 + bcm2708_wr(bi, BSC_C, BSC_C_CLEAR_1);
45 +
46 /* Fill FIFO with entire write message (16 byte FIFO) */
47 while (bi->pos < bi->msg->len) {
48 bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);