Fix beastpatcher on linux and code police.
[kugel-rb.git] / firmware / target / coldfire / iaudio / m3 / audio-m3.c
blobea401cc40eae011dd28d29173ef438f34fb63c9e
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 ****************************************************************************/
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 static bool last_recording = false;
47 bool recording = flags & SRCF_RECORDING;
49 switch (source)
51 default: /* playback - no recording */
52 source = AUDIO_SRC_PLAYBACK;
53 case AUDIO_SRC_PLAYBACK:
54 if (source != last_source)
56 audiohw_disable_recording();
57 audiohw_set_monitor(false);
58 coldfire_set_dataincontrol(0);
60 break;
62 case AUDIO_SRC_MIC: /* recording only */
63 if (source != last_source)
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));
69 break;
71 case AUDIO_SRC_LINEIN: /* recording only */
72 if (source != last_source)
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));
78 break;
80 case AUDIO_SRC_FMRADIO: /* recording and playback */
81 if (!recording)
82 audiohw_set_recvol(23, 23, AUDIO_GAIN_LINEIN);
84 /* I2S recording and analog playback */
85 if (source == last_source && recording == last_recording)
86 break;
88 last_recording = recording;
90 if (recording)
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 */
96 else
98 audiohw_disable_recording();
99 audiohw_set_monitor(true); /* analog bypass */
100 coldfire_set_dataincontrol(0);
102 break;
103 } /* end switch */
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 */
111 or_l((1 << 25), &GPIO1_ENABLE);
112 or_l((1 << 25), &GPIO1_FUNCTION);
114 last_source = source;
115 } /* audio_input_mux */