Update bulgarian.lang by Zahari Yurukov
[maemo-rb.git] / firmware / drivers / rtc / rtc_imx233.c
blob9ed8540b5d56679ff11fd38df16659aafd0d3591
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by Amaury Pouly
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 ****************************************************************************/
22 #include "config.h"
23 #include "time.h"
24 #include "system.h"
25 #include "rtc.h"
26 #include "timefuncs.h"
27 #include "rtc-imx233.h"
29 #define YEAR1980 315532800 /* 1980/1/1 00:00:00 in UTC */
31 void rtc_init(void)
33 /* rtc-imx233 is initialized by the system */
36 int rtc_read_datetime(struct tm *tm)
38 uint32_t seconds = imx233_rtc_read_seconds();
39 #if defined(SANSA_FUZEPLUS) || defined(CREATIVE_ZENXFI3)
40 /* The OF uses PERSISTENT2 register to keep the adjustment and only changes
41 * SECONDS if necessary. */
42 seconds += imx233_rtc_read_persistent(2);
43 #else
44 /* The Freescale recommended way of keeping time is the number of seconds
45 * since 00:00 1/1/1980 */
46 seconds += YEAR1980;
47 #endif
49 gmtime_r(&seconds, tm);
51 return 0;
54 int rtc_write_datetime(const struct tm *tm)
56 uint32_t seconds;
58 seconds = mktime((struct tm *)tm);
60 #if defined(SANSA_FUZEPLUS) || defined(CREATIVE_ZENXFI3)
61 /* The OF uses PERSISTENT2 register to keep the adjustment and only changes
62 * SECONDS if necessary.
63 * NOTE: the OF uses this mechanism to prevent roll back in time. Although
64 * Rockbox will handle a negative PERSISTENT2 value, the OF will detect
65 * it and won't return in time before SECONDS */
66 imx233_rtc_write_persistent(2, seconds - imx233_rtc_read_seconds());
67 #else
68 /* The Freescale recommended way of keeping time is the number of seconds
69 * since 00:00 1/1/1980 */
70 imx233_rtc_write_seconds(seconds - YEAR1980);
71 #endif
73 return 0;
76 void rtc_set_alarm(int h, int m)
78 (void) h;
79 (void) m;
82 void rtc_get_alarm(int *h, int *m)
84 (void) h;
85 (void) m;
88 void rtc_enable_alarm(bool enable)
90 (void) enable;
93 bool rtc_check_alarm_started(bool release_alarm)
95 (void) release_alarm;
96 return false;
99 bool rtc_check_alarm_flag(void)
101 return false;