1 menuconfig
打开pcf8563驱动
在kernel的menuconfig中选中
>Device Drivers
>Real TIme Clock
>Philips PCF8563/Epson RTC8564
2 DTS
&i2c3 {
status = "okay";
+ pcf8563: pcf8563@51 {
+ status = "okay";
+ compatible = "nxp,pcf8563";
+ reg = <0x51>; // 读a3h, 写a2h: a3 >> 1 = 0x51
+ };
};
rk809: pmic@20 {
compatible = "rockchip,rk809";
reg = <0x20>;
...
pwrkey {
status = "okay";
};
+ rtc{
+ status = "disabled";
+ };
pinctrl_rk8xx: pinctrl_rk8xx {
...
};
...
};
3 修改驱动
rtc芯片的电压不低,但是总报错,先注释掉就可以使用了。报错原因以后再看一下寄存器相关文档。
rk3568/kernel/drivers/rtc/rtc-pcf8563.c
static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
{
struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
unsigned char buf[9];
int err;
err = pcf8563_read_block_data(client, PCF8563_REG_ST1, 9, buf);
if (err)
return err;
- /*if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
- pcf8563->voltage_low = 1;
- dev_err(&client->dev,
- "low voltage detected, date/time is not reliable.\n");
- return -EINVAL;
- }*/
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 */
tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]);
if (tm->tm_year < 70)
tm->tm_year += 100; /* assume we are in 1970...2069 */
/* detect the polarity heuristically. see note above. */
pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
(tm->tm_year >= 100) : (tm->tm_year < 100);
dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
"mday=%d, mon=%d, year=%d, wday=%d\n",
__func__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
return 0;
}