Lines Matching +full:no +full:- +full:eeprom
1 // SPDX-License-Identifier: GPL-2.0+
3 // em28xx-i2c.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
29 #include "tuner-xc2028.h"
30 #include <media/v4l2-common.h>
33 /* ----------------------------------------------------------- */
45 dev_printk(KERN_DEBUG, &dev->intf->dev, \
64 switch (dev->i2c_speed & 0x03) { in em28xx_i2c_timeout()
90 return -EOPNOTSUPP; in em2800_i2c_send_bytes()
92 b2[5] = 0x80 + len - 1; in em2800_i2c_send_bytes()
103 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len); in em2800_i2c_send_bytes()
105 dev_warn(&dev->intf->dev, in em2800_i2c_send_bytes()
108 return (ret < 0) ? ret : -EIO; in em2800_i2c_send_bytes()
112 ret = dev->em28xx_read_reg(dev, 0x05); in em2800_i2c_send_bytes()
113 if (ret == 0x80 + len - 1) in em2800_i2c_send_bytes()
115 if (ret == 0x94 + len - 1) { in em2800_i2c_send_bytes()
117 return -ENXIO; in em2800_i2c_send_bytes()
120 dev_warn(&dev->intf->dev, in em2800_i2c_send_bytes()
128 return -ETIMEDOUT; in em2800_i2c_send_bytes()
143 return -EOPNOTSUPP; in em2800_i2c_recv_bytes()
146 buf2[1] = 0x84 + len - 1; in em2800_i2c_recv_bytes()
148 ret = dev->em28xx_write_regs(dev, 0x04, buf2, 2); in em2800_i2c_recv_bytes()
150 dev_warn(&dev->intf->dev, in em2800_i2c_recv_bytes()
153 return (ret < 0) ? ret : -EIO; in em2800_i2c_recv_bytes()
158 ret = dev->em28xx_read_reg(dev, 0x05); in em2800_i2c_recv_bytes()
159 if (ret == 0x84 + len - 1) in em2800_i2c_recv_bytes()
161 if (ret == 0x94 + len - 1) { in em2800_i2c_recv_bytes()
164 return -ENXIO; in em2800_i2c_recv_bytes()
167 dev_warn(&dev->intf->dev, in em2800_i2c_recv_bytes()
174 if (ret != 0x84 + len - 1) in em2800_i2c_recv_bytes()
178 ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4 - len, buf2, len); in em2800_i2c_recv_bytes()
180 dev_warn(&dev->intf->dev, in em2800_i2c_recv_bytes()
183 return (ret < 0) ? ret : -EIO; in em2800_i2c_recv_bytes()
186 buf[i] = buf2[len - 1 - i]; in em2800_i2c_recv_bytes()
203 return (ret < 0) ? ret : -EIO; in em2800_i2c_check_for_device()
216 return -EOPNOTSUPP; in em28xx_i2c_send_bytes()
219 * Zero length reads always succeed, even if no device is connected in em28xx_i2c_send_bytes()
223 ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); in em28xx_i2c_send_bytes()
226 dev_warn(&dev->intf->dev, in em28xx_i2c_send_bytes()
231 dev_warn(&dev->intf->dev, in em28xx_i2c_send_bytes()
234 return -EIO; in em28xx_i2c_send_bytes()
239 ret = dev->em28xx_read_reg(dev, 0x05); in em28xx_i2c_send_bytes()
245 return -ENXIO; in em28xx_i2c_send_bytes()
248 dev_warn(&dev->intf->dev, in em28xx_i2c_send_bytes()
266 return -ETIMEDOUT; in em28xx_i2c_send_bytes()
269 dev_warn(&dev->intf->dev, in em28xx_i2c_send_bytes()
272 return -EIO; in em28xx_i2c_send_bytes()
284 return -EOPNOTSUPP; in em28xx_i2c_recv_bytes()
287 * Zero length reads always succeed, even if no device is connected in em28xx_i2c_recv_bytes()
291 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); in em28xx_i2c_recv_bytes()
293 dev_warn(&dev->intf->dev, in em28xx_i2c_recv_bytes()
300 * bytes if we are on bus B AND there was no write attempt to the in em28xx_i2c_recv_bytes()
301 * specified slave address before AND no device is present at the in em28xx_i2c_recv_bytes()
303 * Anyway, the next check will fail with -ENXIO in this case, so avoid in em28xx_i2c_recv_bytes()
308 ret = dev->em28xx_read_reg(dev, 0x05); in em28xx_i2c_recv_bytes()
312 dev_warn(&dev->intf->dev, in em28xx_i2c_recv_bytes()
320 return -ENXIO; in em28xx_i2c_recv_bytes()
328 return -ETIMEDOUT; in em28xx_i2c_recv_bytes()
331 dev_warn(&dev->intf->dev, in em28xx_i2c_recv_bytes()
334 return -EIO; in em28xx_i2c_recv_bytes()
349 return (ret < 0) ? ret : -EIO; in em28xx_i2c_check_for_device()
362 return -EOPNOTSUPP; in em25xx_bus_B_send_bytes()
365 * Zero length reads always succeed, even if no device is connected in em25xx_bus_B_send_bytes()
369 ret = dev->em28xx_write_regs_req(dev, 0x06, addr, buf, len); in em25xx_bus_B_send_bytes()
372 dev_warn(&dev->intf->dev, in em25xx_bus_B_send_bytes()
378 dev_warn(&dev->intf->dev, in em25xx_bus_B_send_bytes()
381 return -EIO; in em25xx_bus_B_send_bytes()
384 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000); in em25xx_bus_B_send_bytes()
394 return -ENXIO; in em25xx_bus_B_send_bytes()
400 * this operation, it seems to succeed ALWAYS ! (even if there is no in em25xx_bus_B_send_bytes()
401 * slave device or even no second i2c bus provided) in em25xx_bus_B_send_bytes()
415 return -EOPNOTSUPP; in em25xx_bus_B_recv_bytes()
418 * Zero length reads always succeed, even if no device is connected in em25xx_bus_B_recv_bytes()
422 ret = dev->em28xx_read_reg_req_len(dev, 0x06, addr, buf, len); in em25xx_bus_B_recv_bytes()
424 dev_warn(&dev->intf->dev, in em25xx_bus_B_recv_bytes()
431 * bytes if we are on bus B AND there was no write attempt to the in em25xx_bus_B_recv_bytes()
432 * specified slave address before AND no device is present at the in em25xx_bus_B_recv_bytes()
434 * Anyway, the next check will fail with -ENXIO in this case, so avoid in em25xx_bus_B_recv_bytes()
439 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000); in em25xx_bus_B_recv_bytes()
449 return -ENXIO; in em25xx_bus_B_recv_bytes()
455 * this operation, it seems to succeed ALWAYS ! (even if there is no in em25xx_bus_B_recv_bytes()
456 * slave device or even no second i2c bus provided) in em25xx_bus_B_recv_bytes()
476 * it seems to succeed ALWAYS ! (even if no device connected) in em25xx_bus_B_check_for_device()
482 struct em28xx *dev = i2c_bus->dev; in i2c_check_for_device()
483 int rc = -EOPNOTSUPP; in i2c_check_for_device()
485 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) in i2c_check_for_device()
487 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) in i2c_check_for_device()
489 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) in i2c_check_for_device()
497 struct em28xx *dev = i2c_bus->dev; in i2c_recv_bytes()
499 int rc = -EOPNOTSUPP; in i2c_recv_bytes()
501 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) in i2c_recv_bytes()
503 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) in i2c_recv_bytes()
505 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) in i2c_recv_bytes()
513 struct em28xx *dev = i2c_bus->dev; in i2c_send_bytes()
515 int rc = -EOPNOTSUPP; in i2c_send_bytes()
517 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) in i2c_send_bytes()
519 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) in i2c_send_bytes()
521 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) in i2c_send_bytes()
533 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data; in em28xx_i2c_xfer()
534 struct em28xx *dev = i2c_bus->dev; in em28xx_i2c_xfer()
535 unsigned int bus = i2c_bus->bus; in em28xx_i2c_xfer()
544 if (dev->disconnected) in em28xx_i2c_xfer()
545 return -ENODEV; in em28xx_i2c_xfer()
547 if (!rt_mutex_trylock(&dev->i2c_bus_lock)) in em28xx_i2c_xfer()
548 return -EAGAIN; in em28xx_i2c_xfer()
551 if (bus != dev->cur_i2c_bus && in em28xx_i2c_xfer()
552 i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) { in em28xx_i2c_xfer()
559 dev->cur_i2c_bus = bus; in em28xx_i2c_xfer()
566 * no len: check only for device presence in em28xx_i2c_xfer()
571 if (rc == -ENXIO) in em28xx_i2c_xfer()
572 rc = -ENODEV; in em28xx_i2c_xfer()
578 rc = i2c_send_bytes(i2c_bus, msgs[i], i == num - 1); in em28xx_i2c_xfer()
586 i == num - 1 ? "stop" : "nonstop", in em28xx_i2c_xfer()
591 rt_mutex_unlock(&dev->i2c_bus_lock); in em28xx_i2c_xfer()
597 i == num - 1 ? "stop" : "nonstop", in em28xx_i2c_xfer()
599 (rc == -ENODEV) ? "no device " : "", in em28xx_i2c_xfer()
602 rt_mutex_unlock(&dev->i2c_bus_lock); in em28xx_i2c_xfer()
621 len = -1; in em28xx_hash_mem()
627 if ((len & (32 / 8 - 1)) == 0) in em28xx_hash_mem()
631 return (hash >> (32 - bits)) & 0xffffffffUL; in em28xx_hash_mem()
646 return -EINVAL; in em28xx_i2c_read_block()
650 ret = i2c_master_send(&dev->i2c_client[bus], in em28xx_i2c_read_block()
655 if (dev->board.is_em2800) in em28xx_i2c_read_block()
665 ret = i2c_master_recv(&dev->i2c_client[bus], data, rsize); in em28xx_i2c_read_block()
669 remain -= rsize; in em28xx_i2c_read_block()
692 /* EEPROM is always on i2c bus 0 on all known devices. */ in em28xx_i2c_eeprom()
694 dev->i2c_client[bus].addr = 0xa0 >> 1; in em28xx_i2c_eeprom()
696 /* Check if board has eeprom */ in em28xx_i2c_eeprom()
697 err = i2c_master_recv(&dev->i2c_client[bus], &buf, 0); in em28xx_i2c_eeprom()
699 dev_info(&dev->intf->dev, "board has no eeprom\n"); in em28xx_i2c_eeprom()
700 return -ENODEV; in em28xx_i2c_eeprom()
705 return -ENOMEM; in em28xx_i2c_eeprom()
707 /* Read EEPROM content */ in em28xx_i2c_eeprom()
709 dev->eeprom_addrwidth_16bit, in em28xx_i2c_eeprom()
712 dev_err(&dev->intf->dev, in em28xx_i2c_eeprom()
713 "failed to read eeprom (err=%d)\n", err); in em28xx_i2c_eeprom()
718 /* Display eeprom content */ in em28xx_i2c_eeprom()
719 print_hex_dump(KERN_DEBUG, "em28xx eeprom ", DUMP_PREFIX_OFFSET, in em28xx_i2c_eeprom()
722 if (dev->eeprom_addrwidth_16bit) in em28xx_i2c_eeprom()
723 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
724 "eeprom %06x: ... (skipped)\n", 256); in em28xx_i2c_eeprom()
727 if (dev->eeprom_addrwidth_16bit && in em28xx_i2c_eeprom()
729 /* new eeprom format; size 4-64kb */ in em28xx_i2c_eeprom()
733 dev->hash = em28xx_hash_mem(data, len, 32); in em28xx_i2c_eeprom()
736 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
737 "EEPROM ID = %4ph, EEPROM hash = 0x%08lx\n", in em28xx_i2c_eeprom()
738 data, dev->hash); in em28xx_i2c_eeprom()
739 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
740 "EEPROM info:\n"); in em28xx_i2c_eeprom()
741 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
749 * [4] 1 = force fast mode and no suspend for device testing in em28xx_i2c_eeprom()
761 dev_err(&dev->intf->dev, in em28xx_i2c_eeprom()
762 "failed to read hardware configuration data from eeprom (err=%d)\n", in em28xx_i2c_eeprom()
774 * the old eeprom and not longer than 256 bytes. in em28xx_i2c_eeprom()
780 dev_err(&dev->intf->dev, in em28xx_i2c_eeprom()
781 "failed to read hardware configuration data from eeprom (err=%d)\n", in em28xx_i2c_eeprom()
790 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
791 "\tno hardware configuration dataset found in eeprom\n"); in em28xx_i2c_eeprom()
797 * TODO: decrypt eeprom data for camera bridges in em28xx_i2c_eeprom()
801 } else if (!dev->eeprom_addrwidth_16bit && in em28xx_i2c_eeprom()
804 dev->hash = em28xx_hash_mem(data, len, 32); in em28xx_i2c_eeprom()
805 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
806 "EEPROM ID = %4ph, EEPROM hash = 0x%08lx\n", in em28xx_i2c_eeprom()
807 data, dev->hash); in em28xx_i2c_eeprom()
808 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
809 "EEPROM info:\n"); in em28xx_i2c_eeprom()
811 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
812 "unknown eeprom format or eeprom corrupted !\n"); in em28xx_i2c_eeprom()
813 err = -ENODEV; in em28xx_i2c_eeprom()
821 switch (le16_to_cpu(dev_config->chip_conf) >> 4 & 0x3) { in em28xx_i2c_eeprom()
823 dev_info(&dev->intf->dev, "\tNo audio on board.\n"); in em28xx_i2c_eeprom()
826 dev_info(&dev->intf->dev, "\tAC97 audio (5 sample rates)\n"); in em28xx_i2c_eeprom()
829 if (dev->chip_id < CHIP_ID_EM2860) in em28xx_i2c_eeprom()
830 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
833 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
837 if (dev->chip_id < CHIP_ID_EM2860) in em28xx_i2c_eeprom()
838 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
841 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
846 if (le16_to_cpu(dev_config->chip_conf) & 1 << 3) in em28xx_i2c_eeprom()
847 dev_info(&dev->intf->dev, "\tUSB Remote wakeup capable\n"); in em28xx_i2c_eeprom()
849 if (le16_to_cpu(dev_config->chip_conf) & 1 << 2) in em28xx_i2c_eeprom()
850 dev_info(&dev->intf->dev, "\tUSB Self power capable\n"); in em28xx_i2c_eeprom()
852 switch (le16_to_cpu(dev_config->chip_conf) & 0x3) { in em28xx_i2c_eeprom()
854 dev_info(&dev->intf->dev, "\t500mA max power\n"); in em28xx_i2c_eeprom()
857 dev_info(&dev->intf->dev, "\t400mA max power\n"); in em28xx_i2c_eeprom()
860 dev_info(&dev->intf->dev, "\t300mA max power\n"); in em28xx_i2c_eeprom()
863 dev_info(&dev->intf->dev, "\t200mA max power\n"); in em28xx_i2c_eeprom()
866 dev_info(&dev->intf->dev, in em28xx_i2c_eeprom()
868 dev_config->string_idx_table, in em28xx_i2c_eeprom()
869 le16_to_cpu(dev_config->string1), in em28xx_i2c_eeprom()
870 le16_to_cpu(dev_config->string2), in em28xx_i2c_eeprom()
871 le16_to_cpu(dev_config->string3)); in em28xx_i2c_eeprom()
880 /* ----------------------------------------------------------- */
887 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data; in functionality()
889 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX || in functionality()
890 i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) { in functionality()
892 } else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) { in functionality()
916 /* ----------------------------------------------------------- */
932 [0xa0 >> 1] = "eeprom",
955 dev->i2c_client[bus].addr = i; in em28xx_do_i2c_scan()
956 rc = i2c_master_recv(&dev->i2c_client[bus], &buf, 0); in em28xx_do_i2c_scan()
960 dev_info(&dev->intf->dev, in em28xx_do_i2c_scan()
965 if (bus == dev->def_i2c_bus) in em28xx_do_i2c_scan()
966 dev->i2c_hash = em28xx_hash_mem(i2c_devicelist, in em28xx_do_i2c_scan()
979 if (WARN_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg || in em28xx_i2c_register()
980 !dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req)) in em28xx_i2c_register()
981 return -ENODEV; in em28xx_i2c_register()
984 return -ENODEV; in em28xx_i2c_register()
986 dev->i2c_adap[bus] = em28xx_adap_template; in em28xx_i2c_register()
987 dev->i2c_adap[bus].dev.parent = &dev->intf->dev; in em28xx_i2c_register()
988 strscpy(dev->i2c_adap[bus].name, dev_name(&dev->intf->dev), in em28xx_i2c_register()
989 sizeof(dev->i2c_adap[bus].name)); in em28xx_i2c_register()
991 dev->i2c_bus[bus].bus = bus; in em28xx_i2c_register()
992 dev->i2c_bus[bus].algo_type = algo_type; in em28xx_i2c_register()
993 dev->i2c_bus[bus].dev = dev; in em28xx_i2c_register()
994 dev->i2c_adap[bus].algo_data = &dev->i2c_bus[bus]; in em28xx_i2c_register()
996 retval = i2c_add_adapter(&dev->i2c_adap[bus]); in em28xx_i2c_register()
998 dev_err(&dev->intf->dev, in em28xx_i2c_register()
1004 dev->i2c_client[bus] = em28xx_client_template; in em28xx_i2c_register()
1005 dev->i2c_client[bus].adapter = &dev->i2c_adap[bus]; in em28xx_i2c_register()
1010 &dev->eedata, &dev->eedata_len); in em28xx_i2c_register()
1011 if (retval < 0 && retval != -ENODEV) { in em28xx_i2c_register()
1012 dev_err(&dev->intf->dev, in em28xx_i2c_register()
1031 return -ENODEV; in em28xx_i2c_unregister()
1033 i2c_del_adapter(&dev->i2c_adap[bus]); in em28xx_i2c_unregister()