diff options
Diffstat (limited to 'firmware/drivers/audio')
-rw-r--r-- | firmware/drivers/audio/xduoolinux_codec.c | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c index eedde1d667..f8de0bf78d 100644 --- a/firmware/drivers/audio/xduoolinux_codec.c +++ b/firmware/drivers/audio/xduoolinux_codec.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "config.h" | 24 | #include "config.h" |
25 | #include "audio.h" | 25 | #include "audio.h" |
26 | #include "audiohw.h" | 26 | #include "audiohw.h" |
27 | #include "button.h" | ||
27 | #include "system.h" | 28 | #include "system.h" |
28 | #include "kernel.h" | 29 | #include "kernel.h" |
29 | #include "panic.h" | 30 | #include "panic.h" |
@@ -32,6 +33,7 @@ | |||
32 | #include "pcm-alsa.h" | 33 | #include "pcm-alsa.h" |
33 | 34 | ||
34 | static int fd_hw; | 35 | static int fd_hw; |
36 | static int inited = 0; | ||
35 | 37 | ||
36 | static long int vol_l_hw = 255; | 38 | static long int vol_l_hw = 255; |
37 | static long int vol_r_hw = 255; | 39 | static long int vol_r_hw = 255; |
@@ -72,34 +74,45 @@ void audiohw_mute(int mute) | |||
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | void audiohw_set_output(void) | 77 | int xduoo_get_outputs(void){ |
76 | { | ||
77 | long int ps = 2; // headset | 78 | long int ps = 2; // headset |
78 | 79 | ||
79 | int status = 0; | 80 | int status = 0; |
80 | 81 | ||
82 | if (!inited) return ps; | ||
83 | |||
81 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; | 84 | const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; |
82 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; | 85 | const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; |
83 | #if defined(XDUOO_X20) | 86 | #if defined(XDUOO_X20) |
84 | const char * const sysfs_bal_switch = "/sys/class/switch/balance/state"; | 87 | const char * const sysfs_bal_switch = "/sys/class/switch/balance/state"; |
85 | #endif | 88 | #endif |
86 | 89 | ||
87 | sysfs_get_int(sysfs_lo_switch, &status); | ||
88 | if (status) ps = 1; // lineout | ||
89 | |||
90 | sysfs_get_int(sysfs_hs_switch, &status); | 90 | sysfs_get_int(sysfs_hs_switch, &status); |
91 | if (status) ps = 2; // headset | 91 | if (status) ps = 2; // headset |
92 | 92 | ||
93 | sysfs_get_int(sysfs_lo_switch, &status); | ||
94 | if (status) ps = 1; // lineout | ||
95 | |||
93 | #if defined(XDUOO_X20) | 96 | #if defined(XDUOO_X20) |
94 | sysfs_get_int(sysfs_bal_switch, &status); | 97 | sysfs_get_int(sysfs_bal_switch, &status); |
95 | if (status) ps = 3; // balance | 98 | if (status) ps = 3; // balance |
96 | #endif | 99 | #endif |
97 | 100 | ||
101 | xduoo_set_output(ps); | ||
102 | |||
103 | return ps; | ||
104 | } | ||
105 | |||
106 | void xduoo_set_output(int ps) | ||
107 | { | ||
108 | if (!inited) return; | ||
109 | |||
98 | if (last_ps != ps) | 110 | if (last_ps != ps) |
99 | { | 111 | { |
100 | /* Output port switch */ | 112 | /* Output port switch */ |
101 | last_ps = ps; | 113 | last_ps = ps; |
102 | alsa_controls_set_ints("Output Port Switch", 1, &last_ps); | 114 | alsa_controls_set_ints("Output Port Switch", 1, &last_ps); |
115 | audiohw_set_volume(vol_l_hw, vol_r_hw); | ||
103 | } | 116 | } |
104 | } | 117 | } |
105 | 118 | ||
@@ -107,15 +120,17 @@ void audiohw_preinit(void) | |||
107 | { | 120 | { |
108 | alsa_controls_init(); | 121 | alsa_controls_init(); |
109 | hw_open(); | 122 | hw_open(); |
123 | inited = 1; | ||
110 | } | 124 | } |
111 | 125 | ||
112 | void audiohw_postinit(void) | 126 | void audiohw_postinit(void) |
113 | { | 127 | { |
114 | audiohw_set_output(); | 128 | xduoo_set_output(xduoo_get_outputs()); |
115 | } | 129 | } |
116 | 130 | ||
117 | void audiohw_close(void) | 131 | void audiohw_close(void) |
118 | { | 132 | { |
133 | inited = 0; | ||
119 | hw_close(); | 134 | hw_close(); |
120 | alsa_controls_close(); | 135 | alsa_controls_close(); |
121 | } | 136 | } |
@@ -127,16 +142,45 @@ void audiohw_set_frequency(int fsel) | |||
127 | 142 | ||
128 | void audiohw_set_volume(int vol_l, int vol_r) | 143 | void audiohw_set_volume(int vol_l, int vol_r) |
129 | { | 144 | { |
130 | vol_l_hw = -vol_l/5; | 145 | long l,r; |
131 | vol_r_hw = -vol_r/5; | 146 | |
132 | 147 | vol_l_hw = vol_l; | |
133 | alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); | 148 | vol_r_hw = vol_r; |
134 | alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw); | 149 | |
150 | if (lineout_inserted()) { | ||
151 | l = 0; | ||
152 | r = 0; | ||
153 | } else { | ||
154 | l = -vol_l/5; | ||
155 | r = -vol_r/5; | ||
156 | } | ||
157 | |||
158 | alsa_controls_set_ints("Left Playback Volume", 1, &l); | ||
159 | alsa_controls_set_ints("Right Playback Volume", 1, &r); | ||
160 | } | ||
161 | |||
162 | void audiohw_set_lineout_volume(int vol_l, int vol_r) | ||
163 | { | ||
164 | long l,r; | ||
165 | |||
166 | (void)vol_l; | ||
167 | (void)vol_r; | ||
168 | |||
169 | if (lineout_inserted()) { | ||
170 | l = 0; | ||
171 | r = 0; | ||
172 | } else { | ||
173 | l = -vol_l_hw/5; | ||
174 | r = -vol_r_hw/5; | ||
175 | } | ||
176 | |||
177 | alsa_controls_set_ints("Left Playback Volume", 1, &l); | ||
178 | alsa_controls_set_ints("Right Playback Volume", 1, &r); | ||
135 | } | 179 | } |
136 | 180 | ||
137 | void audiohw_set_filter_roll_off(int value) | 181 | void audiohw_set_filter_roll_off(int value) |
138 | { | 182 | { |
139 | /* 0 = Sharp; | 183 | /* 0 = Sharp; |
140 | 1 = Slow; | 184 | 1 = Slow; |
141 | 2 = Short Sharp | 185 | 2 = Short Sharp |
142 | 3 = Short Slow */ | 186 | 3 = Short Slow */ |