2002-04-20 23:18:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2011-11-06 22:44:25 +00:00
|
|
|
* $Id$
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-06-26 12:39:49 +00:00
|
|
|
#include "stdbool.h"
|
2002-07-29 09:34:44 +00:00
|
|
|
#include "config.h"
|
2002-06-26 12:39:49 +00:00
|
|
|
#include "sh7034.h"
|
2002-04-20 23:18:14 +00:00
|
|
|
#include "i2c.h"
|
|
|
|
#include "debug.h"
|
2010-10-31 21:09:34 +00:00
|
|
|
#include "mas35xx.h"
|
2002-06-26 12:39:49 +00:00
|
|
|
#include "kernel.h"
|
2003-11-06 01:34:50 +00:00
|
|
|
#include "system.h"
|
2006-11-12 14:17:49 +00:00
|
|
|
#include "hwcompat.h"
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
static int mas_devread(unsigned long *dest, int len);
|
|
|
|
|
2011-11-22 19:59:31 +00:00
|
|
|
#if 0 /* Currently unused, left for reference and future use */
|
2002-05-16 21:12:57 +00:00
|
|
|
int mas_default_read(unsigned short *buf)
|
2002-05-03 13:12:21 +00:00
|
|
|
{
|
2002-05-16 21:12:57 +00:00
|
|
|
unsigned char *dest = (unsigned char *)buf;
|
|
|
|
int ret = 0;
|
2002-06-24 12:35:37 +00:00
|
|
|
|
|
|
|
i2c_begin();
|
2002-05-16 21:12:57 +00:00
|
|
|
|
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_WRITE);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_outb(MAS_DATA_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
dest[0] = i2c_inb(0);
|
|
|
|
dest[1] = i2c_inb(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
i2c_stop();
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
2002-05-16 21:12:57 +00:00
|
|
|
return ret;
|
2002-05-03 13:12:21 +00:00
|
|
|
}
|
2011-11-22 19:59:31 +00:00
|
|
|
#endif
|
2002-05-03 13:12:21 +00:00
|
|
|
|
2011-11-22 19:59:31 +00:00
|
|
|
#if CONFIG_CODEC == MAS3507D
|
2002-05-03 13:12:21 +00:00
|
|
|
int mas_run(unsigned short address)
|
2002-05-02 23:01:10 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[3];
|
2002-05-02 23:01:10 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_DATA_WRITE;
|
2002-07-28 11:45:52 +00:00
|
|
|
buf[1] = address >> 8;
|
2002-06-24 12:35:37 +00:00
|
|
|
buf[2] = address & 0xff;
|
2002-05-02 23:01:10 +00:00
|
|
|
|
|
|
|
/* send run command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,3))
|
2002-05-02 23:01:10 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-05-02 23:01:10 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-05-02 23:01:10 +00:00
|
|
|
}
|
2011-11-22 19:59:31 +00:00
|
|
|
#endif
|
2002-05-02 23:01:10 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
/* note: 'len' is number of 32-bit words, not number of bytes! */
|
|
|
|
int mas_readmem(int bank, int addr, unsigned long* dest, int len)
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[7];
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_DATA_WRITE;
|
|
|
|
buf[1] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM;
|
|
|
|
buf[2] = 0x00;
|
|
|
|
buf[3] = (len & 0xff00) >> 8;
|
|
|
|
buf[4] = len & 0xff;
|
|
|
|
buf[5] = (addr & 0xff00) >> 8;
|
|
|
|
buf[6] = addr & 0xff;
|
2002-04-20 23:18:14 +00:00
|
|
|
|
|
|
|
/* send read command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,7))
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = mas_devread(dest, len);
|
|
|
|
|
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* note: 'len' is number of 32-bit words, not number of bytes! */
|
2004-08-17 01:45:48 +00:00
|
|
|
int mas_writemem(int bank, int addr, const unsigned long* src, int len)
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
2002-04-20 23:18:14 +00:00
|
|
|
int i, j;
|
|
|
|
unsigned char buf[60];
|
2004-08-17 01:45:48 +00:00
|
|
|
const unsigned char* ptr = (const unsigned char*)src;
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
i=0;
|
|
|
|
buf[i++] = MAS_DATA_WRITE;
|
2002-06-19 12:03:41 +00:00
|
|
|
buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM;
|
2002-04-20 23:18:14 +00:00
|
|
|
buf[i++] = 0x00;
|
|
|
|
buf[i++] = (len & 0xff00) >> 8;
|
|
|
|
buf[i++] = len & 0xff;
|
|
|
|
buf[i++] = (addr & 0xff00) >> 8;
|
|
|
|
buf[i++] = addr & 0xff;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
while(len--) {
|
2005-08-29 21:15:27 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2002-04-20 23:18:14 +00:00
|
|
|
buf[i++] = 0;
|
2002-06-19 12:03:41 +00:00
|
|
|
buf[i++] = ptr[j+1];
|
|
|
|
buf[i++] = ptr[j+2];
|
|
|
|
buf[i++] = ptr[j+3];
|
|
|
|
#else
|
|
|
|
buf[i++] = ptr[j+2];
|
|
|
|
buf[i++] = ptr[j+3];
|
|
|
|
buf[i++] = 0;
|
|
|
|
buf[i++] = ptr[j+1];
|
|
|
|
#endif
|
2002-04-20 23:18:14 +00:00
|
|
|
j += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send write command */
|
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,i))
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mas_readreg(int reg)
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
2002-04-20 23:18:14 +00:00
|
|
|
unsigned char buf[16];
|
2002-06-19 12:03:41 +00:00
|
|
|
unsigned long value;
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_DATA_WRITE;
|
|
|
|
buf[1] = MAS_CMD_READ_REG | (reg >> 4);
|
|
|
|
buf[2] = (reg & 0x0f) << 4;
|
2002-04-20 23:18:14 +00:00
|
|
|
|
|
|
|
/* send read command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,3))
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
2002-06-24 12:35:37 +00:00
|
|
|
else
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
if(mas_devread(&value, 1))
|
|
|
|
{
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = value;
|
|
|
|
}
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 21:12:57 +00:00
|
|
|
int mas_writereg(int reg, unsigned int val)
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[5];
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_DATA_WRITE;
|
|
|
|
buf[1] = MAS_CMD_WRITE_REG | (reg >> 4);
|
2006-03-24 07:57:55 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
buf[2] = ((reg & 0x0f) << 4) | (val >> 16 & 0x0f);
|
|
|
|
buf[3] = (val >> 8) & 0xff;
|
|
|
|
buf[4] = val & 0xff;
|
|
|
|
#else
|
2002-06-24 12:35:37 +00:00
|
|
|
buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f);
|
|
|
|
buf[3] = (val >> 12) & 0xff;
|
|
|
|
buf[4] = (val >> 4) & 0xff;
|
2006-03-24 07:57:55 +00:00
|
|
|
#endif
|
2002-04-20 23:18:14 +00:00
|
|
|
|
|
|
|
/* send write command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,5))
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
2002-06-24 12:35:37 +00:00
|
|
|
|
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* note: 'len' is number of 32-bit words, not number of bytes! */
|
2002-06-24 12:35:37 +00:00
|
|
|
static int mas_devread(unsigned long *dest, int len)
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2002-06-24 12:35:37 +00:00
|
|
|
unsigned char* ptr = (unsigned char*)dest;
|
2002-04-20 23:18:14 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* handle read-back */
|
2002-06-19 12:03:41 +00:00
|
|
|
/* Remember, the MAS values are only 20 bits, so we set
|
|
|
|
the upper 12 bits to 0 */
|
2002-04-20 23:18:14 +00:00
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_WRITE);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_outb(MAS_DATA_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
for (i=0;len;i++) {
|
|
|
|
len--;
|
2005-08-29 21:15:27 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2002-06-19 12:03:41 +00:00
|
|
|
i2c_inb(0); /* Dummy read */
|
|
|
|
ptr[i*4+0] = 0;
|
|
|
|
ptr[i*4+1] = i2c_inb(0) & 0x0f;
|
|
|
|
ptr[i*4+2] = i2c_inb(0);
|
|
|
|
if(len)
|
|
|
|
ptr[i*4+3] = i2c_inb(0);
|
|
|
|
else
|
|
|
|
ptr[i*4+3] = i2c_inb(1); /* NAK the last byte */
|
|
|
|
#else
|
|
|
|
ptr[i*4+2] = i2c_inb(0);
|
2002-04-20 23:18:14 +00:00
|
|
|
ptr[i*4+3] = i2c_inb(0);
|
2002-06-19 12:03:41 +00:00
|
|
|
ptr[i*4+0] = i2c_inb(0);
|
2002-04-20 23:18:14 +00:00
|
|
|
if(len)
|
2002-06-19 12:03:41 +00:00
|
|
|
ptr[i*4+1] = i2c_inb(0);
|
2002-04-20 23:18:14 +00:00
|
|
|
else
|
2002-06-19 12:03:41 +00:00
|
|
|
ptr[i*4+1] = i2c_inb(1); /* NAK the last byte */
|
|
|
|
#endif
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
i2c_stop();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2002-06-19 12:03:41 +00:00
|
|
|
|
2002-06-26 12:39:49 +00:00
|
|
|
void mas_reset(void)
|
|
|
|
{
|
2003-11-07 12:15:24 +00:00
|
|
|
or_b(0x01, &PAIORH);
|
2004-11-22 01:54:26 +00:00
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == MAS3507D
|
2005-05-07 22:29:35 +00:00
|
|
|
/* PB5 is "MAS enable". make it GPIO output and high */
|
|
|
|
PBCR2 &= ~0x0c00;
|
|
|
|
or_b(0x20, &PBIORL);
|
|
|
|
or_b(0x20, &PBDRL);
|
|
|
|
|
2004-11-22 01:54:26 +00:00
|
|
|
and_b(~0x01, &PADRH);
|
|
|
|
sleep(HZ/100);
|
|
|
|
or_b(0x01, &PADRH);
|
|
|
|
sleep(HZ/5);
|
2005-08-29 21:15:27 +00:00
|
|
|
#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2007-04-11 23:51:00 +00:00
|
|
|
if (HW_MASK & ATA_ADDRESS_200)
|
2002-06-26 12:39:49 +00:00
|
|
|
{
|
2003-11-07 12:15:24 +00:00
|
|
|
and_b(~0x01, &PADRH);
|
2006-11-12 14:17:49 +00:00
|
|
|
sleep(HZ/100);
|
|
|
|
or_b(0x01, &PADRH);
|
2002-06-26 12:39:49 +00:00
|
|
|
sleep(HZ/5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-12 14:17:49 +00:00
|
|
|
/* Older recorder models don't invert the POR signal */
|
2003-11-07 12:15:24 +00:00
|
|
|
or_b(0x01, &PADRH);
|
2006-11-12 14:17:49 +00:00
|
|
|
sleep(HZ/100);
|
|
|
|
and_b(~0x01, &PADRH);
|
2002-06-26 12:39:49 +00:00
|
|
|
sleep(HZ/5);
|
2006-11-12 14:17:49 +00:00
|
|
|
}
|
2004-11-22 01:54:26 +00:00
|
|
|
#endif
|
2002-06-26 12:39:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2011-11-22 19:59:31 +00:00
|
|
|
#if 0 /* Currently unused, left for reference and future use */
|
2002-06-19 12:03:41 +00:00
|
|
|
int mas_direct_config_read(unsigned char reg)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2002-06-24 12:35:37 +00:00
|
|
|
unsigned char tmp[2];
|
2002-06-19 12:03:41 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
2002-06-19 12:03:41 +00:00
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_WRITE);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_outb(reg);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
tmp[0] = i2c_inb(0);
|
|
|
|
tmp[1] = i2c_inb(1); /* NAK the last byte */
|
|
|
|
ret = (tmp[0] << 8) | tmp[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
i2c_stop();
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
2002-06-19 12:03:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2011-11-22 19:59:31 +00:00
|
|
|
#endif
|
2002-06-19 12:03:41 +00:00
|
|
|
|
|
|
|
int mas_direct_config_write(unsigned char reg, unsigned int val)
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
2002-06-19 12:03:41 +00:00
|
|
|
unsigned char buf[3];
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
2002-06-19 12:03:41 +00:00
|
|
|
buf[0] = reg;
|
|
|
|
buf[1] = (val >> 8) & 0xff;
|
|
|
|
buf[2] = val & 0xff;
|
|
|
|
|
|
|
|
/* send write command */
|
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,3))
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
2002-06-24 12:35:37 +00:00
|
|
|
|
|
|
|
i2c_end();
|
2002-06-25 14:12:37 +00:00
|
|
|
return ret;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mas_codec_writereg(int reg, unsigned int val)
|
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[5];
|
2002-06-19 12:03:41 +00:00
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_CODEC_WRITE;
|
|
|
|
buf[1] = (reg >> 8) & 0xff;
|
|
|
|
buf[2] = reg & 0xff;
|
|
|
|
buf[3] = (val >> 8) & 0xff;
|
|
|
|
buf[4] = val & 0xff;
|
2002-06-19 12:03:41 +00:00
|
|
|
|
|
|
|
/* send write command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,5))
|
2002-06-19 12:03:41 +00:00
|
|
|
{
|
2002-06-24 12:35:37 +00:00
|
|
|
ret = -1;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
2002-06-24 12:35:37 +00:00
|
|
|
|
|
|
|
i2c_end();
|
|
|
|
return ret;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mas_codec_readreg(int reg)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[16];
|
|
|
|
unsigned char tmp[2];
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_CODEC_WRITE;
|
|
|
|
buf[1] = (reg >> 8) & 0xff;
|
|
|
|
buf[2] = reg & 0xff;
|
2002-06-19 12:03:41 +00:00
|
|
|
|
|
|
|
/* send read command */
|
2002-06-24 12:35:37 +00:00
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,3))
|
2002-06-19 12:03:41 +00:00
|
|
|
{
|
2002-11-24 11:47:24 +00:00
|
|
|
ret = -1;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
2002-11-24 11:47:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_WRITE);
|
2002-06-19 12:03:41 +00:00
|
|
|
if (i2c_getack()) {
|
2002-11-24 11:47:24 +00:00
|
|
|
i2c_outb(MAS_CODEC_READ);
|
2002-06-19 12:03:41 +00:00
|
|
|
if (i2c_getack()) {
|
2002-11-24 11:47:24 +00:00
|
|
|
i2c_start();
|
|
|
|
i2c_outb(MAS_DEV_READ);
|
|
|
|
if (i2c_getack()) {
|
|
|
|
tmp[0] = i2c_inb(0);
|
|
|
|
tmp[1] = i2c_inb(1); /* NAK the last byte */
|
|
|
|
ret = (tmp[0] << 8) | tmp[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -4;
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = -2;
|
2002-11-24 11:47:24 +00:00
|
|
|
|
|
|
|
i2c_stop();
|
2002-06-19 12:03:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 12:35:37 +00:00
|
|
|
i2c_end();
|
2002-06-19 12:03:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2002-11-20 22:22:13 +00:00
|
|
|
|
|
|
|
unsigned long mas_readver(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
unsigned char buf[16];
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
i2c_begin();
|
|
|
|
|
|
|
|
buf[0] = MAS_DATA_WRITE;
|
|
|
|
buf[1] = MAS_CMD_READ_IC_VER;
|
|
|
|
buf[2] = 0;
|
|
|
|
|
|
|
|
/* send read command */
|
|
|
|
if (i2c_write(MAS_DEV_WRITE,buf,3))
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(mas_devread(&value, 1))
|
|
|
|
{
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c_end();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-06-19 12:03:41 +00:00
|
|
|
#endif
|
2008-10-14 11:12:20 +00:00
|
|
|
|
|
|
|
#if CONFIG_TUNER & S1A0903X01
|
|
|
|
static int pllfreq;
|
|
|
|
|
|
|
|
void mas_store_pllfreq(int freq)
|
|
|
|
{
|
|
|
|
pllfreq = freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mas_get_pllfreq(void)
|
|
|
|
{
|
|
|
|
return pllfreq;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|