1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
;
49 static bool last_recording
= false;
50 bool recording
= flags
& SRCF_RECORDING
;
57 default: /* playback - no recording */
58 source
= AUDIO_SRC_PLAYBACK
;
59 case AUDIO_SRC_PLAYBACK
:
61 if (source
!= last_source
)
63 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
64 audiohw_set_monitor(false);
67 audiohw_disable_recording();
72 #if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_MIC)
73 case AUDIO_SRC_MIC
: /* recording only */
75 if (source
!= last_source
)
77 audiohw_set_monitor(false);
78 audiohw_enable_recording(true); /* source mic */
83 #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
84 case AUDIO_SRC_FMRADIO
: /* recording and playback */
87 if (source
== last_source
89 && recording
== last_recording
95 last_recording
= recording
;
98 audiohw_set_monitor(false);
99 audiohw_enable_recording(false);
104 #ifdef HAVE_RECORDING
105 audiohw_disable_recording();
107 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
108 audiohw_set_monitor(true); /* line 1 analog audio path */
113 #endif /* (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) */
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? */
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. */
135 [HW_FREQ_8
] = /* CLK / 1500 (8000Hz) */
140 [HW_FREQ_11
] = /* CLK / 1088 (~11029.41Hz) */
145 [HW_FREQ_12
] = /* CLK / 1000 (120000Hz) */
150 [HW_FREQ_16
] = /* CLK / 750 (16000Hz) */
155 [HW_FREQ_22
] = /* CLK / 544 (~22058.82Hz) */
160 [HW_FREQ_24
] = /* CLK / 500 (24000Hz) */
166 [HW_FREQ_32
] = /* CLK / 375 (32000Hz) */
171 [HW_FREQ_44
] = /* CLK / 272 (~44117.68Hz) */
176 [HW_FREQ_48
] = /* CLK / 250 (48000Hz) */
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
,
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 */
210 #endif /* CONFIG_SAMPR_TYPES */