Add iAudio M5 FM radio mod to the advanced build options. * Unify iAudio audio driver...
[kugel-rb.git] / firmware / target / coldfire / iaudio / audio-iaudio.c
blobed3a926d7255abd6a8a00e0fca43164f76e67634
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Michael Sevakis
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 "config.h"
22 #include "system.h"
23 #include "cpu.h"
24 #include "audio.h"
25 #include "sound.h"
27 void audio_set_output_source(int source)
29 int level = set_irq_level(DMA_IRQ_LEVEL);
30 unsigned long txsrc;
32 if ((unsigned)source >= AUDIO_NUM_SOURCES)
33 txsrc = (3 << 8); /* playback, PDOR3 */
34 else
35 txsrc = (4 << 8); /* recording, iis1RcvData */
37 IIS1CONFIG = (IIS1CONFIG & ~(7 << 8)) | txsrc;
38 restore_irq(level);
39 } /* audio_set_output_source */
41 void audio_input_mux(int source, unsigned flags)
43 /* Prevent pops from unneeded switching */
44 static int last_source = AUDIO_SRC_PLAYBACK;
45 #ifdef HAVE_FMRADIO_IN
46 static bool last_recording = false;
48 bool recording = flags & SRCF_RECORDING;
49 #else
50 (void)flags;
51 #endif
53 switch (source)
55 default: /* playback - no recording */
56 source = AUDIO_SRC_PLAYBACK;
57 case AUDIO_SRC_PLAYBACK:
58 if (source != last_source)
60 audiohw_disable_recording();
61 audiohw_set_monitor(false);
62 coldfire_set_dataincontrol(0);
64 break;
66 case AUDIO_SRC_MIC: /* recording only */
67 if (source != last_source)
69 audiohw_enable_recording(true); /* source mic */
70 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
71 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
73 break;
75 case AUDIO_SRC_LINEIN: /* recording only */
76 if (source != last_source)
78 audiohw_enable_recording(false); /* source line */
79 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
80 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
82 break;
84 #ifdef HAVE_FMRADIO_IN
85 case AUDIO_SRC_FMRADIO: /* recording and playback */
86 if (!recording)
87 audiohw_set_recvol(23, 23, AUDIO_GAIN_LINEIN);
89 /* I2S recording and analog playback */
90 if (source == last_source && recording == last_recording)
91 break;
93 last_recording = recording;
95 if (recording)
97 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
98 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
99 audiohw_enable_recording(false); /* source line */
101 else
103 audiohw_disable_recording();
104 audiohw_set_monitor(true); /* analog bypass */
105 coldfire_set_dataincontrol(0);
107 break;
108 #endif /* HAVE_FMRADIO_IN */
109 } /* end switch */
111 /* set line multiplexer */
112 #ifdef IAUDIO_M3
113 #ifdef HAVE_FMRADIO_IN
114 if (source == AUDIO_SRC_FMRADIO)
115 and_l(~(1 << 25), &GPIO1_OUT); /* FM radio */
116 else
117 #endif
118 or_l((1 << 25), &GPIO1_OUT); /* Line In */
120 or_l((1 << 25), &GPIO1_ENABLE);
121 or_l((1 << 25), &GPIO1_FUNCTION);
123 #else /* iAudio M5, X5 */
124 #ifdef HAVE_FMRADIO_IN
125 if (source == AUDIO_SRC_FMRADIO)
126 and_l(~(1 << 29), &GPIO_OUT); /* FM radio */
127 else
128 #endif
129 or_l((1 << 29), &GPIO_OUT); /* Line In */
131 or_l((1 << 29), &GPIO_ENABLE);
132 or_l((1 << 29), &GPIO_FUNCTION);
134 #endif /* iAudio M5, X5 */
136 last_source = source;
137 } /* audio_input_mux */