summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/drivers/eeprom_24cxx.c55
-rw-r--r--firmware/drivers/pcf50606.c12
-rw-r--r--firmware/export/config-h100.h2
-rw-r--r--firmware/export/config-h120.h3
-rw-r--r--firmware/export/config-h300.h3
-rw-r--r--firmware/export/eeprom_24cxx.h5
-rw-r--r--firmware/export/pcf50606.h8
8 files changed, 60 insertions, 30 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index fda83ee073..23da475304 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -150,8 +150,10 @@ drivers/pcf50606.c
150#endif 150#endif
151#ifdef HAVE_EEPROM 151#ifdef HAVE_EEPROM
152drivers/eeprom_24cxx.c 152drivers/eeprom_24cxx.c
153#ifdef HAVE_EEPROM_SETTINGS
153eeprom_settings.c 154eeprom_settings.c
154#endif 155#endif
156#endif
155#ifdef IPOD_ARCH 157#ifdef IPOD_ARCH
156drivers/pcf50605.c 158drivers/pcf50605.c
157#endif 159#endif
diff --git a/firmware/drivers/eeprom_24cxx.c b/firmware/drivers/eeprom_24cxx.c
index 9a8fa5d86d..66bc235052 100644
--- a/firmware/drivers/eeprom_24cxx.c
+++ b/firmware/drivers/eeprom_24cxx.c
@@ -35,21 +35,24 @@
35#define SW_I2C_WRITE 0 35#define SW_I2C_WRITE 0
36#define SW_I2C_READ 1 36#define SW_I2C_READ 1
37 37
38/* h1x0 needs its own i2c driver,
39 h3x0 uses the pcf i2c driver */
40
41#ifdef IRIVER_H100_SERIES
42
38/* cute little functions, atomic read-modify-write */ 43/* cute little functions, atomic read-modify-write */
39 44
40/* SCL is GPIO, 12 */ 45/* SCL is GPIO, 12 */
41#define SCL_LO and_l(~0x00001000, &GPIO_OUT) // and_b(~0x10, &PBDRL) 46#define SCL ( 0x00001000 & GPIO_READ)
42#define SCL_HI or_l( 0x00001000, &GPIO_OUT) // or_b( 0x10, &PBDRL) 47#define SCL_OUT_LO and_l(~0x00001000, &GPIO_OUT)
43#define SCL_INPUT and_l(~0x00001000, &GPIO_ENABLE) // and_b(~0x10, &PBIORL) 48#define SCL_LO or_l( 0x00001000, &GPIO_ENABLE)
44#define SCL_OUTPUT or_l( 0x00001000, &GPIO_ENABLE) // or_b( 0x10, &PBIORL) 49#define SCL_HI and_l(~0x00001000, &GPIO_ENABLE); while(!SCL);
45#define SCL ( 0x00001000 & GPIO_READ) // (PBDR & 0x0010)
46 50
47/* SDA is GPIO1, 13 */ 51/* SDA is GPIO1, 13 */
48#define SDA_LO and_l(~0x00002000, &GPIO1_OUT) // and_b(~0x02, &PBDRL) 52#define SDA ( 0x00002000 & GPIO1_READ)
49#define SDA_HI or_l( 0x00002000, &GPIO1_OUT) // or_b( 0x02, &PBDRL) 53#define SDA_OUT_LO and_l(~0x00002000, &GPIO1_OUT)
50#define SDA_INPUT and_l(~0x00002000, &GPIO1_ENABLE) // and_b(~0x02, &PBIORL) 54#define SDA_LO or_l( 0x00002000, &GPIO1_ENABLE)
51#define SDA_OUTPUT or_l( 0x00002000, &GPIO1_ENABLE) // or_b( 0x02, &PBIORL) 55#define SDA_HI and_l(~0x00002000, &GPIO1_ENABLE)
52#define SDA ( 0x00002000 & GPIO1_READ) // (PBDR & 0x0002)
53 56
54/* delay loop to achieve 400kHz at 120MHz CPU frequency */ 57/* delay loop to achieve 400kHz at 120MHz CPU frequency */
55#define DELAY do { int _x; for(_x=0;_x<22;_x++);} while(0) 58#define DELAY do { int _x; for(_x=0;_x<22;_x++);} while(0)
@@ -61,17 +64,15 @@ static void sw_i2c_init(void)
61 or_l(0x00002000, &GPIO1_FUNCTION); 64 or_l(0x00002000, &GPIO1_FUNCTION);
62 SDA_HI; 65 SDA_HI;
63 SCL_HI; 66 SCL_HI;
64 SDA_OUTPUT; 67 SDA_OUT_LO;
65 SCL_OUTPUT; 68 SCL_OUT_LO;
66} 69}
67 70
68static void sw_i2c_start(void) 71static void sw_i2c_start(void)
69{ 72{
70 SCL_LO; 73 SCL_LO;
71 SCL_OUTPUT;
72 DELAY; 74 DELAY;
73 SDA_HI; 75 SDA_HI;
74 SDA_OUTPUT;
75 DELAY; 76 DELAY;
76 SCL_HI; 77 SCL_HI;
77 DELAY; 78 DELAY;
@@ -88,7 +89,6 @@ static void sw_i2c_stop(void)
88 DELAY; 89 DELAY;
89} 90}
90 91
91
92static void sw_i2c_ack(void) 92static void sw_i2c_ack(void)
93{ 93{
94 SCL_LO; 94 SCL_LO;
@@ -105,7 +105,7 @@ static bool sw_i2c_getack(void)
105 int count = 10; 105 int count = 10;
106 106
107 SCL_LO; 107 SCL_LO;
108 SDA_INPUT; /* And set to input */ 108 SDA_HI; /* sets to input */
109 DELAY; 109 DELAY;
110 SCL_HI; 110 SCL_HI;
111 DELAY; 111 DELAY;
@@ -118,10 +118,8 @@ static bool sw_i2c_getack(void)
118 ret = false; 118 ret = false;
119 119
120 SCL_LO; 120 SCL_LO;
121 SCL_OUTPUT;
122 DELAY; 121 DELAY;
123 SDA_LO; 122 SDA_LO;
124 SDA_OUTPUT;
125 123
126 return ret; 124 return ret;
127} 125}
@@ -143,8 +141,6 @@ static void sw_i2c_outb(unsigned char byte)
143 SCL_HI; 141 SCL_HI;
144 DELAY; 142 DELAY;
145 } 143 }
146
147 // SDA_LO;
148} 144}
149 145
150static unsigned char sw_i2c_inb(void) 146static unsigned char sw_i2c_inb(void)
@@ -152,7 +148,7 @@ static unsigned char sw_i2c_inb(void)
152 int i; 148 int i;
153 unsigned char byte = 0; 149 unsigned char byte = 0;
154 150
155 SDA_INPUT; /* And set to input */ 151 SDA_HI; /* sets to input */
156 152
157 /* clock in each bit, MSB first */ 153 /* clock in each bit, MSB first */
158 for ( i=0x80; i; i>>=1 ) 154 for ( i=0x80; i; i>>=1 )
@@ -165,13 +161,26 @@ static unsigned char sw_i2c_inb(void)
165 DELAY; 161 DELAY;
166 } 162 }
167 163
168 SDA_OUTPUT;
169
170 sw_i2c_ack(); 164 sw_i2c_ack();
171 165
172 return byte; 166 return byte;
173} 167}
174 168
169#else
170
171#include "pcf50606.h"
172
173#define sw_i2c_init() /* no extra init required */
174#define sw_i2c_start() pcf50606_i2c_start()
175#define sw_i2c_stop() pcf50606_i2c_stop()
176#define sw_i2c_ack() pcf50606_i2c_ack(true)
177#define sw_i2c_getack() pcf50606_i2c_getack()
178#define sw_i2c_outb(x) pcf50606_i2c_outb(x)
179#define sw_i2c_inb() pcf50606_i2c_inb(false)
180
181#endif /* IRIVER_H100_SERIES */
182
183
175int sw_i2c_write(int location, const unsigned char* buf, int count) 184int sw_i2c_write(int location, const unsigned char* buf, int count)
176{ 185{
177 int i; 186 int i;
diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c
index 0f2d73664b..28df295988 100644
--- a/firmware/drivers/pcf50606.c
+++ b/firmware/drivers/pcf50606.c
@@ -52,7 +52,7 @@ void pcf50606_i2c_recalc_delay(int cpu_clock)
52 i2c_delay = MAX(cpu_clock / (400000*2*3) - 7, 1); 52 i2c_delay = MAX(cpu_clock / (400000*2*3) - 7, 1);
53} 53}
54 54
55static inline void pcf50606_i2c_start(void) 55inline void pcf50606_i2c_start(void)
56{ 56{
57#ifdef USE_ASM 57#ifdef USE_ASM
58 asm ( 58 asm (
@@ -101,7 +101,7 @@ static inline void pcf50606_i2c_start(void)
101#endif 101#endif
102} 102}
103 103
104static inline void pcf50606_i2c_stop(void) 104inline void pcf50606_i2c_stop(void)
105{ 105{
106#ifdef USE_ASM 106#ifdef USE_ASM
107 asm ( 107 asm (
@@ -141,7 +141,7 @@ static inline void pcf50606_i2c_stop(void)
141#endif 141#endif
142} 142}
143 143
144static inline void pcf50606_i2c_ack(bool ack) 144inline void pcf50606_i2c_ack(bool ack)
145{ 145{
146#ifdef USE_ASM 146#ifdef USE_ASM
147 asm ( 147 asm (
@@ -193,7 +193,7 @@ static inline void pcf50606_i2c_ack(bool ack)
193#endif 193#endif
194} 194}
195 195
196static inline bool pcf50606_i2c_getack(void) 196inline bool pcf50606_i2c_getack(void)
197{ 197{
198 bool ret; 198 bool ret;
199 199
@@ -251,7 +251,7 @@ static inline bool pcf50606_i2c_getack(void)
251 return ret; 251 return ret;
252} 252}
253 253
254static void pcf50606_i2c_outb(unsigned char byte) 254void pcf50606_i2c_outb(unsigned char byte)
255{ 255{
256#ifdef USE_ASM 256#ifdef USE_ASM
257 asm volatile ( 257 asm volatile (
@@ -321,7 +321,7 @@ static void pcf50606_i2c_outb(unsigned char byte)
321#endif 321#endif
322} 322}
323 323
324static unsigned char pcf50606_i2c_inb(bool ack) 324unsigned char pcf50606_i2c_inb(bool ack)
325{ 325{
326 unsigned char byte = 0; 326 unsigned char byte = 0;
327 327
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index 88108c71f7..38f26c104b 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -129,7 +129,7 @@
129 129
130/* Define this if there is an EEPROM chip */ 130/* Define this if there is an EEPROM chip */
131/* Someone with H100 and BDM, please verify if this works. */ 131/* Someone with H100 and BDM, please verify if this works. */
132// #define HAVE_EEPROM 132/* #define HAVE_EEPROM */
133 133
134#endif /* !SIMULATOR */ 134#endif /* !SIMULATOR */
135 135
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index ca618139e9..a9b0ed3039 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -125,6 +125,9 @@
125/* Define this if there is an EEPROM chip */ 125/* Define this if there is an EEPROM chip */
126#define HAVE_EEPROM 126#define HAVE_EEPROM
127 127
128/* Define this if the EEPROM chip is used */
129#define HAVE_EEPROM_SETTINGS
130
128#endif /* !SIMULATOR */ 131#endif /* !SIMULATOR */
129 132
130/* Define this for S/PDIF input available */ 133/* Define this for S/PDIF input available */
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index f3ba076334..2a174bc4e5 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -133,4 +133,7 @@
133/* define this if the unit can be powered or charged via USB */ 133/* define this if the unit can be powered or charged via USB */
134#define HAVE_USB_POWER 134#define HAVE_USB_POWER
135 135
136/* Define this if there is an EEPROM chip */
137#define HAVE_EEPROM
138
136#endif /* SIMULATOR */ 139#endif /* SIMULATOR */
diff --git a/firmware/export/eeprom_24cxx.h b/firmware/export/eeprom_24cxx.h
index bc0f444f7e..c52dd830ef 100644
--- a/firmware/export/eeprom_24cxx.h
+++ b/firmware/export/eeprom_24cxx.h
@@ -20,8 +20,13 @@
20#ifndef _EEPROM_24CXX_H 20#ifndef _EEPROM_24CXX_H
21#define _EEPROM_24CXX_H 21#define _EEPROM_24CXX_H
22 22
23#ifdef IRIVER_H300_SERIES
24#define EEPROM_ADDR 0xA2
25#define EEPROM_SIZE 256
26#else
23#define EEPROM_ADDR 0xA0 27#define EEPROM_ADDR 0xA0
24#define EEPROM_SIZE 128 28#define EEPROM_SIZE 128
29#endif
25 30
26void eeprom_24cxx_init(void); 31void eeprom_24cxx_init(void);
27int eeprom_24cxx_read_byte(unsigned int address, char *c); 32int eeprom_24cxx_read_byte(unsigned int address, char *c);
diff --git a/firmware/export/pcf50606.h b/firmware/export/pcf50606.h
index d9f44bb577..3e567c963c 100644
--- a/firmware/export/pcf50606.h
+++ b/firmware/export/pcf50606.h
@@ -26,4 +26,12 @@ int pcf50606_write(int address, unsigned char val);
26int pcf50606_read_multiple(int address, unsigned char* buf, int count); 26int pcf50606_read_multiple(int address, unsigned char* buf, int count);
27int pcf50606_read(int address); 27int pcf50606_read(int address);
28 28
29/* internal low level calls used by the eeprom driver for h300 */
30void pcf50606_i2c_start(void);
31void pcf50606_i2c_stop(void);
32void pcf50606_i2c_ack(bool ack);
33bool pcf50606_i2c_getack(void);
34void pcf50606_i2c_outb(unsigned char byte);
35unsigned char pcf50606_i2c_inb(bool ack);
36
29#endif 37#endif