2 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
3 * Andreas Heppel <aheppel@sysgo.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,
25 * Date & Time support for the MK48T59 RTC
36 #if defined(CONFIG_BAB7xx)
38 static uchar rtc_read (short reg)
40 out8(RTC_PORT_ADDR0, reg & 0xFF);
41 out8(RTC_PORT_ADDR1, (reg>>8) & 0xFF);
42 return in8(RTC_PORT_DATA);
45 static void rtc_write (short reg, uchar val)
47 out8(RTC_PORT_ADDR0, reg & 0xFF);
48 out8(RTC_PORT_ADDR1, (reg>>8) & 0xFF);
49 out8(RTC_PORT_DATA, val);
52 #elif defined(CONFIG_PCIPPC2)
54 #include "../board/pcippc2/pcippc2.h"
56 static uchar rtc_read (short reg)
61 static void rtc_write (short reg, uchar val)
66 #elif defined(CONFIG_EVAL5200)
68 static uchar rtc_read (short reg)
73 static void rtc_write (short reg, uchar val)
79 # error Board specific rtc access functions should be supplied
82 /* ------------------------------------------------------------------------- */
84 void *nvram_read(void *dest, const short src, size_t count)
86 uchar *d = (uchar *) dest;
95 void nvram_write(short dest, const void *src, size_t count)
98 uchar *s = (uchar *) src;
101 rtc_write(d++, *s++);
104 #if defined(CONFIG_CMD_DATE)
106 /* ------------------------------------------------------------------------- */
108 int rtc_get (struct rtc_time *tmp)
111 uchar sec, min, hour, mday, wday, mon, year;
113 /* Simple: freeze the clock, read it and allow updates again */
114 save_ctrl_a = rtc_read(RTC_CONTROLA);
116 /* Set the register to read the value. */
117 save_ctrl_a |= RTC_CA_READ;
118 rtc_write(RTC_CONTROLA, save_ctrl_a);
120 sec = rtc_read (RTC_SECONDS);
121 min = rtc_read (RTC_MINUTES);
122 hour = rtc_read (RTC_HOURS);
123 mday = rtc_read (RTC_DAY_OF_MONTH);
124 wday = rtc_read (RTC_DAY_OF_WEEK);
125 mon = rtc_read (RTC_MONTH);
126 year = rtc_read (RTC_YEAR);
128 /* re-enable update */
129 save_ctrl_a &= ~RTC_CA_READ;
130 rtc_write(RTC_CONTROLA, save_ctrl_a);
133 printf ( "Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x "
134 "hr: %02x min: %02x sec: %02x\n",
135 year, mon, mday, wday,
138 tmp->tm_sec = bcd2bin (sec & 0x7F);
139 tmp->tm_min = bcd2bin (min & 0x7F);
140 tmp->tm_hour = bcd2bin (hour & 0x3F);
141 tmp->tm_mday = bcd2bin (mday & 0x3F);
142 tmp->tm_mon = bcd2bin (mon & 0x1F);
143 tmp->tm_year = bcd2bin (year);
144 tmp->tm_wday = bcd2bin (wday & 0x07);
152 printf ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
153 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
154 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
160 int rtc_set (struct rtc_time *tmp)
165 printf ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
166 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
167 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
169 save_ctrl_a = rtc_read(RTC_CONTROLA);
171 save_ctrl_a |= RTC_CA_WRITE;
172 rtc_write(RTC_CONTROLA, save_ctrl_a); /* disables the RTC to update the regs */
174 rtc_write (RTC_YEAR, bin2bcd(tmp->tm_year % 100));
175 rtc_write (RTC_MONTH, bin2bcd(tmp->tm_mon));
177 rtc_write (RTC_DAY_OF_WEEK, bin2bcd(tmp->tm_wday));
178 rtc_write (RTC_DAY_OF_MONTH, bin2bcd(tmp->tm_mday));
179 rtc_write (RTC_HOURS, bin2bcd(tmp->tm_hour));
180 rtc_write (RTC_MINUTES, bin2bcd(tmp->tm_min ));
181 rtc_write (RTC_SECONDS, bin2bcd(tmp->tm_sec ));
183 save_ctrl_a &= ~RTC_CA_WRITE;
184 rtc_write(RTC_CONTROLA, save_ctrl_a); /* enables the RTC to update the regs */
189 void rtc_reset (void)
194 * Start oscillator here.
196 control_b = rtc_read(RTC_CONTROLB);
198 control_b &= ~RTC_CB_STOP;
199 rtc_write(RTC_CONTROLB, control_b);
202 void rtc_set_watchdog(short multi, short res)
206 wd_value = RTC_WDS | ((multi & 0x1F) << 2) | (res & 0x3);
207 rtc_write(RTC_WATCHDOG, wd_value);