3 * David Müller ELSOFT AG Switzerland. d.mueller@elsoft.ch
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 built-in Samsung S3C24X0 RTC
31 #if defined(CONFIG_RTC_S3C24X0) && (defined(CONFIG_CMD_DATE))
33 #if defined(CONFIG_S3C2400)
35 #elif defined(CONFIG_S3C2410)
49 static inline void SetRTC_Access(RTC_ACCESS a
)
51 S3C24X0_RTC
* const rtc
= S3C24X0_GetBase_RTC();
54 rtc
->RTCCON
|= 0x01; break;
57 rtc
->RTCCON
&= ~0x01; break;
61 static unsigned bcd2bin (uchar n
)
63 return ((((n
>> 4) & 0x0F) * 10) + (n
& 0x0F));
66 static unsigned char bin2bcd (unsigned int n
)
68 return (((n
/ 10) << 4) | (n
% 10));
71 /* ------------------------------------------------------------------------- */
73 int rtc_get (struct rtc_time
*tmp
)
75 S3C24X0_RTC
* const rtc
= S3C24X0_GetBase_RTC();
76 uchar sec
, min
, hour
, mday
, wday
, mon
, year
;
77 uchar a_sec
,a_min
, a_hour
, a_date
, a_mon
, a_year
, a_armed
;
79 /* enable access to RTC registers */
80 SetRTC_Access(RTC_ENABLE
);
82 /* read RTC registers */
91 } while (sec
!= rtc
->BCDSEC
);
93 /* read ALARM registers */
96 a_hour
= rtc
->ALMHOUR
;
97 a_date
= rtc
->ALMDATE
;
99 a_year
= rtc
->ALMYEAR
;
100 a_armed
= rtc
->RTCALM
;
102 /* disable access to RTC registers */
103 SetRTC_Access(RTC_DISABLE
);
106 printf ( "Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x "
107 "hr: %02x min: %02x sec: %02x\n",
108 year
, mon
, mday
, wday
,
110 printf ( "Alarms: %02x: year: %02x month: %02x date: %02x hour: %02x min: %02x sec: %02x\n",
112 a_year
, a_mon
, a_date
,
113 a_hour
, a_min
, a_sec
);
116 tmp
->tm_sec
= bcd2bin(sec
& 0x7F);
117 tmp
->tm_min
= bcd2bin(min
& 0x7F);
118 tmp
->tm_hour
= bcd2bin(hour
& 0x3F);
119 tmp
->tm_mday
= bcd2bin(mday
& 0x3F);
120 tmp
->tm_mon
= bcd2bin(mon
& 0x1F);
121 tmp
->tm_year
= bcd2bin(year
);
122 tmp
->tm_wday
= bcd2bin(wday
& 0x07);
130 printf ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
131 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
132 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
138 void rtc_set (struct rtc_time
*tmp
)
140 S3C24X0_RTC
* const rtc
= S3C24X0_GetBase_RTC();
141 uchar sec
, min
, hour
, mday
, wday
, mon
, year
;
144 printf ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
145 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
146 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
148 year
= bin2bcd(tmp
->tm_year
% 100);
149 mon
= bin2bcd(tmp
->tm_mon
);
150 wday
= bin2bcd(tmp
->tm_wday
);
151 mday
= bin2bcd(tmp
->tm_mday
);
152 hour
= bin2bcd(tmp
->tm_hour
);
153 min
= bin2bcd(tmp
->tm_min
);
154 sec
= bin2bcd(tmp
->tm_sec
);
156 /* enable access to RTC registers */
157 SetRTC_Access(RTC_ENABLE
);
159 /* write RTC registers */
168 /* disable access to RTC registers */
169 SetRTC_Access(RTC_DISABLE
);
172 void rtc_reset (void)
174 S3C24X0_RTC
* const rtc
= S3C24X0_GetBase_RTC();
176 rtc
->RTCCON
= (rtc
->RTCCON
& ~0x06) | 0x08;
177 rtc
->RTCCON
&= ~(0x08|0x01);