diff options
| author | Cástor Muñoz <cmvidal@gmail.com> | 2014-12-06 18:58:25 +0100 |
|---|---|---|
| committer | Cástor Muñoz <cmvidal@gmail.com> | 2015-10-07 06:15:03 +0200 |
| commit | 42abc6a49670cd546737a4dc7542f9f3f62e3831 (patch) | |
| tree | 48cd6b9d86ff868be72c968b61cd9102eb33a547 /firmware/drivers | |
| parent | 67b4e7f958f4b6569dce8c50c117b22c9f1f9ca7 (diff) | |
| download | rockbox-42abc6a49670cd546737a4dc7542f9f3f62e3831.zip rockbox-42abc6a49670cd546737a4dc7542f9f3f62e3831.tar.gz rockbox-42abc6a49670cd546737a4dc7542f9f3f62e3831.tar.bz2 rockbox-42abc6a49670cd546737a4dc7542f9f3f62e3831.tar.xz | |
iPod Classic: capture support for CS42L55 codec
There are a couple of power saving options that can be selected using
defines, they configure the CODEC in a different way than OF does:
MONO_MIC: jack microphone is connected to left channel, disabling
right channel saves ~1 mW, there is no reason to not to do it.
BYPASS_PGA: this option only applies to the line-in, OF does not
bypass the PGA and configures it to 0 dB gain. At the beginning,
this patch was written based on CODEC datasheet, bypassing PGA
because it saves power and incrementes dinamic range ~1dB, i have
used this setup for a while without problems. Finally this option
was disabled at the last minute, i decided to do it after reviewing
the OF and realizing that CS42L55 datasheet recommends to bypass the
PGA only if the HW includes a couple of capacitors (see Typical
Connection Diagram, Note 4), at this moment i don't know if Classic
includes these capacitors (probably not). Anyway, i am not able to
tell the difference listening to voice recodings.
TODO:
- Use variable PGA gain for jack microphone (it is fixed to +12 dB.
as OF does).
- I am not a fan of having lots of unused #define options, these could
be useful for a generic driver but actually this driver is Classic
oriented, i am not sure if it could be considered disirable to
eliminate them in the final version.
Change-Id: I3dadf2341f44d5e13f3847e6c9de4a76cd6f0918
Diffstat (limited to 'firmware/drivers')
| -rw-r--r-- | firmware/drivers/audio/cs42l55.c | 135 |
1 files changed, 129 insertions, 6 deletions
diff --git a/firmware/drivers/audio/cs42l55.c b/firmware/drivers/audio/cs42l55.c index 80b6fe8..43f6e1d 100644 --- a/firmware/drivers/audio/cs42l55.c +++ b/firmware/drivers/audio/cs42l55.c @@ -32,6 +32,7 @@ #include "cs42l55.h" static int bass, treble; +static int active_dsp_modules; /* powered DSP modules mask */ /* convert tenth of dB volume (-600..120) to volume register value */ static int vol_tenthdb2hw(int db) @@ -66,6 +67,7 @@ void audiohw_preinit(void) bass = 0; treble = 0; + active_dsp_modules = 0; /* Ask Cirrus or maybe Apple what the hell this means */ cscodec_write(HIDDENCTL, HIDDENCTL_UNLOCK); @@ -143,24 +145,40 @@ void audiohw_enable_lineout(bool enable) PWRCTL2_PDN_LINA_ALWAYS | PWRCTL2_PDN_LINB_ALWAYS); } -static void handle_dsp_power(void) +static void handle_dsp_power(int dsp_module, bool onoff) +{ + if (onoff) + { + if (!active_dsp_modules) + cscodec_setbits(PLAYCTL, PLAYCTL_PDN_DSP, 0); + active_dsp_modules |= dsp_module; + } + else + { + active_dsp_modules &= ~dsp_module; + if (!active_dsp_modules) + cscodec_setbits(PLAYCTL, 0, PLAYCTL_PDN_DSP); + } +} + +static void handle_tone_onoff(void) { if (bass || treble) { - cscodec_setbits(PLAYCTL, PLAYCTL_PDN_DSP, 0); + handle_dsp_power(DSP_MODULE_TONE, 1); cscodec_setbits(BTCTL, 0, BTCTL_TCEN); } else { cscodec_setbits(BTCTL, BTCTL_TCEN, 0); - cscodec_setbits(PLAYCTL, 0, PLAYCTL_PDN_DSP); + handle_dsp_power(DSP_MODULE_TONE, 0); } } void audiohw_set_bass(int value) { bass = value; - handle_dsp_power(); + handle_tone_onoff(); if (value >= -105 && value <= 120) cscodec_setbits(TONECTL, TONECTL_BASS_MASK, (8 - value / 15) << TONECTL_BASS_SHIFT); @@ -169,7 +187,7 @@ void audiohw_set_bass(int value) void audiohw_set_treble(int value) { treble = value; - handle_dsp_power(); + handle_tone_onoff(); if (value >= -105 && value <= 120) cscodec_setbits(TONECTL, TONECTL_TREB_MASK, (8 - value / 15) << TONECTL_TREB_SHIFT); @@ -225,5 +243,110 @@ void audiohw_set_frequency(int fsel) } #ifdef HAVE_RECORDING -//TODO: Implement +/* Saves power for targets supporting only mono microphone. */ +#define MONO_MIC + +/* Classic OF does not bypass PGA when line-in is selected. It can be + * bypassed for power saving instead of using it at fixed 0 dB gain. + * See CS42L55 DS, Figure 1 (Typical Connection Diagram), Note 4. + */ +/*#define BYPASS_PGA*/ + +void audiohw_enable_recording(bool source_mic) +{ + /* mute ADCs */ + cscodec_write(ADCCTL, ADCCTL_ADCAMUTE | ADCCTL_ADCBMUTE); + + /* from cs42l55 DS: + * PWRCTL1[3]: ADC charge pump, for optimal ADC performance + * and power consumption, set to ‘1’b when VA > 2.1 V and + * set to ‘0’b when VA < 2.1 V. + */ + if (source_mic) + { + #ifdef MONO_MIC + /* power-up CODEC, ADCA and ADC pump */ + cscodec_write(PWRCTL1, PWRCTL1_PDN_ADCB); + #else + /* power-up CODEC, ADCA, ADCB and ADC pump */ + cscodec_write(PWRCTL1, 0); + #endif + + #ifdef BYPASS_PGA + /* select PGA as input */ + cscodec_setbits(ALHMUX, ALHMUX_ADCAMUX_MASK | ALHMUX_ADCBMUX_MASK, + ALHMUX_ADCAMUX_PGAA | ALHMUX_ADCBMUX_PGAB); + #endif + + /* configure PGA: select AIN2 and set gain */ + cscodec_write(PGAACTL, PGAACTL_MUX_AIN2A | + ((PGA_GAIN_DB << 1) & PGAACTL_VOLUME_MASK)); + #ifndef MONO_MIC + cscodec_write(PGABCTL, PGABCTL_MUX_AIN2B | + ((PGA_GAIN_DB << 1) & PGABCTL_VOLUME_MASK)); + #endif + } + else /* line-in */ + { + /* power-up CODEC, ADCA, ADCB and ADC pump */ + cscodec_write(PWRCTL1, 0); + + #ifdef BYPASS_PGA + /* selects AIN1 as input (PGA is bypassed) */ + cscodec_setbits(ALHMUX, ALHMUX_ADCAMUX_MASK | ALHMUX_ADCBMUX_MASK, + ALHMUX_ADCAMUX_AIN1A | ALHMUX_ADCBMUX_AIN1B); + #else + /* configure PGA: select AIN1 and set gain to 0dB */ + cscodec_write(PGAACTL, PGAACTL_MUX_AIN1A); + cscodec_write(PGABCTL, PGABCTL_MUX_AIN1B); + #endif + } + + cscodec_write(ADCCTL, 0); /* unmute ADCs */ +} + +void audiohw_disable_recording(void) +{ + /* reset used registers to default values */ + cscodec_write(PGAACTL, 0); + cscodec_write(PGABCTL, 0); +#ifdef BYPASS_PGA + cscodec_setbits(ALHMUX, ALHMUX_ADCAMUX_MASK | ALHMUX_ADCBMUX_MASK, + ALHMUX_ADCAMUX_PGAA | ALHMUX_ADCBMUX_PGAB); +#endif + /* power-down ADC section */ + cscodec_write(PWRCTL1, PWRCTL1_PDN_CHRG | + PWRCTL1_PDN_ADCA | PWRCTL1_PDN_ADCB); +} + +void audiohw_set_recvol(int left, int right, int type) +{ +#ifndef MONO_MIC + (void) type; +#else + if (type == AUDIO_GAIN_LINEIN) +#endif + cscodec_write(ADCBATT, right); + cscodec_write(ADCAATT, left); +} + +void audiohw_set_monitor(bool enable) +{ + if (enable) + { + /* enable DSP power if it is actually disabled */ + handle_dsp_power(DSP_MODULE_MONITOR, 1); + /* unmute ADC mixer */ + cscodec_write(AMIXACTL, 0); + cscodec_write(AMIXBCTL, 0); + } + else + { + /* mute ADC mixer */ + cscodec_write(AMIXACTL, AMIXACTL_AMIXAMUTE); + cscodec_write(AMIXBCTL, AMIXBCTL_AMIXBMUTE); + /* disable DSP power if it is not being used by other modules */ + handle_dsp_power(DSP_MODULE_MONITOR, 0); + } +} #endif /* HAVE_RECORDING */ |