3 * Gururaja Hebbar gururajakr@sanyo.co.in
5 * reference linux-2.6.20.6/drivers/rtc/rtc-pl031.c
7 * SPDX-License-Identifier: GPL-2.0+
14 #if defined(CONFIG_CMD_DATE)
16 #ifndef CONFIG_SYS_RTC_PL031_BASE
17 #error CONFIG_SYS_RTC_PL031_BASE is not defined!
21 * Register definitions
23 #define RTC_DR 0x00 /* Data read register */
24 #define RTC_MR 0x04 /* Match register */
25 #define RTC_LR 0x08 /* Data load register */
26 #define RTC_CR 0x0c /* Control register */
27 #define RTC_IMSC 0x10 /* Interrupt mask and set register */
28 #define RTC_RIS 0x14 /* Raw interrupt status register */
29 #define RTC_MIS 0x18 /* Masked interrupt status register */
30 #define RTC_ICR 0x1c /* Interrupt clear register */
32 #define RTC_CR_START (1 << 0)
34 #define RTC_WRITE_REG(addr, val) \
35 (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr)) = (val))
36 #define RTC_READ_REG(addr) \
37 (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr)))
39 static int pl031_initted = 0;
41 /* Enable RTC Start in Control register*/
44 RTC_WRITE_REG(RTC_CR, RTC_CR_START);
50 * Reset the RTC. We set the date back to 1970-01-01.
54 RTC_WRITE_REG(RTC_LR, 0x00);
62 int rtc_set(struct rtc_time *tmp)
70 puts("Error setting the date/time\n");
74 /* Calculate number of seconds this incoming time represents */
75 tim = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
76 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
78 RTC_WRITE_REG(RTC_LR, tim);
84 * Get the current time from the RTC
86 int rtc_get(struct rtc_time *tmp)
94 puts("Error getting the date/time\n");
98 tim = RTC_READ_REG(RTC_DR);
102 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
103 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
104 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);