Patch 4/4: Fix I2C timing constants
This patch fixes the timing constants given to i2c-algo-bit to time i2c
bus transitions.
For a Standard Mode I2C bus clocked at 100 KHz, the minimum SCL clock
period is 10 usec. i2c-algo-bit wants the udelay parameter specified as
1/2 of the SCL clock period. In the case of the cx18, that should be 5
usec.
For the timeout, i2c-algo-bit wants a timeout specified in jiffies
(timer ticks). The original value of 200 is a 2 second timeout times HZ
jiffies/second, where HZ usually conveyed the timer was set up so the
system counted 100 jiffies/sec on Linux systems in the past. Now that
the kernel HZ value cannot be relied on to be 100, specifying 200
jiffies can give different timeout lengths on different systems. The
value has been changed to be consistently 2 seconds, no matter what the
kernel HZ is set at.
This change produced no problems for me. This change may cause problems
for anyone who does not also apply PATCH 2/4, as tightening up the
udelay timing constant here, requires more deterministic control of the
actual bus line transitions.
Refer to
1. linux/drivers/i2c/algos/i2c-algo-bit.c
2. linux/include/linux/i2c-algo-bit.h
3. <asm/param.h>
4. I2C Bus Specification and User Manual:
http://www.nxp.com/acrobat_download/usermanuals/UM10204_3.pdf
5. Bovet, D.; Cesati, M.; _Understanding the Linux Kernel_, O'Reilly,
2003
-Andy
--- cx18-f763c5864f9a/linux/drivers/media/video/cx18/cx18-i2c.c.change3 2008-04-17 20:58:23.000000000 -0400
+++ cx18-f763c5864f9a/linux/drivers/media/video/cx18/cx18-i2c.c 2008-04-17 21:09:14.000000000 -0400
@@ -248,13 +248,16 @@ static struct i2c_adapter cx18_i2c_adap_
#endif
};
+#define CX18_SCL_PERIOD (10) /* usecs. 10 usec is period for a 100 KHz clock */
+#define CX18_ALGO_BIT_TIMEOUT (2) /* seconds */
+
static struct i2c_algo_bit_data cx18_i2c_algo_template = {
.setsda = cx18_setsda,
.setscl = cx18_setscl,
.getsda = cx18_getsda,
.getscl = cx18_getscl,
- .udelay = 10,
- .timeout = 200,
+ .udelay = CX18_SCL_PERIOD/2, /* 1/2 clock period in usec*/
+ .timeout = CX18_ALGO_BIT_TIMEOUT*HZ /* jiffies */
};
static struct i2c_client cx18_i2c_client_template = {
_______________________________________________
ivtv-devel mailing list
[email protected]
http://ivtvdriver.org/mailman/listinfo/ivtv-devel