RK3568 外接 PCF8563 RTC

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;
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值