diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2021-04-13 21:38:14 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2021-04-14 01:39:57 +0000 |
commit | 42dba708e3bcd2fa448f9d2865157b910a62a11a (patch) | |
tree | 11e37ec97f1ef7f8772c346c0c2f8e7ac57fa88b | |
parent | ec4b5c794ee81de2f604cc67db2087fca2a90ac1 (diff) | |
download | rockbox-42dba708e3bcd2fa448f9d2865157b910a62a11a.tar.gz rockbox-42dba708e3bcd2fa448f9d2865157b910a62a11a.zip |
hosted: Don't open alsa control device directly
It was just being used as a proxy "yeah, we called hw_init()" so
just use a flag for that directly.
affects rocker, erosq, xduoo x3ii/x20, and fiiom3klinux
Change-Id: I14bd9f8d91f1d6cc8de0982a7426e2a103c6bfce
-rw-r--r-- | firmware/drivers/audio/erosqlinux_codec.c | 30 | ||||
-rw-r--r-- | firmware/drivers/audio/fiiolinux_codec.c | 16 | ||||
-rw-r--r-- | firmware/drivers/audio/rocker_codec.c | 25 | ||||
-rw-r--r-- | firmware/drivers/audio/xduoolinux_codec.c | 27 |
4 files changed, 25 insertions, 73 deletions
diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c index abb4fea01f..2b7d819e82 100644 --- a/firmware/drivers/audio/erosqlinux_codec.c +++ b/firmware/drivers/audio/erosqlinux_codec.c | |||
@@ -25,15 +25,11 @@ | |||
25 | #include "config.h" | 25 | #include "config.h" |
26 | #include "audio.h" | 26 | #include "audio.h" |
27 | #include "audiohw.h" | 27 | #include "audiohw.h" |
28 | #include "button.h" | ||
29 | #include "system.h" | 28 | #include "system.h" |
30 | #include "kernel.h" | ||
31 | #include "panic.h" | 29 | #include "panic.h" |
32 | #include "sysfs.h" | 30 | #include "sysfs.h" |
33 | #include "alsa-controls.h" | 31 | #include "alsa-controls.h" |
34 | #include "pcm-alsa.h" | 32 | #include "pcm-alsa.h" |
35 | #include "pcm_sw_volume.h" | ||
36 | |||
37 | #include "settings.h" | 33 | #include "settings.h" |
38 | 34 | ||
39 | #include "logf.h" | 35 | #include "logf.h" |
@@ -64,32 +60,19 @@ | |||
64 | : values=4 | 60 | : values=4 |
65 | */ | 61 | */ |
66 | 62 | ||
67 | static int fd_hw = -1; | 63 | static int hw_init = 0; |
68 | 64 | ||
69 | static long int vol_l_hw = 255; | 65 | static long int vol_l_hw = 255; |
70 | static long int vol_r_hw = 255; | 66 | static long int vol_r_hw = 255; |
71 | static long int last_ps = -1; | 67 | static long int last_ps = -1; |
72 | 68 | ||
73 | static void hw_open(void) | ||
74 | { | ||
75 | fd_hw = open("/dev/snd/controlC0", O_RDWR); | ||
76 | if(fd_hw < 0) | ||
77 | panicf("Cannot open '/dev/snd/controlC0'"); | ||
78 | } | ||
79 | |||
80 | static void hw_close(void) | ||
81 | { | ||
82 | close(fd_hw); | ||
83 | fd_hw = -1; | ||
84 | } | ||
85 | |||
86 | static int muted = -1; | 69 | static int muted = -1; |
87 | 70 | ||
88 | void audiohw_mute(int mute) | 71 | void audiohw_mute(int mute) |
89 | { | 72 | { |
90 | logf("mute %d", mute); | 73 | logf("mute %d", mute); |
91 | 74 | ||
92 | if (fd_hw < 0 || muted == mute) | 75 | if (hw_init < 0 || muted == mute) |
93 | return; | 76 | return; |
94 | 77 | ||
95 | muted = mute; | 78 | muted = mute; |
@@ -111,7 +94,7 @@ int erosq_get_outputs(void) { | |||
111 | 94 | ||
112 | int status = 0; | 95 | int status = 0; |
113 | 96 | ||
114 | if (fd_hw < 0) return ps; | 97 | if (!hw_init) return ps; |
115 | 98 | ||
116 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; | 99 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; |
117 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; | 100 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; |
@@ -129,7 +112,7 @@ int erosq_get_outputs(void) { | |||
129 | 112 | ||
130 | void erosq_set_output(int ps) | 113 | void erosq_set_output(int ps) |
131 | { | 114 | { |
132 | if (fd_hw < 0 || muted) return; | 115 | if (!hw_init || muted) return; |
133 | 116 | ||
134 | if (last_ps != ps) | 117 | if (last_ps != ps) |
135 | { | 118 | { |
@@ -145,7 +128,7 @@ void audiohw_preinit(void) | |||
145 | { | 128 | { |
146 | logf("hw preinit"); | 129 | logf("hw preinit"); |
147 | alsa_controls_init("default"); | 130 | alsa_controls_init("default"); |
148 | hw_open(); | 131 | hw_init = 1; |
149 | audiohw_mute(false); /* No need to stay muted */ | 132 | audiohw_mute(false); /* No need to stay muted */ |
150 | } | 133 | } |
151 | 134 | ||
@@ -157,7 +140,8 @@ void audiohw_postinit(void) | |||
157 | void audiohw_close(void) | 140 | void audiohw_close(void) |
158 | { | 141 | { |
159 | logf("hw close"); | 142 | logf("hw close"); |
160 | hw_close(); | 143 | hw_init = 0; |
144 | muted = -1; | ||
161 | alsa_controls_close(); | 145 | alsa_controls_close(); |
162 | } | 146 | } |
163 | 147 | ||
diff --git a/firmware/drivers/audio/fiiolinux_codec.c b/firmware/drivers/audio/fiiolinux_codec.c index 31731fd6ed..99cff3f5e4 100644 --- a/firmware/drivers/audio/fiiolinux_codec.c +++ b/firmware/drivers/audio/fiiolinux_codec.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include "pcm-alsa.h" | 32 | #include "pcm-alsa.h" |
33 | #include <sys/ioctl.h> | 33 | #include <sys/ioctl.h> |
34 | 34 | ||
35 | static int fd_hw = -1; | ||
36 | static int ak_hw = -1; | 35 | static int ak_hw = -1; |
37 | 36 | ||
38 | static int vol_sw[2] = {0}; | 37 | static int vol_sw[2] = {0}; |
@@ -40,10 +39,6 @@ static long int vol_hw[2] = {0}; | |||
40 | 39 | ||
41 | static void hw_open(void) | 40 | static void hw_open(void) |
42 | { | 41 | { |
43 | fd_hw = open("/dev/snd/controlC0", O_RDWR); | ||
44 | if(fd_hw < 0) | ||
45 | panicf("Cannot open '/dev/snd/controlC0'"); | ||
46 | |||
47 | ak_hw = open("/dev/ak4376", O_RDWR); | 42 | ak_hw = open("/dev/ak4376", O_RDWR); |
48 | if(ak_hw < 0) | 43 | if(ak_hw < 0) |
49 | panicf("Cannot open '/dev/ak4376'"); | 44 | panicf("Cannot open '/dev/ak4376'"); |
@@ -61,8 +56,7 @@ static void hw_close(void) | |||
61 | panicf("Call cmd AK4376_POWER_OFF fail"); | 56 | panicf("Call cmd AK4376_POWER_OFF fail"); |
62 | } | 57 | } |
63 | close(ak_hw); | 58 | close(ak_hw); |
64 | close(fd_hw); | 59 | ak_hw = -1; |
65 | ak_hw = fd_hw = -1; | ||
66 | } | 60 | } |
67 | 61 | ||
68 | void audiohw_preinit(void) | 62 | void audiohw_preinit(void) |
@@ -98,7 +92,7 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
98 | { | 92 | { |
99 | int vol[2]; | 93 | int vol[2]; |
100 | 94 | ||
101 | if (fd_hw < 0) | 95 | if (ak_hw < 0) |
102 | return; | 96 | return; |
103 | 97 | ||
104 | vol[0] = vol_l / 20; | 98 | vol[0] = vol_l / 20; |
@@ -138,7 +132,7 @@ void audiohw_mute(int mute) | |||
138 | { | 132 | { |
139 | long int vol0 = 0; | 133 | long int vol0 = 0; |
140 | 134 | ||
141 | if (fd_hw < 0 || muted == mute) | 135 | if (ak_hw < 0 || muted == mute) |
142 | return; | 136 | return; |
143 | 137 | ||
144 | muted = mute; | 138 | muted = mute; |
@@ -159,14 +153,14 @@ void audiohw_mute(int mute) | |||
159 | 153 | ||
160 | void audiohw_set_filter_roll_off(int value) | 154 | void audiohw_set_filter_roll_off(int value) |
161 | { | 155 | { |
162 | if (fd_hw < 0) | 156 | #if 0 // defined(FIIO_M3K_LINUX) |
157 | if (ak_hw < 0) | ||
163 | return; | 158 | return; |
164 | 159 | ||
165 | /* 0 = Sharp; | 160 | /* 0 = Sharp; |
166 | 1 = Slow; | 161 | 1 = Slow; |
167 | 2 = Short Sharp | 162 | 2 = Short Sharp |
168 | 3 = Short Slow */ | 163 | 3 = Short Slow */ |
169 | #if 0 // defined(FIIO_M3K_LINUX) | ||
170 | // AK4376 supports this but the control isn't wired into ALSA! | 164 | // AK4376 supports this but the control isn't wired into ALSA! |
171 | long int value_hw = value; | 165 | long int value_hw = value; |
172 | alsa_controls_set_ints("AK4376 Digital Filter", 1, &value_hw); | 166 | alsa_controls_set_ints("AK4376 Digital Filter", 1, &value_hw); |
diff --git a/firmware/drivers/audio/rocker_codec.c b/firmware/drivers/audio/rocker_codec.c index 87257c92a4..20e45d5afb 100644 --- a/firmware/drivers/audio/rocker_codec.c +++ b/firmware/drivers/audio/rocker_codec.c | |||
@@ -27,30 +27,16 @@ | |||
27 | #include "panic.h" | 27 | #include "panic.h" |
28 | #include "alsa-controls.h" | 28 | #include "alsa-controls.h" |
29 | 29 | ||
30 | static int fd_hw = -1; | 30 | static int hw_init = 0; |
31 | 31 | ||
32 | static long int vol_l_hw = 255; | 32 | static long int vol_l_hw = 255; |
33 | static long int vol_r_hw = 255; | 33 | static long int vol_r_hw = 255; |
34 | 34 | ||
35 | static int muted = -1; | 35 | static int muted = -1; |
36 | 36 | ||
37 | static void hw_open(void) | ||
38 | { | ||
39 | fd_hw = open("/dev/snd/controlC0", O_RDWR); | ||
40 | if(fd_hw < 0) | ||
41 | panicf("Cannot open '/dev/snd/controlC0'"); | ||
42 | } | ||
43 | |||
44 | static void hw_close(void) | ||
45 | { | ||
46 | close(fd_hw); | ||
47 | fd_hw = -1; | ||
48 | muted = -1; | ||
49 | } | ||
50 | |||
51 | void audiohw_mute(int mute) | 37 | void audiohw_mute(int mute) |
52 | { | 38 | { |
53 | if (fd_hw < 0 || muted == mute) | 39 | if (!hw_init || muted == mute) |
54 | return; | 40 | return; |
55 | 41 | ||
56 | muted = mute; | 42 | muted = mute; |
@@ -70,7 +56,7 @@ void audiohw_mute(int mute) | |||
70 | void audiohw_preinit(void) | 56 | void audiohw_preinit(void) |
71 | { | 57 | { |
72 | alsa_controls_init("default"); | 58 | alsa_controls_init("default"); |
73 | hw_open(); | 59 | hw_init = 1; |
74 | #if defined(AUDIOHW_MUTE_ON_STOP) || defined(AUDIOHW_NEEDS_INITIAL_UNMUTE) | 60 | #if defined(AUDIOHW_MUTE_ON_STOP) || defined(AUDIOHW_NEEDS_INITIAL_UNMUTE) |
75 | audiohw_mute(true); /* Start muted to avoid the POP */ | 61 | audiohw_mute(true); /* Start muted to avoid the POP */ |
76 | #else | 62 | #else |
@@ -84,7 +70,8 @@ void audiohw_postinit(void) | |||
84 | 70 | ||
85 | void audiohw_close(void) | 71 | void audiohw_close(void) |
86 | { | 72 | { |
87 | hw_close(); | 73 | hw_init = 0; |
74 | muted = -1; | ||
88 | alsa_controls_close(); | 75 | alsa_controls_close(); |
89 | } | 76 | } |
90 | 77 | ||
@@ -98,7 +85,7 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
98 | vol_l_hw = -vol_l/5; | 85 | vol_l_hw = -vol_l/5; |
99 | vol_r_hw = -vol_r/5; | 86 | vol_r_hw = -vol_r/5; |
100 | 87 | ||
101 | if (fd_hw < 0) | 88 | if (!hw_init) |
102 | return; | 89 | return; |
103 | 90 | ||
104 | alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); | 91 | alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); |
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c index c78864db2c..749d551739 100644 --- a/firmware/drivers/audio/xduoolinux_codec.c +++ b/firmware/drivers/audio/xduoolinux_codec.c | |||
@@ -78,32 +78,19 @@ X3ii: | |||
78 | 78 | ||
79 | */ | 79 | */ |
80 | 80 | ||
81 | static int fd_hw = -1; | 81 | static int hw_init = 0; |
82 | 82 | ||
83 | static long int vol_l_hw = 255; | 83 | static long int vol_l_hw = 255; |
84 | static long int vol_r_hw = 255; | 84 | static long int vol_r_hw = 255; |
85 | static long int last_ps = -1; | 85 | static long int last_ps = -1; |
86 | 86 | ||
87 | static void hw_open(void) | ||
88 | { | ||
89 | fd_hw = open("/dev/snd/controlC0", O_RDWR); | ||
90 | if(fd_hw < 0) | ||
91 | panicf("Cannot open '/dev/snd/controlC0'"); | ||
92 | } | ||
93 | |||
94 | static void hw_close(void) | ||
95 | { | ||
96 | close(fd_hw); | ||
97 | fd_hw = -1; | ||
98 | } | ||
99 | |||
100 | static int muted = -1; | 87 | static int muted = -1; |
101 | 88 | ||
102 | void audiohw_mute(int mute) | 89 | void audiohw_mute(int mute) |
103 | { | 90 | { |
104 | logf("mute %d", mute); | 91 | logf("mute %d", mute); |
105 | 92 | ||
106 | if (fd_hw < 0 || muted == mute) | 93 | if (!hw_init || muted == mute) |
107 | return; | 94 | return; |
108 | 95 | ||
109 | muted = mute; | 96 | muted = mute; |
@@ -125,7 +112,7 @@ int xduoo_get_outputs(void){ | |||
125 | 112 | ||
126 | int status = 0; | 113 | int status = 0; |
127 | 114 | ||
128 | if (fd_hw < 0) return ps; | 115 | if (!hw_init) return ps; |
129 | 116 | ||
130 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; | 117 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; |
131 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; | 118 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; |
@@ -151,7 +138,7 @@ int xduoo_get_outputs(void){ | |||
151 | 138 | ||
152 | void xduoo_set_output(int ps) | 139 | void xduoo_set_output(int ps) |
153 | { | 140 | { |
154 | if (fd_hw < 0 || muted) return; | 141 | if (!hw_init || muted) return; |
155 | 142 | ||
156 | if (last_ps != ps) | 143 | if (last_ps != ps) |
157 | { | 144 | { |
@@ -172,7 +159,7 @@ void audiohw_preinit(void) | |||
172 | { | 159 | { |
173 | logf("hw preinit"); | 160 | logf("hw preinit"); |
174 | alsa_controls_init("default"); | 161 | alsa_controls_init("default"); |
175 | hw_open(); | 162 | hw_init = 1; |
176 | 163 | ||
177 | #if defined(XDUOO_X3II) | 164 | #if defined(XDUOO_X3II) |
178 | audiohw_mute(true); /* Start muted to avoid the POP */ | 165 | audiohw_mute(true); /* Start muted to avoid the POP */ |
@@ -191,7 +178,7 @@ void audiohw_postinit(void) | |||
191 | void audiohw_close(void) | 178 | void audiohw_close(void) |
192 | { | 179 | { |
193 | logf("hw close"); | 180 | logf("hw close"); |
194 | hw_close(); | 181 | hw_init = 0; |
195 | alsa_controls_close(); | 182 | alsa_controls_close(); |
196 | } | 183 | } |
197 | 184 | ||
@@ -217,7 +204,7 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
217 | r = -vol_r/5; | 204 | r = -vol_r/5; |
218 | } | 205 | } |
219 | 206 | ||
220 | if (fd_hw < 0) | 207 | if (!hw_init) |
221 | return; | 208 | return; |
222 | 209 | ||
223 | alsa_controls_set_ints("Left Playback Volume", 1, &l); | 210 | alsa_controls_set_ints("Left Playback Volume", 1, &l); |