hm60x/hm801: Buttons rework.
[maemo-rb.git] / firmware / target / arm / sandisk / audio-c200_e200.c
blob4de7aa62c3f0222b7e9a83d1e22ab4ab997873ef
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 #ifdef HAVE_RECORDING
49 static bool last_recording = false;
50 bool recording = flags & SRCF_RECORDING;
51 #else
52 (void) flags;
53 #endif
55 switch (source)
57 default: /* playback - no recording */
58 source = AUDIO_SRC_PLAYBACK;
59 case AUDIO_SRC_PLAYBACK:
60 audio_channels = 2;
61 if (source != last_source)
63 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
64 audiohw_set_monitor(false);
65 #endif
66 #ifdef HAVE_RECORDING
67 audiohw_disable_recording();
68 #endif
70 break;
72 #if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_MIC)
73 case AUDIO_SRC_MIC: /* recording only */
74 audio_channels = 1;
75 if (source != last_source)
77 audiohw_set_monitor(false);
78 audiohw_enable_recording(true); /* source mic */
80 break;
81 #endif
83 #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
84 case AUDIO_SRC_FMRADIO: /* recording and playback */
85 audio_channels = 2;
87 if (source == last_source
88 #ifdef HAVE_RECORDING
89 && recording == last_recording
90 #endif
92 break;
94 #ifdef HAVE_RECORDING
95 last_recording = recording;
96 if (recording)
98 audiohw_set_monitor(false);
99 audiohw_enable_recording(false);
101 #endif
102 else
104 #ifdef HAVE_RECORDING
105 audiohw_disable_recording();
106 #endif
107 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
108 audiohw_set_monitor(true); /* line 1 analog audio path */
109 #endif
112 break;
113 #endif /* (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) */
114 } /* end switch */
116 last_source = source;
117 } /* audio_input_mux */
120 void audiohw_set_sampr_dividers(int fsel)
122 /* Seems to predivide 24MHz by 2 for a source clock of 12MHz. Maybe
123 * there's a way to set that? */
124 static const struct
126 unsigned char iisclk;
127 unsigned char iisdiv;
128 } regvals[HW_NUM_FREQ] =
130 /* 8kHz - 24kHz work well but there seems to be a minor crackling
131 * issue for playback at times and all possibilities were checked
132 * for the divisors without any positive change.
133 * 32kHz - 48kHz seem fine all around. */
134 #if 0
135 [HW_FREQ_8] = /* CLK / 1500 (8000Hz) */
137 .iisclk = 24,
138 .iisdiv = 59,
140 [HW_FREQ_11] = /* CLK / 1088 (~11029.41Hz) */
142 .iisclk = 33,
143 .iisdiv = 31,
145 [HW_FREQ_12] = /* CLK / 1000 (120000Hz) */
147 .iisclk = 49,
148 .iisdiv = 19,
150 [HW_FREQ_16] = /* CLK / 750 (16000Hz) */
152 .iisclk = 24,
153 .iisdiv = 29,
155 [HW_FREQ_22] = /* CLK / 544 (~22058.82Hz) */
157 .iisclk = 33,
158 .iisdiv = 15,
160 [HW_FREQ_24] = /* CLK / 500 (24000Hz) */
162 .iisclk = 49,
163 .iisdiv = 9,
165 #endif
166 [HW_FREQ_32] = /* CLK / 375 (32000Hz) */
168 .iisclk = 24,
169 .iisdiv = 14,
171 [HW_FREQ_44] = /* CLK / 272 (~44117.68Hz) */
173 .iisclk = 33,
174 .iisdiv = 7,
176 [HW_FREQ_48] = /* CLK / 250 (48000Hz) */
178 .iisclk = 49,
179 .iisdiv = 4,
181 /* going a bit higher would be nice to get 64kHz play, 32kHz rec, but a
182 * close enough division isn't obtainable unless CLK can be changed */
185 IISCLK = (IISCLK & ~0x17ff) | regvals[fsel].iisclk;
186 IISDIV = (IISDIV & ~0xc000003f) | regvals[fsel].iisdiv;
189 #ifdef CONFIG_SAMPR_TYPES
190 unsigned int pcm_sampr_to_hw_sampr(unsigned int samplerate,
191 unsigned int type)
193 #ifdef HAVE_RECORDING
194 if (samplerate != HW_SAMPR_RESET && type == SAMPR_TYPE_REC)
196 /* Check if the samplerate is in the list of recordable rates.
197 * Fail to default if not */
198 int index = round_value_to_list32(samplerate, rec_freq_sampr,
199 REC_NUM_FREQ, false);
200 if (samplerate != rec_freq_sampr[index])
201 samplerate = REC_SAMPR_DEFAULT;
203 samplerate *= 2; /* Recording rates are 1/2 the codec clock */
205 #endif /* HAVE_RECORDING */
207 return samplerate;
208 (void)type;
210 #endif /* CONFIG_SAMPR_TYPES */