All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] i2c: davinci: Fix race when setting up for TX
@ 2010-09-17  2:46 Jon Povey
       [not found] ` <1284691607-9697-1-git-send-email-jon.povey-Ean/AyPsLtfkYMGBc/C6ZA@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Jon Povey @ 2010-09-17  2:46 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/
  Cc: troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR, Jon Povey

When setting up to transmit, a race exists between the ISR and
i2c_davinci_xfer_msg() trying to load the first byte and adjust counters.
This is mostly visible for transmits > 1 byte long.

The hardware starts sending immediately that MDR is loaded. IMR trickery
doesn't work because if we start sending, finish the first byte and an
XRDY event occurs before we load IMR to unmask it, we never get an
interrupt, and we timeout.

Move the MDR load after DXR,IMR loads to avoid this race without locking.

Tested on DM355 connected to Techwell TW2836 and Wolfson WM8985

Signed-off-by: Jon Povey <jon.povey-Ean/AyPsLtfkYMGBc/C6ZA@public.gmane.org>
---
Troy, thanks for the input. I tried reordering the IMR load before but got
occasional timeouts. Went back to the logic analyser today and worked out
why, see above comment in the commit message.

Moving the MDR load seems to fix things without locking, much neater and
tiny patch.

As I understand it we can be confident inside i2c_davinci_xfer_msg() that
the peripheral is not busy sending or receiving something else, I had a
look at the other interrupt sources in the datasheet and this seems safe
enough.

I'm not sure what the correct thing to do for followup message IDs here..
My original email? Troy's? Clues welcome for next time.

 drivers/i2c/busses/i2c-davinci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 72df4af..baa5209 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -349,9 +349,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 
 	dev->terminate = 0;
 
-	/* write the data into mode register */
-	davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
-
 	/*
 	 * First byte should be set here, not after interrupt,
 	 * because transmit-data-ready interrupt can come before
@@ -371,6 +368,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 		w |= DAVINCI_I2C_IMR_XRDY;
 	davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w);
 
+	/* write the data into mode register; start transmitting */
+	davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+
 	r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
 						      dev->adapter.timeout);
 	if (r == 0) {
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2010-10-12  4:48 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-17  2:46 [PATCH v2] i2c: davinci: Fix race when setting up for TX Jon Povey
     [not found] ` <1284691607-9697-1-git-send-email-jon.povey-Ean/AyPsLtfkYMGBc/C6ZA@public.gmane.org>
2010-09-17  3:02   ` [PATCH v3] " Jon Povey
     [not found]     ` <1284692531-10100-1-git-send-email-jon.povey-Ean/AyPsLtfkYMGBc/C6ZA@public.gmane.org>
2010-09-17 13:09       ` Sudhakar Rajashekhara
     [not found]     ` <001201cb5669$a0200940$e0601bc0$@raj@ti.com>
     [not found]       ` <001201cb5669$a0200940$e0601bc0$@raj-l0cyMroinI0@public.gmane.org>
2010-09-17 19:15         ` Troy Kisky
     [not found]           ` <4C93BE5B.6090701-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2010-09-20  4:40             ` Jon Povey
     [not found]               ` <70E876B0EA86DD4BAF101844BC814DFE093ED5F50E-lPJtnb2sqtq44ywRPIzf9A@public.gmane.org>
2010-09-20 21:14                 ` Troy Kisky
     [not found]                   ` <4C97CEC9.8060602-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2010-09-21  4:13                     ` [PATCH v4] " Jon Povey
     [not found]                       ` <1285042408-13200-1-git-send-email-jon.povey-Ean/AyPsLtfkYMGBc/C6ZA@public.gmane.org>
2010-09-21 11:24                         ` Sudhakar Rajashekhara
2010-09-24  4:42                         ` Sudhakar Rajashekhara
     [not found]                       ` <026901cb597f$86fa9980$94efcc80$@raj@ti.com>
     [not found]                         ` <026901cb597f$86fa9980$94efcc80$@raj-l0cyMroinI0@public.gmane.org>
2010-09-21 19:17                           ` Troy Kisky
     [not found]                             ` <4C9904E6.7070608-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2010-09-22  0:09                               ` Ben Dooks
     [not found]                                 ` <20100922000916.GH7494-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-09-22 10:50                                   ` Sudhakar Rajashekhara
2010-09-30 13:10                                   ` Kevin Hilman
     [not found]                                     ` <87wrq3l6m0.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-10-07  8:39                                       ` Jon Povey
     [not found]                                         ` <70E876B0EA86DD4BAF101844BC814DFE093EE3EA57-lPJtnb2sqtq44ywRPIzf9A@public.gmane.org>
2010-10-07 17:01                                           ` Kevin Hilman
     [not found]                                             ` <87wrpu9bsu.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-10-07 17:20                                               ` Kevin Hilman
     [not found]                                                 ` <87hbgxapig.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-10-12  4:48                                                   ` Jon Povey
2010-09-23 14:27                               ` Kevin Hilman
     [not found]                                 ` <87d3s47cx1.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-09-23 20:27                                   ` Troy Kisky
     [not found]                       ` <022501cb5ba2$d801d760$88058620$@raj@ti.com>
     [not found]                         ` <022501cb5ba2$d801d760$88058620$@raj-l0cyMroinI0@public.gmane.org>
2010-09-24 14:37                           ` Kevin Hilman
     [not found]                             ` <87sk0zky28.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-09-24 16:37                               ` Ben Dooks
     [not found]                                 ` <20100924163754.GH27885-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-09-27 14:16                                   ` Kevin Hilman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.