Commit 45d760567a7d773237b8996584a4ae0440d5e369

Authored by Daniel Mack
Committed by Takashi Iwai
1 parent 7e84789403

ALSA: usb-mixer: use defines from audio.h

No need for the private enum.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

Showing 3 changed files with 12 additions and 25 deletions Inline Diff

1 /* 1 /*
2 * This program is free software; you can redistribute it and/or modify 2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by 3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or 4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version. 5 * (at your option) any later version.
6 * 6 *
7 * This program is distributed in the hope that it will be useful, 7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details. 10 * GNU General Public License for more details.
11 * 11 *
12 * You should have received a copy of the GNU General Public License 12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software 13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * 15 *
16 */ 16 */
17 17
18 #include <linux/init.h> 18 #include <linux/init.h>
19 #include <linux/usb.h> 19 #include <linux/usb.h>
20 #include <linux/usb/audio.h> 20 #include <linux/usb/audio.h>
21 #include <linux/usb/audio-v2.h> 21 #include <linux/usb/audio-v2.h>
22 22
23 #include <sound/core.h> 23 #include <sound/core.h>
24 #include <sound/pcm.h> 24 #include <sound/pcm.h>
25 25
26 #include "usbaudio.h" 26 #include "usbaudio.h"
27 #include "card.h" 27 #include "card.h"
28 #include "quirks.h" 28 #include "quirks.h"
29 #include "helper.h" 29 #include "helper.h"
30 #include "debug.h" 30 #include "debug.h"
31 31
32 /* 32 /*
33 * parse the audio format type I descriptor 33 * parse the audio format type I descriptor
34 * and returns the corresponding pcm format 34 * and returns the corresponding pcm format
35 * 35 *
36 * @dev: usb device 36 * @dev: usb device
37 * @fp: audioformat record 37 * @fp: audioformat record
38 * @format: the format tag (wFormatTag) 38 * @format: the format tag (wFormatTag)
39 * @fmt: the format type descriptor 39 * @fmt: the format type descriptor
40 */ 40 */
41 static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, 41 static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
42 struct audioformat *fp, 42 struct audioformat *fp,
43 int format, void *_fmt, 43 int format, void *_fmt,
44 int protocol) 44 int protocol)
45 { 45 {
46 int sample_width, sample_bytes; 46 int sample_width, sample_bytes;
47 u64 pcm_formats; 47 u64 pcm_formats;
48 48
49 switch (protocol) { 49 switch (protocol) {
50 case UAC_VERSION_1: { 50 case UAC_VERSION_1: {
51 struct uac_format_type_i_discrete_descriptor *fmt = _fmt; 51 struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
52 sample_width = fmt->bBitResolution; 52 sample_width = fmt->bBitResolution;
53 sample_bytes = fmt->bSubframeSize; 53 sample_bytes = fmt->bSubframeSize;
54 format = 1 << format; 54 format = 1 << format;
55 break; 55 break;
56 } 56 }
57 57
58 case UAC_VERSION_2: { 58 case UAC_VERSION_2: {
59 struct uac_format_type_i_ext_descriptor *fmt = _fmt; 59 struct uac_format_type_i_ext_descriptor *fmt = _fmt;
60 sample_width = fmt->bBitResolution; 60 sample_width = fmt->bBitResolution;
61 sample_bytes = fmt->bSubslotSize; 61 sample_bytes = fmt->bSubslotSize;
62 format <<= 1; 62 format <<= 1;
63 break; 63 break;
64 } 64 }
65 65
66 default: 66 default:
67 return -EINVAL; 67 return -EINVAL;
68 } 68 }
69 69
70 pcm_formats = 0; 70 pcm_formats = 0;
71 71
72 if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) { 72 if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) {
73 /* some devices don't define this correctly... */ 73 /* some devices don't define this correctly... */
74 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", 74 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
75 chip->dev->devnum, fp->iface, fp->altsetting); 75 chip->dev->devnum, fp->iface, fp->altsetting);
76 format = 1 << UAC_FORMAT_TYPE_I_PCM; 76 format = 1 << UAC_FORMAT_TYPE_I_PCM;
77 } 77 }
78 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 78 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
79 if (sample_width > sample_bytes * 8) { 79 if (sample_width > sample_bytes * 8) {
80 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 80 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
81 chip->dev->devnum, fp->iface, fp->altsetting, 81 chip->dev->devnum, fp->iface, fp->altsetting,
82 sample_width, sample_bytes); 82 sample_width, sample_bytes);
83 } 83 }
84 /* check the format byte size */ 84 /* check the format byte size */
85 switch (sample_bytes) { 85 switch (sample_bytes) {
86 case 1: 86 case 1:
87 pcm_formats |= SNDRV_PCM_FMTBIT_S8; 87 pcm_formats |= SNDRV_PCM_FMTBIT_S8;
88 break; 88 break;
89 case 2: 89 case 2:
90 if (snd_usb_is_big_endian_format(chip, fp)) 90 if (snd_usb_is_big_endian_format(chip, fp))
91 pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */ 91 pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */
92 else 92 else
93 pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE; 93 pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE;
94 break; 94 break;
95 case 3: 95 case 3:
96 if (snd_usb_is_big_endian_format(chip, fp)) 96 if (snd_usb_is_big_endian_format(chip, fp))
97 pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */ 97 pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */
98 else 98 else
99 pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE; 99 pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE;
100 break; 100 break;
101 case 4: 101 case 4:
102 pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE; 102 pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE;
103 break; 103 break;
104 default: 104 default:
105 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", 105 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
106 chip->dev->devnum, fp->iface, fp->altsetting, 106 chip->dev->devnum, fp->iface, fp->altsetting,
107 sample_width, sample_bytes); 107 sample_width, sample_bytes);
108 break; 108 break;
109 } 109 }
110 } 110 }
111 if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) { 111 if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
112 /* Dallas DS4201 workaround: it advertises U8 format, but really 112 /* Dallas DS4201 workaround: it advertises U8 format, but really
113 supports S8. */ 113 supports S8. */
114 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 114 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
115 pcm_formats |= SNDRV_PCM_FMTBIT_S8; 115 pcm_formats |= SNDRV_PCM_FMTBIT_S8;
116 else 116 else
117 pcm_formats |= SNDRV_PCM_FMTBIT_U8; 117 pcm_formats |= SNDRV_PCM_FMTBIT_U8;
118 } 118 }
119 if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) { 119 if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
120 pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 120 pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
121 } 121 }
122 if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) { 122 if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
123 pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW; 123 pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
124 } 124 }
125 if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) { 125 if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
126 pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW; 126 pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
127 } 127 }
128 if (format & ~0x3f) { 128 if (format & ~0x3f) {
129 snd_printk(KERN_INFO "%d:%u:%d : unsupported format bits %#x\n", 129 snd_printk(KERN_INFO "%d:%u:%d : unsupported format bits %#x\n",
130 chip->dev->devnum, fp->iface, fp->altsetting, format); 130 chip->dev->devnum, fp->iface, fp->altsetting, format);
131 } 131 }
132 return pcm_formats; 132 return pcm_formats;
133 } 133 }
134 134
135 135
136 /* 136 /*
137 * parse the format descriptor and stores the possible sample rates 137 * parse the format descriptor and stores the possible sample rates
138 * on the audioformat table (audio class v1). 138 * on the audioformat table (audio class v1).
139 * 139 *
140 * @dev: usb device 140 * @dev: usb device
141 * @fp: audioformat record 141 * @fp: audioformat record
142 * @fmt: the format descriptor 142 * @fmt: the format descriptor
143 * @offset: the start offset of descriptor pointing the rate type 143 * @offset: the start offset of descriptor pointing the rate type
144 * (7 for type I and II, 8 for type II) 144 * (7 for type I and II, 8 for type II)
145 */ 145 */
146 static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp, 146 static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
147 unsigned char *fmt, int offset) 147 unsigned char *fmt, int offset)
148 { 148 {
149 int nr_rates = fmt[offset]; 149 int nr_rates = fmt[offset];
150 150
151 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { 151 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
152 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", 152 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
153 chip->dev->devnum, fp->iface, fp->altsetting); 153 chip->dev->devnum, fp->iface, fp->altsetting);
154 return -1; 154 return -1;
155 } 155 }
156 156
157 if (nr_rates) { 157 if (nr_rates) {
158 /* 158 /*
159 * build the rate table and bitmap flags 159 * build the rate table and bitmap flags
160 */ 160 */
161 int r, idx; 161 int r, idx;
162 162
163 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 163 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
164 if (fp->rate_table == NULL) { 164 if (fp->rate_table == NULL) {
165 snd_printk(KERN_ERR "cannot malloc\n"); 165 snd_printk(KERN_ERR "cannot malloc\n");
166 return -1; 166 return -1;
167 } 167 }
168 168
169 fp->nr_rates = 0; 169 fp->nr_rates = 0;
170 fp->rate_min = fp->rate_max = 0; 170 fp->rate_min = fp->rate_max = 0;
171 for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) { 171 for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
172 unsigned int rate = combine_triple(&fmt[idx]); 172 unsigned int rate = combine_triple(&fmt[idx]);
173 if (!rate) 173 if (!rate)
174 continue; 174 continue;
175 /* C-Media CM6501 mislabels its 96 kHz altsetting */ 175 /* C-Media CM6501 mislabels its 96 kHz altsetting */
176 if (rate == 48000 && nr_rates == 1 && 176 if (rate == 48000 && nr_rates == 1 &&
177 (chip->usb_id == USB_ID(0x0d8c, 0x0201) || 177 (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
178 chip->usb_id == USB_ID(0x0d8c, 0x0102)) && 178 chip->usb_id == USB_ID(0x0d8c, 0x0102)) &&
179 fp->altsetting == 5 && fp->maxpacksize == 392) 179 fp->altsetting == 5 && fp->maxpacksize == 392)
180 rate = 96000; 180 rate = 96000;
181 /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */ 181 /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */
182 if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068)) 182 if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068))
183 rate = 8000; 183 rate = 8000;
184 184
185 fp->rate_table[fp->nr_rates] = rate; 185 fp->rate_table[fp->nr_rates] = rate;
186 if (!fp->rate_min || rate < fp->rate_min) 186 if (!fp->rate_min || rate < fp->rate_min)
187 fp->rate_min = rate; 187 fp->rate_min = rate;
188 if (!fp->rate_max || rate > fp->rate_max) 188 if (!fp->rate_max || rate > fp->rate_max)
189 fp->rate_max = rate; 189 fp->rate_max = rate;
190 fp->rates |= snd_pcm_rate_to_rate_bit(rate); 190 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
191 fp->nr_rates++; 191 fp->nr_rates++;
192 } 192 }
193 if (!fp->nr_rates) { 193 if (!fp->nr_rates) {
194 hwc_debug("All rates were zero. Skipping format!\n"); 194 hwc_debug("All rates were zero. Skipping format!\n");
195 return -1; 195 return -1;
196 } 196 }
197 } else { 197 } else {
198 /* continuous rates */ 198 /* continuous rates */
199 fp->rates = SNDRV_PCM_RATE_CONTINUOUS; 199 fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
200 fp->rate_min = combine_triple(&fmt[offset + 1]); 200 fp->rate_min = combine_triple(&fmt[offset + 1]);
201 fp->rate_max = combine_triple(&fmt[offset + 4]); 201 fp->rate_max = combine_triple(&fmt[offset + 4]);
202 } 202 }
203 return 0; 203 return 0;
204 } 204 }
205 205
206 /* 206 /*
207 * parse the format descriptor and stores the possible sample rates 207 * parse the format descriptor and stores the possible sample rates
208 * on the audioformat table (audio class v2). 208 * on the audioformat table (audio class v2).
209 */ 209 */
210 static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, 210 static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
211 struct audioformat *fp, 211 struct audioformat *fp,
212 struct usb_host_interface *iface) 212 struct usb_host_interface *iface)
213 { 213 {
214 struct usb_device *dev = chip->dev; 214 struct usb_device *dev = chip->dev;
215 unsigned char tmp[2], *data; 215 unsigned char tmp[2], *data;
216 int i, nr_rates, data_size, ret = 0; 216 int i, nr_rates, data_size, ret = 0;
217 217
218 /* get the number of sample rates first by only fetching 2 bytes */ 218 /* get the number of sample rates first by only fetching 2 bytes */
219 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 219 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
220 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 220 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
221 0x0100, chip->clock_id << 8, tmp, sizeof(tmp), 1000); 221 UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
222 tmp, sizeof(tmp), 1000);
222 223
223 if (ret < 0) { 224 if (ret < 0) {
224 snd_printk(KERN_ERR "unable to retrieve number of sample rates\n"); 225 snd_printk(KERN_ERR "unable to retrieve number of sample rates\n");
225 goto err; 226 goto err;
226 } 227 }
227 228
228 nr_rates = (tmp[1] << 8) | tmp[0]; 229 nr_rates = (tmp[1] << 8) | tmp[0];
229 data_size = 2 + 12 * nr_rates; 230 data_size = 2 + 12 * nr_rates;
230 data = kzalloc(data_size, GFP_KERNEL); 231 data = kzalloc(data_size, GFP_KERNEL);
231 if (!data) { 232 if (!data) {
232 ret = -ENOMEM; 233 ret = -ENOMEM;
233 goto err; 234 goto err;
234 } 235 }
235 236
236 /* now get the full information */ 237 /* now get the full information */
237 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 238 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
238 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 239 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
239 0x0100, chip->clock_id << 8, data, data_size, 1000); 240 UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
241 data, data_size, 1000);
240 242
241 if (ret < 0) { 243 if (ret < 0) {
242 snd_printk(KERN_ERR "unable to retrieve sample rate range\n"); 244 snd_printk(KERN_ERR "unable to retrieve sample rate range\n");
243 ret = -EINVAL; 245 ret = -EINVAL;
244 goto err_free; 246 goto err_free;
245 } 247 }
246 248
247 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 249 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
248 if (!fp->rate_table) { 250 if (!fp->rate_table) {
249 ret = -ENOMEM; 251 ret = -ENOMEM;
250 goto err_free; 252 goto err_free;
251 } 253 }
252 254
253 fp->nr_rates = 0; 255 fp->nr_rates = 0;
254 fp->rate_min = fp->rate_max = 0; 256 fp->rate_min = fp->rate_max = 0;
255 257
256 for (i = 0; i < nr_rates; i++) { 258 for (i = 0; i < nr_rates; i++) {
257 int rate = combine_quad(&data[2 + 12 * i]); 259 int rate = combine_quad(&data[2 + 12 * i]);
258 260
259 fp->rate_table[fp->nr_rates] = rate; 261 fp->rate_table[fp->nr_rates] = rate;
260 if (!fp->rate_min || rate < fp->rate_min) 262 if (!fp->rate_min || rate < fp->rate_min)
261 fp->rate_min = rate; 263 fp->rate_min = rate;
262 if (!fp->rate_max || rate > fp->rate_max) 264 if (!fp->rate_max || rate > fp->rate_max)
263 fp->rate_max = rate; 265 fp->rate_max = rate;
264 fp->rates |= snd_pcm_rate_to_rate_bit(rate); 266 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
265 fp->nr_rates++; 267 fp->nr_rates++;
266 } 268 }
267 269
268 err_free: 270 err_free:
269 kfree(data); 271 kfree(data);
270 err: 272 err:
271 return ret; 273 return ret;
272 } 274 }
273 275
274 /* 276 /*
275 * parse the format type I and III descriptors 277 * parse the format type I and III descriptors
276 */ 278 */
277 static int parse_audio_format_i(struct snd_usb_audio *chip, 279 static int parse_audio_format_i(struct snd_usb_audio *chip,
278 struct audioformat *fp, 280 struct audioformat *fp,
279 int format, void *_fmt, 281 int format, void *_fmt,
280 struct usb_host_interface *iface) 282 struct usb_host_interface *iface)
281 { 283 {
282 struct usb_interface_descriptor *altsd = get_iface_desc(iface); 284 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
283 struct uac_format_type_i_discrete_descriptor *fmt = _fmt; 285 struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
284 int protocol = altsd->bInterfaceProtocol; 286 int protocol = altsd->bInterfaceProtocol;
285 int pcm_format, ret; 287 int pcm_format, ret;
286 288
287 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) { 289 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
288 /* FIXME: the format type is really IECxxx 290 /* FIXME: the format type is really IECxxx
289 * but we give normal PCM format to get the existing 291 * but we give normal PCM format to get the existing
290 * apps working... 292 * apps working...
291 */ 293 */
292 switch (chip->usb_id) { 294 switch (chip->usb_id) {
293 295
294 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 296 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
295 if (chip->setup == 0x00 && 297 if (chip->setup == 0x00 &&
296 fp->altsetting == 6) 298 fp->altsetting == 6)
297 pcm_format = SNDRV_PCM_FORMAT_S16_BE; 299 pcm_format = SNDRV_PCM_FORMAT_S16_BE;
298 else 300 else
299 pcm_format = SNDRV_PCM_FORMAT_S16_LE; 301 pcm_format = SNDRV_PCM_FORMAT_S16_LE;
300 break; 302 break;
301 default: 303 default:
302 pcm_format = SNDRV_PCM_FORMAT_S16_LE; 304 pcm_format = SNDRV_PCM_FORMAT_S16_LE;
303 } 305 }
304 fp->formats = 1uLL << pcm_format; 306 fp->formats = 1uLL << pcm_format;
305 } else { 307 } else {
306 fp->formats = parse_audio_format_i_type(chip, fp, format, 308 fp->formats = parse_audio_format_i_type(chip, fp, format,
307 fmt, protocol); 309 fmt, protocol);
308 if (!fp->formats) 310 if (!fp->formats)
309 return -1; 311 return -1;
310 } 312 }
311 313
312 /* gather possible sample rates */ 314 /* gather possible sample rates */
313 /* audio class v1 reports possible sample rates as part of the 315 /* audio class v1 reports possible sample rates as part of the
314 * proprietary class specific descriptor. 316 * proprietary class specific descriptor.
315 * audio class v2 uses class specific EP0 range requests for that. 317 * audio class v2 uses class specific EP0 range requests for that.
316 */ 318 */
317 switch (protocol) { 319 switch (protocol) {
318 case UAC_VERSION_1: 320 case UAC_VERSION_1:
319 fp->channels = fmt->bNrChannels; 321 fp->channels = fmt->bNrChannels;
320 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7); 322 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7);
321 break; 323 break;
322 case UAC_VERSION_2: 324 case UAC_VERSION_2:
323 /* fp->channels is already set in this case */ 325 /* fp->channels is already set in this case */
324 ret = parse_audio_format_rates_v2(chip, fp, iface); 326 ret = parse_audio_format_rates_v2(chip, fp, iface);
325 break; 327 break;
326 } 328 }
327 329
328 if (fp->channels < 1) { 330 if (fp->channels < 1) {
329 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", 331 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
330 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); 332 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
331 return -1; 333 return -1;
332 } 334 }
333 335
334 return ret; 336 return ret;
335 } 337 }
336 338
337 /* 339 /*
338 * parse the format type II descriptor 340 * parse the format type II descriptor
339 */ 341 */
340 static int parse_audio_format_ii(struct snd_usb_audio *chip, 342 static int parse_audio_format_ii(struct snd_usb_audio *chip,
341 struct audioformat *fp, 343 struct audioformat *fp,
342 int format, void *_fmt, 344 int format, void *_fmt,
343 struct usb_host_interface *iface) 345 struct usb_host_interface *iface)
344 { 346 {
345 int brate, framesize, ret; 347 int brate, framesize, ret;
346 struct usb_interface_descriptor *altsd = get_iface_desc(iface); 348 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
347 int protocol = altsd->bInterfaceProtocol; 349 int protocol = altsd->bInterfaceProtocol;
348 350
349 switch (format) { 351 switch (format) {
350 case UAC_FORMAT_TYPE_II_AC3: 352 case UAC_FORMAT_TYPE_II_AC3:
351 /* FIXME: there is no AC3 format defined yet */ 353 /* FIXME: there is no AC3 format defined yet */
352 // fp->formats = SNDRV_PCM_FMTBIT_AC3; 354 // fp->formats = SNDRV_PCM_FMTBIT_AC3;
353 fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */ 355 fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */
354 break; 356 break;
355 case UAC_FORMAT_TYPE_II_MPEG: 357 case UAC_FORMAT_TYPE_II_MPEG:
356 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 358 fp->formats = SNDRV_PCM_FMTBIT_MPEG;
357 break; 359 break;
358 default: 360 default:
359 snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n", 361 snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n",
360 chip->dev->devnum, fp->iface, fp->altsetting, format); 362 chip->dev->devnum, fp->iface, fp->altsetting, format);
361 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 363 fp->formats = SNDRV_PCM_FMTBIT_MPEG;
362 break; 364 break;
363 } 365 }
364 366
365 fp->channels = 1; 367 fp->channels = 1;
366 368
367 switch (protocol) { 369 switch (protocol) {
368 case UAC_VERSION_1: { 370 case UAC_VERSION_1: {
369 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt; 371 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
370 brate = le16_to_cpu(fmt->wMaxBitRate); 372 brate = le16_to_cpu(fmt->wMaxBitRate);
371 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 373 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
372 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 374 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
373 fp->frame_size = framesize; 375 fp->frame_size = framesize;
374 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */ 376 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
375 break; 377 break;
376 } 378 }
377 case UAC_VERSION_2: { 379 case UAC_VERSION_2: {
378 struct uac_format_type_ii_ext_descriptor *fmt = _fmt; 380 struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
379 brate = le16_to_cpu(fmt->wMaxBitRate); 381 brate = le16_to_cpu(fmt->wMaxBitRate);
380 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 382 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
381 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 383 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
382 fp->frame_size = framesize; 384 fp->frame_size = framesize;
383 ret = parse_audio_format_rates_v2(chip, fp, iface); 385 ret = parse_audio_format_rates_v2(chip, fp, iface);
384 break; 386 break;
385 } 387 }
386 } 388 }
387 389
388 return ret; 390 return ret;
389 } 391 }
390 392
391 int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, 393 int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
392 int format, unsigned char *fmt, int stream, 394 int format, unsigned char *fmt, int stream,
393 struct usb_host_interface *iface) 395 struct usb_host_interface *iface)
394 { 396 {
395 int err; 397 int err;
396 398
397 switch (fmt[3]) { 399 switch (fmt[3]) {
398 case UAC_FORMAT_TYPE_I: 400 case UAC_FORMAT_TYPE_I:
399 case UAC_FORMAT_TYPE_III: 401 case UAC_FORMAT_TYPE_III:
400 err = parse_audio_format_i(chip, fp, format, fmt, iface); 402 err = parse_audio_format_i(chip, fp, format, fmt, iface);
401 break; 403 break;
402 case UAC_FORMAT_TYPE_II: 404 case UAC_FORMAT_TYPE_II:
403 err = parse_audio_format_ii(chip, fp, format, fmt, iface); 405 err = parse_audio_format_ii(chip, fp, format, fmt, iface);
404 break; 406 break;
405 default: 407 default:
406 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", 408 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
407 chip->dev->devnum, fp->iface, fp->altsetting, fmt[3]); 409 chip->dev->devnum, fp->iface, fp->altsetting, fmt[3]);
408 return -1; 410 return -1;
409 } 411 }
410 fp->fmt_type = fmt[3]; 412 fp->fmt_type = fmt[3];
411 if (err < 0) 413 if (err < 0)
412 return err; 414 return err;
413 #if 1 415 #if 1
414 /* FIXME: temporary hack for extigy/audigy 2 nx/zs */ 416 /* FIXME: temporary hack for extigy/audigy 2 nx/zs */
415 /* extigy apparently supports sample rates other than 48k 417 /* extigy apparently supports sample rates other than 48k
416 * but not in ordinary way. so we enable only 48k atm. 418 * but not in ordinary way. so we enable only 48k atm.
417 */ 419 */
418 if (chip->usb_id == USB_ID(0x041e, 0x3000) || 420 if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
419 chip->usb_id == USB_ID(0x041e, 0x3020) || 421 chip->usb_id == USB_ID(0x041e, 0x3020) ||
420 chip->usb_id == USB_ID(0x041e, 0x3061)) { 422 chip->usb_id == USB_ID(0x041e, 0x3061)) {
421 if (fmt[3] == UAC_FORMAT_TYPE_I && 423 if (fmt[3] == UAC_FORMAT_TYPE_I &&
422 fp->rates != SNDRV_PCM_RATE_48000 && 424 fp->rates != SNDRV_PCM_RATE_48000 &&
423 fp->rates != SNDRV_PCM_RATE_96000) 425 fp->rates != SNDRV_PCM_RATE_96000)
424 return -1; 426 return -1;
425 } 427 }
426 #endif 428 #endif
427 return 0; 429 return 0;
428 } 430 }
429 431
430 432
sound/usb/usbmixer.c
1 /* 1 /*
2 * (Tentative) USB Audio Driver for ALSA 2 * (Tentative) USB Audio Driver for ALSA
3 * 3 *
4 * Mixer control part 4 * Mixer control part
5 * 5 *
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> 6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7 * 7 *
8 * Many codes borrowed from audio.c by 8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk) 9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch) 10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
11 * 11 *
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version. 16 * (at your option) any later version.
17 * 17 *
18 * This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details. 21 * GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 26 *
27 */ 27 */
28 28
29 #include <linux/bitops.h> 29 #include <linux/bitops.h>
30 #include <linux/init.h> 30 #include <linux/init.h>
31 #include <linux/list.h> 31 #include <linux/list.h>
32 #include <linux/slab.h> 32 #include <linux/slab.h>
33 #include <linux/string.h> 33 #include <linux/string.h>
34 #include <linux/usb.h> 34 #include <linux/usb.h>
35 #include <linux/usb/audio.h> 35 #include <linux/usb/audio.h>
36 36
37 #include <sound/core.h> 37 #include <sound/core.h>
38 #include <sound/control.h> 38 #include <sound/control.h>
39 #include <sound/hwdep.h> 39 #include <sound/hwdep.h>
40 #include <sound/info.h> 40 #include <sound/info.h>
41 #include <sound/tlv.h> 41 #include <sound/tlv.h>
42 42
43 #include "usbaudio.h" 43 #include "usbaudio.h"
44 #include "usbmixer.h" 44 #include "usbmixer.h"
45 #include "helper.h" 45 #include "helper.h"
46 46
47 /* 47 /*
48 */ 48 */
49 49
50 /* ignore error from controls - for debugging */ 50 /* ignore error from controls - for debugging */
51 /* #define IGNORE_CTL_ERROR */ 51 /* #define IGNORE_CTL_ERROR */
52 52
53 /* 53 /*
54 * Sound Blaster remote control configuration 54 * Sound Blaster remote control configuration
55 * 55 *
56 * format of remote control data: 56 * format of remote control data:
57 * Extigy: xx 00 57 * Extigy: xx 00
58 * Audigy 2 NX: 06 80 xx 00 00 00 58 * Audigy 2 NX: 06 80 xx 00 00 00
59 * Live! 24-bit: 06 80 xx yy 22 83 59 * Live! 24-bit: 06 80 xx yy 22 83
60 */ 60 */
61 static const struct rc_config { 61 static const struct rc_config {
62 u32 usb_id; 62 u32 usb_id;
63 u8 offset; 63 u8 offset;
64 u8 length; 64 u8 length;
65 u8 packet_length; 65 u8 packet_length;
66 u8 min_packet_length; /* minimum accepted length of the URB result */ 66 u8 min_packet_length; /* minimum accepted length of the URB result */
67 u8 mute_mixer_id; 67 u8 mute_mixer_id;
68 u32 mute_code; 68 u32 mute_code;
69 } rc_configs[] = { 69 } rc_configs[] = {
70 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ 70 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
71 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ 71 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
72 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 72 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
73 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 73 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
74 }; 74 };
75 75
76 #define MAX_ID_ELEMS 256 76 #define MAX_ID_ELEMS 256
77 77
78 struct usb_mixer_interface { 78 struct usb_mixer_interface {
79 struct snd_usb_audio *chip; 79 struct snd_usb_audio *chip;
80 unsigned int ctrlif; 80 unsigned int ctrlif;
81 struct list_head list; 81 struct list_head list;
82 unsigned int ignore_ctl_error; 82 unsigned int ignore_ctl_error;
83 struct urb *urb; 83 struct urb *urb;
84 /* array[MAX_ID_ELEMS], indexed by unit id */ 84 /* array[MAX_ID_ELEMS], indexed by unit id */
85 struct usb_mixer_elem_info **id_elems; 85 struct usb_mixer_elem_info **id_elems;
86 86
87 /* Sound Blaster remote control stuff */ 87 /* Sound Blaster remote control stuff */
88 const struct rc_config *rc_cfg; 88 const struct rc_config *rc_cfg;
89 u32 rc_code; 89 u32 rc_code;
90 wait_queue_head_t rc_waitq; 90 wait_queue_head_t rc_waitq;
91 struct urb *rc_urb; 91 struct urb *rc_urb;
92 struct usb_ctrlrequest *rc_setup_packet; 92 struct usb_ctrlrequest *rc_setup_packet;
93 u8 rc_buffer[6]; 93 u8 rc_buffer[6];
94 94
95 u8 audigy2nx_leds[3]; 95 u8 audigy2nx_leds[3];
96 u8 xonar_u1_status; 96 u8 xonar_u1_status;
97 }; 97 };
98 98
99 99
100 struct usb_audio_term { 100 struct usb_audio_term {
101 int id; 101 int id;
102 int type; 102 int type;
103 int channels; 103 int channels;
104 unsigned int chconfig; 104 unsigned int chconfig;
105 int name; 105 int name;
106 }; 106 };
107 107
108 struct usbmix_name_map; 108 struct usbmix_name_map;
109 109
110 struct mixer_build { 110 struct mixer_build {
111 struct snd_usb_audio *chip; 111 struct snd_usb_audio *chip;
112 struct usb_mixer_interface *mixer; 112 struct usb_mixer_interface *mixer;
113 unsigned char *buffer; 113 unsigned char *buffer;
114 unsigned int buflen; 114 unsigned int buflen;
115 DECLARE_BITMAP(unitbitmap, MAX_ID_ELEMS); 115 DECLARE_BITMAP(unitbitmap, MAX_ID_ELEMS);
116 struct usb_audio_term oterm; 116 struct usb_audio_term oterm;
117 const struct usbmix_name_map *map; 117 const struct usbmix_name_map *map;
118 const struct usbmix_selector_map *selector_map; 118 const struct usbmix_selector_map *selector_map;
119 }; 119 };
120 120
121 #define MAX_CHANNELS 10 /* max logical channels */ 121 #define MAX_CHANNELS 10 /* max logical channels */
122 122
123 struct usb_mixer_elem_info { 123 struct usb_mixer_elem_info {
124 struct usb_mixer_interface *mixer; 124 struct usb_mixer_interface *mixer;
125 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */ 125 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
126 struct snd_ctl_elem_id *elem_id; 126 struct snd_ctl_elem_id *elem_id;
127 unsigned int id; 127 unsigned int id;
128 unsigned int control; /* CS or ICN (high byte) */ 128 unsigned int control; /* CS or ICN (high byte) */
129 unsigned int cmask; /* channel mask bitmap: 0 = master */ 129 unsigned int cmask; /* channel mask bitmap: 0 = master */
130 int channels; 130 int channels;
131 int val_type; 131 int val_type;
132 int min, max, res; 132 int min, max, res;
133 int dBmin, dBmax; 133 int dBmin, dBmax;
134 int cached; 134 int cached;
135 int cache_val[MAX_CHANNELS]; 135 int cache_val[MAX_CHANNELS];
136 u8 initialized; 136 u8 initialized;
137 }; 137 };
138 138
139
140 enum { 139 enum {
141 USB_FEATURE_NONE = 0,
142 USB_FEATURE_MUTE = 1,
143 USB_FEATURE_VOLUME,
144 USB_FEATURE_BASS,
145 USB_FEATURE_MID,
146 USB_FEATURE_TREBLE,
147 USB_FEATURE_GEQ,
148 USB_FEATURE_AGC,
149 USB_FEATURE_DELAY,
150 USB_FEATURE_BASSBOOST,
151 USB_FEATURE_LOUDNESS
152 };
153
154 enum {
155 USB_MIXER_BOOLEAN, 140 USB_MIXER_BOOLEAN,
156 USB_MIXER_INV_BOOLEAN, 141 USB_MIXER_INV_BOOLEAN,
157 USB_MIXER_S8, 142 USB_MIXER_S8,
158 USB_MIXER_U8, 143 USB_MIXER_U8,
159 USB_MIXER_S16, 144 USB_MIXER_S16,
160 USB_MIXER_U16, 145 USB_MIXER_U16,
161 }; 146 };
162 147
163 enum { 148 enum {
164 USB_PROC_UPDOWN = 1, 149 USB_PROC_UPDOWN = 1,
165 USB_PROC_UPDOWN_SWITCH = 1, 150 USB_PROC_UPDOWN_SWITCH = 1,
166 USB_PROC_UPDOWN_MODE_SEL = 2, 151 USB_PROC_UPDOWN_MODE_SEL = 2,
167 152
168 USB_PROC_PROLOGIC = 2, 153 USB_PROC_PROLOGIC = 2,
169 USB_PROC_PROLOGIC_SWITCH = 1, 154 USB_PROC_PROLOGIC_SWITCH = 1,
170 USB_PROC_PROLOGIC_MODE_SEL = 2, 155 USB_PROC_PROLOGIC_MODE_SEL = 2,
171 156
172 USB_PROC_3DENH = 3, 157 USB_PROC_3DENH = 3,
173 USB_PROC_3DENH_SWITCH = 1, 158 USB_PROC_3DENH_SWITCH = 1,
174 USB_PROC_3DENH_SPACE = 2, 159 USB_PROC_3DENH_SPACE = 2,
175 160
176 USB_PROC_REVERB = 4, 161 USB_PROC_REVERB = 4,
177 USB_PROC_REVERB_SWITCH = 1, 162 USB_PROC_REVERB_SWITCH = 1,
178 USB_PROC_REVERB_LEVEL = 2, 163 USB_PROC_REVERB_LEVEL = 2,
179 USB_PROC_REVERB_TIME = 3, 164 USB_PROC_REVERB_TIME = 3,
180 USB_PROC_REVERB_DELAY = 4, 165 USB_PROC_REVERB_DELAY = 4,
181 166
182 USB_PROC_CHORUS = 5, 167 USB_PROC_CHORUS = 5,
183 USB_PROC_CHORUS_SWITCH = 1, 168 USB_PROC_CHORUS_SWITCH = 1,
184 USB_PROC_CHORUS_LEVEL = 2, 169 USB_PROC_CHORUS_LEVEL = 2,
185 USB_PROC_CHORUS_RATE = 3, 170 USB_PROC_CHORUS_RATE = 3,
186 USB_PROC_CHORUS_DEPTH = 4, 171 USB_PROC_CHORUS_DEPTH = 4,
187 172
188 USB_PROC_DCR = 6, 173 USB_PROC_DCR = 6,
189 USB_PROC_DCR_SWITCH = 1, 174 USB_PROC_DCR_SWITCH = 1,
190 USB_PROC_DCR_RATIO = 2, 175 USB_PROC_DCR_RATIO = 2,
191 USB_PROC_DCR_MAX_AMP = 3, 176 USB_PROC_DCR_MAX_AMP = 3,
192 USB_PROC_DCR_THRESHOLD = 4, 177 USB_PROC_DCR_THRESHOLD = 4,
193 USB_PROC_DCR_ATTACK = 5, 178 USB_PROC_DCR_ATTACK = 5,
194 USB_PROC_DCR_RELEASE = 6, 179 USB_PROC_DCR_RELEASE = 6,
195 }; 180 };
196 181
197 /*E-mu 0202(0404) eXtension Unit(XU) control*/ 182 /*E-mu 0202(0404) eXtension Unit(XU) control*/
198 enum { 183 enum {
199 USB_XU_CLOCK_RATE = 0xe301, 184 USB_XU_CLOCK_RATE = 0xe301,
200 USB_XU_CLOCK_SOURCE = 0xe302, 185 USB_XU_CLOCK_SOURCE = 0xe302,
201 USB_XU_DIGITAL_IO_STATUS = 0xe303, 186 USB_XU_DIGITAL_IO_STATUS = 0xe303,
202 USB_XU_DEVICE_OPTIONS = 0xe304, 187 USB_XU_DEVICE_OPTIONS = 0xe304,
203 USB_XU_DIRECT_MONITORING = 0xe305, 188 USB_XU_DIRECT_MONITORING = 0xe305,
204 USB_XU_METERING = 0xe306 189 USB_XU_METERING = 0xe306
205 }; 190 };
206 enum { 191 enum {
207 USB_XU_CLOCK_SOURCE_SELECTOR = 0x02, /* clock source*/ 192 USB_XU_CLOCK_SOURCE_SELECTOR = 0x02, /* clock source*/
208 USB_XU_CLOCK_RATE_SELECTOR = 0x03, /* clock rate */ 193 USB_XU_CLOCK_RATE_SELECTOR = 0x03, /* clock rate */
209 USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01, /* the spdif format */ 194 USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01, /* the spdif format */
210 USB_XU_SOFT_LIMIT_SELECTOR = 0x03 /* soft limiter */ 195 USB_XU_SOFT_LIMIT_SELECTOR = 0x03 /* soft limiter */
211 }; 196 };
212 197
213 /* 198 /*
214 * manual mapping of mixer names 199 * manual mapping of mixer names
215 * if the mixer topology is too complicated and the parsed names are 200 * if the mixer topology is too complicated and the parsed names are
216 * ambiguous, add the entries in usbmixer_maps.c. 201 * ambiguous, add the entries in usbmixer_maps.c.
217 */ 202 */
218 #include "usbmixer_maps.c" 203 #include "usbmixer_maps.c"
219 204
220 static const struct usbmix_name_map * 205 static const struct usbmix_name_map *
221 find_map(struct mixer_build *state, int unitid, int control) 206 find_map(struct mixer_build *state, int unitid, int control)
222 { 207 {
223 const struct usbmix_name_map *p = state->map; 208 const struct usbmix_name_map *p = state->map;
224 209
225 if (!p) 210 if (!p)
226 return NULL; 211 return NULL;
227 212
228 for (p = state->map; p->id; p++) { 213 for (p = state->map; p->id; p++) {
229 if (p->id == unitid && 214 if (p->id == unitid &&
230 (!control || !p->control || control == p->control)) 215 (!control || !p->control || control == p->control))
231 return p; 216 return p;
232 } 217 }
233 return NULL; 218 return NULL;
234 } 219 }
235 220
236 /* get the mapped name if the unit matches */ 221 /* get the mapped name if the unit matches */
237 static int 222 static int
238 check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen) 223 check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen)
239 { 224 {
240 if (!p || !p->name) 225 if (!p || !p->name)
241 return 0; 226 return 0;
242 227
243 buflen--; 228 buflen--;
244 return strlcpy(buf, p->name, buflen); 229 return strlcpy(buf, p->name, buflen);
245 } 230 }
246 231
247 /* check whether the control should be ignored */ 232 /* check whether the control should be ignored */
248 static inline int 233 static inline int
249 check_ignored_ctl(const struct usbmix_name_map *p) 234 check_ignored_ctl(const struct usbmix_name_map *p)
250 { 235 {
251 if (!p || p->name || p->dB) 236 if (!p || p->name || p->dB)
252 return 0; 237 return 0;
253 return 1; 238 return 1;
254 } 239 }
255 240
256 /* dB mapping */ 241 /* dB mapping */
257 static inline void check_mapped_dB(const struct usbmix_name_map *p, 242 static inline void check_mapped_dB(const struct usbmix_name_map *p,
258 struct usb_mixer_elem_info *cval) 243 struct usb_mixer_elem_info *cval)
259 { 244 {
260 if (p && p->dB) { 245 if (p && p->dB) {
261 cval->dBmin = p->dB->min; 246 cval->dBmin = p->dB->min;
262 cval->dBmax = p->dB->max; 247 cval->dBmax = p->dB->max;
263 } 248 }
264 } 249 }
265 250
266 /* get the mapped selector source name */ 251 /* get the mapped selector source name */
267 static int check_mapped_selector_name(struct mixer_build *state, int unitid, 252 static int check_mapped_selector_name(struct mixer_build *state, int unitid,
268 int index, char *buf, int buflen) 253 int index, char *buf, int buflen)
269 { 254 {
270 const struct usbmix_selector_map *p; 255 const struct usbmix_selector_map *p;
271 256
272 if (! state->selector_map) 257 if (! state->selector_map)
273 return 0; 258 return 0;
274 for (p = state->selector_map; p->id; p++) { 259 for (p = state->selector_map; p->id; p++) {
275 if (p->id == unitid && index < p->count) 260 if (p->id == unitid && index < p->count)
276 return strlcpy(buf, p->names[index], buflen); 261 return strlcpy(buf, p->names[index], buflen);
277 } 262 }
278 return 0; 263 return 0;
279 } 264 }
280 265
281 /* 266 /*
282 * find an audio control unit with the given unit id 267 * find an audio control unit with the given unit id
283 */ 268 */
284 static void *find_audio_control_unit(struct mixer_build *state, unsigned char unit) 269 static void *find_audio_control_unit(struct mixer_build *state, unsigned char unit)
285 { 270 {
286 unsigned char *p; 271 unsigned char *p;
287 272
288 p = NULL; 273 p = NULL;
289 while ((p = snd_usb_find_desc(state->buffer, state->buflen, p, 274 while ((p = snd_usb_find_desc(state->buffer, state->buflen, p,
290 USB_DT_CS_INTERFACE)) != NULL) { 275 USB_DT_CS_INTERFACE)) != NULL) {
291 if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC_EXTENSION_UNIT_V1 && p[3] == unit) 276 if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC_EXTENSION_UNIT_V1 && p[3] == unit)
292 return p; 277 return p;
293 } 278 }
294 return NULL; 279 return NULL;
295 } 280 }
296 281
297 282
298 /* 283 /*
299 * copy a string with the given id 284 * copy a string with the given id
300 */ 285 */
301 static int snd_usb_copy_string_desc(struct mixer_build *state, int index, char *buf, int maxlen) 286 static int snd_usb_copy_string_desc(struct mixer_build *state, int index, char *buf, int maxlen)
302 { 287 {
303 int len = usb_string(state->chip->dev, index, buf, maxlen - 1); 288 int len = usb_string(state->chip->dev, index, buf, maxlen - 1);
304 buf[len] = 0; 289 buf[len] = 0;
305 return len; 290 return len;
306 } 291 }
307 292
308 /* 293 /*
309 * convert from the byte/word on usb descriptor to the zero-based integer 294 * convert from the byte/word on usb descriptor to the zero-based integer
310 */ 295 */
311 static int convert_signed_value(struct usb_mixer_elem_info *cval, int val) 296 static int convert_signed_value(struct usb_mixer_elem_info *cval, int val)
312 { 297 {
313 switch (cval->val_type) { 298 switch (cval->val_type) {
314 case USB_MIXER_BOOLEAN: 299 case USB_MIXER_BOOLEAN:
315 return !!val; 300 return !!val;
316 case USB_MIXER_INV_BOOLEAN: 301 case USB_MIXER_INV_BOOLEAN:
317 return !val; 302 return !val;
318 case USB_MIXER_U8: 303 case USB_MIXER_U8:
319 val &= 0xff; 304 val &= 0xff;
320 break; 305 break;
321 case USB_MIXER_S8: 306 case USB_MIXER_S8:
322 val &= 0xff; 307 val &= 0xff;
323 if (val >= 0x80) 308 if (val >= 0x80)
324 val -= 0x100; 309 val -= 0x100;
325 break; 310 break;
326 case USB_MIXER_U16: 311 case USB_MIXER_U16:
327 val &= 0xffff; 312 val &= 0xffff;
328 break; 313 break;
329 case USB_MIXER_S16: 314 case USB_MIXER_S16:
330 val &= 0xffff; 315 val &= 0xffff;
331 if (val >= 0x8000) 316 if (val >= 0x8000)
332 val -= 0x10000; 317 val -= 0x10000;
333 break; 318 break;
334 } 319 }
335 return val; 320 return val;
336 } 321 }
337 322
338 /* 323 /*
339 * convert from the zero-based int to the byte/word for usb descriptor 324 * convert from the zero-based int to the byte/word for usb descriptor
340 */ 325 */
341 static int convert_bytes_value(struct usb_mixer_elem_info *cval, int val) 326 static int convert_bytes_value(struct usb_mixer_elem_info *cval, int val)
342 { 327 {
343 switch (cval->val_type) { 328 switch (cval->val_type) {
344 case USB_MIXER_BOOLEAN: 329 case USB_MIXER_BOOLEAN:
345 return !!val; 330 return !!val;
346 case USB_MIXER_INV_BOOLEAN: 331 case USB_MIXER_INV_BOOLEAN:
347 return !val; 332 return !val;
348 case USB_MIXER_S8: 333 case USB_MIXER_S8:
349 case USB_MIXER_U8: 334 case USB_MIXER_U8:
350 return val & 0xff; 335 return val & 0xff;
351 case USB_MIXER_S16: 336 case USB_MIXER_S16:
352 case USB_MIXER_U16: 337 case USB_MIXER_U16:
353 return val & 0xffff; 338 return val & 0xffff;
354 } 339 }
355 return 0; /* not reached */ 340 return 0; /* not reached */
356 } 341 }
357 342
358 static int get_relative_value(struct usb_mixer_elem_info *cval, int val) 343 static int get_relative_value(struct usb_mixer_elem_info *cval, int val)
359 { 344 {
360 if (! cval->res) 345 if (! cval->res)
361 cval->res = 1; 346 cval->res = 1;
362 if (val < cval->min) 347 if (val < cval->min)
363 return 0; 348 return 0;
364 else if (val >= cval->max) 349 else if (val >= cval->max)
365 return (cval->max - cval->min + cval->res - 1) / cval->res; 350 return (cval->max - cval->min + cval->res - 1) / cval->res;
366 else 351 else
367 return (val - cval->min) / cval->res; 352 return (val - cval->min) / cval->res;
368 } 353 }
369 354
370 static int get_abs_value(struct usb_mixer_elem_info *cval, int val) 355 static int get_abs_value(struct usb_mixer_elem_info *cval, int val)
371 { 356 {
372 if (val < 0) 357 if (val < 0)
373 return cval->min; 358 return cval->min;
374 if (! cval->res) 359 if (! cval->res)
375 cval->res = 1; 360 cval->res = 1;
376 val *= cval->res; 361 val *= cval->res;
377 val += cval->min; 362 val += cval->min;
378 if (val > cval->max) 363 if (val > cval->max)
379 return cval->max; 364 return cval->max;
380 return val; 365 return val;
381 } 366 }
382 367
383 368
384 /* 369 /*
385 * retrieve a mixer value 370 * retrieve a mixer value
386 */ 371 */
387 372
388 static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) 373 static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
389 { 374 {
390 unsigned char buf[2]; 375 unsigned char buf[2];
391 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 376 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
392 int timeout = 10; 377 int timeout = 10;
393 378
394 while (timeout-- > 0) { 379 while (timeout-- > 0) {
395 if (snd_usb_ctl_msg(cval->mixer->chip->dev, 380 if (snd_usb_ctl_msg(cval->mixer->chip->dev,
396 usb_rcvctrlpipe(cval->mixer->chip->dev, 0), 381 usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
397 request, 382 request,
398 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 383 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
399 validx, cval->mixer->ctrlif | (cval->id << 8), 384 validx, cval->mixer->ctrlif | (cval->id << 8),
400 buf, val_len, 100) >= val_len) { 385 buf, val_len, 100) >= val_len) {
401 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); 386 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
402 return 0; 387 return 0;
403 } 388 }
404 } 389 }
405 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 390 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
406 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type); 391 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type);
407 return -EINVAL; 392 return -EINVAL;
408 } 393 }
409 394
410 static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value) 395 static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value)
411 { 396 {
412 return get_ctl_value(cval, UAC_GET_CUR, validx, value); 397 return get_ctl_value(cval, UAC_GET_CUR, validx, value);
413 } 398 }
414 399
415 /* channel = 0: master, 1 = first channel */ 400 /* channel = 0: master, 1 = first channel */
416 static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval, 401 static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval,
417 int channel, int *value) 402 int channel, int *value)
418 { 403 {
419 return get_ctl_value(cval, UAC_GET_CUR, (cval->control << 8) | channel, value); 404 return get_ctl_value(cval, UAC_GET_CUR, (cval->control << 8) | channel, value);
420 } 405 }
421 406
422 static int get_cur_mix_value(struct usb_mixer_elem_info *cval, 407 static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
423 int channel, int index, int *value) 408 int channel, int index, int *value)
424 { 409 {
425 int err; 410 int err;
426 411
427 if (cval->cached & (1 << channel)) { 412 if (cval->cached & (1 << channel)) {
428 *value = cval->cache_val[index]; 413 *value = cval->cache_val[index];
429 return 0; 414 return 0;
430 } 415 }
431 err = get_cur_mix_raw(cval, channel, value); 416 err = get_cur_mix_raw(cval, channel, value);
432 if (err < 0) { 417 if (err < 0) {
433 if (!cval->mixer->ignore_ctl_error) 418 if (!cval->mixer->ignore_ctl_error)
434 snd_printd(KERN_ERR "cannot get current value for " 419 snd_printd(KERN_ERR "cannot get current value for "
435 "control %d ch %d: err = %d\n", 420 "control %d ch %d: err = %d\n",
436 cval->control, channel, err); 421 cval->control, channel, err);
437 return err; 422 return err;
438 } 423 }
439 cval->cached |= 1 << channel; 424 cval->cached |= 1 << channel;
440 cval->cache_val[index] = *value; 425 cval->cache_val[index] = *value;
441 return 0; 426 return 0;
442 } 427 }
443 428
444 429
445 /* 430 /*
446 * set a mixer value 431 * set a mixer value
447 */ 432 */
448 433
449 static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set) 434 static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set)
450 { 435 {
451 unsigned char buf[2]; 436 unsigned char buf[2];
452 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 437 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
453 int timeout = 10; 438 int timeout = 10;
454 439
455 value_set = convert_bytes_value(cval, value_set); 440 value_set = convert_bytes_value(cval, value_set);
456 buf[0] = value_set & 0xff; 441 buf[0] = value_set & 0xff;
457 buf[1] = (value_set >> 8) & 0xff; 442 buf[1] = (value_set >> 8) & 0xff;
458 while (timeout-- > 0) 443 while (timeout-- > 0)
459 if (snd_usb_ctl_msg(cval->mixer->chip->dev, 444 if (snd_usb_ctl_msg(cval->mixer->chip->dev,
460 usb_sndctrlpipe(cval->mixer->chip->dev, 0), 445 usb_sndctrlpipe(cval->mixer->chip->dev, 0),
461 request, 446 request,
462 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 447 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
463 validx, cval->mixer->ctrlif | (cval->id << 8), 448 validx, cval->mixer->ctrlif | (cval->id << 8),
464 buf, val_len, 100) >= 0) 449 buf, val_len, 100) >= 0)
465 return 0; 450 return 0;
466 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n", 451 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n",
467 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]); 452 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]);
468 return -EINVAL; 453 return -EINVAL;
469 } 454 }
470 455
471 static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value) 456 static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value)
472 { 457 {
473 return set_ctl_value(cval, UAC_SET_CUR, validx, value); 458 return set_ctl_value(cval, UAC_SET_CUR, validx, value);
474 } 459 }
475 460
476 static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, 461 static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
477 int index, int value) 462 int index, int value)
478 { 463 {
479 int err; 464 int err;
480 err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel, 465 err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel,
481 value); 466 value);
482 if (err < 0) 467 if (err < 0)
483 return err; 468 return err;
484 cval->cached |= 1 << channel; 469 cval->cached |= 1 << channel;
485 cval->cache_val[index] = value; 470 cval->cache_val[index] = value;
486 return 0; 471 return 0;
487 } 472 }
488 473
489 /* 474 /*
490 * TLV callback for mixer volume controls 475 * TLV callback for mixer volume controls
491 */ 476 */
492 static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 477 static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
493 unsigned int size, unsigned int __user *_tlv) 478 unsigned int size, unsigned int __user *_tlv)
494 { 479 {
495 struct usb_mixer_elem_info *cval = kcontrol->private_data; 480 struct usb_mixer_elem_info *cval = kcontrol->private_data;
496 DECLARE_TLV_DB_MINMAX(scale, 0, 0); 481 DECLARE_TLV_DB_MINMAX(scale, 0, 0);
497 482
498 if (size < sizeof(scale)) 483 if (size < sizeof(scale))
499 return -ENOMEM; 484 return -ENOMEM;
500 scale[2] = cval->dBmin; 485 scale[2] = cval->dBmin;
501 scale[3] = cval->dBmax; 486 scale[3] = cval->dBmax;
502 if (copy_to_user(_tlv, scale, sizeof(scale))) 487 if (copy_to_user(_tlv, scale, sizeof(scale)))
503 return -EFAULT; 488 return -EFAULT;
504 return 0; 489 return 0;
505 } 490 }
506 491
507 /* 492 /*
508 * parser routines begin here... 493 * parser routines begin here...
509 */ 494 */
510 495
511 static int parse_audio_unit(struct mixer_build *state, int unitid); 496 static int parse_audio_unit(struct mixer_build *state, int unitid);
512 497
513 498
514 /* 499 /*
515 * check if the input/output channel routing is enabled on the given bitmap. 500 * check if the input/output channel routing is enabled on the given bitmap.
516 * used for mixer unit parser 501 * used for mixer unit parser
517 */ 502 */
518 static int check_matrix_bitmap(unsigned char *bmap, int ich, int och, int num_outs) 503 static int check_matrix_bitmap(unsigned char *bmap, int ich, int och, int num_outs)
519 { 504 {
520 int idx = ich * num_outs + och; 505 int idx = ich * num_outs + och;
521 return bmap[idx >> 3] & (0x80 >> (idx & 7)); 506 return bmap[idx >> 3] & (0x80 >> (idx & 7));
522 } 507 }
523 508
524 509
525 /* 510 /*
526 * add an alsa control element 511 * add an alsa control element
527 * search and increment the index until an empty slot is found. 512 * search and increment the index until an empty slot is found.
528 * 513 *
529 * if failed, give up and free the control instance. 514 * if failed, give up and free the control instance.
530 */ 515 */
531 516
532 static int add_control_to_empty(struct mixer_build *state, struct snd_kcontrol *kctl) 517 static int add_control_to_empty(struct mixer_build *state, struct snd_kcontrol *kctl)
533 { 518 {
534 struct usb_mixer_elem_info *cval = kctl->private_data; 519 struct usb_mixer_elem_info *cval = kctl->private_data;
535 int err; 520 int err;
536 521
537 while (snd_ctl_find_id(state->chip->card, &kctl->id)) 522 while (snd_ctl_find_id(state->chip->card, &kctl->id))
538 kctl->id.index++; 523 kctl->id.index++;
539 if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) { 524 if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) {
540 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err); 525 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
541 return err; 526 return err;
542 } 527 }
543 cval->elem_id = &kctl->id; 528 cval->elem_id = &kctl->id;
544 cval->next_id_elem = state->mixer->id_elems[cval->id]; 529 cval->next_id_elem = state->mixer->id_elems[cval->id];
545 state->mixer->id_elems[cval->id] = cval; 530 state->mixer->id_elems[cval->id] = cval;
546 return 0; 531 return 0;
547 } 532 }
548 533
549 534
550 /* 535 /*
551 * get a terminal name string 536 * get a terminal name string
552 */ 537 */
553 538
554 static struct iterm_name_combo { 539 static struct iterm_name_combo {
555 int type; 540 int type;
556 char *name; 541 char *name;
557 } iterm_names[] = { 542 } iterm_names[] = {
558 { 0x0300, "Output" }, 543 { 0x0300, "Output" },
559 { 0x0301, "Speaker" }, 544 { 0x0301, "Speaker" },
560 { 0x0302, "Headphone" }, 545 { 0x0302, "Headphone" },
561 { 0x0303, "HMD Audio" }, 546 { 0x0303, "HMD Audio" },
562 { 0x0304, "Desktop Speaker" }, 547 { 0x0304, "Desktop Speaker" },
563 { 0x0305, "Room Speaker" }, 548 { 0x0305, "Room Speaker" },
564 { 0x0306, "Com Speaker" }, 549 { 0x0306, "Com Speaker" },
565 { 0x0307, "LFE" }, 550 { 0x0307, "LFE" },
566 { 0x0600, "External In" }, 551 { 0x0600, "External In" },
567 { 0x0601, "Analog In" }, 552 { 0x0601, "Analog In" },
568 { 0x0602, "Digital In" }, 553 { 0x0602, "Digital In" },
569 { 0x0603, "Line" }, 554 { 0x0603, "Line" },
570 { 0x0604, "Legacy In" }, 555 { 0x0604, "Legacy In" },
571 { 0x0605, "IEC958 In" }, 556 { 0x0605, "IEC958 In" },
572 { 0x0606, "1394 DA Stream" }, 557 { 0x0606, "1394 DA Stream" },
573 { 0x0607, "1394 DV Stream" }, 558 { 0x0607, "1394 DV Stream" },
574 { 0x0700, "Embedded" }, 559 { 0x0700, "Embedded" },
575 { 0x0701, "Noise Source" }, 560 { 0x0701, "Noise Source" },
576 { 0x0702, "Equalization Noise" }, 561 { 0x0702, "Equalization Noise" },
577 { 0x0703, "CD" }, 562 { 0x0703, "CD" },
578 { 0x0704, "DAT" }, 563 { 0x0704, "DAT" },
579 { 0x0705, "DCC" }, 564 { 0x0705, "DCC" },
580 { 0x0706, "MiniDisk" }, 565 { 0x0706, "MiniDisk" },
581 { 0x0707, "Analog Tape" }, 566 { 0x0707, "Analog Tape" },
582 { 0x0708, "Phonograph" }, 567 { 0x0708, "Phonograph" },
583 { 0x0709, "VCR Audio" }, 568 { 0x0709, "VCR Audio" },
584 { 0x070a, "Video Disk Audio" }, 569 { 0x070a, "Video Disk Audio" },
585 { 0x070b, "DVD Audio" }, 570 { 0x070b, "DVD Audio" },
586 { 0x070c, "TV Tuner Audio" }, 571 { 0x070c, "TV Tuner Audio" },
587 { 0x070d, "Satellite Rec Audio" }, 572 { 0x070d, "Satellite Rec Audio" },
588 { 0x070e, "Cable Tuner Audio" }, 573 { 0x070e, "Cable Tuner Audio" },
589 { 0x070f, "DSS Audio" }, 574 { 0x070f, "DSS Audio" },
590 { 0x0710, "Radio Receiver" }, 575 { 0x0710, "Radio Receiver" },
591 { 0x0711, "Radio Transmitter" }, 576 { 0x0711, "Radio Transmitter" },
592 { 0x0712, "Multi-Track Recorder" }, 577 { 0x0712, "Multi-Track Recorder" },
593 { 0x0713, "Synthesizer" }, 578 { 0x0713, "Synthesizer" },
594 { 0 }, 579 { 0 },
595 }; 580 };
596 581
597 static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm, 582 static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm,
598 unsigned char *name, int maxlen, int term_only) 583 unsigned char *name, int maxlen, int term_only)
599 { 584 {
600 struct iterm_name_combo *names; 585 struct iterm_name_combo *names;
601 586
602 if (iterm->name) 587 if (iterm->name)
603 return snd_usb_copy_string_desc(state, iterm->name, name, maxlen); 588 return snd_usb_copy_string_desc(state, iterm->name, name, maxlen);
604 589
605 /* virtual type - not a real terminal */ 590 /* virtual type - not a real terminal */
606 if (iterm->type >> 16) { 591 if (iterm->type >> 16) {
607 if (term_only) 592 if (term_only)
608 return 0; 593 return 0;
609 switch (iterm->type >> 16) { 594 switch (iterm->type >> 16) {
610 case UAC_SELECTOR_UNIT: 595 case UAC_SELECTOR_UNIT:
611 strcpy(name, "Selector"); return 8; 596 strcpy(name, "Selector"); return 8;
612 case UAC_PROCESSING_UNIT_V1: 597 case UAC_PROCESSING_UNIT_V1:
613 strcpy(name, "Process Unit"); return 12; 598 strcpy(name, "Process Unit"); return 12;
614 case UAC_EXTENSION_UNIT_V1: 599 case UAC_EXTENSION_UNIT_V1:
615 strcpy(name, "Ext Unit"); return 8; 600 strcpy(name, "Ext Unit"); return 8;
616 case UAC_MIXER_UNIT: 601 case UAC_MIXER_UNIT:
617 strcpy(name, "Mixer"); return 5; 602 strcpy(name, "Mixer"); return 5;
618 default: 603 default:
619 return sprintf(name, "Unit %d", iterm->id); 604 return sprintf(name, "Unit %d", iterm->id);
620 } 605 }
621 } 606 }
622 607
623 switch (iterm->type & 0xff00) { 608 switch (iterm->type & 0xff00) {
624 case 0x0100: 609 case 0x0100:
625 strcpy(name, "PCM"); return 3; 610 strcpy(name, "PCM"); return 3;
626 case 0x0200: 611 case 0x0200:
627 strcpy(name, "Mic"); return 3; 612 strcpy(name, "Mic"); return 3;
628 case 0x0400: 613 case 0x0400:
629 strcpy(name, "Headset"); return 7; 614 strcpy(name, "Headset"); return 7;
630 case 0x0500: 615 case 0x0500:
631 strcpy(name, "Phone"); return 5; 616 strcpy(name, "Phone"); return 5;
632 } 617 }
633 618
634 for (names = iterm_names; names->type; names++) 619 for (names = iterm_names; names->type; names++)
635 if (names->type == iterm->type) { 620 if (names->type == iterm->type) {
636 strcpy(name, names->name); 621 strcpy(name, names->name);
637 return strlen(names->name); 622 return strlen(names->name);
638 } 623 }
639 return 0; 624 return 0;
640 } 625 }
641 626
642 627
643 /* 628 /*
644 * parse the source unit recursively until it reaches to a terminal 629 * parse the source unit recursively until it reaches to a terminal
645 * or a branched unit. 630 * or a branched unit.
646 */ 631 */
647 static int check_input_term(struct mixer_build *state, int id, struct usb_audio_term *term) 632 static int check_input_term(struct mixer_build *state, int id, struct usb_audio_term *term)
648 { 633 {
649 unsigned char *p1; 634 unsigned char *p1;
650 635
651 memset(term, 0, sizeof(*term)); 636 memset(term, 0, sizeof(*term));
652 while ((p1 = find_audio_control_unit(state, id)) != NULL) { 637 while ((p1 = find_audio_control_unit(state, id)) != NULL) {
653 term->id = id; 638 term->id = id;
654 switch (p1[2]) { 639 switch (p1[2]) {
655 case UAC_INPUT_TERMINAL: 640 case UAC_INPUT_TERMINAL:
656 term->type = combine_word(p1 + 4); 641 term->type = combine_word(p1 + 4);
657 term->channels = p1[7]; 642 term->channels = p1[7];
658 term->chconfig = combine_word(p1 + 8); 643 term->chconfig = combine_word(p1 + 8);
659 term->name = p1[11]; 644 term->name = p1[11];
660 return 0; 645 return 0;
661 case UAC_FEATURE_UNIT: 646 case UAC_FEATURE_UNIT:
662 id = p1[4]; 647 id = p1[4];
663 break; /* continue to parse */ 648 break; /* continue to parse */
664 case UAC_MIXER_UNIT: 649 case UAC_MIXER_UNIT:
665 term->type = p1[2] << 16; /* virtual type */ 650 term->type = p1[2] << 16; /* virtual type */
666 term->channels = p1[5 + p1[4]]; 651 term->channels = p1[5 + p1[4]];
667 term->chconfig = combine_word(p1 + 6 + p1[4]); 652 term->chconfig = combine_word(p1 + 6 + p1[4]);
668 term->name = p1[p1[0] - 1]; 653 term->name = p1[p1[0] - 1];
669 return 0; 654 return 0;
670 case UAC_SELECTOR_UNIT: 655 case UAC_SELECTOR_UNIT:
671 /* call recursively to retrieve the channel info */ 656 /* call recursively to retrieve the channel info */
672 if (check_input_term(state, p1[5], term) < 0) 657 if (check_input_term(state, p1[5], term) < 0)
673 return -ENODEV; 658 return -ENODEV;
674 term->type = p1[2] << 16; /* virtual type */ 659 term->type = p1[2] << 16; /* virtual type */
675 term->id = id; 660 term->id = id;
676 term->name = p1[9 + p1[0] - 1]; 661 term->name = p1[9 + p1[0] - 1];
677 return 0; 662 return 0;
678 case UAC_PROCESSING_UNIT_V1: 663 case UAC_PROCESSING_UNIT_V1:
679 case UAC_EXTENSION_UNIT_V1: 664 case UAC_EXTENSION_UNIT_V1:
680 if (p1[6] == 1) { 665 if (p1[6] == 1) {
681 id = p1[7]; 666 id = p1[7];
682 break; /* continue to parse */ 667 break; /* continue to parse */
683 } 668 }
684 term->type = p1[2] << 16; /* virtual type */ 669 term->type = p1[2] << 16; /* virtual type */
685 term->channels = p1[7 + p1[6]]; 670 term->channels = p1[7 + p1[6]];
686 term->chconfig = combine_word(p1 + 8 + p1[6]); 671 term->chconfig = combine_word(p1 + 8 + p1[6]);
687 term->name = p1[12 + p1[6] + p1[11 + p1[6]]]; 672 term->name = p1[12 + p1[6] + p1[11 + p1[6]]];
688 return 0; 673 return 0;
689 default: 674 default:
690 return -ENODEV; 675 return -ENODEV;
691 } 676 }
692 } 677 }
693 return -ENODEV; 678 return -ENODEV;
694 } 679 }
695 680
696 681
697 /* 682 /*
698 * Feature Unit 683 * Feature Unit
699 */ 684 */
700 685
701 /* feature unit control information */ 686 /* feature unit control information */
702 struct usb_feature_control_info { 687 struct usb_feature_control_info {
703 const char *name; 688 const char *name;
704 unsigned int type; /* control type (mute, volume, etc.) */ 689 unsigned int type; /* control type (mute, volume, etc.) */
705 }; 690 };
706 691
707 static struct usb_feature_control_info audio_feature_info[] = { 692 static struct usb_feature_control_info audio_feature_info[] = {
708 { "Mute", USB_MIXER_INV_BOOLEAN }, 693 { "Mute", USB_MIXER_INV_BOOLEAN },
709 { "Volume", USB_MIXER_S16 }, 694 { "Volume", USB_MIXER_S16 },
710 { "Tone Control - Bass", USB_MIXER_S8 }, 695 { "Tone Control - Bass", USB_MIXER_S8 },
711 { "Tone Control - Mid", USB_MIXER_S8 }, 696 { "Tone Control - Mid", USB_MIXER_S8 },
712 { "Tone Control - Treble", USB_MIXER_S8 }, 697 { "Tone Control - Treble", USB_MIXER_S8 },
713 { "Graphic Equalizer", USB_MIXER_S8 }, /* FIXME: not implemeted yet */ 698 { "Graphic Equalizer", USB_MIXER_S8 }, /* FIXME: not implemeted yet */
714 { "Auto Gain Control", USB_MIXER_BOOLEAN }, 699 { "Auto Gain Control", USB_MIXER_BOOLEAN },
715 { "Delay Control", USB_MIXER_U16 }, 700 { "Delay Control", USB_MIXER_U16 },
716 { "Bass Boost", USB_MIXER_BOOLEAN }, 701 { "Bass Boost", USB_MIXER_BOOLEAN },
717 { "Loudness", USB_MIXER_BOOLEAN }, 702 { "Loudness", USB_MIXER_BOOLEAN },
718 }; 703 };
719 704
720 705
721 /* private_free callback */ 706 /* private_free callback */
722 static void usb_mixer_elem_free(struct snd_kcontrol *kctl) 707 static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
723 { 708 {
724 kfree(kctl->private_data); 709 kfree(kctl->private_data);
725 kctl->private_data = NULL; 710 kctl->private_data = NULL;
726 } 711 }
727 712
728 713
729 /* 714 /*
730 * interface to ALSA control for feature/mixer units 715 * interface to ALSA control for feature/mixer units
731 */ 716 */
732 717
733 /* 718 /*
734 * retrieve the minimum and maximum values for the specified control 719 * retrieve the minimum and maximum values for the specified control
735 */ 720 */
736 static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) 721 static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
737 { 722 {
738 /* for failsafe */ 723 /* for failsafe */
739 cval->min = default_min; 724 cval->min = default_min;
740 cval->max = cval->min + 1; 725 cval->max = cval->min + 1;
741 cval->res = 1; 726 cval->res = 1;
742 cval->dBmin = cval->dBmax = 0; 727 cval->dBmin = cval->dBmax = 0;
743 728
744 if (cval->val_type == USB_MIXER_BOOLEAN || 729 if (cval->val_type == USB_MIXER_BOOLEAN ||
745 cval->val_type == USB_MIXER_INV_BOOLEAN) { 730 cval->val_type == USB_MIXER_INV_BOOLEAN) {
746 cval->initialized = 1; 731 cval->initialized = 1;
747 } else { 732 } else {
748 int minchn = 0; 733 int minchn = 0;
749 if (cval->cmask) { 734 if (cval->cmask) {
750 int i; 735 int i;
751 for (i = 0; i < MAX_CHANNELS; i++) 736 for (i = 0; i < MAX_CHANNELS; i++)
752 if (cval->cmask & (1 << i)) { 737 if (cval->cmask & (1 << i)) {
753 minchn = i + 1; 738 minchn = i + 1;
754 break; 739 break;
755 } 740 }
756 } 741 }
757 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 742 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
758 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 743 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
759 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", 744 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n",
760 cval->id, cval->mixer->ctrlif, cval->control, cval->id); 745 cval->id, cval->mixer->ctrlif, cval->control, cval->id);
761 return -EINVAL; 746 return -EINVAL;
762 } 747 }
763 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) { 748 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
764 cval->res = 1; 749 cval->res = 1;
765 } else { 750 } else {
766 int last_valid_res = cval->res; 751 int last_valid_res = cval->res;
767 752
768 while (cval->res > 1) { 753 while (cval->res > 1) {
769 if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0) 754 if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0)
770 break; 755 break;
771 cval->res /= 2; 756 cval->res /= 2;
772 } 757 }
773 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) 758 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0)
774 cval->res = last_valid_res; 759 cval->res = last_valid_res;
775 } 760 }
776 if (cval->res == 0) 761 if (cval->res == 0)
777 cval->res = 1; 762 cval->res = 1;
778 763
779 /* Additional checks for the proper resolution 764 /* Additional checks for the proper resolution
780 * 765 *
781 * Some devices report smaller resolutions than actually 766 * Some devices report smaller resolutions than actually
782 * reacting. They don't return errors but simply clip 767 * reacting. They don't return errors but simply clip
783 * to the lower aligned value. 768 * to the lower aligned value.
784 */ 769 */
785 if (cval->min + cval->res < cval->max) { 770 if (cval->min + cval->res < cval->max) {
786 int last_valid_res = cval->res; 771 int last_valid_res = cval->res;
787 int saved, test, check; 772 int saved, test, check;
788 get_cur_mix_raw(cval, minchn, &saved); 773 get_cur_mix_raw(cval, minchn, &saved);
789 for (;;) { 774 for (;;) {
790 test = saved; 775 test = saved;
791 if (test < cval->max) 776 if (test < cval->max)
792 test += cval->res; 777 test += cval->res;
793 else 778 else
794 test -= cval->res; 779 test -= cval->res;
795 if (test < cval->min || test > cval->max || 780 if (test < cval->min || test > cval->max ||
796 set_cur_mix_value(cval, minchn, 0, test) || 781 set_cur_mix_value(cval, minchn, 0, test) ||
797 get_cur_mix_raw(cval, minchn, &check)) { 782 get_cur_mix_raw(cval, minchn, &check)) {
798 cval->res = last_valid_res; 783 cval->res = last_valid_res;
799 break; 784 break;
800 } 785 }
801 if (test == check) 786 if (test == check)
802 break; 787 break;
803 cval->res *= 2; 788 cval->res *= 2;
804 } 789 }
805 set_cur_mix_value(cval, minchn, 0, saved); 790 set_cur_mix_value(cval, minchn, 0, saved);
806 } 791 }
807 792
808 cval->initialized = 1; 793 cval->initialized = 1;
809 } 794 }
810 795
811 /* USB descriptions contain the dB scale in 1/256 dB unit 796 /* USB descriptions contain the dB scale in 1/256 dB unit
812 * while ALSA TLV contains in 1/100 dB unit 797 * while ALSA TLV contains in 1/100 dB unit
813 */ 798 */
814 cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256; 799 cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256;
815 cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256; 800 cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256;
816 if (cval->dBmin > cval->dBmax) { 801 if (cval->dBmin > cval->dBmax) {
817 /* something is wrong; assume it's either from/to 0dB */ 802 /* something is wrong; assume it's either from/to 0dB */
818 if (cval->dBmin < 0) 803 if (cval->dBmin < 0)
819 cval->dBmax = 0; 804 cval->dBmax = 0;
820 else if (cval->dBmin > 0) 805 else if (cval->dBmin > 0)
821 cval->dBmin = 0; 806 cval->dBmin = 0;
822 if (cval->dBmin > cval->dBmax) { 807 if (cval->dBmin > cval->dBmax) {
823 /* totally crap, return an error */ 808 /* totally crap, return an error */
824 return -EINVAL; 809 return -EINVAL;
825 } 810 }
826 } 811 }
827 812
828 return 0; 813 return 0;
829 } 814 }
830 815
831 816
832 /* get a feature/mixer unit info */ 817 /* get a feature/mixer unit info */
833 static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 818 static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
834 { 819 {
835 struct usb_mixer_elem_info *cval = kcontrol->private_data; 820 struct usb_mixer_elem_info *cval = kcontrol->private_data;
836 821
837 if (cval->val_type == USB_MIXER_BOOLEAN || 822 if (cval->val_type == USB_MIXER_BOOLEAN ||
838 cval->val_type == USB_MIXER_INV_BOOLEAN) 823 cval->val_type == USB_MIXER_INV_BOOLEAN)
839 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 824 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
840 else 825 else
841 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 826 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
842 uinfo->count = cval->channels; 827 uinfo->count = cval->channels;
843 if (cval->val_type == USB_MIXER_BOOLEAN || 828 if (cval->val_type == USB_MIXER_BOOLEAN ||
844 cval->val_type == USB_MIXER_INV_BOOLEAN) { 829 cval->val_type == USB_MIXER_INV_BOOLEAN) {
845 uinfo->value.integer.min = 0; 830 uinfo->value.integer.min = 0;
846 uinfo->value.integer.max = 1; 831 uinfo->value.integer.max = 1;
847 } else { 832 } else {
848 if (! cval->initialized) 833 if (! cval->initialized)
849 get_min_max(cval, 0); 834 get_min_max(cval, 0);
850 uinfo->value.integer.min = 0; 835 uinfo->value.integer.min = 0;
851 uinfo->value.integer.max = 836 uinfo->value.integer.max =
852 (cval->max - cval->min + cval->res - 1) / cval->res; 837 (cval->max - cval->min + cval->res - 1) / cval->res;
853 } 838 }
854 return 0; 839 return 0;
855 } 840 }
856 841
857 /* get the current value from feature/mixer unit */ 842 /* get the current value from feature/mixer unit */
858 static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 843 static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
859 { 844 {
860 struct usb_mixer_elem_info *cval = kcontrol->private_data; 845 struct usb_mixer_elem_info *cval = kcontrol->private_data;
861 int c, cnt, val, err; 846 int c, cnt, val, err;
862 847
863 ucontrol->value.integer.value[0] = cval->min; 848 ucontrol->value.integer.value[0] = cval->min;
864 if (cval->cmask) { 849 if (cval->cmask) {
865 cnt = 0; 850 cnt = 0;
866 for (c = 0; c < MAX_CHANNELS; c++) { 851 for (c = 0; c < MAX_CHANNELS; c++) {
867 if (!(cval->cmask & (1 << c))) 852 if (!(cval->cmask & (1 << c)))
868 continue; 853 continue;
869 err = get_cur_mix_value(cval, c + 1, cnt, &val); 854 err = get_cur_mix_value(cval, c + 1, cnt, &val);
870 if (err < 0) 855 if (err < 0)
871 return cval->mixer->ignore_ctl_error ? 0 : err; 856 return cval->mixer->ignore_ctl_error ? 0 : err;
872 val = get_relative_value(cval, val); 857 val = get_relative_value(cval, val);
873 ucontrol->value.integer.value[cnt] = val; 858 ucontrol->value.integer.value[cnt] = val;
874 cnt++; 859 cnt++;
875 } 860 }
876 return 0; 861 return 0;
877 } else { 862 } else {
878 /* master channel */ 863 /* master channel */
879 err = get_cur_mix_value(cval, 0, 0, &val); 864 err = get_cur_mix_value(cval, 0, 0, &val);
880 if (err < 0) 865 if (err < 0)
881 return cval->mixer->ignore_ctl_error ? 0 : err; 866 return cval->mixer->ignore_ctl_error ? 0 : err;
882 val = get_relative_value(cval, val); 867 val = get_relative_value(cval, val);
883 ucontrol->value.integer.value[0] = val; 868 ucontrol->value.integer.value[0] = val;
884 } 869 }
885 return 0; 870 return 0;
886 } 871 }
887 872
888 /* put the current value to feature/mixer unit */ 873 /* put the current value to feature/mixer unit */
889 static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 874 static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
890 { 875 {
891 struct usb_mixer_elem_info *cval = kcontrol->private_data; 876 struct usb_mixer_elem_info *cval = kcontrol->private_data;
892 int c, cnt, val, oval, err; 877 int c, cnt, val, oval, err;
893 int changed = 0; 878 int changed = 0;
894 879
895 if (cval->cmask) { 880 if (cval->cmask) {
896 cnt = 0; 881 cnt = 0;
897 for (c = 0; c < MAX_CHANNELS; c++) { 882 for (c = 0; c < MAX_CHANNELS; c++) {
898 if (!(cval->cmask & (1 << c))) 883 if (!(cval->cmask & (1 << c)))
899 continue; 884 continue;
900 err = get_cur_mix_value(cval, c + 1, cnt, &oval); 885 err = get_cur_mix_value(cval, c + 1, cnt, &oval);
901 if (err < 0) 886 if (err < 0)
902 return cval->mixer->ignore_ctl_error ? 0 : err; 887 return cval->mixer->ignore_ctl_error ? 0 : err;
903 val = ucontrol->value.integer.value[cnt]; 888 val = ucontrol->value.integer.value[cnt];
904 val = get_abs_value(cval, val); 889 val = get_abs_value(cval, val);
905 if (oval != val) { 890 if (oval != val) {
906 set_cur_mix_value(cval, c + 1, cnt, val); 891 set_cur_mix_value(cval, c + 1, cnt, val);
907 changed = 1; 892 changed = 1;
908 } 893 }
909 cnt++; 894 cnt++;
910 } 895 }
911 } else { 896 } else {
912 /* master channel */ 897 /* master channel */
913 err = get_cur_mix_value(cval, 0, 0, &oval); 898 err = get_cur_mix_value(cval, 0, 0, &oval);
914 if (err < 0) 899 if (err < 0)
915 return cval->mixer->ignore_ctl_error ? 0 : err; 900 return cval->mixer->ignore_ctl_error ? 0 : err;
916 val = ucontrol->value.integer.value[0]; 901 val = ucontrol->value.integer.value[0];
917 val = get_abs_value(cval, val); 902 val = get_abs_value(cval, val);
918 if (val != oval) { 903 if (val != oval) {
919 set_cur_mix_value(cval, 0, 0, val); 904 set_cur_mix_value(cval, 0, 0, val);
920 changed = 1; 905 changed = 1;
921 } 906 }
922 } 907 }
923 return changed; 908 return changed;
924 } 909 }
925 910
926 static struct snd_kcontrol_new usb_feature_unit_ctl = { 911 static struct snd_kcontrol_new usb_feature_unit_ctl = {
927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
928 .name = "", /* will be filled later manually */ 913 .name = "", /* will be filled later manually */
929 .info = mixer_ctl_feature_info, 914 .info = mixer_ctl_feature_info,
930 .get = mixer_ctl_feature_get, 915 .get = mixer_ctl_feature_get,
931 .put = mixer_ctl_feature_put, 916 .put = mixer_ctl_feature_put,
932 }; 917 };
933 918
934 919
935 /* 920 /*
936 * build a feature control 921 * build a feature control
937 */ 922 */
938 923
939 static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str) 924 static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
940 { 925 {
941 return strlcat(kctl->id.name, str, sizeof(kctl->id.name)); 926 return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
942 } 927 }
943 928
944 static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, 929 static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
945 unsigned int ctl_mask, int control, 930 unsigned int ctl_mask, int control,
946 struct usb_audio_term *iterm, int unitid) 931 struct usb_audio_term *iterm, int unitid)
947 { 932 {
948 unsigned int len = 0; 933 unsigned int len = 0;
949 int mapped_name = 0; 934 int mapped_name = 0;
950 int nameid = desc[desc[0] - 1]; 935 int nameid = desc[desc[0] - 1];
951 struct snd_kcontrol *kctl; 936 struct snd_kcontrol *kctl;
952 struct usb_mixer_elem_info *cval; 937 struct usb_mixer_elem_info *cval;
953 const struct usbmix_name_map *map; 938 const struct usbmix_name_map *map;
954 939
955 control++; /* change from zero-based to 1-based value */ 940 control++; /* change from zero-based to 1-based value */
956 941
957 if (control == USB_FEATURE_GEQ) { 942 if (control == UAC_GRAPHIC_EQUALIZER_CONTROL) {
958 /* FIXME: not supported yet */ 943 /* FIXME: not supported yet */
959 return; 944 return;
960 } 945 }
961 946
962 map = find_map(state, unitid, control); 947 map = find_map(state, unitid, control);
963 if (check_ignored_ctl(map)) 948 if (check_ignored_ctl(map))
964 return; 949 return;
965 950
966 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 951 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
967 if (! cval) { 952 if (! cval) {
968 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 953 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
969 return; 954 return;
970 } 955 }
971 cval->mixer = state->mixer; 956 cval->mixer = state->mixer;
972 cval->id = unitid; 957 cval->id = unitid;
973 cval->control = control; 958 cval->control = control;
974 cval->cmask = ctl_mask; 959 cval->cmask = ctl_mask;
975 cval->val_type = audio_feature_info[control-1].type; 960 cval->val_type = audio_feature_info[control-1].type;
976 if (ctl_mask == 0) 961 if (ctl_mask == 0)
977 cval->channels = 1; /* master channel */ 962 cval->channels = 1; /* master channel */
978 else { 963 else {
979 int i, c = 0; 964 int i, c = 0;
980 for (i = 0; i < 16; i++) 965 for (i = 0; i < 16; i++)
981 if (ctl_mask & (1 << i)) 966 if (ctl_mask & (1 << i))
982 c++; 967 c++;
983 cval->channels = c; 968 cval->channels = c;
984 } 969 }
985 970
986 /* get min/max values */ 971 /* get min/max values */
987 get_min_max(cval, 0); 972 get_min_max(cval, 0);
988 973
989 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 974 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
990 if (! kctl) { 975 if (! kctl) {
991 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 976 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
992 kfree(cval); 977 kfree(cval);
993 return; 978 return;
994 } 979 }
995 kctl->private_free = usb_mixer_elem_free; 980 kctl->private_free = usb_mixer_elem_free;
996 981
997 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 982 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
998 mapped_name = len != 0; 983 mapped_name = len != 0;
999 if (! len && nameid) 984 if (! len && nameid)
1000 len = snd_usb_copy_string_desc(state, nameid, 985 len = snd_usb_copy_string_desc(state, nameid,
1001 kctl->id.name, sizeof(kctl->id.name)); 986 kctl->id.name, sizeof(kctl->id.name));
1002 987
1003 switch (control) { 988 switch (control) {
1004 case USB_FEATURE_MUTE: 989 case UAC_MUTE_CONTROL:
1005 case USB_FEATURE_VOLUME: 990 case UAC_VOLUME_CONTROL:
1006 /* determine the control name. the rule is: 991 /* determine the control name. the rule is:
1007 * - if a name id is given in descriptor, use it. 992 * - if a name id is given in descriptor, use it.
1008 * - if the connected input can be determined, then use the name 993 * - if the connected input can be determined, then use the name
1009 * of terminal type. 994 * of terminal type.
1010 * - if the connected output can be determined, use it. 995 * - if the connected output can be determined, use it.
1011 * - otherwise, anonymous name. 996 * - otherwise, anonymous name.
1012 */ 997 */
1013 if (! len) { 998 if (! len) {
1014 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 1); 999 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 1);
1015 if (! len) 1000 if (! len)
1016 len = get_term_name(state, &state->oterm, kctl->id.name, sizeof(kctl->id.name), 1); 1001 len = get_term_name(state, &state->oterm, kctl->id.name, sizeof(kctl->id.name), 1);
1017 if (! len) 1002 if (! len)
1018 len = snprintf(kctl->id.name, sizeof(kctl->id.name), 1003 len = snprintf(kctl->id.name, sizeof(kctl->id.name),
1019 "Feature %d", unitid); 1004 "Feature %d", unitid);
1020 } 1005 }
1021 /* determine the stream direction: 1006 /* determine the stream direction:
1022 * if the connected output is USB stream, then it's likely a 1007 * if the connected output is USB stream, then it's likely a
1023 * capture stream. otherwise it should be playback (hopefully :) 1008 * capture stream. otherwise it should be playback (hopefully :)
1024 */ 1009 */
1025 if (! mapped_name && ! (state->oterm.type >> 16)) { 1010 if (! mapped_name && ! (state->oterm.type >> 16)) {
1026 if ((state->oterm.type & 0xff00) == 0x0100) { 1011 if ((state->oterm.type & 0xff00) == 0x0100) {
1027 len = append_ctl_name(kctl, " Capture"); 1012 len = append_ctl_name(kctl, " Capture");
1028 } else { 1013 } else {
1029 len = append_ctl_name(kctl, " Playback"); 1014 len = append_ctl_name(kctl, " Playback");
1030 } 1015 }
1031 } 1016 }
1032 append_ctl_name(kctl, control == USB_FEATURE_MUTE ? 1017 append_ctl_name(kctl, control == UAC_MUTE_CONTROL ?
1033 " Switch" : " Volume"); 1018 " Switch" : " Volume");
1034 if (control == USB_FEATURE_VOLUME) { 1019 if (control == UAC_VOLUME_CONTROL) {
1035 kctl->tlv.c = mixer_vol_tlv; 1020 kctl->tlv.c = mixer_vol_tlv;
1036 kctl->vd[0].access |= 1021 kctl->vd[0].access |=
1037 SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1022 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1038 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1023 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1039 check_mapped_dB(map, cval); 1024 check_mapped_dB(map, cval);
1040 } 1025 }
1041 break; 1026 break;
1042 1027
1043 default: 1028 default:
1044 if (! len) 1029 if (! len)
1045 strlcpy(kctl->id.name, audio_feature_info[control-1].name, 1030 strlcpy(kctl->id.name, audio_feature_info[control-1].name,
1046 sizeof(kctl->id.name)); 1031 sizeof(kctl->id.name));
1047 break; 1032 break;
1048 } 1033 }
1049 1034
1050 /* volume control quirks */ 1035 /* volume control quirks */
1051 switch (state->chip->usb_id) { 1036 switch (state->chip->usb_id) {
1052 case USB_ID(0x0471, 0x0101): 1037 case USB_ID(0x0471, 0x0101):
1053 case USB_ID(0x0471, 0x0104): 1038 case USB_ID(0x0471, 0x0104):
1054 case USB_ID(0x0471, 0x0105): 1039 case USB_ID(0x0471, 0x0105):
1055 case USB_ID(0x0672, 0x1041): 1040 case USB_ID(0x0672, 0x1041):
1056 /* quirk for UDA1321/N101. 1041 /* quirk for UDA1321/N101.
1057 * note that detection between firmware 2.1.1.7 (N101) 1042 * note that detection between firmware 2.1.1.7 (N101)
1058 * and later 2.1.1.21 is not very clear from datasheets. 1043 * and later 2.1.1.21 is not very clear from datasheets.
1059 * I hope that the min value is -15360 for newer firmware --jk 1044 * I hope that the min value is -15360 for newer firmware --jk
1060 */ 1045 */
1061 if (!strcmp(kctl->id.name, "PCM Playback Volume") && 1046 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
1062 cval->min == -15616) { 1047 cval->min == -15616) {
1063 snd_printk(KERN_INFO 1048 snd_printk(KERN_INFO
1064 "set volume quirk for UDA1321/N101 chip\n"); 1049 "set volume quirk for UDA1321/N101 chip\n");
1065 cval->max = -256; 1050 cval->max = -256;
1066 } 1051 }
1067 break; 1052 break;
1068 1053
1069 case USB_ID(0x046d, 0x09a4): 1054 case USB_ID(0x046d, 0x09a4):
1070 if (!strcmp(kctl->id.name, "Mic Capture Volume")) { 1055 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1071 snd_printk(KERN_INFO 1056 snd_printk(KERN_INFO
1072 "set volume quirk for QuickCam E3500\n"); 1057 "set volume quirk for QuickCam E3500\n");
1073 cval->min = 6080; 1058 cval->min = 6080;
1074 cval->max = 8768; 1059 cval->max = 8768;
1075 cval->res = 192; 1060 cval->res = 192;
1076 } 1061 }
1077 break; 1062 break;
1078 1063
1079 } 1064 }
1080 1065
1081 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", 1066 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
1082 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res); 1067 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res);
1083 add_control_to_empty(state, kctl); 1068 add_control_to_empty(state, kctl);
1084 } 1069 }
1085 1070
1086 1071
1087 1072
1088 /* 1073 /*
1089 * parse a feature unit 1074 * parse a feature unit
1090 * 1075 *
1091 * most of controlls are defined here. 1076 * most of controlls are defined here.
1092 */ 1077 */
1093 static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr) 1078 static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr)
1094 { 1079 {
1095 int channels, i, j; 1080 int channels, i, j;
1096 struct usb_audio_term iterm; 1081 struct usb_audio_term iterm;
1097 unsigned int master_bits, first_ch_bits; 1082 unsigned int master_bits, first_ch_bits;
1098 int err, csize; 1083 int err, csize;
1099 struct uac_feature_unit_descriptor *ftr = _ftr; 1084 struct uac_feature_unit_descriptor *ftr = _ftr;
1100 1085
1101 if (ftr->bLength < 7 || ! (csize = ftr->bControlSize) || ftr->bLength < 7 + csize) { 1086 if (ftr->bLength < 7 || ! (csize = ftr->bControlSize) || ftr->bLength < 7 + csize) {
1102 snd_printk(KERN_ERR "usbaudio: unit %u: invalid UAC_FEATURE_UNIT descriptor\n", unitid); 1087 snd_printk(KERN_ERR "usbaudio: unit %u: invalid UAC_FEATURE_UNIT descriptor\n", unitid);
1103 return -EINVAL; 1088 return -EINVAL;
1104 } 1089 }
1105 1090
1106 /* parse the source unit */ 1091 /* parse the source unit */
1107 if ((err = parse_audio_unit(state, ftr->bSourceID)) < 0) 1092 if ((err = parse_audio_unit(state, ftr->bSourceID)) < 0)
1108 return err; 1093 return err;
1109 1094
1110 /* determine the input source type and name */ 1095 /* determine the input source type and name */
1111 if (check_input_term(state, ftr->bSourceID, &iterm) < 0) 1096 if (check_input_term(state, ftr->bSourceID, &iterm) < 0)
1112 return -EINVAL; 1097 return -EINVAL;
1113 1098
1114 channels = (ftr->bLength - 7) / csize - 1; 1099 channels = (ftr->bLength - 7) / csize - 1;
1115 1100
1116 master_bits = snd_usb_combine_bytes(ftr->controls, csize); 1101 master_bits = snd_usb_combine_bytes(ftr->controls, csize);
1117 /* master configuration quirks */ 1102 /* master configuration quirks */
1118 switch (state->chip->usb_id) { 1103 switch (state->chip->usb_id) {
1119 case USB_ID(0x08bb, 0x2702): 1104 case USB_ID(0x08bb, 0x2702):
1120 snd_printk(KERN_INFO 1105 snd_printk(KERN_INFO
1121 "usbmixer: master volume quirk for PCM2702 chip\n"); 1106 "usbmixer: master volume quirk for PCM2702 chip\n");
1122 /* disable non-functional volume control */ 1107 /* disable non-functional volume control */
1123 master_bits &= ~(1 << (USB_FEATURE_VOLUME - 1)); 1108 master_bits &= ~UAC_FU_VOLUME;
1124 break; 1109 break;
1125 } 1110 }
1126 if (channels > 0) 1111 if (channels > 0)
1127 first_ch_bits = snd_usb_combine_bytes(ftr->controls + csize, csize); 1112 first_ch_bits = snd_usb_combine_bytes(ftr->controls + csize, csize);
1128 else 1113 else
1129 first_ch_bits = 0; 1114 first_ch_bits = 0;
1130 /* check all control types */ 1115 /* check all control types */
1131 for (i = 0; i < 10; i++) { 1116 for (i = 0; i < 10; i++) {
1132 unsigned int ch_bits = 0; 1117 unsigned int ch_bits = 0;
1133 for (j = 0; j < channels; j++) { 1118 for (j = 0; j < channels; j++) {
1134 unsigned int mask = snd_usb_combine_bytes(ftr->controls + csize * (j+1), csize); 1119 unsigned int mask = snd_usb_combine_bytes(ftr->controls + csize * (j+1), csize);
1135 if (mask & (1 << i)) 1120 if (mask & (1 << i))
1136 ch_bits |= (1 << j); 1121 ch_bits |= (1 << j);
1137 } 1122 }
1138 if (ch_bits & 1) /* the first channel must be set (for ease of programming) */ 1123 if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
1139 build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid); 1124 build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid);
1140 if (master_bits & (1 << i)) 1125 if (master_bits & (1 << i))
1141 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid); 1126 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid);
1142 } 1127 }
1143 1128
1144 return 0; 1129 return 0;
1145 } 1130 }
1146 1131
1147 1132
1148 /* 1133 /*
1149 * Mixer Unit 1134 * Mixer Unit
1150 */ 1135 */
1151 1136
1152 /* 1137 /*
1153 * build a mixer unit control 1138 * build a mixer unit control
1154 * 1139 *
1155 * the callbacks are identical with feature unit. 1140 * the callbacks are identical with feature unit.
1156 * input channel number (zero based) is given in control field instead. 1141 * input channel number (zero based) is given in control field instead.
1157 */ 1142 */
1158 1143
1159 static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, 1144 static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1160 int in_pin, int in_ch, int unitid, 1145 int in_pin, int in_ch, int unitid,
1161 struct usb_audio_term *iterm) 1146 struct usb_audio_term *iterm)
1162 { 1147 {
1163 struct usb_mixer_elem_info *cval; 1148 struct usb_mixer_elem_info *cval;
1164 unsigned int input_pins = desc[4]; 1149 unsigned int input_pins = desc[4];
1165 unsigned int num_outs = desc[5 + input_pins]; 1150 unsigned int num_outs = desc[5 + input_pins];
1166 unsigned int i, len; 1151 unsigned int i, len;
1167 struct snd_kcontrol *kctl; 1152 struct snd_kcontrol *kctl;
1168 const struct usbmix_name_map *map; 1153 const struct usbmix_name_map *map;
1169 1154
1170 map = find_map(state, unitid, 0); 1155 map = find_map(state, unitid, 0);
1171 if (check_ignored_ctl(map)) 1156 if (check_ignored_ctl(map))
1172 return; 1157 return;
1173 1158
1174 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1159 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1175 if (! cval) 1160 if (! cval)
1176 return; 1161 return;
1177 1162
1178 cval->mixer = state->mixer; 1163 cval->mixer = state->mixer;
1179 cval->id = unitid; 1164 cval->id = unitid;
1180 cval->control = in_ch + 1; /* based on 1 */ 1165 cval->control = in_ch + 1; /* based on 1 */
1181 cval->val_type = USB_MIXER_S16; 1166 cval->val_type = USB_MIXER_S16;
1182 for (i = 0; i < num_outs; i++) { 1167 for (i = 0; i < num_outs; i++) {
1183 if (check_matrix_bitmap(desc + 9 + input_pins, in_ch, i, num_outs)) { 1168 if (check_matrix_bitmap(desc + 9 + input_pins, in_ch, i, num_outs)) {
1184 cval->cmask |= (1 << i); 1169 cval->cmask |= (1 << i);
1185 cval->channels++; 1170 cval->channels++;
1186 } 1171 }
1187 } 1172 }
1188 1173
1189 /* get min/max values */ 1174 /* get min/max values */
1190 get_min_max(cval, 0); 1175 get_min_max(cval, 0);
1191 1176
1192 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1177 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
1193 if (! kctl) { 1178 if (! kctl) {
1194 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1179 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1195 kfree(cval); 1180 kfree(cval);
1196 return; 1181 return;
1197 } 1182 }
1198 kctl->private_free = usb_mixer_elem_free; 1183 kctl->private_free = usb_mixer_elem_free;
1199 1184
1200 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 1185 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1201 if (! len) 1186 if (! len)
1202 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); 1187 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
1203 if (! len) 1188 if (! len)
1204 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); 1189 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
1205 append_ctl_name(kctl, " Volume"); 1190 append_ctl_name(kctl, " Volume");
1206 1191
1207 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", 1192 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
1208 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1193 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1209 add_control_to_empty(state, kctl); 1194 add_control_to_empty(state, kctl);
1210 } 1195 }
1211 1196
1212 1197
1213 /* 1198 /*
1214 * parse a mixer unit 1199 * parse a mixer unit
1215 */ 1200 */
1216 static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigned char *desc) 1201 static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1217 { 1202 {
1218 struct usb_audio_term iterm; 1203 struct usb_audio_term iterm;
1219 int input_pins, num_ins, num_outs; 1204 int input_pins, num_ins, num_outs;
1220 int pin, ich, err; 1205 int pin, ich, err;
1221 1206
1222 if (desc[0] < 11 || ! (input_pins = desc[4]) || ! (num_outs = desc[5 + input_pins])) { 1207 if (desc[0] < 11 || ! (input_pins = desc[4]) || ! (num_outs = desc[5 + input_pins])) {
1223 snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid); 1208 snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid);
1224 return -EINVAL; 1209 return -EINVAL;
1225 } 1210 }
1226 /* no bmControls field (e.g. Maya44) -> ignore */ 1211 /* no bmControls field (e.g. Maya44) -> ignore */
1227 if (desc[0] <= 10 + input_pins) { 1212 if (desc[0] <= 10 + input_pins) {
1228 snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid); 1213 snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid);
1229 return 0; 1214 return 0;
1230 } 1215 }
1231 1216
1232 num_ins = 0; 1217 num_ins = 0;
1233 ich = 0; 1218 ich = 0;
1234 for (pin = 0; pin < input_pins; pin++) { 1219 for (pin = 0; pin < input_pins; pin++) {
1235 err = parse_audio_unit(state, desc[5 + pin]); 1220 err = parse_audio_unit(state, desc[5 + pin]);
1236 if (err < 0) 1221 if (err < 0)
1237 return err; 1222 return err;
1238 err = check_input_term(state, desc[5 + pin], &iterm); 1223 err = check_input_term(state, desc[5 + pin], &iterm);
1239 if (err < 0) 1224 if (err < 0)
1240 return err; 1225 return err;
1241 num_ins += iterm.channels; 1226 num_ins += iterm.channels;
1242 for (; ich < num_ins; ++ich) { 1227 for (; ich < num_ins; ++ich) {
1243 int och, ich_has_controls = 0; 1228 int och, ich_has_controls = 0;
1244 1229
1245 for (och = 0; och < num_outs; ++och) { 1230 for (och = 0; och < num_outs; ++och) {
1246 if (check_matrix_bitmap(desc + 9 + input_pins, 1231 if (check_matrix_bitmap(desc + 9 + input_pins,
1247 ich, och, num_outs)) { 1232 ich, och, num_outs)) {
1248 ich_has_controls = 1; 1233 ich_has_controls = 1;
1249 break; 1234 break;
1250 } 1235 }
1251 } 1236 }
1252 if (ich_has_controls) 1237 if (ich_has_controls)
1253 build_mixer_unit_ctl(state, desc, pin, ich, 1238 build_mixer_unit_ctl(state, desc, pin, ich,
1254 unitid, &iterm); 1239 unitid, &iterm);
1255 } 1240 }
1256 } 1241 }
1257 return 0; 1242 return 0;
1258 } 1243 }
1259 1244
1260 1245
1261 /* 1246 /*
1262 * Processing Unit / Extension Unit 1247 * Processing Unit / Extension Unit
1263 */ 1248 */
1264 1249
1265 /* get callback for processing/extension unit */ 1250 /* get callback for processing/extension unit */
1266 static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1251 static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1267 { 1252 {
1268 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1253 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1269 int err, val; 1254 int err, val;
1270 1255
1271 err = get_cur_ctl_value(cval, cval->control << 8, &val); 1256 err = get_cur_ctl_value(cval, cval->control << 8, &val);
1272 if (err < 0 && cval->mixer->ignore_ctl_error) { 1257 if (err < 0 && cval->mixer->ignore_ctl_error) {
1273 ucontrol->value.integer.value[0] = cval->min; 1258 ucontrol->value.integer.value[0] = cval->min;
1274 return 0; 1259 return 0;
1275 } 1260 }
1276 if (err < 0) 1261 if (err < 0)
1277 return err; 1262 return err;
1278 val = get_relative_value(cval, val); 1263 val = get_relative_value(cval, val);
1279 ucontrol->value.integer.value[0] = val; 1264 ucontrol->value.integer.value[0] = val;
1280 return 0; 1265 return 0;
1281 } 1266 }
1282 1267
1283 /* put callback for processing/extension unit */ 1268 /* put callback for processing/extension unit */
1284 static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1269 static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1285 { 1270 {
1286 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1271 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1287 int val, oval, err; 1272 int val, oval, err;
1288 1273
1289 err = get_cur_ctl_value(cval, cval->control << 8, &oval); 1274 err = get_cur_ctl_value(cval, cval->control << 8, &oval);
1290 if (err < 0) { 1275 if (err < 0) {
1291 if (cval->mixer->ignore_ctl_error) 1276 if (cval->mixer->ignore_ctl_error)
1292 return 0; 1277 return 0;
1293 return err; 1278 return err;
1294 } 1279 }
1295 val = ucontrol->value.integer.value[0]; 1280 val = ucontrol->value.integer.value[0];
1296 val = get_abs_value(cval, val); 1281 val = get_abs_value(cval, val);
1297 if (val != oval) { 1282 if (val != oval) {
1298 set_cur_ctl_value(cval, cval->control << 8, val); 1283 set_cur_ctl_value(cval, cval->control << 8, val);
1299 return 1; 1284 return 1;
1300 } 1285 }
1301 return 0; 1286 return 0;
1302 } 1287 }
1303 1288
1304 /* alsa control interface for processing/extension unit */ 1289 /* alsa control interface for processing/extension unit */
1305 static struct snd_kcontrol_new mixer_procunit_ctl = { 1290 static struct snd_kcontrol_new mixer_procunit_ctl = {
1306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1307 .name = "", /* will be filled later */ 1292 .name = "", /* will be filled later */
1308 .info = mixer_ctl_feature_info, 1293 .info = mixer_ctl_feature_info,
1309 .get = mixer_ctl_procunit_get, 1294 .get = mixer_ctl_procunit_get,
1310 .put = mixer_ctl_procunit_put, 1295 .put = mixer_ctl_procunit_put,
1311 }; 1296 };
1312 1297
1313 1298
1314 /* 1299 /*
1315 * predefined data for processing units 1300 * predefined data for processing units
1316 */ 1301 */
1317 struct procunit_value_info { 1302 struct procunit_value_info {
1318 int control; 1303 int control;
1319 char *suffix; 1304 char *suffix;
1320 int val_type; 1305 int val_type;
1321 int min_value; 1306 int min_value;
1322 }; 1307 };
1323 1308
1324 struct procunit_info { 1309 struct procunit_info {
1325 int type; 1310 int type;
1326 char *name; 1311 char *name;
1327 struct procunit_value_info *values; 1312 struct procunit_value_info *values;
1328 }; 1313 };
1329 1314
1330 static struct procunit_value_info updown_proc_info[] = { 1315 static struct procunit_value_info updown_proc_info[] = {
1331 { USB_PROC_UPDOWN_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1316 { USB_PROC_UPDOWN_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1332 { USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 }, 1317 { USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
1333 { 0 } 1318 { 0 }
1334 }; 1319 };
1335 static struct procunit_value_info prologic_proc_info[] = { 1320 static struct procunit_value_info prologic_proc_info[] = {
1336 { USB_PROC_PROLOGIC_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1321 { USB_PROC_PROLOGIC_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1337 { USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 }, 1322 { USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
1338 { 0 } 1323 { 0 }
1339 }; 1324 };
1340 static struct procunit_value_info threed_enh_proc_info[] = { 1325 static struct procunit_value_info threed_enh_proc_info[] = {
1341 { USB_PROC_3DENH_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1326 { USB_PROC_3DENH_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1342 { USB_PROC_3DENH_SPACE, "Spaciousness", USB_MIXER_U8 }, 1327 { USB_PROC_3DENH_SPACE, "Spaciousness", USB_MIXER_U8 },
1343 { 0 } 1328 { 0 }
1344 }; 1329 };
1345 static struct procunit_value_info reverb_proc_info[] = { 1330 static struct procunit_value_info reverb_proc_info[] = {
1346 { USB_PROC_REVERB_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1331 { USB_PROC_REVERB_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1347 { USB_PROC_REVERB_LEVEL, "Level", USB_MIXER_U8 }, 1332 { USB_PROC_REVERB_LEVEL, "Level", USB_MIXER_U8 },
1348 { USB_PROC_REVERB_TIME, "Time", USB_MIXER_U16 }, 1333 { USB_PROC_REVERB_TIME, "Time", USB_MIXER_U16 },
1349 { USB_PROC_REVERB_DELAY, "Delay", USB_MIXER_U8 }, 1334 { USB_PROC_REVERB_DELAY, "Delay", USB_MIXER_U8 },
1350 { 0 } 1335 { 0 }
1351 }; 1336 };
1352 static struct procunit_value_info chorus_proc_info[] = { 1337 static struct procunit_value_info chorus_proc_info[] = {
1353 { USB_PROC_CHORUS_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1338 { USB_PROC_CHORUS_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1354 { USB_PROC_CHORUS_LEVEL, "Level", USB_MIXER_U8 }, 1339 { USB_PROC_CHORUS_LEVEL, "Level", USB_MIXER_U8 },
1355 { USB_PROC_CHORUS_RATE, "Rate", USB_MIXER_U16 }, 1340 { USB_PROC_CHORUS_RATE, "Rate", USB_MIXER_U16 },
1356 { USB_PROC_CHORUS_DEPTH, "Depth", USB_MIXER_U16 }, 1341 { USB_PROC_CHORUS_DEPTH, "Depth", USB_MIXER_U16 },
1357 { 0 } 1342 { 0 }
1358 }; 1343 };
1359 static struct procunit_value_info dcr_proc_info[] = { 1344 static struct procunit_value_info dcr_proc_info[] = {
1360 { USB_PROC_DCR_SWITCH, "Switch", USB_MIXER_BOOLEAN }, 1345 { USB_PROC_DCR_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1361 { USB_PROC_DCR_RATIO, "Ratio", USB_MIXER_U16 }, 1346 { USB_PROC_DCR_RATIO, "Ratio", USB_MIXER_U16 },
1362 { USB_PROC_DCR_MAX_AMP, "Max Amp", USB_MIXER_S16 }, 1347 { USB_PROC_DCR_MAX_AMP, "Max Amp", USB_MIXER_S16 },
1363 { USB_PROC_DCR_THRESHOLD, "Threshold", USB_MIXER_S16 }, 1348 { USB_PROC_DCR_THRESHOLD, "Threshold", USB_MIXER_S16 },
1364 { USB_PROC_DCR_ATTACK, "Attack Time", USB_MIXER_U16 }, 1349 { USB_PROC_DCR_ATTACK, "Attack Time", USB_MIXER_U16 },
1365 { USB_PROC_DCR_RELEASE, "Release Time", USB_MIXER_U16 }, 1350 { USB_PROC_DCR_RELEASE, "Release Time", USB_MIXER_U16 },
1366 { 0 } 1351 { 0 }
1367 }; 1352 };
1368 1353
1369 static struct procunit_info procunits[] = { 1354 static struct procunit_info procunits[] = {
1370 { USB_PROC_UPDOWN, "Up Down", updown_proc_info }, 1355 { USB_PROC_UPDOWN, "Up Down", updown_proc_info },
1371 { USB_PROC_PROLOGIC, "Dolby Prologic", prologic_proc_info }, 1356 { USB_PROC_PROLOGIC, "Dolby Prologic", prologic_proc_info },
1372 { USB_PROC_3DENH, "3D Stereo Extender", threed_enh_proc_info }, 1357 { USB_PROC_3DENH, "3D Stereo Extender", threed_enh_proc_info },
1373 { USB_PROC_REVERB, "Reverb", reverb_proc_info }, 1358 { USB_PROC_REVERB, "Reverb", reverb_proc_info },
1374 { USB_PROC_CHORUS, "Chorus", chorus_proc_info }, 1359 { USB_PROC_CHORUS, "Chorus", chorus_proc_info },
1375 { USB_PROC_DCR, "DCR", dcr_proc_info }, 1360 { USB_PROC_DCR, "DCR", dcr_proc_info },
1376 { 0 }, 1361 { 0 },
1377 }; 1362 };
1378 /* 1363 /*
1379 * predefined data for extension units 1364 * predefined data for extension units
1380 */ 1365 */
1381 static struct procunit_value_info clock_rate_xu_info[] = { 1366 static struct procunit_value_info clock_rate_xu_info[] = {
1382 { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 }, 1367 { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 },
1383 { 0 } 1368 { 0 }
1384 }; 1369 };
1385 static struct procunit_value_info clock_source_xu_info[] = { 1370 static struct procunit_value_info clock_source_xu_info[] = {
1386 { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN }, 1371 { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN },
1387 { 0 } 1372 { 0 }
1388 }; 1373 };
1389 static struct procunit_value_info spdif_format_xu_info[] = { 1374 static struct procunit_value_info spdif_format_xu_info[] = {
1390 { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN }, 1375 { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN },
1391 { 0 } 1376 { 0 }
1392 }; 1377 };
1393 static struct procunit_value_info soft_limit_xu_info[] = { 1378 static struct procunit_value_info soft_limit_xu_info[] = {
1394 { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN }, 1379 { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN },
1395 { 0 } 1380 { 0 }
1396 }; 1381 };
1397 static struct procunit_info extunits[] = { 1382 static struct procunit_info extunits[] = {
1398 { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info }, 1383 { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info },
1399 { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info }, 1384 { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info },
1400 { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info }, 1385 { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info },
1401 { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info }, 1386 { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info },
1402 { 0 } 1387 { 0 }
1403 }; 1388 };
1404 /* 1389 /*
1405 * build a processing/extension unit 1390 * build a processing/extension unit
1406 */ 1391 */
1407 static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned char *dsc, struct procunit_info *list, char *name) 1392 static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned char *dsc, struct procunit_info *list, char *name)
1408 { 1393 {
1409 int num_ins = dsc[6]; 1394 int num_ins = dsc[6];
1410 struct usb_mixer_elem_info *cval; 1395 struct usb_mixer_elem_info *cval;
1411 struct snd_kcontrol *kctl; 1396 struct snd_kcontrol *kctl;
1412 int i, err, nameid, type, len; 1397 int i, err, nameid, type, len;
1413 struct procunit_info *info; 1398 struct procunit_info *info;
1414 struct procunit_value_info *valinfo; 1399 struct procunit_value_info *valinfo;
1415 const struct usbmix_name_map *map; 1400 const struct usbmix_name_map *map;
1416 static struct procunit_value_info default_value_info[] = { 1401 static struct procunit_value_info default_value_info[] = {
1417 { 0x01, "Switch", USB_MIXER_BOOLEAN }, 1402 { 0x01, "Switch", USB_MIXER_BOOLEAN },
1418 { 0 } 1403 { 0 }
1419 }; 1404 };
1420 static struct procunit_info default_info = { 1405 static struct procunit_info default_info = {
1421 0, NULL, default_value_info 1406 0, NULL, default_value_info
1422 }; 1407 };
1423 1408
1424 if (dsc[0] < 13 || dsc[0] < 13 + num_ins || dsc[0] < num_ins + dsc[11 + num_ins]) { 1409 if (dsc[0] < 13 || dsc[0] < 13 + num_ins || dsc[0] < num_ins + dsc[11 + num_ins]) {
1425 snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid); 1410 snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid);
1426 return -EINVAL; 1411 return -EINVAL;
1427 } 1412 }
1428 1413
1429 for (i = 0; i < num_ins; i++) { 1414 for (i = 0; i < num_ins; i++) {
1430 if ((err = parse_audio_unit(state, dsc[7 + i])) < 0) 1415 if ((err = parse_audio_unit(state, dsc[7 + i])) < 0)
1431 return err; 1416 return err;
1432 } 1417 }
1433 1418
1434 type = combine_word(&dsc[4]); 1419 type = combine_word(&dsc[4]);
1435 for (info = list; info && info->type; info++) 1420 for (info = list; info && info->type; info++)
1436 if (info->type == type) 1421 if (info->type == type)
1437 break; 1422 break;
1438 if (! info || ! info->type) 1423 if (! info || ! info->type)
1439 info = &default_info; 1424 info = &default_info;
1440 1425
1441 for (valinfo = info->values; valinfo->control; valinfo++) { 1426 for (valinfo = info->values; valinfo->control; valinfo++) {
1442 /* FIXME: bitmap might be longer than 8bit */ 1427 /* FIXME: bitmap might be longer than 8bit */
1443 if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1)))) 1428 if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1))))
1444 continue; 1429 continue;
1445 map = find_map(state, unitid, valinfo->control); 1430 map = find_map(state, unitid, valinfo->control);
1446 if (check_ignored_ctl(map)) 1431 if (check_ignored_ctl(map))
1447 continue; 1432 continue;
1448 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1433 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1449 if (! cval) { 1434 if (! cval) {
1450 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1435 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1451 return -ENOMEM; 1436 return -ENOMEM;
1452 } 1437 }
1453 cval->mixer = state->mixer; 1438 cval->mixer = state->mixer;
1454 cval->id = unitid; 1439 cval->id = unitid;
1455 cval->control = valinfo->control; 1440 cval->control = valinfo->control;
1456 cval->val_type = valinfo->val_type; 1441 cval->val_type = valinfo->val_type;
1457 cval->channels = 1; 1442 cval->channels = 1;
1458 1443
1459 /* get min/max values */ 1444 /* get min/max values */
1460 if (type == USB_PROC_UPDOWN && cval->control == USB_PROC_UPDOWN_MODE_SEL) { 1445 if (type == USB_PROC_UPDOWN && cval->control == USB_PROC_UPDOWN_MODE_SEL) {
1461 /* FIXME: hard-coded */ 1446 /* FIXME: hard-coded */
1462 cval->min = 1; 1447 cval->min = 1;
1463 cval->max = dsc[15]; 1448 cval->max = dsc[15];
1464 cval->res = 1; 1449 cval->res = 1;
1465 cval->initialized = 1; 1450 cval->initialized = 1;
1466 } else { 1451 } else {
1467 if (type == USB_XU_CLOCK_RATE) { 1452 if (type == USB_XU_CLOCK_RATE) {
1468 /* E-Mu USB 0404/0202/TrackerPre 1453 /* E-Mu USB 0404/0202/TrackerPre
1469 * samplerate control quirk 1454 * samplerate control quirk
1470 */ 1455 */
1471 cval->min = 0; 1456 cval->min = 0;
1472 cval->max = 5; 1457 cval->max = 5;
1473 cval->res = 1; 1458 cval->res = 1;
1474 cval->initialized = 1; 1459 cval->initialized = 1;
1475 } else 1460 } else
1476 get_min_max(cval, valinfo->min_value); 1461 get_min_max(cval, valinfo->min_value);
1477 } 1462 }
1478 1463
1479 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); 1464 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
1480 if (! kctl) { 1465 if (! kctl) {
1481 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1466 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1482 kfree(cval); 1467 kfree(cval);
1483 return -ENOMEM; 1468 return -ENOMEM;
1484 } 1469 }
1485 kctl->private_free = usb_mixer_elem_free; 1470 kctl->private_free = usb_mixer_elem_free;
1486 1471
1487 if (check_mapped_name(map, kctl->id.name, 1472 if (check_mapped_name(map, kctl->id.name,
1488 sizeof(kctl->id.name))) 1473 sizeof(kctl->id.name)))
1489 /* nothing */ ; 1474 /* nothing */ ;
1490 else if (info->name) 1475 else if (info->name)
1491 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); 1476 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
1492 else { 1477 else {
1493 nameid = dsc[12 + num_ins + dsc[11 + num_ins]]; 1478 nameid = dsc[12 + num_ins + dsc[11 + num_ins]];
1494 len = 0; 1479 len = 0;
1495 if (nameid) 1480 if (nameid)
1496 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); 1481 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
1497 if (! len) 1482 if (! len)
1498 strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); 1483 strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
1499 } 1484 }
1500 append_ctl_name(kctl, " "); 1485 append_ctl_name(kctl, " ");
1501 append_ctl_name(kctl, valinfo->suffix); 1486 append_ctl_name(kctl, valinfo->suffix);
1502 1487
1503 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", 1488 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
1504 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1489 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1505 if ((err = add_control_to_empty(state, kctl)) < 0) 1490 if ((err = add_control_to_empty(state, kctl)) < 0)
1506 return err; 1491 return err;
1507 } 1492 }
1508 return 0; 1493 return 0;
1509 } 1494 }
1510 1495
1511 1496
1512 static int parse_audio_processing_unit(struct mixer_build *state, int unitid, unsigned char *desc) 1497 static int parse_audio_processing_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1513 { 1498 {
1514 return build_audio_procunit(state, unitid, desc, procunits, "Processing Unit"); 1499 return build_audio_procunit(state, unitid, desc, procunits, "Processing Unit");
1515 } 1500 }
1516 1501
1517 static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc) 1502 static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1518 { 1503 {
1519 return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit"); 1504 return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit");
1520 } 1505 }
1521 1506
1522 1507
1523 /* 1508 /*
1524 * Selector Unit 1509 * Selector Unit
1525 */ 1510 */
1526 1511
1527 /* info callback for selector unit 1512 /* info callback for selector unit
1528 * use an enumerator type for routing 1513 * use an enumerator type for routing
1529 */ 1514 */
1530 static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1515 static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1531 { 1516 {
1532 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1517 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1533 char **itemlist = (char **)kcontrol->private_value; 1518 char **itemlist = (char **)kcontrol->private_value;
1534 1519
1535 if (snd_BUG_ON(!itemlist)) 1520 if (snd_BUG_ON(!itemlist))
1536 return -EINVAL; 1521 return -EINVAL;
1537 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1522 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1538 uinfo->count = 1; 1523 uinfo->count = 1;
1539 uinfo->value.enumerated.items = cval->max; 1524 uinfo->value.enumerated.items = cval->max;
1540 if ((int)uinfo->value.enumerated.item >= cval->max) 1525 if ((int)uinfo->value.enumerated.item >= cval->max)
1541 uinfo->value.enumerated.item = cval->max - 1; 1526 uinfo->value.enumerated.item = cval->max - 1;
1542 strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]); 1527 strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]);
1543 return 0; 1528 return 0;
1544 } 1529 }
1545 1530
1546 /* get callback for selector unit */ 1531 /* get callback for selector unit */
1547 static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1532 static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1548 { 1533 {
1549 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1534 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1550 int val, err; 1535 int val, err;
1551 1536
1552 err = get_cur_ctl_value(cval, 0, &val); 1537 err = get_cur_ctl_value(cval, 0, &val);
1553 if (err < 0) { 1538 if (err < 0) {
1554 if (cval->mixer->ignore_ctl_error) { 1539 if (cval->mixer->ignore_ctl_error) {
1555 ucontrol->value.enumerated.item[0] = 0; 1540 ucontrol->value.enumerated.item[0] = 0;
1556 return 0; 1541 return 0;
1557 } 1542 }
1558 return err; 1543 return err;
1559 } 1544 }
1560 val = get_relative_value(cval, val); 1545 val = get_relative_value(cval, val);
1561 ucontrol->value.enumerated.item[0] = val; 1546 ucontrol->value.enumerated.item[0] = val;
1562 return 0; 1547 return 0;
1563 } 1548 }
1564 1549
1565 /* put callback for selector unit */ 1550 /* put callback for selector unit */
1566 static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1551 static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1567 { 1552 {
1568 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1553 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1569 int val, oval, err; 1554 int val, oval, err;
1570 1555
1571 err = get_cur_ctl_value(cval, 0, &oval); 1556 err = get_cur_ctl_value(cval, 0, &oval);
1572 if (err < 0) { 1557 if (err < 0) {
1573 if (cval->mixer->ignore_ctl_error) 1558 if (cval->mixer->ignore_ctl_error)
1574 return 0; 1559 return 0;
1575 return err; 1560 return err;
1576 } 1561 }
1577 val = ucontrol->value.enumerated.item[0]; 1562 val = ucontrol->value.enumerated.item[0];
1578 val = get_abs_value(cval, val); 1563 val = get_abs_value(cval, val);
1579 if (val != oval) { 1564 if (val != oval) {
1580 set_cur_ctl_value(cval, 0, val); 1565 set_cur_ctl_value(cval, 0, val);
1581 return 1; 1566 return 1;
1582 } 1567 }
1583 return 0; 1568 return 0;
1584 } 1569 }
1585 1570
1586 /* alsa control interface for selector unit */ 1571 /* alsa control interface for selector unit */
1587 static struct snd_kcontrol_new mixer_selectunit_ctl = { 1572 static struct snd_kcontrol_new mixer_selectunit_ctl = {
1588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1573 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1589 .name = "", /* will be filled later */ 1574 .name = "", /* will be filled later */
1590 .info = mixer_ctl_selector_info, 1575 .info = mixer_ctl_selector_info,
1591 .get = mixer_ctl_selector_get, 1576 .get = mixer_ctl_selector_get,
1592 .put = mixer_ctl_selector_put, 1577 .put = mixer_ctl_selector_put,
1593 }; 1578 };
1594 1579
1595 1580
1596 /* private free callback. 1581 /* private free callback.
1597 * free both private_data and private_value 1582 * free both private_data and private_value
1598 */ 1583 */
1599 static void usb_mixer_selector_elem_free(struct snd_kcontrol *kctl) 1584 static void usb_mixer_selector_elem_free(struct snd_kcontrol *kctl)
1600 { 1585 {
1601 int i, num_ins = 0; 1586 int i, num_ins = 0;
1602 1587
1603 if (kctl->private_data) { 1588 if (kctl->private_data) {
1604 struct usb_mixer_elem_info *cval = kctl->private_data; 1589 struct usb_mixer_elem_info *cval = kctl->private_data;
1605 num_ins = cval->max; 1590 num_ins = cval->max;
1606 kfree(cval); 1591 kfree(cval);
1607 kctl->private_data = NULL; 1592 kctl->private_data = NULL;
1608 } 1593 }
1609 if (kctl->private_value) { 1594 if (kctl->private_value) {
1610 char **itemlist = (char **)kctl->private_value; 1595 char **itemlist = (char **)kctl->private_value;
1611 for (i = 0; i < num_ins; i++) 1596 for (i = 0; i < num_ins; i++)
1612 kfree(itemlist[i]); 1597 kfree(itemlist[i]);
1613 kfree(itemlist); 1598 kfree(itemlist);
1614 kctl->private_value = 0; 1599 kctl->private_value = 0;
1615 } 1600 }
1616 } 1601 }
1617 1602
1618 /* 1603 /*
1619 * parse a selector unit 1604 * parse a selector unit
1620 */ 1605 */
1621 static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsigned char *desc) 1606 static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1622 { 1607 {
1623 unsigned int num_ins = desc[4]; 1608 unsigned int num_ins = desc[4];
1624 unsigned int i, nameid, len; 1609 unsigned int i, nameid, len;
1625 int err; 1610 int err;
1626 struct usb_mixer_elem_info *cval; 1611 struct usb_mixer_elem_info *cval;
1627 struct snd_kcontrol *kctl; 1612 struct snd_kcontrol *kctl;
1628 const struct usbmix_name_map *map; 1613 const struct usbmix_name_map *map;
1629 char **namelist; 1614 char **namelist;
1630 1615
1631 if (! num_ins || desc[0] < 5 + num_ins) { 1616 if (! num_ins || desc[0] < 5 + num_ins) {
1632 snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid); 1617 snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid);
1633 return -EINVAL; 1618 return -EINVAL;
1634 } 1619 }
1635 1620
1636 for (i = 0; i < num_ins; i++) { 1621 for (i = 0; i < num_ins; i++) {
1637 if ((err = parse_audio_unit(state, desc[5 + i])) < 0) 1622 if ((err = parse_audio_unit(state, desc[5 + i])) < 0)
1638 return err; 1623 return err;
1639 } 1624 }
1640 1625
1641 if (num_ins == 1) /* only one ? nonsense! */ 1626 if (num_ins == 1) /* only one ? nonsense! */
1642 return 0; 1627 return 0;
1643 1628
1644 map = find_map(state, unitid, 0); 1629 map = find_map(state, unitid, 0);
1645 if (check_ignored_ctl(map)) 1630 if (check_ignored_ctl(map))
1646 return 0; 1631 return 0;
1647 1632
1648 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1633 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1649 if (! cval) { 1634 if (! cval) {
1650 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1635 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1651 return -ENOMEM; 1636 return -ENOMEM;
1652 } 1637 }
1653 cval->mixer = state->mixer; 1638 cval->mixer = state->mixer;
1654 cval->id = unitid; 1639 cval->id = unitid;
1655 cval->val_type = USB_MIXER_U8; 1640 cval->val_type = USB_MIXER_U8;
1656 cval->channels = 1; 1641 cval->channels = 1;
1657 cval->min = 1; 1642 cval->min = 1;
1658 cval->max = num_ins; 1643 cval->max = num_ins;
1659 cval->res = 1; 1644 cval->res = 1;
1660 cval->initialized = 1; 1645 cval->initialized = 1;
1661 1646
1662 namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL); 1647 namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL);
1663 if (! namelist) { 1648 if (! namelist) {
1664 snd_printk(KERN_ERR "cannot malloc\n"); 1649 snd_printk(KERN_ERR "cannot malloc\n");
1665 kfree(cval); 1650 kfree(cval);
1666 return -ENOMEM; 1651 return -ENOMEM;
1667 } 1652 }
1668 #define MAX_ITEM_NAME_LEN 64 1653 #define MAX_ITEM_NAME_LEN 64
1669 for (i = 0; i < num_ins; i++) { 1654 for (i = 0; i < num_ins; i++) {
1670 struct usb_audio_term iterm; 1655 struct usb_audio_term iterm;
1671 len = 0; 1656 len = 0;
1672 namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL); 1657 namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL);
1673 if (! namelist[i]) { 1658 if (! namelist[i]) {
1674 snd_printk(KERN_ERR "cannot malloc\n"); 1659 snd_printk(KERN_ERR "cannot malloc\n");
1675 while (i--) 1660 while (i--)
1676 kfree(namelist[i]); 1661 kfree(namelist[i]);
1677 kfree(namelist); 1662 kfree(namelist);
1678 kfree(cval); 1663 kfree(cval);
1679 return -ENOMEM; 1664 return -ENOMEM;
1680 } 1665 }
1681 len = check_mapped_selector_name(state, unitid, i, namelist[i], 1666 len = check_mapped_selector_name(state, unitid, i, namelist[i],
1682 MAX_ITEM_NAME_LEN); 1667 MAX_ITEM_NAME_LEN);
1683 if (! len && check_input_term(state, desc[5 + i], &iterm) >= 0) 1668 if (! len && check_input_term(state, desc[5 + i], &iterm) >= 0)
1684 len = get_term_name(state, &iterm, namelist[i], MAX_ITEM_NAME_LEN, 0); 1669 len = get_term_name(state, &iterm, namelist[i], MAX_ITEM_NAME_LEN, 0);
1685 if (! len) 1670 if (! len)
1686 sprintf(namelist[i], "Input %d", i); 1671 sprintf(namelist[i], "Input %d", i);
1687 } 1672 }
1688 1673
1689 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval); 1674 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
1690 if (! kctl) { 1675 if (! kctl) {
1691 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1676 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1692 kfree(namelist); 1677 kfree(namelist);
1693 kfree(cval); 1678 kfree(cval);
1694 return -ENOMEM; 1679 return -ENOMEM;
1695 } 1680 }
1696 kctl->private_value = (unsigned long)namelist; 1681 kctl->private_value = (unsigned long)namelist;
1697 kctl->private_free = usb_mixer_selector_elem_free; 1682 kctl->private_free = usb_mixer_selector_elem_free;
1698 1683
1699 nameid = desc[desc[0] - 1]; 1684 nameid = desc[desc[0] - 1];
1700 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); 1685 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
1701 if (len) 1686 if (len)
1702 ; 1687 ;
1703 else if (nameid) 1688 else if (nameid)
1704 snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); 1689 snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
1705 else { 1690 else {
1706 len = get_term_name(state, &state->oterm, 1691 len = get_term_name(state, &state->oterm,
1707 kctl->id.name, sizeof(kctl->id.name), 0); 1692 kctl->id.name, sizeof(kctl->id.name), 0);
1708 if (! len) 1693 if (! len)
1709 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); 1694 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
1710 1695
1711 if ((state->oterm.type & 0xff00) == 0x0100) 1696 if ((state->oterm.type & 0xff00) == 0x0100)
1712 append_ctl_name(kctl, " Capture Source"); 1697 append_ctl_name(kctl, " Capture Source");
1713 else 1698 else
1714 append_ctl_name(kctl, " Playback Source"); 1699 append_ctl_name(kctl, " Playback Source");
1715 } 1700 }
1716 1701
1717 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", 1702 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
1718 cval->id, kctl->id.name, num_ins); 1703 cval->id, kctl->id.name, num_ins);
1719 if ((err = add_control_to_empty(state, kctl)) < 0) 1704 if ((err = add_control_to_empty(state, kctl)) < 0)
1720 return err; 1705 return err;
1721 1706
1722 return 0; 1707 return 0;
1723 } 1708 }
1724 1709
1725 1710
1726 /* 1711 /*
1727 * parse an audio unit recursively 1712 * parse an audio unit recursively
1728 */ 1713 */
1729 1714
1730 static int parse_audio_unit(struct mixer_build *state, int unitid) 1715 static int parse_audio_unit(struct mixer_build *state, int unitid)
1731 { 1716 {
1732 unsigned char *p1; 1717 unsigned char *p1;
1733 1718
1734 if (test_and_set_bit(unitid, state->unitbitmap)) 1719 if (test_and_set_bit(unitid, state->unitbitmap))
1735 return 0; /* the unit already visited */ 1720 return 0; /* the unit already visited */
1736 1721
1737 p1 = find_audio_control_unit(state, unitid); 1722 p1 = find_audio_control_unit(state, unitid);
1738 if (!p1) { 1723 if (!p1) {
1739 snd_printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid); 1724 snd_printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid);
1740 return -EINVAL; 1725 return -EINVAL;
1741 } 1726 }
1742 1727
1743 switch (p1[2]) { 1728 switch (p1[2]) {
1744 case UAC_INPUT_TERMINAL: 1729 case UAC_INPUT_TERMINAL:
1745 return 0; /* NOP */ 1730 return 0; /* NOP */
1746 case UAC_MIXER_UNIT: 1731 case UAC_MIXER_UNIT:
1747 return parse_audio_mixer_unit(state, unitid, p1); 1732 return parse_audio_mixer_unit(state, unitid, p1);
1748 case UAC_SELECTOR_UNIT: 1733 case UAC_SELECTOR_UNIT:
1749 return parse_audio_selector_unit(state, unitid, p1); 1734 return parse_audio_selector_unit(state, unitid, p1);
1750 case UAC_FEATURE_UNIT: 1735 case UAC_FEATURE_UNIT:
1751 return parse_audio_feature_unit(state, unitid, p1); 1736 return parse_audio_feature_unit(state, unitid, p1);
1752 case UAC_PROCESSING_UNIT_V1: 1737 case UAC_PROCESSING_UNIT_V1:
1753 return parse_audio_processing_unit(state, unitid, p1); 1738 return parse_audio_processing_unit(state, unitid, p1);
1754 case UAC_EXTENSION_UNIT_V1: 1739 case UAC_EXTENSION_UNIT_V1:
1755 return parse_audio_extension_unit(state, unitid, p1); 1740 return parse_audio_extension_unit(state, unitid, p1);
1756 default: 1741 default:
1757 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 1742 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
1758 return -EINVAL; 1743 return -EINVAL;
1759 } 1744 }
1760 } 1745 }
1761 1746
1762 static void snd_usb_mixer_free(struct usb_mixer_interface *mixer) 1747 static void snd_usb_mixer_free(struct usb_mixer_interface *mixer)
1763 { 1748 {
1764 kfree(mixer->id_elems); 1749 kfree(mixer->id_elems);
1765 if (mixer->urb) { 1750 if (mixer->urb) {
1766 kfree(mixer->urb->transfer_buffer); 1751 kfree(mixer->urb->transfer_buffer);
1767 usb_free_urb(mixer->urb); 1752 usb_free_urb(mixer->urb);
1768 } 1753 }
1769 usb_free_urb(mixer->rc_urb); 1754 usb_free_urb(mixer->rc_urb);
1770 kfree(mixer->rc_setup_packet); 1755 kfree(mixer->rc_setup_packet);
1771 kfree(mixer); 1756 kfree(mixer);
1772 } 1757 }
1773 1758
1774 static int snd_usb_mixer_dev_free(struct snd_device *device) 1759 static int snd_usb_mixer_dev_free(struct snd_device *device)
1775 { 1760 {
1776 struct usb_mixer_interface *mixer = device->device_data; 1761 struct usb_mixer_interface *mixer = device->device_data;
1777 snd_usb_mixer_free(mixer); 1762 snd_usb_mixer_free(mixer);
1778 return 0; 1763 return 0;
1779 } 1764 }
1780 1765
1781 /* 1766 /*
1782 * create mixer controls 1767 * create mixer controls
1783 * 1768 *
1784 * walk through all UAC_OUTPUT_TERMINAL descriptors to search for mixers 1769 * walk through all UAC_OUTPUT_TERMINAL descriptors to search for mixers
1785 */ 1770 */
1786 static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer) 1771 static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1787 { 1772 {
1788 struct uac_output_terminal_descriptor_v1 *desc; 1773 struct uac_output_terminal_descriptor_v1 *desc;
1789 struct mixer_build state; 1774 struct mixer_build state;
1790 int err; 1775 int err;
1791 const struct usbmix_ctl_map *map; 1776 const struct usbmix_ctl_map *map;
1792 struct usb_host_interface *hostif; 1777 struct usb_host_interface *hostif;
1793 1778
1794 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; 1779 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0];
1795 memset(&state, 0, sizeof(state)); 1780 memset(&state, 0, sizeof(state));
1796 state.chip = mixer->chip; 1781 state.chip = mixer->chip;
1797 state.mixer = mixer; 1782 state.mixer = mixer;
1798 state.buffer = hostif->extra; 1783 state.buffer = hostif->extra;
1799 state.buflen = hostif->extralen; 1784 state.buflen = hostif->extralen;
1800 1785
1801 /* check the mapping table */ 1786 /* check the mapping table */
1802 for (map = usbmix_ctl_maps; map->id; map++) { 1787 for (map = usbmix_ctl_maps; map->id; map++) {
1803 if (map->id == state.chip->usb_id) { 1788 if (map->id == state.chip->usb_id) {
1804 state.map = map->map; 1789 state.map = map->map;
1805 state.selector_map = map->selector_map; 1790 state.selector_map = map->selector_map;
1806 mixer->ignore_ctl_error = map->ignore_ctl_error; 1791 mixer->ignore_ctl_error = map->ignore_ctl_error;
1807 break; 1792 break;
1808 } 1793 }
1809 } 1794 }
1810 1795
1811 desc = NULL; 1796 desc = NULL;
1812 while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, UAC_OUTPUT_TERMINAL)) != NULL) { 1797 while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, UAC_OUTPUT_TERMINAL)) != NULL) {
1813 if (desc->bLength < 9) 1798 if (desc->bLength < 9)
1814 continue; /* invalid descriptor? */ 1799 continue; /* invalid descriptor? */
1815 set_bit(desc->bTerminalID, state.unitbitmap); /* mark terminal ID as visited */ 1800 set_bit(desc->bTerminalID, state.unitbitmap); /* mark terminal ID as visited */
1816 state.oterm.id = desc->bTerminalID; 1801 state.oterm.id = desc->bTerminalID;
1817 state.oterm.type = le16_to_cpu(desc->wTerminalType); 1802 state.oterm.type = le16_to_cpu(desc->wTerminalType);
1818 state.oterm.name = desc->iTerminal; 1803 state.oterm.name = desc->iTerminal;
1819 err = parse_audio_unit(&state, desc->bSourceID); 1804 err = parse_audio_unit(&state, desc->bSourceID);
1820 if (err < 0) 1805 if (err < 0)
1821 return err; 1806 return err;
1822 } 1807 }
1823 return 0; 1808 return 0;
1824 } 1809 }
1825 1810
1826 static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, 1811 static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer,
1827 int unitid) 1812 int unitid)
1828 { 1813 {
1829 struct usb_mixer_elem_info *info; 1814 struct usb_mixer_elem_info *info;
1830 1815
1831 for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem) 1816 for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem)
1832 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 1817 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1833 info->elem_id); 1818 info->elem_id);
1834 } 1819 }
1835 1820
1836 static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer, 1821 static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer,
1837 int unitid, 1822 int unitid,
1838 struct usb_mixer_elem_info *cval) 1823 struct usb_mixer_elem_info *cval)
1839 { 1824 {
1840 static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN", 1825 static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN",
1841 "S8", "U8", "S16", "U16"}; 1826 "S8", "U8", "S16", "U16"};
1842 snd_iprintf(buffer, " Unit: %i\n", unitid); 1827 snd_iprintf(buffer, " Unit: %i\n", unitid);
1843 if (cval->elem_id) 1828 if (cval->elem_id)
1844 snd_iprintf(buffer, " Control: name=\"%s\", index=%i\n", 1829 snd_iprintf(buffer, " Control: name=\"%s\", index=%i\n",
1845 cval->elem_id->name, cval->elem_id->index); 1830 cval->elem_id->name, cval->elem_id->index);
1846 snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, " 1831 snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, "
1847 "channels=%i, type=\"%s\"\n", cval->id, 1832 "channels=%i, type=\"%s\"\n", cval->id,
1848 cval->control, cval->cmask, cval->channels, 1833 cval->control, cval->cmask, cval->channels,
1849 val_types[cval->val_type]); 1834 val_types[cval->val_type]);
1850 snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n", 1835 snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n",
1851 cval->min, cval->max, cval->dBmin, cval->dBmax); 1836 cval->min, cval->max, cval->dBmin, cval->dBmax);
1852 } 1837 }
1853 1838
1854 static void snd_usb_mixer_proc_read(struct snd_info_entry *entry, 1839 static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
1855 struct snd_info_buffer *buffer) 1840 struct snd_info_buffer *buffer)
1856 { 1841 {
1857 struct snd_usb_audio *chip = entry->private_data; 1842 struct snd_usb_audio *chip = entry->private_data;
1858 struct usb_mixer_interface *mixer; 1843 struct usb_mixer_interface *mixer;
1859 struct usb_mixer_elem_info *cval; 1844 struct usb_mixer_elem_info *cval;
1860 int unitid; 1845 int unitid;
1861 1846
1862 list_for_each_entry(mixer, &chip->mixer_list, list) { 1847 list_for_each_entry(mixer, &chip->mixer_list, list) {
1863 snd_iprintf(buffer, 1848 snd_iprintf(buffer,
1864 "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n", 1849 "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n",
1865 chip->usb_id, mixer->ctrlif, 1850 chip->usb_id, mixer->ctrlif,
1866 mixer->ignore_ctl_error); 1851 mixer->ignore_ctl_error);
1867 snd_iprintf(buffer, "Card: %s\n", chip->card->longname); 1852 snd_iprintf(buffer, "Card: %s\n", chip->card->longname);
1868 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) { 1853 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) {
1869 for (cval = mixer->id_elems[unitid]; cval; 1854 for (cval = mixer->id_elems[unitid]; cval;
1870 cval = cval->next_id_elem) 1855 cval = cval->next_id_elem)
1871 snd_usb_mixer_dump_cval(buffer, unitid, cval); 1856 snd_usb_mixer_dump_cval(buffer, unitid, cval);
1872 } 1857 }
1873 } 1858 }
1874 } 1859 }
1875 1860
1876 static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer, 1861 static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
1877 int unitid) 1862 int unitid)
1878 { 1863 {
1879 if (!mixer->rc_cfg) 1864 if (!mixer->rc_cfg)
1880 return; 1865 return;
1881 /* unit ids specific to Extigy/Audigy 2 NX: */ 1866 /* unit ids specific to Extigy/Audigy 2 NX: */
1882 switch (unitid) { 1867 switch (unitid) {
1883 case 0: /* remote control */ 1868 case 0: /* remote control */
1884 mixer->rc_urb->dev = mixer->chip->dev; 1869 mixer->rc_urb->dev = mixer->chip->dev;
1885 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); 1870 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1886 break; 1871 break;
1887 case 4: /* digital in jack */ 1872 case 4: /* digital in jack */
1888 case 7: /* line in jacks */ 1873 case 7: /* line in jacks */
1889 case 19: /* speaker out jacks */ 1874 case 19: /* speaker out jacks */
1890 case 20: /* headphones out jack */ 1875 case 20: /* headphones out jack */
1891 break; 1876 break;
1892 /* live24ext: 4 = line-in jack */ 1877 /* live24ext: 4 = line-in jack */
1893 case 3: /* hp-out jack (may actuate Mute) */ 1878 case 3: /* hp-out jack (may actuate Mute) */
1894 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 1879 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1895 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) 1880 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1896 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); 1881 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1897 break; 1882 break;
1898 default: 1883 default:
1899 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid); 1884 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1900 break; 1885 break;
1901 } 1886 }
1902 } 1887 }
1903 1888
1904 static void snd_usb_mixer_status_complete(struct urb *urb) 1889 static void snd_usb_mixer_status_complete(struct urb *urb)
1905 { 1890 {
1906 struct usb_mixer_interface *mixer = urb->context; 1891 struct usb_mixer_interface *mixer = urb->context;
1907 1892
1908 if (urb->status == 0) { 1893 if (urb->status == 0) {
1909 u8 *buf = urb->transfer_buffer; 1894 u8 *buf = urb->transfer_buffer;
1910 int i; 1895 int i;
1911 1896
1912 for (i = urb->actual_length; i >= 2; buf += 2, i -= 2) { 1897 for (i = urb->actual_length; i >= 2; buf += 2, i -= 2) {
1913 snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n", 1898 snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n",
1914 buf[0], buf[1]); 1899 buf[0], buf[1]);
1915 /* ignore any notifications not from the control interface */ 1900 /* ignore any notifications not from the control interface */
1916 if ((buf[0] & 0x0f) != 0) 1901 if ((buf[0] & 0x0f) != 0)
1917 continue; 1902 continue;
1918 if (!(buf[0] & 0x40)) 1903 if (!(buf[0] & 0x40))
1919 snd_usb_mixer_notify_id(mixer, buf[1]); 1904 snd_usb_mixer_notify_id(mixer, buf[1]);
1920 else 1905 else
1921 snd_usb_mixer_memory_change(mixer, buf[1]); 1906 snd_usb_mixer_memory_change(mixer, buf[1]);
1922 } 1907 }
1923 } 1908 }
1924 if (urb->status != -ENOENT && urb->status != -ECONNRESET) { 1909 if (urb->status != -ENOENT && urb->status != -ECONNRESET) {
1925 urb->dev = mixer->chip->dev; 1910 urb->dev = mixer->chip->dev;
1926 usb_submit_urb(urb, GFP_ATOMIC); 1911 usb_submit_urb(urb, GFP_ATOMIC);
1927 } 1912 }
1928 } 1913 }
1929 1914
1930 /* create the handler for the optional status interrupt endpoint */ 1915 /* create the handler for the optional status interrupt endpoint */
1931 static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer) 1916 static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
1932 { 1917 {
1933 struct usb_host_interface *hostif; 1918 struct usb_host_interface *hostif;
1934 struct usb_endpoint_descriptor *ep; 1919 struct usb_endpoint_descriptor *ep;
1935 void *transfer_buffer; 1920 void *transfer_buffer;
1936 int buffer_length; 1921 int buffer_length;
1937 unsigned int epnum; 1922 unsigned int epnum;
1938 1923
1939 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; 1924 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0];
1940 /* we need one interrupt input endpoint */ 1925 /* we need one interrupt input endpoint */
1941 if (get_iface_desc(hostif)->bNumEndpoints < 1) 1926 if (get_iface_desc(hostif)->bNumEndpoints < 1)
1942 return 0; 1927 return 0;
1943 ep = get_endpoint(hostif, 0); 1928 ep = get_endpoint(hostif, 0);
1944 if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep)) 1929 if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep))
1945 return 0; 1930 return 0;
1946 1931
1947 epnum = usb_endpoint_num(ep); 1932 epnum = usb_endpoint_num(ep);
1948 buffer_length = le16_to_cpu(ep->wMaxPacketSize); 1933 buffer_length = le16_to_cpu(ep->wMaxPacketSize);
1949 transfer_buffer = kmalloc(buffer_length, GFP_KERNEL); 1934 transfer_buffer = kmalloc(buffer_length, GFP_KERNEL);
1950 if (!transfer_buffer) 1935 if (!transfer_buffer)
1951 return -ENOMEM; 1936 return -ENOMEM;
1952 mixer->urb = usb_alloc_urb(0, GFP_KERNEL); 1937 mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
1953 if (!mixer->urb) { 1938 if (!mixer->urb) {
1954 kfree(transfer_buffer); 1939 kfree(transfer_buffer);
1955 return -ENOMEM; 1940 return -ENOMEM;
1956 } 1941 }
1957 usb_fill_int_urb(mixer->urb, mixer->chip->dev, 1942 usb_fill_int_urb(mixer->urb, mixer->chip->dev,
1958 usb_rcvintpipe(mixer->chip->dev, epnum), 1943 usb_rcvintpipe(mixer->chip->dev, epnum),
1959 transfer_buffer, buffer_length, 1944 transfer_buffer, buffer_length,
1960 snd_usb_mixer_status_complete, mixer, ep->bInterval); 1945 snd_usb_mixer_status_complete, mixer, ep->bInterval);
1961 usb_submit_urb(mixer->urb, GFP_KERNEL); 1946 usb_submit_urb(mixer->urb, GFP_KERNEL);
1962 return 0; 1947 return 0;
1963 } 1948 }
1964 1949
1965 static void snd_usb_soundblaster_remote_complete(struct urb *urb) 1950 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
1966 { 1951 {
1967 struct usb_mixer_interface *mixer = urb->context; 1952 struct usb_mixer_interface *mixer = urb->context;
1968 const struct rc_config *rc = mixer->rc_cfg; 1953 const struct rc_config *rc = mixer->rc_cfg;
1969 u32 code; 1954 u32 code;
1970 1955
1971 if (urb->status < 0 || urb->actual_length < rc->min_packet_length) 1956 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
1972 return; 1957 return;
1973 1958
1974 code = mixer->rc_buffer[rc->offset]; 1959 code = mixer->rc_buffer[rc->offset];
1975 if (rc->length == 2) 1960 if (rc->length == 2)
1976 code |= mixer->rc_buffer[rc->offset + 1] << 8; 1961 code |= mixer->rc_buffer[rc->offset + 1] << 8;
1977 1962
1978 /* the Mute button actually changes the mixer control */ 1963 /* the Mute button actually changes the mixer control */
1979 if (code == rc->mute_code) 1964 if (code == rc->mute_code)
1980 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); 1965 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
1981 mixer->rc_code = code; 1966 mixer->rc_code = code;
1982 wmb(); 1967 wmb();
1983 wake_up(&mixer->rc_waitq); 1968 wake_up(&mixer->rc_waitq);
1984 } 1969 }
1985 1970
1986 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, 1971 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
1987 long count, loff_t *offset) 1972 long count, loff_t *offset)
1988 { 1973 {
1989 struct usb_mixer_interface *mixer = hw->private_data; 1974 struct usb_mixer_interface *mixer = hw->private_data;
1990 int err; 1975 int err;
1991 u32 rc_code; 1976 u32 rc_code;
1992 1977
1993 if (count != 1 && count != 4) 1978 if (count != 1 && count != 4)
1994 return -EINVAL; 1979 return -EINVAL;
1995 err = wait_event_interruptible(mixer->rc_waitq, 1980 err = wait_event_interruptible(mixer->rc_waitq,
1996 (rc_code = xchg(&mixer->rc_code, 0)) != 0); 1981 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
1997 if (err == 0) { 1982 if (err == 0) {
1998 if (count == 1) 1983 if (count == 1)
1999 err = put_user(rc_code, buf); 1984 err = put_user(rc_code, buf);
2000 else 1985 else
2001 err = put_user(rc_code, (u32 __user *)buf); 1986 err = put_user(rc_code, (u32 __user *)buf);
2002 } 1987 }
2003 return err < 0 ? err : count; 1988 return err < 0 ? err : count;
2004 } 1989 }
2005 1990
2006 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, 1991 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
2007 poll_table *wait) 1992 poll_table *wait)
2008 { 1993 {
2009 struct usb_mixer_interface *mixer = hw->private_data; 1994 struct usb_mixer_interface *mixer = hw->private_data;
2010 1995
2011 poll_wait(file, &mixer->rc_waitq, wait); 1996 poll_wait(file, &mixer->rc_waitq, wait);
2012 return mixer->rc_code ? POLLIN | POLLRDNORM : 0; 1997 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
2013 } 1998 }
2014 1999
2015 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) 2000 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
2016 { 2001 {
2017 struct snd_hwdep *hwdep; 2002 struct snd_hwdep *hwdep;
2018 int err, len, i; 2003 int err, len, i;
2019 2004
2020 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) 2005 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
2021 if (rc_configs[i].usb_id == mixer->chip->usb_id) 2006 if (rc_configs[i].usb_id == mixer->chip->usb_id)
2022 break; 2007 break;
2023 if (i >= ARRAY_SIZE(rc_configs)) 2008 if (i >= ARRAY_SIZE(rc_configs))
2024 return 0; 2009 return 0;
2025 mixer->rc_cfg = &rc_configs[i]; 2010 mixer->rc_cfg = &rc_configs[i];
2026 2011
2027 len = mixer->rc_cfg->packet_length; 2012 len = mixer->rc_cfg->packet_length;
2028 2013
2029 init_waitqueue_head(&mixer->rc_waitq); 2014 init_waitqueue_head(&mixer->rc_waitq);
2030 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); 2015 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
2031 if (err < 0) 2016 if (err < 0)
2032 return err; 2017 return err;
2033 snprintf(hwdep->name, sizeof(hwdep->name), 2018 snprintf(hwdep->name, sizeof(hwdep->name),
2034 "%s remote control", mixer->chip->card->shortname); 2019 "%s remote control", mixer->chip->card->shortname);
2035 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; 2020 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
2036 hwdep->private_data = mixer; 2021 hwdep->private_data = mixer;
2037 hwdep->ops.read = snd_usb_sbrc_hwdep_read; 2022 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
2038 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; 2023 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
2039 hwdep->exclusive = 1; 2024 hwdep->exclusive = 1;
2040 2025
2041 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); 2026 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
2042 if (!mixer->rc_urb) 2027 if (!mixer->rc_urb)
2043 return -ENOMEM; 2028 return -ENOMEM;
2044 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); 2029 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
2045 if (!mixer->rc_setup_packet) { 2030 if (!mixer->rc_setup_packet) {
2046 usb_free_urb(mixer->rc_urb); 2031 usb_free_urb(mixer->rc_urb);
2047 mixer->rc_urb = NULL; 2032 mixer->rc_urb = NULL;
2048 return -ENOMEM; 2033 return -ENOMEM;
2049 } 2034 }
2050 mixer->rc_setup_packet->bRequestType = 2035 mixer->rc_setup_packet->bRequestType =
2051 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; 2036 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
2052 mixer->rc_setup_packet->bRequest = UAC_GET_MEM; 2037 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
2053 mixer->rc_setup_packet->wValue = cpu_to_le16(0); 2038 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
2054 mixer->rc_setup_packet->wIndex = cpu_to_le16(0); 2039 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
2055 mixer->rc_setup_packet->wLength = cpu_to_le16(len); 2040 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
2056 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, 2041 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
2057 usb_rcvctrlpipe(mixer->chip->dev, 0), 2042 usb_rcvctrlpipe(mixer->chip->dev, 0),
2058 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, 2043 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
2059 snd_usb_soundblaster_remote_complete, mixer); 2044 snd_usb_soundblaster_remote_complete, mixer);
2060 return 0; 2045 return 0;
2061 } 2046 }
2062 2047
2063 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info 2048 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
2064 2049
2065 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2050 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2066 { 2051 {
2067 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 2052 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2068 int index = kcontrol->private_value; 2053 int index = kcontrol->private_value;
2069 2054
2070 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index]; 2055 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
2071 return 0; 2056 return 0;
2072 } 2057 }
2073 2058
2074 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2059 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2075 { 2060 {
2076 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 2061 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2077 int index = kcontrol->private_value; 2062 int index = kcontrol->private_value;
2078 int value = ucontrol->value.integer.value[0]; 2063 int value = ucontrol->value.integer.value[0];
2079 int err, changed; 2064 int err, changed;
2080 2065
2081 if (value > 1) 2066 if (value > 1)
2082 return -EINVAL; 2067 return -EINVAL;
2083 changed = value != mixer->audigy2nx_leds[index]; 2068 changed = value != mixer->audigy2nx_leds[index];
2084 err = snd_usb_ctl_msg(mixer->chip->dev, 2069 err = snd_usb_ctl_msg(mixer->chip->dev,
2085 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 2070 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
2086 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 2071 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2087 value, index + 2, NULL, 0, 100); 2072 value, index + 2, NULL, 0, 100);
2088 if (err < 0) 2073 if (err < 0)
2089 return err; 2074 return err;
2090 mixer->audigy2nx_leds[index] = value; 2075 mixer->audigy2nx_leds[index] = value;
2091 return changed; 2076 return changed;
2092 } 2077 }
2093 2078
2094 static struct snd_kcontrol_new snd_audigy2nx_controls[] = { 2079 static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
2095 { 2080 {
2096 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2081 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2097 .name = "CMSS LED Switch", 2082 .name = "CMSS LED Switch",
2098 .info = snd_audigy2nx_led_info, 2083 .info = snd_audigy2nx_led_info,
2099 .get = snd_audigy2nx_led_get, 2084 .get = snd_audigy2nx_led_get,
2100 .put = snd_audigy2nx_led_put, 2085 .put = snd_audigy2nx_led_put,
2101 .private_value = 0, 2086 .private_value = 0,
2102 }, 2087 },
2103 { 2088 {
2104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2089 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2105 .name = "Power LED Switch", 2090 .name = "Power LED Switch",
2106 .info = snd_audigy2nx_led_info, 2091 .info = snd_audigy2nx_led_info,
2107 .get = snd_audigy2nx_led_get, 2092 .get = snd_audigy2nx_led_get,
2108 .put = snd_audigy2nx_led_put, 2093 .put = snd_audigy2nx_led_put,
2109 .private_value = 1, 2094 .private_value = 1,
2110 }, 2095 },
2111 { 2096 {
2112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2113 .name = "Dolby Digital LED Switch", 2098 .name = "Dolby Digital LED Switch",
2114 .info = snd_audigy2nx_led_info, 2099 .info = snd_audigy2nx_led_info,
2115 .get = snd_audigy2nx_led_get, 2100 .get = snd_audigy2nx_led_get,
2116 .put = snd_audigy2nx_led_put, 2101 .put = snd_audigy2nx_led_put,
2117 .private_value = 2, 2102 .private_value = 2,
2118 }, 2103 },
2119 }; 2104 };
2120 2105
2121 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) 2106 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
2122 { 2107 {
2123 int i, err; 2108 int i, err;
2124 2109
2125 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { 2110 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
2126 if (i > 1 && /* Live24ext has 2 LEDs only */ 2111 if (i > 1 && /* Live24ext has 2 LEDs only */
2127 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 2112 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2128 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) 2113 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
2129 break; 2114 break;
2130 err = snd_ctl_add(mixer->chip->card, 2115 err = snd_ctl_add(mixer->chip->card,
2131 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); 2116 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
2132 if (err < 0) 2117 if (err < 0)
2133 return err; 2118 return err;
2134 } 2119 }
2135 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */ 2120 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
2136 return 0; 2121 return 0;
2137 } 2122 }
2138 2123
2139 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, 2124 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
2140 struct snd_info_buffer *buffer) 2125 struct snd_info_buffer *buffer)
2141 { 2126 {
2142 static const struct sb_jack { 2127 static const struct sb_jack {
2143 int unitid; 2128 int unitid;
2144 const char *name; 2129 const char *name;
2145 } jacks_audigy2nx[] = { 2130 } jacks_audigy2nx[] = {
2146 {4, "dig in "}, 2131 {4, "dig in "},
2147 {7, "line in"}, 2132 {7, "line in"},
2148 {19, "spk out"}, 2133 {19, "spk out"},
2149 {20, "hph out"}, 2134 {20, "hph out"},
2150 {-1, NULL} 2135 {-1, NULL}
2151 }, jacks_live24ext[] = { 2136 }, jacks_live24ext[] = {
2152 {4, "line in"}, /* &1=Line, &2=Mic*/ 2137 {4, "line in"}, /* &1=Line, &2=Mic*/
2153 {3, "hph out"}, /* headphones */ 2138 {3, "hph out"}, /* headphones */
2154 {0, "RC "}, /* last command, 6 bytes see rc_config above */ 2139 {0, "RC "}, /* last command, 6 bytes see rc_config above */
2155 {-1, NULL} 2140 {-1, NULL}
2156 }; 2141 };
2157 const struct sb_jack *jacks; 2142 const struct sb_jack *jacks;
2158 struct usb_mixer_interface *mixer = entry->private_data; 2143 struct usb_mixer_interface *mixer = entry->private_data;
2159 int i, err; 2144 int i, err;
2160 u8 buf[3]; 2145 u8 buf[3];
2161 2146
2162 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); 2147 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
2163 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) 2148 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
2164 jacks = jacks_audigy2nx; 2149 jacks = jacks_audigy2nx;
2165 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 2150 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2166 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) 2151 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2167 jacks = jacks_live24ext; 2152 jacks = jacks_live24ext;
2168 else 2153 else
2169 return; 2154 return;
2170 2155
2171 for (i = 0; jacks[i].name; ++i) { 2156 for (i = 0; jacks[i].name; ++i) {
2172 snd_iprintf(buffer, "%s: ", jacks[i].name); 2157 snd_iprintf(buffer, "%s: ", jacks[i].name);
2173 err = snd_usb_ctl_msg(mixer->chip->dev, 2158 err = snd_usb_ctl_msg(mixer->chip->dev,
2174 usb_rcvctrlpipe(mixer->chip->dev, 0), 2159 usb_rcvctrlpipe(mixer->chip->dev, 0),
2175 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | 2160 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
2176 USB_RECIP_INTERFACE, 0, 2161 USB_RECIP_INTERFACE, 0,
2177 jacks[i].unitid << 8, buf, 3, 100); 2162 jacks[i].unitid << 8, buf, 3, 100);
2178 if (err == 3 && (buf[0] == 3 || buf[0] == 6)) 2163 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
2179 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); 2164 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
2180 else 2165 else
2181 snd_iprintf(buffer, "?\n"); 2166 snd_iprintf(buffer, "?\n");
2182 } 2167 }
2183 } 2168 }
2184 2169
2185 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, 2170 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
2186 struct snd_ctl_elem_value *ucontrol) 2171 struct snd_ctl_elem_value *ucontrol)
2187 { 2172 {
2188 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 2173 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2189 2174
2190 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02); 2175 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
2191 return 0; 2176 return 0;
2192 } 2177 }
2193 2178
2194 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, 2179 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
2195 struct snd_ctl_elem_value *ucontrol) 2180 struct snd_ctl_elem_value *ucontrol)
2196 { 2181 {
2197 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); 2182 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2198 u8 old_status, new_status; 2183 u8 old_status, new_status;
2199 int err, changed; 2184 int err, changed;
2200 2185
2201 old_status = mixer->xonar_u1_status; 2186 old_status = mixer->xonar_u1_status;
2202 if (ucontrol->value.integer.value[0]) 2187 if (ucontrol->value.integer.value[0])
2203 new_status = old_status | 0x02; 2188 new_status = old_status | 0x02;
2204 else 2189 else
2205 new_status = old_status & ~0x02; 2190 new_status = old_status & ~0x02;
2206 changed = new_status != old_status; 2191 changed = new_status != old_status;
2207 err = snd_usb_ctl_msg(mixer->chip->dev, 2192 err = snd_usb_ctl_msg(mixer->chip->dev,
2208 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, 2193 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
2209 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 2194 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2210 50, 0, &new_status, 1, 100); 2195 50, 0, &new_status, 1, 100);
2211 if (err < 0) 2196 if (err < 0)
2212 return err; 2197 return err;
2213 mixer->xonar_u1_status = new_status; 2198 mixer->xonar_u1_status = new_status;
2214 return changed; 2199 return changed;
2215 } 2200 }
2216 2201
2217 static struct snd_kcontrol_new snd_xonar_u1_output_switch = { 2202 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
2218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2219 .name = "Digital Playback Switch", 2204 .name = "Digital Playback Switch",
2220 .info = snd_ctl_boolean_mono_info, 2205 .info = snd_ctl_boolean_mono_info,
2221 .get = snd_xonar_u1_switch_get, 2206 .get = snd_xonar_u1_switch_get,
2222 .put = snd_xonar_u1_switch_put, 2207 .put = snd_xonar_u1_switch_put,
2223 }; 2208 };
2224 2209
2225 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) 2210 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
2226 { 2211 {
2227 int err; 2212 int err;
2228 2213
2229 err = snd_ctl_add(mixer->chip->card, 2214 err = snd_ctl_add(mixer->chip->card,
2230 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); 2215 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
2231 if (err < 0) 2216 if (err < 0)
2232 return err; 2217 return err;
2233 mixer->xonar_u1_status = 0x05; 2218 mixer->xonar_u1_status = 0x05;
2234 return 0; 2219 return 0;
2235 } 2220 }
2236 2221
2237 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, 2222 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
2238 unsigned char samplerate_id) 2223 unsigned char samplerate_id)
2239 { 2224 {
2240 struct usb_mixer_interface *mixer; 2225 struct usb_mixer_interface *mixer;
2241 struct usb_mixer_elem_info *cval; 2226 struct usb_mixer_elem_info *cval;
2242 int unitid = 12; /* SamleRate ExtensionUnit ID */ 2227 int unitid = 12; /* SamleRate ExtensionUnit ID */
2243 2228
2244 list_for_each_entry(mixer, &chip->mixer_list, list) { 2229 list_for_each_entry(mixer, &chip->mixer_list, list) {
2245 cval = mixer->id_elems[unitid]; 2230 cval = mixer->id_elems[unitid];
2246 if (cval) { 2231 if (cval) {
2247 set_cur_ctl_value(cval, cval->control << 8, 2232 set_cur_ctl_value(cval, cval->control << 8,
2248 samplerate_id); 2233 samplerate_id);
2249 snd_usb_mixer_notify_id(mixer, unitid); 2234 snd_usb_mixer_notify_id(mixer, unitid);
2250 } 2235 }
2251 break; 2236 break;
2252 } 2237 }
2253 } 2238 }
2254 2239
2255 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, 2240 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2256 int ignore_error) 2241 int ignore_error)
2257 { 2242 {
2258 static struct snd_device_ops dev_ops = { 2243 static struct snd_device_ops dev_ops = {
2259 .dev_free = snd_usb_mixer_dev_free 2244 .dev_free = snd_usb_mixer_dev_free
2260 }; 2245 };
2261 struct usb_mixer_interface *mixer; 2246 struct usb_mixer_interface *mixer;
2262 struct snd_info_entry *entry; 2247 struct snd_info_entry *entry;
2263 struct usb_host_interface *host_iface; 2248 struct usb_host_interface *host_iface;
2264 int err, protocol; 2249 int err, protocol;
2265 2250
2266 strcpy(chip->card->mixername, "USB Mixer"); 2251 strcpy(chip->card->mixername, "USB Mixer");
2267 2252
2268 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL); 2253 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
2269 if (!mixer) 2254 if (!mixer)
2270 return -ENOMEM; 2255 return -ENOMEM;
2271 mixer->chip = chip; 2256 mixer->chip = chip;
2272 mixer->ctrlif = ctrlif; 2257 mixer->ctrlif = ctrlif;
2273 mixer->ignore_ctl_error = ignore_error; 2258 mixer->ignore_ctl_error = ignore_error;
2274 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems), 2259 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems),
2275 GFP_KERNEL); 2260 GFP_KERNEL);
2276 if (!mixer->id_elems) { 2261 if (!mixer->id_elems) {
2277 kfree(mixer); 2262 kfree(mixer);
2278 return -ENOMEM; 2263 return -ENOMEM;
2279 } 2264 }
2280 2265
2281 host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0]; 2266 host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
2282 protocol = host_iface->desc.bInterfaceProtocol; 2267 protocol = host_iface->desc.bInterfaceProtocol;
2283 2268
2284 /* FIXME! */ 2269 /* FIXME! */
2285 if (protocol != UAC_VERSION_1) { 2270 if (protocol != UAC_VERSION_1) {
2286 snd_printk(KERN_WARNING "mixer interface protocol 0x%02x not yet supported\n", 2271 snd_printk(KERN_WARNING "mixer interface protocol 0x%02x not yet supported\n",
2287 protocol); 2272 protocol);
2288 return 0; 2273 return 0;
2289 } 2274 }
2290 2275
2291 if ((err = snd_usb_mixer_controls(mixer)) < 0 || 2276 if ((err = snd_usb_mixer_controls(mixer)) < 0 ||
2292 (err = snd_usb_mixer_status_create(mixer)) < 0) 2277 (err = snd_usb_mixer_status_create(mixer)) < 0)
2293 goto _error; 2278 goto _error;
2294 2279
2295 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) 2280 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
2296 goto _error; 2281 goto _error;
2297 2282
2298 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || 2283 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
2299 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 2284 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2300 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) { 2285 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
2301 if ((err = snd_audigy2nx_controls_create(mixer)) < 0) 2286 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
2302 goto _error; 2287 goto _error;
2303 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry)) 2288 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry))
2304 snd_info_set_text_ops(entry, mixer, 2289 snd_info_set_text_ops(entry, mixer,
2305 snd_audigy2nx_proc_read); 2290 snd_audigy2nx_proc_read);
2306 } 2291 }
2307 2292
2308 if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) || 2293 if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) ||
2309 mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) { 2294 mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) {
2310 err = snd_xonar_u1_controls_create(mixer); 2295 err = snd_xonar_u1_controls_create(mixer);
2311 if (err < 0) 2296 if (err < 0)
2312 goto _error; 2297 goto _error;
2313 } 2298 }
2314 2299
2315 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); 2300 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
2316 if (err < 0) 2301 if (err < 0)
2317 goto _error; 2302 goto _error;
2318 2303
2319 if (list_empty(&chip->mixer_list) && 2304 if (list_empty(&chip->mixer_list) &&
2320 !snd_card_proc_new(chip->card, "usbmixer", &entry)) 2305 !snd_card_proc_new(chip->card, "usbmixer", &entry))
2321 snd_info_set_text_ops(entry, chip, snd_usb_mixer_proc_read); 2306 snd_info_set_text_ops(entry, chip, snd_usb_mixer_proc_read);
2322 2307
2323 list_add(&mixer->list, &chip->mixer_list); 2308 list_add(&mixer->list, &chip->mixer_list);
2324 return 0; 2309 return 0;
2325 2310
2326 _error: 2311 _error:
2327 snd_usb_mixer_free(mixer); 2312 snd_usb_mixer_free(mixer);
2328 return err; 2313 return err;
2329 } 2314 }
2330 2315
2331 void snd_usb_mixer_disconnect(struct list_head *p) 2316 void snd_usb_mixer_disconnect(struct list_head *p)
2332 { 2317 {
2333 struct usb_mixer_interface *mixer; 2318 struct usb_mixer_interface *mixer;
2334 2319
2335 mixer = list_entry(p, struct usb_mixer_interface, list); 2320 mixer = list_entry(p, struct usb_mixer_interface, list);
2336 usb_kill_urb(mixer->urb); 2321 usb_kill_urb(mixer->urb);
2337 usb_kill_urb(mixer->rc_urb); 2322 usb_kill_urb(mixer->rc_urb);
2338 } 2323 }
2339 2324
sound/usb/usbmixer_maps.c
1 /* 1 /*
2 * Additional mixer mapping 2 * Additional mixer mapping
3 * 3 *
4 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> 4 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 */ 20 */
21 21
22 struct usbmix_dB_map { 22 struct usbmix_dB_map {
23 u32 min; 23 u32 min;
24 u32 max; 24 u32 max;
25 }; 25 };
26 26
27 struct usbmix_name_map { 27 struct usbmix_name_map {
28 int id; 28 int id;
29 const char *name; 29 const char *name;
30 int control; 30 int control;
31 struct usbmix_dB_map *dB; 31 struct usbmix_dB_map *dB;
32 }; 32 };
33 33
34 struct usbmix_selector_map { 34 struct usbmix_selector_map {
35 int id; 35 int id;
36 int count; 36 int count;
37 const char **names; 37 const char **names;
38 }; 38 };
39 39
40 struct usbmix_ctl_map { 40 struct usbmix_ctl_map {
41 u32 id; 41 u32 id;
42 const struct usbmix_name_map *map; 42 const struct usbmix_name_map *map;
43 const struct usbmix_selector_map *selector_map; 43 const struct usbmix_selector_map *selector_map;
44 int ignore_ctl_error; 44 int ignore_ctl_error;
45 }; 45 };
46 46
47 /* 47 /*
48 * USB control mappers for SB Exitigy 48 * USB control mappers for SB Exitigy
49 */ 49 */
50 50
51 /* 51 /*
52 * Topology of SB Extigy (see on the wide screen :) 52 * Topology of SB Extigy (see on the wide screen :)
53 53
54 USB_IN[1] --->FU[2]------------------------------+->MU[16]-->PU[17]-+->FU[18]--+->EU[27]--+->EU[21]-->FU[22]--+->FU[23] > Dig_OUT[24] 54 USB_IN[1] --->FU[2]------------------------------+->MU[16]-->PU[17]-+->FU[18]--+->EU[27]--+->EU[21]-->FU[22]--+->FU[23] > Dig_OUT[24]
55 ^ | | | | 55 ^ | | | |
56 USB_IN[3] -+->SU[5]-->FU[6]--+->MU[14] ->PU[15]->+ | | | +->FU[25] > Dig_OUT[26] 56 USB_IN[3] -+->SU[5]-->FU[6]--+->MU[14] ->PU[15]->+ | | | +->FU[25] > Dig_OUT[26]
57 ^ ^ | | | | 57 ^ ^ | | | |
58 Dig_IN[4] -+ | | | | +->FU[28]---------------------> Spk_OUT[19] 58 Dig_IN[4] -+ | | | | +->FU[28]---------------------> Spk_OUT[19]
59 | | | | 59 | | | |
60 Lin-IN[7] -+-->FU[8]---------+ | | +----------------------------------------> Hph_OUT[20] 60 Lin-IN[7] -+-->FU[8]---------+ | | +----------------------------------------> Hph_OUT[20]
61 | | | 61 | | |
62 Mic-IN[9] --+->FU[10]----------------------------+ | 62 Mic-IN[9] --+->FU[10]----------------------------+ |
63 || | 63 || |
64 || +----------------------------------------------------+ 64 || +----------------------------------------------------+
65 VV V 65 VV V
66 ++--+->SU[11]-->FU[12] --------------------------------------------------------------------------------------> USB_OUT[13] 66 ++--+->SU[11]-->FU[12] --------------------------------------------------------------------------------------> USB_OUT[13]
67 */ 67 */
68 68
69 static struct usbmix_name_map extigy_map[] = { 69 static struct usbmix_name_map extigy_map[] = {
70 /* 1: IT pcm */ 70 /* 1: IT pcm */
71 { 2, "PCM Playback" }, /* FU */ 71 { 2, "PCM Playback" }, /* FU */
72 /* 3: IT pcm */ 72 /* 3: IT pcm */
73 /* 4: IT digital in */ 73 /* 4: IT digital in */
74 { 5, NULL }, /* DISABLED: this seems to be bogus on some firmware */ 74 { 5, NULL }, /* DISABLED: this seems to be bogus on some firmware */
75 { 6, "Digital In" }, /* FU */ 75 { 6, "Digital In" }, /* FU */
76 /* 7: IT line */ 76 /* 7: IT line */
77 { 8, "Line Playback" }, /* FU */ 77 { 8, "Line Playback" }, /* FU */
78 /* 9: IT mic */ 78 /* 9: IT mic */
79 { 10, "Mic Playback" }, /* FU */ 79 { 10, "Mic Playback" }, /* FU */
80 { 11, "Capture Source" }, /* SU */ 80 { 11, "Capture Source" }, /* SU */
81 { 12, "Capture" }, /* FU */ 81 { 12, "Capture" }, /* FU */
82 /* 13: OT pcm capture */ 82 /* 13: OT pcm capture */
83 /* 14: MU (w/o controls) */ 83 /* 14: MU (w/o controls) */
84 /* 15: PU (3D enh) */ 84 /* 15: PU (3D enh) */
85 /* 16: MU (w/o controls) */ 85 /* 16: MU (w/o controls) */
86 { 17, NULL, 1 }, /* DISABLED: PU-switch (any effect?) */ 86 { 17, NULL, 1 }, /* DISABLED: PU-switch (any effect?) */
87 { 17, "Channel Routing", 2 }, /* PU: mode select */ 87 { 17, "Channel Routing", 2 }, /* PU: mode select */
88 { 18, "Tone Control - Bass", USB_FEATURE_BASS }, /* FU */ 88 { 18, "Tone Control - Bass", UAC_BASS_CONTROL }, /* FU */
89 { 18, "Tone Control - Treble", USB_FEATURE_TREBLE }, /* FU */ 89 { 18, "Tone Control - Treble", UAC_TREBLE_CONTROL }, /* FU */
90 { 18, "Master Playback" }, /* FU; others */ 90 { 18, "Master Playback" }, /* FU; others */
91 /* 19: OT speaker */ 91 /* 19: OT speaker */
92 /* 20: OT headphone */ 92 /* 20: OT headphone */
93 { 21, NULL }, /* DISABLED: EU (for what?) */ 93 { 21, NULL }, /* DISABLED: EU (for what?) */
94 { 22, "Digital Out Playback" }, /* FU */ 94 { 22, "Digital Out Playback" }, /* FU */
95 { 23, "Digital Out1 Playback" }, /* FU */ /* FIXME: corresponds to 24 */ 95 { 23, "Digital Out1 Playback" }, /* FU */ /* FIXME: corresponds to 24 */
96 /* 24: OT digital out */ 96 /* 24: OT digital out */
97 { 25, "IEC958 Optical Playback" }, /* FU */ 97 { 25, "IEC958 Optical Playback" }, /* FU */
98 { 26, "IEC958 Optical Playback" }, /* OT */ 98 { 26, "IEC958 Optical Playback" }, /* OT */
99 { 27, NULL }, /* DISABLED: EU (for what?) */ 99 { 27, NULL }, /* DISABLED: EU (for what?) */
100 /* 28: FU speaker (mute) */ 100 /* 28: FU speaker (mute) */
101 { 29, NULL }, /* Digital Input Playback Source? */ 101 { 29, NULL }, /* Digital Input Playback Source? */
102 { 0 } /* terminator */ 102 { 0 } /* terminator */
103 }; 103 };
104 104
105 /* Sound Blaster MP3+ controls mapping 105 /* Sound Blaster MP3+ controls mapping
106 * The default mixer channels have totally misleading names, 106 * The default mixer channels have totally misleading names,
107 * e.g. no Master and fake PCM volume 107 * e.g. no Master and fake PCM volume
108 * Pavel Mihaylov <bin@bash.info> 108 * Pavel Mihaylov <bin@bash.info>
109 */ 109 */
110 static struct usbmix_dB_map mp3plus_dB_1 = {-4781, 0}; /* just guess */ 110 static struct usbmix_dB_map mp3plus_dB_1 = {-4781, 0}; /* just guess */
111 static struct usbmix_dB_map mp3plus_dB_2 = {-1781, 618}; /* just guess */ 111 static struct usbmix_dB_map mp3plus_dB_2 = {-1781, 618}; /* just guess */
112 112
113 static struct usbmix_name_map mp3plus_map[] = { 113 static struct usbmix_name_map mp3plus_map[] = {
114 /* 1: IT pcm */ 114 /* 1: IT pcm */
115 /* 2: IT mic */ 115 /* 2: IT mic */
116 /* 3: IT line */ 116 /* 3: IT line */
117 /* 4: IT digital in */ 117 /* 4: IT digital in */
118 /* 5: OT digital out */ 118 /* 5: OT digital out */
119 /* 6: OT speaker */ 119 /* 6: OT speaker */
120 /* 7: OT pcm capture */ 120 /* 7: OT pcm capture */
121 { 8, "Capture Source" }, /* FU, default PCM Capture Source */ 121 { 8, "Capture Source" }, /* FU, default PCM Capture Source */
122 /* (Mic, Input 1 = Line input, Input 2 = Optical input) */ 122 /* (Mic, Input 1 = Line input, Input 2 = Optical input) */
123 { 9, "Master Playback" }, /* FU, default Speaker 1 */ 123 { 9, "Master Playback" }, /* FU, default Speaker 1 */
124 /* { 10, "Mic Capture", 1 }, */ /* FU, Mic Capture */ 124 /* { 10, "Mic Capture", 1 }, */ /* FU, Mic Capture */
125 { 10, /* "Mic Capture", */ NULL, 2, .dB = &mp3plus_dB_2 }, 125 { 10, /* "Mic Capture", */ NULL, 2, .dB = &mp3plus_dB_2 },
126 /* FU, Mic Capture */ 126 /* FU, Mic Capture */
127 { 10, "Mic Boost", 7 }, /* FU, default Auto Gain Input */ 127 { 10, "Mic Boost", 7 }, /* FU, default Auto Gain Input */
128 { 11, "Line Capture", .dB = &mp3plus_dB_2 }, 128 { 11, "Line Capture", .dB = &mp3plus_dB_2 },
129 /* FU, default PCM Capture */ 129 /* FU, default PCM Capture */
130 { 12, "Digital In Playback" }, /* FU, default PCM 1 */ 130 { 12, "Digital In Playback" }, /* FU, default PCM 1 */
131 { 13, /* "Mic Playback", */ .dB = &mp3plus_dB_1 }, 131 { 13, /* "Mic Playback", */ .dB = &mp3plus_dB_1 },
132 /* FU, default Mic Playback */ 132 /* FU, default Mic Playback */
133 { 14, "Line Playback", .dB = &mp3plus_dB_1 }, /* FU, default Speaker */ 133 { 14, "Line Playback", .dB = &mp3plus_dB_1 }, /* FU, default Speaker */
134 /* 15: MU */ 134 /* 15: MU */
135 { 0 } /* terminator */ 135 { 0 } /* terminator */
136 }; 136 };
137 137
138 /* Topology of SB Audigy 2 NX 138 /* Topology of SB Audigy 2 NX
139 139
140 +----------------------------->EU[27]--+ 140 +----------------------------->EU[27]--+
141 | v 141 | v
142 | +----------------------------------->SU[29]---->FU[22]-->Dig_OUT[24] 142 | +----------------------------------->SU[29]---->FU[22]-->Dig_OUT[24]
143 | | ^ 143 | | ^
144 USB_IN[1]-+------------+ +->EU[17]->+->FU[11]-+ 144 USB_IN[1]-+------------+ +->EU[17]->+->FU[11]-+
145 | v | v | 145 | v | v |
146 Dig_IN[4]---+->FU[6]-->MU[16]->FU[18]-+->EU[21]->SU[31]----->FU[30]->Hph_OUT[20] 146 Dig_IN[4]---+->FU[6]-->MU[16]->FU[18]-+->EU[21]->SU[31]----->FU[30]->Hph_OUT[20]
147 | ^ | | 147 | ^ | |
148 Lin_IN[7]-+--->FU[8]---+ +->EU[23]->FU[28]------------->Spk_OUT[19] 148 Lin_IN[7]-+--->FU[8]---+ +->EU[23]->FU[28]------------->Spk_OUT[19]
149 | | v 149 | | v
150 +--->FU[12]------------------------------------->SU[14]--->USB_OUT[15] 150 +--->FU[12]------------------------------------->SU[14]--->USB_OUT[15]
151 | ^ 151 | ^
152 +->FU[13]--------------------------------------+ 152 +->FU[13]--------------------------------------+
153 */ 153 */
154 static struct usbmix_name_map audigy2nx_map[] = { 154 static struct usbmix_name_map audigy2nx_map[] = {
155 /* 1: IT pcm playback */ 155 /* 1: IT pcm playback */
156 /* 4: IT digital in */ 156 /* 4: IT digital in */
157 { 6, "Digital In Playback" }, /* FU */ 157 { 6, "Digital In Playback" }, /* FU */
158 /* 7: IT line in */ 158 /* 7: IT line in */
159 { 8, "Line Playback" }, /* FU */ 159 { 8, "Line Playback" }, /* FU */
160 { 11, "What-U-Hear Capture" }, /* FU */ 160 { 11, "What-U-Hear Capture" }, /* FU */
161 { 12, "Line Capture" }, /* FU */ 161 { 12, "Line Capture" }, /* FU */
162 { 13, "Digital In Capture" }, /* FU */ 162 { 13, "Digital In Capture" }, /* FU */
163 { 14, "Capture Source" }, /* SU */ 163 { 14, "Capture Source" }, /* SU */
164 /* 15: OT pcm capture */ 164 /* 15: OT pcm capture */
165 /* 16: MU w/o controls */ 165 /* 16: MU w/o controls */
166 { 17, NULL }, /* DISABLED: EU (for what?) */ 166 { 17, NULL }, /* DISABLED: EU (for what?) */
167 { 18, "Master Playback" }, /* FU */ 167 { 18, "Master Playback" }, /* FU */
168 /* 19: OT speaker */ 168 /* 19: OT speaker */
169 /* 20: OT headphone */ 169 /* 20: OT headphone */
170 { 21, NULL }, /* DISABLED: EU (for what?) */ 170 { 21, NULL }, /* DISABLED: EU (for what?) */
171 { 22, "Digital Out Playback" }, /* FU */ 171 { 22, "Digital Out Playback" }, /* FU */
172 { 23, NULL }, /* DISABLED: EU (for what?) */ 172 { 23, NULL }, /* DISABLED: EU (for what?) */
173 /* 24: OT digital out */ 173 /* 24: OT digital out */
174 { 27, NULL }, /* DISABLED: EU (for what?) */ 174 { 27, NULL }, /* DISABLED: EU (for what?) */
175 { 28, "Speaker Playback" }, /* FU */ 175 { 28, "Speaker Playback" }, /* FU */
176 { 29, "Digital Out Source" }, /* SU */ 176 { 29, "Digital Out Source" }, /* SU */
177 { 30, "Headphone Playback" }, /* FU */ 177 { 30, "Headphone Playback" }, /* FU */
178 { 31, "Headphone Source" }, /* SU */ 178 { 31, "Headphone Source" }, /* SU */
179 { 0 } /* terminator */ 179 { 0 } /* terminator */
180 }; 180 };
181 181
182 static struct usbmix_selector_map audigy2nx_selectors[] = { 182 static struct usbmix_selector_map audigy2nx_selectors[] = {
183 { 183 {
184 .id = 14, /* Capture Source */ 184 .id = 14, /* Capture Source */
185 .count = 3, 185 .count = 3,
186 .names = (const char*[]) {"Line", "Digital In", "What-U-Hear"} 186 .names = (const char*[]) {"Line", "Digital In", "What-U-Hear"}
187 }, 187 },
188 { 188 {
189 .id = 29, /* Digital Out Source */ 189 .id = 29, /* Digital Out Source */
190 .count = 3, 190 .count = 3,
191 .names = (const char*[]) {"Front", "PCM", "Digital In"} 191 .names = (const char*[]) {"Front", "PCM", "Digital In"}
192 }, 192 },
193 { 193 {
194 .id = 31, /* Headphone Source */ 194 .id = 31, /* Headphone Source */
195 .count = 2, 195 .count = 2,
196 .names = (const char*[]) {"Front", "Side"} 196 .names = (const char*[]) {"Front", "Side"}
197 }, 197 },
198 { 0 } /* terminator */ 198 { 0 } /* terminator */
199 }; 199 };
200 200
201 /* Creative SoundBlaster Live! 24-bit External */ 201 /* Creative SoundBlaster Live! 24-bit External */
202 static struct usbmix_name_map live24ext_map[] = { 202 static struct usbmix_name_map live24ext_map[] = {
203 /* 2: PCM Playback Volume */ 203 /* 2: PCM Playback Volume */
204 { 5, "Mic Capture" }, /* FU, default PCM Capture Volume */ 204 { 5, "Mic Capture" }, /* FU, default PCM Capture Volume */
205 { 0 } /* terminator */ 205 { 0 } /* terminator */
206 }; 206 };
207 207
208 /* LineX FM Transmitter entry - needed to bypass controls bug */ 208 /* LineX FM Transmitter entry - needed to bypass controls bug */
209 static struct usbmix_name_map linex_map[] = { 209 static struct usbmix_name_map linex_map[] = {
210 /* 1: IT pcm */ 210 /* 1: IT pcm */
211 /* 2: OT Speaker */ 211 /* 2: OT Speaker */
212 { 3, "Master" }, /* FU: master volume - left / right / mute */ 212 { 3, "Master" }, /* FU: master volume - left / right / mute */
213 { 0 } /* terminator */ 213 { 0 } /* terminator */
214 }; 214 };
215 215
216 static struct usbmix_name_map maya44_map[] = { 216 static struct usbmix_name_map maya44_map[] = {
217 /* 1: IT line */ 217 /* 1: IT line */
218 { 2, "Line Playback" }, /* FU */ 218 { 2, "Line Playback" }, /* FU */
219 /* 3: IT line */ 219 /* 3: IT line */
220 { 4, "Line Playback" }, /* FU */ 220 { 4, "Line Playback" }, /* FU */
221 /* 5: IT pcm playback */ 221 /* 5: IT pcm playback */
222 /* 6: MU */ 222 /* 6: MU */
223 { 7, "Master Playback" }, /* FU */ 223 { 7, "Master Playback" }, /* FU */
224 /* 8: OT speaker */ 224 /* 8: OT speaker */
225 /* 9: IT line */ 225 /* 9: IT line */
226 { 10, "Line Capture" }, /* FU */ 226 { 10, "Line Capture" }, /* FU */
227 /* 11: MU */ 227 /* 11: MU */
228 /* 12: OT pcm capture */ 228 /* 12: OT pcm capture */
229 { } 229 { }
230 }; 230 };
231 231
232 /* Section "justlink_map" below added by James Courtier-Dutton <James@superbug.demon.co.uk> 232 /* Section "justlink_map" below added by James Courtier-Dutton <James@superbug.demon.co.uk>
233 * sourced from Maplin Electronics (http://www.maplin.co.uk), part number A56AK 233 * sourced from Maplin Electronics (http://www.maplin.co.uk), part number A56AK
234 * Part has 2 connectors that act as a single output. (TOSLINK Optical for digital out, and 3.5mm Jack for Analogue out.) 234 * Part has 2 connectors that act as a single output. (TOSLINK Optical for digital out, and 3.5mm Jack for Analogue out.)
235 * The USB Mixer publishes a Microphone and extra Volume controls for it, but none exist on the device, 235 * The USB Mixer publishes a Microphone and extra Volume controls for it, but none exist on the device,
236 * so this map removes all unwanted sliders from alsamixer 236 * so this map removes all unwanted sliders from alsamixer
237 */ 237 */
238 238
239 static struct usbmix_name_map justlink_map[] = { 239 static struct usbmix_name_map justlink_map[] = {
240 /* 1: IT pcm playback */ 240 /* 1: IT pcm playback */
241 /* 2: Not present */ 241 /* 2: Not present */
242 { 3, NULL}, /* IT mic (No mic input on device) */ 242 { 3, NULL}, /* IT mic (No mic input on device) */
243 /* 4: Not present */ 243 /* 4: Not present */
244 /* 5: OT speacker */ 244 /* 5: OT speacker */
245 /* 6: OT pcm capture */ 245 /* 6: OT pcm capture */
246 { 7, "Master Playback" }, /* Mute/volume for speaker */ 246 { 7, "Master Playback" }, /* Mute/volume for speaker */
247 { 8, NULL }, /* Capture Switch (No capture inputs on device) */ 247 { 8, NULL }, /* Capture Switch (No capture inputs on device) */
248 { 9, NULL }, /* Capture Mute/volume (No capture inputs on device */ 248 { 9, NULL }, /* Capture Mute/volume (No capture inputs on device */
249 /* 0xa: Not present */ 249 /* 0xa: Not present */
250 /* 0xb: MU (w/o controls) */ 250 /* 0xb: MU (w/o controls) */
251 { 0xc, NULL }, /* Mic feedback Mute/volume (No capture inputs on device) */ 251 { 0xc, NULL }, /* Mic feedback Mute/volume (No capture inputs on device) */
252 { 0 } /* terminator */ 252 { 0 } /* terminator */
253 }; 253 };
254 254
255 /* TerraTec Aureon 5.1 MkII USB */ 255 /* TerraTec Aureon 5.1 MkII USB */
256 static struct usbmix_name_map aureon_51_2_map[] = { 256 static struct usbmix_name_map aureon_51_2_map[] = {
257 /* 1: IT USB */ 257 /* 1: IT USB */
258 /* 2: IT Mic */ 258 /* 2: IT Mic */
259 /* 3: IT Line */ 259 /* 3: IT Line */
260 /* 4: IT SPDIF */ 260 /* 4: IT SPDIF */
261 /* 5: OT SPDIF */ 261 /* 5: OT SPDIF */
262 /* 6: OT Speaker */ 262 /* 6: OT Speaker */
263 /* 7: OT USB */ 263 /* 7: OT USB */
264 { 8, "Capture Source" }, /* SU */ 264 { 8, "Capture Source" }, /* SU */
265 { 9, "Master Playback" }, /* FU */ 265 { 9, "Master Playback" }, /* FU */
266 { 10, "Mic Capture" }, /* FU */ 266 { 10, "Mic Capture" }, /* FU */
267 { 11, "Line Capture" }, /* FU */ 267 { 11, "Line Capture" }, /* FU */
268 { 12, "IEC958 In Capture" }, /* FU */ 268 { 12, "IEC958 In Capture" }, /* FU */
269 { 13, "Mic Playback" }, /* FU */ 269 { 13, "Mic Playback" }, /* FU */
270 { 14, "Line Playback" }, /* FU */ 270 { 14, "Line Playback" }, /* FU */
271 /* 15: MU */ 271 /* 15: MU */
272 {} /* terminator */ 272 {} /* terminator */
273 }; 273 };
274 274
275 static struct usbmix_name_map scratch_live_map[] = { 275 static struct usbmix_name_map scratch_live_map[] = {
276 /* 1: IT Line 1 (USB streaming) */ 276 /* 1: IT Line 1 (USB streaming) */
277 /* 2: OT Line 1 (Speaker) */ 277 /* 2: OT Line 1 (Speaker) */
278 /* 3: IT Line 1 (Line connector) */ 278 /* 3: IT Line 1 (Line connector) */
279 { 4, "Line 1 In" }, /* FU */ 279 { 4, "Line 1 In" }, /* FU */
280 /* 5: OT Line 1 (USB streaming) */ 280 /* 5: OT Line 1 (USB streaming) */
281 /* 6: IT Line 2 (USB streaming) */ 281 /* 6: IT Line 2 (USB streaming) */
282 /* 7: OT Line 2 (Speaker) */ 282 /* 7: OT Line 2 (Speaker) */
283 /* 8: IT Line 2 (Line connector) */ 283 /* 8: IT Line 2 (Line connector) */
284 { 9, "Line 2 In" }, /* FU */ 284 { 9, "Line 2 In" }, /* FU */
285 /* 10: OT Line 2 (USB streaming) */ 285 /* 10: OT Line 2 (USB streaming) */
286 /* 11: IT Mic (Line connector) */ 286 /* 11: IT Mic (Line connector) */
287 /* 12: OT Mic (USB streaming) */ 287 /* 12: OT Mic (USB streaming) */
288 { 0 } /* terminator */ 288 { 0 } /* terminator */
289 }; 289 };
290 290
291 /* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+" 291 /* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+"
292 * most importand difference is SU[8], it should be set to "Capture Source" 292 * most importand difference is SU[8], it should be set to "Capture Source"
293 * to make alsamixer and PA working properly. 293 * to make alsamixer and PA working properly.
294 * FIXME: or mp3plus_map should use "Capture Source" too, 294 * FIXME: or mp3plus_map should use "Capture Source" too,
295 * so this maps can be merget 295 * so this maps can be merget
296 */ 296 */
297 static struct usbmix_name_map hercules_usb51_map[] = { 297 static struct usbmix_name_map hercules_usb51_map[] = {
298 { 8, "Capture Source" }, /* SU, default "PCM Capture Source" */ 298 { 8, "Capture Source" }, /* SU, default "PCM Capture Source" */
299 { 9, "Master Playback" }, /* FU, default "Speaker Playback" */ 299 { 9, "Master Playback" }, /* FU, default "Speaker Playback" */
300 { 10, "Mic Boost", 7 }, /* FU, default "Auto Gain Input" */ 300 { 10, "Mic Boost", 7 }, /* FU, default "Auto Gain Input" */
301 { 11, "Line Capture" }, /* FU, default "PCM Capture" */ 301 { 11, "Line Capture" }, /* FU, default "PCM Capture" */
302 { 13, "Mic Bypass Playback" }, /* FU, default "Mic Playback" */ 302 { 13, "Mic Bypass Playback" }, /* FU, default "Mic Playback" */
303 { 14, "Line Bypass Playback" }, /* FU, default "Line Playback" */ 303 { 14, "Line Bypass Playback" }, /* FU, default "Line Playback" */
304 { 0 } /* terminator */ 304 { 0 } /* terminator */
305 }; 305 };
306 306
307 /* 307 /*
308 * Control map entries 308 * Control map entries
309 */ 309 */
310 310
311 static struct usbmix_ctl_map usbmix_ctl_maps[] = { 311 static struct usbmix_ctl_map usbmix_ctl_maps[] = {
312 { 312 {
313 .id = USB_ID(0x041e, 0x3000), 313 .id = USB_ID(0x041e, 0x3000),
314 .map = extigy_map, 314 .map = extigy_map,
315 .ignore_ctl_error = 1, 315 .ignore_ctl_error = 1,
316 }, 316 },
317 { 317 {
318 .id = USB_ID(0x041e, 0x3010), 318 .id = USB_ID(0x041e, 0x3010),
319 .map = mp3plus_map, 319 .map = mp3plus_map,
320 }, 320 },
321 { 321 {
322 .id = USB_ID(0x041e, 0x3020), 322 .id = USB_ID(0x041e, 0x3020),
323 .map = audigy2nx_map, 323 .map = audigy2nx_map,
324 .selector_map = audigy2nx_selectors, 324 .selector_map = audigy2nx_selectors,
325 }, 325 },
326 { 326 {
327 .id = USB_ID(0x041e, 0x3040), 327 .id = USB_ID(0x041e, 0x3040),
328 .map = live24ext_map, 328 .map = live24ext_map,
329 }, 329 },
330 { 330 {
331 .id = USB_ID(0x041e, 0x3048), 331 .id = USB_ID(0x041e, 0x3048),
332 .map = audigy2nx_map, 332 .map = audigy2nx_map,
333 .selector_map = audigy2nx_selectors, 333 .selector_map = audigy2nx_selectors,
334 }, 334 },
335 { 335 {
336 /* Hercules DJ Console (Windows Edition) */ 336 /* Hercules DJ Console (Windows Edition) */
337 .id = USB_ID(0x06f8, 0xb000), 337 .id = USB_ID(0x06f8, 0xb000),
338 .ignore_ctl_error = 1, 338 .ignore_ctl_error = 1,
339 }, 339 },
340 { 340 {
341 /* Hercules DJ Console (Macintosh Edition) */ 341 /* Hercules DJ Console (Macintosh Edition) */
342 .id = USB_ID(0x06f8, 0xd002), 342 .id = USB_ID(0x06f8, 0xd002),
343 .ignore_ctl_error = 1, 343 .ignore_ctl_error = 1,
344 }, 344 },
345 { 345 {
346 /* Hercules Gamesurround Muse Pocket LT 346 /* Hercules Gamesurround Muse Pocket LT
347 * (USB 5.1 Channel Audio Adapter) 347 * (USB 5.1 Channel Audio Adapter)
348 */ 348 */
349 .id = USB_ID(0x06f8, 0xc000), 349 .id = USB_ID(0x06f8, 0xc000),
350 .map = hercules_usb51_map, 350 .map = hercules_usb51_map,
351 }, 351 },
352 { 352 {
353 .id = USB_ID(0x08bb, 0x2702), 353 .id = USB_ID(0x08bb, 0x2702),
354 .map = linex_map, 354 .map = linex_map,
355 .ignore_ctl_error = 1, 355 .ignore_ctl_error = 1,
356 }, 356 },
357 { 357 {
358 .id = USB_ID(0x0a92, 0x0091), 358 .id = USB_ID(0x0a92, 0x0091),
359 .map = maya44_map, 359 .map = maya44_map,
360 }, 360 },
361 { 361 {
362 .id = USB_ID(0x0c45, 0x1158), 362 .id = USB_ID(0x0c45, 0x1158),
363 .map = justlink_map, 363 .map = justlink_map,
364 }, 364 },
365 { 365 {
366 .id = USB_ID(0x0ccd, 0x0028), 366 .id = USB_ID(0x0ccd, 0x0028),
367 .map = aureon_51_2_map, 367 .map = aureon_51_2_map,
368 }, 368 },
369 { 369 {
370 .id = USB_ID(0x13e5, 0x0001), 370 .id = USB_ID(0x13e5, 0x0001),
371 .map = scratch_live_map, 371 .map = scratch_live_map,
372 .ignore_ctl_error = 1, 372 .ignore_ctl_error = 1,
373 }, 373 },
374 { 0 } /* terminator */ 374 { 0 } /* terminator */
375 }; 375 };
376 376
377 377