x86: implement gbpages support in change_page_attr()
[wrt350n-kernel.git] / sound / usb / usbmixer.c
blob89c63d073cc6fac8f0c00ca1646377994157c64b
1 /*
2 * (Tentative) USB Audio Driver for ALSA
4 * Mixer control part
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
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
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
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
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/bitops.h>
30 #include <linux/init.h>
31 #include <linux/list.h>
32 #include <linux/slab.h>
33 #include <linux/string.h>
34 #include <linux/usb.h>
35 #include <sound/core.h>
36 #include <sound/control.h>
37 #include <sound/hwdep.h>
38 #include <sound/info.h>
39 #include <sound/tlv.h>
41 #include "usbaudio.h"
46 /* ignore error from controls - for debugging */
47 /* #define IGNORE_CTL_ERROR */
50 * Sound Blaster remote control configuration
52 * format of remote control data:
53 * Extigy: xx 00
54 * Audigy 2 NX: 06 80 xx 00 00 00
55 * Live! 24-bit: 06 80 xx yy 22 83
57 static const struct rc_config {
58 u32 usb_id;
59 u8 offset;
60 u8 length;
61 u8 packet_length;
62 u8 mute_mixer_id;
63 u32 mute_code;
64 } rc_configs[] = {
65 { USB_ID(0x041e, 0x3000), 0, 1, 2, 18, 0x0013 }, /* Extigy */
66 { USB_ID(0x041e, 0x3020), 2, 1, 6, 18, 0x0013 }, /* Audigy 2 NX */
67 { USB_ID(0x041e, 0x3040), 2, 2, 6, 2, 0x6e91 }, /* Live! 24-bit */
70 struct usb_mixer_interface {
71 struct snd_usb_audio *chip;
72 unsigned int ctrlif;
73 struct list_head list;
74 unsigned int ignore_ctl_error;
75 struct urb *urb;
76 struct usb_mixer_elem_info **id_elems; /* array[256], indexed by unit id */
78 /* Sound Blaster remote control stuff */
79 const struct rc_config *rc_cfg;
80 unsigned long rc_hwdep_open;
81 u32 rc_code;
82 wait_queue_head_t rc_waitq;
83 struct urb *rc_urb;
84 struct usb_ctrlrequest *rc_setup_packet;
85 u8 rc_buffer[6];
87 u8 audigy2nx_leds[3];
91 struct usb_audio_term {
92 int id;
93 int type;
94 int channels;
95 unsigned int chconfig;
96 int name;
99 struct usbmix_name_map;
101 struct mixer_build {
102 struct snd_usb_audio *chip;
103 struct usb_mixer_interface *mixer;
104 unsigned char *buffer;
105 unsigned int buflen;
106 DECLARE_BITMAP(unitbitmap, 256);
107 struct usb_audio_term oterm;
108 const struct usbmix_name_map *map;
109 const struct usbmix_selector_map *selector_map;
112 struct usb_mixer_elem_info {
113 struct usb_mixer_interface *mixer;
114 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
115 struct snd_ctl_elem_id *elem_id;
116 unsigned int id;
117 unsigned int control; /* CS or ICN (high byte) */
118 unsigned int cmask; /* channel mask bitmap: 0 = master */
119 int channels;
120 int val_type;
121 int min, max, res;
122 u8 initialized;
126 enum {
127 USB_FEATURE_NONE = 0,
128 USB_FEATURE_MUTE = 1,
129 USB_FEATURE_VOLUME,
130 USB_FEATURE_BASS,
131 USB_FEATURE_MID,
132 USB_FEATURE_TREBLE,
133 USB_FEATURE_GEQ,
134 USB_FEATURE_AGC,
135 USB_FEATURE_DELAY,
136 USB_FEATURE_BASSBOOST,
137 USB_FEATURE_LOUDNESS
140 enum {
141 USB_MIXER_BOOLEAN,
142 USB_MIXER_INV_BOOLEAN,
143 USB_MIXER_S8,
144 USB_MIXER_U8,
145 USB_MIXER_S16,
146 USB_MIXER_U16,
149 enum {
150 USB_PROC_UPDOWN = 1,
151 USB_PROC_UPDOWN_SWITCH = 1,
152 USB_PROC_UPDOWN_MODE_SEL = 2,
154 USB_PROC_PROLOGIC = 2,
155 USB_PROC_PROLOGIC_SWITCH = 1,
156 USB_PROC_PROLOGIC_MODE_SEL = 2,
158 USB_PROC_3DENH = 3,
159 USB_PROC_3DENH_SWITCH = 1,
160 USB_PROC_3DENH_SPACE = 2,
162 USB_PROC_REVERB = 4,
163 USB_PROC_REVERB_SWITCH = 1,
164 USB_PROC_REVERB_LEVEL = 2,
165 USB_PROC_REVERB_TIME = 3,
166 USB_PROC_REVERB_DELAY = 4,
168 USB_PROC_CHORUS = 5,
169 USB_PROC_CHORUS_SWITCH = 1,
170 USB_PROC_CHORUS_LEVEL = 2,
171 USB_PROC_CHORUS_RATE = 3,
172 USB_PROC_CHORUS_DEPTH = 4,
174 USB_PROC_DCR = 6,
175 USB_PROC_DCR_SWITCH = 1,
176 USB_PROC_DCR_RATIO = 2,
177 USB_PROC_DCR_MAX_AMP = 3,
178 USB_PROC_DCR_THRESHOLD = 4,
179 USB_PROC_DCR_ATTACK = 5,
180 USB_PROC_DCR_RELEASE = 6,
183 #define MAX_CHANNELS 10 /* max logical channels */
187 * manual mapping of mixer names
188 * if the mixer topology is too complicated and the parsed names are
189 * ambiguous, add the entries in usbmixer_maps.c.
191 #include "usbmixer_maps.c"
193 /* get the mapped name if the unit matches */
194 static int check_mapped_name(struct mixer_build *state, int unitid, int control, char *buf, int buflen)
196 const struct usbmix_name_map *p;
198 if (! state->map)
199 return 0;
201 for (p = state->map; p->id; p++) {
202 if (p->id == unitid && p->name &&
203 (! control || ! p->control || control == p->control)) {
204 buflen--;
205 return strlcpy(buf, p->name, buflen);
208 return 0;
211 /* check whether the control should be ignored */
212 static int check_ignored_ctl(struct mixer_build *state, int unitid, int control)
214 const struct usbmix_name_map *p;
216 if (! state->map)
217 return 0;
218 for (p = state->map; p->id; p++) {
219 if (p->id == unitid && ! p->name &&
220 (! control || ! p->control || control == p->control)) {
221 // printk("ignored control %d:%d\n", unitid, control);
222 return 1;
225 return 0;
228 /* get the mapped selector source name */
229 static int check_mapped_selector_name(struct mixer_build *state, int unitid,
230 int index, char *buf, int buflen)
232 const struct usbmix_selector_map *p;
234 if (! state->selector_map)
235 return 0;
236 for (p = state->selector_map; p->id; p++) {
237 if (p->id == unitid && index < p->count)
238 return strlcpy(buf, p->names[index], buflen);
240 return 0;
244 * find an audio control unit with the given unit id
246 static void *find_audio_control_unit(struct mixer_build *state, unsigned char unit)
248 unsigned char *p;
250 p = NULL;
251 while ((p = snd_usb_find_desc(state->buffer, state->buflen, p,
252 USB_DT_CS_INTERFACE)) != NULL) {
253 if (p[0] >= 4 && p[2] >= INPUT_TERMINAL && p[2] <= EXTENSION_UNIT && p[3] == unit)
254 return p;
256 return NULL;
261 * copy a string with the given id
263 static int snd_usb_copy_string_desc(struct mixer_build *state, int index, char *buf, int maxlen)
265 int len = usb_string(state->chip->dev, index, buf, maxlen - 1);
266 buf[len] = 0;
267 return len;
271 * convert from the byte/word on usb descriptor to the zero-based integer
273 static int convert_signed_value(struct usb_mixer_elem_info *cval, int val)
275 switch (cval->val_type) {
276 case USB_MIXER_BOOLEAN:
277 return !!val;
278 case USB_MIXER_INV_BOOLEAN:
279 return !val;
280 case USB_MIXER_U8:
281 val &= 0xff;
282 break;
283 case USB_MIXER_S8:
284 val &= 0xff;
285 if (val >= 0x80)
286 val -= 0x100;
287 break;
288 case USB_MIXER_U16:
289 val &= 0xffff;
290 break;
291 case USB_MIXER_S16:
292 val &= 0xffff;
293 if (val >= 0x8000)
294 val -= 0x10000;
295 break;
297 return val;
301 * convert from the zero-based int to the byte/word for usb descriptor
303 static int convert_bytes_value(struct usb_mixer_elem_info *cval, int val)
305 switch (cval->val_type) {
306 case USB_MIXER_BOOLEAN:
307 return !!val;
308 case USB_MIXER_INV_BOOLEAN:
309 return !val;
310 case USB_MIXER_S8:
311 case USB_MIXER_U8:
312 return val & 0xff;
313 case USB_MIXER_S16:
314 case USB_MIXER_U16:
315 return val & 0xffff;
317 return 0; /* not reached */
320 static int get_relative_value(struct usb_mixer_elem_info *cval, int val)
322 if (! cval->res)
323 cval->res = 1;
324 if (val < cval->min)
325 return 0;
326 else if (val >= cval->max)
327 return (cval->max - cval->min + cval->res - 1) / cval->res;
328 else
329 return (val - cval->min) / cval->res;
332 static int get_abs_value(struct usb_mixer_elem_info *cval, int val)
334 if (val < 0)
335 return cval->min;
336 if (! cval->res)
337 cval->res = 1;
338 val *= cval->res;
339 val += cval->min;
340 if (val > cval->max)
341 return cval->max;
342 return val;
347 * retrieve a mixer value
350 static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
352 unsigned char buf[2];
353 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
354 int timeout = 10;
356 while (timeout-- > 0) {
357 if (snd_usb_ctl_msg(cval->mixer->chip->dev,
358 usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
359 request,
360 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
361 validx, cval->mixer->ctrlif | (cval->id << 8),
362 buf, val_len, 100) >= val_len) {
363 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
364 return 0;
367 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
368 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type);
369 return -EINVAL;
372 static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value)
374 return get_ctl_value(cval, GET_CUR, validx, value);
377 /* channel = 0: master, 1 = first channel */
378 static inline int get_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, int *value)
380 return get_ctl_value(cval, GET_CUR, (cval->control << 8) | channel, value);
384 * set a mixer value
387 static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set)
389 unsigned char buf[2];
390 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
391 int timeout = 10;
393 value_set = convert_bytes_value(cval, value_set);
394 buf[0] = value_set & 0xff;
395 buf[1] = (value_set >> 8) & 0xff;
396 while (timeout -- > 0)
397 if (snd_usb_ctl_msg(cval->mixer->chip->dev,
398 usb_sndctrlpipe(cval->mixer->chip->dev, 0),
399 request,
400 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
401 validx, cval->mixer->ctrlif | (cval->id << 8),
402 buf, val_len, 100) >= 0)
403 return 0;
404 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n",
405 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]);
406 return -EINVAL;
409 static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value)
411 return set_ctl_value(cval, SET_CUR, validx, value);
414 static inline int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, int value)
416 return set_ctl_value(cval, SET_CUR, (cval->control << 8) | channel, value);
420 * TLV callback for mixer volume controls
422 static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
423 unsigned int size, unsigned int __user *_tlv)
425 struct usb_mixer_elem_info *cval = kcontrol->private_data;
426 DECLARE_TLV_DB_SCALE(scale, 0, 0, 0);
428 if (size < sizeof(scale))
429 return -ENOMEM;
430 /* USB descriptions contain the dB scale in 1/256 dB unit
431 * while ALSA TLV contains in 1/100 dB unit
433 scale[2] = (convert_signed_value(cval, cval->min) * 100) / 256;
434 scale[3] = (convert_signed_value(cval, cval->res) * 100) / 256;
435 if (copy_to_user(_tlv, scale, sizeof(scale)))
436 return -EFAULT;
437 return 0;
441 * parser routines begin here...
444 static int parse_audio_unit(struct mixer_build *state, int unitid);
448 * check if the input/output channel routing is enabled on the given bitmap.
449 * used for mixer unit parser
451 static int check_matrix_bitmap(unsigned char *bmap, int ich, int och, int num_outs)
453 int idx = ich * num_outs + och;
454 return bmap[idx >> 3] & (0x80 >> (idx & 7));
459 * add an alsa control element
460 * search and increment the index until an empty slot is found.
462 * if failed, give up and free the control instance.
465 static int add_control_to_empty(struct mixer_build *state, struct snd_kcontrol *kctl)
467 struct usb_mixer_elem_info *cval = kctl->private_data;
468 int err;
470 while (snd_ctl_find_id(state->chip->card, &kctl->id))
471 kctl->id.index++;
472 if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) {
473 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
474 return err;
476 cval->elem_id = &kctl->id;
477 cval->next_id_elem = state->mixer->id_elems[cval->id];
478 state->mixer->id_elems[cval->id] = cval;
479 return 0;
484 * get a terminal name string
487 static struct iterm_name_combo {
488 int type;
489 char *name;
490 } iterm_names[] = {
491 { 0x0300, "Output" },
492 { 0x0301, "Speaker" },
493 { 0x0302, "Headphone" },
494 { 0x0303, "HMD Audio" },
495 { 0x0304, "Desktop Speaker" },
496 { 0x0305, "Room Speaker" },
497 { 0x0306, "Com Speaker" },
498 { 0x0307, "LFE" },
499 { 0x0600, "External In" },
500 { 0x0601, "Analog In" },
501 { 0x0602, "Digital In" },
502 { 0x0603, "Line" },
503 { 0x0604, "Legacy In" },
504 { 0x0605, "IEC958 In" },
505 { 0x0606, "1394 DA Stream" },
506 { 0x0607, "1394 DV Stream" },
507 { 0x0700, "Embedded" },
508 { 0x0701, "Noise Source" },
509 { 0x0702, "Equalization Noise" },
510 { 0x0703, "CD" },
511 { 0x0704, "DAT" },
512 { 0x0705, "DCC" },
513 { 0x0706, "MiniDisk" },
514 { 0x0707, "Analog Tape" },
515 { 0x0708, "Phonograph" },
516 { 0x0709, "VCR Audio" },
517 { 0x070a, "Video Disk Audio" },
518 { 0x070b, "DVD Audio" },
519 { 0x070c, "TV Tuner Audio" },
520 { 0x070d, "Satellite Rec Audio" },
521 { 0x070e, "Cable Tuner Audio" },
522 { 0x070f, "DSS Audio" },
523 { 0x0710, "Radio Receiver" },
524 { 0x0711, "Radio Transmitter" },
525 { 0x0712, "Multi-Track Recorder" },
526 { 0x0713, "Synthesizer" },
527 { 0 },
530 static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm,
531 unsigned char *name, int maxlen, int term_only)
533 struct iterm_name_combo *names;
535 if (iterm->name)
536 return snd_usb_copy_string_desc(state, iterm->name, name, maxlen);
538 /* virtual type - not a real terminal */
539 if (iterm->type >> 16) {
540 if (term_only)
541 return 0;
542 switch (iterm->type >> 16) {
543 case SELECTOR_UNIT:
544 strcpy(name, "Selector"); return 8;
545 case PROCESSING_UNIT:
546 strcpy(name, "Process Unit"); return 12;
547 case EXTENSION_UNIT:
548 strcpy(name, "Ext Unit"); return 8;
549 case MIXER_UNIT:
550 strcpy(name, "Mixer"); return 5;
551 default:
552 return sprintf(name, "Unit %d", iterm->id);
556 switch (iterm->type & 0xff00) {
557 case 0x0100:
558 strcpy(name, "PCM"); return 3;
559 case 0x0200:
560 strcpy(name, "Mic"); return 3;
561 case 0x0400:
562 strcpy(name, "Headset"); return 7;
563 case 0x0500:
564 strcpy(name, "Phone"); return 5;
567 for (names = iterm_names; names->type; names++)
568 if (names->type == iterm->type) {
569 strcpy(name, names->name);
570 return strlen(names->name);
572 return 0;
577 * parse the source unit recursively until it reaches to a terminal
578 * or a branched unit.
580 static int check_input_term(struct mixer_build *state, int id, struct usb_audio_term *term)
582 unsigned char *p1;
584 memset(term, 0, sizeof(*term));
585 while ((p1 = find_audio_control_unit(state, id)) != NULL) {
586 term->id = id;
587 switch (p1[2]) {
588 case INPUT_TERMINAL:
589 term->type = combine_word(p1 + 4);
590 term->channels = p1[7];
591 term->chconfig = combine_word(p1 + 8);
592 term->name = p1[11];
593 return 0;
594 case FEATURE_UNIT:
595 id = p1[4];
596 break; /* continue to parse */
597 case MIXER_UNIT:
598 term->type = p1[2] << 16; /* virtual type */
599 term->channels = p1[5 + p1[4]];
600 term->chconfig = combine_word(p1 + 6 + p1[4]);
601 term->name = p1[p1[0] - 1];
602 return 0;
603 case SELECTOR_UNIT:
604 /* call recursively to retrieve the channel info */
605 if (check_input_term(state, p1[5], term) < 0)
606 return -ENODEV;
607 term->type = p1[2] << 16; /* virtual type */
608 term->id = id;
609 term->name = p1[9 + p1[0] - 1];
610 return 0;
611 case PROCESSING_UNIT:
612 case EXTENSION_UNIT:
613 if (p1[6] == 1) {
614 id = p1[7];
615 break; /* continue to parse */
617 term->type = p1[2] << 16; /* virtual type */
618 term->channels = p1[7 + p1[6]];
619 term->chconfig = combine_word(p1 + 8 + p1[6]);
620 term->name = p1[12 + p1[6] + p1[11 + p1[6]]];
621 return 0;
622 default:
623 return -ENODEV;
626 return -ENODEV;
631 * Feature Unit
634 /* feature unit control information */
635 struct usb_feature_control_info {
636 const char *name;
637 unsigned int type; /* control type (mute, volume, etc.) */
640 static struct usb_feature_control_info audio_feature_info[] = {
641 { "Mute", USB_MIXER_INV_BOOLEAN },
642 { "Volume", USB_MIXER_S16 },
643 { "Tone Control - Bass", USB_MIXER_S8 },
644 { "Tone Control - Mid", USB_MIXER_S8 },
645 { "Tone Control - Treble", USB_MIXER_S8 },
646 { "Graphic Equalizer", USB_MIXER_S8 }, /* FIXME: not implemeted yet */
647 { "Auto Gain Control", USB_MIXER_BOOLEAN },
648 { "Delay Control", USB_MIXER_U16 },
649 { "Bass Boost", USB_MIXER_BOOLEAN },
650 { "Loudness", USB_MIXER_BOOLEAN },
654 /* private_free callback */
655 static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
657 kfree(kctl->private_data);
658 kctl->private_data = NULL;
663 * interface to ALSA control for feature/mixer units
667 * retrieve the minimum and maximum values for the specified control
669 static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
671 /* for failsafe */
672 cval->min = default_min;
673 cval->max = cval->min + 1;
674 cval->res = 1;
676 if (cval->val_type == USB_MIXER_BOOLEAN ||
677 cval->val_type == USB_MIXER_INV_BOOLEAN) {
678 cval->initialized = 1;
679 } else {
680 int minchn = 0;
681 if (cval->cmask) {
682 int i;
683 for (i = 0; i < MAX_CHANNELS; i++)
684 if (cval->cmask & (1 << i)) {
685 minchn = i + 1;
686 break;
689 if (get_ctl_value(cval, GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
690 get_ctl_value(cval, GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
691 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n",
692 cval->id, cval->mixer->ctrlif, cval->control, cval->id);
693 return -EINVAL;
695 if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
696 cval->res = 1;
697 } else {
698 int last_valid_res = cval->res;
700 while (cval->res > 1) {
701 if (set_ctl_value(cval, SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0)
702 break;
703 cval->res /= 2;
705 if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0)
706 cval->res = last_valid_res;
708 if (cval->res == 0)
709 cval->res = 1;
711 /* Additional checks for the proper resolution
713 * Some devices report smaller resolutions than actually
714 * reacting. They don't return errors but simply clip
715 * to the lower aligned value.
717 if (cval->min + cval->res < cval->max) {
718 int last_valid_res = cval->res;
719 int saved, test, check;
720 get_cur_mix_value(cval, minchn, &saved);
721 for (;;) {
722 test = saved;
723 if (test < cval->max)
724 test += cval->res;
725 else
726 test -= cval->res;
727 if (test < cval->min || test > cval->max ||
728 set_cur_mix_value(cval, minchn, test) ||
729 get_cur_mix_value(cval, minchn, &check)) {
730 cval->res = last_valid_res;
731 break;
733 if (test == check)
734 break;
735 cval->res *= 2;
737 set_cur_mix_value(cval, minchn, saved);
740 cval->initialized = 1;
742 return 0;
746 /* get a feature/mixer unit info */
747 static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
749 struct usb_mixer_elem_info *cval = kcontrol->private_data;
751 if (cval->val_type == USB_MIXER_BOOLEAN ||
752 cval->val_type == USB_MIXER_INV_BOOLEAN)
753 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
754 else
755 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
756 uinfo->count = cval->channels;
757 if (cval->val_type == USB_MIXER_BOOLEAN ||
758 cval->val_type == USB_MIXER_INV_BOOLEAN) {
759 uinfo->value.integer.min = 0;
760 uinfo->value.integer.max = 1;
761 } else {
762 if (! cval->initialized)
763 get_min_max(cval, 0);
764 uinfo->value.integer.min = 0;
765 uinfo->value.integer.max =
766 (cval->max - cval->min + cval->res - 1) / cval->res;
768 return 0;
771 /* get the current value from feature/mixer unit */
772 static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
774 struct usb_mixer_elem_info *cval = kcontrol->private_data;
775 int c, cnt, val, err;
777 if (cval->cmask) {
778 cnt = 0;
779 for (c = 0; c < MAX_CHANNELS; c++) {
780 if (cval->cmask & (1 << c)) {
781 err = get_cur_mix_value(cval, c + 1, &val);
782 if (err < 0) {
783 if (cval->mixer->ignore_ctl_error) {
784 ucontrol->value.integer.value[0] = cval->min;
785 return 0;
787 snd_printd(KERN_ERR "cannot get current value for control %d ch %d: err = %d\n", cval->control, c + 1, err);
788 return err;
790 val = get_relative_value(cval, val);
791 ucontrol->value.integer.value[cnt] = val;
792 cnt++;
795 } else {
796 /* master channel */
797 err = get_cur_mix_value(cval, 0, &val);
798 if (err < 0) {
799 if (cval->mixer->ignore_ctl_error) {
800 ucontrol->value.integer.value[0] = cval->min;
801 return 0;
803 snd_printd(KERN_ERR "cannot get current value for control %d master ch: err = %d\n", cval->control, err);
804 return err;
806 val = get_relative_value(cval, val);
807 ucontrol->value.integer.value[0] = val;
809 return 0;
812 /* put the current value to feature/mixer unit */
813 static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
815 struct usb_mixer_elem_info *cval = kcontrol->private_data;
816 int c, cnt, val, oval, err;
817 int changed = 0;
819 if (cval->cmask) {
820 cnt = 0;
821 for (c = 0; c < MAX_CHANNELS; c++) {
822 if (cval->cmask & (1 << c)) {
823 err = get_cur_mix_value(cval, c + 1, &oval);
824 if (err < 0) {
825 if (cval->mixer->ignore_ctl_error)
826 return 0;
827 return err;
829 val = ucontrol->value.integer.value[cnt];
830 val = get_abs_value(cval, val);
831 if (oval != val) {
832 set_cur_mix_value(cval, c + 1, val);
833 changed = 1;
835 get_cur_mix_value(cval, c + 1, &val);
836 cnt++;
839 } else {
840 /* master channel */
841 err = get_cur_mix_value(cval, 0, &oval);
842 if (err < 0 && cval->mixer->ignore_ctl_error)
843 return 0;
844 if (err < 0)
845 return err;
846 val = ucontrol->value.integer.value[0];
847 val = get_abs_value(cval, val);
848 if (val != oval) {
849 set_cur_mix_value(cval, 0, val);
850 changed = 1;
853 return changed;
856 static struct snd_kcontrol_new usb_feature_unit_ctl = {
857 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
858 .name = "", /* will be filled later manually */
859 .info = mixer_ctl_feature_info,
860 .get = mixer_ctl_feature_get,
861 .put = mixer_ctl_feature_put,
866 * build a feature control
869 static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
870 unsigned int ctl_mask, int control,
871 struct usb_audio_term *iterm, int unitid)
873 unsigned int len = 0;
874 int mapped_name = 0;
875 int nameid = desc[desc[0] - 1];
876 struct snd_kcontrol *kctl;
877 struct usb_mixer_elem_info *cval;
879 control++; /* change from zero-based to 1-based value */
881 if (control == USB_FEATURE_GEQ) {
882 /* FIXME: not supported yet */
883 return;
886 if (check_ignored_ctl(state, unitid, control))
887 return;
889 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
890 if (! cval) {
891 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
892 return;
894 cval->mixer = state->mixer;
895 cval->id = unitid;
896 cval->control = control;
897 cval->cmask = ctl_mask;
898 cval->val_type = audio_feature_info[control-1].type;
899 if (ctl_mask == 0)
900 cval->channels = 1; /* master channel */
901 else {
902 int i, c = 0;
903 for (i = 0; i < 16; i++)
904 if (ctl_mask & (1 << i))
905 c++;
906 cval->channels = c;
909 /* get min/max values */
910 get_min_max(cval, 0);
912 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
913 if (! kctl) {
914 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
915 kfree(cval);
916 return;
918 kctl->private_free = usb_mixer_elem_free;
920 len = check_mapped_name(state, unitid, control, kctl->id.name, sizeof(kctl->id.name));
921 mapped_name = len != 0;
922 if (! len && nameid)
923 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
925 switch (control) {
926 case USB_FEATURE_MUTE:
927 case USB_FEATURE_VOLUME:
928 /* determine the control name. the rule is:
929 * - if a name id is given in descriptor, use it.
930 * - if the connected input can be determined, then use the name
931 * of terminal type.
932 * - if the connected output can be determined, use it.
933 * - otherwise, anonymous name.
935 if (! len) {
936 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 1);
937 if (! len)
938 len = get_term_name(state, &state->oterm, kctl->id.name, sizeof(kctl->id.name), 1);
939 if (! len)
940 len = snprintf(kctl->id.name, sizeof(kctl->id.name),
941 "Feature %d", unitid);
943 /* determine the stream direction:
944 * if the connected output is USB stream, then it's likely a
945 * capture stream. otherwise it should be playback (hopefully :)
947 if (! mapped_name && ! (state->oterm.type >> 16)) {
948 if ((state->oterm.type & 0xff00) == 0x0100) {
949 len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name));
950 } else {
951 len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name));
954 strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume",
955 sizeof(kctl->id.name));
956 if (control == USB_FEATURE_VOLUME) {
957 kctl->tlv.c = mixer_vol_tlv;
958 kctl->vd[0].access |=
959 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
960 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
962 break;
964 default:
965 if (! len)
966 strlcpy(kctl->id.name, audio_feature_info[control-1].name,
967 sizeof(kctl->id.name));
968 break;
971 /* quirk for UDA1321/N101 */
972 /* note that detection between firmware 2.1.1.7 (N101) and later 2.1.1.21 */
973 /* is not very clear from datasheets */
974 /* I hope that the min value is -15360 for newer firmware --jk */
975 switch (state->chip->usb_id) {
976 case USB_ID(0x0471, 0x0101):
977 case USB_ID(0x0471, 0x0104):
978 case USB_ID(0x0471, 0x0105):
979 case USB_ID(0x0672, 0x1041):
980 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
981 cval->min == -15616) {
982 snd_printk(KERN_INFO "using volume control quirk for the UDA1321/N101 chip\n");
983 cval->max = -256;
987 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
988 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res);
989 add_control_to_empty(state, kctl);
995 * parse a feature unit
997 * most of controlls are defined here.
999 static int parse_audio_feature_unit(struct mixer_build *state, int unitid, unsigned char *ftr)
1001 int channels, i, j;
1002 struct usb_audio_term iterm;
1003 unsigned int master_bits, first_ch_bits;
1004 int err, csize;
1006 if (ftr[0] < 7 || ! (csize = ftr[5]) || ftr[0] < 7 + csize) {
1007 snd_printk(KERN_ERR "usbaudio: unit %u: invalid FEATURE_UNIT descriptor\n", unitid);
1008 return -EINVAL;
1011 /* parse the source unit */
1012 if ((err = parse_audio_unit(state, ftr[4])) < 0)
1013 return err;
1015 /* determine the input source type and name */
1016 if (check_input_term(state, ftr[4], &iterm) < 0)
1017 return -EINVAL;
1019 channels = (ftr[0] - 7) / csize - 1;
1021 master_bits = snd_usb_combine_bytes(ftr + 6, csize);
1022 if (channels > 0)
1023 first_ch_bits = snd_usb_combine_bytes(ftr + 6 + csize, csize);
1024 else
1025 first_ch_bits = 0;
1026 /* check all control types */
1027 for (i = 0; i < 10; i++) {
1028 unsigned int ch_bits = 0;
1029 for (j = 0; j < channels; j++) {
1030 unsigned int mask = snd_usb_combine_bytes(ftr + 6 + csize * (j+1), csize);
1031 if (mask & (1 << i))
1032 ch_bits |= (1 << j);
1034 if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
1035 build_feature_ctl(state, ftr, ch_bits, i, &iterm, unitid);
1036 if (master_bits & (1 << i))
1037 build_feature_ctl(state, ftr, 0, i, &iterm, unitid);
1040 return 0;
1045 * Mixer Unit
1049 * build a mixer unit control
1051 * the callbacks are identical with feature unit.
1052 * input channel number (zero based) is given in control field instead.
1055 static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1056 int in_pin, int in_ch, int unitid,
1057 struct usb_audio_term *iterm)
1059 struct usb_mixer_elem_info *cval;
1060 unsigned int input_pins = desc[4];
1061 unsigned int num_outs = desc[5 + input_pins];
1062 unsigned int i, len;
1063 struct snd_kcontrol *kctl;
1065 if (check_ignored_ctl(state, unitid, 0))
1066 return;
1068 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1069 if (! cval)
1070 return;
1072 cval->mixer = state->mixer;
1073 cval->id = unitid;
1074 cval->control = in_ch + 1; /* based on 1 */
1075 cval->val_type = USB_MIXER_S16;
1076 for (i = 0; i < num_outs; i++) {
1077 if (check_matrix_bitmap(desc + 9 + input_pins, in_ch, i, num_outs)) {
1078 cval->cmask |= (1 << i);
1079 cval->channels++;
1083 /* get min/max values */
1084 get_min_max(cval, 0);
1086 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
1087 if (! kctl) {
1088 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1089 kfree(cval);
1090 return;
1092 kctl->private_free = usb_mixer_elem_free;
1094 len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name));
1095 if (! len)
1096 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
1097 if (! len)
1098 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
1099 strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name));
1101 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
1102 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1103 add_control_to_empty(state, kctl);
1108 * parse a mixer unit
1110 static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1112 struct usb_audio_term iterm;
1113 int input_pins, num_ins, num_outs;
1114 int pin, ich, err;
1116 if (desc[0] < 11 || ! (input_pins = desc[4]) || ! (num_outs = desc[5 + input_pins])) {
1117 snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid);
1118 return -EINVAL;
1120 /* no bmControls field (e.g. Maya44) -> ignore */
1121 if (desc[0] <= 10 + input_pins) {
1122 snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid);
1123 return 0;
1126 num_ins = 0;
1127 ich = 0;
1128 for (pin = 0; pin < input_pins; pin++) {
1129 err = parse_audio_unit(state, desc[5 + pin]);
1130 if (err < 0)
1131 return err;
1132 err = check_input_term(state, desc[5 + pin], &iterm);
1133 if (err < 0)
1134 return err;
1135 num_ins += iterm.channels;
1136 for (; ich < num_ins; ++ich) {
1137 int och, ich_has_controls = 0;
1139 for (och = 0; och < num_outs; ++och) {
1140 if (check_matrix_bitmap(desc + 9 + input_pins,
1141 ich, och, num_outs)) {
1142 ich_has_controls = 1;
1143 break;
1146 if (ich_has_controls)
1147 build_mixer_unit_ctl(state, desc, pin, ich,
1148 unitid, &iterm);
1151 return 0;
1156 * Processing Unit / Extension Unit
1159 /* get callback for processing/extension unit */
1160 static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1162 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1163 int err, val;
1165 err = get_cur_ctl_value(cval, cval->control << 8, &val);
1166 if (err < 0 && cval->mixer->ignore_ctl_error) {
1167 ucontrol->value.integer.value[0] = cval->min;
1168 return 0;
1170 if (err < 0)
1171 return err;
1172 val = get_relative_value(cval, val);
1173 ucontrol->value.integer.value[0] = val;
1174 return 0;
1177 /* put callback for processing/extension unit */
1178 static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1180 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1181 int val, oval, err;
1183 err = get_cur_ctl_value(cval, cval->control << 8, &oval);
1184 if (err < 0) {
1185 if (cval->mixer->ignore_ctl_error)
1186 return 0;
1187 return err;
1189 val = ucontrol->value.integer.value[0];
1190 val = get_abs_value(cval, val);
1191 if (val != oval) {
1192 set_cur_ctl_value(cval, cval->control << 8, val);
1193 return 1;
1195 return 0;
1198 /* alsa control interface for processing/extension unit */
1199 static struct snd_kcontrol_new mixer_procunit_ctl = {
1200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1201 .name = "", /* will be filled later */
1202 .info = mixer_ctl_feature_info,
1203 .get = mixer_ctl_procunit_get,
1204 .put = mixer_ctl_procunit_put,
1209 * predefined data for processing units
1211 struct procunit_value_info {
1212 int control;
1213 char *suffix;
1214 int val_type;
1215 int min_value;
1218 struct procunit_info {
1219 int type;
1220 char *name;
1221 struct procunit_value_info *values;
1224 static struct procunit_value_info updown_proc_info[] = {
1225 { USB_PROC_UPDOWN_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1226 { USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
1227 { 0 }
1229 static struct procunit_value_info prologic_proc_info[] = {
1230 { USB_PROC_PROLOGIC_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1231 { USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
1232 { 0 }
1234 static struct procunit_value_info threed_enh_proc_info[] = {
1235 { USB_PROC_3DENH_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1236 { USB_PROC_3DENH_SPACE, "Spaciousness", USB_MIXER_U8 },
1237 { 0 }
1239 static struct procunit_value_info reverb_proc_info[] = {
1240 { USB_PROC_REVERB_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1241 { USB_PROC_REVERB_LEVEL, "Level", USB_MIXER_U8 },
1242 { USB_PROC_REVERB_TIME, "Time", USB_MIXER_U16 },
1243 { USB_PROC_REVERB_DELAY, "Delay", USB_MIXER_U8 },
1244 { 0 }
1246 static struct procunit_value_info chorus_proc_info[] = {
1247 { USB_PROC_CHORUS_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1248 { USB_PROC_CHORUS_LEVEL, "Level", USB_MIXER_U8 },
1249 { USB_PROC_CHORUS_RATE, "Rate", USB_MIXER_U16 },
1250 { USB_PROC_CHORUS_DEPTH, "Depth", USB_MIXER_U16 },
1251 { 0 }
1253 static struct procunit_value_info dcr_proc_info[] = {
1254 { USB_PROC_DCR_SWITCH, "Switch", USB_MIXER_BOOLEAN },
1255 { USB_PROC_DCR_RATIO, "Ratio", USB_MIXER_U16 },
1256 { USB_PROC_DCR_MAX_AMP, "Max Amp", USB_MIXER_S16 },
1257 { USB_PROC_DCR_THRESHOLD, "Threshold", USB_MIXER_S16 },
1258 { USB_PROC_DCR_ATTACK, "Attack Time", USB_MIXER_U16 },
1259 { USB_PROC_DCR_RELEASE, "Release Time", USB_MIXER_U16 },
1260 { 0 }
1263 static struct procunit_info procunits[] = {
1264 { USB_PROC_UPDOWN, "Up Down", updown_proc_info },
1265 { USB_PROC_PROLOGIC, "Dolby Prologic", prologic_proc_info },
1266 { USB_PROC_3DENH, "3D Stereo Extender", threed_enh_proc_info },
1267 { USB_PROC_REVERB, "Reverb", reverb_proc_info },
1268 { USB_PROC_CHORUS, "Chorus", chorus_proc_info },
1269 { USB_PROC_DCR, "DCR", dcr_proc_info },
1270 { 0 },
1274 * build a processing/extension unit
1276 static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned char *dsc, struct procunit_info *list, char *name)
1278 int num_ins = dsc[6];
1279 struct usb_mixer_elem_info *cval;
1280 struct snd_kcontrol *kctl;
1281 int i, err, nameid, type, len;
1282 struct procunit_info *info;
1283 struct procunit_value_info *valinfo;
1284 static struct procunit_value_info default_value_info[] = {
1285 { 0x01, "Switch", USB_MIXER_BOOLEAN },
1286 { 0 }
1288 static struct procunit_info default_info = {
1289 0, NULL, default_value_info
1292 if (dsc[0] < 13 || dsc[0] < 13 + num_ins || dsc[0] < num_ins + dsc[11 + num_ins]) {
1293 snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid);
1294 return -EINVAL;
1297 for (i = 0; i < num_ins; i++) {
1298 if ((err = parse_audio_unit(state, dsc[7 + i])) < 0)
1299 return err;
1302 type = combine_word(&dsc[4]);
1303 for (info = list; info && info->type; info++)
1304 if (info->type == type)
1305 break;
1306 if (! info || ! info->type)
1307 info = &default_info;
1309 for (valinfo = info->values; valinfo->control; valinfo++) {
1310 /* FIXME: bitmap might be longer than 8bit */
1311 if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1))))
1312 continue;
1313 if (check_ignored_ctl(state, unitid, valinfo->control))
1314 continue;
1315 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1316 if (! cval) {
1317 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1318 return -ENOMEM;
1320 cval->mixer = state->mixer;
1321 cval->id = unitid;
1322 cval->control = valinfo->control;
1323 cval->val_type = valinfo->val_type;
1324 cval->channels = 1;
1326 /* get min/max values */
1327 if (type == USB_PROC_UPDOWN && cval->control == USB_PROC_UPDOWN_MODE_SEL) {
1328 /* FIXME: hard-coded */
1329 cval->min = 1;
1330 cval->max = dsc[15];
1331 cval->res = 1;
1332 cval->initialized = 1;
1333 } else
1334 get_min_max(cval, valinfo->min_value);
1336 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
1337 if (! kctl) {
1338 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1339 kfree(cval);
1340 return -ENOMEM;
1342 kctl->private_free = usb_mixer_elem_free;
1344 if (check_mapped_name(state, unitid, cval->control, kctl->id.name, sizeof(kctl->id.name)))
1346 else if (info->name)
1347 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
1348 else {
1349 nameid = dsc[12 + num_ins + dsc[11 + num_ins]];
1350 len = 0;
1351 if (nameid)
1352 len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
1353 if (! len)
1354 strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
1356 strlcat(kctl->id.name, " ", sizeof(kctl->id.name));
1357 strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name));
1359 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
1360 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1361 if ((err = add_control_to_empty(state, kctl)) < 0)
1362 return err;
1364 return 0;
1368 static int parse_audio_processing_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1370 return build_audio_procunit(state, unitid, desc, procunits, "Processing Unit");
1373 static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1375 return build_audio_procunit(state, unitid, desc, NULL, "Extension Unit");
1380 * Selector Unit
1383 /* info callback for selector unit
1384 * use an enumerator type for routing
1386 static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1388 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1389 char **itemlist = (char **)kcontrol->private_value;
1391 snd_assert(itemlist, return -EINVAL);
1392 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1393 uinfo->count = 1;
1394 uinfo->value.enumerated.items = cval->max;
1395 if ((int)uinfo->value.enumerated.item >= cval->max)
1396 uinfo->value.enumerated.item = cval->max - 1;
1397 strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]);
1398 return 0;
1401 /* get callback for selector unit */
1402 static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1404 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1405 int val, err;
1407 err = get_cur_ctl_value(cval, 0, &val);
1408 if (err < 0) {
1409 if (cval->mixer->ignore_ctl_error) {
1410 ucontrol->value.enumerated.item[0] = 0;
1411 return 0;
1413 return err;
1415 val = get_relative_value(cval, val);
1416 ucontrol->value.enumerated.item[0] = val;
1417 return 0;
1420 /* put callback for selector unit */
1421 static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1423 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1424 int val, oval, err;
1426 err = get_cur_ctl_value(cval, 0, &oval);
1427 if (err < 0) {
1428 if (cval->mixer->ignore_ctl_error)
1429 return 0;
1430 return err;
1432 val = ucontrol->value.enumerated.item[0];
1433 val = get_abs_value(cval, val);
1434 if (val != oval) {
1435 set_cur_ctl_value(cval, 0, val);
1436 return 1;
1438 return 0;
1441 /* alsa control interface for selector unit */
1442 static struct snd_kcontrol_new mixer_selectunit_ctl = {
1443 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1444 .name = "", /* will be filled later */
1445 .info = mixer_ctl_selector_info,
1446 .get = mixer_ctl_selector_get,
1447 .put = mixer_ctl_selector_put,
1451 /* private free callback.
1452 * free both private_data and private_value
1454 static void usb_mixer_selector_elem_free(struct snd_kcontrol *kctl)
1456 int i, num_ins = 0;
1458 if (kctl->private_data) {
1459 struct usb_mixer_elem_info *cval = kctl->private_data;
1460 num_ins = cval->max;
1461 kfree(cval);
1462 kctl->private_data = NULL;
1464 if (kctl->private_value) {
1465 char **itemlist = (char **)kctl->private_value;
1466 for (i = 0; i < num_ins; i++)
1467 kfree(itemlist[i]);
1468 kfree(itemlist);
1469 kctl->private_value = 0;
1474 * parse a selector unit
1476 static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsigned char *desc)
1478 unsigned int num_ins = desc[4];
1479 unsigned int i, nameid, len;
1480 int err;
1481 struct usb_mixer_elem_info *cval;
1482 struct snd_kcontrol *kctl;
1483 char **namelist;
1485 if (! num_ins || desc[0] < 5 + num_ins) {
1486 snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid);
1487 return -EINVAL;
1490 for (i = 0; i < num_ins; i++) {
1491 if ((err = parse_audio_unit(state, desc[5 + i])) < 0)
1492 return err;
1495 if (num_ins == 1) /* only one ? nonsense! */
1496 return 0;
1498 if (check_ignored_ctl(state, unitid, 0))
1499 return 0;
1501 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1502 if (! cval) {
1503 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1504 return -ENOMEM;
1506 cval->mixer = state->mixer;
1507 cval->id = unitid;
1508 cval->val_type = USB_MIXER_U8;
1509 cval->channels = 1;
1510 cval->min = 1;
1511 cval->max = num_ins;
1512 cval->res = 1;
1513 cval->initialized = 1;
1515 namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL);
1516 if (! namelist) {
1517 snd_printk(KERN_ERR "cannot malloc\n");
1518 kfree(cval);
1519 return -ENOMEM;
1521 #define MAX_ITEM_NAME_LEN 64
1522 for (i = 0; i < num_ins; i++) {
1523 struct usb_audio_term iterm;
1524 len = 0;
1525 namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL);
1526 if (! namelist[i]) {
1527 snd_printk(KERN_ERR "cannot malloc\n");
1528 while (i--)
1529 kfree(namelist[i]);
1530 kfree(namelist);
1531 kfree(cval);
1532 return -ENOMEM;
1534 len = check_mapped_selector_name(state, unitid, i, namelist[i],
1535 MAX_ITEM_NAME_LEN);
1536 if (! len && check_input_term(state, desc[5 + i], &iterm) >= 0)
1537 len = get_term_name(state, &iterm, namelist[i], MAX_ITEM_NAME_LEN, 0);
1538 if (! len)
1539 sprintf(namelist[i], "Input %d", i);
1542 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
1543 if (! kctl) {
1544 snd_printk(KERN_ERR "cannot malloc kcontrol\n");
1545 kfree(namelist);
1546 kfree(cval);
1547 return -ENOMEM;
1549 kctl->private_value = (unsigned long)namelist;
1550 kctl->private_free = usb_mixer_selector_elem_free;
1552 nameid = desc[desc[0] - 1];
1553 len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name));
1554 if (len)
1556 else if (nameid)
1557 snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
1558 else {
1559 len = get_term_name(state, &state->oterm,
1560 kctl->id.name, sizeof(kctl->id.name), 0);
1561 if (! len)
1562 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
1564 if ((state->oterm.type & 0xff00) == 0x0100)
1565 strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name));
1566 else
1567 strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name));
1570 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
1571 cval->id, kctl->id.name, num_ins);
1572 if ((err = add_control_to_empty(state, kctl)) < 0)
1573 return err;
1575 return 0;
1580 * parse an audio unit recursively
1583 static int parse_audio_unit(struct mixer_build *state, int unitid)
1585 unsigned char *p1;
1587 if (test_and_set_bit(unitid, state->unitbitmap))
1588 return 0; /* the unit already visited */
1590 p1 = find_audio_control_unit(state, unitid);
1591 if (!p1) {
1592 snd_printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid);
1593 return -EINVAL;
1596 switch (p1[2]) {
1597 case INPUT_TERMINAL:
1598 return 0; /* NOP */
1599 case MIXER_UNIT:
1600 return parse_audio_mixer_unit(state, unitid, p1);
1601 case SELECTOR_UNIT:
1602 return parse_audio_selector_unit(state, unitid, p1);
1603 case FEATURE_UNIT:
1604 return parse_audio_feature_unit(state, unitid, p1);
1605 case PROCESSING_UNIT:
1606 return parse_audio_processing_unit(state, unitid, p1);
1607 case EXTENSION_UNIT:
1608 return parse_audio_extension_unit(state, unitid, p1);
1609 default:
1610 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
1611 return -EINVAL;
1615 static void snd_usb_mixer_free(struct usb_mixer_interface *mixer)
1617 kfree(mixer->id_elems);
1618 if (mixer->urb) {
1619 kfree(mixer->urb->transfer_buffer);
1620 usb_free_urb(mixer->urb);
1622 usb_free_urb(mixer->rc_urb);
1623 kfree(mixer->rc_setup_packet);
1624 kfree(mixer);
1627 static int snd_usb_mixer_dev_free(struct snd_device *device)
1629 struct usb_mixer_interface *mixer = device->device_data;
1630 snd_usb_mixer_free(mixer);
1631 return 0;
1635 * create mixer controls
1637 * walk through all OUTPUT_TERMINAL descriptors to search for mixers
1639 static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1641 unsigned char *desc;
1642 struct mixer_build state;
1643 int err;
1644 const struct usbmix_ctl_map *map;
1645 struct usb_host_interface *hostif;
1647 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0];
1648 memset(&state, 0, sizeof(state));
1649 state.chip = mixer->chip;
1650 state.mixer = mixer;
1651 state.buffer = hostif->extra;
1652 state.buflen = hostif->extralen;
1654 /* check the mapping table */
1655 for (map = usbmix_ctl_maps; map->id; map++) {
1656 if (map->id == state.chip->usb_id) {
1657 state.map = map->map;
1658 state.selector_map = map->selector_map;
1659 mixer->ignore_ctl_error = map->ignore_ctl_error;
1660 break;
1664 desc = NULL;
1665 while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, OUTPUT_TERMINAL)) != NULL) {
1666 if (desc[0] < 9)
1667 continue; /* invalid descriptor? */
1668 set_bit(desc[3], state.unitbitmap); /* mark terminal ID as visited */
1669 state.oterm.id = desc[3];
1670 state.oterm.type = combine_word(&desc[4]);
1671 state.oterm.name = desc[8];
1672 err = parse_audio_unit(&state, desc[7]);
1673 if (err < 0)
1674 return err;
1676 return 0;
1679 static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer,
1680 int unitid)
1682 struct usb_mixer_elem_info *info;
1684 for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem)
1685 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1686 info->elem_id);
1689 static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
1690 int unitid)
1692 if (!mixer->rc_cfg)
1693 return;
1694 /* unit ids specific to Extigy/Audigy 2 NX: */
1695 switch (unitid) {
1696 case 0: /* remote control */
1697 mixer->rc_urb->dev = mixer->chip->dev;
1698 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1699 break;
1700 case 4: /* digital in jack */
1701 case 7: /* line in jacks */
1702 case 19: /* speaker out jacks */
1703 case 20: /* headphones out jack */
1704 break;
1705 /* live24ext: 4 = line-in jack */
1706 case 3: /* hp-out jack (may actuate Mute) */
1707 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
1708 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1709 break;
1710 default:
1711 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1712 break;
1716 static void snd_usb_mixer_status_complete(struct urb *urb)
1718 struct usb_mixer_interface *mixer = urb->context;
1720 if (urb->status == 0) {
1721 u8 *buf = urb->transfer_buffer;
1722 int i;
1724 for (i = urb->actual_length; i >= 2; buf += 2, i -= 2) {
1725 snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n",
1726 buf[0], buf[1]);
1727 /* ignore any notifications not from the control interface */
1728 if ((buf[0] & 0x0f) != 0)
1729 continue;
1730 if (!(buf[0] & 0x40))
1731 snd_usb_mixer_notify_id(mixer, buf[1]);
1732 else
1733 snd_usb_mixer_memory_change(mixer, buf[1]);
1736 if (urb->status != -ENOENT && urb->status != -ECONNRESET) {
1737 urb->dev = mixer->chip->dev;
1738 usb_submit_urb(urb, GFP_ATOMIC);
1742 /* create the handler for the optional status interrupt endpoint */
1743 static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
1745 struct usb_host_interface *hostif;
1746 struct usb_endpoint_descriptor *ep;
1747 void *transfer_buffer;
1748 int buffer_length;
1749 unsigned int epnum;
1751 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0];
1752 /* we need one interrupt input endpoint */
1753 if (get_iface_desc(hostif)->bNumEndpoints < 1)
1754 return 0;
1755 ep = get_endpoint(hostif, 0);
1756 if ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN ||
1757 (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
1758 return 0;
1760 epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
1761 buffer_length = le16_to_cpu(ep->wMaxPacketSize);
1762 transfer_buffer = kmalloc(buffer_length, GFP_KERNEL);
1763 if (!transfer_buffer)
1764 return -ENOMEM;
1765 mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
1766 if (!mixer->urb) {
1767 kfree(transfer_buffer);
1768 return -ENOMEM;
1770 usb_fill_int_urb(mixer->urb, mixer->chip->dev,
1771 usb_rcvintpipe(mixer->chip->dev, epnum),
1772 transfer_buffer, buffer_length,
1773 snd_usb_mixer_status_complete, mixer, ep->bInterval);
1774 usb_submit_urb(mixer->urb, GFP_KERNEL);
1775 return 0;
1778 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
1780 struct usb_mixer_interface *mixer = urb->context;
1781 const struct rc_config *rc = mixer->rc_cfg;
1782 u32 code;
1784 if (urb->status < 0 || urb->actual_length < rc->packet_length)
1785 return;
1787 code = mixer->rc_buffer[rc->offset];
1788 if (rc->length == 2)
1789 code |= mixer->rc_buffer[rc->offset + 1] << 8;
1791 /* the Mute button actually changes the mixer control */
1792 if (code == rc->mute_code)
1793 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
1794 mixer->rc_code = code;
1795 wmb();
1796 wake_up(&mixer->rc_waitq);
1799 static int snd_usb_sbrc_hwdep_open(struct snd_hwdep *hw, struct file *file)
1801 struct usb_mixer_interface *mixer = hw->private_data;
1803 if (test_and_set_bit(0, &mixer->rc_hwdep_open))
1804 return -EBUSY;
1805 return 0;
1808 static int snd_usb_sbrc_hwdep_release(struct snd_hwdep *hw, struct file *file)
1810 struct usb_mixer_interface *mixer = hw->private_data;
1812 clear_bit(0, &mixer->rc_hwdep_open);
1813 smp_mb__after_clear_bit();
1814 return 0;
1817 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
1818 long count, loff_t *offset)
1820 struct usb_mixer_interface *mixer = hw->private_data;
1821 int err;
1822 u32 rc_code;
1824 if (count != 1 && count != 4)
1825 return -EINVAL;
1826 err = wait_event_interruptible(mixer->rc_waitq,
1827 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
1828 if (err == 0) {
1829 if (count == 1)
1830 err = put_user(rc_code, buf);
1831 else
1832 err = put_user(rc_code, (u32 __user *)buf);
1834 return err < 0 ? err : count;
1837 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
1838 poll_table *wait)
1840 struct usb_mixer_interface *mixer = hw->private_data;
1842 poll_wait(file, &mixer->rc_waitq, wait);
1843 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
1846 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
1848 struct snd_hwdep *hwdep;
1849 int err, len, i;
1851 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
1852 if (rc_configs[i].usb_id == mixer->chip->usb_id)
1853 break;
1854 if (i >= ARRAY_SIZE(rc_configs))
1855 return 0;
1856 mixer->rc_cfg = &rc_configs[i];
1858 len = mixer->rc_cfg->packet_length;
1860 init_waitqueue_head(&mixer->rc_waitq);
1861 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
1862 if (err < 0)
1863 return err;
1864 snprintf(hwdep->name, sizeof(hwdep->name),
1865 "%s remote control", mixer->chip->card->shortname);
1866 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
1867 hwdep->private_data = mixer;
1868 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
1869 hwdep->ops.open = snd_usb_sbrc_hwdep_open;
1870 hwdep->ops.release = snd_usb_sbrc_hwdep_release;
1871 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
1873 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
1874 if (!mixer->rc_urb)
1875 return -ENOMEM;
1876 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
1877 if (!mixer->rc_setup_packet) {
1878 usb_free_urb(mixer->rc_urb);
1879 mixer->rc_urb = NULL;
1880 return -ENOMEM;
1882 mixer->rc_setup_packet->bRequestType =
1883 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
1884 mixer->rc_setup_packet->bRequest = GET_MEM;
1885 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
1886 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
1887 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
1888 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
1889 usb_rcvctrlpipe(mixer->chip->dev, 0),
1890 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
1891 snd_usb_soundblaster_remote_complete, mixer);
1892 return 0;
1895 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
1897 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1899 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
1900 int index = kcontrol->private_value;
1902 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
1903 return 0;
1906 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1908 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
1909 int index = kcontrol->private_value;
1910 int value = ucontrol->value.integer.value[0];
1911 int err, changed;
1913 if (value > 1)
1914 return -EINVAL;
1915 changed = value != mixer->audigy2nx_leds[index];
1916 err = snd_usb_ctl_msg(mixer->chip->dev,
1917 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
1918 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1919 value, index + 2, NULL, 0, 100);
1920 if (err < 0)
1921 return err;
1922 mixer->audigy2nx_leds[index] = value;
1923 return changed;
1926 static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
1928 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1929 .name = "CMSS LED Switch",
1930 .info = snd_audigy2nx_led_info,
1931 .get = snd_audigy2nx_led_get,
1932 .put = snd_audigy2nx_led_put,
1933 .private_value = 0,
1936 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1937 .name = "Power LED Switch",
1938 .info = snd_audigy2nx_led_info,
1939 .get = snd_audigy2nx_led_get,
1940 .put = snd_audigy2nx_led_put,
1941 .private_value = 1,
1944 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1945 .name = "Dolby Digital LED Switch",
1946 .info = snd_audigy2nx_led_info,
1947 .get = snd_audigy2nx_led_get,
1948 .put = snd_audigy2nx_led_put,
1949 .private_value = 2,
1953 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
1955 int i, err;
1957 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
1958 if (i > 1 && /* Live24ext has 2 LEDs only */
1959 mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
1960 break;
1961 err = snd_ctl_add(mixer->chip->card,
1962 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
1963 if (err < 0)
1964 return err;
1966 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
1967 return 0;
1970 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
1971 struct snd_info_buffer *buffer)
1973 static const struct sb_jack {
1974 int unitid;
1975 const char *name;
1976 } jacks_audigy2nx[] = {
1977 {4, "dig in "},
1978 {7, "line in"},
1979 {19, "spk out"},
1980 {20, "hph out"},
1981 {-1, NULL}
1982 }, jacks_live24ext[] = {
1983 {4, "line in"}, /* &1=Line, &2=Mic*/
1984 {3, "hph out"}, /* headphones */
1985 {0, "RC "}, /* last command, 6 bytes see rc_config above */
1986 {-1, NULL}
1988 const struct sb_jack *jacks;
1989 struct usb_mixer_interface *mixer = entry->private_data;
1990 int i, err;
1991 u8 buf[3];
1993 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
1994 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
1995 jacks = jacks_audigy2nx;
1996 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
1997 jacks = jacks_live24ext;
1998 else
1999 return;
2001 for (i = 0; jacks[i].name; ++i) {
2002 snd_iprintf(buffer, "%s: ", jacks[i].name);
2003 err = snd_usb_ctl_msg(mixer->chip->dev,
2004 usb_rcvctrlpipe(mixer->chip->dev, 0),
2005 GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
2006 USB_RECIP_INTERFACE, 0,
2007 jacks[i].unitid << 8, buf, 3, 100);
2008 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
2009 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
2010 else
2011 snd_iprintf(buffer, "?\n");
2015 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif)
2017 static struct snd_device_ops dev_ops = {
2018 .dev_free = snd_usb_mixer_dev_free
2020 struct usb_mixer_interface *mixer;
2021 int err;
2023 strcpy(chip->card->mixername, "USB Mixer");
2025 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
2026 if (!mixer)
2027 return -ENOMEM;
2028 mixer->chip = chip;
2029 mixer->ctrlif = ctrlif;
2030 #ifdef IGNORE_CTL_ERROR
2031 mixer->ignore_ctl_error = 1;
2032 #endif
2033 mixer->id_elems = kcalloc(256, sizeof(*mixer->id_elems), GFP_KERNEL);
2034 if (!mixer->id_elems) {
2035 kfree(mixer);
2036 return -ENOMEM;
2039 if ((err = snd_usb_mixer_controls(mixer)) < 0 ||
2040 (err = snd_usb_mixer_status_create(mixer)) < 0)
2041 goto _error;
2043 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
2044 goto _error;
2046 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
2047 mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) {
2048 struct snd_info_entry *entry;
2050 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
2051 goto _error;
2052 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry))
2053 snd_info_set_text_ops(entry, mixer,
2054 snd_audigy2nx_proc_read);
2057 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
2058 if (err < 0)
2059 goto _error;
2060 list_add(&mixer->list, &chip->mixer_list);
2061 return 0;
2063 _error:
2064 snd_usb_mixer_free(mixer);
2065 return err;
2068 void snd_usb_mixer_disconnect(struct list_head *p)
2070 struct usb_mixer_interface *mixer;
2072 mixer = list_entry(p, struct usb_mixer_interface, list);
2073 usb_kill_urb(mixer->urb);
2074 usb_kill_urb(mixer->rc_urb);