aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb/m920x.c
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2007-03-05 21:55:00 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-04-27 14:44:42 -0400
commitd40860f8e2edb31196f4233d3691704d313dbdd6 (patch)
tree033a5354d255a7090aadbf1c134a392aaf6409bc /drivers/media/dvb/dvb-usb/m920x.c
parent634bc48da766a9817e55e7dbd9909a6b26567e92 (diff)
V4L/DVB (5427): M920x: Improve I2C operations
Write some better documentation about what might be known about how the m920x I2C works, since a datasheet is lacking. The I2C xfer function should now handle more types of I2C transactions than it could before. Those it can't, will return error codes instead of being executed incorrectly. Multi-byte reads were not being done correctly, which should be fixed. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/dvb-usb/m920x.c')
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index 621819f6597a..08469ccabb72 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -141,43 +141,43 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
141 int i, j; 141 int i, j;
142 int ret = 0; 142 int ret = 0;
143 143
144 if (!num)
145 return -EINVAL;
146
144 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 147 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
145 return -EAGAIN; 148 return -EAGAIN;
146 149
147 for (i = 0; i < num; i++) { 150 for (i = 0; i < num; i++) {
148 if (msg[i].flags & I2C_M_RD) { 151 if (msg[i].flags & (I2C_M_NO_RD_ACK|I2C_M_IGNORE_NAK|I2C_M_TEN)) {
149 152 ret = -ENOTSUPP;
150 if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr << 1) | 0x01, 0x80)) != 0) 153 goto unlock;
154 }
155 /* Send START & address/RW bit */
156 if (!(msg[i].flags & I2C_M_NOSTART)) {
157 if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:00), 0x80)) != 0)
151 goto unlock; 158 goto unlock;
152 159 /* Should check for ack here, if we knew how. */
153 for(j = 0; j < msg[i].len; j++) { 160 }
154 if (j + 1 == msg[i].len && i + 1== num) { 161 if (msg[i].flags & I2C_M_RD) {
155 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, &msg[i].buf[j], msg[i].len)) != 0) 162 for (j = 0; j < msg[i].len; j++) {
156 goto unlock; 163 /* Last byte of transaction? Send STOP, otherwise send ACK. */
157 } else { 164 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x01;
158 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x21, &msg[i].buf[j], msg[i].len)) != 0) 165 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x20|stop, &msg[i].buf[j], 1)) != 0)
159 goto unlock; 166 goto unlock;
160 }
161 } 167 }
162
163 } else { 168 } else {
164 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr << 1, 0x80)) != 0) 169 for (j = 0; j < msg[i].len; j++) {
165 goto unlock; 170 /* Last byte of transaction? Then send STOP. */
166 171 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x00;
167 for(j = 0; j < msg[i].len; j++) { 172 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
168 if (j + 1 == msg[i].len && i + 1== num) { 173 goto unlock;
169 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x40)) != 0) 174 /* Should check for ack here too. */
170 goto unlock;
171
172 } else {
173 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x0)) != 0)
174 goto unlock;
175 }
176 } 175 }
177 } 176 }
178 } 177 }
179 ret = num; 178 ret = num;
180 unlock: 179
180unlock:
181 mutex_unlock(&d->i2c_mutex); 181 mutex_unlock(&d->i2c_mutex);
182 182
183 return ret; 183 return ret;