summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-10-01 14:06:48 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-10-01 15:41:30 -0400
commitb030bf5885dc5e018dd38eacbb294f1321f2b400 (patch)
tree4d9f06c7928fa44d225477b5551c69c29617a98a
parent6d47dc9a8860a17a9e630b8662f33df63011bad9 (diff)
downloadrockbox-b030bf5885dc5e018dd38eacbb294f1321f2b400.tar.gz
rockbox-b030bf5885dc5e018dd38eacbb294f1321f2b400.zip
xduoox3ii/x20: Proper lineout detection and volume mangling.
hotplugging hp and lineout works, without blowing out eardrums. Change-Id: I2df5c7a618bb2d1d77d416548d45dff9cfc619db
-rw-r--r--apps/playback.c4
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c68
-rw-r--r--firmware/export/audiohw.h4
-rw-r--r--firmware/export/config/xduoox20.h2
-rw-r--r--firmware/export/config/xduoox3.h3
-rw-r--r--firmware/export/config/xduoox3ii.h2
-rw-r--r--firmware/export/xduoolinux_codec.h5
-rw-r--r--firmware/target/hosted/agptek/debug-agptek.c7
-rw-r--r--firmware/target/hosted/alsa-controls.c10
-rw-r--r--firmware/target/hosted/xduoo/button-xduoo.c23
10 files changed, 80 insertions, 48 deletions
diff --git a/apps/playback.c b/apps/playback.c
index c7cfef018a..31aed2abe1 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -3851,10 +3851,6 @@ static void audio_change_frequency_callback(unsigned short id, void *data)
3851 static bool starting_playback = false; 3851 static bool starting_playback = false;
3852 struct mp3entry *id3; 3852 struct mp3entry *id3;
3853 3853
3854#ifdef AUDIOHW_HAVE_SET_OUTPUT
3855 audiohw_set_output();
3856#endif
3857
3858 switch (id) 3854 switch (id)
3859 { 3855 {
3860 case PLAYBACK_EVENT_START_PLAYBACK: 3856 case PLAYBACK_EVENT_START_PLAYBACK:
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c
index eedde1d667..f8de0bf78d 100644
--- a/firmware/drivers/audio/xduoolinux_codec.c
+++ b/firmware/drivers/audio/xduoolinux_codec.c
@@ -24,6 +24,7 @@
24#include "config.h" 24#include "config.h"
25#include "audio.h" 25#include "audio.h"
26#include "audiohw.h" 26#include "audiohw.h"
27#include "button.h"
27#include "system.h" 28#include "system.h"
28#include "kernel.h" 29#include "kernel.h"
29#include "panic.h" 30#include "panic.h"
@@ -32,6 +33,7 @@
32#include "pcm-alsa.h" 33#include "pcm-alsa.h"
33 34
34static int fd_hw; 35static int fd_hw;
36static int inited = 0;
35 37
36static long int vol_l_hw = 255; 38static long int vol_l_hw = 255;
37static long int vol_r_hw = 255; 39static long int vol_r_hw = 255;
@@ -72,34 +74,45 @@ void audiohw_mute(int mute)
72 } 74 }
73} 75}
74 76
75void audiohw_set_output(void) 77int xduoo_get_outputs(void){
76{
77 long int ps = 2; // headset 78 long int ps = 2; // headset
78 79
79 int status = 0; 80 int status = 0;
80 81
82 if (!inited) return ps;
83
81 const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; 84 const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
82 const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; 85 const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
83#if defined(XDUOO_X20) 86#if defined(XDUOO_X20)
84 const char * const sysfs_bal_switch = "/sys/class/switch/balance/state"; 87 const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
85#endif 88#endif
86 89
87 sysfs_get_int(sysfs_lo_switch, &status);
88 if (status) ps = 1; // lineout
89
90 sysfs_get_int(sysfs_hs_switch, &status); 90 sysfs_get_int(sysfs_hs_switch, &status);
91 if (status) ps = 2; // headset 91 if (status) ps = 2; // headset
92 92
93 sysfs_get_int(sysfs_lo_switch, &status);
94 if (status) ps = 1; // lineout
95
93#if defined(XDUOO_X20) 96#if defined(XDUOO_X20)
94 sysfs_get_int(sysfs_bal_switch, &status); 97 sysfs_get_int(sysfs_bal_switch, &status);
95 if (status) ps = 3; // balance 98 if (status) ps = 3; // balance
96#endif 99#endif
97 100
101 xduoo_set_output(ps);
102
103 return ps;
104}
105
106void xduoo_set_output(int ps)
107{
108 if (!inited) return;
109
98 if (last_ps != ps) 110 if (last_ps != ps)
99 { 111 {
100 /* Output port switch */ 112 /* Output port switch */
101 last_ps = ps; 113 last_ps = ps;
102 alsa_controls_set_ints("Output Port Switch", 1, &last_ps); 114 alsa_controls_set_ints("Output Port Switch", 1, &last_ps);
115 audiohw_set_volume(vol_l_hw, vol_r_hw);
103 } 116 }
104} 117}
105 118
@@ -107,15 +120,17 @@ void audiohw_preinit(void)
107{ 120{
108 alsa_controls_init(); 121 alsa_controls_init();
109 hw_open(); 122 hw_open();
123 inited = 1;
110} 124}
111 125
112void audiohw_postinit(void) 126void audiohw_postinit(void)
113{ 127{
114 audiohw_set_output(); 128 xduoo_set_output(xduoo_get_outputs());
115} 129}
116 130
117void audiohw_close(void) 131void audiohw_close(void)
118{ 132{
133 inited = 0;
119 hw_close(); 134 hw_close();
120 alsa_controls_close(); 135 alsa_controls_close();
121} 136}
@@ -127,16 +142,45 @@ void audiohw_set_frequency(int fsel)
127 142
128void audiohw_set_volume(int vol_l, int vol_r) 143void audiohw_set_volume(int vol_l, int vol_r)
129{ 144{
130 vol_l_hw = -vol_l/5; 145 long l,r;
131 vol_r_hw = -vol_r/5; 146
132 147 vol_l_hw = vol_l;
133 alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); 148 vol_r_hw = vol_r;
134 alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw); 149
150 if (lineout_inserted()) {
151 l = 0;
152 r = 0;
153 } else {
154 l = -vol_l/5;
155 r = -vol_r/5;
156 }
157
158 alsa_controls_set_ints("Left Playback Volume", 1, &l);
159 alsa_controls_set_ints("Right Playback Volume", 1, &r);
160}
161
162void audiohw_set_lineout_volume(int vol_l, int vol_r)
163{
164 long l,r;
165
166 (void)vol_l;
167 (void)vol_r;
168
169 if (lineout_inserted()) {
170 l = 0;
171 r = 0;
172 } else {
173 l = -vol_l_hw/5;
174 r = -vol_r_hw/5;
175 }
176
177 alsa_controls_set_ints("Left Playback Volume", 1, &l);
178 alsa_controls_set_ints("Right Playback Volume", 1, &r);
135} 179}
136 180
137void audiohw_set_filter_roll_off(int value) 181void audiohw_set_filter_roll_off(int value)
138{ 182{
139 /* 0 = Sharp; 183 /* 0 = Sharp;
140 1 = Slow; 184 1 = Slow;
141 2 = Short Sharp 185 2 = Short Sharp
142 3 = Short Slow */ 186 3 = Short Slow */
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 34a253e893..31be0555f8 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -452,10 +452,6 @@ void audiohw_set_volume(int vol_l, int vol_r);
452void audiohw_set_lineout_volume(int vol_l, int vol_r); 452void audiohw_set_lineout_volume(int vol_l, int vol_r);
453#endif 453#endif
454 454
455#ifdef AUDIOHW_HAVE_SET_OUTPUT
456void audiohw_set_output(void);
457#endif
458
459#ifndef AUDIOHW_HAVE_CLIPPING 455#ifndef AUDIOHW_HAVE_CLIPPING
460#if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \ 456#if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \
461 || defined(AUDIOHW_HAVE_EQ) 457 || defined(AUDIOHW_HAVE_EQ)
diff --git a/firmware/export/config/xduoox20.h b/firmware/export/config/xduoox20.h
index 28a19baaae..b90ebceb04 100644
--- a/firmware/export/config/xduoox20.h
+++ b/firmware/export/config/xduoox20.h
@@ -67,6 +67,7 @@
67#define PLUGIN_BUFFER_SIZE 0x100000 67#define PLUGIN_BUFFER_SIZE 0x100000
68 68
69#define HAVE_HEADPHONE_DETECTION 69#define HAVE_HEADPHONE_DETECTION
70#define HAVE_LINEOUT_DETECTION
70 71
71/* KeyPad configuration for plugins */ 72/* KeyPad configuration for plugins */
72#define CONFIG_KEYPAD XDUOO_X20_PAD 73#define CONFIG_KEYPAD XDUOO_X20_PAD
@@ -81,7 +82,6 @@
81/* We have usb power and can detect usb but it is handled by Linux */ 82/* We have usb power and can detect usb but it is handled by Linux */
82#define HAVE_USB_POWER 83#define HAVE_USB_POWER
83 84
84#define AUDIOHW_HAVE_SET_OUTPUT
85#endif 85#endif
86 86
87#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE 87#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
diff --git a/firmware/export/config/xduoox3.h b/firmware/export/config/xduoox3.h
index 4c2cc47fc9..484e52d151 100644
--- a/firmware/export/config/xduoox3.h
+++ b/firmware/export/config/xduoox3.h
@@ -85,9 +85,6 @@
85/* Define this if a programmable hotkey is mapped */ 85/* Define this if a programmable hotkey is mapped */
86#define HAVE_HOTKEY 86#define HAVE_HOTKEY
87 87
88
89
90
91#ifndef BOOTLOADER 88#ifndef BOOTLOADER
92/* define this if you have a real-time clock */ 89/* define this if you have a real-time clock */
93#define CONFIG_RTC RTC_JZ4760 90#define CONFIG_RTC RTC_JZ4760
diff --git a/firmware/export/config/xduoox3ii.h b/firmware/export/config/xduoox3ii.h
index 02e8a57909..9ad7b5884b 100644
--- a/firmware/export/config/xduoox3ii.h
+++ b/firmware/export/config/xduoox3ii.h
@@ -67,6 +67,7 @@
67#define PLUGIN_BUFFER_SIZE 0x100000 67#define PLUGIN_BUFFER_SIZE 0x100000
68 68
69#define HAVE_HEADPHONE_DETECTION 69#define HAVE_HEADPHONE_DETECTION
70#define HAVE_LINEOUT_DETECTION
70 71
71/* KeyPad configuration for plugins */ 72/* KeyPad configuration for plugins */
72#define CONFIG_KEYPAD XDUOO_X3II_PAD 73#define CONFIG_KEYPAD XDUOO_X3II_PAD
@@ -81,7 +82,6 @@
81/* We have usb power and can detect usb but it is handled by Linux */ 82/* We have usb power and can detect usb but it is handled by Linux */
82#define HAVE_USB_POWER 83#define HAVE_USB_POWER
83 84
84#define AUDIOHW_HAVE_SET_OUTPUT
85#endif 85#endif
86 86
87#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE 87#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
diff --git a/firmware/export/xduoolinux_codec.h b/firmware/export/xduoolinux_codec.h
index ea0b2988f1..a46976d386 100644
--- a/firmware/export/xduoolinux_codec.h
+++ b/firmware/export/xduoolinux_codec.h
@@ -1,10 +1,11 @@
1#ifndef __XDUOOLINUX_CODEC__ 1#ifndef __XDUOOLINUX_CODEC__
2#define __XDUOOLINUX_CODEC__ 2#define __XDUOOLINUX_CODEC__
3 3
4#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) 4#define AUDIOHW_CAPS (LINEOUT_CAP | FILTER_ROLL_OFF_CAP)
5AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -127, 0, -30) 5AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -127, 0, -30)
6AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0) 6AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
7#endif 7#endif
8 8
9void audiohw_mute(int mute); 9void audiohw_mute(int mute);
10void audiohw_set_output(void); 10void xduoo_set_output(int ps);
11int xduoo_get_outputs(void);
diff --git a/firmware/target/hosted/agptek/debug-agptek.c b/firmware/target/hosted/agptek/debug-agptek.c
index b4fcb4246b..7f794a7073 100644
--- a/firmware/target/hosted/agptek/debug-agptek.c
+++ b/firmware/target/hosted/agptek/debug-agptek.c
@@ -41,6 +41,13 @@ bool dbg_hw_info(void)
41 line = 0; 41 line = 0;
42 42
43 lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate()); 43 lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate());
44#ifdef HAVE_HEADPHONE_DETECTION
45 lcd_putsf(0, line++, "hp: %d", headphones_inserted());
46#endif
47#ifdef HAVE_LINEOUT_DETECTION
48 lcd_putsf(0, line++, "lo: %d", lineout_inserted());
49#endif
50
44 btn = button_read_device(); 51 btn = button_read_device();
45 52
46 lcd_update(); 53 lcd_update();
diff --git a/firmware/target/hosted/alsa-controls.c b/firmware/target/hosted/alsa-controls.c
index 19de7aea44..f4914aa216 100644
--- a/firmware/target/hosted/alsa-controls.c
+++ b/firmware/target/hosted/alsa-controls.c
@@ -1,10 +1,10 @@
1/*************************************************************************** 1/***************************************************************************
2 * __________ __ ___. 2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * Copyright (C) 2016 Amaury Pouly 9 * Copyright (C) 2016 Amaury Pouly
10 * 10 *
diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c
index 9fd1392b89..03bb7bbfc9 100644
--- a/firmware/target/hosted/xduoo/button-xduoo.c
+++ b/firmware/target/hosted/xduoo/button-xduoo.c
@@ -166,25 +166,16 @@ int button_read_device(void)
166 166
167bool headphones_inserted(void) 167bool headphones_inserted(void)
168{ 168{
169 int status = 0; 169 int ps = xduoo_get_outputs();
170 const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
171 const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
172#ifdef XDUOO_X20
173 const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
174#endif
175
176 sysfs_get_int(sysfs_lo_switch, &status);
177 if (status) return true;
178 170
179 sysfs_get_int(sysfs_hs_switch, &status); 171 return (ps == 2 || ps == 3);
180 if (status) return true; 172}
181 173
182#ifdef XDUOO_X20 174bool lineout_inserted(void)
183 sysfs_get_int(sysfs_bal_switch, &status); 175{
184 if (status) return true; 176 int ps = xduoo_get_outputs();
185#endif
186 177
187 return false; 178 return (ps == 1);
188} 179}
189 180
190void button_close_device(void) 181void button_close_device(void)