summaryrefslogtreecommitdiffstats
path: root/firmware/target
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-01-03 20:46:54 -0500
committerSolomon Peachy <pizza@shaftnet.org>2019-01-04 23:52:42 +0100
commitd24edc605b9b52d3610efbb9cf691c437ea00746 (patch)
treebd8e6119e4611c6ff83bd316816e0b9534d84deb /firmware/target
parent100f4338deea5239423a0b8974784939d520385c (diff)
downloadrockbox-d24edc605b9b52d3610efbb9cf691c437ea00746.tar.gz
rockbox-d24edc605b9b52d3610efbb9cf691c437ea00746.tar.bz2
rockbox-d24edc605b9b52d3610efbb9cf691c437ea00746.zip
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
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/codec-jz4760.c32
-rw-r--r--firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c11
2 files changed, 36 insertions, 7 deletions
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
}
diff --git a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c
index be02167a5d..d227255b8a 100644
--- a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c
+++ b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c
@@ -53,6 +53,13 @@ bool headphones_inserted(void)
return (__gpio_get_pin(PIN_PH_DECT) != 0);
}
+bool lineout_inserted(void)
+{
+ /* We want to prevent LO being "enabled" if HP is attached
+ to avoid potential eardrum damage */
+ return (__gpio_get_pin(PIN_LO_DECT) == 0) && !headphones_inserted();
+}
+
void button_init_device(void)
{
key_val = 0xfff;
@@ -72,11 +79,11 @@ void button_init_device(void)
__gpio_set_pin(PIN_CHARGE_CON); /* 0.7 A */
__gpio_as_output(PIN_CHARGE_CON);
- __gpio_as_input(PIN_LO_DECT);
__gpio_as_input(PIN_PH_DECT);
+ __gpio_disable_pull(PIN_PH_DECT);
+ __gpio_as_input(PIN_LO_DECT);
__gpio_disable_pull(PIN_LO_DECT);
- __gpio_disable_pull(PIN_PH_DECT);
}
bool button_hold(void)