Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: em28xx: adjust I2C timeout according with I2C speed

If the I2C speed is too slow, it should wait more for an
answer.

While here, change disconnected type from char to unsigned
int, just like all other bitmask fields there at em28xx
struct.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

+37 -20
+2
drivers/media/usb/em28xx/em28xx-cards.c
··· 2704 2704 i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | 2705 2705 EM28XX_I2C_FREQ_100_KHZ; 2706 2706 2707 + dev->i2c_speed = i2c_speed & 0x03; 2708 + 2707 2709 if (!dev->board.is_em2800) 2708 2710 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, i2c_speed); 2709 2711 msleep(50);
+33 -3
drivers/media/usb/em28xx/em28xx-i2c.c
··· 52 52 53 53 54 54 /* 55 + * Time in msecs to wait for i2c xfers to finish. 56 + * 35ms is the maximum time a SMBUS device could wait when 57 + * clock stretching is used. As the transfer itself will take 58 + * some time to happen, set it to 35 ms. 59 + * 60 + * Ok, I2C doesn't specify any limit. So, eventually, we may need 61 + * to increase this timeout. 62 + */ 63 + #define EM28XX_I2C_XFER_TIMEOUT 35 /* ms */ 64 + 65 + static int em28xx_i2c_timeout(struct em28xx *dev) 66 + { 67 + int time = EM28XX_I2C_XFER_TIMEOUT; 68 + 69 + switch (dev->i2c_speed & 0x03) { 70 + case EM28XX_I2C_FREQ_25_KHZ: 71 + time += 4; /* Assume 4 ms for transfers */ 72 + break; 73 + case EM28XX_I2C_FREQ_100_KHZ: 74 + case EM28XX_I2C_FREQ_400_KHZ: 75 + time += 1; /* Assume 1 ms for transfers */ 76 + break; 77 + default: /* EM28XX_I2C_FREQ_1_5_MHZ */ 78 + break; 79 + } 80 + 81 + return msecs_to_jiffies(time); 82 + } 83 + 84 + /* 55 85 * em2800_i2c_send_bytes() 56 86 * send up to 4 bytes to the em2800 i2c device 57 87 */ 58 88 static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) 59 89 { 60 - unsigned long timeout = jiffies + msecs_to_jiffies(EM28XX_I2C_XFER_TIMEOUT); 90 + unsigned long timeout = jiffies + em28xx_i2c_timeout(dev); 61 91 int ret; 62 92 u8 b2[6]; 63 93 ··· 140 110 */ 141 111 static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) 142 112 { 143 - unsigned long timeout = jiffies + msecs_to_jiffies(EM28XX_I2C_XFER_TIMEOUT); 113 + unsigned long timeout = jiffies + em28xx_i2c_timeout(dev); 144 114 u8 buf2[4]; 145 115 int ret; 146 116 int i; ··· 216 186 static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf, 217 187 u16 len, int stop) 218 188 { 219 - unsigned long timeout = jiffies + msecs_to_jiffies(EM28XX_I2C_XFER_TIMEOUT); 189 + unsigned long timeout = jiffies + em28xx_i2c_timeout(dev); 220 190 int ret; 221 191 222 192 if (len < 1 || len > 64)
+2 -17
drivers/media/usb/em28xx/em28xx.h
··· 195 195 196 196 #define EM28XX_INTERLACED_DEFAULT 1 197 197 198 - /* 199 - * Time in msecs to wait for i2c xfers to finish. 200 - * 35ms is the maximum time a SMBUS device could wait when 201 - * clock stretching is used. As the transfer itself will take 202 - * some time to happen, set it to 35 ms. 203 - * 204 - * Ok, I2C doesn't specify any limit. So, eventually, we may need 205 - * to increase this timeout. 206 - * 207 - * FIXME: this assumes that an I2C message is not longer than 1ms. 208 - * This is actually dependent on the I2C bus speed, although most 209 - * devices use a 100kHz clock. So, this assumtion is true most of 210 - * the time. 211 - */ 212 - #define EM28XX_I2C_XFER_TIMEOUT 36 213 - 214 198 /* time in msecs to wait for AC97 xfers to finish */ 215 199 #define EM28XX_AC97_XFER_TIMEOUT 100 216 200 ··· 604 620 enum em28xx_chip_id chip_id; 605 621 606 622 unsigned int is_em25xx:1; /* em25xx/em276x/7x/8x family bridge */ 607 - unsigned char disconnected:1; /* device has been diconnected */ 623 + unsigned int disconnected:1; /* device has been diconnected */ 608 624 unsigned int has_video:1; 609 625 unsigned int is_audio_only:1; 610 626 unsigned int is_webcam:1; 611 627 unsigned int has_msp34xx:1; 628 + unsigned int i2c_speed:2; 612 629 enum em28xx_int_audio_type int_audio_type; 613 630 enum em28xx_usb_audio_type usb_audio_type; 614 631 unsigned char name[32];