3 * Gururaja Hebbar gururajakr@sanyo.co.in
5 * reference linux-2.6.20.6/drivers/rtc/rtc-pl031.c
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #if defined(CONFIG_CMD_DATE)
32 #ifndef CONFIG_SYS_RTC_PL031_BASE
33 #error CONFIG_SYS_RTC_PL031_BASE is not defined!
37 * Register definitions
39 #define RTC_DR 0x00 /* Data read register */
40 #define RTC_MR 0x04 /* Match register */
41 #define RTC_LR 0x08 /* Data load register */
42 #define RTC_CR 0x0c /* Control register */
43 #define RTC_IMSC 0x10 /* Interrupt mask and set register */
44 #define RTC_RIS 0x14 /* Raw interrupt status register */
45 #define RTC_MIS 0x18 /* Masked interrupt status register */
46 #define RTC_ICR 0x1c /* Interrupt clear register */
48 #define RTC_CR_START (1 << 0)
50 #define RTC_WRITE_REG(addr, val) \
51 (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr)) = (val))
52 #define RTC_READ_REG(addr) \
53 (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr)))
55 static int pl031_initted = 0;
57 /* Enable RTC Start in Control register*/
60 RTC_WRITE_REG(RTC_CR, RTC_CR_START);
66 * Reset the RTC. We set the date back to 1970-01-01.
70 RTC_WRITE_REG(RTC_LR, 0x00);
78 int rtc_set(struct rtc_time *tmp)
86 puts("Error setting the date/time\n");
90 /* Calculate number of seconds this incoming time represents */
91 tim = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
92 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
94 RTC_WRITE_REG(RTC_LR, tim);
100 * Get the current time from the RTC
102 int rtc_get(struct rtc_time *tmp)
110 puts("Error getting the date/time\n");
114 tim = RTC_READ_REG(RTC_DR);
118 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
119 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
120 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);