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
;
48 static bool last_recording
= false;
49 bool recording
= flags
& SRCF_RECORDING
;
53 default: /* playback - no recording */
54 source
= AUDIO_SRC_PLAYBACK
;
55 case AUDIO_SRC_PLAYBACK
:
57 if (source
!= last_source
)
59 audiohw_set_monitor(false);
60 audiohw_disable_recording();
64 case AUDIO_SRC_MIC
: /* recording only */
66 if (source
!= last_source
)
68 audiohw_set_monitor(false);
69 audiohw_enable_recording(true); /* source mic */
73 case AUDIO_SRC_FMRADIO
: /* recording and playback */
76 if (source
== last_source
&& recording
== last_recording
)
79 last_recording
= recording
;
83 audiohw_set_monitor(false);
84 audiohw_enable_recording(false);
88 audiohw_disable_recording();
89 audiohw_set_monitor(true); /* line 1 analog audio path */
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? */
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. */
113 [HW_FREQ_8
] = /* CLK / 1500 (8000Hz) */
118 [HW_FREQ_11
] = /* CLK / 1088 (~11029.41Hz) */
123 [HW_FREQ_12
] = /* CLK / 1000 (120000Hz) */
128 [HW_FREQ_16
] = /* CLK / 750 (16000Hz) */
133 [HW_FREQ_22
] = /* CLK / 544 (~22058.82Hz) */
138 [HW_FREQ_24
] = /* CLK / 500 (24000Hz) */
144 [HW_FREQ_32
] = /* CLK / 375 (32000Hz) */
149 [HW_FREQ_44
] = /* CLK / 272 (~44117.68Hz) */
154 [HW_FREQ_48
] = /* CLK / 250 (48000Hz) */
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 */