Update bulgarian.lang by Zahari Yurukov
[maemo-rb.git] / firmware / drivers / rtc / rtc_s3c2440.c
bloba8787e3f8f26f55889248830840632e66964cafb
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(struct tm *tm)
35 tm->tm_sec = BCD2DEC(BCDSEC);
36 tm->tm_min = BCD2DEC(BCDMIN);
37 tm->tm_hour = BCD2DEC(BCDHOUR);
38 tm->tm_wday = BCD2DEC(BCDDAY) - 1; /* timefuncs wants 0..6 for wday */
39 tm->tm_mday = BCD2DEC(BCDDATE);
40 tm->tm_mon = BCD2DEC(BCDMON) - 1;
41 tm->tm_year = BCD2DEC(BCDYEAR) + 100;
43 return 1;
46 int rtc_write_datetime(const struct tm *tm)
48 BCDSEC = DEC2BCD(tm->tm_sec);
49 BCDMIN = DEC2BCD(tm->tm_min);
50 BCDHOUR = DEC2BCD(tm->tm_hour);
51 BCDDAY = DEC2BCD(tm->tm_wday) + 1; /* chip wants 1..7 for wday */
52 BCDDATE = DEC2BCD(tm->tm_mday);
53 BCDMON = DEC2BCD(tm->tm_mon + 1);
54 BCDYEAR = DEC2BCD(tm->tm_year - 100);
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 = DEC2BCD(m); /* minutes */
92 ALMHOUR = DEC2BCD(h); /* hour */
95 /* read out the current alarm time */
96 void rtc_get_alarm(int *h, int *m)
98 *m = BCD2DEC(ALMMIN);
99 *h = BCD2DEC(ALMHOUR);
102 /* turn alarm on or off by setting the alarm flag enable
104 void rtc_enable_alarm(bool enable)
106 if (enable)
108 RTCALM=0x46;
110 else
112 RTCALM=0x00;
115 #endif