3 * Jason Cooper <u-boot@lakedaemon.net>
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,
25 * Date & Time support for Marvell Integrated RTC
33 /* This RTC does not support century, so we assume 20 */
36 int rtc_get(struct rtc_time *t)
40 struct mvrtc_registers *mvrtc_regs;
42 mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
44 /* read the time register */
45 time = readl(&mvrtc_regs->time);
47 /* read the date register */
48 date = readl(&mvrtc_regs->date);
50 /* test for 12 hour clock (can't tell if it's am/pm) */
51 if (time & MVRTC_HRFMT_MSK) {
52 printf("Error: RTC in 12 hour mode, can't determine AM/PM.\n");
57 t->tm_sec = bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK);
58 t->tm_min = bcd2bin((time >> MVRTC_MIN_SFT) & MVRTC_MIN_MSK);
59 t->tm_hour = bcd2bin((time >> MVRTC_HOUR_SFT) & MVRTC_HOUR_MSK);
60 t->tm_wday = bcd2bin((time >> MVRTC_DAY_SFT) & MVRTC_DAY_MSK);
64 t->tm_mday = bcd2bin((date >> MVRTC_DATE_SFT) & MVRTC_DATE_MSK);
65 t->tm_mon = bcd2bin((date >> MVRTC_MON_SFT) & MVRTC_MON_MSK);
66 t->tm_year = bcd2bin((date >> MVRTC_YEAR_SFT) & MVRTC_YEAR_MSK);
67 t->tm_year += CENTURY * 100;
69 /* not supported in this RTC */
76 int rtc_set(struct rtc_time *t)
78 u32 time = 0; /* sets hour format bit to zero, 24hr format. */
80 struct mvrtc_registers *mvrtc_regs;
82 mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
84 /* check that this code isn't 80+ years old ;-) */
85 if ((t->tm_year / 100) != CENTURY)
86 printf("Warning: Only century %d supported.\n", CENTURY);
89 time |= (bin2bcd(t->tm_sec) & MVRTC_SEC_MSK) << MVRTC_SEC_SFT;
90 time |= (bin2bcd(t->tm_min) & MVRTC_MIN_MSK) << MVRTC_MIN_SFT;
91 time |= (bin2bcd(t->tm_hour) & MVRTC_HOUR_MSK) << MVRTC_HOUR_SFT;
92 time |= (bin2bcd(t->tm_wday + 1) & MVRTC_DAY_MSK) << MVRTC_DAY_SFT;
95 date |= (bin2bcd(t->tm_mday) & MVRTC_DATE_MSK) << MVRTC_DATE_SFT;
96 date |= (bin2bcd(t->tm_mon) & MVRTC_MON_MSK) << MVRTC_MON_SFT;
97 date |= (bin2bcd(t->tm_year % 100) & MVRTC_YEAR_MSK) << MVRTC_YEAR_SFT;
99 /* write the time register */
100 writel(time, &mvrtc_regs->time);
102 /* write the date register */
103 writel(date, &mvrtc_regs->date);
112 struct mvrtc_registers *mvrtc_regs;
114 mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
116 /* no init routine for this RTC needed, just check that it's working */
117 time = readl(&mvrtc_regs->time);
118 sec = bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK);
120 time = readl(&mvrtc_regs->time);
122 if (sec == bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK))
123 printf("Error: RTC did not increment.\n");