Commit 4e11502d authored by Stefan Ringel's avatar Stefan Ringel Committed by Mauro Carvalho Chehab

V4L/DVB: tm6000: add send and recv function

Split the i2c send and receive functions on separate functions

[mchehab@redhat.com: CodingStyle and fix the logic for more than 2 read values]
Signed-off-by: default avatarStefan Ringel <stefan.ringel@arcor.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent e28f49b0
...@@ -44,6 +44,36 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); ...@@ -44,6 +44,36 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
printk(KERN_DEBUG "%s at %s: " fmt, \ printk(KERN_DEBUG "%s at %s: " fmt, \
dev->name, __FUNCTION__ , ##args); } while (0) dev->name, __FUNCTION__ , ##args); } while (0)
static int tm6000_i2c_send_regs(struct tm6000_core *dev, unsigned char addr,
__u8 reg, char *buf, int len)
{
return tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len);
}
/* Generic read - doesn't work fine with 16bit registers */
static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr,
__u8 reg, char *buf, int len)
{
int rc;
rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len);
return rc;
}
/*
* read from a 16bit register
* for example xc2028, xc3028 or xc3028L
*/
static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr,
__u16 reg, char *buf, int len)
{
return tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_14_SET_GET_I2C_WR2_RDN, addr, reg, buf, len);
}
static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
struct i2c_msg msgs[], int num) struct i2c_msg msgs[], int num)
{ {
...@@ -78,13 +108,16 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -78,13 +108,16 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
i2c_dprintk(2, "; joined to read %s len=%d:", i2c_dprintk(2, "; joined to read %s len=%d:",
i == num - 2 ? "stop" : "nonstop", i == num - 2 ? "stop" : "nonstop",
msgs[i + 1].len); msgs[i + 1].len);
rc = tm6000_read_write_usb (dev,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, if (msgs[i].len == 2) {
msgs[i].len == 1 ? REQ_16_SET_GET_I2C_WR1_RDN rc = tm6000_i2c_recv_regs16(dev, addr,
: REQ_14_SET_GET_I2C_WR2_RDN, msgs[i].buf[0] << 8 | msgs[i].buf[1],
addr | msgs[i].buf[0] << 8,
msgs[i].len == 1 ? 0 : msgs[i].buf[1],
msgs[i + 1].buf, msgs[i + 1].len); msgs[i + 1].buf, msgs[i + 1].len);
} else {
rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0],
msgs[i + 1].buf, msgs[i + 1].len);
}
i++; i++;
if (addr == dev->tuner_addr << 1) { if (addr == dev->tuner_addr << 1) {
...@@ -99,10 +132,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -99,10 +132,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
if (i2c_debug >= 2) if (i2c_debug >= 2)
for (byte = 0; byte < msgs[i].len; byte++) for (byte = 0; byte < msgs[i].len; byte++)
printk(" %02x", msgs[i].buf[byte]); printk(" %02x", msgs[i].buf[byte]);
rc = tm6000_read_write_usb(dev, rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0],
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2C_WR1_RDN,
addr | msgs[i].buf[0] << 8, 0,
msgs[i].buf + 1, msgs[i].len - 1); msgs[i].buf + 1, msgs[i].len - 1);
if (addr == dev->tuner_addr << 1) { if (addr == dev->tuner_addr << 1) {
...@@ -134,9 +164,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev, ...@@ -134,9 +164,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev,
bytes[16] = '\0'; bytes[16] = '\0';
for (i = 0; i < len; ) { for (i = 0; i < len; ) {
*p = i; *p = i;
rc = tm6000_read_write_usb (dev, rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1);
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2C_WR1_RDN, 0xa0 | i<<8, 0, p, 1);
if (rc < 1) { if (rc < 1) {
if (p == eedata) if (p == eedata)
goto noeeprom; goto noeeprom;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment