^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // tm6000-i2c.c - driver for TM5600/TM6000/TM6010 USB video capture devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Copyright (c) 2006-2007 Mauro Carvalho Chehab <mchehab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Copyright (c) 2007 Michel Ludwig <michel.ludwig@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // - Fix SMBus Read Byte command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "tm6000.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "tm6000-regs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <media/v4l2-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <media/tuner.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "tuner-xc2028.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* ----------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static unsigned int i2c_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) module_param(i2c_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define i2c_dprintk(lvl, fmt, args...) if (i2c_debug >= lvl) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) printk(KERN_DEBUG "%s at %s: " fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) dev->name, __func__, ##args); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int tm6000_i2c_send_regs(struct tm6000_core *dev, unsigned char addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) __u8 reg, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int i2c_packet_limit = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (dev->dev_type == TM6010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) i2c_packet_limit = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (len < 1 || len > i2c_packet_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) len, i2c_packet_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* capture mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) addr | reg << 8, 0, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* release mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* release mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Generic read - doesn't work fine with 16bit registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __u8 reg, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 b[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned int i2c_packet_limit = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (dev->dev_type == TM6010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) i2c_packet_limit = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (len < 1 || len > i2c_packet_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) len, i2c_packet_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* capture mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if ((dev->caps.has_zl10353) && (dev->demod_addr << 1 == addr) && (reg % 2 == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Workaround an I2C bug when reading from zl10353
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) reg -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) len += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, b, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *buf = b[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* release mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * read from a 16bit register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * for example xc2028, xc3028 or xc3028L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __u16 reg, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned char ureg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!buf || len != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* capture mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (dev->dev_type == TM6010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ureg = reg & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) addr | (reg & 0xFF00), 0, &ureg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* release mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) USB_RECIP_DEVICE, REQ_35_AFTEK_TUNER_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) reg, 0, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) USB_RECIP_DEVICE, REQ_14_SET_GET_I2C_WR2_RDN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) addr, reg, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* release mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct i2c_msg msgs[], int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct tm6000_core *dev = i2c_adap->algo_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int addr, rc, i, byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) addr = (msgs[i].addr << 1) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) i2c_dprintk(2, "%s %s addr=0x%x len=%d:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) (msgs[i].flags & I2C_M_RD) ? "read" : "write",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (msgs[i].flags & I2C_M_RD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* read request without preceding register selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * The TM6000 only supports a read transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * immediately after a 1 or 2 byte write to select
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * a register. We cannot fulfill this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) i2c_dprintk(2, " read without preceding write not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) } else if (i + 1 < num && msgs[i].len <= 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) (msgs[i + 1].flags & I2C_M_RD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) msgs[i].addr == msgs[i + 1].addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* 1 or 2 byte write followed by a read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (i2c_debug >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) for (byte = 0; byte < msgs[i].len; byte++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) printk(KERN_CONT " %02x", msgs[i].buf[byte]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) i2c_dprintk(2, "; joined to read %s len=%d:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) i == num - 2 ? "stop" : "nonstop",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) msgs[i + 1].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (msgs[i].len == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) rc = tm6000_i2c_recv_regs16(dev, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) msgs[i].buf[0] << 8 | msgs[i].buf[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) msgs[i + 1].buf, msgs[i + 1].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) msgs[i + 1].buf, msgs[i + 1].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (addr == dev->tuner_addr << 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (i2c_debug >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) for (byte = 0; byte < msgs[i].len; byte++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) printk(KERN_CONT " %02x", msgs[i].buf[byte]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* write bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (i2c_debug >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) for (byte = 0; byte < msgs[i].len; byte++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) printk(KERN_CONT " %02x", msgs[i].buf[byte]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) msgs[i].buf + 1, msgs[i].len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (i2c_debug >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) printk(KERN_CONT "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) i2c_dprintk(2, " ERROR: %i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int tm6000_i2c_eeprom(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned char *p = dev->eedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) unsigned char bytes[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dev->i2c_client.addr = 0xa0 >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dev->eedata_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bytes[16] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) for (i = 0; i < sizeof(dev->eedata); ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *p = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (rc < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (p == dev->eedata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) goto noeeprom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) "%s: i2c eeprom read error (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dev->eedata_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (0 == (i % 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) printk(KERN_CONT " %02x", dev->eedata[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if ((dev->eedata[i] >= ' ') && (dev->eedata[i] <= 'z'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) bytes[i%16] = dev->eedata[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bytes[i%16] = '.';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (0 == (i % 16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) bytes[16] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) printk(KERN_CONT " %s\n", bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (0 != (i%16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) bytes[i%16] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) for (i %= 16; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) printk(KERN_CONT " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) printk(KERN_CONT " %s\n", bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) noeeprom:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dev->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* ----------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * functionality()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static u32 functionality(struct i2c_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return I2C_FUNC_SMBUS_EMUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static const struct i2c_algorithm tm6000_algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .master_xfer = tm6000_i2c_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .functionality = functionality,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* ----------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * tm6000_i2c_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * register i2c bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int tm6000_i2c_register(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) dev->i2c_adap.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dev->i2c_adap.algo = &tm6000_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) dev->i2c_adap.dev.parent = &dev->udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) strscpy(dev->i2c_adap.name, dev->name, sizeof(dev->i2c_adap.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) dev->i2c_adap.algo_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) rc = i2c_add_adapter(&dev->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) dev->i2c_client.adapter = &dev->i2c_adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) strscpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) tm6000_i2c_eeprom(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * tm6000_i2c_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * unregister i2c_bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int tm6000_i2c_unregister(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) i2c_del_adapter(&dev->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }