e200v1/c200v1: Implement limited samplerate switching. Rates 24kHz and below are...
[kugel-rb.git] / firmware / target / arm / sandisk / audio-c200_e200.c
blob0037bac58b969d52fb50d0b8edc70a387c9a4956
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 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 ****************************************************************************/
21 #include "system.h"
22 #include "cpu.h"
23 #include "audio.h"
24 #include "sound.h"
25 #include "general.h"
27 int audio_channels = 2;
28 int audio_output_source = AUDIO_SRC_PLAYBACK;
30 void audio_set_output_source(int source)
32 int oldmode = set_fiq_status(FIQ_DISABLED);
34 if ((unsigned)source >= AUDIO_NUM_SOURCES)
35 source = AUDIO_SRC_PLAYBACK;
37 audio_output_source = source;
39 if (source != AUDIO_SRC_PLAYBACK)
40 IISCONFIG |= (1 << 29);
42 set_fiq_status(oldmode);
43 } /* audio_set_output_source */
45 void audio_input_mux(int source, unsigned flags)
47 static int last_source = AUDIO_SRC_PLAYBACK;
48 static bool last_recording = false;
49 bool recording = flags & SRCF_RECORDING;
51 switch (source)
53 default: /* playback - no recording */
54 source = AUDIO_SRC_PLAYBACK;
55 case AUDIO_SRC_PLAYBACK:
56 audio_channels = 2;
57 if (source != last_source)
59 audiohw_set_monitor(false);
60 audiohw_disable_recording();
62 break;
64 case AUDIO_SRC_MIC: /* recording only */
65 audio_channels = 1;
66 if (source != last_source)
68 audiohw_set_monitor(false);
69 audiohw_enable_recording(true); /* source mic */
71 break;
73 case AUDIO_SRC_FMRADIO: /* recording and playback */
74 audio_channels = 2;
76 if (source == last_source && recording == last_recording)
77 break;
79 last_recording = recording;
81 if (recording)
83 audiohw_set_monitor(false);
84 audiohw_enable_recording(false);
86 else
88 audiohw_disable_recording();
89 audiohw_set_monitor(true); /* line 1 analog audio path */
91 break;
92 } /* end switch */
94 last_source = source;
95 } /* audio_input_mux */
98 void audiohw_set_sampr_dividers(int fsel)
100 /* Seems to predivide 24MHz by 2 for a source clock of 12MHz. Maybe
101 * there's a way to set that? */
102 static const struct
104 unsigned char iisclk;
105 unsigned char iisdiv;
106 } regvals[HW_NUM_FREQ] =
108 /* 8kHz - 24kHz work well but there seems to be a minor crackling
109 * issue for playback at times and all possibilities were checked
110 * for the divisors without any positive change.
111 * 32kHz - 48kHz seem fine all around. */
112 #if 0
113 [HW_FREQ_8] = /* CLK / 1500 (8000Hz) */
115 .iisclk = 24,
116 .iisdiv = 59,
118 [HW_FREQ_11] = /* CLK / 1088 (~11029.41Hz) */
120 .iisclk = 33,
121 .iisdiv = 31,
123 [HW_FREQ_12] = /* CLK / 1000 (120000Hz) */
125 .iisclk = 49,
126 .iisdiv = 19,
128 [HW_FREQ_16] = /* CLK / 750 (16000Hz) */
130 .iisclk = 24,
131 .iisdiv = 29,
133 [HW_FREQ_22] = /* CLK / 544 (~22058.82Hz) */
135 .iisclk = 33,
136 .iisdiv = 15,
138 [HW_FREQ_24] = /* CLK / 500 (24000Hz) */
140 .iisclk = 49,
141 .iisdiv = 9,
143 #endif
144 [HW_FREQ_32] = /* CLK / 375 (32000Hz) */
146 .iisclk = 24,
147 .iisdiv = 14,
149 [HW_FREQ_44] = /* CLK / 272 (~44117.68Hz) */
151 .iisclk = 33,
152 .iisdiv = 7,
154 [HW_FREQ_48] = /* CLK / 250 (48000Hz) */
156 .iisclk = 49,
157 .iisdiv = 4,
159 /* going a bit higher would be nice to get 64kHz play, 32kHz rec, but a
160 * close enough division isn't obtainable unless CLK can be changed */
163 IISCLK = (IISCLK & ~0x17ff) | regvals[fsel].iisclk;
164 IISDIV = (IISDIV & ~0xc000003f) | regvals[fsel].iisdiv;
167 unsigned int pcm_sampr_type_rec_to_play(unsigned int samplerate)
169 /* Check if the samplerate is in the list of recordable rates.
170 * Fail to default if not */
171 int index = round_value_to_list32(samplerate, rec_freq_sampr,
172 REC_NUM_FREQ, false);
173 if (samplerate != rec_freq_sampr[index])
174 return HW_SAMPR_DEFAULT;
176 return samplerate * 2; /* Recording rates are 1/2 the codec clock */