summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2008-02-03 18:15:39 +0000
committerRobert Kukla <roolku@rockbox.org>2008-02-03 18:15:39 +0000
commit9dc67828a9906498a16fd4ad55ae5319cc934dd1 (patch)
treed127977ce10ba6773ee142419267051027b3f2b5
parent6f65afd0b757e2111c5b764def30170caa937a6f (diff)
downloadrockbox-9dc67828a9906498a16fd4ad55ae5319cc934dd1.tar.gz
rockbox-9dc67828a9906498a16fd4ad55ae5319cc934dd1.zip
mrobe 100: real time clock (if anybody recognises the RTC chip let me know)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16208 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES5
-rw-r--r--firmware/drivers/rtc/rtc_mr100.c114
-rw-r--r--firmware/drivers/sw_i2c.c (renamed from firmware/target/coldfire/iriver/h100/sw_i2c-h100.c)44
-rw-r--r--firmware/export/config-mrobe100.h2
-rw-r--r--firmware/export/config.h1
-rw-r--r--firmware/export/sw_i2c.h4
6 files changed, 160 insertions, 10 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index eaa4cb32cb..9330576145 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -148,6 +148,8 @@ drivers/rtc/rtc_s3c2440.c
148drivers/rtc/rtc_as3514.c 148drivers/rtc/rtc_as3514.c
149#elif (CONFIG_RTC == RTC_RX5X348AB) 149#elif (CONFIG_RTC == RTC_RX5X348AB)
150drivers/rtc/rtc_rx5x348ab.c 150drivers/rtc/rtc_rx5x348ab.c
151#elif (CONFIG_RTC == RTC_MR100)
152drivers/rtc/rtc_mr100.c
151#endif /* (CONFIG_RTC == RTC_) */ 153#endif /* (CONFIG_RTC == RTC_) */
152#endif /* SIMULATOR */ 154#endif /* SIMULATOR */
153 155
@@ -523,12 +525,12 @@ target/coldfire/iriver/audio-iriver.c
523 525
524#ifdef IRIVER_H100_SERIES 526#ifdef IRIVER_H100_SERIES
525#ifndef SIMULATOR 527#ifndef SIMULATOR
528drivers/sw_i2c.c
526target/coldfire/ata-as-coldfire.S 529target/coldfire/ata-as-coldfire.S
527target/coldfire/iriver/ata-iriver.c 530target/coldfire/iriver/ata-iriver.c
528target/coldfire/iriver/lcd-remote-iriver.c 531target/coldfire/iriver/lcd-remote-iriver.c
529target/coldfire/iriver/system-iriver.c 532target/coldfire/iriver/system-iriver.c
530target/coldfire/iriver/fmradio_i2c-iriver.c 533target/coldfire/iriver/fmradio_i2c-iriver.c
531target/coldfire/iriver/h100/sw_i2c-h100.c
532target/coldfire/iriver/h100/adc-h100.c 534target/coldfire/iriver/h100/adc-h100.c
533target/coldfire/iriver/h100/backlight-h100.c 535target/coldfire/iriver/h100/backlight-h100.c
534target/coldfire/iriver/h100/button-h100.c 536target/coldfire/iriver/h100/button-h100.c
@@ -661,6 +663,7 @@ target/arm/tms320dm320/dsp-dm320.c
661 663
662#ifdef MROBE_100 664#ifdef MROBE_100
663#ifndef SIMULATOR 665#ifndef SIMULATOR
666drivers/sw_i2c.c
664target/arm/ata-as-arm.S 667target/arm/ata-as-arm.S
665target/arm/ata-pp5020.c 668target/arm/ata-pp5020.c
666target/arm/wmcodec-pp.c 669target/arm/wmcodec-pp.c
diff --git a/firmware/drivers/rtc/rtc_mr100.c b/firmware/drivers/rtc/rtc_mr100.c
new file mode 100644
index 0000000000..96d84156a7
--- /dev/null
+++ b/firmware/drivers/rtc/rtc_mr100.c
@@ -0,0 +1,114 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Robert Kukla
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 "rtc.h"
20#include "logf.h"
21#include "sw_i2c.h"
22#include "i2c-pp.h"
23
24/* The RTC chip is unknown, the information about it was gathered by
25 * reverse engineering the bootloader.
26 */
27
28#define RTC_ADDR 0x60
29
30#define RTC_CMD_CTRL 0 /* OF uses it with single byte 1 or 2 */
31#define RTC_CMD_UNKN 1 /* OF uses it with single byte 8 */
32#define RTC_CMD_DATA 2
33#define RTC_CMD_TEST 7 /* OF uses it with single byte 0xAA */
34
35/* private */
36
37static void reverse_bits(unsigned char* v, int size) {
38
39 int i,j,in,out=0;
40
41 for(j=0; j<size; j++) {
42 in = v[j];
43 for(i=0; i<8; i++) {
44 out |= (in & 1);
45 in = in >>1;
46 out = out<<1;
47 }
48 v[j] = out>>1;
49 }
50}
51
52static int sw_i2c(int access, unsigned char chip, unsigned char cmd,
53 unsigned char* buf, int count) {
54 int i;
55
56 i2c_lock();
57 GPIOC_ENABLE |= 0x00000030;
58
59 chip|=cmd<<1;
60
61 if(access == SW_I2C_READ) {
62 i = sw_i2c_read(chip, 0, buf, count);
63 reverse_bits(buf, count);
64 } else {
65 reverse_bits(buf, count);
66 i = sw_i2c_write(chip, 0, buf, count);
67 }
68
69 GPIOC_ENABLE &= ~0x00000030;
70 i2c_unlock();
71
72 return i;
73}
74
75/* public */
76
77void rtc_init(void)
78{
79 sw_i2c_init();
80
81 /* to set a time while buttons are stil not working
82 unsigned char v[7] = {0x00,0x47,0x17,0x06,0x03,0x02,0x08};
83 rtc_write_datetime(v);
84 */
85}
86
87int rtc_read_datetime(unsigned char* buf)
88{
89 int i;
90 unsigned char v[7];
91
92 i = sw_i2c(SW_I2C_READ, RTC_ADDR, RTC_CMD_DATA, v, 7);
93
94 v[4] &= 0x3f; /* mask out p.m. flag */
95
96 for(i=0; i<7; i++)
97 buf[i] = v[6-i];
98
99 return i;
100}
101
102int rtc_write_datetime(unsigned char* buf)
103{
104 int i;
105 unsigned char v[7];
106
107 for(i=0; i<7; i++)
108 v[i]=buf[6-i];
109
110 i = sw_i2c(SW_I2C_WRITE, RTC_ADDR, RTC_CMD_DATA, v, 7);
111
112 return i;
113}
114
diff --git a/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c b/firmware/drivers/sw_i2c.c
index 3b2cdc4042..c1f6868226 100644
--- a/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c
+++ b/firmware/drivers/sw_i2c.c
@@ -24,11 +24,30 @@
24 24
25/** 25/**
26 * I2C-functions are copied and ported from fmradio.c. 26 * I2C-functions are copied and ported from fmradio.c.
27 * later fixed, adapted and moved to a seperate file so they can be re-used by the rtc-ds1339c code by Robert Kukla 27 * later fixed, adapted and moved to a seperate file so they can be re-used
28 * by the rtc-ds1339c and later by the m:robe-100 code by Robert Kukla
28 */ 29 */
29 30
30/* cute little functions, atomic read-modify-write */ 31/* cute little functions, atomic read-modify-write */
31 32
33#ifdef MROBE_100
34
35/* SCL is GPIOC, 4 */
36#define SCL (GPIOC_INPUT_VAL & 0x00000010)
37#define SCL_OUT_LO GPIOC_OUTPUT_VAL&=~0x00000010
38#define SCL_LO GPIOC_OUTPUT_EN |= 0x00000010
39#define SCL_HI GPIOC_OUTPUT_EN &=~0x00000010
40
41/* SDA is GPIOC, 5 */
42#define SDA (GPIOC_INPUT_VAL & 0x00000020)
43#define SDA_OUT_LO GPIOC_OUTPUT_VAL&=~0x00000020
44#define SDA_LO GPIOC_OUTPUT_EN |= 0x00000020
45#define SDA_HI GPIOC_OUTPUT_EN &=~0x00000020
46
47#define DELAY do { volatile int _x; for(_x=0;_x<22;_x++);} while(0)
48
49#else
50
32/* SCL is GPIO, 12 */ 51/* SCL is GPIO, 12 */
33#define SCL ( 0x00001000 & GPIO_READ) 52#define SCL ( 0x00001000 & GPIO_READ)
34#define SCL_OUT_LO and_l(~0x00001000, &GPIO_OUT) 53#define SCL_OUT_LO and_l(~0x00001000, &GPIO_OUT)
@@ -54,10 +73,15 @@
54 ); \ 73 ); \
55 }) 74 })
56 75
76#endif
77
57void sw_i2c_init(void) 78void sw_i2c_init(void)
58{ 79{
80#ifndef MROBE_100
59 or_l(0x00001000, &GPIO_FUNCTION); 81 or_l(0x00001000, &GPIO_FUNCTION);
60 or_l(0x00002000, &GPIO1_FUNCTION); 82 or_l(0x00002000, &GPIO1_FUNCTION);
83#endif
84
61 SDA_HI; 85 SDA_HI;
62 SCL_HI; 86 SCL_HI;
63 SDA_OUT_LO; 87 SDA_OUT_LO;
@@ -192,7 +216,7 @@ static unsigned char sw_i2c_inb(void)
192 return byte; 216 return byte;
193} 217}
194 218
195int sw_i2c_write(unsigned char chip, unsigned char location, const unsigned char* buf, int count) 219int sw_i2c_write(unsigned char chip, unsigned char location, unsigned char* buf, int count)
196{ 220{
197 int i; 221 int i;
198 222
@@ -203,14 +227,18 @@ int sw_i2c_write(unsigned char chip, unsigned char location, const unsigned char
203 sw_i2c_stop(); 227 sw_i2c_stop();
204 return -1; 228 return -1;
205 } 229 }
206 230
231#ifdef MROBE_100 /* does not use register addressing */
232 (void) location;
233#else
207 sw_i2c_outb(location); 234 sw_i2c_outb(location);
208 if (!sw_i2c_getack()) 235 if (!sw_i2c_getack())
209 { 236 {
210 sw_i2c_stop(); 237 sw_i2c_stop();
211 return -2; 238 return -2;
212 } 239 }
213 240#endif
241
214 for (i=0; i<count; i++) 242 for (i=0; i<count; i++)
215 { 243 {
216 sw_i2c_outb(buf[i]); 244 sw_i2c_outb(buf[i]);
@@ -229,7 +257,10 @@ int sw_i2c_write(unsigned char chip, unsigned char location, const unsigned char
229int sw_i2c_read(unsigned char chip, unsigned char location, unsigned char* buf, int count) 257int sw_i2c_read(unsigned char chip, unsigned char location, unsigned char* buf, int count)
230{ 258{
231 int i; 259 int i;
232 260
261#ifdef MROBE_100 /* does not use register addressing */
262 (void) location;
263#else
233 sw_i2c_start(); 264 sw_i2c_start();
234 sw_i2c_outb((chip & 0xfe) | SW_I2C_WRITE); 265 sw_i2c_outb((chip & 0xfe) | SW_I2C_WRITE);
235 if (!sw_i2c_getack()) 266 if (!sw_i2c_getack())
@@ -244,7 +275,8 @@ int sw_i2c_read(unsigned char chip, unsigned char location, unsigned char* buf,
244 sw_i2c_stop(); 275 sw_i2c_stop();
245 return -2; 276 return -2;
246 } 277 }
247 278#endif
279
248 sw_i2c_start(); 280 sw_i2c_start();
249 sw_i2c_outb((chip & 0xfe) | SW_I2C_READ); 281 sw_i2c_outb((chip & 0xfe) | SW_I2C_READ);
250 if (!sw_i2c_getack()) 282 if (!sw_i2c_getack())
diff --git a/firmware/export/config-mrobe100.h b/firmware/export/config-mrobe100.h
index 0d49023b63..f796d10abb 100644
--- a/firmware/export/config-mrobe100.h
+++ b/firmware/export/config-mrobe100.h
@@ -43,7 +43,7 @@
43 43
44/* define this if you have a real-time clock */ 44/* define this if you have a real-time clock */
45#ifndef BOOTLOADER 45#ifndef BOOTLOADER
46//#define CONFIG_RTC RTC_E8564 46#define CONFIG_RTC RTC_MR100
47#endif 47#endif
48 48
49/* Define this if you have a software controlled poweroff */ 49/* Define this if you have a software controlled poweroff */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 1f29a4f207..4d2f70fa86 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -161,6 +161,7 @@
161#define RTC_RX5X348AB 9 161#define RTC_RX5X348AB 9
162#define RTC_TCC77X 10 162#define RTC_TCC77X 10
163#define RTC_TCC780X 11 163#define RTC_TCC780X 11
164#define RTC_MR100 12
164 165
165/* USB On-the-go */ 166/* USB On-the-go */
166#define USBOTG_ISP1362 1362 /* iriver H300 */ 167#define USBOTG_ISP1362 1362 /* iriver H300 */
diff --git a/firmware/export/sw_i2c.h b/firmware/export/sw_i2c.h
index 42dccad742..dd48a6206f 100644
--- a/firmware/export/sw_i2c.h
+++ b/firmware/export/sw_i2c.h
@@ -24,7 +24,7 @@
24#define SW_I2C_READ 1 24#define SW_I2C_READ 1
25 25
26void sw_i2c_init(void); 26void sw_i2c_init(void);
27int sw_i2c_write(unsigned char chip, unsigned char location, const unsigned char* buf, int count); 27int sw_i2c_write(unsigned char chip, unsigned char location, unsigned char* buf, int count);
28int sw_i2c_read (unsigned char chip, unsigned char location, unsigned char* buf, int count); 28int sw_i2c_read (unsigned char chip, unsigned char location, unsigned char* buf, int count);
29 29
30#endif 30#endif