1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
28 extern bool old_recorder
;
30 static int mas_devread(unsigned long *dest
, int len
);
32 int mas_default_read(unsigned short *buf
)
34 unsigned char *dest
= (unsigned char *)buf
;
40 i2c_outb(MAS_DEV_WRITE
);
42 i2c_outb(MAS_DATA_READ
);
45 i2c_outb(MAS_DEV_READ
);
65 int mas_run(unsigned short address
)
72 buf
[0] = MAS_DATA_WRITE
;
73 buf
[1] = address
>> 8;
74 buf
[2] = address
& 0xff;
76 /* send run command */
77 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
86 /* note: 'len' is number of 32-bit words, not number of bytes! */
87 int mas_readmem(int bank
, int addr
, unsigned long* dest
, int len
)
94 buf
[0] = MAS_DATA_WRITE
;
95 buf
[1] = bank
?MAS_CMD_READ_D1_MEM
:MAS_CMD_READ_D0_MEM
;
97 buf
[3] = (len
& 0xff00) >> 8;
99 buf
[5] = (addr
& 0xff00) >> 8;
100 buf
[6] = addr
& 0xff;
102 /* send read command */
103 if (i2c_write(MAS_DEV_WRITE
,buf
,7))
108 ret
= mas_devread(dest
, len
);
114 /* note: 'len' is number of 32-bit words, not number of bytes! */
115 int mas_writemem(int bank
, int addr
, const unsigned long* src
, int len
)
119 unsigned char buf
[60];
120 const unsigned char* ptr
= (const unsigned char*)src
;
125 buf
[i
++] = MAS_DATA_WRITE
;
126 buf
[i
++] = bank
?MAS_CMD_WRITE_D1_MEM
:MAS_CMD_WRITE_D0_MEM
;
128 buf
[i
++] = (len
& 0xff00) >> 8;
129 buf
[i
++] = len
& 0xff;
130 buf
[i
++] = (addr
& 0xff00) >> 8;
131 buf
[i
++] = addr
& 0xff;
135 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
149 /* send write command */
150 if (i2c_write(MAS_DEV_WRITE
,buf
,i
))
159 int mas_readreg(int reg
)
162 unsigned char buf
[16];
167 buf
[0] = MAS_DATA_WRITE
;
168 buf
[1] = MAS_CMD_READ_REG
| (reg
>> 4);
169 buf
[2] = (reg
& 0x0f) << 4;
171 /* send read command */
172 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
178 if(mas_devread(&value
, 1))
192 int mas_writereg(int reg
, unsigned int val
)
195 unsigned char buf
[5];
199 buf
[0] = MAS_DATA_WRITE
;
200 buf
[1] = MAS_CMD_WRITE_REG
| (reg
>> 4);
201 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
202 buf
[2] = ((reg
& 0x0f) << 4) | (val
>> 16 & 0x0f);
203 buf
[3] = (val
>> 8) & 0xff;
206 buf
[2] = ((reg
& 0x0f) << 4) | (val
& 0x0f);
207 buf
[3] = (val
>> 12) & 0xff;
208 buf
[4] = (val
>> 4) & 0xff;
211 /* send write command */
212 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
221 /* note: 'len' is number of 32-bit words, not number of bytes! */
222 static int mas_devread(unsigned long *dest
, int len
)
225 unsigned char* ptr
= (unsigned char*)dest
;
228 /* handle read-back */
229 /* Remember, the MAS values are only 20 bits, so we set
230 the upper 12 bits to 0 */
232 i2c_outb(MAS_DEV_WRITE
);
234 i2c_outb(MAS_DATA_READ
);
237 i2c_outb(MAS_DEV_READ
);
241 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
242 i2c_inb(0); /* Dummy read */
244 ptr
[i
*4+1] = i2c_inb(0) & 0x0f;
245 ptr
[i
*4+2] = i2c_inb(0);
247 ptr
[i
*4+3] = i2c_inb(0);
249 ptr
[i
*4+3] = i2c_inb(1); /* NAK the last byte */
251 ptr
[i
*4+2] = i2c_inb(0);
252 ptr
[i
*4+3] = i2c_inb(0);
253 ptr
[i
*4+0] = i2c_inb(0);
255 ptr
[i
*4+1] = i2c_inb(0);
257 ptr
[i
*4+1] = i2c_inb(1); /* NAK the last byte */
279 #if CONFIG_CODEC == MAS3507D
280 /* PB5 is "MAS enable". make it GPIO output and high */
285 and_b(~0x01, &PADRH
);
289 #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
292 /* Older recorder models don't invert the POR signal */
295 and_b(~0x01, &PADRH
);
300 and_b(~0x01, &PADRH
);
308 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
309 int mas_direct_config_read(unsigned char reg
)
312 unsigned char tmp
[2];
317 i2c_outb(MAS_DEV_WRITE
);
322 i2c_outb(MAS_DEV_READ
);
325 tmp
[1] = i2c_inb(1); /* NAK the last byte */
326 ret
= (tmp
[0] << 8) | tmp
[1];
343 int mas_direct_config_write(unsigned char reg
, unsigned int val
)
346 unsigned char buf
[3];
351 buf
[1] = (val
>> 8) & 0xff;
354 /* send write command */
355 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
364 int mas_codec_writereg(int reg
, unsigned int val
)
367 unsigned char buf
[5];
371 buf
[0] = MAS_CODEC_WRITE
;
372 buf
[1] = (reg
>> 8) & 0xff;
374 buf
[3] = (val
>> 8) & 0xff;
377 /* send write command */
378 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
387 int mas_codec_readreg(int reg
)
390 unsigned char buf
[16];
391 unsigned char tmp
[2];
395 buf
[0] = MAS_CODEC_WRITE
;
396 buf
[1] = (reg
>> 8) & 0xff;
399 /* send read command */
400 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
407 i2c_outb(MAS_DEV_WRITE
);
409 i2c_outb(MAS_CODEC_READ
);
412 i2c_outb(MAS_DEV_READ
);
415 tmp
[1] = i2c_inb(1); /* NAK the last byte */
416 ret
= (tmp
[0] << 8) | tmp
[1];
434 unsigned long mas_readver(void)
437 unsigned char buf
[16];
442 buf
[0] = MAS_DATA_WRITE
;
443 buf
[1] = MAS_CMD_READ_IC_VER
;
446 /* send read command */
447 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
453 if(mas_devread(&value
, 1))