summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/xduoolinux_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/audio/xduoolinux_codec.c')
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c27
1 files changed, 7 insertions, 20 deletions
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
81static int fd_hw = -1; 81static int hw_init = 0;
82 82
83static long int vol_l_hw = 255; 83static long int vol_l_hw = 255;
84static long int vol_r_hw = 255; 84static long int vol_r_hw = 255;
85static long int last_ps = -1; 85static long int last_ps = -1;
86 86
87static 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
94static void hw_close(void)
95{
96 close(fd_hw);
97 fd_hw = -1;
98}
99
100static int muted = -1; 87static int muted = -1;
101 88
102void audiohw_mute(int mute) 89void 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
152void xduoo_set_output(int ps) 139void 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)
191void audiohw_close(void) 178void 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);