public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] omap i2c: add timeout to a busy loop in isr
@ 2009-12-14 13:21 Alexander Shishkin
  2009-12-15 13:20 ` Aaro Koskinen
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Shishkin @ 2009-12-14 13:21 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-omap, Alexander Shishkin

Signed-off-by: Alexander Shishkin <virtuoso@slind.org>
---
 drivers/i2c/busses/i2c-omap.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 75bf3ad..7617f18 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -803,15 +803,20 @@ complete:
 				 */
 
 				if (dev->rev <= OMAP_I2C_REV_ON_3430) {
-						while (!(stat & OMAP_I2C_STAT_XUDF)) {
-							if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
-								omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
-								err |= OMAP_I2C_STAT_XUDF;
-								goto complete;
-							}
-							cpu_relax();
-							stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					unsigned long timeout = 10000;
+
+					while (!(stat & OMAP_I2C_STAT_XUDF) && --timeout) {
+						if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
+							omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
+							err |= OMAP_I2C_STAT_XUDF;
+							goto complete;
 						}
+						cpu_relax();
+						stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					}
+
+					if (!timeout)
+						dev_err(dev->dev, "timeout waiting on XUDF bit\n");
 				}
 
 				omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
-- 
1.6.3.3


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

* Re: [PATCH] omap i2c: add timeout to a busy loop in isr
  2009-12-14 13:21 [PATCH] omap i2c: add timeout to a busy loop in isr Alexander Shishkin
@ 2009-12-15 13:20 ` Aaro Koskinen
  0 siblings, 0 replies; 2+ messages in thread
From: Aaro Koskinen @ 2009-12-15 13:20 UTC (permalink / raw)
  To: ext Alexander Shishkin; +Cc: Tony Lindgren, linux-omap@vger.kernel.org

Hi,

Alexander Shishkin wrote:
> Signed-off-by: Alexander Shishkin <virtuoso@slind.org>

Could you add a better patch description? I.e. the patch is needed
because I2C failure can cause a kernel hang. The problem can be
reproduced by running the bus with wrong (too high) speed.

Also, you should send the patch to ben-linux@fluff.org with
linux-omap and linux-i2c@vger.kernel.org in CC.

Tested-by: Aaro Koskinen <aaro.koskinen@nokia.com>

>  drivers/i2c/busses/i2c-omap.c |   21 +++++++++++++--------
>  1 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index 75bf3ad..7617f18 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -803,15 +803,20 @@ complete:
>  				 */
>  
>  				if (dev->rev <= OMAP_I2C_REV_ON_3430) {
> -						while (!(stat & OMAP_I2C_STAT_XUDF)) {
> -							if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
> -								omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
> -								err |= OMAP_I2C_STAT_XUDF;
> -								goto complete;
> -							}
> -							cpu_relax();
> -							stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
> +					unsigned long timeout = 10000;

I think 10000 reads (with L4 core interconnect latency) is at least 0.8 ms. It should be more than
enough for normal cases.

> +					while (!(stat & OMAP_I2C_STAT_XUDF) && --timeout) {
> +						if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
> +							omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
> +							err |= OMAP_I2C_STAT_XUDF;
> +							goto complete;
>  						}
> +						cpu_relax();
> +						stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
> +					}
> +
> +					if (!timeout)
> +						dev_err(dev->dev, "timeout waiting on XUDF bit\n");
>  				}
>  
>  				omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);

A.

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

end of thread, other threads:[~2009-12-15 13:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-14 13:21 [PATCH] omap i2c: add timeout to a busy loop in isr Alexander Shishkin
2009-12-15 13:20 ` Aaro Koskinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox