1
0
Fork 0
forked from len0rd/rockbox

Ak4537: Optimization of the code.

Change-Id: I98e25d7177b24b277a79d8bf8d494dac26553c2c
This commit is contained in:
Szymon Dziok 2014-07-12 16:31:44 +00:00
parent f734eedc1f
commit fb373e1f50

View file

@ -221,20 +221,63 @@ void audiohw_set_frequency(int fsel)
} }
#if defined(HAVE_RECORDING) #if defined(HAVE_RECORDING)
void audiohw_set_recsrc(int source)
void akc_disable_mic(void)
{ {
switch(source)
{
case AUDIO_SRC_PLAYBACK:
/* disable mic power supply */ /* disable mic power supply */
#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) #if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
akc_clear(AK4537_MIC, MPWRE); akc_clear(AK4537_MIC, MPWRE);
#else #else
akc_clear(AK4537_MIC, MPWRI); akc_clear(AK4537_MIC, MPWRI);
#endif #endif
/* power down ADC, mic preamp and line amp */ /* power down mic preamp */
akc_clear(AK4537_PM1, PMADL | PMMICL | PMIPGL); akc_clear(AK4537_PM1, PMMICL);
akc_clear(AK4537_PM3, PMADR | PMMICR | PMIPGR); akc_clear(AK4537_PM3, PMMICR);
}
void akc_enable_mic(void)
{
/* enable mic power supply */
#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
/* additionally select external mic */
akc_set(AK4537_MIC, MPWRE | MSEL);
#else
akc_set(AK4537_MIC, MPWRI);
#endif
/* power up mic preamp */
akc_set(AK4537_PM1, PMMICL);
}
void akc_setup_input(unsigned linesel, unsigned gcontrol)
{
/* select line1 or line2 input */
akc_write_masked(AK4537_PM3, linesel, INL | INR);
/* route ALC output to ADC input */
akc_set(AK4537_MIC, MICAD);
/* set ALC (automatic level control) to manual mode */
akc_clear(AK4537_ALC1, ALC1);
/* set gain control to dependent or independent left & right */
akc_write_masked(AK4537_MIC, gcontrol, IPGAC);
/* power up left channel ADC and line in */
akc_set(AK4537_PM1, PMADL | PMIPGL);
/* power up right channel ADC and line in */
akc_set(AK4537_PM3, PMADR | PMIPGR);
/* ADC -> DAC, external data to DAC ignored */
akc_set(AK4537_MODE2, LOOP);
}
void audiohw_set_recsrc(int source)
{
switch(source)
{
case AUDIO_SRC_PLAYBACK:
/* disable microphone */
akc_disable_mic();
/* power down ADC and line amp */
akc_clear(AK4537_PM1, PMADL | PMIPGL);
akc_clear(AK4537_PM3, PMADR | PMIPGR);
/* break ADC -> DAC connection */ /* break ADC -> DAC connection */
akc_clear(AK4537_MODE2, LOOP); akc_clear(AK4537_MODE2, LOOP);
@ -243,98 +286,41 @@ void audiohw_set_recsrc(int source)
#if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
case AUDIO_SRC_FMRADIO: case AUDIO_SRC_FMRADIO:
/* disable mic power supply */
#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
akc_clear(AK4537_MIC, MPWRE);
#else
akc_clear(AK4537_MIC, MPWRI);
#endif
/* disable mic preamp */
akc_clear(AK4537_PM1, PMMICL);
/* Select line2 input: Radio */ /* disable microphone */
akc_set(AK4537_PM3, INL | INR); akc_disable_mic();
/* route ALC output to ADC input */
akc_set(AK4537_MIC, MICAD);
/* set ALC (automatic level control) to manual mode */
akc_clear(AK4537_ALC1, ALC1);
/* set gain control to independent left & right gain */ /* Select line2 input, set gain control to independent left & right gain */
akc_set(AK4537_MIC, IPGAC); akc_setup_input(0xff, 0xff);
/* power up left channel input and ADC */
akc_set(AK4537_PM1, PMADL | PMIPGL);
/* power up right channel input and ADC */
akc_set(AK4537_PM3, PMADR | PMIPGR);
/* set line in vol = 0 dB */ /* set line in vol = 0 dB */
akc_write(AK4537_IPGAL, 0x2f); akc_write(AK4537_IPGAL, 0x2f);
akc_write(AK4537_IPGAR, 0x2f); akc_write(AK4537_IPGAR, 0x2f);
/* ADC -> DAC, external data to DAC ignored */
akc_set(AK4537_MODE2, LOOP);
break; break;
#endif /* INPUT_SRC_CAPS & SRC_CAP_FMRADIO */ #endif /* INPUT_SRC_CAPS & SRC_CAP_FMRADIO */
#if (INPUT_SRC_CAPS & SRC_CAP_LINEIN) #if (INPUT_SRC_CAPS & SRC_CAP_LINEIN)
case AUDIO_SRC_LINEIN: case AUDIO_SRC_LINEIN:
/* disable mic power supply */
#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
akc_clear(AK4537_MIC, MPWRE);
#else
akc_clear(AK4537_MIC, MPWRI);
#endif
/* disable mic preamp */
akc_clear(AK4537_PM1, PMMICL);
/* Select line1 input */ /* disable microphone */
akc_clear(AK4537_PM3, INL | INR); akc_disable_mic();
/* route ALC output to ADC input */
akc_set(AK4537_MIC, MICAD);
/* set ALC (automatic level control) to manual mode */
akc_clear(AK4537_ALC1, ALC1);
/* set gain control to independent left & right gain */ /* Select line1 input, set gain control to independent left & right gain */
akc_set(AK4537_MIC, IPGAC); akc_setup_input(0x00, 0xff);
/* power up left channel input and ADC */
akc_set(AK4537_PM1, PMADL | PMIPGL);
/* power up right channel input and ADC */
akc_set(AK4537_PM3, PMADR | PMIPGR);
/* ADC -> DAC, external data to DAC ignored */
akc_set(AK4537_MODE2, LOOP);
break; break;
#endif /* INPUT_SRC_CAPS & SRC_CAP_LINEIN */ #endif /* INPUT_SRC_CAPS & SRC_CAP_LINEIN */
#if (INPUT_SRC_CAPS & SRC_CAP_MIC) #if (INPUT_SRC_CAPS & SRC_CAP_MIC)
case AUDIO_SRC_MIC: case AUDIO_SRC_MIC:
/* enable mic power supply */
#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
/* additionally select external mic */
akc_set(AK4537_MIC, MPWRE | MSEL);
#else
akc_set(AK4537_MIC, MPWRI);
#endif
/* mic out is connected to line1 input */ /* enable micropohone */
akc_clear(AK4537_PM3, INL | INR); akc_enable_mic();
/* route ALC output to ADC input */ /* Select line1 input (mic connected), set gain control to 'dependent' */
akc_set(AK4537_MIC, MICAD); /* (left & right at the same time) */
/* set ALC (automatic level control) to manual mode */ akc_setup_input(0x00, 0x00);
akc_clear(AK4537_ALC1, ALC1);
/* set gain control to 'dependent' (left&right at the same time) */
akc_clear(AK4537_MIC, IPGAC);
/* power up mic preamp, left channel ADC and line in */
akc_set(AK4537_PM1, PMMICL | PMIPGL | PMADL);
/* power up right channel ADC and line in */
akc_set(AK4537_PM3, PMADR | PMIPGR);
/* ADC -> DAC, external data to DAC ignored */
akc_set(AK4537_MODE2, LOOP);
break; break;
#endif /* INPUT_SRC_CAPS & SRC_CAP_MIC) */ #endif /* INPUT_SRC_CAPS & SRC_CAP_MIC) */