From d0c0fad43aca1a2fad480855ca655456ca922cd8 Mon Sep 17 00:00:00 2001 From: Robert Walker Date: Wed, 30 Mar 2011 20:29:09 +0100 Subject: [PATCH] Use lineout setting to enable/disable lineout on Sansa Fuze V2 --- firmware/drivers/audio/as3514.c | 33 +++++++++++++++++++++++++++++ firmware/export/as3514.h | 5 ++++ firmware/export/config/sansafuzev2.h | 3 ++ firmware/target/arm/as3525/power-as3525.c | 8 +++++++ 4 files changed, 49 insertions(+), 0 deletions(-) diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c index 1774932..be6bfb0 100644 --- a/firmware/drivers/audio/as3514.c +++ b/firmware/drivers/audio/as3514.c @@ -78,6 +78,11 @@ const struct sound_settings_info audiohw_settings[] = { #endif }; +#ifdef SANSA_FUZEV2 +static int as3514_vol_l; +static int as3514_vol_r; +#endif + /* Shadow registers */ static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */ @@ -265,6 +270,7 @@ void audiohw_postinit(void) audiohw_mute(false); } + void audiohw_set_master_vol(int vol_l, int vol_r) { unsigned int hph_r, hph_l; @@ -275,6 +281,17 @@ void audiohw_set_master_vol(int vol_l, int vol_r) return; } +#ifdef SANSA_FUZEV2 + as3514_vol_l = vol_l; + as3514_vol_r = vol_r; + + if (as3514_regs[AS3514_HPH_OUT_R] & HPH_OUT_R_LINEOUT) + { + /* lineout active: force to 0dB */ + vol_l = vol_r = tenthdb2master(0); + } +#endif + /* We combine the mixer/DAC channel volume range with the headphone volume range - keep first stage as loud as possible */ @@ -316,6 +333,22 @@ void audiohw_set_master_vol(int vol_l, int vol_r) audiohw_mute(false); } +#if defined(SANSA_FUZEV2) +void audiohw_enable_lineout(bool enable) +{ + if (enable) + { + as3514_set(AS3514_HPH_OUT_R, HPH_OUT_R_LINEOUT); + audiohw_set_master_vol(as3514_vol_l, as3514_vol_r); + } + else + { + as3514_clear(AS3514_HPH_OUT_R, HPH_OUT_R_LINEOUT); + audiohw_set_master_vol(as3514_vol_l, as3514_vol_r); + } +} +#endif + #if 0 /* unused */ void audiohw_set_lineout_vol(int vol_l, int vol_r) { diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h index dfe0f80..bd6f066 100644 --- a/firmware/export/as3514.h +++ b/firmware/export/as3514.h @@ -23,6 +23,7 @@ #define _AS3514_H #include "config.h" +#include extern int tenthdb2master(int db); @@ -30,6 +31,10 @@ extern void audiohw_set_master_vol(int vol_l, int vol_r); extern void audiohw_set_lineout_vol(int vol_l, int vol_r); extern void audiohw_set_sampr_dividers(int fsel); +#if defined(SANSA_FUZEV2) +extern void audiohw_enable_lineout(bool enable); +#endif + /* Register Descriptions */ #ifndef HAVE_AS3543 diff --git a/firmware/export/config/sansafuzev2.h b/firmware/export/config/sansafuzev2.h index b725ab5..c469708 100644 --- a/firmware/export/config/sansafuzev2.h +++ b/firmware/export/config/sansafuzev2.h @@ -209,5 +209,8 @@ #define INCLUDE_TIMEOUT_API +/* Define this, if you can switch on/off the lineout */ +#define HAVE_LINEOUT_POWEROFF + /* Define this if a programmable hotkey is mapped */ #define HAVE_HOTKEY diff --git a/firmware/target/arm/as3525/power-as3525.c b/firmware/target/arm/as3525/power-as3525.c index 21ce98b..2917f70 100644 --- a/firmware/target/arm/as3525/power-as3525.c +++ b/firmware/target/arm/as3525/power-as3525.c @@ -73,3 +73,11 @@ bool tuner_powered(void) return true; } #endif + +#ifdef HAVE_LINEOUT_POWEROFF +void lineout_set(bool enable) +{ + /* Call audio hardware driver implementation */ + audiohw_enable_lineout(enable); +} +#endif -- 1.7.1