blob: 489536f3fb359d9d0ed67830da7caffe93c30139 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD5fe13772009-03-29 23:01:40 +02001/*
2 * (C) Copyright 2004
3 * DAVE Srl
4 * http://www.dave-tech.it
5 * http://www.wawnet.biz
6 * mailto:info@wawnet.biz
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27/*
28 * S3C44B0 CPU specific code
29 */
30
31#include <common.h>
32#include <command.h>
33#include <asm/hardware.h>
34#include <rtc.h>
35#include <bcd.h>
36
37int rtc_get (struct rtc_time* tm)
38{
39 RTCCON |= 1;
40 tm->tm_year = BCD2BIN(BCDYEAR);
41 tm->tm_mon = BCD2BIN(BCDMON);
42 tm->tm_wday = BCD2BIN(BCDDATE);
43 tm->tm_mday = BCD2BIN(BCDDAY);
44 tm->tm_hour = BCD2BIN(BCDHOUR);
45 tm->tm_min = BCD2BIN(BCDMIN);
46 tm->tm_sec = BCD2BIN(BCDSEC);
47
48 if (tm->tm_sec==0) {
49 /* we have to re-read the rtc data because of the "one second deviation" problem */
50 /* see RTC datasheet for more info about it */
51 tm->tm_year = BCD2BIN(BCDYEAR);
52 tm->tm_mon = BCD2BIN(BCDMON);
53 tm->tm_mday = BCD2BIN(BCDDAY);
54 tm->tm_wday = BCD2BIN(BCDDATE);
55 tm->tm_hour = BCD2BIN(BCDHOUR);
56 tm->tm_min = BCD2BIN(BCDMIN);
57 tm->tm_sec = BCD2BIN(BCDSEC);
58 }
59
60 RTCCON &= ~1;
61
62 if(tm->tm_year >= 70)
63 tm->tm_year += 1900;
64 else
65 tm->tm_year += 2000;
66
67 return 0;
68}
69
70int rtc_set (struct rtc_time* tm)
71{
72 if(tm->tm_year < 2000)
73 tm->tm_year -= 1900;
74 else
75 tm->tm_year -= 2000;
76
77 RTCCON |= 1;
78 BCDYEAR = BIN2BCD(tm->tm_year);
79 BCDMON = BIN2BCD(tm->tm_mon);
80 BCDDAY = BIN2BCD(tm->tm_mday);
81 BCDDATE = BIN2BCD(tm->tm_wday);
82 BCDHOUR = BIN2BCD(tm->tm_hour);
83 BCDMIN = BIN2BCD(tm->tm_min);
84 BCDSEC = BIN2BCD(tm->tm_sec);
85 RTCCON &= 1;
86
87 return 0;
88}
89
90void rtc_reset (void)
91{
92 RTCCON |= 1;
93 BCDYEAR = 0;
94 BCDMON = 0;
95 BCDDAY = 0;
96 BCDDATE = 0;
97 BCDHOUR = 0;
98 BCDMIN = 0;
99 BCDSEC = 0;
100 RTCCON &= 1;
101}
102