summaryrefslogtreecommitdiff
path: root/firmware/drivers/eeprom_24cxx.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/eeprom_24cxx.c')
-rw-r--r--firmware/drivers/eeprom_24cxx.c55
1 files changed, 32 insertions, 23 deletions
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;