summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/erosqlinux_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/audio/erosqlinux_codec.c')
-rw-r--r--firmware/drivers/audio/erosqlinux_codec.c30
1 files changed, 7 insertions, 23 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
67static int fd_hw = -1; 63static int hw_init = 0;
68 64
69static long int vol_l_hw = 255; 65static long int vol_l_hw = 255;
70static long int vol_r_hw = 255; 66static long int vol_r_hw = 255;
71static long int last_ps = -1; 67static long int last_ps = -1;
72 68
73static 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
80static void hw_close(void)
81{
82 close(fd_hw);
83 fd_hw = -1;
84}
85
86static int muted = -1; 69static int muted = -1;
87 70
88void audiohw_mute(int mute) 71void 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
130void erosq_set_output(int ps) 113void 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)
157void audiohw_close(void) 140void 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