summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/rocker_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/audio/rocker_codec.c')
-rw-r--r--firmware/drivers/audio/rocker_codec.c25
1 files changed, 6 insertions, 19 deletions
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
30static int fd_hw = -1; 30static int hw_init = 0;
31 31
32static long int vol_l_hw = 255; 32static long int vol_l_hw = 255;
33static long int vol_r_hw = 255; 33static long int vol_r_hw = 255;
34 34
35static int muted = -1; 35static int muted = -1;
36 36
37static 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
44static void hw_close(void)
45{
46 close(fd_hw);
47 fd_hw = -1;
48 muted = -1;
49}
50
51void audiohw_mute(int mute) 37void 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)
70void audiohw_preinit(void) 56void 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
85void audiohw_close(void) 71void 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);