diff options
Diffstat (limited to 'firmware/target/coldfire/iaudio/audio-iaudio.c')
-rw-r--r-- | firmware/target/coldfire/iaudio/audio-iaudio.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iaudio/audio-iaudio.c b/firmware/target/coldfire/iaudio/audio-iaudio.c new file mode 100644 index 0000000000..ed3a926d72 --- /dev/null +++ b/firmware/target/coldfire/iaudio/audio-iaudio.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Michael Sevakis | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "system.h" | ||
23 | #include "cpu.h" | ||
24 | #include "audio.h" | ||
25 | #include "sound.h" | ||
26 | |||
27 | void 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; | ||
38 | restore_irq(level); | ||
39 | } /* audio_set_output_source */ | ||
40 | |||
41 | void audio_input_mux(int source, unsigned flags) | ||
42 | { | ||
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; | ||
47 | |||
48 | bool recording = flags & SRCF_RECORDING; | ||
49 | #else | ||
50 | (void)flags; | ||
51 | #endif | ||
52 | |||
53 | switch (source) | ||
54 | { | ||
55 | default: /* playback - no recording */ | ||
56 | source = AUDIO_SRC_PLAYBACK; | ||
57 | case AUDIO_SRC_PLAYBACK: | ||
58 | if (source != last_source) | ||
59 | { | ||
60 | audiohw_disable_recording(); | ||
61 | audiohw_set_monitor(false); | ||
62 | coldfire_set_dataincontrol(0); | ||
63 | } | ||
64 | break; | ||
65 | |||
66 | case AUDIO_SRC_MIC: /* recording only */ | ||
67 | if (source != last_source) | ||
68 | { | ||
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)); | ||
72 | } | ||
73 | break; | ||
74 | |||
75 | case AUDIO_SRC_LINEIN: /* recording only */ | ||
76 | if (source != last_source) | ||
77 | { | ||
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)); | ||
81 | } | ||
82 | break; | ||
83 | |||
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); | ||
88 | |||
89 | /* I2S recording and analog playback */ | ||
90 | if (source == last_source && recording == last_recording) | ||
91 | break; | ||
92 | |||
93 | last_recording = recording; | ||
94 | |||
95 | if (recording) | ||
96 | { | ||
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 */ | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | audiohw_disable_recording(); | ||
104 | audiohw_set_monitor(true); /* analog bypass */ | ||
105 | coldfire_set_dataincontrol(0); | ||
106 | } | ||
107 | break; | ||
108 | #endif /* HAVE_FMRADIO_IN */ | ||
109 | } /* end switch */ | ||
110 | |||
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 */ | ||
119 | |||
120 | or_l((1 << 25), &GPIO1_ENABLE); | ||
121 | or_l((1 << 25), &GPIO1_FUNCTION); | ||
122 | |||
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 */ | ||
130 | |||
131 | or_l((1 << 29), &GPIO_ENABLE); | ||
132 | or_l((1 << 29), &GPIO_FUNCTION); | ||
133 | |||
134 | #endif /* iAudio M5, X5 */ | ||
135 | |||
136 | last_source = source; | ||
137 | } /* audio_input_mux */ | ||
138 | |||