aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Pascoe <c.pascoe@itee.uq.edu.au>2007-11-23 11:18:56 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:40:02 -0400
commitcf9e1509c278c3d5005f222539813933e4dc345c (patch)
tree0de9f74f1dbde228db37cabb6ea0f8fbfb0b04d1
parent3716ae3ed7e4fc0a60c8733f7e6a15ba48f65b01 (diff)
V4L/DVB (12820): tm6000: fix i2c readings
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/staging/tm6000/tm6000-i2c.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
index c0327d724eb2..8569cfca8f82 100644
--- a/drivers/staging/tm6000/tm6000-i2c.c
+++ b/drivers/staging/tm6000/tm6000-i2c.c
@@ -94,7 +94,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
94{ 94{
95 struct tm6000_core *dev = i2c_adap->algo_data; 95 struct tm6000_core *dev = i2c_adap->algo_data;
96 int addr, rc, i, byte; 96 int addr, rc, i, byte;
97 u8 prev_reg = 0; 97 int prev_reg = -1;
98 98
99 if (num <= 0) 99 if (num <= 0)
100 return 0; 100 return 0;
@@ -113,16 +113,38 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
113 out of message data. 113 out of message data.
114 */ 114 */
115 /* SMBus Read Byte command */ 115 /* SMBus Read Byte command */
116 if (prev_reg < 0)
117 printk("XXX read from unknown prev_reg\n");
116 rc = tm6000_read_write_usb (dev, 118 rc = tm6000_read_write_usb (dev,
117 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 119 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
118 REQ_16_SET_GET_I2CSEQ, 120 REQ_16_SET_GET_I2CSEQ,
119 addr | (prev_reg << 8), 0, 121 addr | (prev_reg << 8), 0,
120 msgs[i].buf, msgs[i].len); 122 msgs[i].buf, msgs[i].len);
123 if (prev_reg >= 0)
124 prev_reg += msgs[i].len;
121 if (i2c_debug>=2) { 125 if (i2c_debug>=2) {
122 for (byte = 0; byte < msgs[i].len; byte++) { 126 for (byte = 0; byte < msgs[i].len; byte++) {
123 printk(" %02x", msgs[i].buf[byte]); 127 printk(" %02x", msgs[i].buf[byte]);
124 } 128 }
125 } 129 }
130 } else if (i+1 < num && msgs[i].len == 2 &&
131 (msgs[i+1].flags & I2C_M_RD) &&
132 msgs[i].addr == msgs[i+1].addr) {
133 i2c_dprintk(2, "msg %d: write 2, read %d", i,
134 msgs[i+1].len);
135 /* Write 2 Read N command */
136 rc = tm6000_read_write_usb (dev,
137 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
138 REQ_14_SET_GET_EEPROM_PAGE, /* XXX wrong name */
139 addr | msgs[i].buf[0] << 8, msgs[i].buf[1],
140 msgs[i+1].buf, msgs[i+1].len);
141 i++;
142 if (i2c_debug>=2) {
143 for (byte = 0; byte < msgs[i].len; byte++) {
144 printk(" %02x", msgs[i].buf[byte]);
145 }
146 }
147 prev_reg = -1;
126 } else { 148 } else {
127 /* write bytes */ 149 /* write bytes */
128 if (i2c_debug>=2) { 150 if (i2c_debug>=2) {
@@ -134,6 +156,8 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
134 if(msgs[i].len == 1 && i+1 < num && msgs[i+1].flags & I2C_M_RD 156 if(msgs[i].len == 1 && i+1 < num && msgs[i+1].flags & I2C_M_RD
135 && msgs[i+1].addr == msgs[i].addr) { 157 && msgs[i+1].addr == msgs[i].addr) {
136 prev_reg = msgs[i].buf[0]; 158 prev_reg = msgs[i].buf[0];
159 if (i2c_debug >= 2)
160 printk("\n");
137 continue; 161 continue;
138 } 162 }
139 163
@@ -143,12 +167,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
143 addr|(*msgs[i].buf)<<8, 0, 167 addr|(*msgs[i].buf)<<8, 0,
144 msgs[i].buf+1, msgs[i].len-1); 168 msgs[i].buf+1, msgs[i].len-1);
145 169
146 if(msgs[i].len >= 1) { 170 prev_reg = -1;
147 prev_reg = msgs[i].buf[0];
148 }
149 else {
150 prev_reg = 0;
151 }
152 } 171 }
153 if (i2c_debug>=2) 172 if (i2c_debug>=2)
154 printk("\n"); 173 printk("\n");