RTC Driver

Block Diagram

The following image shows the block diagram of the RTC driver.
Figure 1. Block Diagram
Besides the general user space layer, the following layers are specific to the RTC module.
  • RTC subsystem: The RTC driver framework provided by the Linux kernel.
    • rtc-core: Provide API for RTC drivers to register the RTC devices and drivers.
    • interface: Provide interface to interact with the RTC devices (by calling ops functions). So ioctrl/proc/sysfs can either be used to set or read RTC time and alarm using API interface.
  • StarFive(AT8563) RTC driver: Define all underlying operations (read/write register) and register RTC devices to rtc-core.
  • StarFive RTC driver: Define all underlying operations (read/write register) and register RTC devices to rtc-core.

Device Tree Source Code

The following code block shows the content of the RTC device tree source code.
     rtc: rtc@17040000 {
            compatible = "starfive,rtc_hms";
            reg = <0x0 0x17040000 0x0 0x10000>;
            interrupts = <10>, <11>, <12>;
            interrupt-names = "rtc_ms_pulse", "rtc_sec_pulse", "rtc";
            clocks = <&clkgen JH7110_RTC_HMS_CLK_APB>,
                     <&clkgen JH7110_RTC_HMS_CLK_CAL>;
            clock-names = "pclk", "cal_clk";
            resets = <&rstgen RSTN_U0_RTC_HMS_APB>,
                     <&rstgen RSTN_U0_RTC_HMS_CAL>,
                     <&rstgen RSTN_U0_RTC_HMS_OSC32K>;
            reset-names = "rst_apb", "rst_cal", "rst_osc";
            rtc,cal-clock-freq = <1000000>;
            status = "okay";
        };
The following table describes the device tree parameters:
Table 1. RTC DT Parameters
Parameter Description
compatible Compatibility information, used to associate the driver and its target device
reg Register base address "0x17040000" and range "0x10000"
clocks The clocks used by the RTC module
clock-names The names of the clocks used by the RTC module
resets The reset signals used by the RTC module
reset-names The names of the reset signals
interrupts Hardware interrupt ID
interrupt-names Hardware interrupt names
cal-clock-freq The work frequency of the clock calibration
status

The work status of the RTC module. To enable the module, set this bit to okay. To disable the module, set this bit to disabled.

Source Code Structure

The RTC source code structure is listed as follows:
linux
├── drivers
│   ├── rtc
│   │   ├── rtc-core.h
│   │   ├── lib.c
│   │   ├── interface.c
│   │   ├── dev.c
│   │   ├── class.c
│   │   ├── proc.c
│   │   ├── sysfs.c
│   │   ├── rtc-starfive.c