summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2009-06-28 09:58:05 +0000
committerBertrik Sikken <bertrik@sikken.nl>2009-06-28 09:58:05 +0000
commitce5dc3ab965740e3e71e35ff96a7e7b7fbe8fde1 (patch)
tree04038b9f28303decefc6ad1eb0312a037e03d295
parent79642ea634c34e599fe21935ea0817059d2c488a (diff)
downloadrockbox-ce5dc3ab965740e3e71e35ff96a7e7b7fbe8fde1.tar.gz
rockbox-ce5dc3ab965740e3e71e35ff96a7e7b7fbe8fde1.zip
Add RTC driver for Seiko S35390A (used in the Meizu M3 and possibly other Meizus)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21539 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/drivers/rtc/rtc_s35390a.c93
-rw-r--r--firmware/export/config-meizu-m3.h4
3 files changed, 97 insertions, 2 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index fb192cd7ae..5365d70040 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -177,6 +177,8 @@ drivers/rtc/rtc_mc13783.c
177drivers/rtc/rtc_tcc77x.c 177drivers/rtc/rtc_tcc77x.c
178#elif (CONFIG_RTC == RTC_JZ47XX) 178#elif (CONFIG_RTC == RTC_JZ47XX)
179drivers/rtc/rtc_jz4740.c 179drivers/rtc/rtc_jz4740.c
180#elif (CONFIG_RTC == RTC_S35390A)
181drivers/rtc/rtc_s35390a.c
180#endif /* (CONFIG_RTC == RTC_) */ 182#endif /* (CONFIG_RTC == RTC_) */
181#endif /* SIMULATOR */ 183#endif /* SIMULATOR */
182 184
diff --git a/firmware/drivers/rtc/rtc_s35390a.c b/firmware/drivers/rtc/rtc_s35390a.c
new file mode 100644
index 0000000000..5e0c90926c
--- /dev/null
+++ b/firmware/drivers/rtc/rtc_s35390a.c
@@ -0,0 +1,93 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Bertrik Sikken
11 * Copyright (C) 2008 by Robert Kukla
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "config.h"
23#include "rtc.h"
24#include "i2c-s5l8700.h"
25
26/* Driver for the Seiko S35390A real-time clock chip with i2c interface
27
28 This driver was derived from rtc_mr100.c and adapted for the S35390A
29 used in the Meizu M3 (and possibly others).
30 */
31
32#define RTC_ADDR 0x60
33
34#define STATUS_REG1 0
35#define STATUS_REG2 1
36#define REALTIME_DATA1 2
37#define REALTIME_DATA2 3
38#define INT1_REG 4
39#define INT2_REG 5
40#define CLOCK_CORR_REG 6
41#define FREE_REG 7
42
43
44static void reverse_bits(unsigned char* v, int size)
45{
46 static const unsigned char flipnibble[] =
47 {0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E,
48 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F};
49 int i;
50
51 for (i = 0; i < size; i++) {
52 v[i] = (flipnibble[v[i] & 0x0F] << 4) |
53 flipnibble[(v[i] >> 4) & 0x0F];
54 }
55}
56
57void rtc_init(void)
58{
59 i2c_init();
60}
61
62int rtc_read_datetime(unsigned char* buf)
63{
64 unsigned char data[7];
65 int i, ret;
66
67 ret = i2c_read(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data);
68 reverse_bits(data, sizeof(data));
69
70 buf[4] &= 0x3f; /* mask out p.m. flag */
71
72 for (i = 0; i < 7; i++) {
73 buf[i] = data[6 - i];
74 }
75
76 return ret;
77}
78
79int rtc_write_datetime(unsigned char* buf)
80{
81 unsigned char data[7];
82 int i, ret;
83
84 for (i = 0; i < 7; i++) {
85 data[i] = buf[6 - i];
86 }
87
88 reverse_bits(data, sizeof(data));
89 ret = i2c_write(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data);
90
91 return ret;
92}
93
diff --git a/firmware/export/config-meizu-m3.h b/firmware/export/config-meizu-m3.h
index 06a0992550..2a02052381 100644
--- a/firmware/export/config-meizu-m3.h
+++ b/firmware/export/config-meizu-m3.h
@@ -80,8 +80,8 @@
80#define CONFIG_CODEC SWCODEC 80#define CONFIG_CODEC SWCODEC
81 81
82/* define this if you have a real-time clock */ 82/* define this if you have a real-time clock */
83#define CONFIG_RTC RTC_S5L8700 83//#define CONFIG_RTC RTC_S5L8700
84//#define CONFIG_RTC RTC_S35390A 84#define CONFIG_RTC RTC_S35390A
85 85
86#define CONFIG_LCD LCD_MEIZUM6 86#define CONFIG_LCD LCD_MEIZUM6
87 87