blob: ea401cc40eae011dd28d29173ef438f34fb63c9e [file] [log] [blame]
Jens Arnold8a6291d2008-03-14 08:54:54 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Michael Sevakis
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Jens Arnold8a6291d2008-03-14 08:54:54 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "system.h"
23#include "cpu.h"
24#include "audio.h"
25#include "sound.h"
26
27void audio_set_output_source(int source)
28{
29 int level = set_irq_level(DMA_IRQ_LEVEL);
30 unsigned long txsrc;
31
32 if ((unsigned)source >= AUDIO_NUM_SOURCES)
33 txsrc = (3 << 8); /* playback, PDOR3 */
34 else
35 txsrc = (4 << 8); /* recording, iis1RcvData */
36
37 IIS1CONFIG = (IIS1CONFIG & ~(7 << 8)) | txsrc;
Michael Sevakisaf395f42008-03-26 01:50:41 +000038 restore_irq(level);
Jens Arnold8a6291d2008-03-14 08:54:54 +000039} /* audio_set_output_source */
40
41void audio_input_mux(int source, unsigned flags)
42{
43 /* Prevent pops from unneeded switching */
44 static int last_source = AUDIO_SRC_PLAYBACK;
45 static bool last_recording = false;
46
47 bool recording = flags & SRCF_RECORDING;
48
49 switch (source)
50 {
51 default: /* playback - no recording */
52 source = AUDIO_SRC_PLAYBACK;
53 case AUDIO_SRC_PLAYBACK:
54 if (source != last_source)
55 {
56 audiohw_disable_recording();
57 audiohw_set_monitor(false);
58 coldfire_set_dataincontrol(0);
59 }
60 break;
61
62 case AUDIO_SRC_MIC: /* recording only */
63 if (source != last_source)
64 {
65 audiohw_enable_recording(true); /* source mic */
66 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
67 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
68 }
69 break;
70
71 case AUDIO_SRC_LINEIN: /* recording only */
72 if (source != last_source)
73 {
74 audiohw_enable_recording(false); /* source line */
75 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
76 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
77 }
78 break;
79
80 case AUDIO_SRC_FMRADIO: /* recording and playback */
81 if (!recording)
82 audiohw_set_recvol(23, 23, AUDIO_GAIN_LINEIN);
83
84 /* I2S recording and analog playback */
85 if (source == last_source && recording == last_recording)
86 break;
87
88 last_recording = recording;
89
90 if (recording)
91 {
92 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
93 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
94 audiohw_enable_recording(false); /* source line */
95 }
96 else
97 {
98 audiohw_disable_recording();
99 audiohw_set_monitor(true); /* analog bypass */
100 coldfire_set_dataincontrol(0);
101 }
102 break;
103 } /* end switch */
104
105 /* set line multiplexer */
106 if (source == AUDIO_SRC_FMRADIO)
107 and_l(~(1 << 25), &GPIO1_OUT); /* FM radio */
108 else
109 or_l((1 << 25), &GPIO1_OUT); /* Line In */
110
111 or_l((1 << 25), &GPIO1_ENABLE);
112 or_l((1 << 25), &GPIO1_FUNCTION);
113
114 last_source = source;
115} /* audio_input_mux */
116