RTC hym8563 seems to not work with linux kernel 4.9 ubuntu while the VIM3 is offline. After several days and reboots, the clock fails to read and the system time gets more and more behind. I believe this may be a similar hardware and firmware issue related to this raspberry pi issue because the same IOCTL error is present:
I would appreciate any additional troubleshooting steps that I could perform, as it looks like I am unable to read the raw data from the chip using i2cget.
Post a console log of your issue below:
Khadas:~$ sudo dmesg | grep rtc
[ 1.077052] rtc-hym8563 4-0051: rtc core: registered hym8563 as rtc0
[ 1.435882] aml_vrtc rtc: rtc core: registered aml_vrtc as rtc1
[ 2.039698] rtc-hym8563 4-0051: hctosys: unable to read the hardware clock
Khadas:~$ sudo hwclock -rv
hwclock from util-linux 2.34
System Time: 1718036866.593629
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
ioctl(4, RTC_UIE_ON, 0): Invalid argument
Waiting in loop for time from /dev/rtc0 to change
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument
...synchronization failed
Khadas:~$ i2cdetect -l 4
i2c-3 i2c Meson I2C adapter I2C adapter
i2c-4 i2c Meson I2C adapter I2C adapter
Khadas:~$ i2cdetect -y 4
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- UU --
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
20: UU -- 22 -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Khadas:~$ sudo i2cget -y 4 0x51
Error: Could not set address to 0x51: Device or resource busy
Khadas:~$ date
Mon 10 Jun 2024 12:46:34 PM EDT
Khadas:~$
Hmm. Looking at the driver code for the rtc-hym8563.c module in the Linux Kernel v5.15, there would still be a case where the VL flag could be set, even if the time is correct, or even just 1 ms off.
if (buf[0] & HYM8563_SEC_VL) {
dev_warn(&client->dev,
"no valid clock/calendar values available\n");
return -EINVAL;
}
I will try rebuilding it with the below changes to see if there is a difference:
//if (buf[0] & HYM8563_SEC_VL) {
if (buf[0] & 0) {
dev_warn(&client->dev,
"no valid clock/calendar values available\n");
return -EINVAL;
}
As mentioned before, I believe the RTC should have a 10uF capacitor instead of 10nF to prevent a VL condition when switching to the battery power. I believe that there is sometimes a voltage glitch during this time, which sometimes causes the VL flag to be set, even if the time is off by 1 ms. If I’m correct, when the function returns the error -EINVAL, the time is not read by the RTC at all. I would rather read from the RTC as long as the time is greater that the system time.
Thank you! It was a power supply problem. Interesting that 4.9 didn’t have this issue. Maybe 5.15 consumes more power? Is that related to the added GPU drivers?
Yes, it seems that we missed the HW RTC configuration in previous version, could you upgrade to latest version and check again? Based on your current system and follow the commands below to upgrade your system:
khadas@Khadas:~$ dmesg | grep hym
[ 2.538111] rtc-hym8563 6-0051: registered as rtc0
[ 2.539256] rtc-hym8563 6-0051: setting system clock to 2024-06-20T01:18:22 UTC (1718846302)
khadas@Khadas:~$
khadas@Khadas:~$
khadas@Khadas:~$
khadas@Khadas:~$ sudo hwclock -rv
hwclock from util-linux 2.39.3
System Time: 1718846585.070798
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1718845632 seconds after 1969
Last calibration done at 1718845632 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
ioctl(4, RTC_UIE_ON, 0): Invalid argument
Waiting in loop for time from /dev/rtc0 to change
...got clock tick
Time read from Hardware Clock: 2024/06/20 01:23:06
Hw clock time : 2024/06/20 01:23:06 = 1718846586 seconds since 1969
Time since last adjustment is 954 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2024-06-20 01:23:05.795477+00:00
khadas@Khadas:~$
Rebuilt from scratch again with a fresh repo pull. The hym8563 module is now loaded on the 5.15 kernel. There was a note during the build that some firmware may be missing though…
After setting the system time with: sudo date -s "24 JUN 2024 16:30:00"
Then pushing to hardware clock with: sudo hwclock -systohc
The RTC works great for a few days. Then after awhile, it resets to a date that it was last powered on. There is no network available for this application, so NTP is not an option. Are there any known issues with the RTC other than was was solved above?