2 * (C) Copyright 2011 DENX Software Engineering GmbH
3 * Heiko Schocher <hs@denx.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/arch/hardware.h>
29 #if defined(CONFIG_CMD_DATE)
35 u_int32_t month; /* 0x10 */
39 u_int32_t alarmsecond; /* 0x20 */
40 u_int32_t alarmminute;
43 u_int32_t alarmmonth; /* 0x30 */
46 u_int32_t ctrl; /* 0x40 */
51 #define RTC_STATE_BUSY 0x01
52 #define RTC_STATE_RUN 0x02
54 #define davinci_rtc_base ((struct davinci_rtc *)DAVINCI_RTC_BASE)
56 int rtc_get(struct rtc_time *tmp)
58 struct davinci_rtc *rtc = davinci_rtc_base;
59 unsigned long sec, min, hour, mday, wday, mon_cent, year;
62 status = readl(&rtc->status);
63 if ((status & RTC_STATE_RUN) != RTC_STATE_RUN) {
64 printf("RTC doesn't run\n");
67 if ((status & RTC_STATE_BUSY) == RTC_STATE_BUSY)
70 sec = readl(&rtc->second);
71 min = readl(&rtc->minutes);
72 hour = readl(&rtc->hours);
73 mday = readl(&rtc->day);
74 wday = readl(&rtc->dotw);
75 mon_cent = readl(&rtc->month);
76 year = readl(&rtc->year);
78 debug("Get RTC year: %02lx mon/cent: %02lx mday: %02lx wday: %02lx "
79 "hr: %02lx min: %02lx sec: %02lx\n",
80 year, mon_cent, mday, wday,
83 tmp->tm_sec = bcd2bin(sec & 0x7F);
84 tmp->tm_min = bcd2bin(min & 0x7F);
85 tmp->tm_hour = bcd2bin(hour & 0x3F);
86 tmp->tm_mday = bcd2bin(mday & 0x3F);
87 tmp->tm_mon = bcd2bin(mon_cent & 0x1F);
88 tmp->tm_year = bcd2bin(year) + 2000;
89 tmp->tm_wday = bcd2bin(wday & 0x07);
93 debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
94 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
95 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
100 int rtc_set(struct rtc_time *tmp)
102 struct davinci_rtc *rtc = davinci_rtc_base;
104 debug("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
105 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
106 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
107 writel(bin2bcd(tmp->tm_year % 100), &rtc->year);
108 writel(bin2bcd(tmp->tm_mon), &rtc->month);
110 writel(bin2bcd(tmp->tm_wday), &rtc->dotw);
111 writel(bin2bcd(tmp->tm_mday), &rtc->day);
112 writel(bin2bcd(tmp->tm_hour), &rtc->hours);
113 writel(bin2bcd(tmp->tm_min), &rtc->minutes);
114 writel(bin2bcd(tmp->tm_sec), &rtc->second);
120 struct davinci_rtc *rtc = davinci_rtc_base;
122 /* run RTC counter */
123 writel(0x01, &rtc->ctrl);