summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Dziok <b0hoon@o2.pl>2014-07-12 16:31:44 +0000
committerSzymon Dziok <b0hoon@o2.pl>2014-07-26 15:36:12 +0000
commitfb373e1f50e8362ccff0db5b8818fbc0dca85b4c (patch)
treed5dc9c85a41cf0e2311833f115c525bed2bf1583
parentf734eedc1fc014d8358e2c4a26581eec38c2807d (diff)
downloadrockbox-fb373e1f50e8362ccff0db5b8818fbc0dca85b4c.tar.gz
rockbox-fb373e1f50e8362ccff0db5b8818fbc0dca85b4c.zip
Ak4537: Optimization of the code.
Change-Id: I98e25d7177b24b277a79d8bf8d494dac26553c2c
-rw-r--r--firmware/drivers/audio/ak4537.c138
1 files changed, 62 insertions, 76 deletions
diff --git a/firmware/drivers/audio/ak4537.c b/firmware/drivers/audio/ak4537.c
index a42b1346d2..67ce9e3ed9 100644
--- a/firmware/drivers/audio/ak4537.c
+++ b/firmware/drivers/audio/ak4537.c
@@ -221,120 +221,106 @@ void audiohw_set_frequency(int fsel)
221} 221}
222 222
223#if defined(HAVE_RECORDING) 223#if defined(HAVE_RECORDING)
224void audiohw_set_recsrc(int source) 224
225void akc_disable_mic(void)
225{ 226{
226 switch(source)
227 {
228 case AUDIO_SRC_PLAYBACK:
229 /* disable mic power supply */ 227 /* disable mic power supply */
230#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) 228#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
231 akc_clear(AK4537_MIC, MPWRE); 229 akc_clear(AK4537_MIC, MPWRE);
232#else 230#else
233 akc_clear(AK4537_MIC, MPWRI); 231 akc_clear(AK4537_MIC, MPWRI);
234#endif 232#endif
235 /* power down ADC, mic preamp and line amp */ 233 /* power down mic preamp */
236 akc_clear(AK4537_PM1, PMADL | PMMICL | PMIPGL); 234 akc_clear(AK4537_PM1, PMMICL);
237 akc_clear(AK4537_PM3, PMADR | PMMICR | PMIPGR); 235 akc_clear(AK4537_PM3, PMMICR);
238 236}
239 /* break ADC -> DAC connection */
240 akc_clear(AK4537_MODE2, LOOP);
241
242 break;
243 237
244#if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) 238void akc_enable_mic(void)
245 case AUDIO_SRC_FMRADIO: 239{
246 /* disable mic power supply */ 240 /* enable mic power supply */
247#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) 241#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
248 akc_clear(AK4537_MIC, MPWRE); 242 /* additionally select external mic */
243 akc_set(AK4537_MIC, MPWRE | MSEL);
249#else 244#else
250 akc_clear(AK4537_MIC, MPWRI); 245 akc_set(AK4537_MIC, MPWRI);
251#endif 246#endif
252 /* disable mic preamp */ 247 /* power up mic preamp */
253 akc_clear(AK4537_PM1, PMMICL); 248 akc_set(AK4537_PM1, PMMICL);
249}
254 250
255 /* Select line2 input: Radio */ 251void akc_setup_input(unsigned linesel, unsigned gcontrol)
256 akc_set(AK4537_PM3, INL | INR); 252{
253 /* select line1 or line2 input */
254 akc_write_masked(AK4537_PM3, linesel, INL | INR);
257 /* route ALC output to ADC input */ 255 /* route ALC output to ADC input */
258 akc_set(AK4537_MIC, MICAD); 256 akc_set(AK4537_MIC, MICAD);
259 /* set ALC (automatic level control) to manual mode */ 257 /* set ALC (automatic level control) to manual mode */
260 akc_clear(AK4537_ALC1, ALC1); 258 akc_clear(AK4537_ALC1, ALC1);
261 259 /* set gain control to dependent or independent left & right */
262 /* set gain control to independent left & right gain */ 260 akc_write_masked(AK4537_MIC, gcontrol, IPGAC);
263 akc_set(AK4537_MIC, IPGAC); 261 /* power up left channel ADC and line in */
264
265 /* power up left channel input and ADC */
266 akc_set(AK4537_PM1, PMADL | PMIPGL); 262 akc_set(AK4537_PM1, PMADL | PMIPGL);
267 /* power up right channel input and ADC */ 263 /* power up right channel ADC and line in */
268 akc_set(AK4537_PM3, PMADR | PMIPGR); 264 akc_set(AK4537_PM3, PMADR | PMIPGR);
265 /* ADC -> DAC, external data to DAC ignored */
266 akc_set(AK4537_MODE2, LOOP);
267}
268
269void audiohw_set_recsrc(int source)
270{
271 switch(source)
272 {
273 case AUDIO_SRC_PLAYBACK:
274
275 /* disable microphone */
276 akc_disable_mic();
277
278 /* power down ADC and line amp */
279 akc_clear(AK4537_PM1, PMADL | PMIPGL);
280 akc_clear(AK4537_PM3, PMADR | PMIPGR);
281
282 /* break ADC -> DAC connection */
283 akc_clear(AK4537_MODE2, LOOP);
284
285 break;
286
287#if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
288 case AUDIO_SRC_FMRADIO:
289
290 /* disable microphone */
291 akc_disable_mic();
292
293 /* Select line2 input, set gain control to independent left & right gain */
294 akc_setup_input(0xff, 0xff);
269 295
270 /* set line in vol = 0 dB */ 296 /* set line in vol = 0 dB */
271 akc_write(AK4537_IPGAL, 0x2f); 297 akc_write(AK4537_IPGAL, 0x2f);
272 akc_write(AK4537_IPGAR, 0x2f); 298 akc_write(AK4537_IPGAR, 0x2f);
273 299
274 /* ADC -> DAC, external data to DAC ignored */
275 akc_set(AK4537_MODE2, LOOP);
276
277 break; 300 break;
278#endif /* INPUT_SRC_CAPS & SRC_CAP_FMRADIO */ 301#endif /* INPUT_SRC_CAPS & SRC_CAP_FMRADIO */
279 302
280#if (INPUT_SRC_CAPS & SRC_CAP_LINEIN) 303#if (INPUT_SRC_CAPS & SRC_CAP_LINEIN)
281 case AUDIO_SRC_LINEIN: 304 case AUDIO_SRC_LINEIN:
282 /* disable mic power supply */
283#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
284 akc_clear(AK4537_MIC, MPWRE);
285#else
286 akc_clear(AK4537_MIC, MPWRI);
287#endif
288 /* disable mic preamp */
289 akc_clear(AK4537_PM1, PMMICL);
290
291 /* Select line1 input */
292 akc_clear(AK4537_PM3, INL | INR);
293 /* route ALC output to ADC input */
294 akc_set(AK4537_MIC, MICAD);
295 /* set ALC (automatic level control) to manual mode */
296 akc_clear(AK4537_ALC1, ALC1);
297 305
298 /* set gain control to independent left & right gain */ 306 /* disable microphone */
299 akc_set(AK4537_MIC, IPGAC); 307 akc_disable_mic();
300 308
301 /* power up left channel input and ADC */ 309 /* Select line1 input, set gain control to independent left & right gain */
302 akc_set(AK4537_PM1, PMADL | PMIPGL); 310 akc_setup_input(0x00, 0xff);
303 /* power up right channel input and ADC */
304 akc_set(AK4537_PM3, PMADR | PMIPGR);
305
306 /* ADC -> DAC, external data to DAC ignored */
307 akc_set(AK4537_MODE2, LOOP);
308 311
309 break; 312 break;
310#endif /* INPUT_SRC_CAPS & SRC_CAP_LINEIN */ 313#endif /* INPUT_SRC_CAPS & SRC_CAP_LINEIN */
311 314
312#if (INPUT_SRC_CAPS & SRC_CAP_MIC) 315#if (INPUT_SRC_CAPS & SRC_CAP_MIC)
313 case AUDIO_SRC_MIC: 316 case AUDIO_SRC_MIC:
314 /* enable mic power supply */
315#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
316 /* additionally select external mic */
317 akc_set(AK4537_MIC, MPWRE | MSEL);
318#else
319 akc_set(AK4537_MIC, MPWRI);
320#endif
321
322 /* mic out is connected to line1 input */
323 akc_clear(AK4537_PM3, INL | INR);
324 317
325 /* route ALC output to ADC input */ 318 /* enable micropohone */
326 akc_set(AK4537_MIC, MICAD); 319 akc_enable_mic();
327 /* set ALC (automatic level control) to manual mode */
328 akc_clear(AK4537_ALC1, ALC1);
329 /* set gain control to 'dependent' (left&right at the same time) */
330 akc_clear(AK4537_MIC, IPGAC);
331 /* power up mic preamp, left channel ADC and line in */
332 akc_set(AK4537_PM1, PMMICL | PMIPGL | PMADL);
333 /* power up right channel ADC and line in */
334 akc_set(AK4537_PM3, PMADR | PMIPGR);
335 320
336 /* ADC -> DAC, external data to DAC ignored */ 321 /* Select line1 input (mic connected), set gain control to 'dependent' */
337 akc_set(AK4537_MODE2, LOOP); 322 /* (left & right at the same time) */
323 akc_setup_input(0x00, 0x00);
338 324
339 break; 325 break;
340#endif /* INPUT_SRC_CAPS & SRC_CAP_MIC) */ 326#endif /* INPUT_SRC_CAPS & SRC_CAP_MIC) */