summaryrefslogtreecommitdiff
path: root/src/rhd_i2c.c
diff options
context:
space:
mode:
authorEgbert Eich <eich@freedesktop.org>2007-09-27 21:29:02 +0200
committerEgbert Eich <eich@freedesktop.org>2007-09-27 21:41:10 +0200
commit651e776d2cd9aaaef4782e6cf600cc35cc0c9cc7 (patch)
treebf778a0ae94776416e63c295ce1ede0042639ad0 /src/rhd_i2c.c
parentfe08f8e56f97697012e77ccf5f28ccb0adfcee19 (diff)
Fixed I2C probing on R5xx.
The R5xx I2CWriteRead() function didn't handle the case where neither write nor read data is available correctly. In this situation only the slave address should be written. R5xx appearantly cannot deal with a one byte slave address and zero data bytes. Therefore we write one dummy byte (i.e. an index value) after the address.
Diffstat (limited to 'src/rhd_i2c.c')
-rw-r--r--src/rhd_i2c.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/rhd_i2c.c b/src/rhd_i2c.c
index a6e779f..677740a 100644
--- a/src/rhd_i2c.c
+++ b/src/rhd_i2c.c
@@ -206,26 +206,36 @@ rhd5xxWriteReadChunk(I2CDevPtr i2cDevPtr, I2CByte *WriteBuffer,
(line & 0x0f) << 16 | R5_DC_I2C_EN,
R5_DC_I2C_PIN_SELECT | R5_DC_I2C_EN);
- if (nWrite) {
+ if (nWrite || !nRead) { /* special case for bus probing */
+ /*
+ * chip can't just write the slave address without data.
+ * Add a dummy byte.
+ */
RHDRegWrite(I2CPtr, R5_DC_I2C_CONTROL2,
- prescale << 16 | nWrite << 8 | 0x01); /* addr_cnt: 1 */
+ prescale << 16 |
+ (nWrite ? nWrite : 1) << 8 | 0x01); /* addr_cnt: 1 */
RHDRegMask(I2CPtr, R5_DC_I2C_CONTROL3,
0x30 << 24, 0xff << 24); /* time limit 30 */
-
+
RHDRegWrite(I2CPtr, R5_DC_I2C_DATA, slave);
-
- while (nWrite--)
- RHDRegWrite(I2CPtr, R5_DC_I2C_DATA, *WriteBuffer++);
-
+
+ /* Add dummy byte */
+ if (!nWrite)
+ RHDRegWrite(I2CPtr, R5_DC_I2C_DATA, 0);
+ else
+ while (nWrite--)
+ RHDRegWrite(I2CPtr, R5_DC_I2C_DATA, *WriteBuffer++);
+
RHDRegMask(I2CPtr, R5_DC_I2C_CONTROL1,
R5_DC_I2C_START | R5_DC_I2C_STOP, 0xff);
RHDRegMask(I2CPtr, R5_DC_I2C_STATUS1, R5_DC_I2C_GO, 0xff);
-
+
if ((ret = rhd5xxI2CStatus(I2CPtr)))
RHDRegMask(I2CPtr, R5_DC_I2C_STATUS1,R5_DC_I2C_DONE, 0xff);
else
ret = FALSE;
}
+
if (ret && nRead) {
RHDRegWrite(I2CPtr, R5_DC_I2C_DATA, slave | 1); /*slave*/