提交 d40860f8 编写于 作者: T Trent Piepho 提交者: Mauro Carvalho Chehab

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: NTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: NMauro Carvalho Chehab <mchehab@infradead.org>
上级 634bc48d
...@@ -141,43 +141,43 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -141,43 +141,43 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
int i, j; int i, j;
int ret = 0; int ret = 0;
if (!num)
return -EINVAL;
if (mutex_lock_interruptible(&d->i2c_mutex) < 0) if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
return -EAGAIN; return -EAGAIN;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
if (msg[i].flags & I2C_M_RD) { if (msg[i].flags & (I2C_M_NO_RD_ACK|I2C_M_IGNORE_NAK|I2C_M_TEN)) {
ret = -ENOTSUPP;
if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr << 1) | 0x01, 0x80)) != 0) goto unlock;
}
/* Send START & address/RW bit */
if (!(msg[i].flags & I2C_M_NOSTART)) {
if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:00), 0x80)) != 0)
goto unlock; goto unlock;
/* Should check for ack here, if we knew how. */
for(j = 0; j < msg[i].len; j++) { }
if (j + 1 == msg[i].len && i + 1== num) { if (msg[i].flags & I2C_M_RD) {
if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, &msg[i].buf[j], msg[i].len)) != 0) for (j = 0; j < msg[i].len; j++) {
goto unlock; /* Last byte of transaction? Send STOP, otherwise send ACK. */
} else { int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x01;
if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x21, &msg[i].buf[j], msg[i].len)) != 0) if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x20|stop, &msg[i].buf[j], 1)) != 0)
goto unlock; goto unlock;
}
} }
} else { } else {
if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr << 1, 0x80)) != 0) for (j = 0; j < msg[i].len; j++) {
goto unlock; /* Last byte of transaction? Then send STOP. */
int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x00;
for(j = 0; j < msg[i].len; j++) { if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
if (j + 1 == msg[i].len && i + 1== num) { goto unlock;
if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x40)) != 0) /* Should check for ack here too. */
goto unlock;
} else {
if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x0)) != 0)
goto unlock;
}
} }
} }
} }
ret = num; ret = num;
unlock:
unlock:
mutex_unlock(&d->i2c_mutex); mutex_unlock(&d->i2c_mutex);
return ret; return ret;
......
...@@ -37,13 +37,27 @@ this sequence works: ...@@ -37,13 +37,27 @@ this sequence works:
(0x21 in byte)* (0x21 in byte)*
0x60 in byte 0x60 in byte
_my guess_: Guess at API of the I2C function:
0x80: begin i2c transfer using address. value=address<<1|(reading?1:0) I2C operation is done one byte at a time with USB control messages. The
0x00: write byte index the messages is sent to is made up of a set of flags that control
0x21: read byte, more to follow the I2C bus state:
0x40: write last byte of message sequence 0x80: Send START condition. After a START condition, one would normally
0x60: read last byte of message sequence always send the 7-bit slave I2C address as the 7 MSB, followed by
*/ the read/write bit as the LSB.
0x40: Send STOP condition. This should be set on the last byte of an
I2C transaction.
0x20: Read a byte from the slave. As opposed to writing a byte to the
slave. The slave will normally not produce any data unless you
set the R/W bit to 1 when sending the slave's address after the
START condition.
0x01: Respond with ACK, as opposed to a NACK. For a multi-byte read,
the master should send an ACK, that is pull SDA low during the 9th
clock cycle, after every byte but the last. This flags only makes
sense when bit 0x20 is set, indicating a read.
What any other bits might mean, or how to get the slave's ACK/NACK
response to a write, is unknown.
*/
struct m9206_state { struct m9206_state {
u16 filters[M9206_MAX_FILTERS]; u16 filters[M9206_MAX_FILTERS];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册