0495-Fixes-i2c_bcm2708-Write-to-FIFO-correctly-v2-1574.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From 1bb11b1cfccb209ca841878ec650538e972a34ab 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. * i2c: fix i2c_bcm2708: Clear FIFO before sending data
  6. Make sure FIFO gets cleared before trying to send
  7. data in case of a repeated start (COMBINED=Y).
  8. * i2c: fix i2c_bcm2708: Only write to FIFO when not full
  9. Check if FIFO can accept data before writing.
  10. To avoid a peripheral read on the last iteration of a loop,
  11. both bcm2708_bsc_fifo_fill and ~drain are changed as well.
  12. ---
  13. drivers/i2c/busses/i2c-bcm2708.c | 8 ++++++--
  14. 1 file changed, 6 insertions(+), 2 deletions(-)
  15. --- a/drivers/i2c/busses/i2c-bcm2708.c
  16. +++ b/drivers/i2c/busses/i2c-bcm2708.c
  17. @@ -115,13 +115,13 @@ static inline void bcm2708_bsc_reset(str
  18. static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  19. {
  20. - while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  21. + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_RXD))
  22. bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  23. }
  24. static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  25. {
  26. - while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  27. + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_TXD))
  28. bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  29. }
  30. @@ -155,6 +155,10 @@ static inline int bcm2708_bsc_setup(stru
  31. if ( (bi->nmsgs > 1) &&
  32. !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  33. (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  34. +
  35. + /* Clear FIFO */
  36. + bcm2708_wr(bi, BSC_C, BSC_C_CLEAR_1);
  37. +
  38. /* Fill FIFO with entire write message (16 byte FIFO) */
  39. while (bi->pos < bi->msg->len) {
  40. bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);