MPIO HD300 - initial commit
[maemo-rb.git] / firmware / target / coldfire / mpio / audio-mpio.c
blobba1258e5e74a38165becead050f15e0bdfa774db
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Marcin Bukat
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "system.h"
22 #include "cpu.h"
23 #include "audio.h"
24 #include "sound.h"
26 static inline void enable_mclk(bool enable)
28 if(enable)
29 and_l(~(1<<10), &GPIO1_FUNCTION);
30 else
31 or_l((1<<10), &GPIO1_FUNCTION);
34 void audio_set_output_source(int source)
36 static const unsigned char txsrc_select[AUDIO_NUM_SOURCES+1] =
38 [AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
39 #if (INPUT_SRC_CAPS & SRC_CAP_MIC)
40 [AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
41 #endif
42 #if (INPUT_SRC_CAPS & SRC_CAP_LINEIN)
43 [AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
44 #endif
45 #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
46 [AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
47 #endif
50 int level = set_irq_level(DMA_IRQ_LEVEL);
52 if ((unsigned)source >= AUDIO_NUM_SOURCES)
53 source = AUDIO_SRC_PLAYBACK;
55 /* route incoming audio samples to DAC */
56 IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8);
58 restore_irq(level);
61 void audio_input_mux(int source, unsigned flags)
63 /* Prevent pops from unneeded switching */
64 static int last_source = AUDIO_SRC_PLAYBACK;
65 bool recording = flags & SRCF_RECORDING;
66 static bool last_recording = false;
68 switch(source)
70 default:
71 /* playback - no recording */
72 source = AUDIO_SRC_PLAYBACK;
74 case AUDIO_SRC_PLAYBACK:
75 if (source != last_source)
77 audiohw_set_recsrc(source,false);
78 coldfire_set_dataincontrol(0);
80 break;
82 case AUDIO_SRC_MIC:
83 #if (INPUT_SRC_CAPS & SRC_CAP_LINEIN)
84 case AUDIO_SRC_LINEIN:
85 #endif
86 /* recording only */
87 if (source != last_source)
89 audiohw_set_recsrc(source,true);
90 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
91 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
93 break;
95 case AUDIO_SRC_FMRADIO:
96 if (source == last_source && recording == last_recording)
97 break;
99 last_recording = recording;
101 audiohw_set_recsrc(source,recording);
102 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
103 coldfire_set_dataincontrol(recording ?
104 ((3 << 14) | (4 << 3)) : 0);
105 break;
108 last_source = source;