Title: [9290] branches/2010R1/drivers/i2c/busses/i2c-bfin-twi.c: i2c-bfin-twi: Break dead waiting loop if i2c device misbehaves.
- Revision
- 9290
- Author
- sonicz
- Date
- 2010-10-22 06:03:23 -0400 (Fri, 22 Oct 2010)
Log Message
i2c-bfin-twi: Break dead waiting loop if i2c device misbehaves.
Some fault i2c device may hold the sda/scl line and cause i2c driver
wait in the BUS busy loop. This patch breaks this potential dead
loop.
Modified Paths
Diff
Modified: branches/2010R1/drivers/i2c/busses/i2c-bfin-twi.c (9289 => 9290)
--- branches/2010R1/drivers/i2c/busses/i2c-bfin-twi.c 2010-10-22 08:48:41 UTC (rev 9289)
+++ branches/2010R1/drivers/i2c/busses/i2c-bfin-twi.c 2010-10-22 10:03:23 UTC (rev 9290)
@@ -288,6 +288,8 @@
return IRQ_HANDLED;
}
+#define BFIN_TWI_BUSY_TIMEOUT 1000
+
/*
* One i2c master transfer
*/
@@ -297,12 +299,16 @@
struct bfin_twi_iface *iface = adap->algo_data;
struct i2c_msg *pmsg;
int rc = 0;
+ unsigned int busy_timeout = BFIN_TWI_BUSY_TIMEOUT;
if (!(read_CONTROL(iface) & TWI_ENA))
return -ENXIO;
- while (read_MASTER_STAT(iface) & BUSBUSY)
+ while (read_MASTER_STAT(iface) & BUSBUSY) {
+ if ((--busy_timeout) == 0)
+ return -EBUSY;
yield();
+ }
iface->pmsg = msgs;
iface->msg_num = num;
@@ -397,12 +403,16 @@
{
struct bfin_twi_iface *iface = adap->algo_data;
int rc = 0;
+ unsigned int busy_timeout = BFIN_TWI_BUSY_TIMEOUT;
if (!(read_CONTROL(iface) & TWI_ENA))
return -ENXIO;
- while (read_MASTER_STAT(iface) & BUSBUSY)
+ while (read_MASTER_STAT(iface) & BUSBUSY) {
+ if ((--busy_timeout) == 0)
+ return -EBUSY;
yield();
+ }
iface->writeNum = 0;
iface->readNum = 0;
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits