2 em28xx-i2c.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com>
6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Sascha Sommer <saschasommer@freenet.de>
8 Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/usb.h>
28 #include <linux/i2c.h>
31 #include "tuner-xc2028.h"
32 #include <media/v4l2-common.h>
33 #include <media/tuner.h>
35 /* ----------------------------------------------------------- */
37 static unsigned int i2c_scan;
38 module_param(i2c_scan, int, 0444);
39 MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
41 static unsigned int i2c_debug;
42 module_param(i2c_debug, int, 0644);
43 MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
46 * em2800_i2c_send_bytes()
47 * send up to 4 bytes to the em2800 i2c device
49 static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
55 if (len < 1 || len > 4)
58 BUG_ON(len < 1 || len > 4);
59 b2[5] = 0x80 + len - 1;
70 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len);
72 em28xx_warn("failed to trigger write to i2c address 0x%x (error=%i)\n",
74 return (ret < 0) ? ret : -EIO;
76 /* wait for completion */
77 for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout > 0;
79 ret = dev->em28xx_read_reg(dev, 0x05);
80 if (ret == 0x80 + len - 1) {
82 } else if (ret == 0x94 + len - 1) {
85 em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n",
91 em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
96 * em2800_i2c_recv_bytes()
97 * read up to 4 bytes from the em2800 i2c device
99 static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
106 if (len < 1 || len > 4)
110 buf2[1] = 0x84 + len - 1;
112 ret = dev->em28xx_write_regs(dev, 0x04, buf2, 2);
114 em28xx_warn("failed to trigger read from i2c address 0x%x (error=%i)\n",
116 return (ret < 0) ? ret : -EIO;
119 /* wait for completion */
120 for (read_timeout = EM2800_I2C_XFER_TIMEOUT; read_timeout > 0;
122 ret = dev->em28xx_read_reg(dev, 0x05);
123 if (ret == 0x84 + len - 1) {
125 } else if (ret == 0x94 + len - 1) {
127 } else if (ret < 0) {
128 em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n",
134 if (ret != 0x84 + len - 1)
135 em28xx_warn("read from i2c device at 0x%x timed out\n", addr);
137 /* get the received message */
138 ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len);
140 em28xx_warn("reading from i2c device at 0x%x failed: couldn't get the received message from the bridge (error=%i)\n",
142 return (ret < 0) ? ret : -EIO;
144 for (i = 0; i < len; i++)
145 buf[i] = buf2[len - 1 - i];
151 * em2800_i2c_check_for_device()
152 * check if there is an i2c device at the supplied address
154 static int em2800_i2c_check_for_device(struct em28xx *dev, u8 addr)
159 ret = em2800_i2c_recv_bytes(dev, addr, &buf, 1);
162 return (ret < 0) ? ret : -EIO;
166 * em28xx_i2c_send_bytes()
168 static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
171 int write_timeout, ret;
173 if (len < 1 || len > 64)
176 * NOTE: limited by the USB ctrl message constraints
177 * Zero length reads always succeed, even if no device is connected
180 /* Write to i2c device */
181 ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
184 em28xx_warn("writing to i2c device at 0x%x failed (error=%i)\n",
188 em28xx_warn("%i bytes write to i2c device at 0x%x requested, but %i bytes written\n",
194 /* Check success of the i2c operation */
195 for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout > 0;
196 write_timeout -= 5) {
197 ret = dev->em28xx_read_reg(dev, 0x05);
198 if (ret == 0) { /* success */
200 } else if (ret == 0x10) {
202 } else if (ret < 0) {
203 em28xx_warn("failed to read i2c transfer status from bridge (error=%i)\n",
209 * NOTE: do we really have to wait for success ?
210 * Never seen anything else than 0x00 or 0x10
211 * (even with high payload) ...
214 em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
219 * em28xx_i2c_recv_bytes()
220 * read a byte from the i2c device
222 static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len)
226 if (len < 1 || len > 64)
229 * NOTE: limited by the USB ctrl message constraints
230 * Zero length reads always succeed, even if no device is connected
233 /* Read data from i2c device */
234 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len);
236 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n",
241 * NOTE: some devices with two i2c busses have the bad habit to return 0
242 * bytes if we are on bus B AND there was no write attempt to the
243 * specified slave address before AND no device is present at the
244 * requested slave address.
245 * Anyway, the next check will fail with -ENODEV in this case, so avoid
246 * spamming the system log on device probing and do nothing here.
249 /* Check success of the i2c operation */
250 ret = dev->em28xx_read_reg(dev, 0x05);
252 em28xx_warn("failed to read i2c transfer status from bridge (error=%i)\n",
260 em28xx_warn("unknown i2c error (status=%i)\n", ret);
268 * em28xx_i2c_check_for_device()
269 * check if there is a i2c_device at the supplied address
271 static int em28xx_i2c_check_for_device(struct em28xx *dev, u16 addr)
276 ret = em28xx_i2c_recv_bytes(dev, addr, &buf, 1);
279 return (ret < 0) ? ret : -EIO;
283 * em25xx_bus_B_send_bytes
284 * write bytes to the i2c device
286 static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
291 if (len < 1 || len > 64)
294 * NOTE: limited by the USB ctrl message constraints
295 * Zero length reads always succeed, even if no device is connected
298 /* Set register and write value */
299 ret = dev->em28xx_write_regs_req(dev, 0x06, addr, buf, len);
302 em28xx_warn("writing to i2c device at 0x%x failed (error=%i)\n",
306 em28xx_warn("%i bytes write to i2c device at 0x%x requested, but %i bytes written\n",
312 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000);
314 * NOTE: the only error we've seen so far is
315 * 0x01 when the slave device is not present
324 * NOTE: With chip types (other chip IDs) which actually don't support
325 * this operation, it seems to succeed ALWAYS ! (even if there is no
326 * slave device or even no second i2c bus provided)
331 * em25xx_bus_B_recv_bytes
332 * read bytes from the i2c device
334 static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf,
339 if (len < 1 || len > 64)
342 * NOTE: limited by the USB ctrl message constraints
343 * Zero length reads always succeed, even if no device is connected
347 ret = dev->em28xx_read_reg_req_len(dev, 0x06, addr, buf, len);
349 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n",
354 * NOTE: some devices with two i2c busses have the bad habit to return 0
355 * bytes if we are on bus B AND there was no write attempt to the
356 * specified slave address before AND no device is present at the
357 * requested slave address.
358 * Anyway, the next check will fail with -ENODEV in this case, so avoid
359 * spamming the system log on device probing and do nothing here.
363 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000);
365 * NOTE: the only error we've seen so far is
366 * 0x01 when the slave device is not present
375 * NOTE: With chip types (other chip IDs) which actually don't support
376 * this operation, it seems to succeed ALWAYS ! (even if there is no
377 * slave device or even no second i2c bus provided)
382 * em25xx_bus_B_check_for_device()
383 * check if there is a i2c device at the supplied address
385 static int em25xx_bus_B_check_for_device(struct em28xx *dev, u16 addr)
390 ret = em25xx_bus_B_recv_bytes(dev, addr, &buf, 1);
396 * NOTE: With chips which do not support this operation,
397 * it seems to succeed ALWAYS ! (even if no device connected)
401 static inline int i2c_check_for_device(struct em28xx_i2c_bus *i2c_bus, u16 addr)
403 struct em28xx *dev = i2c_bus->dev;
404 int rc = -EOPNOTSUPP;
406 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
407 rc = em28xx_i2c_check_for_device(dev, addr);
408 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
409 rc = em2800_i2c_check_for_device(dev, addr);
410 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
411 rc = em25xx_bus_B_check_for_device(dev, addr);
414 printk(" no device\n");
419 static inline int i2c_recv_bytes(struct em28xx_i2c_bus *i2c_bus,
422 struct em28xx *dev = i2c_bus->dev;
423 u16 addr = msg.addr << 1;
424 int byte, rc = -EOPNOTSUPP;
426 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
427 rc = em28xx_i2c_recv_bytes(dev, addr, msg.buf, msg.len);
428 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
429 rc = em2800_i2c_recv_bytes(dev, addr, msg.buf, msg.len);
430 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
431 rc = em25xx_bus_B_recv_bytes(dev, addr, msg.buf, msg.len);
433 for (byte = 0; byte < msg.len; byte++)
434 printk(" %02x", msg.buf[byte]);
439 static inline int i2c_send_bytes(struct em28xx_i2c_bus *i2c_bus,
440 struct i2c_msg msg, int stop)
442 struct em28xx *dev = i2c_bus->dev;
443 u16 addr = msg.addr << 1;
444 int byte, rc = -EOPNOTSUPP;
447 for (byte = 0; byte < msg.len; byte++)
448 printk(" %02x", msg.buf[byte]);
450 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
451 rc = em28xx_i2c_send_bytes(dev, addr, msg.buf, msg.len, stop);
452 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
453 rc = em2800_i2c_send_bytes(dev, addr, msg.buf, msg.len);
454 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
455 rc = em25xx_bus_B_send_bytes(dev, addr, msg.buf, msg.len);
461 * the main i2c transfer function
463 static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
464 struct i2c_msg msgs[], int num)
466 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data;
467 struct em28xx *dev = i2c_bus->dev;
468 unsigned bus = i2c_bus->bus;
472 rc = rt_mutex_trylock(&dev->i2c_bus_lock);
476 /* Switch I2C bus if needed */
477 if (bus != dev->cur_i2c_bus &&
478 i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) {
480 reg = EM2874_I2C_SECONDARY_BUS_SELECT;
483 em28xx_write_reg_bits(dev, EM28XX_R06_I2C_CLK, reg,
484 EM2874_I2C_SECONDARY_BUS_SELECT);
485 dev->cur_i2c_bus = bus;
489 rt_mutex_unlock(&dev->i2c_bus_lock);
492 for (i = 0; i < num; i++) {
493 addr = msgs[i].addr << 1;
495 printk(KERN_DEBUG "%s at %s: %s %s addr=%02x len=%d:",
496 dev->name, __func__ ,
497 (msgs[i].flags & I2C_M_RD) ? "read" : "write",
498 i == num - 1 ? "stop" : "nonstop",
500 if (!msgs[i].len) { /* no len: check only for device presence */
501 rc = i2c_check_for_device(i2c_bus, addr);
503 rt_mutex_unlock(&dev->i2c_bus_lock);
506 } else if (msgs[i].flags & I2C_M_RD) {
508 rc = i2c_recv_bytes(i2c_bus, msgs[i]);
511 rc = i2c_send_bytes(i2c_bus, msgs[i], i == num - 1);
515 printk(" ERROR: %i\n", rc);
516 rt_mutex_unlock(&dev->i2c_bus_lock);
523 rt_mutex_unlock(&dev->i2c_bus_lock);
528 * based on linux/sunrpc/svcauth.h and linux/hash.h
529 * The original hash function returns a different value, if arch is x86_64
532 static inline unsigned long em28xx_hash_mem(char *buf, int length, int bits)
534 unsigned long hash = 0;
546 if ((len & (32 / 8 - 1)) == 0)
547 hash = ((hash^l) * 0x9e370001UL);
550 return (hash >> (32 - bits)) & 0xffffffffUL;
554 * Helper function to read data blocks from i2c clients with 8 or 16 bit
555 * address width, 8 bit register width and auto incrementation been activated
557 static int em28xx_i2c_read_block(struct em28xx *dev, unsigned bus, u16 addr,
558 bool addr_w16, u16 len, u8 *data)
560 int remain = len, rsize, rsize_max, ret;
564 if (addr + remain > (addr_w16 * 0xff00 + 0xff + 1))
568 buf[1] = addr & 0xff;
569 ret = i2c_master_send(&dev->i2c_client[bus], buf + !addr_w16, 1 + addr_w16);
573 if (dev->board.is_em2800)
578 if (remain > rsize_max)
583 ret = i2c_master_recv(&dev->i2c_client[bus], data, rsize);
594 static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned bus,
595 u8 **eedata, u16 *eedata_len)
599 * FIXME common length/size for bytes to read, to display, hash
600 * calculation and returned device dataset. Simplifies the code a lot,
601 * but we might have to deal with multiple sizes in the future !
604 struct em28xx_eeprom *dev_config;
610 /* EEPROM is always on i2c bus 0 on all known devices. */
612 dev->i2c_client[bus].addr = 0xa0 >> 1;
614 /* Check if board has eeprom */
615 err = i2c_master_recv(&dev->i2c_client[bus], &buf, 0);
617 em28xx_info("board has no eeprom\n");
621 data = kzalloc(len, GFP_KERNEL);
625 /* Read EEPROM content */
626 err = em28xx_i2c_read_block(dev, bus, 0x0000,
627 dev->eeprom_addrwidth_16bit,
630 em28xx_errdev("failed to read eeprom (err=%d)\n", err);
634 /* Display eeprom content */
635 for (i = 0; i < len; i++) {
637 if (dev->eeprom_addrwidth_16bit)
638 em28xx_info("i2c eeprom %04x:", i);
640 em28xx_info("i2c eeprom %02x:", i);
642 printk(" %02x", data[i]);
646 if (dev->eeprom_addrwidth_16bit)
647 em28xx_info("i2c eeprom %04x: ... (skipped)\n", i);
649 if (dev->eeprom_addrwidth_16bit &&
650 data[0] == 0x26 && data[3] == 0x00) {
651 /* new eeprom format; size 4-64kb */
655 dev->hash = em28xx_hash_mem(data, len, 32);
656 mc_start = (data[1] << 8) + 4; /* usually 0x0004 */
658 em28xx_info("EEPROM ID = %02x %02x %02x %02x, EEPROM hash = 0x%08lx\n",
659 data[0], data[1], data[2], data[3], dev->hash);
660 em28xx_info("EEPROM info:\n");
661 em28xx_info("\tmicrocode start address = 0x%04x, boot configuration = 0x%02x\n",
664 * boot configuration (address 0x0002):
665 * [0] microcode download speed: 1 = 400 kHz; 0 = 100 kHz
666 * [1] always selects 12 kb RAM
667 * [2] USB device speed: 1 = force Full Speed; 0 = auto detect
668 * [4] 1 = force fast mode and no suspend for device testing
669 * [5:7] USB PHY tuning registers; determined by device
674 * Read hardware config dataset offset from address
675 * (microcode start + 46)
677 err = em28xx_i2c_read_block(dev, bus, mc_start + 46, 1, 2,
680 em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n",
685 /* Calculate hardware config dataset start address */
686 hwconf_offset = mc_start + data[0] + (data[1] << 8);
688 /* Read hardware config dataset */
690 * NOTE: the microcode copy can be multiple pages long, but
691 * we assume the hardware config dataset is the same as in
692 * the old eeprom and not longer than 256 bytes.
693 * tveeprom is currently also limited to 256 bytes.
695 err = em28xx_i2c_read_block(dev, bus, hwconf_offset, 1, len,
698 em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n",
703 /* Verify hardware config dataset */
704 /* NOTE: not all devices provide this type of dataset */
705 if (data[0] != 0x1a || data[1] != 0xeb ||
706 data[2] != 0x67 || data[3] != 0x95) {
707 em28xx_info("\tno hardware configuration dataset found in eeprom\n");
712 /* TODO: decrypt eeprom data for camera bridges (em25xx, em276x+) */
714 } else if (!dev->eeprom_addrwidth_16bit &&
715 data[0] == 0x1a && data[1] == 0xeb &&
716 data[2] == 0x67 && data[3] == 0x95) {
717 dev->hash = em28xx_hash_mem(data, len, 32);
718 em28xx_info("EEPROM ID = %02x %02x %02x %02x, EEPROM hash = 0x%08lx\n",
719 data[0], data[1], data[2], data[3], dev->hash);
720 em28xx_info("EEPROM info:\n");
722 em28xx_info("unknown eeprom format or eeprom corrupted !\n");
729 dev_config = (void *)eedata;
731 switch (le16_to_cpu(dev_config->chip_conf) >> 4 & 0x3) {
733 em28xx_info("\tNo audio on board.\n");
736 em28xx_info("\tAC97 audio (5 sample rates)\n");
739 em28xx_info("\tI2S audio, sample rate=32k\n");
742 em28xx_info("\tI2S audio, 3 sample rates\n");
746 if (le16_to_cpu(dev_config->chip_conf) & 1 << 3)
747 em28xx_info("\tUSB Remote wakeup capable\n");
749 if (le16_to_cpu(dev_config->chip_conf) & 1 << 2)
750 em28xx_info("\tUSB Self power capable\n");
752 switch (le16_to_cpu(dev_config->chip_conf) & 0x3) {
754 em28xx_info("\t500mA max power\n");
757 em28xx_info("\t400mA max power\n");
760 em28xx_info("\t300mA max power\n");
763 em28xx_info("\t200mA max power\n");
766 em28xx_info("\tTable at offset 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n",
767 dev_config->string_idx_table,
768 le16_to_cpu(dev_config->string1),
769 le16_to_cpu(dev_config->string2),
770 le16_to_cpu(dev_config->string3));
779 /* ----------------------------------------------------------- */
784 static u32 functionality(struct i2c_adapter *i2c_adap)
786 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data;
788 if ((i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) ||
789 (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)) {
790 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
791 } else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) {
792 return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL) &
793 ~I2C_FUNC_SMBUS_WRITE_BLOCK_DATA;
796 WARN(1, "Unknown i2c bus algorithm.\n");
800 static struct i2c_algorithm em28xx_algo = {
801 .master_xfer = em28xx_i2c_xfer,
802 .functionality = functionality,
805 static struct i2c_adapter em28xx_adap_template = {
806 .owner = THIS_MODULE,
808 .algo = &em28xx_algo,
811 static struct i2c_client em28xx_client_template = {
812 .name = "em28xx internal",
815 /* ----------------------------------------------------------- */
819 * incomplete list of known devices
821 static char *i2c_devs[128] = {
822 [0x3e >> 1] = "remote IR sensor",
823 [0x4a >> 1] = "saa7113h",
824 [0x52 >> 1] = "drxk",
825 [0x60 >> 1] = "remote IR sensor",
826 [0x8e >> 1] = "remote IR sensor",
827 [0x86 >> 1] = "tda9887",
828 [0x80 >> 1] = "msp34xx",
829 [0x88 >> 1] = "msp34xx",
830 [0xa0 >> 1] = "eeprom",
831 [0xb0 >> 1] = "tda9874",
832 [0xb8 >> 1] = "tvp5150a",
833 [0xba >> 1] = "webcam sensor or tvp5150a",
834 [0xc0 >> 1] = "tuner (analog)",
835 [0xc2 >> 1] = "tuner (analog)",
836 [0xc4 >> 1] = "tuner (analog)",
837 [0xc6 >> 1] = "tuner (analog)",
842 * check i2c address range for devices
844 void em28xx_do_i2c_scan(struct em28xx *dev, unsigned bus)
846 u8 i2c_devicelist[128];
850 memset(i2c_devicelist, 0, ARRAY_SIZE(i2c_devicelist));
852 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
853 dev->i2c_client[bus].addr = i;
854 rc = i2c_master_recv(&dev->i2c_client[bus], &buf, 0);
857 i2c_devicelist[i] = i;
858 em28xx_info("found i2c device @ 0x%x on bus %d [%s]\n",
859 i << 1, bus, i2c_devs[i] ? i2c_devs[i] : "???");
862 if (bus == dev->def_i2c_bus)
863 dev->i2c_hash = em28xx_hash_mem(i2c_devicelist,
864 ARRAY_SIZE(i2c_devicelist), 32);
868 * em28xx_i2c_register()
871 int em28xx_i2c_register(struct em28xx *dev, unsigned bus,
872 enum em28xx_i2c_algo_type algo_type)
876 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
877 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
879 if (bus >= NUM_I2C_BUSES)
882 dev->i2c_adap[bus] = em28xx_adap_template;
883 dev->i2c_adap[bus].dev.parent = &dev->udev->dev;
884 strcpy(dev->i2c_adap[bus].name, dev->name);
886 dev->i2c_bus[bus].bus = bus;
887 dev->i2c_bus[bus].algo_type = algo_type;
888 dev->i2c_bus[bus].dev = dev;
889 dev->i2c_adap[bus].algo_data = &dev->i2c_bus[bus];
890 i2c_set_adapdata(&dev->i2c_adap[bus], &dev->v4l2_dev);
892 retval = i2c_add_adapter(&dev->i2c_adap[bus]);
894 em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
899 dev->i2c_client[bus] = em28xx_client_template;
900 dev->i2c_client[bus].adapter = &dev->i2c_adap[bus];
902 /* Up to now, all eeproms are at bus 0 */
904 retval = em28xx_i2c_eeprom(dev, bus, &dev->eedata, &dev->eedata_len);
905 if ((retval < 0) && (retval != -ENODEV)) {
906 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
914 em28xx_do_i2c_scan(dev, bus);
920 * em28xx_i2c_unregister()
923 int em28xx_i2c_unregister(struct em28xx *dev, unsigned bus)
925 if (bus >= NUM_I2C_BUSES)
928 i2c_del_adapter(&dev->i2c_adap[bus]);