RTC

Introduction

The LKD3568 development board uses the HYM8563 as its RTC(RealTime Clock).The HYM8563 is a low-power CMOS real-time clock/calendar chip that provides a programmable clock output, an interrupt output, and a power-down detector. All addresses and data are serially transmitted through the I2C bus interface. The maximum bus speed is 400Kbits/s, and the embedded word address register automatically increments after each read/write operation.

  • Capable of timing seconds, minutes, hours, days of the week, days, months, and years based on a 32.768kHz crystal.

  • Wide operating voltage range: 1.0~5.5V.

  • Low sleep current: typical value is 0.25μA (VDD = 3.0V, TA = 25°C).

  • Integrated oscillation capacitor internally.

  • Open-drain interrupt pin.

RTC Driver

Reference for DTS configuration in Android SDK:  kernel/arch/arm64/boot/dts/rockchip/rk3568-evb.dtsi

&i2c5 {
    status = "okay";

    hym8563: hym8563@51 {
                compatible = "haoyu,hym8563";
                reg = <0x51>;
                status = "okay";
    };
};

Driver reference: kernel/drivers/rtc/rtc-hym8563.c

Interface Usage

Linux provides three user-space call interfaces. On the LKD3566 development board, the corresponding paths are:

  • SYSFS interface:/sys/class/rtc/rtc0/

  • PROCFS interface: /proc/driver/rtc

  • IOCTL interface: /dev/rtc0

SYSFS Interface

You can directly use  cat  and  echo  to operate the interfaces under  /sys/class/rtc/rtc0/ .

For example, to view the current RTC date and time:

# cat /sys/class/rtc/rtc0/date
2022-01-15
#cat /sys/class/rtc/rtc0/time
12:46:00

To set the boot time, such as setting to boot after 120 seconds:

#Set to boot after 120 seconds
echo +120 >  /sys/class/rtc/rtc0/wakealarm
# View boot time
cat /sys/class/rtc/rtc0/wakealarm
#Shutdown
reboot -p

PROCFS Interface

Print RTC-related information:

# cat /proc/driver/rtc
rtc_time    : 03:36:05
rtc_date    : 2022-01-05
alrm_time   : 12:46:00
alrm_date   : 2022-01-05
alarm_IRQ   : yes
alrm_pending    : no
update IRQ enabled  : no
periodic IRQ enabled    : no
periodic IRQ frequency  : 1
max user IRQ frequency  : 64
24hr        : yes

IOCTL Interface

You can use  ioctl  to control  /dev/rtc0

For detailed usage instructions, please refer to the document  rtc.txt .

FAQs

Q1: Why is the time not synchronized after powering on the development board?

A1: Check if the RTC battery is correctly connected.