2005-08-06 10:12:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Christian Gmeiner
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "power.h"
|
2006-03-23 14:02:43 +00:00
|
|
|
#include "logf.h"
|
2005-08-06 10:12:19 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "buffer.h"
|
2006-07-21 08:42:28 +00:00
|
|
|
#include "audio.h"
|
2005-08-06 10:12:19 +00:00
|
|
|
|
|
|
|
#include "i2c-coldfire.h"
|
|
|
|
#include "tlv320.h"
|
|
|
|
|
|
|
|
/* local functions and definations */
|
|
|
|
#define TLV320_ADDR 0x34
|
|
|
|
|
|
|
|
struct tlv320_info
|
|
|
|
{
|
|
|
|
int vol_l;
|
|
|
|
int vol_r;
|
|
|
|
} tlv320;
|
|
|
|
|
2006-03-28 20:36:59 +00:00
|
|
|
/* Shadow registers */
|
2005-08-06 10:12:19 +00:00
|
|
|
unsigned tlv320_regs[0xf];
|
|
|
|
|
|
|
|
void tlv320_write_reg(unsigned reg, unsigned value)
|
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
unsigned char data[2];
|
2005-08-06 10:12:19 +00:00
|
|
|
|
2006-03-28 20:36:59 +00:00
|
|
|
/* The register address is the high 7 bits and the data the low 9 bits */
|
2006-07-21 08:42:28 +00:00
|
|
|
data[0] = (reg << 1) | ((value >> 8) & 1);
|
|
|
|
data[1] = value & 0xff;
|
2005-08-06 10:12:19 +00:00
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
if (i2c_write(I2C_IFACE_0, TLV320_ADDR, data, 2) != 2)
|
2005-08-06 10:12:19 +00:00
|
|
|
{
|
2006-03-23 14:02:43 +00:00
|
|
|
logf("tlv320 error reg=0x%x", reg);
|
2005-08-06 10:12:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tlv320_regs[reg] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init our tlv with default values
|
|
|
|
*/
|
2006-02-03 23:59:41 +00:00
|
|
|
void tlv320_init(void)
|
2005-08-06 10:12:19 +00:00
|
|
|
{
|
2006-03-28 20:36:59 +00:00
|
|
|
memset(tlv320_regs, 0, sizeof(tlv320_regs));
|
|
|
|
|
|
|
|
/* Initialize all registers */
|
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
tlv320_write_reg(REG_PC, PC_ADC|PC_MIC|PC_LINE); /* All ON except ADC, MIC and LINE */
|
|
|
|
tlv320_set_recvol(0, 0, AUDIO_GAIN_MIC);
|
|
|
|
tlv320_set_recvol(0, 0, AUDIO_GAIN_LINEIN);
|
2006-03-28 20:36:59 +00:00
|
|
|
tlv320_mute(true);
|
|
|
|
tlv320_write_reg(REG_AAP, AAP_DAC|AAP_MICM);
|
|
|
|
tlv320_write_reg(REG_DAP, 0x00); /* No deemphasis */
|
|
|
|
tlv320_write_reg(REG_DAIF, DAIF_IWL_16|DAIF_FOR_I2S);
|
|
|
|
tlv320_set_headphone_vol(0, 0);
|
|
|
|
tlv320_write_reg(REG_DIA, DIA_ACT);
|
2006-07-21 08:42:28 +00:00
|
|
|
tlv320_write_reg(REG_SRC, (1 << 5)); /* 44.1kHz */
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets tlv320 to default values
|
|
|
|
*/
|
2006-02-03 23:59:41 +00:00
|
|
|
void tlv320_reset(void)
|
2005-08-06 10:12:19 +00:00
|
|
|
{
|
2006-02-03 23:59:41 +00:00
|
|
|
tlv320_write_reg(REG_RR, RR_RESET);
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets left and right headphone volume (127(max) to 48(muted))
|
|
|
|
*/
|
|
|
|
void tlv320_set_headphone_vol(int vol_l, int vol_r)
|
|
|
|
{
|
|
|
|
unsigned value_l = tlv320_regs[REG_LHV];
|
|
|
|
unsigned value_r = tlv320_regs[REG_RHV];
|
|
|
|
|
|
|
|
/* keep track of current setting */
|
|
|
|
tlv320.vol_l = vol_l;
|
|
|
|
tlv320.vol_r = vol_r;
|
|
|
|
|
|
|
|
/* set new values in local register holders */
|
2006-03-28 20:36:59 +00:00
|
|
|
value_l = LHV_LHV(vol_l);
|
|
|
|
value_r = RHV_RHV(vol_r);
|
2005-08-06 10:12:19 +00:00
|
|
|
|
|
|
|
/* update */
|
|
|
|
tlv320_write_reg(REG_LHV, value_l);
|
|
|
|
tlv320_write_reg(REG_RHV, value_r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-21 08:42:28 +00:00
|
|
|
* Set recording volume
|
|
|
|
*
|
|
|
|
* Line in : 0 .. 31 => Volume -34.5 .. 12 dB
|
|
|
|
* Mic (left): 0 .. 1 => Volume 0 .. 20 dB
|
|
|
|
*
|
2005-08-06 10:12:19 +00:00
|
|
|
*/
|
2006-07-21 08:42:28 +00:00
|
|
|
void tlv320_set_recvol(int left, int right, int type)
|
2005-08-06 10:12:19 +00:00
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
if (type == AUDIO_GAIN_MIC)
|
|
|
|
{
|
|
|
|
unsigned value_aap = tlv320_regs[REG_AAP];
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
value_aap |= AAP_MICB; /* Enable mic boost (20dB) */
|
|
|
|
else
|
|
|
|
value_aap &= ~AAP_MICB;
|
|
|
|
|
|
|
|
tlv320_write_reg(REG_AAP, value_aap);
|
|
|
|
|
|
|
|
} else if (type == AUDIO_GAIN_LINEIN)
|
|
|
|
{
|
|
|
|
tlv320_write_reg(REG_LLIV, LLIV_LIV(left));
|
|
|
|
tlv320_write_reg(REG_RLIV, RLIV_RIV(right));
|
|
|
|
}
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mute (mute=true) or enable sound (mute=false)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void tlv320_mute(bool mute)
|
|
|
|
{
|
2006-02-03 23:59:41 +00:00
|
|
|
unsigned value_l = tlv320_regs[REG_LHV];
|
|
|
|
unsigned value_r = tlv320_regs[REG_RHV];
|
2005-08-06 10:12:19 +00:00
|
|
|
|
|
|
|
if (mute)
|
|
|
|
{
|
2006-03-28 20:36:59 +00:00
|
|
|
value_l = LHV_LHV(HEADPHONE_MUTE);
|
|
|
|
value_r = RHV_RHV(HEADPHONE_MUTE);
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-28 20:36:59 +00:00
|
|
|
value_l = LHV_LHV(tlv320.vol_l);
|
|
|
|
value_r = RHV_RHV(tlv320.vol_r);
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
tlv320_write_reg(REG_LHV, value_l);
|
2005-08-06 10:12:19 +00:00
|
|
|
tlv320_write_reg(REG_RHV, value_r);
|
|
|
|
}
|
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
/* Nice shutdown of TLV320 codec */
|
2005-08-06 10:12:19 +00:00
|
|
|
void tlv320_close()
|
|
|
|
{
|
2006-07-13 21:20:28 +00:00
|
|
|
tlv320_write_reg(REG_PC, 0xFF); /* All OFF */
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tlv320_enable_recording(bool source_mic)
|
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
unsigned value_daif = tlv320_regs[REG_DAIF];
|
|
|
|
unsigned value_aap, value_pc;
|
|
|
|
|
2005-08-06 10:12:19 +00:00
|
|
|
if (source_mic)
|
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
/* select mic and enable mic boost (20 dB) */
|
|
|
|
value_aap = AAP_DAC | AAP_INSEL | AAP_MICB;
|
|
|
|
value_pc = PC_LINE; /* power down line-in */
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
value_aap = AAP_DAC | AAP_MICM;
|
|
|
|
value_pc = PC_MIC; /* power down mic */
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
tlv320_write_reg(REG_PC, value_pc);
|
|
|
|
sleep(HZ/8);
|
2005-08-06 10:12:19 +00:00
|
|
|
|
|
|
|
tlv320_write_reg(REG_AAP, value_aap);
|
2006-07-21 08:42:28 +00:00
|
|
|
sleep(HZ/8);
|
|
|
|
|
|
|
|
/* Enable MASTER mode (start sending I2S data to the CPU) */
|
|
|
|
value_daif |= DAIF_MS;
|
|
|
|
tlv320_write_reg(REG_DAIF, value_daif);
|
2005-08-06 10:12:19 +00:00
|
|
|
}
|
2006-07-21 08:42:28 +00:00
|
|
|
|
2005-08-06 10:12:19 +00:00
|
|
|
void tlv320_disable_recording()
|
|
|
|
{
|
2006-07-21 08:42:28 +00:00
|
|
|
unsigned value_pc = tlv320_regs[REG_PC];
|
|
|
|
unsigned value_aap = tlv320_regs[REG_AAP];
|
|
|
|
unsigned value_daif = tlv320_regs[REG_DAIF];
|
|
|
|
|
|
|
|
value_daif &= ~DAIF_MS; /* disable MASTER mode */
|
|
|
|
tlv320_write_reg(REG_DAIF, value_daif);
|
|
|
|
|
|
|
|
value_aap |= AAP_MICM; /* mute mic */
|
|
|
|
tlv320_write_reg(REG_PC, value_aap);
|
|
|
|
|
|
|
|
value_pc |= (PC_MIC|PC_LINE|PC_ADC); /* power down mic, line-in and adc */
|
|
|
|
tlv320_write_reg(REG_PC, value_pc);
|
|
|
|
|
|
|
|
sleep(HZ/8);
|
|
|
|
}
|
2005-08-06 10:12:19 +00:00
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
void tlv320_set_monitor(bool enable)
|
|
|
|
{
|
|
|
|
unsigned value_aap, value_pc;
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
value_aap = AAP_BYPASS | AAP_MICM;
|
|
|
|
value_pc = (PC_MIC|PC_DAC|PC_ADC); /* power down mic, dac and adc */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value_aap = AAP_DAC | AAP_MICM;
|
|
|
|
value_pc = (PC_MIC|PC_LINE|PC_ADC); /* power down mic, line-in and adc */
|
|
|
|
}
|
|
|
|
tlv320_write_reg(REG_AAP, value_aap);
|
|
|
|
tlv320_write_reg(REG_PC, value_pc);
|
|
|
|
|
|
|
|
sleep(HZ/8);
|
2006-02-03 23:59:41 +00:00
|
|
|
}
|
2006-07-21 08:42:28 +00:00
|
|
|
|