blob: d087d8adbd43032896204a4b0485d575c1a7203d [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>
Jean-Christophe PLAGNIOL-VILLARD5fe13772009-03-29 23:01:40 +020035
36int rtc_get (struct rtc_time* tm)
37{
38 RTCCON |= 1;
Albin Tonnerree84aba12009-08-13 15:31:11 +020039 tm->tm_year = bcd2bin(BCDYEAR);
40 tm->tm_mon = bcd2bin(BCDMON);
41 tm->tm_wday = bcd2bin(BCDDATE);
42 tm->tm_mday = bcd2bin(BCDDAY);
43 tm->tm_hour = bcd2bin(BCDHOUR);
44 tm->tm_min = bcd2bin(BCDMIN);
45 tm->tm_sec = bcd2bin(BCDSEC);
Jean-Christophe PLAGNIOL-VILLARD5fe13772009-03-29 23:01:40 +020046
47 if (tm->tm_sec==0) {
48 /* we have to re-read the rtc data because of the "one second deviation" problem */
49 /* see RTC datasheet for more info about it */
Albin Tonnerree84aba12009-08-13 15:31:11 +020050 tm->tm_year = bcd2bin(BCDYEAR);
51 tm->tm_mon = bcd2bin(BCDMON);
52 tm->tm_mday = bcd2bin(BCDDAY);
53 tm->tm_wday = bcd2bin(BCDDATE);
54 tm->tm_hour = bcd2bin(BCDHOUR);
55 tm->tm_min = bcd2bin(BCDMIN);
56 tm->tm_sec = bcd2bin(BCDSEC);
Jean-Christophe PLAGNIOL-VILLARD5fe13772009-03-29 23:01:40 +020057 }
58
59 RTCCON &= ~1;
60
61 if(tm->tm_year >= 70)
62 tm->tm_year += 1900;
63 else
64 tm->tm_year += 2000;
65
66 return 0;
67}
68
69int rtc_set (struct rtc_time* tm)
70{
71 if(tm->tm_year < 2000)
72 tm->tm_year -= 1900;
73 else
74 tm->tm_year -= 2000;
75
76 RTCCON |= 1;
Albin Tonnerree84aba12009-08-13 15:31:11 +020077 BCDYEAR = bin2bcd(tm->tm_year);
78 BCDMON = bin2bcd(tm->tm_mon);
79 BCDDAY = bin2bcd(tm->tm_mday);
80 BCDDATE = bin2bcd(tm->tm_wday);
81 BCDHOUR = bin2bcd(tm->tm_hour);
82 BCDMIN = bin2bcd(tm->tm_min);
83 BCDSEC = bin2bcd(tm->tm_sec);
Jean-Christophe PLAGNIOL-VILLARD5fe13772009-03-29 23:01:40 +020084 RTCCON &= 1;
85
86 return 0;
87}
88
89void rtc_reset (void)
90{
91 RTCCON |= 1;
92 BCDYEAR = 0;
93 BCDMON = 0;
94 BCDDAY = 0;
95 BCDDATE = 0;
96 BCDHOUR = 0;
97 BCDMIN = 0;
98 BCDSEC = 0;
99 RTCCON &= 1;
100}