Commit e30b9d6c authored by Chris Pascoe's avatar Chris Pascoe Committed by Mauro Carvalho Chehab

V4L/DVB (12821): tm6000: update USB request names and clean up i2c routine

Update the descriptions of the USB request types so that they match what
we now know they do.

Rework the i2c_xfer function so that it is more explicit what sort of I2C
transfers it is that the tm6000 can't perform.
Signed-off-by: default avatarChris Pascoe <c.pascoe@itee.uq.edu.au>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent cf9e1509
...@@ -73,7 +73,7 @@ static int tm6000_i2c_scan(struct i2c_adapter *i2c_adap, int addr) ...@@ -73,7 +73,7 @@ static int tm6000_i2c_scan(struct i2c_adapter *i2c_adap, int addr)
/* This sends addr + 1 byte with 0 */ /* This sends addr + 1 byte with 0 */
rc = tm6000_read_write_usb (dev, rc = tm6000_read_write_usb (dev,
USB_DIR_IN | USB_TYPE_VENDOR, USB_DIR_IN | USB_TYPE_VENDOR,
REQ_16_SET_GET_I2CSEQ, REQ_16_SET_GET_I2C_WR1_RDN,
addr, 0, addr, 0,
buf, 0); buf, 0);
msleep(10); msleep(10);
...@@ -94,82 +94,61 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -94,82 +94,61 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
{ {
struct tm6000_core *dev = i2c_adap->algo_data; struct tm6000_core *dev = i2c_adap->algo_data;
int addr, rc, i, byte; int addr, rc, i, byte;
int prev_reg = -1;
if (num <= 0) if (num <= 0)
return 0; return 0;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
addr = (msgs[i].addr << 1) &0xff; addr = (msgs[i].addr << 1) & 0xff;
i2c_dprintk(2,"%s %s addr=0x%x len=%d:", i2c_dprintk(2,"%s %s addr=0x%x len=%d:",
(msgs[i].flags & I2C_M_RD) ? "read" : "write", (msgs[i].flags & I2C_M_RD) ? "read" : "write",
i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len);
if (!msgs[i].len) { if (!msgs[i].len) {
/* Do I2C scan */ /* Do I2C scan */
rc=tm6000_i2c_scan(i2c_adap, addr); rc = tm6000_i2c_scan(i2c_adap, addr);
} else if (msgs[i].flags & I2C_M_RD) { } else if (msgs[i].flags & I2C_M_RD) {
/* Read bytes */ /* read request without preceding register selection */
/* I2C is assumed to have always a subaddr at the first byte of the /*
message bus. Also, the first i2c value of the answer is returned * The TM6000 only supports a read transaction
out of message data. * immediately after a 1 or 2 byte write to select
* a register. We cannot fulfil this request.
*/ */
/* SMBus Read Byte command */ i2c_dprintk(2, " read without preceding write not"
if (prev_reg < 0) " supported");
printk("XXX read from unknown prev_reg\n"); rc = -EOPNOTSUPP;
rc = tm6000_read_write_usb (dev, goto err;
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, } else if (i + 1 < num && msgs[i].len <= 2 &&
REQ_16_SET_GET_I2CSEQ, (msgs[i + 1].flags & I2C_M_RD) &&
addr | (prev_reg << 8), 0, msgs[i].addr == msgs[i + 1].addr) {
msgs[i].buf, msgs[i].len); /* 1 or 2 byte write followed by a read */
if (prev_reg >= 0) if (i2c_debug >= 2)
prev_reg += msgs[i].len; for (byte = 0; byte < msgs[i].len; byte++)
if (i2c_debug>=2) {
for (byte = 0; byte < msgs[i].len; byte++) {
printk(" %02x", msgs[i].buf[byte]); printk(" %02x", msgs[i].buf[byte]);
} i2c_dprintk(2, "; joined to read %s len=%d:",
} i == num - 2 ? "stop" : "nonstop",
} else if (i+1 < num && msgs[i].len == 2 && msgs[i + 1].len);
(msgs[i+1].flags & I2C_M_RD) &&
msgs[i].addr == msgs[i+1].addr) {
i2c_dprintk(2, "msg %d: write 2, read %d", i,
msgs[i+1].len);
/* Write 2 Read N command */
rc = tm6000_read_write_usb (dev, rc = tm6000_read_write_usb (dev,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_14_SET_GET_EEPROM_PAGE, /* XXX wrong name */ msgs[i].len == 1 ? REQ_16_SET_GET_I2C_WR1_RDN
addr | msgs[i].buf[0] << 8, msgs[i].buf[1], : REQ_14_SET_GET_I2C_WR2_RDN,
msgs[i+1].buf, msgs[i+1].len); addr | msgs[i].buf[0] << 8,
msgs[i].len == 1 ? 0 : msgs[i].buf[1],
msgs[i + 1].buf, msgs[i + 1].len);
i++; i++;
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]);
}
}
prev_reg = -1;
} else { } else {
/* write bytes */ /* write bytes */
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,
/* SMBus Write Byte command followed by a read command */
if(msgs[i].len == 1 && i+1 < num && msgs[i+1].flags & I2C_M_RD
&& msgs[i+1].addr == msgs[i].addr) {
prev_reg = msgs[i].buf[0];
if (i2c_debug >= 2)
printk("\n");
continue;
}
rc = tm6000_read_write_usb (dev,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2CSEQ, REQ_16_SET_GET_I2C_WR1_RDN,
addr|(*msgs[i].buf)<<8, 0, addr | msgs[i].buf[0] << 8, 0,
msgs[i].buf+1, msgs[i].len-1); msgs[i].buf + 1, msgs[i].len - 1);
prev_reg = -1;
} }
if (i2c_debug>=2) if (i2c_debug >= 2)
printk("\n"); printk("\n");
if (rc < 0) if (rc < 0)
goto err; goto err;
...@@ -181,7 +160,6 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -181,7 +160,6 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
return rc; return rc;
} }
static int tm6000_i2c_eeprom(struct tm6000_core *dev, static int tm6000_i2c_eeprom(struct tm6000_core *dev,
unsigned char *eedata, int len) unsigned char *eedata, int len)
{ {
...@@ -196,7 +174,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev, ...@@ -196,7 +174,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev,
*p = i; *p = i;
rc = tm6000_read_write_usb (dev, rc = tm6000_read_write_usb (dev,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
REQ_16_SET_GET_I2CSEQ, 0xa0 | i<<8, 0, p, 1); 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;
...@@ -273,7 +251,7 @@ static void dec_use(struct i2c_adapter *adap) ...@@ -273,7 +251,7 @@ static void dec_use(struct i2c_adapter *adap)
#define mass_write(addr, reg, data...) \ #define mass_write(addr, reg, data...) \
{ const static u8 _val[] = data; \ { const static u8 _val[] = data; \
rc=tm6000_read_write_usb(dev,USB_DIR_OUT | USB_TYPE_VENDOR, \ rc=tm6000_read_write_usb(dev,USB_DIR_OUT | USB_TYPE_VENDOR, \
REQ_16_SET_GET_I2CSEQ,(reg<<8)+addr, 0x00, (u8 *) _val, \ REQ_16_SET_GET_I2C_WR1_RDN,(reg<<8)+addr, 0x00, (u8 *) _val, \
ARRAY_SIZE(_val)); \ ARRAY_SIZE(_val)); \
if (rc<0) { \ if (rc<0) { \
printk(KERN_ERR "Error on line %d: %d\n",__LINE__,rc); \ printk(KERN_ERR "Error on line %d: %d\n",__LINE__,rc); \
......
...@@ -38,11 +38,11 @@ ...@@ -38,11 +38,11 @@
#define REQ_11_SET_EEPROM_ADDR 11 #define REQ_11_SET_EEPROM_ADDR 11
#define REQ_12_SET_GET_EEPROMBYTE 12 #define REQ_12_SET_GET_EEPROMBYTE 12
#define REQ_13_GET_EEPROM_SEQREAD 13 #define REQ_13_GET_EEPROM_SEQREAD 13
#define REQ_14_SET_GET_EEPROM_PAGE 14 #define REQ_14_SET_GET_I2C_WR2_RDN 14
#define REQ_15_SET_GET_I2CBYTE 15 #define REQ_15_SET_GET_I2CBYTE 15
/* Write: Subaddr, Slave Addr, value, 0 */ /* Write: Subaddr, Slave Addr, value, 0 */
/* Read : Subaddr, Slave Addr, value, 1 */ /* Read : Subaddr, Slave Addr, value, 1 */
#define REQ_16_SET_GET_I2CSEQ 16 #define REQ_16_SET_GET_I2C_WR1_RDN 16
/* Subaddr, Slave Addr, 0, length */ /* Subaddr, Slave Addr, 0, length */
#define REQ_17_SET_GET_I2CFP 17 #define REQ_17_SET_GET_I2CFP 17
/* Write: Slave Addr, register, value */ /* Write: Slave Addr, register, value */
......
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