xref: /openbmc/linux/sound/usb/mixer_quirks.c (revision f35e839a)
1 /*
2  *   USB Audio Driver for ALSA
3  *
4  *   Quirks and vendor-specific extensions for mixer interfaces
5  *
6  *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7  *
8  *   Many codes borrowed from audio.c by
9  *	    Alan Cox (alan@lxorguk.ukuu.org.uk)
10  *	    Thomas Sailer (sailer@ife.ee.ethz.ch)
11  *
12  *
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.
17  *
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.
22  *
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
26  */
27 
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/usb.h>
31 #include <linux/usb/audio.h>
32 
33 #include <sound/core.h>
34 #include <sound/control.h>
35 #include <sound/hwdep.h>
36 #include <sound/info.h>
37 
38 #include "usbaudio.h"
39 #include "mixer.h"
40 #include "mixer_quirks.h"
41 #include "helper.h"
42 
43 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
44 
45 struct std_mono_table {
46 	unsigned int unitid, control, cmask;
47 	int val_type;
48 	const char *name;
49 	snd_kcontrol_tlv_rw_t *tlv_callback;
50 };
51 
52 /* private_free callback */
53 static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
54 {
55 	kfree(kctl->private_data);
56 	kctl->private_data = NULL;
57 }
58 
59 /* This function allows for the creation of standard UAC controls.
60  * See the quirks for M-Audio FTUs or Ebox-44.
61  * If you don't want to set a TLV callback pass NULL.
62  *
63  * Since there doesn't seem to be a devices that needs a multichannel
64  * version, we keep it mono for simplicity.
65  */
66 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
67 				unsigned int unitid,
68 				unsigned int control,
69 				unsigned int cmask,
70 				int val_type,
71 				unsigned int idx_off,
72 				const char *name,
73 				snd_kcontrol_tlv_rw_t *tlv_callback)
74 {
75 	int err;
76 	struct usb_mixer_elem_info *cval;
77 	struct snd_kcontrol *kctl;
78 
79 	cval = kzalloc(sizeof(*cval), GFP_KERNEL);
80 	if (!cval)
81 		return -ENOMEM;
82 
83 	cval->id = unitid;
84 	cval->mixer = mixer;
85 	cval->val_type = val_type;
86 	cval->channels = 1;
87 	cval->control = control;
88 	cval->cmask = cmask;
89 	cval->idx_off = idx_off;
90 
91 	/* get_min_max() is called only for integer volumes later,
92 	 * so provide a short-cut for booleans */
93 	cval->min = 0;
94 	cval->max = 1;
95 	cval->res = 0;
96 	cval->dBmin = 0;
97 	cval->dBmax = 0;
98 
99 	/* Create control */
100 	kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
101 	if (!kctl) {
102 		kfree(cval);
103 		return -ENOMEM;
104 	}
105 
106 	/* Set name */
107 	snprintf(kctl->id.name, sizeof(kctl->id.name), name);
108 	kctl->private_free = usb_mixer_elem_free;
109 
110 	/* set TLV */
111 	if (tlv_callback) {
112 		kctl->tlv.c = tlv_callback;
113 		kctl->vd[0].access |=
114 			SNDRV_CTL_ELEM_ACCESS_TLV_READ |
115 			SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
116 	}
117 	/* Add control to mixer */
118 	err = snd_usb_mixer_add_control(mixer, kctl);
119 	if (err < 0)
120 		return err;
121 
122 	return 0;
123 }
124 
125 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
126 				unsigned int unitid,
127 				unsigned int control,
128 				unsigned int cmask,
129 				int val_type,
130 				const char *name,
131 				snd_kcontrol_tlv_rw_t *tlv_callback)
132 {
133 	return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
134 		val_type, 0 /* Offset */, name, tlv_callback);
135 }
136 
137 /*
138  * Create a set of standard UAC controls from a table
139  */
140 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
141 				struct std_mono_table *t)
142 {
143 	int err;
144 
145 	while (t->name != NULL) {
146 		err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
147 				t->cmask, t->val_type, t->name, t->tlv_callback);
148 		if (err < 0)
149 			return err;
150 		t++;
151 	}
152 
153 	return 0;
154 }
155 
156 /*
157  * Sound Blaster remote control configuration
158  *
159  * format of remote control data:
160  * Extigy:       xx 00
161  * Audigy 2 NX:  06 80 xx 00 00 00
162  * Live! 24-bit: 06 80 xx yy 22 83
163  */
164 static const struct rc_config {
165 	u32 usb_id;
166 	u8  offset;
167 	u8  length;
168 	u8  packet_length;
169 	u8  min_packet_length; /* minimum accepted length of the URB result */
170 	u8  mute_mixer_id;
171 	u32 mute_code;
172 } rc_configs[] = {
173 	{ USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
174 	{ USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
175 	{ USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
176 	{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 */
177 	{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
178 	{ USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
179 };
180 
181 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
182 {
183 	struct usb_mixer_interface *mixer = urb->context;
184 	const struct rc_config *rc = mixer->rc_cfg;
185 	u32 code;
186 
187 	if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
188 		return;
189 
190 	code = mixer->rc_buffer[rc->offset];
191 	if (rc->length == 2)
192 		code |= mixer->rc_buffer[rc->offset + 1] << 8;
193 
194 	/* the Mute button actually changes the mixer control */
195 	if (code == rc->mute_code)
196 		snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
197 	mixer->rc_code = code;
198 	wmb();
199 	wake_up(&mixer->rc_waitq);
200 }
201 
202 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
203 				     long count, loff_t *offset)
204 {
205 	struct usb_mixer_interface *mixer = hw->private_data;
206 	int err;
207 	u32 rc_code;
208 
209 	if (count != 1 && count != 4)
210 		return -EINVAL;
211 	err = wait_event_interruptible(mixer->rc_waitq,
212 				       (rc_code = xchg(&mixer->rc_code, 0)) != 0);
213 	if (err == 0) {
214 		if (count == 1)
215 			err = put_user(rc_code, buf);
216 		else
217 			err = put_user(rc_code, (u32 __user *)buf);
218 	}
219 	return err < 0 ? err : count;
220 }
221 
222 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
223 					    poll_table *wait)
224 {
225 	struct usb_mixer_interface *mixer = hw->private_data;
226 
227 	poll_wait(file, &mixer->rc_waitq, wait);
228 	return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
229 }
230 
231 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
232 {
233 	struct snd_hwdep *hwdep;
234 	int err, len, i;
235 
236 	for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
237 		if (rc_configs[i].usb_id == mixer->chip->usb_id)
238 			break;
239 	if (i >= ARRAY_SIZE(rc_configs))
240 		return 0;
241 	mixer->rc_cfg = &rc_configs[i];
242 
243 	len = mixer->rc_cfg->packet_length;
244 
245 	init_waitqueue_head(&mixer->rc_waitq);
246 	err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
247 	if (err < 0)
248 		return err;
249 	snprintf(hwdep->name, sizeof(hwdep->name),
250 		 "%s remote control", mixer->chip->card->shortname);
251 	hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
252 	hwdep->private_data = mixer;
253 	hwdep->ops.read = snd_usb_sbrc_hwdep_read;
254 	hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
255 	hwdep->exclusive = 1;
256 
257 	mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
258 	if (!mixer->rc_urb)
259 		return -ENOMEM;
260 	mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
261 	if (!mixer->rc_setup_packet) {
262 		usb_free_urb(mixer->rc_urb);
263 		mixer->rc_urb = NULL;
264 		return -ENOMEM;
265 	}
266 	mixer->rc_setup_packet->bRequestType =
267 		USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
268 	mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
269 	mixer->rc_setup_packet->wValue = cpu_to_le16(0);
270 	mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
271 	mixer->rc_setup_packet->wLength = cpu_to_le16(len);
272 	usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
273 			     usb_rcvctrlpipe(mixer->chip->dev, 0),
274 			     (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
275 			     snd_usb_soundblaster_remote_complete, mixer);
276 	return 0;
277 }
278 
279 #define snd_audigy2nx_led_info		snd_ctl_boolean_mono_info
280 
281 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
282 {
283 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
284 	int index = kcontrol->private_value;
285 
286 	ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
287 	return 0;
288 }
289 
290 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291 {
292 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
293 	int index = kcontrol->private_value;
294 	int value = ucontrol->value.integer.value[0];
295 	int err, changed;
296 
297 	if (value > 1)
298 		return -EINVAL;
299 	changed = value != mixer->audigy2nx_leds[index];
300 	down_read(&mixer->chip->shutdown_rwsem);
301 	if (mixer->chip->shutdown) {
302 		err = -ENODEV;
303 		goto out;
304 	}
305 	if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
306 		err = snd_usb_ctl_msg(mixer->chip->dev,
307 			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
308 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
309 			      !value, 0, NULL, 0);
310 	/* USB X-Fi S51 Pro */
311 	if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
312 		err = snd_usb_ctl_msg(mixer->chip->dev,
313 			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
314 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
315 			      !value, 0, NULL, 0);
316 	else
317 		err = snd_usb_ctl_msg(mixer->chip->dev,
318 			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
319 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
320 			      value, index + 2, NULL, 0);
321  out:
322 	up_read(&mixer->chip->shutdown_rwsem);
323 	if (err < 0)
324 		return err;
325 	mixer->audigy2nx_leds[index] = value;
326 	return changed;
327 }
328 
329 static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
330 	{
331 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
332 		.name = "CMSS LED Switch",
333 		.info = snd_audigy2nx_led_info,
334 		.get = snd_audigy2nx_led_get,
335 		.put = snd_audigy2nx_led_put,
336 		.private_value = 0,
337 	},
338 	{
339 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
340 		.name = "Power LED Switch",
341 		.info = snd_audigy2nx_led_info,
342 		.get = snd_audigy2nx_led_get,
343 		.put = snd_audigy2nx_led_put,
344 		.private_value = 1,
345 	},
346 	{
347 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
348 		.name = "Dolby Digital LED Switch",
349 		.info = snd_audigy2nx_led_info,
350 		.get = snd_audigy2nx_led_get,
351 		.put = snd_audigy2nx_led_put,
352 		.private_value = 2,
353 	},
354 };
355 
356 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
357 {
358 	int i, err;
359 
360 	for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
361 		/* USB X-Fi S51 doesn't have a CMSS LED */
362 		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
363 			continue;
364 		/* USB X-Fi S51 Pro doesn't have one either */
365 		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
366 			continue;
367 		if (i > 1 && /* Live24ext has 2 LEDs only */
368 			(mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
369 			 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
370 			 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
371 			 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
372 			break;
373 		err = snd_ctl_add(mixer->chip->card,
374 				  snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
375 		if (err < 0)
376 			return err;
377 	}
378 	mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
379 	return 0;
380 }
381 
382 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
383 				    struct snd_info_buffer *buffer)
384 {
385 	static const struct sb_jack {
386 		int unitid;
387 		const char *name;
388 	}  jacks_audigy2nx[] = {
389 		{4,  "dig in "},
390 		{7,  "line in"},
391 		{19, "spk out"},
392 		{20, "hph out"},
393 		{-1, NULL}
394 	}, jacks_live24ext[] = {
395 		{4,  "line in"}, /* &1=Line, &2=Mic*/
396 		{3,  "hph out"}, /* headphones */
397 		{0,  "RC     "}, /* last command, 6 bytes see rc_config above */
398 		{-1, NULL}
399 	};
400 	const struct sb_jack *jacks;
401 	struct usb_mixer_interface *mixer = entry->private_data;
402 	int i, err;
403 	u8 buf[3];
404 
405 	snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
406 	if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
407 		jacks = jacks_audigy2nx;
408 	else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
409 		 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
410 		jacks = jacks_live24ext;
411 	else
412 		return;
413 
414 	for (i = 0; jacks[i].name; ++i) {
415 		snd_iprintf(buffer, "%s: ", jacks[i].name);
416 		down_read(&mixer->chip->shutdown_rwsem);
417 		if (mixer->chip->shutdown)
418 			err = 0;
419 		else
420 			err = snd_usb_ctl_msg(mixer->chip->dev,
421 				      usb_rcvctrlpipe(mixer->chip->dev, 0),
422 				      UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
423 				      USB_RECIP_INTERFACE, 0,
424 				      jacks[i].unitid << 8, buf, 3);
425 		up_read(&mixer->chip->shutdown_rwsem);
426 		if (err == 3 && (buf[0] == 3 || buf[0] == 6))
427 			snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
428 		else
429 			snd_iprintf(buffer, "?\n");
430 	}
431 }
432 
433 /* ASUS Xonar U1 / U3 controls */
434 
435 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
436 				   struct snd_ctl_elem_value *ucontrol)
437 {
438 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
439 
440 	ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
441 	return 0;
442 }
443 
444 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
445 				   struct snd_ctl_elem_value *ucontrol)
446 {
447 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
448 	u8 old_status, new_status;
449 	int err, changed;
450 
451 	old_status = mixer->xonar_u1_status;
452 	if (ucontrol->value.integer.value[0])
453 		new_status = old_status | 0x02;
454 	else
455 		new_status = old_status & ~0x02;
456 	changed = new_status != old_status;
457 	down_read(&mixer->chip->shutdown_rwsem);
458 	if (mixer->chip->shutdown)
459 		err = -ENODEV;
460 	else
461 		err = snd_usb_ctl_msg(mixer->chip->dev,
462 			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
463 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
464 			      50, 0, &new_status, 1);
465 	up_read(&mixer->chip->shutdown_rwsem);
466 	if (err < 0)
467 		return err;
468 	mixer->xonar_u1_status = new_status;
469 	return changed;
470 }
471 
472 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
473 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
474 	.name = "Digital Playback Switch",
475 	.info = snd_ctl_boolean_mono_info,
476 	.get = snd_xonar_u1_switch_get,
477 	.put = snd_xonar_u1_switch_put,
478 };
479 
480 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
481 {
482 	int err;
483 
484 	err = snd_ctl_add(mixer->chip->card,
485 			  snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
486 	if (err < 0)
487 		return err;
488 	mixer->xonar_u1_status = 0x05;
489 	return 0;
490 }
491 
492 /* Native Instruments device quirks */
493 
494 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
495 
496 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
497 					     struct snd_ctl_elem_value *ucontrol)
498 {
499 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
500 	struct usb_device *dev = mixer->chip->dev;
501 	u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
502 	u16 wIndex = kcontrol->private_value & 0xffff;
503 	u8 tmp;
504 	int ret;
505 
506 	down_read(&mixer->chip->shutdown_rwsem);
507 	if (mixer->chip->shutdown)
508 		ret = -ENODEV;
509 	else
510 		ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
511 				  USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
512 				  0, wIndex,
513 				  &tmp, sizeof(tmp), 1000);
514 	up_read(&mixer->chip->shutdown_rwsem);
515 
516 	if (ret < 0) {
517 		snd_printk(KERN_ERR
518 			   "unable to issue vendor read request (ret = %d)", ret);
519 		return ret;
520 	}
521 
522 	ucontrol->value.integer.value[0] = tmp;
523 
524 	return 0;
525 }
526 
527 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
528 					     struct snd_ctl_elem_value *ucontrol)
529 {
530 	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
531 	struct usb_device *dev = mixer->chip->dev;
532 	u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
533 	u16 wIndex = kcontrol->private_value & 0xffff;
534 	u16 wValue = ucontrol->value.integer.value[0];
535 	int ret;
536 
537 	down_read(&mixer->chip->shutdown_rwsem);
538 	if (mixer->chip->shutdown)
539 		ret = -ENODEV;
540 	else
541 		ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
542 				  USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
543 				  wValue, wIndex,
544 				  NULL, 0, 1000);
545 	up_read(&mixer->chip->shutdown_rwsem);
546 
547 	if (ret < 0) {
548 		snd_printk(KERN_ERR
549 			   "unable to issue vendor write request (ret = %d)", ret);
550 		return ret;
551 	}
552 
553 	return 0;
554 }
555 
556 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
557 	{
558 		.name = "Direct Thru Channel A",
559 		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
560 	},
561 	{
562 		.name = "Direct Thru Channel B",
563 		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
564 	},
565 	{
566 		.name = "Phono Input Channel A",
567 		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
568 	},
569 	{
570 		.name = "Phono Input Channel B",
571 		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
572 	},
573 };
574 
575 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
576 	{
577 		.name = "Direct Thru Channel A",
578 		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
579 	},
580 	{
581 		.name = "Direct Thru Channel B",
582 		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
583 	},
584 	{
585 		.name = "Direct Thru Channel C",
586 		.private_value = _MAKE_NI_CONTROL(0x01, 0x07),
587 	},
588 	{
589 		.name = "Direct Thru Channel D",
590 		.private_value = _MAKE_NI_CONTROL(0x01, 0x09),
591 	},
592 	{
593 		.name = "Phono Input Channel A",
594 		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
595 	},
596 	{
597 		.name = "Phono Input Channel B",
598 		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
599 	},
600 	{
601 		.name = "Phono Input Channel C",
602 		.private_value = _MAKE_NI_CONTROL(0x02, 0x07),
603 	},
604 	{
605 		.name = "Phono Input Channel D",
606 		.private_value = _MAKE_NI_CONTROL(0x02, 0x09),
607 	},
608 };
609 
610 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
611 					      const struct snd_kcontrol_new *kc,
612 					      unsigned int count)
613 {
614 	int i, err = 0;
615 	struct snd_kcontrol_new template = {
616 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
617 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
618 		.get = snd_nativeinstruments_control_get,
619 		.put = snd_nativeinstruments_control_put,
620 		.info = snd_ctl_boolean_mono_info,
621 	};
622 
623 	for (i = 0; i < count; i++) {
624 		struct snd_kcontrol *c;
625 
626 		template.name = kc[i].name;
627 		template.private_value = kc[i].private_value;
628 
629 		c = snd_ctl_new1(&template, mixer);
630 		err = snd_ctl_add(mixer->chip->card, c);
631 
632 		if (err < 0)
633 			break;
634 	}
635 
636 	return err;
637 }
638 
639 /* M-Audio FastTrack Ultra quirks */
640 /* FTU Effect switch (also used by C400/C600) */
641 struct snd_ftu_eff_switch_priv_val {
642 	struct usb_mixer_interface *mixer;
643 	int cached_value;
644 	int is_cached;
645 	int bUnitID;
646 	int validx;
647 };
648 
649 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
650 					struct snd_ctl_elem_info *uinfo)
651 {
652 	static const char *texts[8] = {"Room 1",
653 				       "Room 2",
654 				       "Room 3",
655 				       "Hall 1",
656 				       "Hall 2",
657 				       "Plate",
658 				       "Delay",
659 				       "Echo"
660 	};
661 
662 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
663 	uinfo->count = 1;
664 	uinfo->value.enumerated.items = 8;
665 	if (uinfo->value.enumerated.item > 7)
666 		uinfo->value.enumerated.item = 7;
667 	strcpy(uinfo->value.enumerated.name,
668 		texts[uinfo->value.enumerated.item]);
669 
670 	return 0;
671 }
672 
673 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
674 					struct snd_ctl_elem_value *ucontrol)
675 {
676 	struct snd_usb_audio *chip;
677 	struct usb_mixer_interface *mixer;
678 	struct snd_ftu_eff_switch_priv_val *pval;
679 	int err;
680 	unsigned char value[2];
681 	int id, validx;
682 
683 	const int val_len = 2;
684 
685 	value[0] = 0x00;
686 	value[1] = 0x00;
687 
688 	pval = (struct snd_ftu_eff_switch_priv_val *)
689 		kctl->private_value;
690 
691 	if (pval->is_cached) {
692 		ucontrol->value.enumerated.item[0] = pval->cached_value;
693 		return 0;
694 	}
695 
696 	mixer = (struct usb_mixer_interface *) pval->mixer;
697 	if (snd_BUG_ON(!mixer))
698 		return -EINVAL;
699 
700 	chip = (struct snd_usb_audio *) mixer->chip;
701 	if (snd_BUG_ON(!chip))
702 		return -EINVAL;
703 
704 	id = pval->bUnitID;
705 	validx = pval->validx;
706 
707 	down_read(&mixer->chip->shutdown_rwsem);
708 	if (mixer->chip->shutdown)
709 		err = -ENODEV;
710 	else
711 		err = snd_usb_ctl_msg(chip->dev,
712 			usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
713 			USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
714 			validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
715 			value, val_len);
716 	up_read(&mixer->chip->shutdown_rwsem);
717 	if (err < 0)
718 		return err;
719 
720 	ucontrol->value.enumerated.item[0] = value[0];
721 	pval->cached_value = value[0];
722 	pval->is_cached = 1;
723 
724 	return 0;
725 }
726 
727 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
728 					struct snd_ctl_elem_value *ucontrol)
729 {
730 	struct snd_usb_audio *chip;
731 	struct snd_ftu_eff_switch_priv_val *pval;
732 
733 	struct usb_mixer_interface *mixer;
734 	int changed, cur_val, err, new_val;
735 	unsigned char value[2];
736 	int id, validx;
737 
738 	const int val_len = 2;
739 
740 	changed = 0;
741 
742 	pval = (struct snd_ftu_eff_switch_priv_val *)
743 		kctl->private_value;
744 	cur_val = pval->cached_value;
745 	new_val = ucontrol->value.enumerated.item[0];
746 
747 	mixer = (struct usb_mixer_interface *) pval->mixer;
748 	if (snd_BUG_ON(!mixer))
749 		return -EINVAL;
750 
751 	chip = (struct snd_usb_audio *) mixer->chip;
752 	if (snd_BUG_ON(!chip))
753 		return -EINVAL;
754 
755 	id = pval->bUnitID;
756 	validx = pval->validx;
757 
758 	if (!pval->is_cached) {
759 		/* Read current value */
760 		down_read(&mixer->chip->shutdown_rwsem);
761 		if (mixer->chip->shutdown)
762 			err = -ENODEV;
763 		else
764 			err = snd_usb_ctl_msg(chip->dev,
765 				usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
766 				USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
767 				validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
768 				value, val_len);
769 		up_read(&mixer->chip->shutdown_rwsem);
770 		if (err < 0)
771 			return err;
772 
773 		cur_val = value[0];
774 		pval->cached_value = cur_val;
775 		pval->is_cached = 1;
776 	}
777 	/* update value if needed */
778 	if (cur_val != new_val) {
779 		value[0] = new_val;
780 		value[1] = 0;
781 		down_read(&mixer->chip->shutdown_rwsem);
782 		if (mixer->chip->shutdown)
783 			err = -ENODEV;
784 		else
785 			err = snd_usb_ctl_msg(chip->dev,
786 				usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
787 				USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
788 				validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
789 				value, val_len);
790 		up_read(&mixer->chip->shutdown_rwsem);
791 		if (err < 0)
792 			return err;
793 
794 		pval->cached_value = new_val;
795 		pval->is_cached = 1;
796 		changed = 1;
797 	}
798 
799 	return changed;
800 }
801 
802 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
803 	int validx, int bUnitID)
804 {
805 	static struct snd_kcontrol_new template = {
806 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807 		.name = "Effect Program Switch",
808 		.index = 0,
809 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
810 		.info = snd_ftu_eff_switch_info,
811 		.get = snd_ftu_eff_switch_get,
812 		.put = snd_ftu_eff_switch_put
813 	};
814 
815 	int err;
816 	struct snd_kcontrol *kctl;
817 	struct snd_ftu_eff_switch_priv_val *pval;
818 
819 	pval = kzalloc(sizeof(*pval), GFP_KERNEL);
820 	if (!pval)
821 		return -ENOMEM;
822 
823 	pval->cached_value = 0;
824 	pval->is_cached = 0;
825 	pval->mixer = mixer;
826 	pval->bUnitID = bUnitID;
827 	pval->validx = validx;
828 
829 	template.private_value = (unsigned long) pval;
830 	kctl = snd_ctl_new1(&template, mixer->chip);
831 	if (!kctl) {
832 		kfree(pval);
833 		return -ENOMEM;
834 	}
835 
836 	err = snd_ctl_add(mixer->chip->card, kctl);
837 	if (err < 0)
838 		return err;
839 
840 	return 0;
841 }
842 
843 /* Create volume controls for FTU devices*/
844 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
845 {
846 	char name[64];
847 	unsigned int control, cmask;
848 	int in, out, err;
849 
850 	const unsigned int id = 5;
851 	const int val_type = USB_MIXER_S16;
852 
853 	for (out = 0; out < 8; out++) {
854 		control = out + 1;
855 		for (in = 0; in < 8; in++) {
856 			cmask = 1 << in;
857 			snprintf(name, sizeof(name),
858 				"AIn%d - Out%d Capture Volume",
859 				in  + 1, out + 1);
860 			err = snd_create_std_mono_ctl(mixer, id, control,
861 							cmask, val_type, name,
862 							&snd_usb_mixer_vol_tlv);
863 			if (err < 0)
864 				return err;
865 		}
866 		for (in = 8; in < 16; in++) {
867 			cmask = 1 << in;
868 			snprintf(name, sizeof(name),
869 				"DIn%d - Out%d Playback Volume",
870 				in - 7, out + 1);
871 			err = snd_create_std_mono_ctl(mixer, id, control,
872 							cmask, val_type, name,
873 							&snd_usb_mixer_vol_tlv);
874 			if (err < 0)
875 				return err;
876 		}
877 	}
878 
879 	return 0;
880 }
881 
882 /* This control needs a volume quirk, see mixer.c */
883 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
884 {
885 	static const char name[] = "Effect Volume";
886 	const unsigned int id = 6;
887 	const int val_type = USB_MIXER_U8;
888 	const unsigned int control = 2;
889 	const unsigned int cmask = 0;
890 
891 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
892 					name, snd_usb_mixer_vol_tlv);
893 }
894 
895 /* This control needs a volume quirk, see mixer.c */
896 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
897 {
898 	static const char name[] = "Effect Duration";
899 	const unsigned int id = 6;
900 	const int val_type = USB_MIXER_S16;
901 	const unsigned int control = 3;
902 	const unsigned int cmask = 0;
903 
904 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
905 					name, snd_usb_mixer_vol_tlv);
906 }
907 
908 /* This control needs a volume quirk, see mixer.c */
909 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
910 {
911 	static const char name[] = "Effect Feedback Volume";
912 	const unsigned int id = 6;
913 	const int val_type = USB_MIXER_U8;
914 	const unsigned int control = 4;
915 	const unsigned int cmask = 0;
916 
917 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
918 					name, NULL);
919 }
920 
921 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
922 {
923 	unsigned int cmask;
924 	int err, ch;
925 	char name[48];
926 
927 	const unsigned int id = 7;
928 	const int val_type = USB_MIXER_S16;
929 	const unsigned int control = 7;
930 
931 	for (ch = 0; ch < 4; ++ch) {
932 		cmask = 1 << ch;
933 		snprintf(name, sizeof(name),
934 			"Effect Return %d Volume", ch + 1);
935 		err = snd_create_std_mono_ctl(mixer, id, control,
936 						cmask, val_type, name,
937 						snd_usb_mixer_vol_tlv);
938 		if (err < 0)
939 			return err;
940 	}
941 
942 	return 0;
943 }
944 
945 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
946 {
947 	unsigned int  cmask;
948 	int err, ch;
949 	char name[48];
950 
951 	const unsigned int id = 5;
952 	const int val_type = USB_MIXER_S16;
953 	const unsigned int control = 9;
954 
955 	for (ch = 0; ch < 8; ++ch) {
956 		cmask = 1 << ch;
957 		snprintf(name, sizeof(name),
958 			"Effect Send AIn%d Volume", ch + 1);
959 		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
960 						val_type, name,
961 						snd_usb_mixer_vol_tlv);
962 		if (err < 0)
963 			return err;
964 	}
965 	for (ch = 8; ch < 16; ++ch) {
966 		cmask = 1 << ch;
967 		snprintf(name, sizeof(name),
968 			"Effect Send DIn%d Volume", ch - 7);
969 		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
970 						val_type, name,
971 						snd_usb_mixer_vol_tlv);
972 		if (err < 0)
973 			return err;
974 	}
975 	return 0;
976 }
977 
978 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
979 {
980 	int err;
981 
982 	err = snd_ftu_create_volume_ctls(mixer);
983 	if (err < 0)
984 		return err;
985 
986 	err = snd_ftu_create_effect_switch(mixer, 1, 6);
987 	if (err < 0)
988 		return err;
989 
990 	err = snd_ftu_create_effect_volume_ctl(mixer);
991 	if (err < 0)
992 		return err;
993 
994 	err = snd_ftu_create_effect_duration_ctl(mixer);
995 	if (err < 0)
996 		return err;
997 
998 	err = snd_ftu_create_effect_feedback_ctl(mixer);
999 	if (err < 0)
1000 		return err;
1001 
1002 	err = snd_ftu_create_effect_return_ctls(mixer);
1003 	if (err < 0)
1004 		return err;
1005 
1006 	err = snd_ftu_create_effect_send_ctls(mixer);
1007 	if (err < 0)
1008 		return err;
1009 
1010 	return 0;
1011 }
1012 
1013 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1014 			       unsigned char samplerate_id)
1015 {
1016 	struct usb_mixer_interface *mixer;
1017 	struct usb_mixer_elem_info *cval;
1018 	int unitid = 12; /* SamleRate ExtensionUnit ID */
1019 
1020 	list_for_each_entry(mixer, &chip->mixer_list, list) {
1021 		cval = mixer->id_elems[unitid];
1022 		if (cval) {
1023 			snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1024 						    cval->control << 8,
1025 						    samplerate_id);
1026 			snd_usb_mixer_notify_id(mixer, unitid);
1027 		}
1028 		break;
1029 	}
1030 }
1031 
1032 /* M-Audio Fast Track C400/C600 */
1033 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1034 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1035 {
1036 	char name[64];
1037 	unsigned int cmask, offset;
1038 	int out, chan, err;
1039 	int num_outs = 0;
1040 	int num_ins = 0;
1041 
1042 	const unsigned int id = 0x40;
1043 	const int val_type = USB_MIXER_S16;
1044 	const int control = 1;
1045 
1046 	switch (mixer->chip->usb_id) {
1047 	case USB_ID(0x0763, 0x2030):
1048 		num_outs = 6;
1049 		num_ins = 4;
1050 		break;
1051 	case USB_ID(0x0763, 0x2031):
1052 		num_outs = 8;
1053 		num_ins = 6;
1054 		break;
1055 	}
1056 
1057 	for (chan = 0; chan < num_outs + num_ins; chan++) {
1058 		for (out = 0; out < num_outs; out++) {
1059 			if (chan < num_outs) {
1060 				snprintf(name, sizeof(name),
1061 					"PCM%d-Out%d Playback Volume",
1062 					chan + 1, out + 1);
1063 			} else {
1064 				snprintf(name, sizeof(name),
1065 					"In%d-Out%d Playback Volume",
1066 					chan - num_outs + 1, out + 1);
1067 			}
1068 
1069 			cmask = (out == 0) ? 0 : 1 << (out - 1);
1070 			offset = chan * num_outs;
1071 			err = snd_create_std_mono_ctl_offset(mixer, id, control,
1072 						cmask, val_type, offset, name,
1073 						&snd_usb_mixer_vol_tlv);
1074 			if (err < 0)
1075 				return err;
1076 		}
1077 	}
1078 
1079 	return 0;
1080 }
1081 
1082 /* This control needs a volume quirk, see mixer.c */
1083 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1084 {
1085 	static const char name[] = "Effect Volume";
1086 	const unsigned int id = 0x43;
1087 	const int val_type = USB_MIXER_U8;
1088 	const unsigned int control = 3;
1089 	const unsigned int cmask = 0;
1090 
1091 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1092 					name, snd_usb_mixer_vol_tlv);
1093 }
1094 
1095 /* This control needs a volume quirk, see mixer.c */
1096 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1097 {
1098 	static const char name[] = "Effect Duration";
1099 	const unsigned int id = 0x43;
1100 	const int val_type = USB_MIXER_S16;
1101 	const unsigned int control = 4;
1102 	const unsigned int cmask = 0;
1103 
1104 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1105 					name, snd_usb_mixer_vol_tlv);
1106 }
1107 
1108 /* This control needs a volume quirk, see mixer.c */
1109 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1110 {
1111 	static const char name[] = "Effect Feedback Volume";
1112 	const unsigned int id = 0x43;
1113 	const int val_type = USB_MIXER_U8;
1114 	const unsigned int control = 5;
1115 	const unsigned int cmask = 0;
1116 
1117 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1118 					name, NULL);
1119 }
1120 
1121 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1122 {
1123 	char name[64];
1124 	unsigned int cmask;
1125 	int chan, err;
1126 	int num_outs = 0;
1127 	int num_ins = 0;
1128 
1129 	const unsigned int id = 0x42;
1130 	const int val_type = USB_MIXER_S16;
1131 	const int control = 1;
1132 
1133 	switch (mixer->chip->usb_id) {
1134 	case USB_ID(0x0763, 0x2030):
1135 		num_outs = 6;
1136 		num_ins = 4;
1137 		break;
1138 	case USB_ID(0x0763, 0x2031):
1139 		num_outs = 8;
1140 		num_ins = 6;
1141 		break;
1142 	}
1143 
1144 	for (chan = 0; chan < num_outs + num_ins; chan++) {
1145 		if (chan < num_outs) {
1146 			snprintf(name, sizeof(name),
1147 				"Effect Send DOut%d",
1148 				chan + 1);
1149 		} else {
1150 			snprintf(name, sizeof(name),
1151 				"Effect Send AIn%d",
1152 				chan - num_outs + 1);
1153 		}
1154 
1155 		cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1156 		err = snd_create_std_mono_ctl(mixer, id, control,
1157 						cmask, val_type, name,
1158 						&snd_usb_mixer_vol_tlv);
1159 		if (err < 0)
1160 			return err;
1161 	}
1162 
1163 	return 0;
1164 }
1165 
1166 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1167 {
1168 	char name[64];
1169 	unsigned int cmask;
1170 	int chan, err;
1171 	int num_outs = 0;
1172 	int offset = 0;
1173 
1174 	const unsigned int id = 0x40;
1175 	const int val_type = USB_MIXER_S16;
1176 	const int control = 1;
1177 
1178 	switch (mixer->chip->usb_id) {
1179 	case USB_ID(0x0763, 0x2030):
1180 		num_outs = 6;
1181 		offset = 0x3c;
1182 		/* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1183 		break;
1184 	case USB_ID(0x0763, 0x2031):
1185 		num_outs = 8;
1186 		offset = 0x70;
1187 		/* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1188 		break;
1189 	}
1190 
1191 	for (chan = 0; chan < num_outs; chan++) {
1192 		snprintf(name, sizeof(name),
1193 			"Effect Return %d",
1194 			chan + 1);
1195 
1196 		cmask = (chan == 0) ? 0 :
1197 			1 << (chan + (chan % 2) * num_outs - 1);
1198 		err = snd_create_std_mono_ctl_offset(mixer, id, control,
1199 						cmask, val_type, offset, name,
1200 						&snd_usb_mixer_vol_tlv);
1201 		if (err < 0)
1202 			return err;
1203 	}
1204 
1205 	return 0;
1206 }
1207 
1208 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1209 {
1210 	int err;
1211 
1212 	err = snd_c400_create_vol_ctls(mixer);
1213 	if (err < 0)
1214 		return err;
1215 
1216 	err = snd_c400_create_effect_vol_ctls(mixer);
1217 	if (err < 0)
1218 		return err;
1219 
1220 	err = snd_c400_create_effect_ret_vol_ctls(mixer);
1221 	if (err < 0)
1222 		return err;
1223 
1224 	err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1225 	if (err < 0)
1226 		return err;
1227 
1228 	err = snd_c400_create_effect_volume_ctl(mixer);
1229 	if (err < 0)
1230 		return err;
1231 
1232 	err = snd_c400_create_effect_duration_ctl(mixer);
1233 	if (err < 0)
1234 		return err;
1235 
1236 	err = snd_c400_create_effect_feedback_ctl(mixer);
1237 	if (err < 0)
1238 		return err;
1239 
1240 	return 0;
1241 }
1242 
1243 /*
1244  * The mixer units for Ebox-44 are corrupt, and even where they
1245  * are valid they presents mono controls as L and R channels of
1246  * stereo. So we provide a good mixer here.
1247  */
1248 static struct std_mono_table ebox44_table[] = {
1249 	{
1250 		.unitid = 4,
1251 		.control = 1,
1252 		.cmask = 0x0,
1253 		.val_type = USB_MIXER_INV_BOOLEAN,
1254 		.name = "Headphone Playback Switch"
1255 	},
1256 	{
1257 		.unitid = 4,
1258 		.control = 2,
1259 		.cmask = 0x1,
1260 		.val_type = USB_MIXER_S16,
1261 		.name = "Headphone A Mix Playback Volume"
1262 	},
1263 	{
1264 		.unitid = 4,
1265 		.control = 2,
1266 		.cmask = 0x2,
1267 		.val_type = USB_MIXER_S16,
1268 		.name = "Headphone B Mix Playback Volume"
1269 	},
1270 
1271 	{
1272 		.unitid = 7,
1273 		.control = 1,
1274 		.cmask = 0x0,
1275 		.val_type = USB_MIXER_INV_BOOLEAN,
1276 		.name = "Output Playback Switch"
1277 	},
1278 	{
1279 		.unitid = 7,
1280 		.control = 2,
1281 		.cmask = 0x1,
1282 		.val_type = USB_MIXER_S16,
1283 		.name = "Output A Playback Volume"
1284 	},
1285 	{
1286 		.unitid = 7,
1287 		.control = 2,
1288 		.cmask = 0x2,
1289 		.val_type = USB_MIXER_S16,
1290 		.name = "Output B Playback Volume"
1291 	},
1292 
1293 	{
1294 		.unitid = 10,
1295 		.control = 1,
1296 		.cmask = 0x0,
1297 		.val_type = USB_MIXER_INV_BOOLEAN,
1298 		.name = "Input Capture Switch"
1299 	},
1300 	{
1301 		.unitid = 10,
1302 		.control = 2,
1303 		.cmask = 0x1,
1304 		.val_type = USB_MIXER_S16,
1305 		.name = "Input A Capture Volume"
1306 	},
1307 	{
1308 		.unitid = 10,
1309 		.control = 2,
1310 		.cmask = 0x2,
1311 		.val_type = USB_MIXER_S16,
1312 		.name = "Input B Capture Volume"
1313 	},
1314 
1315 	{}
1316 };
1317 
1318 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1319 {
1320 	int err = 0;
1321 	struct snd_info_entry *entry;
1322 
1323 	if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1324 		return err;
1325 
1326 	switch (mixer->chip->usb_id) {
1327 	case USB_ID(0x041e, 0x3020):
1328 	case USB_ID(0x041e, 0x3040):
1329 	case USB_ID(0x041e, 0x3042):
1330 	case USB_ID(0x041e, 0x30df):
1331 	case USB_ID(0x041e, 0x3048):
1332 		err = snd_audigy2nx_controls_create(mixer);
1333 		if (err < 0)
1334 			break;
1335 		if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1336 			snd_info_set_text_ops(entry, mixer,
1337 					      snd_audigy2nx_proc_read);
1338 		break;
1339 
1340 	case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1341 	case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1342 		err = snd_c400_create_mixer(mixer);
1343 		break;
1344 
1345 	case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1346 	case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1347 		err = snd_ftu_create_mixer(mixer);
1348 		break;
1349 
1350 	case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1351 	case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1352 	case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1353 		err = snd_xonar_u1_controls_create(mixer);
1354 		break;
1355 
1356 	case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1357 		err = snd_nativeinstruments_create_mixer(mixer,
1358 				snd_nativeinstruments_ta6_mixers,
1359 				ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
1360 		break;
1361 
1362 	case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1363 		err = snd_nativeinstruments_create_mixer(mixer,
1364 				snd_nativeinstruments_ta10_mixers,
1365 				ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
1366 		break;
1367 
1368 	case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1369 		/* detection is disabled in mixer_maps.c */
1370 		err = snd_create_std_mono_table(mixer, ebox44_table);
1371 		break;
1372 	}
1373 
1374 	return err;
1375 }
1376 
1377 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1378 				    int unitid)
1379 {
1380 	if (!mixer->rc_cfg)
1381 		return;
1382 	/* unit ids specific to Extigy/Audigy 2 NX: */
1383 	switch (unitid) {
1384 	case 0: /* remote control */
1385 		mixer->rc_urb->dev = mixer->chip->dev;
1386 		usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1387 		break;
1388 	case 4: /* digital in jack */
1389 	case 7: /* line in jacks */
1390 	case 19: /* speaker out jacks */
1391 	case 20: /* headphones out jack */
1392 		break;
1393 	/* live24ext: 4 = line-in jack */
1394 	case 3:	/* hp-out jack (may actuate Mute) */
1395 		if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1396 		    mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1397 			snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1398 		break;
1399 	default:
1400 		snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1401 		break;
1402 	}
1403 }
1404 
1405