blob: de7898cc347db84016c39b72314fdca9a8180100 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD20b50802009-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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Jean-Christophe PLAGNIOL-VILLARD20b50802009-03-29 23:01:40 +02009 */
10
11/*
12 * S3C44B0 CPU specific code
13 */
14
15#include <common.h>
16#include <command.h>
17#include <asm/hardware.h>
18#include <rtc.h>
Jean-Christophe PLAGNIOL-VILLARD20b50802009-03-29 23:01:40 +020019
20int rtc_get (struct rtc_time* tm)
21{
22 RTCCON |= 1;
Albin Tonnerre8aca7202009-08-13 15:31:11 +020023 tm->tm_year = bcd2bin(BCDYEAR);
24 tm->tm_mon = bcd2bin(BCDMON);
25 tm->tm_wday = bcd2bin(BCDDATE);
26 tm->tm_mday = bcd2bin(BCDDAY);
27 tm->tm_hour = bcd2bin(BCDHOUR);
28 tm->tm_min = bcd2bin(BCDMIN);
29 tm->tm_sec = bcd2bin(BCDSEC);
Jean-Christophe PLAGNIOL-VILLARD20b50802009-03-29 23:01:40 +020030
31 if (tm->tm_sec==0) {
32 /* we have to re-read the rtc data because of the "one second deviation" problem */
33 /* see RTC datasheet for more info about it */
Albin Tonnerre8aca7202009-08-13 15:31:11 +020034 tm->tm_year = bcd2bin(BCDYEAR);
35 tm->tm_mon = bcd2bin(BCDMON);
36 tm->tm_mday = bcd2bin(BCDDAY);
37 tm->tm_wday = bcd2bin(BCDDATE);
38 tm->tm_hour = bcd2bin(BCDHOUR);
39 tm->tm_min = bcd2bin(BCDMIN);
40 tm->tm_sec = bcd2bin(BCDSEC);
Jean-Christophe PLAGNIOL-VILLARD20b50802009-03-29 23:01:40 +020041 }
42
43 RTCCON &= ~1;
44
45 if(tm->tm_year >= 70)
46 tm->tm_year += 1900;
47 else
48 tm->tm_year += 2000;
49
50 return 0;
51}
52
53int rtc_set (struct rtc_time* tm)
54{
55 if(tm->tm_year < 2000)
56 tm->tm_year -= 1900;
57 else
58 tm->tm_year -= 2000;
59
60 RTCCON |= 1;
Albin Tonnerre8aca7202009-08-13 15:31:11 +020061 BCDYEAR = bin2bcd(tm->tm_year);
62 BCDMON = bin2bcd(tm->tm_mon);
63 BCDDAY = bin2bcd(tm->tm_mday);
64 BCDDATE = bin2bcd(tm->tm_wday);
65 BCDHOUR = bin2bcd(tm->tm_hour);
66 BCDMIN = bin2bcd(tm->tm_min);
67 BCDSEC = bin2bcd(tm->tm_sec);
Jean-Christophe PLAGNIOL-VILLARD20b50802009-03-29 23:01:40 +020068 RTCCON &= 1;
69
70 return 0;
71}
72
73void rtc_reset (void)
74{
75 RTCCON |= 1;
76 BCDYEAR = 0;
77 BCDMON = 0;
78 BCDDAY = 0;
79 BCDDATE = 0;
80 BCDHOUR = 0;
81 BCDMIN = 0;
82 BCDSEC = 0;
83 RTCCON &= 1;
84}