1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
31 static int mas_devread(unsigned long *dest
, int len
);
33 int mas_default_read(unsigned short *buf
)
35 unsigned char *dest
= (unsigned char *)buf
;
41 i2c_outb(MAS_DEV_WRITE
);
43 i2c_outb(MAS_DATA_READ
);
46 i2c_outb(MAS_DEV_READ
);
66 int mas_run(unsigned short address
)
73 buf
[0] = MAS_DATA_WRITE
;
74 buf
[1] = address
>> 8;
75 buf
[2] = address
& 0xff;
77 /* send run command */
78 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
87 /* note: 'len' is number of 32-bit words, not number of bytes! */
88 int mas_readmem(int bank
, int addr
, unsigned long* dest
, int len
)
95 buf
[0] = MAS_DATA_WRITE
;
96 buf
[1] = bank
?MAS_CMD_READ_D1_MEM
:MAS_CMD_READ_D0_MEM
;
98 buf
[3] = (len
& 0xff00) >> 8;
100 buf
[5] = (addr
& 0xff00) >> 8;
101 buf
[6] = addr
& 0xff;
103 /* send read command */
104 if (i2c_write(MAS_DEV_WRITE
,buf
,7))
109 ret
= mas_devread(dest
, len
);
115 /* note: 'len' is number of 32-bit words, not number of bytes! */
116 int mas_writemem(int bank
, int addr
, const unsigned long* src
, int len
)
120 unsigned char buf
[60];
121 const unsigned char* ptr
= (const unsigned char*)src
;
126 buf
[i
++] = MAS_DATA_WRITE
;
127 buf
[i
++] = bank
?MAS_CMD_WRITE_D1_MEM
:MAS_CMD_WRITE_D0_MEM
;
129 buf
[i
++] = (len
& 0xff00) >> 8;
130 buf
[i
++] = len
& 0xff;
131 buf
[i
++] = (addr
& 0xff00) >> 8;
132 buf
[i
++] = addr
& 0xff;
136 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
150 /* send write command */
151 if (i2c_write(MAS_DEV_WRITE
,buf
,i
))
160 int mas_readreg(int reg
)
163 unsigned char buf
[16];
168 buf
[0] = MAS_DATA_WRITE
;
169 buf
[1] = MAS_CMD_READ_REG
| (reg
>> 4);
170 buf
[2] = (reg
& 0x0f) << 4;
172 /* send read command */
173 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
179 if(mas_devread(&value
, 1))
193 int mas_writereg(int reg
, unsigned int val
)
196 unsigned char buf
[5];
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;
207 buf
[2] = ((reg
& 0x0f) << 4) | (val
& 0x0f);
208 buf
[3] = (val
>> 12) & 0xff;
209 buf
[4] = (val
>> 4) & 0xff;
212 /* send write command */
213 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
222 /* note: 'len' is number of 32-bit words, not number of bytes! */
223 static int mas_devread(unsigned long *dest
, int len
)
226 unsigned char* ptr
= (unsigned char*)dest
;
229 /* handle read-back */
230 /* Remember, the MAS values are only 20 bits, so we set
231 the upper 12 bits to 0 */
233 i2c_outb(MAS_DEV_WRITE
);
235 i2c_outb(MAS_DATA_READ
);
238 i2c_outb(MAS_DEV_READ
);
242 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
243 i2c_inb(0); /* Dummy read */
245 ptr
[i
*4+1] = i2c_inb(0) & 0x0f;
246 ptr
[i
*4+2] = i2c_inb(0);
248 ptr
[i
*4+3] = i2c_inb(0);
250 ptr
[i
*4+3] = i2c_inb(1); /* NAK the last byte */
252 ptr
[i
*4+2] = i2c_inb(0);
253 ptr
[i
*4+3] = i2c_inb(0);
254 ptr
[i
*4+0] = i2c_inb(0);
256 ptr
[i
*4+1] = i2c_inb(0);
258 ptr
[i
*4+1] = i2c_inb(1); /* NAK the last byte */
280 #if CONFIG_CODEC == MAS3507D
281 /* PB5 is "MAS enable". make it GPIO output and high */
286 and_b(~0x01, &PADRH
);
290 #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
291 if (HW_MASK
& ATA_ADDRESS_200
)
293 and_b(~0x01, &PADRH
);
300 /* Older recorder models don't invert the POR signal */
303 and_b(~0x01, &PADRH
);
309 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
310 int mas_direct_config_read(unsigned char reg
)
313 unsigned char tmp
[2];
318 i2c_outb(MAS_DEV_WRITE
);
323 i2c_outb(MAS_DEV_READ
);
326 tmp
[1] = i2c_inb(1); /* NAK the last byte */
327 ret
= (tmp
[0] << 8) | tmp
[1];
344 int mas_direct_config_write(unsigned char reg
, unsigned int val
)
347 unsigned char buf
[3];
352 buf
[1] = (val
>> 8) & 0xff;
355 /* send write command */
356 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
365 int mas_codec_writereg(int reg
, unsigned int val
)
368 unsigned char buf
[5];
372 buf
[0] = MAS_CODEC_WRITE
;
373 buf
[1] = (reg
>> 8) & 0xff;
375 buf
[3] = (val
>> 8) & 0xff;
378 /* send write command */
379 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
388 int mas_codec_readreg(int reg
)
391 unsigned char buf
[16];
392 unsigned char tmp
[2];
396 buf
[0] = MAS_CODEC_WRITE
;
397 buf
[1] = (reg
>> 8) & 0xff;
400 /* send read command */
401 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
408 i2c_outb(MAS_DEV_WRITE
);
410 i2c_outb(MAS_CODEC_READ
);
413 i2c_outb(MAS_DEV_READ
);
416 tmp
[1] = i2c_inb(1); /* NAK the last byte */
417 ret
= (tmp
[0] << 8) | tmp
[1];
435 unsigned long mas_readver(void)
438 unsigned char buf
[16];
443 buf
[0] = MAS_DATA_WRITE
;
444 buf
[1] = MAS_CMD_READ_IC_VER
;
447 /* send read command */
448 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
454 if(mas_devread(&value
, 1))
470 #if CONFIG_TUNER & S1A0903X01
473 void mas_store_pllfreq(int freq
)
478 int mas_get_pllfreq(void)