2010-04-26 21:40:16 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id:$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Marcin Bukat
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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 "sound.h"
|
|
|
|
|
2010-04-29 13:14:43 +00:00
|
|
|
static inline void enable_mclk(bool enable)
|
|
|
|
{
|
|
|
|
if(enable)
|
|
|
|
and_l(~(1<<10), &GPIO1_FUNCTION);
|
|
|
|
else
|
|
|
|
or_l((1<<10), &GPIO1_FUNCTION);
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
void audio_set_output_source(int source)
|
|
|
|
{
|
2010-04-29 13:14:43 +00:00
|
|
|
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 */
|
|
|
|
};
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
int level = set_irq_level(DMA_IRQ_LEVEL);
|
|
|
|
|
2010-04-29 13:14:43 +00:00
|
|
|
if ((unsigned)source >= AUDIO_NUM_SOURCES)
|
|
|
|
source = AUDIO_SRC_PLAYBACK;
|
|
|
|
|
2010-07-02 21:09:28 +00:00
|
|
|
/* route incoming audio samples to DAC */
|
2010-04-29 13:14:43 +00:00
|
|
|
IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8);
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
restore_irq(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_input_mux(int source, unsigned flags)
|
|
|
|
{
|
2010-04-29 13:14:43 +00:00
|
|
|
/* Prevent pops from unneeded switching */
|
|
|
|
static int last_source = AUDIO_SRC_PLAYBACK;
|
|
|
|
bool recording = flags & SRCF_RECORDING;
|
|
|
|
static bool last_recording = false;
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
switch(source)
|
|
|
|
{
|
2010-04-29 13:14:43 +00:00
|
|
|
default:
|
|
|
|
/* playback - no recording */
|
|
|
|
source = AUDIO_SRC_PLAYBACK;
|
|
|
|
|
|
|
|
case AUDIO_SRC_PLAYBACK:
|
|
|
|
if (source != last_source)
|
|
|
|
{
|
|
|
|
audiohw_set_recsrc(source,false);
|
|
|
|
coldfire_set_dataincontrol(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_SRC_MIC:
|
2010-07-02 21:09:28 +00:00
|
|
|
case AUDIO_SRC_LINEIN:
|
|
|
|
/* recording only */
|
2010-04-29 13:14:43 +00:00
|
|
|
if (source != last_source)
|
|
|
|
{
|
|
|
|
audiohw_set_recsrc(source,true);
|
|
|
|
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
|
|
|
|
coldfire_set_dataincontrol((3 << 14) | (4 << 3));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
case AUDIO_SRC_FMRADIO:
|
2010-04-29 13:14:43 +00:00
|
|
|
if (source == last_source && recording == last_recording)
|
|
|
|
break;
|
|
|
|
|
|
|
|
last_recording = recording;
|
|
|
|
|
2010-07-02 21:09:28 +00:00
|
|
|
audiohw_set_recsrc(source,recording);
|
2010-04-29 13:14:43 +00:00
|
|
|
/* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
|
|
|
|
coldfire_set_dataincontrol(recording ?
|
|
|
|
((3 << 14) | (4 << 3)) : 0);
|
|
|
|
break;
|
2010-04-26 21:40:16 +00:00
|
|
|
}
|
2010-04-29 13:14:43 +00:00
|
|
|
|
|
|
|
last_source = source;
|
2010-04-26 21:40:16 +00:00
|
|
|
}
|