KVIM3 RTC not working on Linux 4.9 offline

Which system do you use?

Fenix build Linux Kernel 4.9 Ubuntu Focal

Please describe your issue below:

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:

(pcf8523) hwclock: ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument · Issue #1065 · raspberrypi/firmware · GitHub

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:~$ 


Hello @JamesK

Can you check with latest 5.15 kernel images?

Desktop - https://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/vim3-ubuntu-22.04-gnome-linux-5.15-fenix-1.6.3-240112-emmc.img.xz
Server - https://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/vim3-ubuntu-22.04-server-linux-5.15-fenix-1.6.3-240112-emmc.img.xz

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.

5.15 Kernel seems to be stuck in a boot loop. Shows Khadas logo, starts booting, then restarts.

Which image you used?Please make sure you use the official PD adaptor to supply the power.