tsc2007 driver, read data abort after i2c timeout

From: Super Eichtig
Date: Mon Sep 02 2013 - 08:39:03 EST


Hello!
Â
In the last few weeks I worked on a problem I had with I2C errors and the effect they had on the touchscreen performance with a TI TSC2007 IC.
For I'm stuck with an old kernel (2.6.28) i used the tsc2003 driver, but the code seems to be close to the tsc2007.c .
Â
I came across the funktion "tsc2003_read_values" where 5 I2C transfers are executed after a PenIRQ event (read x,y,z1,z2 and power down).
In this function the return values of the tsc2007_xfer function are ignored. So there will always be 5 tries to access the bus.
In the I2C driver there is a timeout for failed transfers of 5 second. This leads to an overall time for the above function of 25s in case of an error on the i2c bus.
Â
In my case it helped a lot to abort the read_values function after an error return value from the _xfer function.
Â
I obviously don't know all the details of the tsc code. To this day I don't understand how the transfer recovers and reacts to the next penirq when the first transfer is interrupted and so the tsc-chip is never returned to the "power down and listen to the penirq" state. Maybe there are good reasons not to interrupt the function.
Can you comment on this change? Is it a grave mistake or could this work. It does right now but not understanding all implications means it probably bites me in the ass at one point.
Â
Attached you'll find a patch for the tsc2003.c file.
Â
Best regards
Sebastian
Â
Â
diff --git a/drivers/input/touchscreen/tsc2003.c b/drivers/input/touchscreen/tsc2003.c
index 4f3a2c9..7ad62f2 100644
--- a/drivers/input/touchscreen/tsc2003.c
+++ b/drivers/input/touchscreen/tsc2003.c
@@ -115,15 +115,31 @@ static inline int tsc2003_xfer(struct tsc2003 *tsc, u8 cmd)
Â
Âstatic void tsc2003_read_values(struct tsc2003 *tsc, struct ts_event *tc)
Â{
+ÂÂ Âs32 temp;
+
+ÂÂ Âtc->y = 0;
+ÂÂ Âtc->x = 0;
+ÂÂ Âtc->z1 = 0;
+ÂÂ Âtc->z2 = 0;
+
ÂÂÂ Â/* y- still on; turn on only y+ (and ADC) */
-ÂÂ Âtc->y = tsc2003_xfer(tsc, READ_Y);
+ÂÂ Âtemp = tsc2003_xfer(tsc, READ_Y);
+ÂÂ Âif (temp > 0) tc->y = temp;
+ÂÂ Âelse return;
Â
ÂÂÂ Â/* turn y- off, x+ on, then leave in lowpower */
-ÂÂ Âtc->x = tsc2003_xfer(tsc, READ_X);
+ÂÂ Âtemp = tsc2003_xfer(tsc, READ_X);
+ÂÂ Âif (temp > 0) tc->x = temp;
+ÂÂ Âelse return;
Â
ÂÂÂ Â/* turn y+ off, x- on; we'll use formula #1 */
-ÂÂ Âtc->z1 = tsc2003_xfer(tsc, READ_Z1);
-ÂÂ Âtc->z2 = tsc2003_xfer(tsc, READ_Z2);
+ÂÂ Âtemp = tsc2003_xfer(tsc, READ_Z1);
+ÂÂ Âif (temp > 0) tc->z1 = temp;
+ÂÂ Âelse return;
+
+ÂÂ Âtemp = tsc2003_xfer(tsc, READ_Z2);
+ÂÂ Âif (temp > 0) tc->z2 = temp;
+ÂÂ Âelse return;
Â
ÂÂÂ Â/* Prepare for next touch reading - power down ADC, enable PENIRQ */
ÂÂÂ Âtsc2003_xfer(tsc, PWRDOWN);
Â
Â
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/