From d24edc605b9b52d3610efbb9cf691c437ea00746 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 3 Jan 2019 20:46:54 -0500 Subject: Add HAVE_LINEOUT_DETECTION and associated logic This allows targets to automatically switch audio settings when the line out is plugged/unplugged. Only hooked up on the xDuoo X3, but there are other potential users. Change-Id: Ic46a329bc955cca2e2ad0335ca16295eab24ad59 --- firmware/target/mips/ingenic_jz47xx/codec-jz4760.c | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'firmware/target/mips/ingenic_jz47xx/codec-jz4760.c') diff --git a/firmware/target/mips/ingenic_jz47xx/codec-jz4760.c b/firmware/target/mips/ingenic_jz47xx/codec-jz4760.c index 09d4858b34..a2de80a914 100644 --- a/firmware/target/mips/ingenic_jz47xx/codec-jz4760.c +++ b/firmware/target/mips/ingenic_jz47xx/codec-jz4760.c @@ -26,6 +26,7 @@ #include "pcm_sw_volume.h" #include "cs4398.h" #include "kernel.h" +#include "button.h" #define PIN_CS_RST (32*1+10) #define PIN_CODEC_PWRON (32*1+13) @@ -140,7 +141,11 @@ static int vol_tenthdb2hw(const int tdb) } } -void audiohw_set_volume(int vol_l, int vol_r) +#ifdef HAVE_LINEOUT_DETECTION +static int real_vol_l, real_vol_r; +#endif + +static void jz4760_set_vol(int vol_l, int vol_r) { uint8_t val = cs4398_read_reg(CS4398_REG_MISC) &~ CS4398_FREEZE; cs4398_write_reg(CS4398_REG_MISC, val | CS4398_FREEZE); @@ -149,14 +154,31 @@ void audiohw_set_volume(int vol_l, int vol_r) cs4398_write_reg(CS4398_REG_MISC, val); } +void audiohw_set_volume(int vol_l, int vol_r) +{ +#ifdef HAVE_LINEOUT_DETECTION + real_vol_l = vol_l; + real_vol_r = vol_r; + + if (lineout_inserted()) { + vol_l = 0; + vol_r = 0; + } +#endif + jz4760_set_vol(vol_l, vol_r); +} + void audiohw_set_lineout_volume(int vol_l, int vol_r) { -#if 0 /* unused */ - cs4398_write_reg(CS4398_REG_VOL_A, vol_tenthdb2hw(vol_l)); - cs4398_write_reg(CS4398_REG_VOL_B, vol_tenthdb2hw(vol_r)); -#else (void)vol_l; (void)vol_r; + +#ifdef HAVE_LINEOUT_DETECTION + if (lineout_inserted()) { + jz4760_set_vol(0, 0); + } else { + jz4760_set_vol(real_vol_l, real_vol_r); + } #endif } -- cgit v1.2.3