iRiver/iAudio: Added audio_set_recording gain and sound_default to plugin API. Simplified plugin recording by target/-ing some audio functions. UDA1380 records with WSPLL as a result.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11577 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2006-11-23 19:21:15 +00:00
parent 069c54d5d8
commit ab1861a3c2
13 changed files with 330 additions and 263 deletions

View File

@ -456,22 +456,25 @@ static const struct plugin_api rockbox_api = {
#ifdef HAVE_RECORDING
&rec_freq_sampr[0],
#ifndef SIMULATOR
pcm_set_monitor,
pcm_set_rec_source,
pcm_init_recording,
pcm_close_recording,
pcm_record_data,
pcm_stop_recording,
pcm_calculate_rec_peaks,
audio_set_recording_gain,
audio_set_output_source,
rec_set_source,
#endif
#endif /* HAVE_RECORDING */
#endif /* CONFIG_CODEC == SWCODEC */
#ifdef IRAM_STEAL
plugin_iram_init,
#endif
#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(SIMULATOR)
sound_default,
#endif
};
int plugin_load(const char* plugin, void* parameter)

View File

@ -568,25 +568,27 @@ struct plugin_api {
#ifdef HAVE_RECORDING
const unsigned long *rec_freq_sampr;
#ifndef SIMULATOR
void (*pcm_set_monitor)(int monitor);
void (*pcm_set_rec_source)(int source);
void (*pcm_init_recording)(void);
void (*pcm_close_recording)(void);
void (*pcm_record_data)(pcm_more_callback_type more_ready,
unsigned char *start, size_t size);
void (*pcm_stop_recording)(void);
void (*pcm_calculate_rec_peaks)(int *left, int *right);
void (*audio_set_recording_gain)(int left, int right, int type);
void (*audio_set_output_source)(int monitor);
void (*rec_set_source)(int source, unsigned flags);
#endif
#endif /* HAVE_RECORDING */
#endif /* CONFIG_CODEC == SWCODEC */
#ifdef IRAM_STEAL
void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
char *iedata, size_t iedata_size);
#endif
#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(SIMULATOR)
int (*sound_default)(int setting);
#endif
};
/* plugin header */

View File

@ -38,12 +38,6 @@
#include "spdif.h"
#endif
#endif /* CONFIG_CODEC == SWCODEC */
#ifdef HAVE_UDA1380
#include "uda1380.h"
#endif
#ifdef HAVE_TLV320
#include "tlv320.h"
#endif
#include "recording.h"
#include "mp3_playback.h"
#include "mas.h"
@ -580,36 +574,14 @@ static void rec_boost(bool state)
* The order of setting monitoring may need tweaking dependent upon the
* selected source to get the smoothest transition.
*/
#if defined(HAVE_UDA1380)
#define ac_disable_recording uda1380_disable_recording
#define ac_enable_recording uda1380_enable_recording
#define ac_set_monitor uda1380_set_monitor
#elif defined(HAVE_TLV320)
#define ac_disable_recording tlv320_disable_recording
#define ac_enable_recording tlv320_enable_recording
#define ac_set_monitor tlv320_set_monitor
#endif
void rec_set_source(int source, unsigned flags)
{
/* Prevent pops from unneeded switching */
static int last_source = AUDIO_SRC_PLAYBACK;
#ifdef HAVE_TLV320
static bool last_recording = false;
#endif
bool recording = flags & SRCF_RECORDING;
/* Default to peakmeter record. */
bool pm_playback = false;
bool pm_enabled = true;
/** Do power up/down of associated device(s) **/
/** SPDIF **/
#ifdef HAVE_SPDIF_IN
/* Always boost for SPDIF */
if ((source == AUDIO_SRC_SPDIF) != (source == last_source))
rec_boost(source == AUDIO_SRC_SPDIF);
rec_boost(source == AUDIO_SRC_SPDIF);
#endif /* HAVE_SPDIF_IN */
#ifdef HAVE_SPDIF_POWER
@ -639,87 +611,11 @@ void rec_set_source(int source, unsigned flags)
radio_start();
#endif
switch (source)
{
default: /* playback - no recording */
source = AUDIO_SRC_PLAYBACK;
case AUDIO_SRC_PLAYBACK:
pm_playback = true;
if (source == last_source)
break;
ac_disable_recording();
ac_set_monitor(false);
pcm_rec_mux(0); /* line in */
break;
/* set hardware inputs */
audio_set_source(source, flags);
case AUDIO_SRC_MIC: /* recording only */
if (source == last_source)
break;
ac_enable_recording(true); /* source mic */
pcm_rec_mux(0); /* line in */
break;
case AUDIO_SRC_LINEIN: /* recording only */
if (source == last_source)
break;
pcm_rec_mux(0); /* line in */
ac_enable_recording(false); /* source line */
break;
#ifdef HAVE_SPDIF_IN
case AUDIO_SRC_SPDIF: /* recording only */
if (source == last_source)
break;
ac_disable_recording();
break;
#endif /* HAVE_SPDIF_IN */
#ifdef HAVE_FMRADIO_IN
case AUDIO_SRC_FMRADIO: /* recording and playback */
if (!recording)
{
audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
pm_playback = true;
pm_enabled = false;
}
pcm_rec_mux(1); /* fm radio */
#ifdef HAVE_UDA1380
if (source == last_source)
break;
/* I2S recording and playback */
uda1380_enable_recording(false); /* source line */
uda1380_set_monitor(true);
#endif
#ifdef HAVE_TLV320
/* I2S recording and analog playback */
if (source == last_source && recording == last_recording)
break;
last_recording = recording;
if (recording)
tlv320_enable_recording(false); /* source line */
else
{
tlv320_disable_recording();
tlv320_set_monitor(true); /* analog bypass */
}
#endif
break;
/* #elif defined(CONFIG_TUNER) */
/* Have radio but cannot record it */
/* case AUDIO_SRC_FMRADIO: */
/* break; */
#endif /* HAVE_FMRADIO_IN */
} /* end switch */
peak_meter_playback(pm_playback);
peak_meter_enabled = pm_enabled;
last_source = source;
peak_meter_playback((flags & SRCF_RECORDING) == 0);
peak_meter_enabled = true;
} /* rec_set_source */
#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */

View File

@ -24,14 +24,7 @@ char *rec_create_filename(char *buf);
int rec_create_directory(void);
#if CONFIG_CODEC == SWCODEC
/* selects an audio source for recording or playback */
#define SRCF_PLAYBACK 0x0000 /* default */
#define SRCF_RECORDING 0x1000
#ifdef CONFIG_TUNER
/* for AUDIO_SRC_FMRADIO */
#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
#define SRCF_FMRADIO_PAUSED 0x2000
#endif
/* handles device powerup and sets audio source */
void rec_set_source(int source, unsigned flags);
#endif /* CONFIG_CODEC == SW_CODEC */

View File

@ -324,6 +324,7 @@ target/coldfire/iaudio/x5/power-x5.c
target/coldfire/pcf50606-coldfire.c
target/coldfire/iaudio/x5/adc-x5.c
target/coldfire/iaudio/x5/ata-x5.c
target/coldfire/iaudio/x5/audio-x5.c
target/coldfire/iaudio/x5/backlight-x5.c
target/coldfire/iaudio/x5/button-x5.c
target/coldfire/iaudio/x5/lcd-as-x5.S
@ -348,6 +349,7 @@ target/coldfire/iriver/h300/power-h300.c
#ifndef SIMULATOR
target/coldfire/pcf50606-coldfire.c
target/coldfire/iriver/ata-iriver.c
target/coldfire/iriver/audio-iriver.c
target/coldfire/iriver/system-iriver.c
target/coldfire/iriver/h300/adc-h300.c
target/coldfire/iriver/h300/backlight-h300.c
@ -363,6 +365,7 @@ target/coldfire/iriver/h300/usb-h300.c
target/coldfire/iriver/h100/power-h100.c
#ifndef SIMULATOR
target/coldfire/iriver/ata-iriver.c
target/coldfire/iriver/audio-iriver.c
target/coldfire/iriver/system-iriver.c
target/coldfire/iriver/h100/adc-h100.c
target/coldfire/iriver/h100/backlight-h100.c

View File

@ -272,7 +272,7 @@ void uda1380_enable_recording(bool source_mic)
{
/* VGA_GAIN: 0=0 dB, F=30dB */
/* Output of left ADC is fed into right bitstream */
uda1380_regs[REG_PWR] &= ~(PON_PLL | PON_PGAR | PON_ADCR);
uda1380_regs[REG_PWR] &= ~(PON_PGAR | PON_ADCR);
uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_LNA | PON_ADCL);
uda1380_regs[REG_ADC] &= ~SKIP_DCFIL;
uda1380_write_reg(REG_ADC, (uda1380_regs[REG_ADC] & VGA_GAIN_MASK)
@ -282,7 +282,7 @@ void uda1380_enable_recording(bool source_mic)
else
{
/* PGA_GAIN: 0=0 dB, F=24dB */
uda1380_regs[REG_PWR] &= ~(PON_PLL | PON_LNA);
uda1380_regs[REG_PWR] &= ~PON_LNA;
uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_PGAL | PON_ADCL
| PON_PGAR | PON_ADCR);
uda1380_write_reg(REG_ADC, EN_DCFIL);
@ -305,8 +305,9 @@ void uda1380_disable_recording(void)
uda1380_write_reg(REG_I2S, I2S_IFMT_IIS);
uda1380_regs[REG_PWR] &= ~(PON_LNA | PON_ADCL | PON_ADCR | PON_PGAL | PON_PGAR);
uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_PLL);
uda1380_regs[REG_PWR] &= ~(PON_LNA | PON_ADCL | PON_ADCR |
PON_PGAL | PON_PGAR);
uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR]);
uda1380_regs[REG_0] &= ~EN_ADC;
uda1380_write_reg(REG_0, uda1380_regs[REG_0] | ADC_CLK | DAC_CLK);

View File

@ -150,6 +150,17 @@ enum audio_sources
AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1
};
#if CONFIG_CODEC == SWCODEC
/* selects an audio source for recording or playback */
#define SRCF_PLAYBACK 0x0000 /* default */
#define SRCF_RECORDING 0x1000
#ifdef CONFIG_TUNER
/* for AUDIO_SRC_FMRADIO */
#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
#define SRCF_FMRADIO_PAUSED 0x2000
#endif
#endif
#ifdef HAVE_RECORDING
/* parameters for audio_set_recording_options */
struct audio_recording_options
@ -186,6 +197,8 @@ unsigned long audio_num_recorded_bytes(void);
bool audio_load_encoder(int afmt);
void audio_remove_encoder(void);
unsigned char *audio_get_recording_buffer(size_t *buffer_size);
void audio_set_source(int source, unsigned flags);
void audio_set_output_source(int source);
#endif /* CONFIG_CODEC == SWCODEC */
#endif /* HAVE_RECORDING */

View File

@ -24,9 +24,6 @@
#ifdef HAVE_SPDIF_IN
#define DMA_REC_ERROR_SPDIF ((size_t)-2)
#endif
/* Use AUDIO_SRC_* enumeration values */
void pcm_set_monitor(int monitor);
void pcm_set_rec_source(int source);
/**
* RAW pcm data recording
@ -55,7 +52,6 @@ void pcm_calculate_rec_peaks(int *left, int *right);
results for consistency with the hardware codec version */
/* unsigned long pcm_rec_status(void); */
void pcm_rec_init(void);
void pcm_rec_mux(int source);
int pcm_rec_current_bitrate(void);
int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */
int pcm_rec_rec_format(void); /* Format index or -1 otherwise */

View File

@ -597,11 +597,6 @@ void pcm_apply_settings(bool reset)
{
(void)reset;
}
void pcm_set_monitor(int monitor)
{
(void)monitor;
}
/** **/
void pcm_mute(bool mute)

View File

@ -323,13 +323,9 @@ void audio_close_recording(void)
pcm_thread_wait_for_stop();
pcm_thread_sync_post(PCMREC_CLOSE, NULL);
/* reset pcm to defaults (playback only) */
pcm_set_frequency(-1);
pcm_set_monitor(-1);
pcm_set_rec_source(-1);
#ifdef HAVE_TLV320
/* tlv320 screeches if left at 88.2 with no inputs */
pcm_set_frequency(HW_SAMPR_DEFAULT);
audio_set_output_source(AUDIO_SRC_PLAYBACK);
pcm_apply_settings(true);
#endif
audio_remove_encoder();
} /* audio_close_recording */
@ -408,12 +404,12 @@ void audio_set_recording_options(struct audio_recording_options *options)
pcm_set_frequency(sample_rate);
}
pcm_set_monitor(rec_source);
pcm_set_rec_source(rec_source);
/* set monitoring */
audio_set_output_source(rec_source);
/* apply pcm settings to hardware */
pcm_apply_settings(true);
if (audio_load_encoder(enc_config.afmt))
{
/* start DMA transfer */
@ -425,26 +421,9 @@ void audio_set_recording_options(struct audio_recording_options *options)
{
logf("set rec opt: enc load failed");
is_error = true;
}
}
} /* audio_set_recording_options */
/**
* Note that microphone is mono, only left value is used
* See {uda1380,tlv320}_set_recvol() for exact ranges.
*
* @param type 0=line-in (radio), 1=mic
*
*/
void audio_set_recording_gain(int left, int right, int type)
{
//logf("rcmrec: t=%d l=%d r=%d", type, left, right);
#if defined(HAVE_UDA1380)
uda1380_set_recvol(left, right, type);
#elif defined (HAVE_TLV320)
tlv320_set_recvol(left, right, type);
#endif
} /* audio_set_recording_gain */
/**
* Start recording
*

View File

@ -0,0 +1,126 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006 by Michael Sevakis
*
* 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 "system.h"
#include "cpu.h"
#include "audio.h"
#include "tlv320.h"
/**
* Note that microphone is mono, only left value is used
* See tlv320_set_recvol() for exact ranges.
*
* @param type 0=line-in (radio), 1=mic
*
*/
void audio_set_recording_gain(int left, int right, int type)
{
//logf("rcmrec: t=%d l=%d r=%d", type, left, right);
tlv320_set_recvol(left, right, type);
} /* audio_set_recording_gain */
void audio_set_output_source(int source)
{
unsigned long txsrc;
if ((unsigned)source >= AUDIO_NUM_SOURCES)
txsrc = (3 << 8); /* playback, PDOR3 */
else
txsrc = (4 << 8); /* recording, iis1RcvData */
IIS1CONFIG = (IIS1CONFIG & ~(7 << 8)) | txsrc;
} /* audio_set_output_source */
void audio_set_source(int source, unsigned flags)
{
/* Prevent pops from unneeded switching */
static int last_source = AUDIO_SRC_PLAYBACK;
static bool last_recording = false;
bool recording = flags & SRCF_RECORDING;
switch (source)
{
default: /* playback - no recording */
source = AUDIO_SRC_PLAYBACK;
case AUDIO_SRC_PLAYBACK:
if (source != last_source)
{
tlv320_disable_recording();
tlv320_set_monitor(false);
/* Reset PDIR2 data flow */
DATAINCONTROL = (1 << 9);
}
break;
case AUDIO_SRC_MIC: /* recording only */
if (source != last_source)
{
tlv320_enable_recording(true); /* source mic */
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
}
break;
case AUDIO_SRC_LINEIN: /* recording only */
if (source != last_source)
{
tlv320_enable_recording(false); /* source line */
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
}
break;
case AUDIO_SRC_FMRADIO: /* recording and playback */
if (!recording)
tlv320_set_recvol(23, 23, AUDIO_GAIN_LINEIN);
/* I2S recording and analog playback */
if (source == last_source && recording == last_recording)
break;
last_recording = recording;
if (recording)
{
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
tlv320_enable_recording(false); /* source line */
}
else
{
tlv320_disable_recording();
tlv320_set_monitor(true); /* analog bypass */
/* Reset PDIR2 data flow */
DATAINCONTROL = (1 << 9);
}
break;
} /* end switch */
/* set line multiplexer */
if (source == AUDIO_SRC_FMRADIO)
and_l(~(1 << 29), &GPIO_OUT); /* FM radio */
else
or_l((1 << 29), &GPIO_OUT); /* Line In */
or_l((1 << 29), &GPIO_ENABLE);
or_l((1 << 29), &GPIO_FUNCTION);
last_source = source;
} /* audio_set_source */

View File

@ -0,0 +1,148 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006 by Michael Sevakis
*
* 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 "system.h"
#include "cpu.h"
#include "audio.h"
#include "uda1380.h"
/**
* Note that microphone is mono, only left value is used
* See uda1380_set_recvol() for exact ranges.
*
* @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN
*
*/
void audio_set_recording_gain(int left, int right, int type)
{
//logf("rcmrec: t=%d l=%d r=%d", type, left, right);
uda1380_set_recvol(left, right, type);
} /* audio_set_recording_gain */
void audio_set_output_source(int source)
{
static const unsigned char txsrc_select[AUDIO_NUM_SOURCES+1] =
{
[AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
[AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
[AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
[AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
#ifdef HAVE_SPDIF_IN
[AUDIO_SRC_SPDIF+1] = 7, /* EBU1 RcvData */
#endif
};
if ((unsigned)source >= AUDIO_NUM_SOURCES)
source = AUDIO_SRC_PLAYBACK;
IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8);
} /* audio_set_output_source */
void audio_set_source(int source, unsigned flags)
{
/* Prevent pops from unneeded switching */
static int last_source = AUDIO_SRC_PLAYBACK;
bool recording = flags & SRCF_RECORDING;
switch (source)
{
default: /* playback - no recording */
source = AUDIO_SRC_PLAYBACK;
case AUDIO_SRC_PLAYBACK:
if (source != last_source)
{
uda1380_disable_recording();
uda1380_set_monitor(false);
/* Reset PDIR2 data flow */
DATAINCONTROL = (1 << 9);
}
break;
case AUDIO_SRC_MIC: /* recording only */
if (source != last_source)
{
uda1380_enable_recording(true); /* source mic */
uda1380_set_monitor(true);
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
}
break;
case AUDIO_SRC_LINEIN: /* recording only */
if (source != last_source)
{
uda1380_enable_recording(false); /* source line */
uda1380_set_monitor(true);
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
}
break;
#ifdef HAVE_SPDIF_IN
case AUDIO_SRC_SPDIF: /* recording only */
if (source != last_source)
{
uda1380_disable_recording();
uda1380_set_monitor(false);
/* Int. when 6 samples in FIFO, PDIR2 src = ebu1RcvData */
DATAINCONTROL = (3 << 14) | (7 << 3);
}
break;
#endif /* HAVE_SPDIF_IN */
case AUDIO_SRC_FMRADIO: /* recording and playback */
if (recording)
{
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
DATAINCONTROL = (3 << 14) | (4 << 3);
}
else
{
uda1380_set_recvol(0, 0, AUDIO_GAIN_LINEIN);
/* Reset PDIR2 data flow */
DATAINCONTROL = (1 << 9);
}
if (source != last_source)
{
/* I2S recording and playback */
uda1380_enable_recording(false); /* source line */
uda1380_set_monitor(true);
}
break;
} /* end switch */
/* set line multiplexer */
#if defined(IRIVER_H100_SERIES)
#define MUX_BIT (1 << 23)
#elif defined(IRIVER_H300_SERIES)
#define MUX_BIT (1 << 30)
#endif
if (source == AUDIO_SRC_FMRADIO)
or_l(MUX_BIT, &GPIO_OUT); /* FM radio */
else
and_l(~MUX_BIT, &GPIO_OUT); /* Line In */
or_l(MUX_BIT, &GPIO_ENABLE);
or_l(MUX_BIT, &GPIO_FUNCTION);
last_source = source;
} /* audio_set_source */

View File

@ -57,9 +57,9 @@ static int play_peak_left, play_peak_right;
static unsigned long *rec_peak_addr;
static int rec_peak_left, rec_peak_right;
#define IIS_DEFPARM ( (freq_ent[FPARM_CLOCKSEL] << 12) | \
(pcm_txsrc_select[pcm_monitor+1] << 8) | \
(4 << 2) ) /* 64 bit clocks / word clock */
#define IIS_DEFPARM(output) ( (freq_ent[FPARM_CLOCKSEL] << 12) | \
(output) | \
(4 << 2) ) /* 64 bit clocks / word clock */
#define IIS_RESET 0x800
#ifdef IAUDIO_X5
@ -128,80 +128,22 @@ void pcm_set_frequency(unsigned int frequency)
pcm_freq = hw_freq_sampr[index];
} /* pcm_set_frequency */
/** monitoring/source selection **/
static int pcm_monitor = AUDIO_SRC_PLAYBACK;
static const unsigned char pcm_txsrc_select[AUDIO_NUM_SOURCES+1] =
{
[AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
[AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
[AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
#ifdef HAVE_FMRADIO_IN
[AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
#endif
#ifdef HAVE_SPDIF_IN
[AUDIO_SRC_SPDIF+1] = 7, /* EBU1 RcvData */
#endif
};
static const unsigned short pcm_dataincontrol[AUDIO_NUM_SOURCES+1] =
{
[AUDIO_SRC_PLAYBACK+1] = 0x0200, /* Reset PDIR2 data flow */
[AUDIO_SRC_MIC+1] = 0xc020, /* Int. when 6 samples in FIFO,
PDIR2 src = ebu1RcvData */
[AUDIO_SRC_LINEIN+1] = 0xc020, /* Int. when 6 samples in FIFO,
PDIR2 src = ebu1RcvData */
#ifdef HAVE_FMRADIO_IN
[AUDIO_SRC_FMRADIO+1] = 0xc020, /* Int. when 6 samples in FIFO,
PDIR2 src = ebu1RcvData */
#endif
#ifdef HAVE_SPDIF_IN
[AUDIO_SRC_SPDIF+1] = 0xc038, /* Int. when 6 samples in FIFO,
PDIR2 src = ebu1RcvData */
#endif
};
static int pcm_rec_src = AUDIO_SRC_PLAYBACK;
void pcm_set_monitor(int monitor)
{
if ((unsigned)monitor >= AUDIO_NUM_SOURCES)
monitor = AUDIO_SRC_PLAYBACK;
pcm_monitor = monitor;
} /* pcm_set_monitor */
void pcm_set_rec_source(int source)
{
if ((unsigned)source >= AUDIO_NUM_SOURCES)
source = AUDIO_SRC_PLAYBACK;
pcm_rec_src = source;
} /* pcm_set_rec_source */
/* apply audio settings */
void pcm_apply_settings(bool reset)
{
static int last_pcm_freq = HW_SAMPR_DEFAULT;
#if 0
static int last_pcm_monitor = AUDIO_SRC_PLAYBACK;
#endif
static int last_pcm_rec_src = AUDIO_SRC_PLAYBACK;
static int last_pcm_freq = HW_SAMPR_DEFAULT;
unsigned long output = IIS_CONFIG & (7 << 8);
/* Playback must prevent pops and record monitoring won't work at all
/* Playback must prevent pops and record monitoring won't work at all if
adding IIS_RESET when setting IIS_CONFIG. Use a different method for
each. */
if (reset && (pcm_monitor != AUDIO_SRC_PLAYBACK))
if (reset && output != (3 << 8))
{
/* Not playback - reset first */
SET_IIS_CONFIG(IIS_RESET);
reset = false;
}
if (pcm_rec_src != last_pcm_rec_src)
{
last_pcm_rec_src = pcm_rec_src;
DATAINCONTROL = pcm_dataincontrol[pcm_rec_src+1];
}
if (pcm_freq != last_pcm_freq)
{
last_pcm_freq = pcm_freq;
@ -209,7 +151,7 @@ void pcm_apply_settings(bool reset)
coldfire_set_pllcr_audio_bits(PLLCR_SET_AUDIO_BITS_DEFPARM);
}
SET_IIS_CONFIG(IIS_DEFPARM | (reset ? IIS_RESET : 0));
SET_IIS_CONFIG(IIS_DEFPARM(output) | (reset ? IIS_RESET : 0));
} /* pcm_apply_settings */
/** DMA **/
@ -270,11 +212,10 @@ void pcm_init(void)
/* Reset the audio FIFO */
SET_IIS_CONFIG(IIS_RESET);
pcm_set_frequency(-1);
pcm_set_monitor(-1);
pcm_set_frequency(HW_FREQ_DEFAULT);
/* Prevent pops (resets DAC to zero point) */
SET_IIS_CONFIG(IIS_DEFPARM | IIS_RESET);
SET_IIS_CONFIG(IIS_DEFPARM(3 << 8) | IIS_RESET);
#if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
spdif_init();
@ -443,7 +384,7 @@ void DMA1(void)
logf("DMA1 err: 0x%x", res);
}
#ifdef HAVE_SPDIF_IN
else if (pcm_rec_src == AUDIO_SRC_SPDIF &&
else if (DATAINCONTROL == 0xc038 &&
(INTERRUPTSTAT & 0x01c00000)) /* valnogood, symbolerr, parityerr */
{
INTERRUPTCLEAR = 0x03c00000;
@ -685,32 +626,3 @@ peak_done:
if (right)
*right = rec_peak_right;
} /* pcm_calculate_rec_peaks */
/**
* Select VINL & VINR source: 0=Line-in, 1=FM Radio
*/
/* All use GPIO */
#if defined(IAUDIO_X5)
#define REC_MUX_BIT (1 << 29)
#define REC_MUX_SET_LINE() or_l(REC_MUX_BIT, &GPIO_OUT)
#define REC_MUX_SET_FM() and_l(~REC_MUX_BIT, &GPIO_OUT)
#else
#if defined(IRIVER_H100_SERIES)
#define REC_MUX_BIT (1 << 23)
#elif defined(IRIVER_H300_SERIES)
#define REC_MUX_BIT (1 << 30)
#endif
#define REC_MUX_SET_LINE() and_l(~REC_MUX_BIT, &GPIO_OUT)
#define REC_MUX_SET_FM() or_l(REC_MUX_BIT, &GPIO_OUT)
#endif
void pcm_rec_mux(int source)
{
if (source == 0)
REC_MUX_SET_LINE(); /* Line In */
else
REC_MUX_SET_FM(); /* FM radio */
or_l(REC_MUX_BIT, &GPIO_ENABLE);
or_l(REC_MUX_BIT, &GPIO_FUNCTION);
} /* pcm_rec_mux */