Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Michael Sevakis |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 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" |
Michael Sevakis | 36c9405 | 2006-12-17 11:03:19 +0000 | [diff] [blame] | 24 | #include "sound.h" |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 25 | |
| 26 | void audio_set_output_source(int source) |
| 27 | { |
Michael Sevakis | 633f388 | 2007-03-07 06:23:02 +0000 | [diff] [blame] | 28 | int level = set_irq_level(DMA_IRQ_LEVEL); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 29 | unsigned long txsrc; |
| 30 | |
| 31 | if ((unsigned)source >= AUDIO_NUM_SOURCES) |
| 32 | txsrc = (3 << 8); /* playback, PDOR3 */ |
| 33 | else |
| 34 | txsrc = (4 << 8); /* recording, iis1RcvData */ |
| 35 | |
| 36 | IIS1CONFIG = (IIS1CONFIG & ~(7 << 8)) | txsrc; |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 37 | restore_irq(level); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 38 | } /* audio_set_output_source */ |
| 39 | |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 40 | void audio_input_mux(int source, unsigned flags) |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 41 | { |
| 42 | /* Prevent pops from unneeded switching */ |
| 43 | static int last_source = AUDIO_SRC_PLAYBACK; |
| 44 | static bool last_recording = false; |
| 45 | |
| 46 | bool recording = flags & SRCF_RECORDING; |
| 47 | |
| 48 | switch (source) |
| 49 | { |
| 50 | default: /* playback - no recording */ |
| 51 | source = AUDIO_SRC_PLAYBACK; |
| 52 | case AUDIO_SRC_PLAYBACK: |
| 53 | if (source != last_source) |
| 54 | { |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 55 | audiohw_disable_recording(); |
| 56 | audiohw_set_monitor(false); |
Michael Sevakis | 8867d00 | 2007-03-05 08:14:27 +0000 | [diff] [blame] | 57 | coldfire_set_dataincontrol(0); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 58 | } |
| 59 | break; |
| 60 | |
| 61 | case AUDIO_SRC_MIC: /* recording only */ |
| 62 | if (source != last_source) |
| 63 | { |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 64 | audiohw_enable_recording(true); /* source mic */ |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 65 | /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */ |
Michael Sevakis | 8867d00 | 2007-03-05 08:14:27 +0000 | [diff] [blame] | 66 | coldfire_set_dataincontrol((3 << 14) | (4 << 3)); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 67 | } |
| 68 | break; |
| 69 | |
| 70 | case AUDIO_SRC_LINEIN: /* recording only */ |
| 71 | if (source != last_source) |
| 72 | { |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 73 | audiohw_enable_recording(false); /* source line */ |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 74 | /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */ |
Michael Sevakis | 8867d00 | 2007-03-05 08:14:27 +0000 | [diff] [blame] | 75 | coldfire_set_dataincontrol((3 << 14) | (4 << 3)); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 76 | } |
| 77 | break; |
| 78 | |
| 79 | case AUDIO_SRC_FMRADIO: /* recording and playback */ |
| 80 | if (!recording) |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 81 | audiohw_set_recvol(23, 23, AUDIO_GAIN_LINEIN); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 82 | |
| 83 | /* I2S recording and analog playback */ |
| 84 | if (source == last_source && recording == last_recording) |
| 85 | break; |
| 86 | |
| 87 | last_recording = recording; |
| 88 | |
| 89 | if (recording) |
| 90 | { |
| 91 | /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */ |
Michael Sevakis | 8867d00 | 2007-03-05 08:14:27 +0000 | [diff] [blame] | 92 | coldfire_set_dataincontrol((3 << 14) | (4 << 3)); |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 93 | audiohw_enable_recording(false); /* source line */ |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 94 | } |
| 95 | else |
| 96 | { |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 97 | audiohw_disable_recording(); |
| 98 | audiohw_set_monitor(true); /* analog bypass */ |
Michael Sevakis | 8867d00 | 2007-03-05 08:14:27 +0000 | [diff] [blame] | 99 | coldfire_set_dataincontrol(0); |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 100 | } |
| 101 | break; |
| 102 | } /* end switch */ |
| 103 | |
| 104 | /* set line multiplexer */ |
| 105 | if (source == AUDIO_SRC_FMRADIO) |
| 106 | and_l(~(1 << 29), &GPIO_OUT); /* FM radio */ |
| 107 | else |
| 108 | or_l((1 << 29), &GPIO_OUT); /* Line In */ |
| 109 | |
| 110 | or_l((1 << 29), &GPIO_ENABLE); |
| 111 | or_l((1 << 29), &GPIO_FUNCTION); |
| 112 | |
| 113 | last_source = source; |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 114 | } /* audio_input_mux */ |
Michael Sevakis | ab1861a | 2006-11-23 19:21:15 +0000 | [diff] [blame] | 115 | |