diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/audio/erosqlinux_codec.c | 15 | ||||
-rw-r--r-- | firmware/drivers/audio/fiiolinux_codec.c | 25 | ||||
-rw-r--r-- | firmware/drivers/audio/rocker_codec.c | 9 | ||||
-rw-r--r-- | firmware/drivers/audio/xduoolinux_codec.c | 15 |
4 files changed, 40 insertions, 24 deletions
diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c index c8a104efd6..268da54280 100644 --- a/firmware/drivers/audio/erosqlinux_codec.c +++ b/firmware/drivers/audio/erosqlinux_codec.c | |||
@@ -37,8 +37,7 @@ | |||
37 | 37 | ||
38 | #include "logf.h" | 38 | #include "logf.h" |
39 | 39 | ||
40 | static int fd_hw; | 40 | static int fd_hw = -1; |
41 | static int inited = 0; | ||
42 | 41 | ||
43 | static long int vol_l_hw = 255; | 42 | static long int vol_l_hw = 255; |
44 | static long int vol_r_hw = 255; | 43 | static long int vol_r_hw = 255; |
@@ -54,6 +53,7 @@ static void hw_open(void) | |||
54 | static void hw_close(void) | 53 | static void hw_close(void) |
55 | { | 54 | { |
56 | close(fd_hw); | 55 | close(fd_hw); |
56 | fd_hw = -1; | ||
57 | } | 57 | } |
58 | 58 | ||
59 | static int muted = -1; | 59 | static int muted = -1; |
@@ -62,7 +62,7 @@ void audiohw_mute(int mute) | |||
62 | { | 62 | { |
63 | logf("mute %d", mute); | 63 | logf("mute %d", mute); |
64 | 64 | ||
65 | if (muted == mute) | 65 | if (fd_hw < 0 || muted == mute) |
66 | return; | 66 | return; |
67 | 67 | ||
68 | muted = mute; | 68 | muted = mute; |
@@ -84,7 +84,7 @@ int erosq_get_outputs(void) { | |||
84 | 84 | ||
85 | int status = 0; | 85 | int status = 0; |
86 | 86 | ||
87 | if (!inited) return ps; | 87 | if (fd_hw < 0) return ps; |
88 | 88 | ||
89 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; | 89 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; |
90 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; | 90 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; |
@@ -102,7 +102,7 @@ int erosq_get_outputs(void) { | |||
102 | 102 | ||
103 | void erosq_set_output(int ps) | 103 | void erosq_set_output(int ps) |
104 | { | 104 | { |
105 | if (!inited || muted) return; | 105 | if (fd_hw < 0 || muted) return; |
106 | 106 | ||
107 | if (last_ps != ps) | 107 | if (last_ps != ps) |
108 | { | 108 | { |
@@ -119,9 +119,7 @@ void audiohw_preinit(void) | |||
119 | logf("hw preinit"); | 119 | logf("hw preinit"); |
120 | alsa_controls_init(); | 120 | alsa_controls_init(); |
121 | hw_open(); | 121 | hw_open(); |
122 | // audiohw_mute(true); /* Start muted to avoid the POP */ | 122 | audiohw_mute(false); /* No need to stay muted */ |
123 | audiohw_mute(false); | ||
124 | inited = 1; | ||
125 | } | 123 | } |
126 | 124 | ||
127 | void audiohw_postinit(void) | 125 | void audiohw_postinit(void) |
@@ -132,7 +130,6 @@ void audiohw_postinit(void) | |||
132 | void audiohw_close(void) | 130 | void audiohw_close(void) |
133 | { | 131 | { |
134 | logf("hw close"); | 132 | logf("hw close"); |
135 | inited = 0; | ||
136 | hw_close(); | 133 | hw_close(); |
137 | alsa_controls_close(); | 134 | alsa_controls_close(); |
138 | } | 135 | } |
diff --git a/firmware/drivers/audio/fiiolinux_codec.c b/firmware/drivers/audio/fiiolinux_codec.c index 44ebdd092c..d23e023564 100644 --- a/firmware/drivers/audio/fiiolinux_codec.c +++ b/firmware/drivers/audio/fiiolinux_codec.c | |||
@@ -32,8 +32,8 @@ | |||
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; | 35 | static int fd_hw = -1; |
36 | static int ak_hw; | 36 | static int ak_hw = -1; |
37 | 37 | ||
38 | static int vol_sw[2] = {0}; | 38 | static int vol_sw[2] = {0}; |
39 | static long int vol_hw[2] = {0}; | 39 | static long int vol_hw[2] = {0}; |
@@ -61,8 +61,8 @@ static void hw_close(void) | |||
61 | panicf("Call cmd AK4376_POWER_OFF fail"); | 61 | panicf("Call cmd AK4376_POWER_OFF fail"); |
62 | } | 62 | } |
63 | close(ak_hw); | 63 | close(ak_hw); |
64 | |||
65 | close(fd_hw); | 64 | close(fd_hw); |
65 | ak_hw = fd_hw = -1; | ||
66 | } | 66 | } |
67 | 67 | ||
68 | void audiohw_preinit(void) | 68 | void audiohw_preinit(void) |
@@ -91,10 +91,15 @@ void audiohw_set_frequency(int fsel) | |||
91 | (void)fsel; | 91 | (void)fsel; |
92 | } | 92 | } |
93 | 93 | ||
94 | static int muted = -1; | ||
95 | |||
94 | void audiohw_set_volume(int vol_l, int vol_r) | 96 | void audiohw_set_volume(int vol_l, int vol_r) |
95 | { | 97 | { |
96 | int vol[2]; | 98 | int vol[2]; |
97 | 99 | ||
100 | if (fd_hw < 0) | ||
101 | return; | ||
102 | |||
98 | vol[0] = vol_l / 20; | 103 | vol[0] = vol_l / 20; |
99 | vol[1] = vol_r / 20; | 104 | vol[1] = vol_r / 20; |
100 | 105 | ||
@@ -121,15 +126,20 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
121 | } | 126 | } |
122 | } | 127 | } |
123 | 128 | ||
124 | alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]); | 129 | if (!muted) { |
125 | alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]); | 130 | alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]); |
126 | pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]); | 131 | alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]); |
132 | pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]); | ||
133 | } | ||
127 | } | 134 | } |
128 | 135 | ||
129 | void audiohw_mute(int mute) | 136 | void audiohw_mute(int mute) |
130 | { | 137 | { |
131 | long int vol0 = 0; | 138 | long int vol0 = 0; |
132 | 139 | ||
140 | if (fd_hw < 0 || muted == mute) | ||
141 | return; | ||
142 | |||
133 | if(mute) | 143 | if(mute) |
134 | { | 144 | { |
135 | alsa_controls_set_ints("DACL Playback Volume", 1, &vol0); | 145 | alsa_controls_set_ints("DACL Playback Volume", 1, &vol0); |
@@ -146,6 +156,9 @@ void audiohw_mute(int mute) | |||
146 | 156 | ||
147 | void audiohw_set_filter_roll_off(int value) | 157 | void audiohw_set_filter_roll_off(int value) |
148 | { | 158 | { |
159 | if (fd_hw < 0) | ||
160 | return; | ||
161 | |||
149 | /* 0 = Sharp; | 162 | /* 0 = Sharp; |
150 | 1 = Slow; | 163 | 1 = Slow; |
151 | 2 = Short Sharp | 164 | 2 = Short Sharp |
diff --git a/firmware/drivers/audio/rocker_codec.c b/firmware/drivers/audio/rocker_codec.c index f4135fdaa5..abe13be285 100644 --- a/firmware/drivers/audio/rocker_codec.c +++ b/firmware/drivers/audio/rocker_codec.c | |||
@@ -27,7 +27,7 @@ | |||
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; | 30 | static int fd_hw = -1; |
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; |
@@ -44,11 +44,13 @@ static void hw_open(void) | |||
44 | static void hw_close(void) | 44 | static void hw_close(void) |
45 | { | 45 | { |
46 | close(fd_hw); | 46 | close(fd_hw); |
47 | fd_hw = -1; | ||
48 | muted = -1; | ||
47 | } | 49 | } |
48 | 50 | ||
49 | void audiohw_mute(int mute) | 51 | void audiohw_mute(int mute) |
50 | { | 52 | { |
51 | if (muted == mute) | 53 | if (fd_hw < 0 || muted == mute) |
52 | return; | 54 | return; |
53 | 55 | ||
54 | muted = mute; | 56 | muted = mute; |
@@ -92,6 +94,9 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
92 | vol_l_hw = -vol_l/5; | 94 | vol_l_hw = -vol_l/5; |
93 | vol_r_hw = -vol_r/5; | 95 | vol_r_hw = -vol_r/5; |
94 | 96 | ||
97 | if (fd_hw < 0) | ||
98 | return; | ||
99 | |||
95 | alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); | 100 | alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); |
96 | alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw); | 101 | alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw); |
97 | } | 102 | } |
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c index 0425989dc5..31224abd96 100644 --- a/firmware/drivers/audio/xduoolinux_codec.c +++ b/firmware/drivers/audio/xduoolinux_codec.c | |||
@@ -36,8 +36,7 @@ | |||
36 | 36 | ||
37 | #include "logf.h" | 37 | #include "logf.h" |
38 | 38 | ||
39 | static int fd_hw; | 39 | static int fd_hw = -1; |
40 | static int inited = 0; | ||
41 | 40 | ||
42 | static long int vol_l_hw = 255; | 41 | static long int vol_l_hw = 255; |
43 | static long int vol_r_hw = 255; | 42 | static long int vol_r_hw = 255; |
@@ -53,6 +52,7 @@ static void hw_open(void) | |||
53 | static void hw_close(void) | 52 | static void hw_close(void) |
54 | { | 53 | { |
55 | close(fd_hw); | 54 | close(fd_hw); |
55 | fd_hw = -1; | ||
56 | } | 56 | } |
57 | 57 | ||
58 | static int muted = -1; | 58 | static int muted = -1; |
@@ -61,7 +61,7 @@ void audiohw_mute(int mute) | |||
61 | { | 61 | { |
62 | logf("mute %d", mute); | 62 | logf("mute %d", mute); |
63 | 63 | ||
64 | if (muted == mute) | 64 | if (fd_hw < 0 || muted == mute) |
65 | return; | 65 | return; |
66 | 66 | ||
67 | muted = mute; | 67 | muted = mute; |
@@ -83,7 +83,7 @@ int xduoo_get_outputs(void){ | |||
83 | 83 | ||
84 | int status = 0; | 84 | int status = 0; |
85 | 85 | ||
86 | if (!inited) return ps; | 86 | if (fd_hw < 0) return ps; |
87 | 87 | ||
88 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; | 88 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; |
89 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; | 89 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; |
@@ -109,7 +109,7 @@ int xduoo_get_outputs(void){ | |||
109 | 109 | ||
110 | void xduoo_set_output(int ps) | 110 | void xduoo_set_output(int ps) |
111 | { | 111 | { |
112 | if (!inited || muted) return; | 112 | if (fd_hw < 0 || muted) return; |
113 | 113 | ||
114 | if (last_ps != ps) | 114 | if (last_ps != ps) |
115 | { | 115 | { |
@@ -127,7 +127,6 @@ void audiohw_preinit(void) | |||
127 | alsa_controls_init(); | 127 | alsa_controls_init(); |
128 | hw_open(); | 128 | hw_open(); |
129 | audiohw_mute(true); /* Start muted to avoid the POP */ | 129 | audiohw_mute(true); /* Start muted to avoid the POP */ |
130 | inited = 1; | ||
131 | // const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000 | 130 | // const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000 |
132 | } | 131 | } |
133 | 132 | ||
@@ -139,7 +138,6 @@ void audiohw_postinit(void) | |||
139 | void audiohw_close(void) | 138 | void audiohw_close(void) |
140 | { | 139 | { |
141 | logf("hw close"); | 140 | logf("hw close"); |
142 | inited = 0; | ||
143 | hw_close(); | 141 | hw_close(); |
144 | alsa_controls_close(); | 142 | alsa_controls_close(); |
145 | } | 143 | } |
@@ -166,6 +164,9 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
166 | r = -vol_r/5; | 164 | r = -vol_r/5; |
167 | } | 165 | } |
168 | 166 | ||
167 | if (fd_hw < 0) | ||
168 | return; | ||
169 | |||
169 | alsa_controls_set_ints("Left Playback Volume", 1, &l); | 170 | alsa_controls_set_ints("Left Playback Volume", 1, &l); |
170 | alsa_controls_set_ints("Right Playback Volume", 1, &r); | 171 | alsa_controls_set_ints("Right Playback Volume", 1, &r); |
171 | } | 172 | } |