diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2010-05-19 17:30:38 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2010-05-19 17:30:38 +0000 |
commit | 9c774b3849b397345040fa064081368e17ed663e (patch) | |
tree | 81200e464b13442891e770920019b8623407d785 /firmware/drivers/audio | |
parent | 9fbd7fd9c9ef4d2ef52556af7479866521018048 (diff) |
as3514.c: clean up
- enhance registers description in header file with respect to the as3543
registers: point which one are present or not in the as3543, which bits
change (i didn't detail all registers)
- cache less registers, only up to the ones which are written to
multiple times
- use ascodec_readbytes() to cache all needed registers in a row
- separate the as3543 bits from as3514/as3515 in audiohw_preinit()
- comment out unused audiohw_set_lineout_vol
- some cosmetics
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26174 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/audio')
-rw-r--r-- | firmware/drivers/audio/as3514.c | 124 |
1 files changed, 56 insertions, 68 deletions
diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c index ac3350eb47..3b0a7cf087 100644 --- a/firmware/drivers/audio/as3514.c +++ b/firmware/drivers/audio/as3514.c @@ -88,19 +88,10 @@ static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */ */ static void as3514_write(unsigned int reg, unsigned int value) { - if (ascodec_write(reg, value) != 2) - { - DEBUGF("as3514 error reg=0x%02x", reg); - } + ascodec_write(reg, value); - if (reg < ARRAYLEN(as3514_regs)) - { + if (reg < AS3514_NUM_AUDIO_REGS) as3514_regs[reg] = value; - } - else - { - DEBUGF("as3514 error reg=0x%02x", reg); - } } /* Helpers to set/clear bits */ @@ -135,24 +126,18 @@ int tenthdb2master(int db) int sound_val2phys(int setting, int value) { - int result; - switch(setting) { #if defined(HAVE_RECORDING) case SOUND_LEFT_GAIN: case SOUND_RIGHT_GAIN: case SOUND_MIC_GAIN: - result = (value - 23) * 15; - break; + return (value - 23) * 15; #endif default: - result = value; - break; + return value; } - - return result; } /* @@ -160,28 +145,49 @@ int sound_val2phys(int setting, int value) */ void audiohw_preinit(void) { - unsigned int i; - /* read all reg values */ - for (i = 0; i < ARRAYLEN(as3514_regs); i++) - { - as3514_regs[i] = ascodec_read(i); - } + ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs); - /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ +#ifdef HAVE_AS3543 + + as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_DAC_GAIN_on); + as3514_write(AS3514_AUDIOSET2, AUDIOSET2_HPH_QUALITY_LOW_POWER); + /* common ground on, delay playback unmuting when inserting headphones */ + as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_on | AUDIOSET3_HP_LONGSTART); + + as3514_write(AS3543_DAC_IF, AS3543_DAC_INT_PLL); + /* Select Line 2 for FM radio */ + as3514_set(AS3514_LINE_IN1_R, LINE_IN_R_LINE_SELECT); + /* Output SUM of microphone/line/DAC */ + as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HEADPHONES | HPH_OUT_R_HP_OUT_SUM); + +#else + /* as3514/as3515 */ + /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ /* Turn on SUM, DAC */ as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_SUM_on); -#ifdef HAVE_AS3543 - as3514_write(AS3514_AUDIOSET2, AUDIOSET2_HPH_QUALITY_LOW_POWER); -#else /* Set BIAS on, DITH off, AGC off, IBR_DAC max reduction, LSP_LP on, IBR_LSP max reduction (50%), taken from c200v2 OF */ as3514_write(AS3514_AUDIOSET2, AUDIOSET2_IBR_LSP_50 | AUDIOSET2_LSP_LP | AUDIOSET2_IBR_DAC_50 | AUDIOSET2_AGC_off | AUDIOSET2_DITH_off ); -#endif + + /* Mute and disable speaker */ + as3514_write(AS3514_LSP_OUT_R, LSP_OUT_R_SP_OVC_TO_256MS | 0x00); + as3514_write(AS3514_LSP_OUT_L, LSP_OUT_L_SP_MUTE | 0x00); + +#ifdef PHILIPS_SA9200 + /* LRCK 8-23kHz (there are audible clicks while reading the ADC otherwise) */ + as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_8_23); +#else + /* LRCK 24-48kHz */ + as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_24_48); +#endif /* PHILIPS_SA9200 */ + + /* Set headphone over-current to 0, Min volume */ + as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HP_OVC_TO_0MS | 0x00); /* AMS Sansas based on the AS3525 need HPCM enabled, otherwise they output the L-R signal on both L and R headphone outputs instead of normal stereo. @@ -194,46 +200,23 @@ void audiohw_preinit(void) /* TODO: check if AS3525 settings save power on e200v1 or as3525v2 */ /* Set HPCM off, ZCU on */ as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_off); -#endif +#endif /* CONFIG_CPU == AS3525 */ -#ifdef HAVE_AS3543 - as3514_write(AS3543_DAC_IF, AS3543_DAC_INT_PLL); - as3514_set(AS3514_LINE_IN1_R, LINE_IN_R_LINE_SELECT); /* Line 2 */ -#else - /* Mute and disable speaker */ - as3514_write(AS3514_LSP_OUT_R, LSP_OUT_R_SP_OVC_TO_256MS | 0x00); - as3514_write(AS3514_LSP_OUT_L, LSP_OUT_L_SP_MUTE | 0x00); -#endif - -#ifdef HAVE_AS3543 - as3514_write(AS3514_HPH_OUT_R, (0<<7) /* out */ | HPH_OUT_R_HP_OUT_SUM | - 0x00); -#else - /* Set headphone over-current to 0, Min volume */ - as3514_write(AS3514_HPH_OUT_R, - HPH_OUT_R_HP_OVC_TO_0MS | 0x00); -#endif - /* Headphone ON, MUTE, Min volume */ - as3514_write(AS3514_HPH_OUT_L, - HPH_OUT_L_HP_ON | HPH_OUT_L_HP_MUTE | 0x00); + /* M2_Sup_off */ + as3514_set(AS3514_MIC2_L, MIC2_L_M2_SUP_off); -#ifdef PHILIPS_SA9200 - /* LRCK 8-23kHz (there are audible clicks while reading the ADC otherwise) */ - as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_8_23); -#else - /* LRCK 24-48kHz */ - as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_24_48); -#endif +#endif /* HAVE_AS3543 */ - /* DAC_Mute_off */ - as3514_set(AS3514_DAC_L, DAC_L_DAC_MUTE_off); + /* registers identical on as3514/as3515 and as3543 */ /* M1_Sup_off */ as3514_set(AS3514_MIC1_L, MIC1_L_M1_SUP_off); -#ifndef HAVE_AS3543 - /* M2_Sup_off */ - as3514_set(AS3514_MIC2_L, MIC2_L_M2_SUP_off); -#endif + + /* Headphone ON, MUTE, Min volume */ + as3514_write(AS3514_HPH_OUT_L, HPH_OUT_L_HP_ON | HPH_OUT_L_HP_MUTE | 0x00); + + /* DAC_Mute_off */ + as3514_set(AS3514_DAC_L, DAC_L_DAC_MUTE_off); } static void audiohw_mute(bool mute) @@ -262,8 +245,7 @@ void audiohw_set_master_vol(int vol_l, int vol_r) unsigned int hph_r, hph_l; unsigned int mix_l, mix_r; - if(vol_l == 0 && vol_r == 0) - { + if (vol_l == 0 && vol_r == 0) { audiohw_mute(true); return; } @@ -298,11 +280,18 @@ void audiohw_set_master_vol(int vol_l, int vol_r) audiohw_mute(false); } +#if 0 /* unused */ void audiohw_set_lineout_vol(int vol_l, int vol_r) { +#ifdef HAVE_AS3543 + /* line out volume is set in the same registers */ + audiohw_set_master_vol(vol_l, vol_r); +#else as3514_write_masked(AS3514_LINE_OUT_R, vol_r, AS3514_VOL_MASK); as3514_write_masked(AS3514_LINE_OUT_L, vol_l, AS3514_VOL_MASK); +#endif } +#endif /* Nice shutdown of AS3514 audio codec */ void audiohw_close(void) @@ -343,6 +332,7 @@ void audiohw_enable_recording(bool source_mic) AUDIOSET1_INPUT_MASK); #if CONFIG_CPU == AS3525v2 + /* XXX: why is the microphone supply not needed on other models ?? */ /* Enable supply */ as3514_clear(AS3514_MIC1_L, MIC1_L_M1_SUP_off); #endif @@ -455,5 +445,3 @@ void audiohw_set_monitor(bool enable) } } #endif /* HAVE_RECORDING || HAVE_FMRADIO_IN */ - - |