static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
u8 *data, int length, int phase)
{
//added by handawei.2012.7.2
printk(KERN_DEBUG "%s:data[0](msgs->buf[0]) = %xtarget(addr) = %x, length = %d,phase = %d\n",
__func__,data[0],target,length,phase);
int i, result;
u8 tmp;
if (length < 1)
return -EINVAL;
restart:
result = octeon_i2c_start(i2c);
if (result)
return result;
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, (target<<1) | 1);
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
result = octeon_i2c_wait(i2c);
if (result)
return result;
for (i = 0; i < length; i++) {
tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
if (phase == 0 && octeon_i2c_lost_arb(tmp))
goto restart;
if ((tmp != STAT_RXDATA_ACK) && (tmp != STAT_RXADDR_ACK)) {
dev_err(i2c->dev,
"%s: bad status before read (0x%x)\n",
__func__, tmp);
return -EIO;
}
if (i+1 < length)
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
TWSI_CTL_ENAB | TWSI_CTL_AAK);
else
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
TWSI_CTL_ENAB);
result = octeon_i2c_wait(i2c);
if (result)
return result;
data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA);
printk(KERN_DEBUG "%s: data[%d] = %x\n",__func__,i,data[i]);
}
return 0;
}
data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA);
data[i] 就保存了cpu 读数据寄存器后的返回结果,即保存了读的操作。
