Commit | Line | Data |
---|---|---|
d2bb390a DU |
1 | /* |
2 | * Tascam US-16x08 ALSA driver | |
3 | * | |
4 | * Copyright (c) 2016 by Detlef Urban (onkel@paraair.de) | |
5 | * | |
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 | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <linux/slab.h> | |
19 | #include <linux/usb.h> | |
20 | #include <linux/usb/audio-v2.h> | |
21 | ||
22 | #include <sound/core.h> | |
23 | #include <sound/control.h> | |
24 | ||
25 | #include "usbaudio.h" | |
26 | #include "mixer.h" | |
27 | #include "helper.h" | |
28 | ||
29 | #include "mixer_us16x08.h" | |
30 | ||
31 | /* USB control message templates */ | |
32 | static const char route_msg[] = { | |
33 | 0x61, | |
34 | 0x02, | |
35 | 0x03, /* input from master (0x02) or input from computer bus (0x03) */ | |
36 | 0x62, | |
37 | 0x02, | |
38 | 0x01, /* input index (0x01/0x02 eq. left/right) or bus (0x01-0x08) */ | |
39 | 0x41, | |
40 | 0x01, | |
41 | 0x61, | |
42 | 0x02, | |
43 | 0x01, | |
44 | 0x62, | |
45 | 0x02, | |
46 | 0x01, /* output index (0x01-0x08) */ | |
47 | 0x42, | |
48 | 0x01, | |
49 | 0x43, | |
50 | 0x01, | |
51 | 0x00, | |
52 | 0x00 | |
53 | }; | |
54 | ||
55 | static const char mix_init_msg1[] = { | |
56 | 0x71, 0x01, 0x00, 0x00 | |
57 | }; | |
58 | ||
59 | static const char mix_init_msg2[] = { | |
60 | 0x62, 0x02, 0x00, 0x61, 0x02, 0x04, 0xb1, 0x01, 0x00, 0x00 | |
61 | }; | |
62 | ||
63 | static const char mix_msg_in[] = { | |
64 | /* default message head, equal to all mixers */ | |
65 | 0x61, 0x02, 0x04, 0x62, 0x02, 0x01, | |
66 | 0x81, /* 0x06: Controller ID */ | |
67 | 0x02, /* 0x07: */ | |
68 | 0x00, /* 0x08: Value of common mixer */ | |
69 | 0x00, | |
70 | 0x00 | |
71 | }; | |
72 | ||
73 | static const char mix_msg_out[] = { | |
74 | /* default message head, equal to all mixers */ | |
75 | 0x61, 0x02, 0x02, 0x62, 0x02, 0x01, | |
76 | 0x81, /* 0x06: Controller ID */ | |
77 | 0x02, /* 0x07: */ | |
78 | 0x00, /* 0x08: Value of common mixer */ | |
79 | 0x00, | |
80 | 0x00 | |
81 | }; | |
82 | ||
83 | static const char bypass_msg_out[] = { | |
84 | 0x45, | |
85 | 0x02, | |
86 | 0x01, /* on/off flag */ | |
87 | 0x00, | |
88 | 0x00 | |
89 | }; | |
90 | ||
91 | static const char bus_msg_out[] = { | |
92 | 0x44, | |
93 | 0x02, | |
94 | 0x01, /* on/off flag */ | |
95 | 0x00, | |
96 | 0x00 | |
97 | }; | |
98 | ||
99 | static const char comp_msg[] = { | |
100 | /* default message head, equal to all mixers */ | |
101 | 0x61, 0x02, 0x04, 0x62, 0x02, 0x01, | |
102 | 0x91, | |
103 | 0x02, | |
104 | 0xf0, /* 0x08: Threshold db (8) (e0 ... 00) (+-0dB -- -32dB) x-32 */ | |
105 | 0x92, | |
106 | 0x02, | |
107 | 0x0a, /* 0x0b: Ratio (0a,0b,0d,0f,11,14,19,1e,23,28,32,3c,50,a0,ff) */ | |
108 | 0x93, | |
109 | 0x02, | |
110 | 0x02, /* 0x0e: Attack (0x02 ... 0xc0) (2ms ... 200ms) */ | |
111 | 0x94, | |
112 | 0x02, | |
113 | 0x01, /* 0x11: Release (0x01 ... 0x64) (10ms ... 1000ms) x*10 */ | |
114 | 0x95, | |
115 | 0x02, | |
116 | 0x03, /* 0x14: gain (0 ... 20) (0dB .. 20dB) */ | |
117 | 0x96, | |
118 | 0x02, | |
119 | 0x01, | |
120 | 0x97, | |
121 | 0x02, | |
122 | 0x01, /* 0x1a: main Comp switch (0 ... 1) (off ... on)) */ | |
123 | 0x00, | |
124 | 0x00 | |
125 | }; | |
126 | ||
127 | static const char eqs_msq[] = { | |
128 | /* default message head, equal to all mixers */ | |
129 | 0x61, 0x02, 0x04, 0x62, 0x02, 0x01, | |
130 | 0x51, /* 0x06: Controller ID */ | |
131 | 0x02, | |
132 | 0x04, /* 0x08: EQ set num (0x01..0x04) (LOW, LOWMID, HIGHMID, HIGH)) */ | |
133 | 0x52, | |
134 | 0x02, | |
135 | 0x0c, /* 0x0b: value dB (0 ... 12) (-12db .. +12db) x-6 */ | |
136 | 0x53, | |
137 | 0x02, | |
138 | 0x0f, /* 0x0e: value freq (32-47) (1.7kHz..18kHz) */ | |
139 | 0x54, | |
140 | 0x02, | |
141 | 0x02, /* 0x11: band width (0-6) (Q16-Q0.25) 2^x/4 (EQ xxMID only) */ | |
142 | 0x55, | |
143 | 0x02, | |
144 | 0x01, /* 0x14: main EQ switch (0 ... 1) (off ... on)) */ | |
145 | 0x00, | |
146 | 0x00 | |
147 | }; | |
148 | ||
149 | /* compressor ratio map */ | |
150 | static const char ratio_map[] = { | |
151 | 0x0a, 0x0b, 0x0d, 0x0f, 0x11, 0x14, 0x19, 0x1e, | |
152 | 0x23, 0x28, 0x32, 0x3c, 0x50, 0xa0, 0xff | |
153 | }; | |
154 | ||
155 | /* route enumeration names */ | |
02ed051f | 156 | static const char *const route_names[] = { |
d2bb390a DU |
157 | "Master Left", "Master Right", "Output 1", "Output 2", "Output 3", |
158 | "Output 4", "Output 5", "Output 6", "Output 7", "Output 8", | |
159 | }; | |
160 | ||
161 | static int snd_us16x08_recv_urb(struct snd_usb_audio *chip, | |
162 | unsigned char *buf, int size) | |
163 | { | |
164 | ||
165 | mutex_lock(&chip->mutex); | |
166 | snd_usb_ctl_msg(chip->dev, | |
167 | usb_rcvctrlpipe(chip->dev, 0), | |
168 | SND_US16X08_URB_METER_REQUEST, | |
169 | SND_US16X08_URB_METER_REQUESTTYPE, 0, 0, buf, size); | |
170 | mutex_unlock(&chip->mutex); | |
171 | return 0; | |
172 | } | |
173 | ||
174 | /* wrapper function to send prepared URB buffer to usb device. Return an error | |
175 | * code if something went wrong | |
176 | */ | |
177 | static int snd_us16x08_send_urb(struct snd_usb_audio *chip, char *buf, int size) | |
178 | { | |
179 | int err = 0; | |
180 | ||
181 | if (chip) { | |
182 | err = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), | |
183 | SND_US16X08_URB_REQUEST, SND_US16X08_URB_REQUESTTYPE, | |
184 | 0, 0, buf, size); | |
185 | } | |
186 | ||
187 | return err; | |
188 | } | |
189 | ||
190 | static int snd_us16x08_route_info(struct snd_kcontrol *kcontrol, | |
191 | struct snd_ctl_elem_info *uinfo) | |
192 | { | |
193 | return snd_ctl_enum_info(uinfo, 1, 10, route_names); | |
194 | } | |
195 | ||
196 | static int snd_us16x08_route_get(struct snd_kcontrol *kcontrol, | |
197 | struct snd_ctl_elem_value *ucontrol) | |
198 | { | |
199 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
200 | int index = ucontrol->id.index; | |
201 | ||
202 | /* route has no bias */ | |
203 | ucontrol->value.enumerated.item[0] = elem->cache_val[index]; | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | static int snd_us16x08_route_put(struct snd_kcontrol *kcontrol, | |
209 | struct snd_ctl_elem_value *ucontrol) | |
210 | { | |
211 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
212 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
213 | int index = ucontrol->id.index; | |
214 | char buf[sizeof(route_msg)]; | |
215 | int val, val_org, err = 0; | |
216 | ||
217 | /* prepare the message buffer from template */ | |
218 | memcpy(buf, route_msg, sizeof(route_msg)); | |
219 | ||
220 | /* get the new value (no bias for routes) */ | |
221 | val = ucontrol->value.enumerated.item[0]; | |
222 | ||
223 | /* sanity check */ | |
224 | if (val < 0 || val > 9) | |
225 | return -EINVAL; | |
226 | ||
227 | if (val < 2) { | |
228 | /* input comes from a master channel */ | |
229 | val_org = val; | |
230 | buf[2] = 0x02; | |
231 | } else { | |
232 | /* input comes from a computer channel */ | |
233 | buf[2] = 0x03; | |
234 | val_org = val - 2; | |
235 | } | |
236 | ||
237 | /* place new route selection in URB message */ | |
238 | buf[5] = (unsigned char) (val_org & 0x0f) + 1; | |
239 | /* place route selector in URB message */ | |
240 | buf[13] = index + 1; | |
241 | ||
242 | err = snd_us16x08_send_urb(chip, buf, sizeof(route_msg)); | |
243 | ||
244 | if (err > 0) { | |
245 | elem->cached |= 1 << index; | |
246 | elem->cache_val[index] = val; | |
247 | } else { | |
248 | usb_audio_dbg(chip, "Failed to set routing, err:%d\n", err); | |
249 | } | |
250 | ||
251 | return err > 0 ? 1 : 0; | |
252 | } | |
253 | ||
254 | static int snd_us16x08_master_info(struct snd_kcontrol *kcontrol, | |
255 | struct snd_ctl_elem_info *uinfo) | |
256 | { | |
257 | uinfo->count = 1; | |
258 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
259 | uinfo->value.integer.max = SND_US16X08_KCMAX(kcontrol); | |
260 | uinfo->value.integer.min = SND_US16X08_KCMIN(kcontrol); | |
261 | uinfo->value.integer.step = SND_US16X08_KCSTEP(kcontrol); | |
262 | return 0; | |
263 | } | |
264 | ||
265 | static int snd_us16x08_master_get(struct snd_kcontrol *kcontrol, | |
266 | struct snd_ctl_elem_value *ucontrol) | |
267 | { | |
268 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
269 | int index = ucontrol->id.index; | |
270 | ||
271 | ucontrol->value.integer.value[0] = elem->cache_val[index]; | |
272 | ||
273 | return 0; | |
274 | } | |
275 | ||
276 | static int snd_us16x08_master_put(struct snd_kcontrol *kcontrol, | |
277 | struct snd_ctl_elem_value *ucontrol) | |
278 | { | |
279 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
280 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
281 | char buf[sizeof(mix_msg_out)]; | |
282 | int val, err = 0; | |
283 | int index = ucontrol->id.index; | |
284 | ||
285 | /* prepare the message buffer from template */ | |
286 | memcpy(buf, mix_msg_out, sizeof(mix_msg_out)); | |
287 | ||
288 | /* new control value incl. bias*/ | |
289 | val = ucontrol->value.integer.value[0]; | |
290 | ||
291 | /* sanity check */ | |
292 | if (val < SND_US16X08_KCMIN(kcontrol) | |
293 | || val > SND_US16X08_KCMAX(kcontrol)) | |
294 | return -EINVAL; | |
295 | ||
296 | buf[8] = val - SND_US16X08_KCBIAS(kcontrol); | |
297 | buf[6] = elem->head.id; | |
298 | ||
299 | /* place channel selector in URB message */ | |
300 | buf[5] = index + 1; | |
301 | err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_out)); | |
302 | ||
303 | if (err > 0) { | |
304 | elem->cached |= 1 << index; | |
305 | elem->cache_val[index] = val; | |
306 | } else { | |
307 | usb_audio_dbg(chip, "Failed to set master, err:%d\n", err); | |
308 | } | |
309 | ||
310 | return err > 0 ? 1 : 0; | |
311 | } | |
312 | ||
313 | static int snd_us16x08_bus_put(struct snd_kcontrol *kcontrol, | |
314 | struct snd_ctl_elem_value *ucontrol) | |
315 | { | |
316 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
317 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
318 | char buf[sizeof(mix_msg_out)]; | |
319 | int val, err = 0; | |
320 | ||
321 | val = ucontrol->value.integer.value[0]; | |
322 | ||
323 | /* prepare the message buffer from template */ | |
324 | switch (elem->head.id) { | |
325 | case SND_US16X08_ID_BYPASS: | |
326 | memcpy(buf, bypass_msg_out, sizeof(bypass_msg_out)); | |
327 | buf[2] = val; | |
328 | err = snd_us16x08_send_urb(chip, buf, sizeof(bypass_msg_out)); | |
329 | break; | |
330 | case SND_US16X08_ID_BUSS_OUT: | |
331 | memcpy(buf, bus_msg_out, sizeof(bus_msg_out)); | |
332 | buf[2] = val; | |
333 | err = snd_us16x08_send_urb(chip, buf, sizeof(bus_msg_out)); | |
334 | break; | |
335 | case SND_US16X08_ID_MUTE: | |
336 | memcpy(buf, mix_msg_out, sizeof(mix_msg_out)); | |
337 | buf[8] = val; | |
338 | buf[6] = elem->head.id; | |
339 | buf[5] = 1; | |
340 | err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_out)); | |
341 | break; | |
342 | } | |
343 | ||
344 | if (err > 0) { | |
345 | elem->cached |= 1; | |
346 | elem->cache_val[0] = val; | |
347 | } else { | |
348 | usb_audio_dbg(chip, "Failed to set buss param, err:%d\n", err); | |
349 | } | |
350 | ||
351 | return err > 0 ? 1 : 0; | |
352 | } | |
353 | ||
354 | static int snd_us16x08_bus_get(struct snd_kcontrol *kcontrol, | |
355 | struct snd_ctl_elem_value *ucontrol) | |
356 | { | |
357 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
358 | ||
359 | switch (elem->head.id) { | |
360 | case SND_US16X08_ID_BUSS_OUT: | |
361 | ucontrol->value.integer.value[0] = elem->cache_val[0]; | |
362 | break; | |
363 | case SND_US16X08_ID_BYPASS: | |
364 | ucontrol->value.integer.value[0] = elem->cache_val[0]; | |
365 | break; | |
366 | case SND_US16X08_ID_MUTE: | |
367 | ucontrol->value.integer.value[0] = elem->cache_val[0]; | |
368 | break; | |
369 | } | |
370 | ||
371 | return 0; | |
372 | } | |
373 | ||
374 | /* gets a current mixer value from common store */ | |
375 | static int snd_us16x08_channel_get(struct snd_kcontrol *kcontrol, | |
376 | struct snd_ctl_elem_value *ucontrol) | |
377 | { | |
378 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
379 | int index = ucontrol->id.index; | |
380 | ||
381 | ucontrol->value.integer.value[0] = elem->cache_val[index]; | |
382 | ||
383 | return 0; | |
384 | } | |
385 | ||
386 | static int snd_us16x08_channel_put(struct snd_kcontrol *kcontrol, | |
387 | struct snd_ctl_elem_value *ucontrol) | |
388 | { | |
389 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
390 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
391 | char buf[sizeof(mix_msg_in)]; | |
392 | int val, err; | |
393 | int index = ucontrol->id.index; | |
394 | ||
395 | /* prepare URB message from template */ | |
396 | memcpy(buf, mix_msg_in, sizeof(mix_msg_in)); | |
397 | ||
398 | val = ucontrol->value.integer.value[0]; | |
399 | ||
400 | /* sanity check */ | |
401 | if (val < SND_US16X08_KCMIN(kcontrol) | |
402 | || val > SND_US16X08_KCMAX(kcontrol)) | |
403 | return -EINVAL; | |
404 | ||
405 | /* add the bias to the new value */ | |
406 | buf[8] = val - SND_US16X08_KCBIAS(kcontrol); | |
407 | buf[6] = elem->head.id; | |
408 | buf[5] = index + 1; | |
409 | ||
410 | err = snd_us16x08_send_urb(chip, buf, sizeof(mix_msg_in)); | |
411 | ||
412 | if (err > 0) { | |
413 | elem->cached |= 1 << index; | |
414 | elem->cache_val[index] = val; | |
415 | } else { | |
416 | usb_audio_dbg(chip, "Failed to set channel, err:%d\n", err); | |
417 | } | |
418 | ||
419 | return err > 0 ? 1 : 0; | |
420 | } | |
421 | ||
422 | static int snd_us16x08_mix_info(struct snd_kcontrol *kcontrol, | |
423 | struct snd_ctl_elem_info *uinfo) | |
424 | { | |
425 | uinfo->count = 1; | |
426 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
427 | uinfo->value.integer.max = SND_US16X08_KCMAX(kcontrol); | |
428 | uinfo->value.integer.min = SND_US16X08_KCMIN(kcontrol); | |
429 | uinfo->value.integer.step = SND_US16X08_KCSTEP(kcontrol); | |
430 | return 0; | |
431 | } | |
432 | ||
433 | static int snd_us16x08_comp_get(struct snd_kcontrol *kcontrol, | |
434 | struct snd_ctl_elem_value *ucontrol) | |
435 | { | |
436 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
437 | struct snd_us16x08_comp_store *store = | |
438 | ((struct snd_us16x08_comp_store *) elem->private_data); | |
439 | int index = ucontrol->id.index; | |
440 | int val_idx = COMP_STORE_IDX(elem->head.id); | |
441 | ||
442 | ucontrol->value.integer.value[0] = store->val[val_idx][index]; | |
443 | ||
444 | return 0; | |
445 | } | |
446 | ||
447 | static int snd_us16x08_comp_put(struct snd_kcontrol *kcontrol, | |
448 | struct snd_ctl_elem_value *ucontrol) | |
449 | { | |
450 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
451 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
452 | struct snd_us16x08_comp_store *store = | |
453 | ((struct snd_us16x08_comp_store *) elem->private_data); | |
454 | int index = ucontrol->id.index; | |
455 | char buf[sizeof(comp_msg)]; | |
456 | int val_idx, val; | |
457 | int err = 0; | |
458 | ||
459 | /* prepare compressor URB message from template */ | |
460 | memcpy(buf, comp_msg, sizeof(comp_msg)); | |
461 | ||
462 | /* new control value incl. bias*/ | |
463 | val_idx = elem->head.id - SND_US16X08_ID_COMP_BASE; | |
464 | ||
465 | val = ucontrol->value.integer.value[0]; | |
466 | ||
467 | /* sanity check */ | |
468 | if (val < SND_US16X08_KCMIN(kcontrol) | |
469 | || val > SND_US16X08_KCMAX(kcontrol)) | |
470 | return -EINVAL; | |
471 | ||
472 | store->val[val_idx][index] = ucontrol->value.integer.value[0]; | |
473 | ||
474 | /* place comp values in message buffer watch bias! */ | |
475 | buf[8] = store->val[ | |
476 | COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)][index] | |
477 | - SND_US16X08_COMP_THRESHOLD_BIAS; | |
478 | buf[11] = ratio_map[store->val[ | |
479 | COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][index]]; | |
480 | buf[14] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][index] | |
481 | + SND_US16X08_COMP_ATTACK_BIAS; | |
482 | buf[17] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)][index] | |
483 | + SND_US16X08_COMP_RELEASE_BIAS; | |
484 | buf[20] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][index]; | |
485 | buf[26] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)][index]; | |
486 | ||
487 | /* place channel selector in message buffer */ | |
488 | buf[5] = index + 1; | |
489 | ||
490 | err = snd_us16x08_send_urb(chip, buf, sizeof(comp_msg)); | |
491 | ||
492 | if (err > 0) { | |
493 | elem->cached |= 1 << index; | |
494 | elem->cache_val[index] = val; | |
495 | } else { | |
496 | usb_audio_dbg(chip, "Failed to set compressor, err:%d\n", err); | |
497 | } | |
498 | ||
499 | return 1; | |
500 | } | |
501 | ||
502 | static int snd_us16x08_eqswitch_get(struct snd_kcontrol *kcontrol, | |
503 | struct snd_ctl_elem_value *ucontrol) | |
504 | { | |
505 | int val = 0; | |
506 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
507 | struct snd_us16x08_eq_store *store = | |
508 | ((struct snd_us16x08_eq_store *) elem->private_data); | |
509 | int index = ucontrol->id.index; | |
510 | ||
511 | /* get low switch from cache is enough, cause all bands are together */ | |
512 | val = store->val[EQ_STORE_BAND_IDX(elem->head.id)] | |
513 | [EQ_STORE_PARAM_IDX(elem->head.id)][index]; | |
514 | ucontrol->value.integer.value[0] = val; | |
515 | ||
516 | return 0; | |
517 | } | |
518 | ||
519 | static int snd_us16x08_eqswitch_put(struct snd_kcontrol *kcontrol, | |
520 | struct snd_ctl_elem_value *ucontrol) | |
521 | { | |
522 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
523 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
524 | struct snd_us16x08_eq_store *store = | |
525 | ((struct snd_us16x08_eq_store *) elem->private_data); | |
526 | int index = ucontrol->id.index; | |
527 | ||
528 | char buf[sizeof(eqs_msq)]; | |
529 | int val, err = 0; | |
530 | int b_idx; | |
531 | ||
532 | /* new control value incl. bias*/ | |
533 | val = ucontrol->value.integer.value[0] + SND_US16X08_KCBIAS(kcontrol); | |
534 | ||
535 | /* prepare URB message from EQ template */ | |
536 | memcpy(buf, eqs_msq, sizeof(eqs_msq)); | |
537 | ||
538 | /* place channel index in URB message */ | |
539 | buf[5] = index + 1; | |
540 | for (b_idx = 0; b_idx < SND_US16X08_ID_EQ_BAND_COUNT; b_idx++) { | |
541 | /* all four EQ bands have to be enabled/disabled in once */ | |
542 | buf[20] = val; | |
543 | buf[17] = store->val[b_idx][2][index]; | |
544 | buf[14] = store->val[b_idx][1][index]; | |
545 | buf[11] = store->val[b_idx][0][index]; | |
546 | buf[8] = b_idx + 1; | |
547 | err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq)); | |
548 | if (err < 0) | |
549 | break; | |
550 | store->val[b_idx][3][index] = val; | |
551 | msleep(15); | |
552 | } | |
553 | ||
554 | if (err > 0) { | |
555 | elem->cached |= 1 << index; | |
556 | elem->cache_val[index] = val; | |
557 | } else { | |
558 | usb_audio_dbg(chip, "Failed to set eq switch, err:%d\n", err); | |
559 | } | |
560 | ||
561 | return 1; | |
562 | } | |
563 | ||
564 | static int snd_us16x08_eq_get(struct snd_kcontrol *kcontrol, | |
565 | struct snd_ctl_elem_value *ucontrol) | |
566 | { | |
567 | int val = 0; | |
568 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
569 | struct snd_us16x08_eq_store *store = | |
570 | ((struct snd_us16x08_eq_store *) elem->private_data); | |
571 | int index = ucontrol->id.index; | |
572 | int b_idx = EQ_STORE_BAND_IDX(elem->head.id) - 1; | |
573 | int p_idx = EQ_STORE_PARAM_IDX(elem->head.id); | |
574 | ||
575 | val = store->val[b_idx][p_idx][index]; | |
576 | ||
577 | ucontrol->value.integer.value[0] = val; | |
578 | ||
579 | return 0; | |
580 | } | |
581 | ||
582 | static int snd_us16x08_eq_put(struct snd_kcontrol *kcontrol, | |
583 | struct snd_ctl_elem_value *ucontrol) | |
584 | { | |
585 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
586 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
587 | struct snd_us16x08_eq_store *store = | |
588 | ((struct snd_us16x08_eq_store *) elem->private_data); | |
589 | int index = ucontrol->id.index; | |
590 | char buf[sizeof(eqs_msq)]; | |
591 | int val, err = 0; | |
592 | int b_idx = EQ_STORE_BAND_IDX(elem->head.id) - 1; | |
593 | int p_idx = EQ_STORE_PARAM_IDX(elem->head.id); | |
594 | ||
595 | /* copy URB buffer from EQ template */ | |
596 | memcpy(buf, eqs_msq, sizeof(eqs_msq)); | |
597 | ||
598 | val = ucontrol->value.integer.value[0]; | |
599 | ||
600 | /* sanity check */ | |
601 | if (val < SND_US16X08_KCMIN(kcontrol) | |
602 | || val > SND_US16X08_KCMAX(kcontrol)) | |
603 | return -EINVAL; | |
604 | ||
605 | store->val[b_idx][p_idx][index] = val; | |
606 | buf[20] = store->val[b_idx][3][index]; | |
607 | buf[17] = store->val[b_idx][2][index]; | |
608 | buf[14] = store->val[b_idx][1][index]; | |
609 | buf[11] = store->val[b_idx][0][index]; | |
610 | ||
611 | /* place channel index in URB buffer */ | |
612 | buf[5] = index + 1; | |
613 | ||
614 | /* place EQ band in URB buffer */ | |
615 | buf[8] = b_idx + 1; | |
616 | ||
617 | err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq)); | |
618 | ||
619 | if (err > 0) { | |
620 | /* store new value in EQ band cache */ | |
621 | elem->cached |= 1 << index; | |
622 | elem->cache_val[index] = val; | |
623 | } else { | |
624 | usb_audio_dbg(chip, "Failed to set eq param, err:%d\n", err); | |
625 | } | |
626 | ||
627 | return 1; | |
628 | } | |
629 | ||
630 | static int snd_us16x08_meter_info(struct snd_kcontrol *kcontrol, | |
631 | struct snd_ctl_elem_info *uinfo) | |
632 | { | |
633 | uinfo->count = 1; | |
634 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
635 | uinfo->value.integer.max = 0x7FFF; | |
636 | uinfo->value.integer.min = 0; | |
637 | ||
638 | return 0; | |
639 | } | |
640 | ||
641 | /* calculate compressor index for reduction level request */ | |
642 | static int snd_get_meter_comp_index(struct snd_us16x08_meter_store *store) | |
643 | { | |
644 | int ret; | |
645 | ||
646 | /* any channel active */ | |
647 | if (store->comp_active_index) { | |
648 | /* check for stereo link */ | |
649 | if (store->comp_active_index & 0x20) { | |
650 | /* reset comp_index to left channel*/ | |
651 | if (store->comp_index - | |
652 | store->comp_active_index > 1) | |
653 | store->comp_index = | |
654 | store->comp_active_index; | |
655 | ||
656 | ret = store->comp_index++ & 0x1F; | |
657 | } else { | |
658 | /* no stereo link */ | |
659 | ret = store->comp_active_index; | |
660 | } | |
661 | } else { | |
662 | /* skip channels with no compressor active */ | |
663 | while (!store->comp_store->val[ | |
664 | COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)] | |
665 | [store->comp_index - 1] | |
666 | && store->comp_index <= SND_US16X08_MAX_CHANNELS) { | |
667 | store->comp_index++; | |
668 | } | |
669 | ret = store->comp_index++; | |
670 | if (store->comp_index > SND_US16X08_MAX_CHANNELS) | |
671 | store->comp_index = 1; | |
672 | } | |
673 | return ret; | |
674 | } | |
675 | ||
676 | /* retrieve the meter level values from URB message */ | |
677 | static void get_meter_levels_from_urb(int s, | |
678 | struct snd_us16x08_meter_store *store, | |
679 | u8 *meter_urb) | |
680 | { | |
681 | int val = MUC2(meter_urb, s) + (MUC3(meter_urb, s) << 8); | |
682 | ||
683 | if (MUA0(meter_urb, s) == 0x61 && MUA1(meter_urb, s) == 0x02 && | |
684 | MUA2(meter_urb, s) == 0x04 && MUB0(meter_urb, s) == 0x62) { | |
685 | if (MUC0(meter_urb, s) == 0x72) | |
686 | store->meter_level[MUB2(meter_urb, s) - 1] = val; | |
687 | if (MUC0(meter_urb, s) == 0xb2) | |
688 | store->comp_level[MUB2(meter_urb, s) - 1] = val; | |
689 | } | |
690 | if (MUA0(meter_urb, s) == 0x61 && MUA1(meter_urb, s) == 0x02 && | |
691 | MUA2(meter_urb, s) == 0x02 && MUB0(meter_urb, s) == 0x62) | |
692 | store->master_level[MUB2(meter_urb, s) - 1] = val; | |
693 | } | |
694 | ||
695 | /* Function to retrieve current meter values from the device. | |
696 | * | |
697 | * The device needs to be polled for meter values with an initial | |
698 | * requests. It will return with a sequence of different meter value | |
699 | * packages. The first request (case 0:) initiate this meter response sequence. | |
700 | * After the third response, an additional request can be placed, | |
701 | * to retrieve compressor reduction level value for given channel. This round | |
702 | * trip channel selector will skip all inactive compressors. | |
703 | * A mixer can interrupt this round-trip by selecting one ore two (stereo-link) | |
704 | * specific channels. | |
705 | */ | |
706 | static int snd_us16x08_meter_get(struct snd_kcontrol *kcontrol, | |
707 | struct snd_ctl_elem_value *ucontrol) | |
708 | { | |
709 | int i, set; | |
710 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
711 | struct snd_usb_audio *chip = elem->head.mixer->chip; | |
712 | struct snd_us16x08_meter_store *store = elem->private_data; | |
713 | u8 meter_urb[64]; | |
714 | char tmp[max(sizeof(mix_init_msg1), sizeof(mix_init_msg2))]; | |
715 | ||
716 | if (elem) { | |
717 | store = (struct snd_us16x08_meter_store *) elem->private_data; | |
718 | chip = elem->head.mixer->chip; | |
719 | } else | |
720 | return 0; | |
721 | ||
722 | switch (kcontrol->private_value) { | |
723 | case 0: | |
724 | memcpy(tmp, mix_init_msg1, sizeof(mix_init_msg1)); | |
725 | snd_us16x08_send_urb(chip, tmp, 4); | |
726 | snd_us16x08_recv_urb(chip, meter_urb, | |
727 | sizeof(meter_urb)); | |
728 | kcontrol->private_value++; | |
729 | break; | |
730 | case 1: | |
731 | snd_us16x08_recv_urb(chip, meter_urb, | |
732 | sizeof(meter_urb)); | |
733 | kcontrol->private_value++; | |
734 | break; | |
735 | case 2: | |
736 | snd_us16x08_recv_urb(chip, meter_urb, | |
737 | sizeof(meter_urb)); | |
738 | kcontrol->private_value++; | |
739 | break; | |
740 | case 3: | |
741 | memcpy(tmp, mix_init_msg2, sizeof(mix_init_msg2)); | |
742 | tmp[2] = snd_get_meter_comp_index(store); | |
743 | snd_us16x08_send_urb(chip, tmp, 10); | |
744 | snd_us16x08_recv_urb(chip, meter_urb, | |
745 | sizeof(meter_urb)); | |
746 | kcontrol->private_value = 0; | |
747 | break; | |
748 | } | |
749 | ||
750 | for (set = 0; set < 6; set++) | |
751 | get_meter_levels_from_urb(set, store, meter_urb); | |
752 | ||
753 | for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) { | |
754 | ucontrol->value.integer.value[i] = | |
755 | store ? store->meter_level[i] : 0; | |
756 | } | |
757 | ||
758 | ucontrol->value.integer.value[i++] = store ? store->master_level[0] : 0; | |
759 | ucontrol->value.integer.value[i++] = store ? store->master_level[1] : 0; | |
760 | ||
761 | for (i = 2; i < SND_US16X08_MAX_CHANNELS + 2; i++) | |
762 | ucontrol->value.integer.value[i + SND_US16X08_MAX_CHANNELS] = | |
763 | store ? store->comp_level[i - 2] : 0; | |
764 | ||
765 | return 1; | |
766 | } | |
767 | ||
768 | static int snd_us16x08_meter_put(struct snd_kcontrol *kcontrol, | |
769 | struct snd_ctl_elem_value *ucontrol) | |
770 | { | |
771 | struct usb_mixer_elem_info *elem = kcontrol->private_data; | |
772 | struct snd_us16x08_meter_store *store = elem->private_data; | |
773 | int val; | |
774 | ||
775 | val = ucontrol->value.integer.value[0]; | |
776 | ||
777 | /* sanity check */ | |
778 | if (val < 0 || val >= SND_US16X08_MAX_CHANNELS) | |
779 | return -EINVAL; | |
780 | ||
781 | store->comp_active_index = val; | |
782 | store->comp_index = val; | |
783 | ||
784 | return 1; | |
785 | } | |
786 | ||
787 | static struct snd_kcontrol_new snd_us16x08_ch_boolean_ctl = { | |
788 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
789 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
790 | .count = 16, | |
791 | .info = snd_us16x08_switch_info, | |
792 | .get = snd_us16x08_channel_get, | |
793 | .put = snd_us16x08_channel_put, | |
794 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1) | |
795 | }; | |
796 | ||
797 | static struct snd_kcontrol_new snd_us16x08_ch_int_ctl = { | |
798 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
799 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
800 | .count = 16, | |
801 | .info = snd_us16x08_mix_info, | |
802 | .get = snd_us16x08_channel_get, | |
803 | .put = snd_us16x08_channel_put, | |
804 | .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 133) | |
805 | }; | |
806 | ||
807 | static struct snd_kcontrol_new snd_us16x08_pan_int_ctl = { | |
808 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
809 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
810 | .count = 16, | |
811 | .info = snd_us16x08_mix_info, | |
812 | .get = snd_us16x08_channel_get, | |
813 | .put = snd_us16x08_channel_put, | |
814 | .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 255) | |
815 | }; | |
816 | ||
817 | static struct snd_kcontrol_new snd_us16x08_master_ctl = { | |
818 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
819 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
820 | .count = 1, | |
821 | .info = snd_us16x08_master_info, | |
822 | .get = snd_us16x08_master_get, | |
823 | .put = snd_us16x08_master_put, | |
824 | .private_value = SND_US16X08_KCSET(SND_US16X08_FADER_BIAS, 1, 0, 133) | |
825 | }; | |
826 | ||
827 | static struct snd_kcontrol_new snd_us16x08_route_ctl = { | |
828 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
829 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
830 | .count = 8, | |
831 | .info = snd_us16x08_route_info, | |
832 | .get = snd_us16x08_route_get, | |
833 | .put = snd_us16x08_route_put, | |
834 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 9) | |
835 | }; | |
836 | ||
837 | static struct snd_kcontrol_new snd_us16x08_bus_ctl = { | |
838 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
839 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
840 | .count = 1, | |
841 | .info = snd_us16x08_switch_info, | |
842 | .get = snd_us16x08_bus_get, | |
843 | .put = snd_us16x08_bus_put, | |
844 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1) | |
845 | }; | |
846 | ||
847 | static struct snd_kcontrol_new snd_us16x08_compswitch_ctl = { | |
848 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
849 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
850 | .count = 16, | |
851 | .info = snd_us16x08_switch_info, | |
852 | .get = snd_us16x08_comp_get, | |
853 | .put = snd_us16x08_comp_put, | |
854 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1) | |
855 | }; | |
856 | ||
857 | static struct snd_kcontrol_new snd_us16x08_comp_threshold_ctl = { | |
858 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
859 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
860 | .count = 16, | |
861 | .info = snd_us16x08_mix_info, | |
862 | .get = snd_us16x08_comp_get, | |
863 | .put = snd_us16x08_comp_put, | |
864 | .private_value = SND_US16X08_KCSET(SND_US16X08_COMP_THRESHOLD_BIAS, 1, | |
865 | 0, 0x20) | |
866 | }; | |
867 | ||
868 | static struct snd_kcontrol_new snd_us16x08_comp_ratio_ctl = { | |
869 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
870 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
871 | .count = 16, | |
872 | .info = snd_us16x08_mix_info, | |
873 | .get = snd_us16x08_comp_get, | |
874 | .put = snd_us16x08_comp_put, | |
875 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, | |
876 | sizeof(ratio_map) - 1), /*max*/ | |
877 | }; | |
878 | ||
879 | static struct snd_kcontrol_new snd_us16x08_comp_gain_ctl = { | |
880 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
881 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
882 | .count = 16, | |
883 | .info = snd_us16x08_mix_info, | |
884 | .get = snd_us16x08_comp_get, | |
885 | .put = snd_us16x08_comp_put, | |
886 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x14) | |
887 | }; | |
888 | ||
889 | static struct snd_kcontrol_new snd_us16x08_comp_attack_ctl = { | |
890 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
891 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
892 | .count = 16, | |
893 | .info = snd_us16x08_mix_info, | |
894 | .get = snd_us16x08_comp_get, | |
895 | .put = snd_us16x08_comp_put, | |
896 | .private_value = | |
897 | SND_US16X08_KCSET(SND_US16X08_COMP_ATTACK_BIAS, 1, 0, 0xc6), | |
898 | }; | |
899 | ||
900 | static struct snd_kcontrol_new snd_us16x08_comp_release_ctl = { | |
901 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
902 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
903 | .count = 16, | |
904 | .info = snd_us16x08_mix_info, | |
905 | .get = snd_us16x08_comp_get, | |
906 | .put = snd_us16x08_comp_put, | |
907 | .private_value = | |
908 | SND_US16X08_KCSET(SND_US16X08_COMP_RELEASE_BIAS, 1, 0, 0x63), | |
909 | }; | |
910 | ||
911 | static struct snd_kcontrol_new snd_us16x08_eq_gain_ctl = { | |
912 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
913 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
914 | .count = 16, | |
915 | .info = snd_us16x08_mix_info, | |
916 | .get = snd_us16x08_eq_get, | |
917 | .put = snd_us16x08_eq_put, | |
918 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 24), | |
919 | }; | |
920 | ||
921 | static struct snd_kcontrol_new snd_us16x08_eq_low_freq_ctl = { | |
922 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
923 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
924 | .count = 16, | |
925 | .info = snd_us16x08_mix_info, | |
926 | .get = snd_us16x08_eq_get, | |
927 | .put = snd_us16x08_eq_put, | |
928 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x1F), | |
929 | }; | |
930 | ||
931 | static struct snd_kcontrol_new snd_us16x08_eq_mid_freq_ctl = { | |
932 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
933 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
934 | .count = 16, | |
935 | .info = snd_us16x08_mix_info, | |
936 | .get = snd_us16x08_eq_get, | |
937 | .put = snd_us16x08_eq_put, | |
938 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x3F) | |
939 | }; | |
940 | ||
941 | static struct snd_kcontrol_new snd_us16x08_eq_mid_width_ctl = { | |
942 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
943 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
944 | .count = 16, | |
945 | .info = snd_us16x08_mix_info, | |
946 | .get = snd_us16x08_eq_get, | |
947 | .put = snd_us16x08_eq_put, | |
948 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 0x06) | |
949 | }; | |
950 | ||
951 | static struct snd_kcontrol_new snd_us16x08_eq_high_freq_ctl = { | |
952 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
953 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
954 | .count = 16, | |
955 | .info = snd_us16x08_mix_info, | |
956 | .get = snd_us16x08_eq_get, | |
957 | .put = snd_us16x08_eq_put, | |
958 | .private_value = | |
959 | SND_US16X08_KCSET(SND_US16X08_EQ_HIGHFREQ_BIAS, 1, 0, 0x1F) | |
960 | }; | |
961 | ||
962 | static struct snd_kcontrol_new snd_us16x08_eq_switch_ctl = { | |
963 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
964 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
965 | .count = 16, | |
966 | .info = snd_us16x08_switch_info, | |
967 | .get = snd_us16x08_eqswitch_get, | |
968 | .put = snd_us16x08_eqswitch_put, | |
969 | .private_value = SND_US16X08_KCSET(SND_US16X08_NO_BIAS, 1, 0, 1) | |
970 | }; | |
971 | ||
972 | static struct snd_kcontrol_new snd_us16x08_meter_ctl = { | |
973 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
974 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | |
975 | .count = 1, | |
976 | .info = snd_us16x08_meter_info, | |
977 | .get = snd_us16x08_meter_get, | |
978 | .put = snd_us16x08_meter_put | |
979 | }; | |
980 | ||
981 | /* control store preparation */ | |
982 | ||
983 | /* setup compressor store and assign default value */ | |
984 | static struct snd_us16x08_comp_store *snd_us16x08_create_comp_store(void) | |
985 | { | |
986 | int i = 0; | |
987 | struct snd_us16x08_comp_store *tmp = | |
988 | kmalloc(sizeof(struct snd_us16x08_comp_store), GFP_KERNEL); | |
989 | ||
990 | if (tmp == NULL) | |
991 | return NULL; | |
992 | ||
993 | for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) { | |
994 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)][i] | |
995 | = 0x20; | |
996 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][i] = 0x00; | |
997 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][i] = 0x00; | |
998 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)][i] = 0x00; | |
999 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][i] = 0x00; | |
1000 | tmp->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)][i] = 0x00; | |
1001 | } | |
1002 | return tmp; | |
1003 | } | |
1004 | ||
1005 | /* setup EQ store and assign default values */ | |
1006 | static struct snd_us16x08_eq_store *snd_us16x08_create_eq_store(void) | |
1007 | { | |
1008 | int i, b_idx; | |
1009 | struct snd_us16x08_eq_store *tmp = | |
1010 | kmalloc(sizeof(struct snd_us16x08_eq_store), GFP_KERNEL); | |
1011 | ||
1012 | if (tmp == NULL) | |
1013 | return NULL; | |
1014 | ||
1015 | for (i = 0; i < SND_US16X08_MAX_CHANNELS; i++) { | |
1016 | for (b_idx = 0; b_idx < SND_US16X08_ID_EQ_BAND_COUNT; b_idx++) { | |
1017 | tmp->val[b_idx][0][i] = 0x0c; | |
1018 | tmp->val[b_idx][3][i] = 0x00; | |
1019 | switch (b_idx) { | |
1020 | case 0: /* EQ Low */ | |
1021 | tmp->val[b_idx][1][i] = 0x05; | |
1022 | tmp->val[b_idx][2][i] = 0xff; | |
1023 | break; | |
1024 | case 1: /* EQ Mid low */ | |
1025 | tmp->val[b_idx][1][i] = 0x0e; | |
1026 | tmp->val[b_idx][2][i] = 0x02; | |
1027 | break; | |
1028 | case 2: /* EQ Mid High */ | |
1029 | tmp->val[b_idx][1][i] = 0x1b; | |
1030 | tmp->val[b_idx][2][i] = 0x02; | |
1031 | break; | |
1032 | case 3: /* EQ High */ | |
1033 | tmp->val[b_idx][1][i] = 0x2f | |
1034 | - SND_US16X08_EQ_HIGHFREQ_BIAS; | |
1035 | tmp->val[b_idx][2][i] = 0xff; | |
1036 | break; | |
1037 | } | |
1038 | } | |
1039 | } | |
1040 | return tmp; | |
1041 | } | |
1042 | ||
34371d23 | 1043 | static struct snd_us16x08_meter_store *snd_us16x08_create_meter_store(void) |
d2bb390a DU |
1044 | { |
1045 | struct snd_us16x08_meter_store *tmp = | |
1046 | kzalloc(sizeof(struct snd_us16x08_meter_store), GFP_KERNEL); | |
1047 | ||
1048 | if (!tmp) | |
1049 | return NULL; | |
1050 | tmp->comp_index = 1; | |
1051 | tmp->comp_active_index = 0; | |
1052 | return tmp; | |
1053 | ||
1054 | } | |
1055 | ||
1056 | static int add_new_ctl(struct usb_mixer_interface *mixer, | |
1057 | const struct snd_kcontrol_new *ncontrol, | |
1058 | int index, int val_type, int channels, | |
1059 | const char *name, const void *opt, | |
1060 | void (*freeer)(struct snd_kcontrol *kctl), | |
1061 | struct usb_mixer_elem_info **elem_ret) | |
1062 | { | |
1063 | struct snd_kcontrol *kctl; | |
1064 | struct usb_mixer_elem_info *elem; | |
1065 | int err; | |
1066 | ||
1067 | usb_audio_dbg(mixer->chip, "us16x08 add mixer %s\n", name); | |
1068 | ||
1069 | elem = kzalloc(sizeof(*elem), GFP_KERNEL); | |
1070 | if (!elem) | |
1071 | return -ENOMEM; | |
1072 | ||
1073 | elem->head.mixer = mixer; | |
1074 | elem->head.resume = NULL; | |
1075 | elem->control = 0; | |
1076 | elem->idx_off = 0; | |
1077 | elem->head.id = index; | |
1078 | elem->val_type = val_type; | |
1079 | elem->channels = channels; | |
1080 | elem->private_data = (void *) opt; | |
1081 | ||
1082 | kctl = snd_ctl_new1(ncontrol, elem); | |
1083 | if (!kctl) { | |
1084 | kfree(elem); | |
1085 | return -ENOMEM; | |
1086 | } | |
1087 | ||
1088 | kctl->private_free = freeer; | |
1089 | ||
1090 | strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); | |
1091 | ||
1092 | err = snd_usb_mixer_add_control(&elem->head, kctl); | |
1093 | if (err < 0) | |
1094 | return err; | |
1095 | ||
1096 | if (elem_ret) | |
1097 | *elem_ret = elem; | |
1098 | ||
1099 | return 0; | |
1100 | } | |
1101 | ||
1102 | static struct snd_us16x08_control_params control_params; | |
1103 | ||
1104 | /* table of EQ controls */ | |
1105 | static struct snd_us16x08_control_params eq_controls[] = { | |
1106 | { /* EQ switch */ | |
1107 | .kcontrol_new = &snd_us16x08_eq_switch_ctl, | |
1108 | .control_id = SND_US16X08_ID_EQENABLE, | |
1109 | .type = USB_MIXER_BOOLEAN, | |
1110 | .num_channels = 16, | |
1111 | .name = "EQ Switch", | |
1112 | .freeer = snd_usb_mixer_elem_free | |
1113 | }, | |
1114 | { /* EQ low gain */ | |
1115 | .kcontrol_new = &snd_us16x08_eq_gain_ctl, | |
1116 | .control_id = SND_US16X08_ID_EQLOWLEVEL, | |
1117 | .type = USB_MIXER_U8, | |
1118 | .num_channels = 16, | |
1119 | .name = "EQ Low Volume", | |
1120 | .freeer = snd_usb_mixer_elem_free | |
1121 | }, | |
1122 | { /* EQ low freq */ | |
1123 | .kcontrol_new = &snd_us16x08_eq_low_freq_ctl, | |
1124 | .control_id = SND_US16X08_ID_EQLOWFREQ, | |
1125 | .type = USB_MIXER_U8, | |
1126 | .num_channels = 16, | |
1127 | .name = "EQ Low Frequence", | |
1128 | .freeer = NULL | |
1129 | }, | |
1130 | { /* EQ mid low gain */ | |
1131 | .kcontrol_new = &snd_us16x08_eq_gain_ctl, | |
1132 | .control_id = SND_US16X08_ID_EQLOWMIDLEVEL, | |
1133 | .type = USB_MIXER_U8, | |
1134 | .num_channels = 16, | |
1135 | .name = "EQ MidLow Volume", | |
1136 | .freeer = snd_usb_mixer_elem_free | |
1137 | }, | |
1138 | { /* EQ mid low freq */ | |
1139 | .kcontrol_new = &snd_us16x08_eq_mid_freq_ctl, | |
1140 | .control_id = SND_US16X08_ID_EQLOWMIDFREQ, | |
1141 | .type = USB_MIXER_U8, | |
1142 | .num_channels = 16, | |
1143 | .name = "EQ MidLow Frequence", | |
1144 | .freeer = NULL | |
1145 | }, | |
1146 | { /* EQ mid low Q */ | |
1147 | .kcontrol_new = &snd_us16x08_eq_mid_width_ctl, | |
1148 | .control_id = SND_US16X08_ID_EQLOWMIDWIDTH, | |
1149 | .type = USB_MIXER_U8, | |
1150 | .num_channels = 16, | |
1151 | .name = "EQ MidQLow Q", | |
1152 | .freeer = NULL | |
1153 | }, | |
1154 | { /* EQ mid high gain */ | |
1155 | .kcontrol_new = &snd_us16x08_eq_gain_ctl, | |
1156 | .control_id = SND_US16X08_ID_EQHIGHMIDLEVEL, | |
1157 | .type = USB_MIXER_U8, | |
1158 | .num_channels = 16, | |
1159 | .name = "EQ MidHigh Volume", | |
1160 | .freeer = snd_usb_mixer_elem_free | |
1161 | }, | |
1162 | { /* EQ mid high freq */ | |
1163 | .kcontrol_new = &snd_us16x08_eq_mid_freq_ctl, | |
1164 | .control_id = SND_US16X08_ID_EQHIGHMIDFREQ, | |
1165 | .type = USB_MIXER_U8, | |
1166 | .num_channels = 16, | |
1167 | .name = "EQ MidHigh Frequence", | |
1168 | .freeer = NULL | |
1169 | }, | |
1170 | { /* EQ mid high Q */ | |
1171 | .kcontrol_new = &snd_us16x08_eq_mid_width_ctl, | |
1172 | .control_id = SND_US16X08_ID_EQHIGHMIDWIDTH, | |
1173 | .type = USB_MIXER_U8, | |
1174 | .num_channels = 16, | |
1175 | .name = "EQ MidHigh Q", | |
1176 | .freeer = NULL | |
1177 | }, | |
1178 | { /* EQ high gain */ | |
1179 | .kcontrol_new = &snd_us16x08_eq_gain_ctl, | |
1180 | .control_id = SND_US16X08_ID_EQHIGHLEVEL, | |
1181 | .type = USB_MIXER_U8, | |
1182 | .num_channels = 16, | |
1183 | .name = "EQ High Volume", | |
1184 | .freeer = snd_usb_mixer_elem_free | |
1185 | }, | |
1186 | { /* EQ low freq */ | |
1187 | .kcontrol_new = &snd_us16x08_eq_high_freq_ctl, | |
1188 | .control_id = SND_US16X08_ID_EQHIGHFREQ, | |
1189 | .type = USB_MIXER_U8, | |
1190 | .num_channels = 16, | |
1191 | .name = "EQ High Frequence", | |
1192 | .freeer = NULL | |
1193 | }, | |
1194 | }; | |
1195 | ||
1196 | /* table of compressor controls */ | |
1197 | static struct snd_us16x08_control_params comp_controls[] = { | |
1198 | { /* Comp enable */ | |
1199 | .kcontrol_new = &snd_us16x08_compswitch_ctl, | |
1200 | .control_id = SND_US16X08_ID_COMP_SWITCH, | |
1201 | .type = USB_MIXER_BOOLEAN, | |
1202 | .num_channels = 16, | |
1203 | .name = "Compressor Switch", | |
1204 | .freeer = snd_usb_mixer_elem_free | |
1205 | }, | |
1206 | { /* Comp threshold */ | |
1207 | .kcontrol_new = &snd_us16x08_comp_threshold_ctl, | |
1208 | .control_id = SND_US16X08_ID_COMP_THRESHOLD, | |
1209 | .type = USB_MIXER_U8, | |
1210 | .num_channels = 16, | |
1211 | .name = "Compressor Threshold Volume", | |
1212 | .freeer = NULL | |
1213 | }, | |
1214 | { /* Comp ratio */ | |
1215 | .kcontrol_new = &snd_us16x08_comp_ratio_ctl, | |
1216 | .control_id = SND_US16X08_ID_COMP_RATIO, | |
1217 | .type = USB_MIXER_U8, | |
1218 | .num_channels = 16, | |
1219 | .name = "Compressor Ratio", | |
1220 | .freeer = NULL | |
1221 | }, | |
1222 | { /* Comp attack */ | |
1223 | .kcontrol_new = &snd_us16x08_comp_attack_ctl, | |
1224 | .control_id = SND_US16X08_ID_COMP_ATTACK, | |
1225 | .type = USB_MIXER_U8, | |
1226 | .num_channels = 16, | |
1227 | .name = "Compressor Attack", | |
1228 | .freeer = NULL | |
1229 | }, | |
1230 | { /* Comp release */ | |
1231 | .kcontrol_new = &snd_us16x08_comp_release_ctl, | |
1232 | .control_id = SND_US16X08_ID_COMP_RELEASE, | |
1233 | .type = USB_MIXER_U8, | |
1234 | .num_channels = 16, | |
1235 | .name = "Compressor Release", | |
1236 | .freeer = NULL | |
1237 | }, | |
1238 | { /* Comp gain */ | |
1239 | .kcontrol_new = &snd_us16x08_comp_gain_ctl, | |
1240 | .control_id = SND_US16X08_ID_COMP_GAIN, | |
1241 | .type = USB_MIXER_U8, | |
1242 | .num_channels = 16, | |
1243 | .name = "Compressor Volume", | |
1244 | .freeer = NULL | |
1245 | }, | |
1246 | }; | |
1247 | ||
1248 | /* table of channel controls */ | |
1249 | static struct snd_us16x08_control_params channel_controls[] = { | |
1250 | { /* Phase */ | |
1251 | .kcontrol_new = &snd_us16x08_ch_boolean_ctl, | |
1252 | .control_id = SND_US16X08_ID_PHASE, | |
1253 | .type = USB_MIXER_BOOLEAN, | |
1254 | .num_channels = 16, | |
1255 | .name = "Phase Switch", | |
1256 | .freeer = snd_usb_mixer_elem_free, | |
1257 | .default_val = 0 | |
1258 | }, | |
1259 | { /* Fader */ | |
1260 | .kcontrol_new = &snd_us16x08_ch_int_ctl, | |
1261 | .control_id = SND_US16X08_ID_FADER, | |
1262 | .type = USB_MIXER_U8, | |
1263 | .num_channels = 16, | |
1264 | .name = "Line Volume", | |
1265 | .freeer = NULL, | |
1266 | .default_val = 127 | |
1267 | }, | |
1268 | { /* Mute */ | |
1269 | .kcontrol_new = &snd_us16x08_ch_boolean_ctl, | |
1270 | .control_id = SND_US16X08_ID_MUTE, | |
1271 | .type = USB_MIXER_BOOLEAN, | |
1272 | .num_channels = 16, | |
1273 | .name = "Mute Switch", | |
1274 | .freeer = NULL, | |
1275 | .default_val = 0 | |
1276 | }, | |
1277 | { /* Pan */ | |
1278 | .kcontrol_new = &snd_us16x08_pan_int_ctl, | |
1279 | .control_id = SND_US16X08_ID_PAN, | |
1280 | .type = USB_MIXER_U16, | |
1281 | .num_channels = 16, | |
1282 | .name = "Pan Left-Right Volume", | |
1283 | .freeer = NULL, | |
1284 | .default_val = 127 | |
1285 | }, | |
1286 | }; | |
1287 | ||
1288 | /* table of master controls */ | |
1289 | static struct snd_us16x08_control_params master_controls[] = { | |
1290 | { /* Master */ | |
1291 | .kcontrol_new = &snd_us16x08_master_ctl, | |
1292 | .control_id = SND_US16X08_ID_FADER, | |
1293 | .type = USB_MIXER_U8, | |
1294 | .num_channels = 16, | |
1295 | .name = "Master Volume", | |
1296 | .freeer = NULL, | |
1297 | .default_val = 127 | |
1298 | }, | |
1299 | { /* Bypass */ | |
1300 | .kcontrol_new = &snd_us16x08_bus_ctl, | |
1301 | .control_id = SND_US16X08_ID_BYPASS, | |
1302 | .type = USB_MIXER_BOOLEAN, | |
1303 | .num_channels = 16, | |
1304 | .name = "DSP Bypass Switch", | |
1305 | .freeer = NULL, | |
1306 | .default_val = 0 | |
1307 | }, | |
1308 | { /* Buss out */ | |
1309 | .kcontrol_new = &snd_us16x08_bus_ctl, | |
1310 | .control_id = SND_US16X08_ID_BUSS_OUT, | |
1311 | .type = USB_MIXER_BOOLEAN, | |
1312 | .num_channels = 16, | |
1313 | .name = "Buss Out Switch", | |
1314 | .freeer = NULL, | |
1315 | .default_val = 0 | |
1316 | }, | |
1317 | { /* Master mute */ | |
1318 | .kcontrol_new = &snd_us16x08_bus_ctl, | |
1319 | .control_id = SND_US16X08_ID_MUTE, | |
1320 | .type = USB_MIXER_BOOLEAN, | |
1321 | .num_channels = 16, | |
1322 | .name = "Master Mute Switch", | |
1323 | .freeer = NULL, | |
1324 | .default_val = 0 | |
1325 | }, | |
1326 | ||
1327 | }; | |
1328 | ||
1329 | int snd_us16x08_controls_create(struct usb_mixer_interface *mixer) | |
1330 | { | |
1331 | int i, j; | |
1332 | int err; | |
1333 | struct usb_mixer_elem_info *elem; | |
1334 | struct snd_us16x08_comp_store *comp_store; | |
1335 | struct snd_us16x08_meter_store *meter_store; | |
1336 | struct snd_us16x08_eq_store *eq_store; | |
1337 | ||
1338 | /* just check for non-MIDI interface */ | |
1339 | if (mixer->hostif->desc.bInterfaceNumber == 3) { | |
1340 | ||
1341 | /* create compressor mixer elements */ | |
1342 | comp_store = snd_us16x08_create_comp_store(); | |
1343 | if (comp_store == NULL) | |
1344 | return -ENOMEM; | |
1345 | ||
1346 | /* create eq store */ | |
1347 | eq_store = snd_us16x08_create_eq_store(); | |
1348 | if (eq_store == NULL) { | |
1349 | kfree(comp_store); | |
1350 | return -ENOMEM; | |
1351 | } | |
1352 | ||
1353 | /* create meters store */ | |
1354 | meter_store = snd_us16x08_create_meter_store(); | |
1355 | if (meter_store == NULL) { | |
1356 | kfree(comp_store); | |
1357 | kfree(eq_store); | |
1358 | return -ENOMEM; | |
1359 | } | |
1360 | ||
1361 | /* add routing control */ | |
1362 | err = add_new_ctl(mixer, &snd_us16x08_route_ctl, | |
1363 | SND_US16X08_ID_ROUTE, USB_MIXER_U8, 8, "Line Out Route", | |
1364 | NULL, NULL, &elem); | |
1365 | if (err < 0) { | |
1366 | usb_audio_dbg(mixer->chip, | |
1367 | "Failed to create route control, err:%d\n", | |
1368 | err); | |
1369 | return err; | |
1370 | } | |
1371 | for (i = 0; i < 8; i++) | |
1372 | elem->cache_val[i] = i < 2 ? i : i + 2; | |
1373 | elem->cached = 0xff; | |
1374 | ||
1375 | /* add master controls */ | |
1376 | for (i = 0; | |
1377 | i < sizeof(master_controls) | |
1378 | / sizeof(control_params); | |
1379 | i++) { | |
1380 | ||
1381 | err = add_new_ctl(mixer, | |
1382 | master_controls[i].kcontrol_new, | |
1383 | master_controls[i].control_id, | |
1384 | master_controls[i].type, | |
1385 | master_controls[i].num_channels, | |
1386 | master_controls[i].name, | |
1387 | comp_store, | |
1388 | master_controls[i].freeer, &elem); | |
1389 | if (err < 0) | |
1390 | return err; | |
1391 | elem->cache_val[0] = master_controls[i].default_val; | |
1392 | elem->cached = 1; | |
1393 | } | |
1394 | ||
1395 | /* add channel controls */ | |
1396 | for (i = 0; | |
1397 | i < sizeof(channel_controls) | |
1398 | / sizeof(control_params); | |
1399 | i++) { | |
1400 | ||
1401 | err = add_new_ctl(mixer, | |
1402 | channel_controls[i].kcontrol_new, | |
1403 | channel_controls[i].control_id, | |
1404 | channel_controls[i].type, | |
1405 | channel_controls[i].num_channels, | |
1406 | channel_controls[i].name, | |
1407 | comp_store, | |
1408 | channel_controls[i].freeer, &elem); | |
1409 | if (err < 0) | |
1410 | return err; | |
1411 | for (j = 0; j < SND_US16X08_MAX_CHANNELS; j++) { | |
1412 | elem->cache_val[j] = | |
1413 | channel_controls[i].default_val; | |
1414 | } | |
1415 | elem->cached = 0xffff; | |
1416 | } | |
1417 | ||
1418 | /* add EQ controls */ | |
1419 | for (i = 0; i < sizeof(eq_controls) / | |
1420 | sizeof(control_params); i++) { | |
1421 | ||
1422 | err = add_new_ctl(mixer, | |
1423 | eq_controls[i].kcontrol_new, | |
1424 | eq_controls[i].control_id, | |
1425 | eq_controls[i].type, | |
1426 | eq_controls[i].num_channels, | |
1427 | eq_controls[i].name, | |
1428 | eq_store, | |
1429 | eq_controls[i].freeer, NULL); | |
1430 | if (err < 0) | |
1431 | return err; | |
1432 | } | |
1433 | ||
1434 | /* add compressor controls */ | |
1435 | for (i = 0; | |
1436 | i < sizeof(comp_controls) | |
1437 | / sizeof(control_params); | |
1438 | i++) { | |
1439 | ||
1440 | err = add_new_ctl(mixer, | |
1441 | comp_controls[i].kcontrol_new, | |
1442 | comp_controls[i].control_id, | |
1443 | comp_controls[i].type, | |
1444 | comp_controls[i].num_channels, | |
1445 | comp_controls[i].name, | |
1446 | comp_store, | |
1447 | comp_controls[i].freeer, NULL); | |
1448 | if (err < 0) | |
1449 | return err; | |
1450 | } | |
1451 | ||
1452 | /* meter function 'get' must access to compressor store | |
1453 | * so place a reference here | |
1454 | */ | |
1455 | meter_store->comp_store = comp_store; | |
1456 | err = add_new_ctl(mixer, &snd_us16x08_meter_ctl, | |
1457 | SND_US16X08_ID_METER, USB_MIXER_U16, 0, "Level Meter", | |
1458 | (void *) meter_store, snd_usb_mixer_elem_free, NULL); | |
1459 | if (err < 0) | |
1460 | return err; | |
1461 | } | |
1462 | ||
1463 | return 0; | |
1464 | } | |
1465 |