External RTC not working

Hi,

We have a customized board with NXP PCF8563 RTC. I have modified carrier board device tree to support the external RTC as follows:

aliases {
		rtc = &pcf8563;
		rtc1 = "/soc/aips-bus@02000000/snvs@020cc000/snvs-rtc-lp@34";
	};
.
.
.
.
&i2c3 {
	status = "okay";
.
.
	pcf8563: pcf8563@51 {
	compatible = "nxp,pcf8563";
	reg = <0x51>;
	};
};

The output of dmesg is as follows

[ 2.603421] snvs_rtc 20cc034.snvs-rtc-lp: can’t get snvs-rtc clock
[ 2.611534] check_alarm_past: alarm in the past
[ 2.618031] snvs_rtc 20cc034.snvs-rtc-lp: rtc core: registered 20cc034.snvs-1
[ 2.630058] i2c /dev entries driver

Thank you in advance for your assistance.

I found this link for NXP PCF8563 device tree bindings

Hi

Did you enable the driver for this in the kernel configuration, recompiled kernel and modules and deployed them?
Just adding the configuration data to the device tree by itself is not enough.

The dmesg snipplet you provide is created by the driver for the i.MX 6 internal RTC and has nothing to do with your PCF8563 device. The output of dmesg | grep -i rtc and dmesg | grep -i pcf might give further clues.

You could also first use the userspace I2C tools to confirm that the device is seen and can be accessed as an I2C device.

Max

Thanks Max for the input. I am still not able to read the clock.

Here is what I did. I enabled the driver in the Kernel Config file. Compiled all the modules, uImage and device tree files. I deployed the uImage and device tree.

The output of dmesg | grep -i rtc is as follows

sh-4.3# dmesg | grep -i rtc
[    2.603191] rtc-pcf8563 2-0051: chip found, driver version 0.4.3
[    2.611227] rtc-pcf8563 2-0051: pcf8563_get_datetime: read error
[    2.619195] rtc-pcf8563 2-0051: rtc core: registered rtc-pcf8563 as rtc0
[    2.627914] snvs_rtc 20cc034.snvs-rtc-lp: can't get snvs-rtc clock
[    2.642587] snvs_rtc 20cc034.snvs-rtc-lp: rtc core: registered 20cc034.snvs-rtc-lp as rtc1
[    5.061141] rtc-pcf8563 2-0051: pcf8563_get_datetime: read error
[    5.068344] rtc-pcf8563 2-0051: hctosys: unable to read the hardware clock

The system now polls the RTC every second and I get this

[  449.253127] rtc-pcf8563 2-0051: pcf8563_set_datetime: err=-5 addr=02, data=11
[  449.260669] rtc-pcf8563 2-0051: pcf8563_get_datetime: read error
[  450.253180] rtc-pcf8563 2-0051: pcf8563_set_datetime: err=-5 addr=02, data=12
[  450.260733] rtc-pcf8563 2-0051: pcf8563_get_datetime: read error

The timedatectl query reports Failed to query server: Input/output error

One possibility is that everything is working but the RTC never got set to a valid time

 root@apalis_t30:~# hwclock -r
 hwclock: RTC_RD_TIME: Invalid argument
 root@apalis_t30:~# hwclock -w
 root@apalis_t30:~# hwclock -r
 Fri Aug 12 12:12:16 2016  0.000000 seconds

However the following points more into the direction of your I2C communication not working

 [  449.253127] rtc-pcf8563 2-0051: pcf8563_set_datetime: err=-5 addr=02, data=11
 [  449.260669] rtc-pcf8563 2-0051: pcf8563_get_datetime: read error

So what did your experiments with the I2C user space tools give?
e.g. when I probe for the RTC on our carrier boards, m41t00 at address 0x68 I see the device on the I2C bus and I can read register 0 (which contains the seconds) as follows:

root@colibri-imx6:~# i2cdetect 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         


root@colibri-imx6:~# i2cget -f 2 0x68 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x68, data address
0x00, using read byte data.
Continue? [Y/n] y
0x10

The hwclock -r gives an I/O error

Here are the results of Userspace I2C tools

sh-4.3# hwclock -r
hwclock: RTC_RD_TIME: Input/output error
sh-4.3# hwclock -w
hwclock: RTC_SET_TIME: Input/output error
sh-4.3# hwclock -r
hwclock: RTC_RD_TIME: Input/output error
sh-4.3# i2cdetect 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
sh-4.3# i2cget -f 2 0x51 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x51, data address
0x00, using read byte data.
Continue? [Y/n] y
Error: Read failed
sh-4.3# hwclock -r
hwclock: RTC_RD_TIME: Input/output error
sh-4.3# hwclock -w
hwclock: RTC_SET_TIME: Input/output error
sh-4.3# hwclock -r
hwclock: RTC_RD_TIME: Input/output error
sh-4.3# i2cdetect 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
sh-4.3# i2cget -f 2 0x51 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x51, data address
0x00, using read byte data.
Continue? [Y/n] y
Error: Read failed

I am still confused as to what would cause the device to have I/O errors

Some possibilites to check which come to mind:

  • Your RTC is not connected correctly
  • I2C does not have its pull up and/or the pull up resistors don’t have the right value. An oszilloscope on SCL/SDA while doing the i2cget -f 2 0x51 0 might shed light on this
  • Your RTC does not use 0x51 as its device address
  • The device tree does not setup the I2C bus correctly, e.g. pinmuxing is not done or not done on the pins you expect it to be
  • others?

Hey Marcel,

You are right. The RTC was not connected properly.

Thank you for helping me out. :slight_smile: