summaryrefslogtreecommitdiff
path: root/firmware/drivers/mas.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2010-10-31 21:09:34 +0000
committerMarcin Bukat <marcin.bukat@gmail.com>2010-10-31 21:09:34 +0000
commit56c4e9fa600557242d8b78f5fd8e32c2245b76fc (patch)
treef8558778a302f89c3e819e66e86577a5e37c3660 /firmware/drivers/mas.c
parent40ed5f57d9be61f1200026e9b0f944a9718111c1 (diff)
downloadrockbox-56c4e9fa600557242d8b78f5fd8e32c2245b76fc.tar.gz
rockbox-56c4e9fa600557242d8b78f5fd8e32c2245b76fc.zip
Separate mas35xx lowlevel stuff. Move SH specific bits to target tree. FS#11189 by me.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28425 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/mas.c')
-rw-r--r--firmware/drivers/mas.c485
1 files changed, 0 insertions, 485 deletions
diff --git a/firmware/drivers/mas.c b/firmware/drivers/mas.c
deleted file mode 100644
index 4f384d3b98..0000000000
--- a/firmware/drivers/mas.c
+++ /dev/null
@@ -1,485 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "stdbool.h"
22#include "config.h"
23#include "sh7034.h"
24#include "i2c.h"
25#include "debug.h"
26#include "mas.h"
27#include "kernel.h"
28#include "system.h"
29#include "hwcompat.h"
30
31static int mas_devread(unsigned long *dest, int len);
32
33int mas_default_read(unsigned short *buf)
34{
35 unsigned char *dest = (unsigned char *)buf;
36 int ret = 0;
37
38 i2c_begin();
39
40 i2c_start();
41 i2c_outb(MAS_DEV_WRITE);
42 if (i2c_getack()) {
43 i2c_outb(MAS_DATA_READ);
44 if (i2c_getack()) {
45 i2c_start();
46 i2c_outb(MAS_DEV_READ);
47 if (i2c_getack()) {
48 dest[0] = i2c_inb(0);
49 dest[1] = i2c_inb(1);
50 }
51 else
52 ret = -3;
53 }
54 else
55 ret = -2;
56 }
57 else
58 ret = -1;
59
60 i2c_stop();
61
62 i2c_end();
63 return ret;
64}
65
66int mas_run(unsigned short address)
67{
68 int ret = 0;
69 unsigned char buf[3];
70
71 i2c_begin();
72
73 buf[0] = MAS_DATA_WRITE;
74 buf[1] = address >> 8;
75 buf[2] = address & 0xff;
76
77 /* send run command */
78 if (i2c_write(MAS_DEV_WRITE,buf,3))
79 {
80 ret = -1;
81 }
82
83 i2c_end();
84 return ret;
85}
86
87/* note: 'len' is number of 32-bit words, not number of bytes! */
88int mas_readmem(int bank, int addr, unsigned long* dest, int len)
89{
90 int ret = 0;
91 unsigned char buf[7];
92
93 i2c_begin();
94
95 buf[0] = MAS_DATA_WRITE;
96 buf[1] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM;
97 buf[2] = 0x00;
98 buf[3] = (len & 0xff00) >> 8;
99 buf[4] = len & 0xff;
100 buf[5] = (addr & 0xff00) >> 8;
101 buf[6] = addr & 0xff;
102
103 /* send read command */
104 if (i2c_write(MAS_DEV_WRITE,buf,7))
105 {
106 ret = -1;
107 }
108
109 ret = mas_devread(dest, len);
110
111 i2c_end();
112 return ret;
113}
114
115/* note: 'len' is number of 32-bit words, not number of bytes! */
116int mas_writemem(int bank, int addr, const unsigned long* src, int len)
117{
118 int ret = 0;
119 int i, j;
120 unsigned char buf[60];
121 const unsigned char* ptr = (const unsigned char*)src;
122
123 i2c_begin();
124
125 i=0;
126 buf[i++] = MAS_DATA_WRITE;
127 buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM;
128 buf[i++] = 0x00;
129 buf[i++] = (len & 0xff00) >> 8;
130 buf[i++] = len & 0xff;
131 buf[i++] = (addr & 0xff00) >> 8;
132 buf[i++] = addr & 0xff;
133
134 j = 0;
135 while(len--) {
136#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
137 buf[i++] = 0;
138 buf[i++] = ptr[j+1];
139 buf[i++] = ptr[j+2];
140 buf[i++] = ptr[j+3];
141#else
142 buf[i++] = ptr[j+2];
143 buf[i++] = ptr[j+3];
144 buf[i++] = 0;
145 buf[i++] = ptr[j+1];
146#endif
147 j += 4;
148 }
149
150 /* send write command */
151 if (i2c_write(MAS_DEV_WRITE,buf,i))
152 {
153 ret = -1;
154 }
155
156 i2c_end();
157 return ret;
158}
159
160int mas_readreg(int reg)
161{
162 int ret = 0;
163 unsigned char buf[16];
164 unsigned long value;
165
166 i2c_begin();
167
168 buf[0] = MAS_DATA_WRITE;
169 buf[1] = MAS_CMD_READ_REG | (reg >> 4);
170 buf[2] = (reg & 0x0f) << 4;
171
172 /* send read command */
173 if (i2c_write(MAS_DEV_WRITE,buf,3))
174 {
175 ret = -1;
176 }
177 else
178 {
179 if(mas_devread(&value, 1))
180 {
181 ret = -2;
182 }
183 else
184 {
185 ret = value;
186 }
187 }
188
189 i2c_end();
190 return ret;
191}
192
193int mas_writereg(int reg, unsigned int val)
194{
195 int ret = 0;
196 unsigned char buf[5];
197
198 i2c_begin();
199
200 buf[0] = MAS_DATA_WRITE;
201 buf[1] = MAS_CMD_WRITE_REG | (reg >> 4);
202#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
203 buf[2] = ((reg & 0x0f) << 4) | (val >> 16 & 0x0f);
204 buf[3] = (val >> 8) & 0xff;
205 buf[4] = val & 0xff;
206#else
207 buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f);
208 buf[3] = (val >> 12) & 0xff;
209 buf[4] = (val >> 4) & 0xff;
210#endif
211
212 /* send write command */
213 if (i2c_write(MAS_DEV_WRITE,buf,5))
214 {
215 ret = -1;
216 }
217
218 i2c_end();
219 return ret;
220}
221
222/* note: 'len' is number of 32-bit words, not number of bytes! */
223static int mas_devread(unsigned long *dest, int len)
224{
225 int ret = 0;
226 unsigned char* ptr = (unsigned char*)dest;
227 int i;
228
229 /* handle read-back */
230 /* Remember, the MAS values are only 20 bits, so we set
231 the upper 12 bits to 0 */
232 i2c_start();
233 i2c_outb(MAS_DEV_WRITE);
234 if (i2c_getack()) {
235 i2c_outb(MAS_DATA_READ);
236 if (i2c_getack()) {
237 i2c_start();
238 i2c_outb(MAS_DEV_READ);
239 if (i2c_getack()) {
240 for (i=0;len;i++) {
241 len--;
242#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
243 i2c_inb(0); /* Dummy read */
244 ptr[i*4+0] = 0;
245 ptr[i*4+1] = i2c_inb(0) & 0x0f;
246 ptr[i*4+2] = i2c_inb(0);
247 if(len)
248 ptr[i*4+3] = i2c_inb(0);
249 else
250 ptr[i*4+3] = i2c_inb(1); /* NAK the last byte */
251#else
252 ptr[i*4+2] = i2c_inb(0);
253 ptr[i*4+3] = i2c_inb(0);
254 ptr[i*4+0] = i2c_inb(0);
255 if(len)
256 ptr[i*4+1] = i2c_inb(0);
257 else
258 ptr[i*4+1] = i2c_inb(1); /* NAK the last byte */
259#endif
260 }
261 }
262 else
263 ret = -3;
264 }
265 else
266 ret = -2;
267 }
268 else
269 ret = -1;
270
271 i2c_stop();
272
273 return ret;
274}
275
276void mas_reset(void)
277{
278 or_b(0x01, &PAIORH);
279
280#if CONFIG_CODEC == MAS3507D
281 /* PB5 is "MAS enable". make it GPIO output and high */
282 PBCR2 &= ~0x0c00;
283 or_b(0x20, &PBIORL);
284 or_b(0x20, &PBDRL);
285
286 and_b(~0x01, &PADRH);
287 sleep(HZ/100);
288 or_b(0x01, &PADRH);
289 sleep(HZ/5);
290#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
291 if (HW_MASK & ATA_ADDRESS_200)
292 {
293 and_b(~0x01, &PADRH);
294 sleep(HZ/100);
295 or_b(0x01, &PADRH);
296 sleep(HZ/5);
297 }
298 else
299 {
300 /* Older recorder models don't invert the POR signal */
301 or_b(0x01, &PADRH);
302 sleep(HZ/100);
303 and_b(~0x01, &PADRH);
304 sleep(HZ/5);
305 }
306#endif
307}
308
309#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
310int mas_direct_config_read(unsigned char reg)
311{
312 int ret = 0;
313 unsigned char tmp[2];
314
315 i2c_begin();
316
317 i2c_start();
318 i2c_outb(MAS_DEV_WRITE);
319 if (i2c_getack()) {
320 i2c_outb(reg);
321 if (i2c_getack()) {
322 i2c_start();
323 i2c_outb(MAS_DEV_READ);
324 if (i2c_getack()) {
325 tmp[0] = i2c_inb(0);
326 tmp[1] = i2c_inb(1); /* NAK the last byte */
327 ret = (tmp[0] << 8) | tmp[1];
328 }
329 else
330 ret = -3;
331 }
332 else
333 ret = -2;
334 }
335 else
336 ret = -1;
337
338 i2c_stop();
339
340 i2c_end();
341 return ret;
342}
343
344int mas_direct_config_write(unsigned char reg, unsigned int val)
345{
346 int ret = 0;
347 unsigned char buf[3];
348
349 i2c_begin();
350
351 buf[0] = reg;
352 buf[1] = (val >> 8) & 0xff;
353 buf[2] = val & 0xff;
354
355 /* send write command */
356 if (i2c_write(MAS_DEV_WRITE,buf,3))
357 {
358 ret = -1;
359 }
360
361 i2c_end();
362 return ret;
363}
364
365int mas_codec_writereg(int reg, unsigned int val)
366{
367 int ret = 0;
368 unsigned char buf[5];
369
370 i2c_begin();
371
372 buf[0] = MAS_CODEC_WRITE;
373 buf[1] = (reg >> 8) & 0xff;
374 buf[2] = reg & 0xff;
375 buf[3] = (val >> 8) & 0xff;
376 buf[4] = val & 0xff;
377
378 /* send write command */
379 if (i2c_write(MAS_DEV_WRITE,buf,5))
380 {
381 ret = -1;
382 }
383
384 i2c_end();
385 return ret;
386}
387
388int mas_codec_readreg(int reg)
389{
390 int ret = 0;
391 unsigned char buf[16];
392 unsigned char tmp[2];
393
394 i2c_begin();
395
396 buf[0] = MAS_CODEC_WRITE;
397 buf[1] = (reg >> 8) & 0xff;
398 buf[2] = reg & 0xff;
399
400 /* send read command */
401 if (i2c_write(MAS_DEV_WRITE,buf,3))
402 {
403 ret = -1;
404 }
405 else
406 {
407 i2c_start();
408 i2c_outb(MAS_DEV_WRITE);
409 if (i2c_getack()) {
410 i2c_outb(MAS_CODEC_READ);
411 if (i2c_getack()) {
412 i2c_start();
413 i2c_outb(MAS_DEV_READ);
414 if (i2c_getack()) {
415 tmp[0] = i2c_inb(0);
416 tmp[1] = i2c_inb(1); /* NAK the last byte */
417 ret = (tmp[0] << 8) | tmp[1];
418 }
419 else
420 ret = -4;
421 }
422 else
423 ret = -3;
424 }
425 else
426 ret = -2;
427
428 i2c_stop();
429 }
430
431 i2c_end();
432 return ret;
433}
434
435unsigned long mas_readver(void)
436{
437 int ret = 0;
438 unsigned char buf[16];
439 unsigned long value;
440
441 i2c_begin();
442
443 buf[0] = MAS_DATA_WRITE;
444 buf[1] = MAS_CMD_READ_IC_VER;
445 buf[2] = 0;
446
447 /* send read command */
448 if (i2c_write(MAS_DEV_WRITE,buf,3))
449 {
450 ret = -1;
451 }
452 else
453 {
454 if(mas_devread(&value, 1))
455 {
456 ret = -2;
457 }
458 else
459 {
460 ret = value;
461 }
462 }
463
464 i2c_end();
465 return ret;
466}
467
468#endif
469
470#if CONFIG_TUNER & S1A0903X01
471static int pllfreq;
472
473void mas_store_pllfreq(int freq)
474{
475 pllfreq = freq;
476}
477
478int mas_get_pllfreq(void)
479{
480 return pllfreq;
481}
482#endif
483
484
485