summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-24 12:35:37 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-24 12:35:37 +0000
commite1cb054fa0bebd10b40156e4b0318d233ca11d8f (patch)
treef6442d6cd4d8e9add63769455c67db6ea2b7a03d
parentb38c2d996d339a68f33a8b681cce359a86f65bcf (diff)
downloadrockbox-e1cb054fa0bebd10b40156e4b0318d233ca11d8f.tar.gz
rockbox-e1cb054fa0bebd10b40156e4b0318d233ca11d8f.zip
Now uses i2c_begin/end
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1147 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/dac.c38
-rw-r--r--firmware/drivers/mas.c172
2 files changed, 127 insertions, 83 deletions
diff --git a/firmware/drivers/dac.c b/firmware/drivers/dac.c
index c968246a61..63695c3c67 100644
--- a/firmware/drivers/dac.c
+++ b/firmware/drivers/dac.c
@@ -22,23 +22,26 @@
22 22
23int dac_volume(unsigned int volume) 23int dac_volume(unsigned int volume)
24{ 24{
25 int i; 25 int ret = 0;
26 unsigned char buf[16]; 26 unsigned char buf[3];
27
28 i2c_begin();
27 29
28 if(volume > 0x38) 30 if(volume > 0x38)
29 volume = 0x38; 31 volume = 0x38;
30 32
31 i=0; 33 buf[0] = DAC_REG_WRITE | DAC_AVOL;
32 buf[i++] = DAC_REG_WRITE | DAC_AVOL; 34 buf[1] = (volume & 0x3f) | 0x40; /* Deemphasis ON */
33 buf[i++] = (volume & 0x3f) | 0x40; /* Deemphasis ON */ 35 buf[2] = volume & 0x3f;
34 buf[i++] = volume & 0x3f;
35 36
36 /* send read command */ 37 /* send read command */
37 if (i2c_write(DAC_DEV_WRITE,buf,i)) 38 if (i2c_write(DAC_DEV_WRITE,buf,3))
38 { 39 {
39 return -1; 40 ret = -1;
40 } 41 }
41 return 0; 42
43 i2c_end();
44 return ret;
42} 45}
43 46
44/****************************************************************** 47/******************************************************************
@@ -52,17 +55,20 @@ int dac_volume(unsigned int volume)
52******************************************************************/ 55******************************************************************/
53int dac_config(int value) 56int dac_config(int value)
54{ 57{
55 int i; 58 int ret = 0;
56 unsigned char buf[16]; 59 unsigned char buf[2];
57 60
58 i=0; 61 i2c_begin();
59 buf[i++] = DAC_REG_WRITE | DAC_GCFG; 62
60 buf[i++] = value; 63 buf[0] = DAC_REG_WRITE | DAC_GCFG;
64 buf[1] = value;
61 65
62 /* send read command */ 66 /* send read command */
63 if (i2c_write(DAC_DEV_WRITE,buf,i)) 67 if (i2c_write(DAC_DEV_WRITE,buf,2))
64 { 68 {
65 return -1; 69 ret = -1;
66 } 70 }
71
72 i2c_end();
67 return 0; 73 return 0;
68} 74}
diff --git a/firmware/drivers/mas.c b/firmware/drivers/mas.c
index 86a188d42b..c8082c8a2a 100644
--- a/firmware/drivers/mas.c
+++ b/firmware/drivers/mas.c
@@ -20,10 +20,14 @@
20#include "debug.h" 20#include "debug.h"
21#include "mas.h" 21#include "mas.h"
22 22
23static int mas_devread(unsigned long *dest, int len);
24
23int mas_default_read(unsigned short *buf) 25int mas_default_read(unsigned short *buf)
24{ 26{
25 unsigned char *dest = (unsigned char *)buf; 27 unsigned char *dest = (unsigned char *)buf;
26 int ret = 0; 28 int ret = 0;
29
30 i2c_begin();
27 31
28 i2c_start(); 32 i2c_start();
29 i2c_outb(MAS_DEV_WRITE); 33 i2c_outb(MAS_DEV_WRITE);
@@ -47,59 +51,69 @@ int mas_default_read(unsigned short *buf)
47 51
48 i2c_stop(); 52 i2c_stop();
49 53
54 i2c_end();
50 return ret; 55 return ret;
51} 56}
52 57
53int mas_run(unsigned short address) 58int mas_run(unsigned short address)
54{ 59{
55 int i; 60 int ret = 0;
56 unsigned char buf[16]; 61 unsigned char buf[3];
57 62
58 i=0; 63 i2c_begin();
59 buf[i++] = MAS_DATA_WRITE; 64
60 buf[i++] = address << 8; 65 buf[0] = MAS_DATA_WRITE;
61 buf[i++] = address & 0xff; 66 buf[1] = address << 8;
67 buf[2] = address & 0xff;
62 68
63 /* send run command */ 69 /* send run command */
64 if (i2c_write(MAS_DEV_WRITE,buf,i)) 70 if (i2c_write(MAS_DEV_WRITE,buf,3))
65 { 71 {
66 return -1; 72 ret = -1;
67 } 73 }
68 74
69 return 0; 75 i2c_end();
76 return ret;
70} 77}
71 78
72/* note: 'len' is number of 32-bit words, not number of bytes! */ 79/* note: 'len' is number of 32-bit words, not number of bytes! */
73int mas_readmem(int bank, int addr, unsigned long* dest, int len) 80int mas_readmem(int bank, int addr, unsigned long* dest, int len)
74{ 81{
75 int i; 82 int ret = 0;
76 unsigned char buf[16]; 83 unsigned char buf[7];
77 84
78 i=0; 85 i2c_begin();
79 buf[i++] = MAS_DATA_WRITE; 86
80 buf[i++] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM; 87 buf[0] = MAS_DATA_WRITE;
81 buf[i++] = 0x00; 88 buf[1] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM;
82 buf[i++] = (len & 0xff00) >> 8; 89 buf[2] = 0x00;
83 buf[i++] = len & 0xff; 90 buf[3] = (len & 0xff00) >> 8;
84 buf[i++] = (addr & 0xff00) >> 8; 91 buf[4] = len & 0xff;
85 buf[i++] = addr & 0xff; 92 buf[5] = (addr & 0xff00) >> 8;
93 buf[6] = addr & 0xff;
86 94
87 /* send read command */ 95 /* send read command */
88 if (i2c_write(MAS_DEV_WRITE,buf,i)) 96 if (i2c_write(MAS_DEV_WRITE,buf,7))
89 { 97 {
90 return -1; 98 ret = -1;
91 } 99 }
92 100
93 return mas_devread(dest, len); 101 ret = mas_devread(dest, len);
102
103 i2c_end();
104 return ret;
94} 105}
95 106
96/* note: 'len' is number of 32-bit words, not number of bytes! */ 107/* note: 'len' is number of 32-bit words, not number of bytes! */
97int mas_writemem(int bank, int addr, unsigned long* src, int len) 108int mas_writemem(int bank, int addr, unsigned long* src, int len)
98{ 109{
110 int ret = 0;
99 int i, j; 111 int i, j;
100 unsigned char buf[60]; 112 unsigned char buf[60];
101 unsigned char* ptr = (unsigned char*)src; 113 unsigned char* ptr = (unsigned char*)src;
102 114
115 i2c_begin();
116
103 i=0; 117 i=0;
104 buf[i++] = MAS_DATA_WRITE; 118 buf[i++] = MAS_DATA_WRITE;
105 buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM; 119 buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM;
@@ -128,62 +142,74 @@ int mas_writemem(int bank, int addr, unsigned long* src, int len)
128 /* send write command */ 142 /* send write command */
129 if (i2c_write(MAS_DEV_WRITE,buf,i)) 143 if (i2c_write(MAS_DEV_WRITE,buf,i))
130 { 144 {
131 return -1; 145 ret = -1;
132 } 146 }
133 147
134 return 0; 148 i2c_end();
149 return ret;
135} 150}
136 151
137int mas_readreg(int reg) 152int mas_readreg(int reg)
138{ 153{
139 int i; 154 int ret = 0;
140 unsigned char buf[16]; 155 unsigned char buf[16];
141 unsigned long value; 156 unsigned long value;
142 157
143 i=0; 158 i2c_begin();
144 buf[i++] = MAS_DATA_WRITE; 159
145 buf[i++] = MAS_CMD_READ_REG | (reg >> 4); 160 buf[0] = MAS_DATA_WRITE;
146 buf[i++] = (reg & 0x0f) << 4; 161 buf[1] = MAS_CMD_READ_REG | (reg >> 4);
162 buf[2] = (reg & 0x0f) << 4;
147 163
148 /* send read command */ 164 /* send read command */
149 if (i2c_write(MAS_DEV_WRITE,buf,i)) 165 if (i2c_write(MAS_DEV_WRITE,buf,3))
150 { 166 {
151 return -1; 167 ret = -1;
152 } 168 }
153 169 else
154 if(mas_devread(&value, 1))
155 { 170 {
156 return -2; 171 if(mas_devread(&value, 1))
172 {
173 ret = -2;
174 }
175 else
176 {
177 ret = value;
178 }
157 } 179 }
158 180
159 return value; 181 i2c_end();
182 return ret;
160} 183}
161 184
162int mas_writereg(int reg, unsigned int val) 185int mas_writereg(int reg, unsigned int val)
163{ 186{
164 int i; 187 int ret = 0;
165 unsigned char buf[16]; 188 unsigned char buf[5];
166 189
167 i=0; 190 i2c_begin();
168 buf[i++] = MAS_DATA_WRITE; 191
169 buf[i++] = MAS_CMD_WRITE_REG | (reg >> 4); 192 buf[0] = MAS_DATA_WRITE;
170 buf[i++] = ((reg & 0x0f) << 4) | (val & 0x0f); 193 buf[1] = MAS_CMD_WRITE_REG | (reg >> 4);
171 buf[i++] = (val >> 12) & 0xff; 194 buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f);
172 buf[i++] = (val >> 4) & 0xff; 195 buf[3] = (val >> 12) & 0xff;
196 buf[4] = (val >> 4) & 0xff;
173 197
174 /* send write command */ 198 /* send write command */
175 if (i2c_write(MAS_DEV_WRITE,buf,i)) 199 if (i2c_write(MAS_DEV_WRITE,buf,5))
176 { 200 {
177 return -1; 201 ret = -1;
178 } 202 }
179 return 0; 203
204 i2c_end();
205 return ret;
180} 206}
181 207
182/* note: 'len' is number of 32-bit words, not number of bytes! */ 208/* note: 'len' is number of 32-bit words, not number of bytes! */
183int mas_devread(unsigned long *dest, int len) 209static int mas_devread(unsigned long *dest, int len)
184{ 210{
185 unsigned char* ptr = (unsigned char*)dest;
186 int ret = 0; 211 int ret = 0;
212 unsigned char* ptr = (unsigned char*)dest;
187 int i; 213 int i;
188 214
189 /* handle read-back */ 215 /* handle read-back */
@@ -236,9 +262,11 @@ int mas_devread(unsigned long *dest, int len)
236#ifdef ARCHOS_RECORDER 262#ifdef ARCHOS_RECORDER
237int mas_direct_config_read(unsigned char reg) 263int mas_direct_config_read(unsigned char reg)
238{ 264{
239 unsigned char tmp[2];
240 int ret = 0; 265 int ret = 0;
266 unsigned char tmp[2];
241 267
268 i2c_begin();
269
242 i2c_start(); 270 i2c_start();
243 i2c_outb(MAS_DEV_WRITE); 271 i2c_outb(MAS_DEV_WRITE);
244 if (i2c_getack()) { 272 if (i2c_getack()) {
@@ -262,13 +290,17 @@ int mas_direct_config_read(unsigned char reg)
262 290
263 i2c_stop(); 291 i2c_stop();
264 292
293 i2c_end();
265 return ret; 294 return ret;
266} 295}
267 296
268int mas_direct_config_write(unsigned char reg, unsigned int val) 297int mas_direct_config_write(unsigned char reg, unsigned int val)
269{ 298{
299 int ret = 0;
270 unsigned char buf[3]; 300 unsigned char buf[3];
271 301
302 i2c_begin();
303
272 buf[0] = reg; 304 buf[0] = reg;
273 buf[1] = (val >> 8) & 0xff; 305 buf[1] = (val >> 8) & 0xff;
274 buf[2] = val & 0xff; 306 buf[2] = val & 0xff;
@@ -276,45 +308,50 @@ int mas_direct_config_write(unsigned char reg, unsigned int val)
276 /* send write command */ 308 /* send write command */
277 if (i2c_write(MAS_DEV_WRITE,buf,3)) 309 if (i2c_write(MAS_DEV_WRITE,buf,3))
278 { 310 {
279 return -1; 311 ret = -1;
280 } 312 }
313
314 i2c_end();
281 return 0; 315 return 0;
282} 316}
283 317
284int mas_codec_writereg(int reg, unsigned int val) 318int mas_codec_writereg(int reg, unsigned int val)
285{ 319{
286 int i; 320 int ret = 0;
287 unsigned char buf[16]; 321 unsigned char buf[5];
288 322
289 i=0; 323 i2c_begin();
290 buf[i++] = MAS_CODEC_WRITE; 324
291 buf[i++] = (reg >> 8) & 0xff; 325 buf[0] = MAS_CODEC_WRITE;
292 buf[i++] = reg & 0xff; 326 buf[1] = (reg >> 8) & 0xff;
293 buf[i++] = (val >> 8) & 0xff; 327 buf[2] = reg & 0xff;
294 buf[i++] = val & 0xff; 328 buf[3] = (val >> 8) & 0xff;
329 buf[4] = val & 0xff;
295 330
296 /* send write command */ 331 /* send write command */
297 if (i2c_write(MAS_DEV_WRITE,buf,i)) 332 if (i2c_write(MAS_DEV_WRITE,buf,5))
298 { 333 {
299 return -1; 334 ret = -1;
300 } 335 }
301 return 0; 336
337 i2c_end();
338 return ret;
302} 339}
303 340
304int mas_codec_readreg(int reg) 341int mas_codec_readreg(int reg)
305{ 342{
306 int i;
307 int ret = 0; 343 int ret = 0;
308 unsigned char buf[16]; 344 unsigned char buf[16];
309 unsigned char tmp[2]; 345 unsigned char tmp[2];
310 346
311 i=0; 347 i2c_begin();
312 buf[i++] = MAS_CODEC_WRITE; 348
313 buf[i++] = (reg >> 8) & 0xff; 349 buf[0] = MAS_CODEC_WRITE;
314 buf[i++] = reg & 0xff; 350 buf[1] = (reg >> 8) & 0xff;
351 buf[2] = reg & 0xff;
315 352
316 /* send read command */ 353 /* send read command */
317 if (i2c_write(MAS_DEV_WRITE,buf,i)) 354 if (i2c_write(MAS_DEV_WRITE,buf,3))
318 { 355 {
319 return -1; 356 return -1;
320 } 357 }
@@ -342,6 +379,7 @@ int mas_codec_readreg(int reg)
342 379
343 i2c_stop(); 380 i2c_stop();
344 381
382 i2c_end();
345 return ret; 383 return ret;
346} 384}
347#endif 385#endif