这就是为什么使用hwclock -w 后观察不到octeon_i2c_xfer()进入octeon_i2c_simple_read()的原因。
Hwclock -w 后:
here is pcf8563_get_datetime ,next func is i2c_transfer!
[ 1102.616179] octeon_i2c_xfer: num = 2
[ 1102.616188] octeon_i2c_xfer:msgs[0].addr = 51, msgs[0].flags = 0, msgs[0].len = 1
[ 1102.616200] octeon_i2c_xfer:msgs[0].buf[0] = 0
[ 1102.616211] octeon_i2c_xfer:msgs[1].addr = 51, msgs[1].flags = 1, msgs[1].len = 13
[ 1102.616223] octeon_i2c_xfer:msgs[1].buf[1] = 0
[ 1102.616233] octeon_i2c_write:data[0](msgs->buf[]) = 0, target(addr) = 51, length = 1, phase = 0
[ 1102.616360] octeon_i2c_write: data[0] = 0
[ 1102.616468] octeon_i2c_read:data[0](msgs->buf[0]) = 0,target(addr) = 51, length = 13,phase = 1
[ 1102.616697] octeon_i2c_read: data[0] = 8
[ 1102.616804] octeon_i2c_read: data[1] = 0
[ 1102.616911] octeon_i2c_read: data[2] = 28
[ 1102.617019] octeon_i2c_read: data[3] = 35
[ 1102.617127] octeon_i2c_read: data[4] = 14
[ 1102.617235] octeon_i2c_read: data[5] = 6
[ 1102.617342] octeon_i2c_read: data[6] = 2d
[ 1102.617450] octeon_i2c_read: data[7] = 27
[ 1102.617557] octeon_i2c_read: data[8] = 12
[ 1102.617665] octeon_i2c_read: data[9] = a0
[ 1102.617773] octeon_i2c_read: data[10] = 84
[ 1102.617881] octeon_i2c_read: data[11] = b2
[ 1102.617989] octeon_i2c_read: data[12] = b5
[ 1102.618003] here come back pcf8563_get_datetime ,the received data : secs=28, mins=35, hours=14,mday=6, mon=6, year=112,wday=5
由于num = 2,
进入octeon_i2c_xfer后 先要判断:
else if (num == 2) {
if ((msgs[0].flags & I2C_M_RD) == 0 &&
msgs[0].len > 0 && msgs[0].len <= 2 &&
msgs[1].len > 0 && msgs[1].len <= 8 &&
msgs[0].addr == msgs[1].addr) {
if (msgs[1].flags & I2C_M_RD)
ret = octeon_i2c_ia_read(i2c, msgs);
else
ret = octeon_i2c_ia_write(i2c, msgs);
goto out;
for (i = 0; ret == 0 && i < num; i++) {
pmsg = &msgs[i];
dev_dbg(i2c->dev,
"Doing %s %d byte(s) to/from 0x%02x - %d of %d messages\n",
pmsg->flags & I2C_M_RD ? "read" : "write",
pmsg->len, pmsg->addr, i + 1, num);
if (pmsg->flags & I2C_M_RD)
ret = octeon_i2c_read(i2c, pmsg->addr, pmsg->buf,
pmsg->len, i);
else
ret = octeon_i2c_write(i2c, pmsg->addr, pmsg->buf,
pmsg->len, i);
}
由于 msgs[1].len = 13,不满足条件,因此即使num=2,pcf8563_get_datetime永远不会进入octeon_i2c_ia_read/write ,不会进入内部地址的读写操作。
之后程序进入for循环,这样,经过判断,第一次要进入octeon_i2c_write()函数,第二次循环进入 octeon_i2c_read(),
在 Octeon_i2c_write()中:
static int octeon_i2c_write(struct octeon_i2c *i2c, int target,
const u8 *data, int length, int phase)
{
int i, result;
u8 tmp;
restart:
result = octeon_i2c_start(i2c);
if (result)
return result;
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, target << 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_TXADDR_ACK) && (tmp != STAT_TXDATA_ACK)) {
dev_err(i2c->dev,
"%s: bad status before write (0x%x)\n",
__func__, tmp);
return -EIO;
}
printk(KERN_DEBUG "%s: data[%d] = %x\n",__func__,i,data[i]);
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, data[i]);
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
result = octeon_i2c_wait(i2c);
if (result)
return result;
}
return 0;
}
其中:
octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, data[i]);
作用就是将data[i] 数据写进入octeon 的数据寄存器,即实现了写的操作。
