AMS SoC's: Some register bit changes need interrupt protection: timer API and CGU_PERI.
[kugel-rb.git] / firmware / target / arm / as3525 / audio-as3525.c
blob10c61618815677ea60cb66212840e93be0d45e4e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 by Bertrik Sikken
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 ****************************************************************************/
21 #include "config.h"
22 #include "system.h"
23 #include "cpu.h"
24 #include "audio.h"
25 #include "audiohw.h"
26 #include "sound.h"
28 int audio_channels = 2;
30 void audio_set_output_source(int source)
32 bitset32(&CGU_PERI, CGU_I2SOUT_APB_CLOCK_ENABLE);
33 if (source == AUDIO_SRC_PLAYBACK)
34 I2SOUT_CONTROL &= ~(1<<5);
35 else
36 I2SOUT_CONTROL |= 1<<5; /* source = loopback from i2sin fifo */
39 void audio_input_mux(int source, unsigned flags)
41 static int last_source = AUDIO_SRC_PLAYBACK;
42 #if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
43 static bool last_recording = false;
44 const bool recording = flags & SRCF_RECORDING;
45 #else
46 (void) flags;
47 #endif
49 switch (source)
51 default: /* playback - no recording */
52 source = AUDIO_SRC_PLAYBACK;
53 case AUDIO_SRC_PLAYBACK:
54 if (source != last_source)
56 audio_channels = 2;
57 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
58 audiohw_set_monitor(false);
59 #endif
60 #ifdef HAVE_RECORDING
61 audiohw_disable_recording();
62 #endif
64 break;
66 #if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_MIC)
67 case AUDIO_SRC_MIC: /* recording only */
68 if (source != last_source)
70 audio_channels = 1;
71 audiohw_set_monitor(false);
72 audiohw_enable_recording(true); /* source mic */
74 break;
75 #endif
77 #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
79 case AUDIO_SRC_FMRADIO: /* recording and playback */
80 if (source == last_source
81 #ifdef HAVE_RECORDING
82 && recording == last_recording
83 #endif
85 break;
87 audio_channels = 2;
88 #ifdef HAVE_RECORDING
89 last_recording = recording;
91 if (recording)
93 audiohw_set_monitor(false);
94 audiohw_enable_recording(false);
96 else
97 #endif
99 #ifdef HAVE_RECORDING
100 audiohw_disable_recording();
101 #endif
102 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
103 audiohw_set_monitor(true); /* line 2 analog audio path */
104 #endif
106 break;
107 #endif /* (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) */
110 last_source = source;