FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / drivers / rtc / rtc_s3c2440.c
blobd39b50a2ca5487ebebe77840d4858198a782c633
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include "i2c.h"
23 #include "rtc.h"
24 #include "kernel.h"
25 #include "system.h"
27 void rtc_init(void)
29 /* RTC Enable */
30 RTCCON |= 1;
33 int rtc_read_datetime(unsigned char* buf)
35 buf[0] = BCDSEC;
36 buf[1] = BCDMIN;
37 buf[2] = BCDHOUR;
38 buf[3] = BCDDAY-1; /* timefuncs wants 0..6 for wday */
39 buf[4] = BCDDATE;
40 buf[5] = BCDMON;
41 buf[6] = BCDYEAR;
43 return 1;
46 int rtc_write_datetime(unsigned char* buf)
48 BCDSEC = buf[0];
49 BCDMIN = buf[1];
50 BCDHOUR = buf[2];
51 BCDDAY = buf[3]+1; /* chip wants 1..7 for wday */
52 BCDDATE = buf[4];
53 BCDMON = buf[5];
54 BCDYEAR = buf[6];
56 return 1;
59 #ifdef HAVE_RTC_ALARM
60 /* This alarm code works with a flashed bootloader. This will not work with
61 * the OF bootloader.
64 /* Check whether the unit has been started by the RTC alarm function */
65 bool rtc_check_alarm_started(bool release_alarm)
67 if (GSTATUS3)
69 GSTATUS3 &= ~release_alarm;
70 return true;
72 else
74 return false;
78 /* Check to see if the alarm has flaged since the last it was checked */
79 bool rtc_check_alarm_flag(void)
81 bool ret=SRCPND & 0x40000000;
83 SRCPND=RTC_MASK;
85 return ret;
88 /* set alarm time registers to the given time (repeat once per day) */
89 void rtc_set_alarm(int h, int m)
91 ALMMIN=(((m / 10) << 4) | (m % 10)) & 0x7f; /* minutes */
92 ALMHOUR=(((h / 10) << 4) | (h % 10)) & 0x3f; /* hour */
95 /* read out the current alarm time */
96 void rtc_get_alarm(int *h, int *m)
98 *m=((ALMMIN & 0x70) >> 4) * 10 + (ALMMIN & 0x0f);
99 *h=((ALMHOUR & 0x30) >> 4) * 10 + (ALMHOUR & 0x0f);
102 /* turn alarm on or off by setting the alarm flag enable
103 * returns false if alarm was set and alarm flag (output) is off
105 bool rtc_enable_alarm(bool enable)
107 if (enable)
109 RTCALM=0x46;
111 else
113 RTCALM=0x00;
116 return false; /* all ok */
118 #endif