diff options
Diffstat (limited to 'firmware/drivers/rtc.c')
-rw-r--r-- | firmware/drivers/rtc.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c new file mode 100644 index 0000000000..66b37fccb7 --- /dev/null +++ b/firmware/drivers/rtc.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #ifdef HAVE_RTC | ||
21 | #include "i2c.h" | ||
22 | #include "rtc.h" | ||
23 | |||
24 | #define RTC_ADR 0xd0 | ||
25 | #define RTC_DEV_WRITE (RTC_ADR | 0x00) | ||
26 | #define RTC_DEV_READ (RTC_ADR | 0x01) | ||
27 | |||
28 | int rtc_write(unsigned char address, unsigned char value) | ||
29 | { | ||
30 | int ret = 0; | ||
31 | unsigned char buf[2]; | ||
32 | |||
33 | i2c_begin(); | ||
34 | |||
35 | buf[0] = address; | ||
36 | buf[1] = value; | ||
37 | |||
38 | /* send run command */ | ||
39 | if (i2c_write(RTC_DEV_WRITE,buf,2)) | ||
40 | { | ||
41 | ret = -1; | ||
42 | } | ||
43 | |||
44 | i2c_end(); | ||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | |||
49 | int rtc_read(unsigned char address) | ||
50 | { | ||
51 | int value = -1; | ||
52 | unsigned char buf[1]; | ||
53 | |||
54 | i2c_begin(); | ||
55 | |||
56 | buf[0] = address; | ||
57 | |||
58 | /* send run command */ | ||
59 | if (i2c_write(RTC_DEV_READ,buf,1) >= 0) | ||
60 | { | ||
61 | i2c_start(); | ||
62 | i2c_outb(RTC_DEV_READ); | ||
63 | if (i2c_getack()) | ||
64 | { | ||
65 | value = i2c_inb(1); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | i2c_end(); | ||
70 | return value; | ||
71 | } | ||
72 | |||
73 | #endif | ||