forked from len0rd/rockbox
iAudio: First unfinished attempt for tlv320 driver and rockbox integration
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7286 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
095854b989
commit
14e80671af
8 changed files with 441 additions and 142 deletions
|
@ -48,10 +48,14 @@
|
|||
#include "sound.h"
|
||||
#include "ata.h"
|
||||
#include "logf.h"
|
||||
#if defined(HAVE_UDA1380)
|
||||
#include "uda1380.h"
|
||||
#elif defined(HAVE_TLV320)
|
||||
#include "tlv320.h"
|
||||
#endif
|
||||
#include "pcm_record.h"
|
||||
|
||||
#ifdef HAVE_UDA1380
|
||||
#if defined(HAVE_UDA1380) || defined(HAVE_TLV320)
|
||||
|
||||
bool pcm_rec_screen(void)
|
||||
{
|
||||
|
@ -73,8 +77,17 @@ bool pcm_rec_screen(void)
|
|||
|
||||
//cpu_boost(true);
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_enable_output(true);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_enable_output(true);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_set_master_vol(play_vol, play_vol);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_set_headphone_vol(play_vol, play_vol);
|
||||
#endif
|
||||
|
||||
rec_monitor = 0; // No record feedback
|
||||
rec_source = 1; // Mic
|
||||
|
@ -176,7 +189,9 @@ bool pcm_rec_screen(void)
|
|||
|
||||
case BUTTON_RC_MENU:
|
||||
rec_monitor = 1 - rec_monitor;
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_set_monitor(rec_monitor);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BUTTON_RC_ON:
|
||||
|
@ -205,9 +220,11 @@ bool pcm_rec_screen(void)
|
|||
} else
|
||||
{
|
||||
pcm_stop_recording();
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_enable_output(false);
|
||||
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_enable_output(false);
|
||||
#endif
|
||||
default_event_handler(SYS_USB_CONNECTED);
|
||||
return false;
|
||||
}
|
||||
|
@ -220,7 +237,11 @@ bool pcm_rec_screen(void)
|
|||
pcm_stop_recording();
|
||||
pcm_close_recording();
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_enable_output(false);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_enable_output(false);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -126,6 +126,8 @@ drivers/lcd-h100-remote.c
|
|||
#endif
|
||||
#if defined(HAVE_UDA1380) && !defined(SIMULATOR)
|
||||
drivers/uda1380.c
|
||||
#elif defined(HAVE_TLV320) && !defined(SIMULATOR)
|
||||
drivers/tlv320.c
|
||||
#endif
|
||||
#if (CONFIG_HWCODEC == MASNONE) && !defined(SIMULATOR)
|
||||
pcm_playback.c
|
||||
|
@ -133,7 +135,7 @@ pcm_playback.c
|
|||
#if CONFIG_HWCODEC == MASNONE
|
||||
replaygain.c
|
||||
#endif
|
||||
#if defined(HAVE_UDA1380) && !defined(SIMULATOR)
|
||||
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
|
||||
pcm_record.c
|
||||
#endif
|
||||
sound.c
|
||||
|
|
223
firmware/drivers/tlv320.c
Normal file
223
firmware/drivers/tlv320.c
Normal file
|
@ -0,0 +1,223 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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"
|
||||
#include "debug.h"
|
||||
#include "system.h"
|
||||
#include "sprintf.h"
|
||||
#include "button.h"
|
||||
#include "string.h"
|
||||
#include "file.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#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;
|
||||
|
||||
/* Definition of a playback configuration to start with */
|
||||
#define NUM_DEFAULT_REGS 10
|
||||
unsigned tlv320_defaults[2*NUM_DEFAULT_REGS] =
|
||||
{
|
||||
REG_PC, PC_ON | PC_OSC | PC_CLK | PC_DAC | ~PC_OUT, /* do we need to enable osciliator and clock? */
|
||||
REG_LLIV, LLIV_LIM, /* mute adc input */
|
||||
REG_RLIV, RLIV_RIM, /* mute adc input */
|
||||
REG_LHV, LHV_LHV(HEADPHONE_MUTE), /* mute headphone */
|
||||
REG_RHV, RHV_RHV(HEADPHONE_MUTE), /* mute headphone */
|
||||
REG_AAP, AAP_MICM, /* mute microphone */
|
||||
REG_DAP, DAP_DEEMP_DIS, /* de-emphasis control: disabled */
|
||||
REG_DAIF, DAIF_FOR_I2S | DAIF_IWL_24 | ~DAIF_MS, /* i2s with 24 bit data len and slave mode */
|
||||
REG_SRC, 0, /* ToDo */
|
||||
REG_DIA, DIA_ACT, /* activate digital interface */
|
||||
};
|
||||
unsigned tlv320_regs[0xf];
|
||||
|
||||
void tlv320_write_reg(unsigned reg, unsigned value)
|
||||
{
|
||||
unsigned data[3];
|
||||
|
||||
data[0] = TLV320_ADDR;
|
||||
data[1] = reg << 1;
|
||||
data[2] = value & 0xff;
|
||||
|
||||
if (i2c_write(1, data, 3) != 3)
|
||||
{
|
||||
DEBUGF("tlv320 error reg=0x%x", reg);
|
||||
return;
|
||||
}
|
||||
|
||||
tlv320_regs[reg] = value;
|
||||
}
|
||||
|
||||
/* Returns 0 if successful or -1 if some register failed */
|
||||
void tlv320_set_regs()
|
||||
{
|
||||
int i;
|
||||
memset(tlv320_regs, 0, sizeof(tlv320_regs));
|
||||
|
||||
/* Initialize all registers */
|
||||
for (i=0; i<NUM_DEFAULT_REGS; i++)
|
||||
{
|
||||
unsigned reg = tlv320_defaults[i*2+0];
|
||||
unsigned value = tlv320_defaults[i*2+1];
|
||||
|
||||
tlv320_write_reg(reg, value);
|
||||
}
|
||||
}
|
||||
|
||||
/* public functions */
|
||||
|
||||
/**
|
||||
* Init our tlv with default values
|
||||
*/
|
||||
void tlv320_init()
|
||||
{
|
||||
tlv320_reset();
|
||||
tlv320_set_regs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets tlv320 to default values
|
||||
*/
|
||||
void tlv320_reset()
|
||||
{
|
||||
tlv320_write_reg(REG_RR, RR_RESET):
|
||||
}
|
||||
|
||||
void tlv320_enable_output(bool enable)
|
||||
{
|
||||
unsigned value = tlv320regs[REG_PC];
|
||||
|
||||
if (enable)
|
||||
value |= PC_OUT;
|
||||
else
|
||||
value &= ~PC_OUT;
|
||||
|
||||
tlv320_write_reg(REG_PC, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
value_l |= LHV_LHV(vol_l);
|
||||
value_r |= LHV_LHV(vol_r);
|
||||
|
||||
/* update */
|
||||
tlv320_write_reg(REG_LHV, value_l);
|
||||
tlv320_write_reg(REG_RHV, value_r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets left and right linein volume (31(max) to 0(muted))
|
||||
*/
|
||||
void tlv320_set_linein_vol(int vol_l, int vol_r)
|
||||
{
|
||||
unsigned value_l = tlv320regs[REG_LLIV];
|
||||
unsigned value_r = tlv320regs[REG_RLIV];
|
||||
|
||||
value_l |= LLIV_LHV(vol_l);
|
||||
value_r |= RLIV_RHV(vol_r);
|
||||
|
||||
tlv320_write_reg(REG_LLIV, value_l);
|
||||
tlv320_write_reg(REG_RLIV, value_r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mute (mute=true) or enable sound (mute=false)
|
||||
*
|
||||
*/
|
||||
void tlv320_mute(bool mute)
|
||||
{
|
||||
unsigned value_l = tlv320regs[REG_LHV];
|
||||
unsigned value_r = tlv320regs[REG_RHV];
|
||||
|
||||
if (mute)
|
||||
{
|
||||
value_l |= LHV_LHV(HEADPHONE_MUTE);
|
||||
value_r |= RHV_RHV(HEADPHONE_MUTE);
|
||||
}
|
||||
else
|
||||
{
|
||||
value_l |= LHV_LHV(tlv320.vol_l);
|
||||
value_r |= RHV_RHV(tlv320.vol_r);
|
||||
}
|
||||
|
||||
tlv320_write_reg(REG_LHV, value_r);
|
||||
tlv320_write_reg(REG_RHV, value_r);
|
||||
}
|
||||
|
||||
void tlv320_close()
|
||||
{
|
||||
/* todo */
|
||||
}
|
||||
|
||||
void tlv320_enable_recording(bool source_mic)
|
||||
{
|
||||
unsigned value_pc = tlv320regs[REG_PC];
|
||||
unsigned value_aap = tlv320regs[REG_AAP];
|
||||
|
||||
/* select source*/
|
||||
if (source_mic)
|
||||
{
|
||||
value_aap &= ~AAP_INSEL;
|
||||
value_pc |= PC_MIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
value_aap |= AAP_INSEL;
|
||||
value_pc |= PC_LINE;
|
||||
}
|
||||
|
||||
/* poweron adc */
|
||||
value_pc |= PC_ADC;
|
||||
|
||||
tlv320_write_reg(REG_AAP, value_aap);
|
||||
tlv320_write_reg(REG_PC, value_pc);
|
||||
}
|
||||
|
||||
void tlv320_disable_recording()
|
||||
{
|
||||
unsigned value = tlv320regs[REG_PC];
|
||||
|
||||
/* powerdown mic, linein and adc */
|
||||
value &= ~(PC_MIC | PC_LINE | PC_ADC);
|
||||
|
||||
/* powerdown mic, linein and adc */
|
||||
tlv320_write_reg(REG_PC, value);
|
||||
}
|
|
@ -22,10 +22,15 @@
|
|||
|
||||
/*** definitions ***/
|
||||
|
||||
extern void tlv320_reset(void);
|
||||
extern int tlv320_init(void);
|
||||
extern int tlv320_set_headphone_vol(int vol_l, int vol_r);
|
||||
extern int tlv320_mute(bool mute);
|
||||
extern void tlv320_init();
|
||||
extern void tlv320_reset();
|
||||
extern void tlv320_enable_output(bool enable);
|
||||
extern void tlv320_set_headphone_vol(int vol_l, int vol_r);
|
||||
extern void tlv320_set_linein_vol(int vol_l, int vol_r);
|
||||
extern void tlv320_mute(bool mute);
|
||||
extern void tlv320_close();
|
||||
extern void tlv320_enable_recording(bool source_mic);
|
||||
extern void tlv320_disable_recording();
|
||||
|
||||
#define HEADPHONE_MUTE 0x30 /* 0110000 = -73db */
|
||||
|
||||
|
@ -35,8 +40,8 @@ extern int tlv320_mute(bool mute);
|
|||
/* REG_LLIV: Left line input channel volume control */
|
||||
#define REG_LLIV 0x0
|
||||
#define LLIV_LRS (0 << 8) /* simultaneous volume/mute update */
|
||||
#define LIM (1 << 7) /* Left line input mute */
|
||||
#define LIV ((x) & 0x1f)/* Left line input volume control */
|
||||
#define LLIV_LIM (1 << 7) /* Left line input mute */
|
||||
#define LLIV_LIV ((x) & 0x1f)/* Left line input volume control */
|
||||
|
||||
/* REG_RLIV: Right line input channel volume control */
|
||||
#define REG_RLIV 0x1
|
||||
|
@ -75,7 +80,7 @@ extern int tlv320_mute(bool mute);
|
|||
|
||||
/* REG_PC: Power Down Control */
|
||||
#define REG_PC 0x6
|
||||
#define PC_OFF (0 << 7) /* Device power */
|
||||
#define PC_ON (0 << 7) /* Device power */
|
||||
#define PC_CLK (0 << 6) /* Clock */
|
||||
#define PC_OSC (0 << 5) /* Oscillator */
|
||||
#define PC_OUT (0 << 4) /* Outputs */
|
||||
|
|
|
@ -24,7 +24,11 @@
|
|||
#ifndef SIMULATOR
|
||||
#include "cpu.h"
|
||||
#include "i2c.h"
|
||||
#if defined(HAVE_UDA1380)
|
||||
#include "uda1380.h"
|
||||
#elif defined(HAVE_TLV320)
|
||||
#include "tlv320.h"
|
||||
#endif
|
||||
#include "system.h"
|
||||
#endif
|
||||
#include "logf.h"
|
||||
|
@ -187,7 +191,12 @@ void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
|
|||
get_more((unsigned char **)&start, (long *)&size);
|
||||
get_more(&next_start, &next_size);
|
||||
dma_start(start, size);
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_mute(false);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_mute(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
long pcm_get_bytes_waiting(void)
|
||||
|
@ -198,7 +207,12 @@ long pcm_get_bytes_waiting(void)
|
|||
void pcm_play_stop(void)
|
||||
{
|
||||
if (pcm_playing) {
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_mute(true);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_mute(true);
|
||||
#endif
|
||||
dma_stop();
|
||||
}
|
||||
}
|
||||
|
@ -217,12 +231,21 @@ void pcm_play_pause(bool play)
|
|||
EBU1CONFIG = (7 << 12) | (3 << 8) | (1 << 5) | (5 << 2);
|
||||
DCR0 |= DMA_EEXT | DMA_START;
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_mute(false);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_mute(false);
|
||||
#endif
|
||||
}
|
||||
else if(!pcm_paused && !play)
|
||||
{
|
||||
logf("pause");
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_mute(true);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_mute(true);
|
||||
#endif
|
||||
|
||||
/* Disable DMA peripheral request. */
|
||||
DCR0 &= ~DMA_EEXT;
|
||||
|
@ -283,7 +306,11 @@ void pcm_init(void)
|
|||
pcm_playing = false;
|
||||
pcm_paused = false;
|
||||
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_init();
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_init();
|
||||
#endif
|
||||
|
||||
BUSMASTER_CTRL = 0x81; /* PARK[1,0]=10 + BCR24BIT */
|
||||
DIVR0 = 54; /* DMA0 is mapped into vector 54 in system.c */
|
||||
|
@ -300,10 +327,17 @@ void pcm_init(void)
|
|||
pcm_set_frequency(44100);
|
||||
|
||||
/* Turn on headphone power with audio output muted. */
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_mute(true);
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_mute(true);
|
||||
#endif
|
||||
sleep(HZ/4);
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_enable_output(true);
|
||||
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_enable_output(true);
|
||||
#endif
|
||||
/* Call dma_stop to initialize everything. */
|
||||
dma_stop();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,11 @@
|
|||
|
||||
#include "cpu.h"
|
||||
#include "i2c.h"
|
||||
#if defined(HAVE_UDA1380)
|
||||
#include "uda1380.h"
|
||||
#elif defined(HAVE_TLV320)
|
||||
#include "tlv320.h"
|
||||
#endif
|
||||
#include "system.h"
|
||||
#include "usb.h"
|
||||
|
||||
|
@ -222,10 +226,12 @@ void pcm_resume_recording(void)
|
|||
*/
|
||||
void pcm_set_recording_options(int source, bool enable_waveform)
|
||||
{
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_enable_recording(source);
|
||||
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_enable_recording(source);
|
||||
#endif
|
||||
show_waveform = enable_waveform;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -240,7 +246,6 @@ void pcm_set_recording_gain(int gain, int volume)
|
|||
rec_volume = volume;
|
||||
|
||||
queue_post(&pcmrec_queue, PCMREC_SET_GAIN, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,8 +279,6 @@ void pcm_stop_recording(void)
|
|||
}
|
||||
|
||||
logf("pcm_stop_recording done");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -374,8 +377,6 @@ void pcmrec_callback(bool flush)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void pcmrec_dma_start(void)
|
||||
{
|
||||
DAR1 = (unsigned long)rec_buffers[write_index++]; /* Destination address */
|
||||
|
@ -577,7 +578,11 @@ static void pcmrec_open(void)
|
|||
|
||||
static void pcmrec_close(void)
|
||||
{
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_disable_recording();
|
||||
#elif defined(HAVE_TLV320)
|
||||
tlv320_disable_recording();
|
||||
#endif
|
||||
|
||||
DMAROUTE = (DMAROUTE & 0xffff00ff);
|
||||
ICR4 = (ICR4 & 0xffffff00); /* Disable interrupt */
|
||||
|
@ -626,7 +631,11 @@ static void pcmrec_thread(void)
|
|||
break;
|
||||
|
||||
case PCMREC_SET_GAIN:
|
||||
#if defined(HAVE_UDA1380)
|
||||
uda1380_set_recvol(rec_gain, rec_gain, rec_volume);
|
||||
#elif defined(HAVE_TLV320)
|
||||
/* ToDo */
|
||||
#endif
|
||||
break;
|
||||
|
||||
case PCMREC_GOT_DATA:
|
||||
|
@ -639,7 +648,6 @@ static void pcmrec_thread(void)
|
|||
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
||||
usb_wait_for_disconnect(&pcmrec_queue);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#endif
|
||||
#ifdef HAVE_UDA1380
|
||||
#include "uda1380.h"
|
||||
#eilf HAVE_TLV320
|
||||
#include "tlv320.h"
|
||||
#endif
|
||||
#include "logf.h"
|
||||
|
||||
|
@ -903,6 +905,8 @@ void shutdown_hw(void)
|
|||
mp3_shutdown();
|
||||
#ifdef HAVE_UDA1380
|
||||
uda1380_close();
|
||||
#eilf HAVE_TLV320
|
||||
tlv320_close();
|
||||
#endif
|
||||
#if CONFIG_KEYPAD == ONDIO_PAD
|
||||
backlight_off();
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "mas.h"
|
||||
#ifdef HAVE_UDA1380
|
||||
#include "uda1380.h"
|
||||
#elif HAVE_TLV320
|
||||
#include "tlv320.h"
|
||||
#endif
|
||||
#include "dac.h"
|
||||
#include "system.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue