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.

1 Like

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?

So I fixed the power supply issue, but it looks like the HYM8563 rtc driver is never loaded? I only see two virtual rtc devices:

$ ls /dev | grep rtc
rtc
rtc0

Was this support lost in 5.15 somehow?

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:

sudo apt update
sudo apt full-upgrade -y
sync
sudo reboot

After reboot & check RTC:

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

Did not work. Maybe I will have to rebuild with fenix? Or change the config myself?

$ sudo apt update
Hit:1 http://ports.ubuntu.com noble InRelease
Hit:2 http://ports.ubuntu.com noble-security InRelease
Hit:3 http://ports.ubuntu.com noble-updates InRelease
Hit:4 http://ports.ubuntu.com noble-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

$ sudo apt full-upgrade -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  libcjson1 libavdevice60 libpostproc57 libavcodec60 libavutil58 libswscale7
  libswresample4 libavformat60 libavfilter9
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ sync
$ sudo reboot 0

When I check if rtc exists:

$ sudo dmesg | grep hym
$ ls /dev | grep rtc
rtc
rtc0

And hwclock still reads from fake rtc at rtc0.

What’s your current system? The link above is Ubuntu 22.04, but why the log you provided is 24.04?