summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/drivers/rtc/rtc_s35380a.c128
-rw-r--r--firmware/export/config.h3
-rw-r--r--firmware/export/config/mpiohd300.h2
4 files changed, 133 insertions, 2 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 5506f98e85..349155f8ce 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -252,6 +252,8 @@ drivers/rtc/rtc_tcc77x.c
252drivers/rtc/rtc_jz4740.c 252drivers/rtc/rtc_jz4740.c
253#elif (CONFIG_RTC == RTC_S35390A) 253#elif (CONFIG_RTC == RTC_S35390A)
254drivers/rtc/rtc_s35390a.c 254drivers/rtc/rtc_s35390a.c
255#elif (CONFIG_RTC == RTC_S35380A)
256drivers/rtc/rtc_s35380a.c
255#elif (CONFIG_RTC == RTC_D2) 257#elif (CONFIG_RTC == RTC_D2)
256drivers/rtc/rtc_d2.c 258drivers/rtc/rtc_d2.c
257#endif /* (CONFIG_RTC == RTC_) */ 259#endif /* (CONFIG_RTC == RTC_) */
diff --git a/firmware/drivers/rtc/rtc_s35380a.c b/firmware/drivers/rtc/rtc_s35380a.c
new file mode 100644
index 0000000000..7a7bf81118
--- /dev/null
+++ b/firmware/drivers/rtc/rtc_s35380a.c
@@ -0,0 +1,128 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * adopted for HD300 by Marcin Bukat
11 * Copyright (C) 2009 by Bertrik Sikken
12 * Copyright (C) 2008 by Robert Kukla
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "config.h"
24#include "rtc.h"
25#include "i2c-coldfire.h"
26
27/* Driver for the Seiko S35380A real-time clock chip with i2c interface
28
29 This driver was derived from rtc_s3539a.c and adapted for the MPIO HD300
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/* STATUS_REG1 flags */
44#define STATUS_REG1_POC 0x80
45#define STATUS_REG1_BLD 0x40
46#define STATUS_REG1_INT2 0x20
47#define STATUS_REG1_INT1 0x10
48#define STATUS_REG1_SC1 0x08
49#define STATUS_REG1_SC0 0x04
50#define STATUS_REG1_H1224 0x02
51#define STATUS_REG1_RESET 0x01
52
53
54static void reverse_bits(unsigned char* v, int size)
55{
56 static const unsigned char flipnibble[] =
57 {0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E,
58 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F};
59 int i;
60
61 for (i = 0; i < size; i++) {
62 v[i] = (flipnibble[v[i] & 0x0F] << 4) |
63 flipnibble[(v[i] >> 4) & 0x0F];
64 }
65}
66
67void rtc_init(void)
68{
69 unsigned char status_reg;
70 i2c_read(I2C_IFACE_1, RTC_ADDR | (STATUS_REG1<<1), &status_reg, 1);
71
72 if ( (status_reg & STATUS_REG1_POC) ||
73 (status_reg & STATUS_REG1_BLD) )
74 {
75 /* perform rtc reset*/
76 status_reg |= STATUS_REG1_RESET;
77 i2c_write(I2C_IFACE_1, RTC_ADDR | (STATUS_REG1<<1), &status_reg, 1);
78 }
79}
80
81int rtc_read_datetime(struct tm *tm)
82{
83 unsigned char buf[7];
84 unsigned int i;
85 int ret;
86
87 ret = i2c_read(I2C_IFACE_1, RTC_ADDR | (REALTIME_DATA1<<1), buf, sizeof(buf));
88 reverse_bits(buf, sizeof(buf));
89
90 buf[4] &= 0x3f; /* mask out p.m. flag */
91
92 for (i = 0; i < sizeof(buf); i++)
93 buf[i] = BCD2DEC(buf[i]);
94
95 tm->tm_sec = buf[6];
96 tm->tm_min = buf[5];
97 tm->tm_hour = buf[4];
98 tm->tm_wday = buf[3];
99 tm->tm_mday = buf[2];
100 tm->tm_mon = buf[1] - 1;
101 tm->tm_year = buf[0] + 100;
102
103 return ret;
104}
105
106int rtc_write_datetime(const struct tm *tm)
107{
108 unsigned char buf[7];
109 unsigned int i;
110 int ret;
111
112 buf[6] = tm->tm_sec;
113 buf[5] = tm->tm_min;
114 buf[4] = tm->tm_hour;
115 buf[3] = tm->tm_wday;
116 buf[2] = tm->tm_mday;
117 buf[1] = tm->tm_mon + 1;
118 buf[0] = tm->tm_year - 100;
119
120 for (i = 0; i < sizeof(buf); i++)
121 buf[i] = DEC2BCD(buf[i]);
122
123 reverse_bits(buf, sizeof(buf));
124 ret = i2c_write(I2C_IFACE_1, RTC_ADDR | (REALTIME_DATA1<<1), buf, sizeof(buf));
125
126 return ret;
127}
128
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 52cb79bdae..540eff0329 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -279,7 +279,8 @@ Lyre prototype 1 */
279#define RTC_S35390A 15 279#define RTC_S35390A 15
280#define RTC_JZ47XX 16 /* Ingenic Jz47XX */ 280#define RTC_JZ47XX 16 /* Ingenic Jz47XX */
281#define RTC_NANO2G 17 /* This seems to be a PCF5063x */ 281#define RTC_NANO2G 17 /* This seems to be a PCF5063x */
282#define RTC_D2 18 /* Either PCF50606 or PCF50635 */ 282#define RTC_D2 18 /* Either PCF50606 or PCF50635 */
283#define RTC_S35380A 19
283 284
284/* USB On-the-go */ 285/* USB On-the-go */
285#define USBOTG_M66591 6591 /* M:Robe 500 */ 286#define USBOTG_M66591 6591 /* M:Robe 500 */
diff --git a/firmware/export/config/mpiohd300.h b/firmware/export/config/mpiohd300.h
index 37f79b4d47..afab313bb2 100644
--- a/firmware/export/config/mpiohd300.h
+++ b/firmware/export/config/mpiohd300.h
@@ -73,7 +73,7 @@
73#define CONFIG_CODEC SWCODEC 73#define CONFIG_CODEC SWCODEC
74 74
75/* Define this if you have RTC */ 75/* Define this if you have RTC */
76#define CONFIG_RTC RTC_S35390A 76#define CONFIG_RTC RTC_S35380A
77 77
78#define CONFIG_LCD LCD_S1D15E06 78#define CONFIG_LCD LCD_S1D15E06
79 79