Skip to main content

RTC

RTC设备驱动是一个标准的字符设备驱动。

1 rtc 驱动配置

以主配置 x1600e_halley6_nand_factory_defconfig 为例

2023-06-28_11-27

kernel的配置为:

2023-06-28_11-34

或者通过如下命令:

build$ grep -nr "kernel" configs/x1600e_halley6_nand_factory_defconfig 
6:APP_kernel_dir=../kernel/kernel-x2000
7:APP_kernel_config=x1600_halley6_module_base_linux_sfc_nand_defconfig

可知kernel的配置为: x1600_halley6_module_base_linux_sfc_nand_defconfig

可知当前的kernel 编译路径为:kernel/kernel-x2000

1.1 选中 kernel 相关配置

先使用主配置 x1600e_halley6_nand_factory_defconfig 整体编译以后,再执行如下操作。

执行如下命令,进入kernel的配置界面

kernel/kernel-x2000$ make menuconfig
Ingenic device-drivers Configurations → [RTC] drivers

<*> INGENIC RTC
[*] Ingenic RTC suspend test
(60) Ingenic RTC suspend alarm time Unit of second (NEW)
<*> INGENIC RTC V1

2023-04-19_16-03

保存配置退出,执行如下操作,让配置 x1600_halley6_module_base_linux_sfc_nand_defconfig生效。

kernel/kernel-x2000$ cp .config arch/mips/configs/x1600_halley6_module_base_linux_sfc_nand_defconfig -arf

1.2 kernel设备树相关配置

执行如下命令,进入kernel的配置界面

make menuconfig 进入配置菜单
kernel/kernel-x2000$ make menuconfig

2023-06-28_14-15

或者通过如下命令:

kernel/kernel-x2000$ grep -nr ".dts" arch/mips/configs/x1600_halley6_module_base_linux_sfc_nand_defconfig 
70:CONFIG_DT_X1600_MODULE_BASE_DTS_FILE="x1600_halley6_module_base.dts"

搜索 x1600_halley6_module_base.dts 文件路径。

kernel/kernel-x2000$ find ./ -name "x1600_halley6_module_base.dts"
./arch/mips/boot/dts/ingenic/x1600_halley6_module_base.dts

可知文件路径:kernel/kernel-x2000$ ls arch/mips/boot/dts/ingenic/x1600_halley6_module_base.dts

打开文件 x1600_halley6_module_base.dts

2023-06-28_14-52

可知用到的文件为:x1600.dtsi ,确定文件路径如下:

kernel/kernel-x2000$ find ./ -name "x1600.dtsi"
./arch/mips/boot/dts/ingenic/x1600.dtsi
[2]+ Done gedit arch/mips/boot/dts/ingenic/x1600_halley6_module_base.dts
rtc: rtc@0x10003000 {
compatible = "ingenic,rtc-x1600";
reg = <0x10003000 0x4c>;
interrupt-parent = <&core_intc>;
interrupts = <IRQ_RTC>;
system-power-controller;
power-on-press-ms = <1000>;
status = "ok";
};

2 rtc 测试

编译进入内核,进行休眠唤醒一段时间
echo mem > sys/power/state (休眠60秒后自动唤醒-(测试点为定时和计时准确以及唤醒功能))
# echo mem > /sys/power/state 
[ 22.955409] PM: Syncing filesystems ... done.
[ 22.960401] Freezing user space processes ... (elapsed 0.001 seconds) done.
[ 22.962327] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[ 22.963945] x1600 suspend begin
[ 22.964165] Suspending console(s) (use no_console_suspend to debug)
CDWXRD00000004
1t00000003
B2345[ 22.966490] -------suspend count = 0
[ 22.966563] PM: suspend of devices complete after 1.669 msecs
[ 22.966567] x1600 suspend prepare
[ 22.967191] PM: late suspend of devices complete after 0.606 msecs
[ 22.967681] PM: noirq suspend of devices complete after 0.470 msecs
[ 22.967687] REG |+++GPA++|+++GPB++|+++GPC++|+++GPD++|
[ 22.967687]
[ 22.967687] INL |0f9fd79d|d010073f|89540000|00000002|
[ 22.967687] INT |00000000|00000000|90000000|00000000|
[ 22.967687] MSK |cfffffff|c0027030|0b000007|0000003f|
[ 22.967687] PAT1 |ffffffff|0003f030|9b000007|0000003f|
[ 22.967687] PAT0 |00000000|dff80003|00000000|00000000|
[ 22.967687] EDG |00000000|00000000|90000000|00000000|
[ 22.967687] PULL |00000000|8000001f|077e0007|00000000|
[ 22.967687] FLAG |00000000|00000000|00000000|00000000|
[ 22.967687] PA00:Inpt,High PB00:Fun1,High PC00:Inpt,Low PD00:Inpt,Low
[ 22.967687] PA01:Inpt,Low PB01:Fun1,High PC01:Inpt,Low PD01:Inpt,High
[ 22.967687] PA02:Inpt,High PB02:Fun0,High PC02:Inpt,Low PD02:Inpt,Low
[ 22.967687] PA03:Inpt,High PB03:Fun0,High PC03:Fun0,Low PD03:Inpt,Low
[ 22.967687] PA04:Inpt,High PB04:Inpt,High PC04:Fun0,Low PD04:Inpt,Low
PB08:Fun0,High PC08:Fun0,Low PD08:Fun0,Low
[ 22.967687] PA09:Inpt,High PB09:Fun0,High PC09:Fun0,Low PD09:Fun0,Low
[ 22.967687] PA10:Inpt,High PB10:Fun0,High PC10:Fun0,Low PD10:Fun0,Low
[ 22.967687] PA11:Inpt,Low PB11:Fun0,Low PC11:Fun0,Low PD11:Fun0,Low
[ 22.967687] PA12:Inpt,High PB12:Inpt,Low PC12:Fun0,Low PD12:Fun0,Low
[ 22.967687] PA13:Inpt,Low PB13:Inpt,Low PC13:Fun0,Low PD13:Fun0,Low
[ 22.967687] PA14:Inpt,High PB14:Inpt,Low PC14:Fun0,Low PD14:Fun0,Low
[ 22.967687] PA15:Inpt,High PB15:Fun2,Low PC15:Fun0,Low PD15:Fun0,Low
[ 22.967687] PA16:Inpt,High PB16:Fun2,Low PC16:Fun0,Low PD16:Fun0,Low
[ 22.967687] PA17:Inpt,High PB17:Inpt,Low PC17:Fun0,Low PD17:Fun0,Low
[ 22.967687] PA18:Inpt,High PB18:Fun0,Low PC18:Fun0,High PD18:Fun0,Low
D21:Fun0,Low
[ 22.967687] PA22:Inpt,Low PB22:Fun1,Low PC22:Fun0,High PD22:Fun0,Low
[ 22.967687] PA23:Inpt,High PB23:Fun1,Low PC23:Fun0,Low PD23:Fun0,Low
[ 22.967687] PA24:Inpt,High PB24:Fun1,Low PC24:Inpt,High PD24:Fun0,Low
[ 22.967687] PA25:Inpt,High PB25:Fun1,Low PC25:Inpt,Low PD25:Fun0,Low
[ 22.967687] PA26:Inpt,High PB26:Fun1,Low PC26:Fun0,High PD26:Fun0,Low
[ 22.967687] PA27:Inpt,High PB27:Fun1,Low PC27:Inpt,High PD27:Fun0,Low
[ 22.967687] PA28:Fun2,Low PB28:Fun1,High PC28:IntR,Low PD28:Fun0,Low
[ 22.967687] PA29:Fun2,Low PB29:Fun0,Low PC29:Fun0,Low PD29:Fun0,Low
[ 22.967687] PA30:Inpt,Low PB30:Out1,High PC30:Fun0,Low PD30:Fun0,Low
[ 22.967687] PA31:Inpt,Low PB31:Out1,High PC31:IntR,High PD31:Fun0,Low
[ 22.967687] REG |+++GPA++|+++GPB++|+++GPC++|+++GPD++|
[ 22.967687]
[ 22.967687] INL |0f9fd79d|d010073f|89540000|00000002|
[ 22.967687] INT |00000000|00000000|90000000|00000000|
[ 22.967687] MSK |cfffffff|c0027030|0b000007|0000003f|
[ 22.967687] PAT1 |ffffffff|0003f030|9b000007|0000003f|
[ 22.967687] PAT0 |00000000|dff80003|00000000|00000000|
[ 22.967687] EDG |00000000|00000000|90000000|00000000|
[ 22.967687] PULL |00000000|8000001f|077e0007|00000000|
[ 22.967687] FLAG |00000000|00000000|00000000|00000000|
[ 22.967687] PA00:Inpt,High PB00:Fun1,High PC00:Inpt,Low PD00:Inpt,Low
[ 22.967687] PA01:Inpt,Low PB01:Fun1,High PC01:Inpt,Low PD01:Inpt,High
[ 22.967687] PA02:Inpt,High PB02:Fun0,High PC02:Inpt,Low PD02:Inpt,Low
[ 22.967687] PA03:Inpt,High PB03:Fun0,High PC03:Fun0,Low PD03:Inpt,Low
[ 22.967687] PA04:Inpt,High PB04:Inpt,High PC04:Fun0,Low PD04:Inpt,Low
PB08:Fun0,High PC08:Fun0,Low PD08:Fun0,Low
[ 22.967687] PA09:Inpt,High PB09:Fun0,High PC09:Fun0,Low PD09:Fun0,Low
[ 22.967687] PA10:Inpt,High PB10:Fun0,High PC10:Fun0,Low PD10:Fun0,Low
[ 22.967687] PA11:Inpt,Low PB11:Fun0,Low PC11:Fun0,Low PD11:Fun0,Low
[ 22.967687] PA12:Inpt,High PB12:Inpt,Low PC12:Fun0,Low PD12:Fun0,Low
[ 22.967687] PA13:Inpt,Low PB13:Inpt,Low PC13:Fun0,Low PD13:Fun0,Low
[ 22.967687] PA14:Inpt,High PB14:Inpt,Low PC14:Fun0,Low PD14:Fun0,Low
[ 22.967687] PA15:Inpt,High PB15:Fun2,Low PC15:Fun0,Low PD15:Fun0,Low
[ 22.967687] PA16:Inpt,High PB16:Fun2,Low PC16:Fun0,Low PD16:Fun0,Low
[ 22.967687] PA17:Inpt,High PB17:Inpt,Low PC17:Fun0,Low PD17:Fun0,Low
[ 22.967687] PA18:Inpt,High PB18:Fun0,Low PC18:Fun0,High PD18:Fun0,Low
D21:Fun0,Low
[ 22.967687] PA22:Inpt,Low PB22:Fun1,Low PC22:Fun0,High PD22:Fun0,Low
[ 22.967687] PA23:Inpt,High PB23:Fun1,Low PC23:Fun0,Low PD23:Fun0,Low
[ 22.967687] PA24:Inpt,High PB24:Fun1,Low PC24:Inpt,High PD24:Fun0,Low
[ 22.967687] PA25:Inpt,High PB25:Fun1,Low PC25:Inpt,Low PD25:Fun0,Low
[ 22.967687] PA26:Inpt,High PB26:Fun1,Low PC26:Fun0,Low PD26:Fun0,Low
[ 22.967687] PA27:Inpt,High PB27:Fun1,Low PC27:Inpt,High PD27:Fun0,Low
[ 22.967687] PA28:Fun2,Low PB28:Fun1,High PC28:IntR,Low PD28:Fun0,Low
[ 22.967687] PA29:Fun2,Low PB29:Fun0,Low PC29:Fun0,Low PD29:Fun0,Low
[ 22.967687] PA30:Inpt,Low PB30:Out1,High PC30:Fun0,Low PD30:Fun0,Low
[ 22.967687] PA31:Inpt,Low PB31:Out1,High PC31:IntR,High PD31:Fun0,Low
[ 22.967687] x1600 pm enter!!
[ 22.967687] sleep_param->state addr = 3
[ 22.967687] tcsm addr = b3422000 80014c30 size = 64
[ 22.967687] tcsm addr = b3422040 80014c74 size = 4096
[ 22.967687] tcsm addr = b3423040 80015140 size = 3072
[ 22.967687] pd core and l2c
[ 22.967687] LCR: 00001f01
[ 22.967687] OPCR: 4470152c
[ 22.967687] gate0 = 0x43dab7f7
[ 22.967687] gate1 = 0x33fffcdb
[ 22.967687] warning : bit[3] in clk gate0 is enabled
[ 22.967687] warning : bit[11] in clk gate0 is enabled
[ 22.967687] warning : bit[14] in clk gate0 is enabled
[ 22.967687] warning : bit[16] in clk gate0 is enabled
[ 22.967687] warning : bit[18] in clk gate0 is enabled
[ 22.967687] warning : bit[21] in clk gate0 is enabled
[ 22.967687] warning : bit[26] in clk gate0 is enabled
[ 22.967687] warning : bit[27] in clk gate0 is enabled
[ 22.967687] warning : bit[28] in clk gate0 is enabled
[ 22.967687] warning : bit[29] in clk gate0 is enabled
[ 22.967687] warning : bit[31] in clk gate0 is enabled
[ 22.967687] warning : bit[2] in clk gate1 is enabled
[ 22.967687] warning : bit[5] in clk gate1 is enabled
[ 22.967687] warning : bit[8] in clk gate1 is enabled
[ 22.967687] warning : bit[9] in clk gate1 is enabled
[ 22.967687] warning : bit[26] in clk gate1 is enabled
[ 22.967687] warning : bit[27] in clk gate1 is enabled
[ 22.967687] warning : bit[30] in clk gate1 is enabled
[ 22.967687] warning : bit[31] in clk gate1 is enabled
[ 22.967687] mem_pd0 = 0x3fb1007b
[ 22.967687] mem_pd1 = 0x30
[ 22.967687] intc0 mask = 0xffff7fef
[ 22.967687] intc1 mask = 0xfffffffe
[ 22.967687] post wakeup!
[ 22.967687] -----------------
[ 22.967687] WAKE UP by INTC1: bit[0] -> RTC
[ 22.967687] -----------------
[ 22.968208] PM: noirq resume of devices complete after 0.459 msecs
[ 22.969789] PM: early resume of devices complete after 0.374 msecs
[ 22.970339] x1600 suspend finishcreate CDT index: 0 ~ 22, index number:23.
[ 22.970943] PM: resume of devices complete after 1.131 msecs
[ 23.018159] x1600 pm end irq_num=40!
[ 23.018408] Restarting tasks ... done.
#