Index: firmware/drivers/audio/as3514.c =================================================================== --- firmware/drivers/audio/as3514.c (revision 15914) +++ firmware/drivers/audio/as3514.c (working copy) @@ -23,6 +23,7 @@ #include "debug.h" #include "system.h" #include "audio.h" +#include "power.h" #include "audiohw.h" #include "i2s.h" @@ -157,10 +158,10 @@ i2s_reset(); - /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ - + /* Set ADC off, mixer on, DAC on, line out on, line in off, mic off */ + /* Turn on SUM, DAC */ - as3514_write(AUDIOSET1, (1 << 6) | (1 << 5)); + as3514_write(AUDIOSET1, (1 << 6) | (1 << 5) | (1 << 4)); /* Set BIAS on, DITH on, AGC on, IBR_DAC max, LSP_LP on, IBR_LSP min */ as3514_write(AUDIOSET2, (1 << 2) | (3 << 0)); @@ -256,16 +257,33 @@ as3514_write(mix_reg_r, mix_r); as3514_write(mix_reg_l, mix_l); - as3514_write(HPH_OUT_R, hph_r); - as3514_write(HPH_OUT_L, hph_l); + if (charger_inserted()) { + audiohw_set_lineout_vol(vol_l, vol_r); + } else { + as3514_write(HPH_OUT_R, hph_r); + as3514_write(HPH_OUT_L, hph_l); + } return 0; } int audiohw_set_lineout_vol(int vol_l, int vol_r) { + /* + * Subtract off the magic offset to make the logical range match + * the as3514's range. + */ + vol_l -= 0x16; + vol_r -= 0x16; + + if (vol_l < 0) vol_l = 0; + if (vol_l > 0x1F) vol_l = 0x1F; + + if (vol_r < 0) vol_r = 0; + if (vol_r > 0x1F) vol_r = 0x1F; + as3514_write(LINE_OUT_R, vol_r); - as3514_write(LINE_OUT_L, (1 << 6) | vol_l); + as3514_write(LINE_OUT_L, (2 << 6) | vol_l); /* stereo out */ return 0; } @@ -273,13 +291,23 @@ void audiohw_mute(bool mute) { if (mute) { - as3514_write_or(HPH_OUT_L, (1 << 7)); + /* + * Mute both headphones and line out + */ + as3514_write_or(HPH_OUT_L, (1 << 7)); + as3514_write_and(LINE_OUT_L, ~(3 << 6)); } else { - as3514_write_and(HPH_OUT_L, ~(1 << 7)); + if (charger_inserted()) { + as3514_write_or(LINE_OUT_L, (2 << 6)); /* unmute */ + as3514_write_or(HPH_OUT_L, (1 << 7)); /* mute */ + } else { + as3514_write_and(HPH_OUT_L, ~(1 << 7)); /* unmute */ + as3514_write_and(LINE_OUT_L, ~(3 << 6)); /* mute */ + } } } -/* Nice shutdown of WM8758 codec */ +/* Nice shutdown of the codec */ void audiohw_close(void) { /* mute headphones */