Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Marcin Bukat | 082c7d3 | 2010-10-22 12:28:43 +0000 | [diff] [blame^] | 8 | * $Id$ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 9 | * |
| 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 Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 26 | static 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 Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 34 | void audio_set_output_source(int source) |
| 35 | { |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 36 | 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 Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 43 | |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 44 | int level = set_irq_level(DMA_IRQ_LEVEL); |
| 45 | |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 46 | if ((unsigned)source >= AUDIO_NUM_SOURCES) |
| 47 | source = AUDIO_SRC_PLAYBACK; |
| 48 | |
Marcin Bukat | 971a6e9 | 2010-07-02 21:09:28 +0000 | [diff] [blame] | 49 | /* route incoming audio samples to DAC */ |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 50 | IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 51 | |
| 52 | restore_irq(level); |
| 53 | } |
| 54 | |
| 55 | void audio_input_mux(int source, unsigned flags) |
| 56 | { |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 57 | /* 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 Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 61 | |
| 62 | switch(source) |
| 63 | { |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 64 | 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 Bukat | 971a6e9 | 2010-07-02 21:09:28 +0000 | [diff] [blame] | 77 | case AUDIO_SRC_LINEIN: |
| 78 | /* recording only */ |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 79 | 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 Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 87 | case AUDIO_SRC_FMRADIO: |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 88 | if (source == last_source && recording == last_recording) |
| 89 | break; |
| 90 | |
| 91 | last_recording = recording; |
| 92 | |
Marcin Bukat | 971a6e9 | 2010-07-02 21:09:28 +0000 | [diff] [blame] | 93 | audiohw_set_recsrc(source,recording); |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 94 | /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */ |
| 95 | coldfire_set_dataincontrol(recording ? |
| 96 | ((3 << 14) | (4 << 3)) : 0); |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 97 | break; |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 98 | } |
Marcin Bukat | c740af2 | 2010-04-29 13:14:43 +0000 | [diff] [blame] | 99 | |
| 100 | last_source = source; |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 101 | } |