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.617773] octeon_i2c_read: data[10] = 84
[ 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
可以看到,len = 13,经过了13次循环后,通过读pcf8563的00-0c号寄存器,buf[]得到了填充。
而返回后Buf[] 的值赋给了 struct rtc_time *tm 的相应成员。
在pcf8563_get_datatime()中,完成了对struct rtc_time *tm 的填充,完成了读了操作。
static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
{
struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
unsigned char buf[13] = { PCF8563_REG_ST1 };
struct i2c_msg msgs[] = {
{ client->addr, 0, 1, buf }, /* setup read ptr */
{ client->addr, I2C_M_RD, 13, buf }, /* read status + date */
};
printk(KERN_DEBUG "here is %s ,next func is i2c_transfer!\n",__func__);
/* read registers */
if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
dev_err(&client->dev, "%s: read error\n", __func__);
return -EIO;
}
if (buf[PCF8563_REG_SC] & PCF8563_SC_LV)
dev_info(&client->dev,
"low voltage detected, date/time is not reliable.\n");
// the orginal data is dev_dbg . modified by handawei.2012.6.4
dev_dbg(&client->dev,
"%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
"mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
__func__,
buf[0], buf[1], buf[2], buf[3],
buf[4], buf[5], buf[6], buf[7],
buf[8]);
tm->tm_sec = bcd2bin(buf[PCF8563_REG_SC] & 0x7F);
tm->tm_min = bcd2bin(buf[PCF8563_REG_MN] & 0x7F);
tm->tm_hour = bcd2bin(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */
tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F);
tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ /* -1 :tm_mon: [0-11] */
tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]);
if (tm->tm_year < 70)
tm->tm_year += 100; /* assume we are in 1970...2069 */
pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
(tm->tm_year >= 100) : (tm->tm_year < 100);
/* detect the polarity heuristically. see note above. */
if (rtc_valid_tm(tm) < 0)
dev_err(&client->dev, "retrieved date/time is not valid.\n");
return 0;
}
