diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-01 21:00:31 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-01 21:00:31 +0000 |
commit | fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea (patch) | |
tree | 8a61f852ef81a9dd5950e9ebc9ffb8ac41bf3390 /firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c | |
parent | 5212f03124c486239479d75cafb8017d84f63ee9 (diff) | |
download | rockbox-fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea.tar.gz rockbox-fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea.zip |
Onda VX747: try at implementing FM tuner support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21160 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c b/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c index 5df0e90683..79968889b9 100644 --- a/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c | |||
@@ -20,6 +20,10 @@ | |||
20 | * KIND, either express or implied. | 20 | * KIND, either express or implied. |
21 | * | 21 | * |
22 | ****************************************************************************/ | 22 | ****************************************************************************/ |
23 | #include "config.h" | ||
24 | #include "system.h" | ||
25 | #include "jz4740.h" | ||
26 | #include "logf.h" | ||
23 | 27 | ||
24 | /* | 28 | /* |
25 | * Jz4740 I2C routines. | 29 | * Jz4740 I2C routines. |
@@ -42,15 +46,9 @@ | |||
42 | * | 46 | * |
43 | */ | 47 | */ |
44 | 48 | ||
45 | #include "config.h" | ||
46 | #include "system.h" | ||
47 | #include "jz4740.h" | ||
48 | #include "logf.h" | ||
49 | |||
50 | |||
51 | /* I2C protocol */ | 49 | /* I2C protocol */ |
52 | #define I2C_READ 1 | 50 | #define I2C_READ 1 |
53 | #define I2C_WRITE 0 | 51 | #define I2C_WRITE 0 |
54 | 52 | ||
55 | #define TIMEOUT 1000 | 53 | #define TIMEOUT 1000 |
56 | 54 | ||
@@ -84,7 +82,7 @@ static int i2c_put_data_nack(unsigned char data) | |||
84 | while (__i2c_check_drf() != 0); | 82 | while (__i2c_check_drf() != 0); |
85 | while (!__i2c_transmit_ended()); | 83 | while (!__i2c_transmit_ended()); |
86 | while (timeout--); | 84 | while (timeout--); |
87 | 85 | ||
88 | return 0; | 86 | return 0; |
89 | } | 87 | } |
90 | #endif | 88 | #endif |
@@ -121,13 +119,13 @@ void i2c_setclk(unsigned int i2cclk) | |||
121 | /* | 119 | /* |
122 | * I2C interface | 120 | * I2C interface |
123 | */ | 121 | */ |
124 | void i2c_open(void) | 122 | static void i2c_open(void) |
125 | { | 123 | { |
126 | i2c_setclk(10000); /* default 10 KHz */ | 124 | i2c_setclk(10000); /* default 10 KHz */ |
127 | __i2c_enable(); | 125 | __i2c_enable(); |
128 | } | 126 | } |
129 | 127 | ||
130 | void i2c_close(void) | 128 | static void i2c_close(void) |
131 | { | 129 | { |
132 | udelay(300); /* wait for STOP goes over. */ | 130 | udelay(300); /* wait for STOP goes over. */ |
133 | __i2c_disable(); | 131 | __i2c_disable(); |
@@ -137,21 +135,23 @@ int i2c_read(int device, unsigned char *buf, int count) | |||
137 | { | 135 | { |
138 | int cnt = count; | 136 | int cnt = count; |
139 | int timeout = 5; | 137 | int timeout = 5; |
140 | 138 | ||
141 | device &= 0xFF; | 139 | device &= 0xFF; |
142 | 140 | ||
141 | i2c_open(); | ||
142 | |||
143 | L_try_again: | 143 | L_try_again: |
144 | if (timeout < 0) | 144 | if (timeout < 0) |
145 | goto L_timeout; | 145 | goto L_timeout; |
146 | 146 | ||
147 | __i2c_send_nack(); /* Master does not send ACK, slave sends it */ | 147 | __i2c_send_nack(); /* Master does not send ACK, slave sends it */ |
148 | 148 | ||
149 | __i2c_send_start(); | 149 | __i2c_send_start(); |
150 | if (i2c_put_data( (device << 1) | I2C_READ ) < 0) | 150 | if (i2c_put_data( (device << 1) | I2C_READ ) < 0) |
151 | goto device_err; | 151 | goto device_err; |
152 | 152 | ||
153 | __i2c_send_ack(); /* Master sends ACK for continue reading */ | 153 | __i2c_send_ack(); /* Master sends ACK for continue reading */ |
154 | 154 | ||
155 | while (cnt) | 155 | while (cnt) |
156 | { | 156 | { |
157 | if (cnt == 1) | 157 | if (cnt == 1) |
@@ -170,7 +170,7 @@ L_try_again: | |||
170 | 170 | ||
171 | __i2c_send_stop(); | 171 | __i2c_send_stop(); |
172 | return count - cnt; | 172 | return count - cnt; |
173 | 173 | ||
174 | device_err: | 174 | device_err: |
175 | timeout--; | 175 | timeout--; |
176 | __i2c_send_stop(); | 176 | __i2c_send_stop(); |
@@ -179,6 +179,7 @@ device_err: | |||
179 | L_timeout: | 179 | L_timeout: |
180 | __i2c_send_stop(); | 180 | __i2c_send_stop(); |
181 | logf("Read I2C device 0x%2x failed.", device); | 181 | logf("Read I2C device 0x%2x failed.", device); |
182 | i2c_close(); | ||
182 | return -1; | 183 | return -1; |
183 | } | 184 | } |
184 | 185 | ||
@@ -186,9 +187,11 @@ int i2c_write(int device, unsigned char *buf, int count) | |||
186 | { | 187 | { |
187 | int cnt = count; | 188 | int cnt = count; |
188 | int timeout = 5; | 189 | int timeout = 5; |
189 | 190 | ||
190 | device &= 0xFF; | 191 | device &= 0xFF; |
191 | 192 | ||
193 | i2c_open(); | ||
194 | |||
192 | __i2c_send_nack(); /* Master does not send ACK, slave sends it */ | 195 | __i2c_send_nack(); /* Master does not send ACK, slave sends it */ |
193 | 196 | ||
194 | W_try_again: | 197 | W_try_again: |
@@ -200,7 +203,7 @@ W_try_again: | |||
200 | __i2c_send_start(); | 203 | __i2c_send_start(); |
201 | if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0) | 204 | if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0) |
202 | goto device_err; | 205 | goto device_err; |
203 | 206 | ||
204 | #if 0 //CONFIG_JZ_TPANEL_ATA2508 | 207 | #if 0 //CONFIG_JZ_TPANEL_ATA2508 |
205 | if (address == 0xff) | 208 | if (address == 0xff) |
206 | { | 209 | { |
@@ -226,7 +229,7 @@ W_try_again: | |||
226 | 229 | ||
227 | __i2c_send_stop(); | 230 | __i2c_send_stop(); |
228 | return count - cnt; | 231 | return count - cnt; |
229 | 232 | ||
230 | device_err: | 233 | device_err: |
231 | timeout--; | 234 | timeout--; |
232 | __i2c_send_stop(); | 235 | __i2c_send_stop(); |
@@ -235,6 +238,7 @@ device_err: | |||
235 | W_timeout: | 238 | W_timeout: |
236 | logf("Write I2C device 0x%2x failed.", device); | 239 | logf("Write I2C device 0x%2x failed.", device); |
237 | __i2c_send_stop(); | 240 | __i2c_send_stop(); |
241 | i2c_close(); | ||
238 | return -1; | 242 | return -1; |
239 | } | 243 | } |
240 | 244 | ||