blob: 4455281267e16bce2d195f42f2e99ebbcdffed9d [file] [log] [blame]
Marcin Bukat28d54c62010-04-26 21:40:16 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Marcin Bukat082c7d32010-10-22 12:28:43 +00008 * $Id$
Marcin Bukat28d54c62010-04-26 21:40:16 +00009 *
10 * Copyright (C) 2010 Marcin Bukat
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 "system.h"
22#include "cpu.h"
23#include "audio.h"
24#include "sound.h"
25
Marcin Bukatc740af22010-04-29 13:14:43 +000026static inline void enable_mclk(bool enable)
27{
28 if(enable)
29 and_l(~(1<<10), &GPIO1_FUNCTION);
30 else
31 or_l((1<<10), &GPIO1_FUNCTION);
32}
33
Marcin Bukat28d54c62010-04-26 21:40:16 +000034void audio_set_output_source(int source)
35{
Marcin Bukatc740af22010-04-29 13:14:43 +000036 static const unsigned char txsrc_select[AUDIO_NUM_SOURCES+1] =
37 {
38 [AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
39 [AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
40 [AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
41 [AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
42 };
Marcin Bukat28d54c62010-04-26 21:40:16 +000043
Marcin Bukat28d54c62010-04-26 21:40:16 +000044 int level = set_irq_level(DMA_IRQ_LEVEL);
45
Marcin Bukatc740af22010-04-29 13:14:43 +000046 if ((unsigned)source >= AUDIO_NUM_SOURCES)
47 source = AUDIO_SRC_PLAYBACK;
48
Marcin Bukat971a6e92010-07-02 21:09:28 +000049 /* route incoming audio samples to DAC */
Marcin Bukatc740af22010-04-29 13:14:43 +000050 IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8);
Marcin Bukat28d54c62010-04-26 21:40:16 +000051
52 restore_irq(level);
53}
54
55void audio_input_mux(int source, unsigned flags)
56{
Marcin Bukatc740af22010-04-29 13:14:43 +000057 /* Prevent pops from unneeded switching */
58 static int last_source = AUDIO_SRC_PLAYBACK;
59 bool recording = flags & SRCF_RECORDING;
60 static bool last_recording = false;
Marcin Bukat28d54c62010-04-26 21:40:16 +000061
62 switch(source)
63 {
Marcin Bukatc740af22010-04-29 13:14:43 +000064 default:
65 /* playback - no recording */
66 source = AUDIO_SRC_PLAYBACK;
67
68 case AUDIO_SRC_PLAYBACK:
69 if (source != last_source)
70 {
71 audiohw_set_recsrc(source,false);
72 coldfire_set_dataincontrol(0);
73 }
74 break;
75
76 case AUDIO_SRC_MIC:
Marcin Bukat971a6e92010-07-02 21:09:28 +000077 case AUDIO_SRC_LINEIN:
78 /* recording only */
Marcin Bukatc740af22010-04-29 13:14:43 +000079 if (source != last_source)
80 {
81 audiohw_set_recsrc(source,true);
82 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
83 coldfire_set_dataincontrol((3 << 14) | (4 << 3));
84 }
85 break;
86
Marcin Bukat28d54c62010-04-26 21:40:16 +000087 case AUDIO_SRC_FMRADIO:
Marcin Bukatc740af22010-04-29 13:14:43 +000088 if (source == last_source && recording == last_recording)
89 break;
90
91 last_recording = recording;
92
Marcin Bukat971a6e92010-07-02 21:09:28 +000093 audiohw_set_recsrc(source,recording);
Marcin Bukatc740af22010-04-29 13:14:43 +000094 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
95 coldfire_set_dataincontrol(recording ?
96 ((3 << 14) | (4 << 3)) : 0);
Marcin Bukatc740af22010-04-29 13:14:43 +000097 break;
Marcin Bukat28d54c62010-04-26 21:40:16 +000098 }
Marcin Bukatc740af22010-04-29 13:14:43 +000099
100 last_source = source;
Marcin Bukat28d54c62010-04-26 21:40:16 +0000101}