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 ****************************************************************************/
29 static int mas_devread(unsigned long *dest
, int len
);
31 int mas_default_read(unsigned short *buf
)
33 unsigned char *dest
= (unsigned char *)buf
;
39 i2c_outb(MAS_DEV_WRITE
);
41 i2c_outb(MAS_DATA_READ
);
44 i2c_outb(MAS_DEV_READ
);
64 int mas_run(unsigned short address
)
71 buf
[0] = MAS_DATA_WRITE
;
72 buf
[1] = address
>> 8;
73 buf
[2] = address
& 0xff;
75 /* send run command */
76 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
85 /* note: 'len' is number of 32-bit words, not number of bytes! */
86 int mas_readmem(int bank
, int addr
, unsigned long* dest
, int len
)
93 buf
[0] = MAS_DATA_WRITE
;
94 buf
[1] = bank
?MAS_CMD_READ_D1_MEM
:MAS_CMD_READ_D0_MEM
;
96 buf
[3] = (len
& 0xff00) >> 8;
98 buf
[5] = (addr
& 0xff00) >> 8;
101 /* send read command */
102 if (i2c_write(MAS_DEV_WRITE
,buf
,7))
107 ret
= mas_devread(dest
, len
);
113 /* note: 'len' is number of 32-bit words, not number of bytes! */
114 int mas_writemem(int bank
, int addr
, const unsigned long* src
, int len
)
118 unsigned char buf
[60];
119 const unsigned char* ptr
= (const unsigned char*)src
;
124 buf
[i
++] = MAS_DATA_WRITE
;
125 buf
[i
++] = bank
?MAS_CMD_WRITE_D1_MEM
:MAS_CMD_WRITE_D0_MEM
;
127 buf
[i
++] = (len
& 0xff00) >> 8;
128 buf
[i
++] = len
& 0xff;
129 buf
[i
++] = (addr
& 0xff00) >> 8;
130 buf
[i
++] = addr
& 0xff;
134 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
148 /* send write command */
149 if (i2c_write(MAS_DEV_WRITE
,buf
,i
))
158 int mas_readreg(int reg
)
161 unsigned char buf
[16];
166 buf
[0] = MAS_DATA_WRITE
;
167 buf
[1] = MAS_CMD_READ_REG
| (reg
>> 4);
168 buf
[2] = (reg
& 0x0f) << 4;
170 /* send read command */
171 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
177 if(mas_devread(&value
, 1))
191 int mas_writereg(int reg
, unsigned int val
)
194 unsigned char buf
[5];
198 buf
[0] = MAS_DATA_WRITE
;
199 buf
[1] = MAS_CMD_WRITE_REG
| (reg
>> 4);
200 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
201 buf
[2] = ((reg
& 0x0f) << 4) | (val
>> 16 & 0x0f);
202 buf
[3] = (val
>> 8) & 0xff;
205 buf
[2] = ((reg
& 0x0f) << 4) | (val
& 0x0f);
206 buf
[3] = (val
>> 12) & 0xff;
207 buf
[4] = (val
>> 4) & 0xff;
210 /* send write command */
211 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
220 /* note: 'len' is number of 32-bit words, not number of bytes! */
221 static int mas_devread(unsigned long *dest
, int len
)
224 unsigned char* ptr
= (unsigned char*)dest
;
227 /* handle read-back */
228 /* Remember, the MAS values are only 20 bits, so we set
229 the upper 12 bits to 0 */
231 i2c_outb(MAS_DEV_WRITE
);
233 i2c_outb(MAS_DATA_READ
);
236 i2c_outb(MAS_DEV_READ
);
240 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
241 i2c_inb(0); /* Dummy read */
243 ptr
[i
*4+1] = i2c_inb(0) & 0x0f;
244 ptr
[i
*4+2] = i2c_inb(0);
246 ptr
[i
*4+3] = i2c_inb(0);
248 ptr
[i
*4+3] = i2c_inb(1); /* NAK the last byte */
250 ptr
[i
*4+2] = i2c_inb(0);
251 ptr
[i
*4+3] = i2c_inb(0);
252 ptr
[i
*4+0] = i2c_inb(0);
254 ptr
[i
*4+1] = i2c_inb(0);
256 ptr
[i
*4+1] = i2c_inb(1); /* NAK the last byte */
278 #if CONFIG_CODEC == MAS3507D
279 /* PB5 is "MAS enable". make it GPIO output and high */
284 and_b(~0x01, &PADRH
);
288 #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
289 if (HW_MASK
& ATA_ADDRESS_200
)
291 and_b(~0x01, &PADRH
);
298 /* Older recorder models don't invert the POR signal */
301 and_b(~0x01, &PADRH
);
307 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
308 int mas_direct_config_read(unsigned char reg
)
311 unsigned char tmp
[2];
316 i2c_outb(MAS_DEV_WRITE
);
321 i2c_outb(MAS_DEV_READ
);
324 tmp
[1] = i2c_inb(1); /* NAK the last byte */
325 ret
= (tmp
[0] << 8) | tmp
[1];
342 int mas_direct_config_write(unsigned char reg
, unsigned int val
)
345 unsigned char buf
[3];
350 buf
[1] = (val
>> 8) & 0xff;
353 /* send write command */
354 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
363 int mas_codec_writereg(int reg
, unsigned int val
)
366 unsigned char buf
[5];
370 buf
[0] = MAS_CODEC_WRITE
;
371 buf
[1] = (reg
>> 8) & 0xff;
373 buf
[3] = (val
>> 8) & 0xff;
376 /* send write command */
377 if (i2c_write(MAS_DEV_WRITE
,buf
,5))
386 int mas_codec_readreg(int reg
)
389 unsigned char buf
[16];
390 unsigned char tmp
[2];
394 buf
[0] = MAS_CODEC_WRITE
;
395 buf
[1] = (reg
>> 8) & 0xff;
398 /* send read command */
399 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
406 i2c_outb(MAS_DEV_WRITE
);
408 i2c_outb(MAS_CODEC_READ
);
411 i2c_outb(MAS_DEV_READ
);
414 tmp
[1] = i2c_inb(1); /* NAK the last byte */
415 ret
= (tmp
[0] << 8) | tmp
[1];
433 unsigned long mas_readver(void)
436 unsigned char buf
[16];
441 buf
[0] = MAS_DATA_WRITE
;
442 buf
[1] = MAS_CMD_READ_IC_VER
;
445 /* send read command */
446 if (i2c_write(MAS_DEV_WRITE
,buf
,3))
452 if(mas_devread(&value
, 1))