24 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <linux/i2c.h>
36 static unsigned int i2c_scan;
44 #define dprintk2(lvl, fmt, args...) \
46 if (i2c_debug >= lvl) { \
47 printk(KERN_DEBUG "%s at %s: " fmt, \
48 dev->name, __func__ , ##args); \
56 static int em2800_i2c_send_max4(
struct em28xx *
dev,
unsigned char addr,
62 BUG_ON(len < 1 || len > 4);
63 b2[5] = 0x80 + len - 1;
75 em28xx_warn(
"writing to i2c device failed (error=%i)\n", ret);
81 if (ret == 0x80 + len - 1)
92 static int em2800_i2c_send_bytes(
void *
data,
unsigned char addr,
char *
buf,
102 count = (len > maxLen) ? maxLen : len;
103 ret = em2800_i2c_send_max4(dev, addr, bufPtr, count);
109 return (ret < 0) ? ret : -
EFAULT;
118 static int em2800_i2c_check_for_device(
struct em28xx *dev,
unsigned char addr)
126 em28xx_warn(
"setting i2c device address failed (error=%i)\n",
133 em28xx_warn(
"preparing i2c read failed (error=%i)\n", ret);
137 write_timeout -= 5) {
142 else if (reg == 0x84)
153 static int em2800_i2c_recv_bytes(
struct em28xx *dev,
unsigned char addr,
158 ret = em2800_i2c_check_for_device(dev, addr);
161 (
"preparing read at i2c address 0x%x failed (error=%i)\n",
167 em28xx_warn(
"reading from i2c device at 0x%x failed (error=%i)",
177 static int em28xx_i2c_send_bytes(
void *data,
unsigned char addr,
char *buf,
182 int write_timeout,
ret;
188 write_timeout -= 5) {
202 static int em28xx_i2c_recv_bytes(
struct em28xx *dev,
unsigned char addr,
208 em28xx_warn(
"reading i2c device failed (error=%i)\n", ret);
220 static int em28xx_i2c_check_for_device(
struct em28xx *dev,
unsigned char addr)
226 em28xx_warn(
"reading from i2c device failed (error=%i)\n", ret);
239 struct i2c_msg msgs[],
int num)
246 for (i = 0; i < num; i++) {
247 addr = msgs[
i].
addr << 1;
248 dprintk2(2,
"%s %s addr=%x len=%d:",
250 i == num - 1 ?
"stop" :
"nonstop", addr, msgs[i].len);
252 if (dev->
board.is_em2800)
253 rc = em2800_i2c_check_for_device(dev, addr);
255 rc = em28xx_i2c_check_for_device(dev, addr);
263 if (dev->
board.is_em2800)
264 rc = em2800_i2c_recv_bytes(dev, addr,
268 rc = em28xx_i2c_recv_bytes(dev, addr,
272 for (byte = 0; byte < msgs[
i].
len; byte++)
273 printk(
" %02x", msgs[i].buf[byte]);
278 for (byte = 0; byte < msgs[
i].
len; byte++)
279 printk(
" %02x", msgs[i].buf[byte]);
281 if (dev->
board.is_em2800)
282 rc = em2800_i2c_send_bytes(dev, addr,
286 rc = em28xx_i2c_send_bytes(dev, addr,
307 static inline unsigned long em28xx_hash_mem(
char *buf,
int length,
int bits)
309 unsigned long hash = 0;
321 if ((len & (32 / 8 - 1)) == 0)
322 hash = ((hash^
l) * 0x9e370001UL);
325 return (hash >> (32 - bits)) & 0xffffffffUL;
328 static int em28xx_i2c_eeprom(
struct em28xx *dev,
unsigned char *
eedata,
int len)
374 "%s: i2c eeprom read error (err=%d)\n",
381 for (i = 0; i < len; i++) {
384 printk(
" %02x", eedata[i]);
389 if (em_eeprom->
id == 0x9567eb1a)
390 dev->
hash = em28xx_hash_mem(eedata, len, 32);
397 switch (em_eeprom->
chip_conf >> 4 & 0x3) {
435 printk(
KERN_INFO "%s:\tTable at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n",
456 .master_xfer = em28xx_i2c_xfer,
463 .algo = &em28xx_algo,
466 static struct i2c_client em28xx_client_template = {
467 .name =
"em28xx internal",
477 [0x4a >> 1] =
"saa7113h",
478 [0x52 >> 1] =
"drxk",
479 [0x60 >> 1] =
"remote IR sensor",
480 [0x8e >> 1] =
"remote IR sensor",
481 [0x86 >> 1] =
"tda9887",
482 [0x80 >> 1] =
"msp34xx",
483 [0x88 >> 1] =
"msp34xx",
484 [0xa0 >> 1] =
"eeprom",
485 [0xb0 >> 1] =
"tda9874",
486 [0xb8 >> 1] =
"tvp5150a",
487 [0xba >> 1] =
"webcam sensor or tvp5150a",
488 [0xc0 >> 1] =
"tuner (analog)",
489 [0xc2 >> 1] =
"tuner (analog)",
490 [0xc4 >> 1] =
"tuner (analog)",
491 [0xc6 >> 1] =
"tuner (analog)",
500 u8 i2c_devicelist[128];
511 i2c_devicelist[
i] =
i;
513 dev->
name, i << 1, i2c_devs[i] ? i2c_devs[i] :
"???");
516 dev->
i2c_hash = em28xx_hash_mem(i2c_devicelist,
530 dev->
i2c_adap = em28xx_adap_template;
546 retval = em28xx_i2c_eeprom(dev, dev->
eedata,
sizeof(dev->
eedata));
547 if ((retval < 0) && (retval != -
ENODEV)) {