xref: /openbmc/linux/sound/usb/mixer_quirks.c (revision 15e3ae36)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *   USB Audio Driver for ALSA
4  *
5  *   Quirks and vendor-specific extensions for mixer interfaces
6  *
7  *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8  *
9  *   Many codes borrowed from audio.c by
10  *	    Alan Cox (alan@lxorguk.ukuu.org.uk)
11  *	    Thomas Sailer (sailer@ife.ee.ethz.ch)
12  *
13  *   Audio Advantage Micro II support added by:
14  *	    Przemek Rudy (prudy1@o2.pl)
15  */
16 
17 #include <linux/hid.h>
18 #include <linux/init.h>
19 #include <linux/math64.h>
20 #include <linux/slab.h>
21 #include <linux/usb.h>
22 #include <linux/usb/audio.h>
23 
24 #include <sound/asoundef.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/hwdep.h>
28 #include <sound/info.h>
29 #include <sound/tlv.h>
30 
31 #include "usbaudio.h"
32 #include "mixer.h"
33 #include "mixer_quirks.h"
34 #include "mixer_scarlett.h"
35 #include "mixer_scarlett_gen2.h"
36 #include "mixer_us16x08.h"
37 #include "mixer_s1810c.h"
38 #include "helper.h"
39 
40 struct std_mono_table {
41 	unsigned int unitid, control, cmask;
42 	int val_type;
43 	const char *name;
44 	snd_kcontrol_tlv_rw_t *tlv_callback;
45 };
46 
47 /* This function allows for the creation of standard UAC controls.
48  * See the quirks for M-Audio FTUs or Ebox-44.
49  * If you don't want to set a TLV callback pass NULL.
50  *
51  * Since there doesn't seem to be a devices that needs a multichannel
52  * version, we keep it mono for simplicity.
53  */
54 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
55 				unsigned int unitid,
56 				unsigned int control,
57 				unsigned int cmask,
58 				int val_type,
59 				unsigned int idx_off,
60 				const char *name,
61 				snd_kcontrol_tlv_rw_t *tlv_callback)
62 {
63 	struct usb_mixer_elem_info *cval;
64 	struct snd_kcontrol *kctl;
65 
66 	cval = kzalloc(sizeof(*cval), GFP_KERNEL);
67 	if (!cval)
68 		return -ENOMEM;
69 
70 	snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
71 	cval->val_type = val_type;
72 	cval->channels = 1;
73 	cval->control = control;
74 	cval->cmask = cmask;
75 	cval->idx_off = idx_off;
76 
77 	/* get_min_max() is called only for integer volumes later,
78 	 * so provide a short-cut for booleans */
79 	cval->min = 0;
80 	cval->max = 1;
81 	cval->res = 0;
82 	cval->dBmin = 0;
83 	cval->dBmax = 0;
84 
85 	/* Create control */
86 	kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
87 	if (!kctl) {
88 		kfree(cval);
89 		return -ENOMEM;
90 	}
91 
92 	/* Set name */
93 	snprintf(kctl->id.name, sizeof(kctl->id.name), name);
94 	kctl->private_free = snd_usb_mixer_elem_free;
95 
96 	/* set TLV */
97 	if (tlv_callback) {
98 		kctl->tlv.c = tlv_callback;
99 		kctl->vd[0].access |=
100 			SNDRV_CTL_ELEM_ACCESS_TLV_READ |
101 			SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
102 	}
103 	/* Add control to mixer */
104 	return snd_usb_mixer_add_control(&cval->head, kctl);
105 }
106 
107 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
108 				unsigned int unitid,
109 				unsigned int control,
110 				unsigned int cmask,
111 				int val_type,
112 				const char *name,
113 				snd_kcontrol_tlv_rw_t *tlv_callback)
114 {
115 	return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
116 		val_type, 0 /* Offset */, name, tlv_callback);
117 }
118 
119 /*
120  * Create a set of standard UAC controls from a table
121  */
122 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
123 				     const struct std_mono_table *t)
124 {
125 	int err;
126 
127 	while (t->name != NULL) {
128 		err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
129 				t->cmask, t->val_type, t->name, t->tlv_callback);
130 		if (err < 0)
131 			return err;
132 		t++;
133 	}
134 
135 	return 0;
136 }
137 
138 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
139 				      int id,
140 				      usb_mixer_elem_resume_func_t resume,
141 				      const struct snd_kcontrol_new *knew,
142 				      struct usb_mixer_elem_list **listp)
143 {
144 	struct usb_mixer_elem_list *list;
145 	struct snd_kcontrol *kctl;
146 
147 	list = kzalloc(sizeof(*list), GFP_KERNEL);
148 	if (!list)
149 		return -ENOMEM;
150 	if (listp)
151 		*listp = list;
152 	list->mixer = mixer;
153 	list->id = id;
154 	list->resume = resume;
155 	kctl = snd_ctl_new1(knew, list);
156 	if (!kctl) {
157 		kfree(list);
158 		return -ENOMEM;
159 	}
160 	kctl->private_free = snd_usb_mixer_elem_free;
161 	return snd_usb_mixer_add_control(list, kctl);
162 }
163 
164 /*
165  * Sound Blaster remote control configuration
166  *
167  * format of remote control data:
168  * Extigy:       xx 00
169  * Audigy 2 NX:  06 80 xx 00 00 00
170  * Live! 24-bit: 06 80 xx yy 22 83
171  */
172 static const struct rc_config {
173 	u32 usb_id;
174 	u8  offset;
175 	u8  length;
176 	u8  packet_length;
177 	u8  min_packet_length; /* minimum accepted length of the URB result */
178 	u8  mute_mixer_id;
179 	u32 mute_code;
180 } rc_configs[] = {
181 	{ USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
182 	{ USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
183 	{ USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
184 	{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 */
185 	{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
186 	{ USB_ID(0x041e, 0x3237), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
187 	{ USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
188 };
189 
190 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
191 {
192 	struct usb_mixer_interface *mixer = urb->context;
193 	const struct rc_config *rc = mixer->rc_cfg;
194 	u32 code;
195 
196 	if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
197 		return;
198 
199 	code = mixer->rc_buffer[rc->offset];
200 	if (rc->length == 2)
201 		code |= mixer->rc_buffer[rc->offset + 1] << 8;
202 
203 	/* the Mute button actually changes the mixer control */
204 	if (code == rc->mute_code)
205 		snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
206 	mixer->rc_code = code;
207 	wmb();
208 	wake_up(&mixer->rc_waitq);
209 }
210 
211 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
212 				     long count, loff_t *offset)
213 {
214 	struct usb_mixer_interface *mixer = hw->private_data;
215 	int err;
216 	u32 rc_code;
217 
218 	if (count != 1 && count != 4)
219 		return -EINVAL;
220 	err = wait_event_interruptible(mixer->rc_waitq,
221 				       (rc_code = xchg(&mixer->rc_code, 0)) != 0);
222 	if (err == 0) {
223 		if (count == 1)
224 			err = put_user(rc_code, buf);
225 		else
226 			err = put_user(rc_code, (u32 __user *)buf);
227 	}
228 	return err < 0 ? err : count;
229 }
230 
231 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
232 					    poll_table *wait)
233 {
234 	struct usb_mixer_interface *mixer = hw->private_data;
235 
236 	poll_wait(file, &mixer->rc_waitq, wait);
237 	return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
238 }
239 
240 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
241 {
242 	struct snd_hwdep *hwdep;
243 	int err, len, i;
244 
245 	for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
246 		if (rc_configs[i].usb_id == mixer->chip->usb_id)
247 			break;
248 	if (i >= ARRAY_SIZE(rc_configs))
249 		return 0;
250 	mixer->rc_cfg = &rc_configs[i];
251 
252 	len = mixer->rc_cfg->packet_length;
253 
254 	init_waitqueue_head(&mixer->rc_waitq);
255 	err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
256 	if (err < 0)
257 		return err;
258 	snprintf(hwdep->name, sizeof(hwdep->name),
259 		 "%s remote control", mixer->chip->card->shortname);
260 	hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
261 	hwdep->private_data = mixer;
262 	hwdep->ops.read = snd_usb_sbrc_hwdep_read;
263 	hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
264 	hwdep->exclusive = 1;
265 
266 	mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
267 	if (!mixer->rc_urb)
268 		return -ENOMEM;
269 	mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
270 	if (!mixer->rc_setup_packet) {
271 		usb_free_urb(mixer->rc_urb);
272 		mixer->rc_urb = NULL;
273 		return -ENOMEM;
274 	}
275 	mixer->rc_setup_packet->bRequestType =
276 		USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
277 	mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
278 	mixer->rc_setup_packet->wValue = cpu_to_le16(0);
279 	mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
280 	mixer->rc_setup_packet->wLength = cpu_to_le16(len);
281 	usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
282 			     usb_rcvctrlpipe(mixer->chip->dev, 0),
283 			     (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
284 			     snd_usb_soundblaster_remote_complete, mixer);
285 	return 0;
286 }
287 
288 #define snd_audigy2nx_led_info		snd_ctl_boolean_mono_info
289 
290 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291 {
292 	ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
293 	return 0;
294 }
295 
296 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
297 				    int value, int index)
298 {
299 	struct snd_usb_audio *chip = mixer->chip;
300 	int err;
301 
302 	err = snd_usb_lock_shutdown(chip);
303 	if (err < 0)
304 		return err;
305 
306 	if (chip->usb_id == USB_ID(0x041e, 0x3042))
307 		err = snd_usb_ctl_msg(chip->dev,
308 			      usb_sndctrlpipe(chip->dev, 0), 0x24,
309 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
310 			      !value, 0, NULL, 0);
311 	/* USB X-Fi S51 Pro */
312 	if (chip->usb_id == USB_ID(0x041e, 0x30df))
313 		err = snd_usb_ctl_msg(chip->dev,
314 			      usb_sndctrlpipe(chip->dev, 0), 0x24,
315 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
316 			      !value, 0, NULL, 0);
317 	else
318 		err = snd_usb_ctl_msg(chip->dev,
319 			      usb_sndctrlpipe(chip->dev, 0), 0x24,
320 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
321 			      value, index + 2, NULL, 0);
322 	snd_usb_unlock_shutdown(chip);
323 	return err;
324 }
325 
326 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
327 				 struct snd_ctl_elem_value *ucontrol)
328 {
329 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
330 	struct usb_mixer_interface *mixer = list->mixer;
331 	int index = kcontrol->private_value & 0xff;
332 	unsigned int value = ucontrol->value.integer.value[0];
333 	int old_value = kcontrol->private_value >> 8;
334 	int err;
335 
336 	if (value > 1)
337 		return -EINVAL;
338 	if (value == old_value)
339 		return 0;
340 	kcontrol->private_value = (value << 8) | index;
341 	err = snd_audigy2nx_led_update(mixer, value, index);
342 	return err < 0 ? err : 1;
343 }
344 
345 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
346 {
347 	int priv_value = list->kctl->private_value;
348 
349 	return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
350 					priv_value & 0xff);
351 }
352 
353 /* name and private_value are set dynamically */
354 static const struct snd_kcontrol_new snd_audigy2nx_control = {
355 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
356 	.info = snd_audigy2nx_led_info,
357 	.get = snd_audigy2nx_led_get,
358 	.put = snd_audigy2nx_led_put,
359 };
360 
361 static const char * const snd_audigy2nx_led_names[] = {
362 	"CMSS LED Switch",
363 	"Power LED Switch",
364 	"Dolby Digital LED Switch",
365 };
366 
367 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
368 {
369 	int i, err;
370 
371 	for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
372 		struct snd_kcontrol_new knew;
373 
374 		/* USB X-Fi S51 doesn't have a CMSS LED */
375 		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
376 			continue;
377 		/* USB X-Fi S51 Pro doesn't have one either */
378 		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
379 			continue;
380 		if (i > 1 && /* Live24ext has 2 LEDs only */
381 			(mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
382 			 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
383 			 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
384 			 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
385 			break;
386 
387 		knew = snd_audigy2nx_control;
388 		knew.name = snd_audigy2nx_led_names[i];
389 		knew.private_value = (1 << 8) | i; /* LED on as default */
390 		err = add_single_ctl_with_resume(mixer, 0,
391 						 snd_audigy2nx_led_resume,
392 						 &knew, NULL);
393 		if (err < 0)
394 			return err;
395 	}
396 	return 0;
397 }
398 
399 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
400 				    struct snd_info_buffer *buffer)
401 {
402 	static const struct sb_jack {
403 		int unitid;
404 		const char *name;
405 	}  jacks_audigy2nx[] = {
406 		{4,  "dig in "},
407 		{7,  "line in"},
408 		{19, "spk out"},
409 		{20, "hph out"},
410 		{-1, NULL}
411 	}, jacks_live24ext[] = {
412 		{4,  "line in"}, /* &1=Line, &2=Mic*/
413 		{3,  "hph out"}, /* headphones */
414 		{0,  "RC     "}, /* last command, 6 bytes see rc_config above */
415 		{-1, NULL}
416 	};
417 	const struct sb_jack *jacks;
418 	struct usb_mixer_interface *mixer = entry->private_data;
419 	int i, err;
420 	u8 buf[3];
421 
422 	snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
423 	if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
424 		jacks = jacks_audigy2nx;
425 	else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
426 		 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
427 		jacks = jacks_live24ext;
428 	else
429 		return;
430 
431 	for (i = 0; jacks[i].name; ++i) {
432 		snd_iprintf(buffer, "%s: ", jacks[i].name);
433 		err = snd_usb_lock_shutdown(mixer->chip);
434 		if (err < 0)
435 			return;
436 		err = snd_usb_ctl_msg(mixer->chip->dev,
437 				      usb_rcvctrlpipe(mixer->chip->dev, 0),
438 				      UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
439 				      USB_RECIP_INTERFACE, 0,
440 				      jacks[i].unitid << 8, buf, 3);
441 		snd_usb_unlock_shutdown(mixer->chip);
442 		if (err == 3 && (buf[0] == 3 || buf[0] == 6))
443 			snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
444 		else
445 			snd_iprintf(buffer, "?\n");
446 	}
447 }
448 
449 /* EMU0204 */
450 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
451 				      struct snd_ctl_elem_info *uinfo)
452 {
453 	static const char * const texts[2] = {"1/2", "3/4"};
454 
455 	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
456 }
457 
458 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
459 				     struct snd_ctl_elem_value *ucontrol)
460 {
461 	ucontrol->value.enumerated.item[0] = kcontrol->private_value;
462 	return 0;
463 }
464 
465 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
466 					int value)
467 {
468 	struct snd_usb_audio *chip = mixer->chip;
469 	int err;
470 	unsigned char buf[2];
471 
472 	err = snd_usb_lock_shutdown(chip);
473 	if (err < 0)
474 		return err;
475 
476 	buf[0] = 0x01;
477 	buf[1] = value ? 0x02 : 0x01;
478 	err = snd_usb_ctl_msg(chip->dev,
479 		      usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
480 		      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
481 		      0x0400, 0x0e00, buf, 2);
482 	snd_usb_unlock_shutdown(chip);
483 	return err;
484 }
485 
486 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
487 				     struct snd_ctl_elem_value *ucontrol)
488 {
489 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
490 	struct usb_mixer_interface *mixer = list->mixer;
491 	unsigned int value = ucontrol->value.enumerated.item[0];
492 	int err;
493 
494 	if (value > 1)
495 		return -EINVAL;
496 
497 	if (value == kcontrol->private_value)
498 		return 0;
499 
500 	kcontrol->private_value = value;
501 	err = snd_emu0204_ch_switch_update(mixer, value);
502 	return err < 0 ? err : 1;
503 }
504 
505 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
506 {
507 	return snd_emu0204_ch_switch_update(list->mixer,
508 					    list->kctl->private_value);
509 }
510 
511 static const struct snd_kcontrol_new snd_emu0204_control = {
512 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
513 	.name = "Front Jack Channels",
514 	.info = snd_emu0204_ch_switch_info,
515 	.get = snd_emu0204_ch_switch_get,
516 	.put = snd_emu0204_ch_switch_put,
517 	.private_value = 0,
518 };
519 
520 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
521 {
522 	return add_single_ctl_with_resume(mixer, 0,
523 					  snd_emu0204_ch_switch_resume,
524 					  &snd_emu0204_control, NULL);
525 }
526 
527 /* ASUS Xonar U1 / U3 controls */
528 
529 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
530 				   struct snd_ctl_elem_value *ucontrol)
531 {
532 	ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
533 	return 0;
534 }
535 
536 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
537 				      unsigned char status)
538 {
539 	struct snd_usb_audio *chip = mixer->chip;
540 	int err;
541 
542 	err = snd_usb_lock_shutdown(chip);
543 	if (err < 0)
544 		return err;
545 	err = snd_usb_ctl_msg(chip->dev,
546 			      usb_sndctrlpipe(chip->dev, 0), 0x08,
547 			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
548 			      50, 0, &status, 1);
549 	snd_usb_unlock_shutdown(chip);
550 	return err;
551 }
552 
553 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
554 				   struct snd_ctl_elem_value *ucontrol)
555 {
556 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
557 	u8 old_status, new_status;
558 	int err;
559 
560 	old_status = kcontrol->private_value;
561 	if (ucontrol->value.integer.value[0])
562 		new_status = old_status | 0x02;
563 	else
564 		new_status = old_status & ~0x02;
565 	if (new_status == old_status)
566 		return 0;
567 
568 	kcontrol->private_value = new_status;
569 	err = snd_xonar_u1_switch_update(list->mixer, new_status);
570 	return err < 0 ? err : 1;
571 }
572 
573 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
574 {
575 	return snd_xonar_u1_switch_update(list->mixer,
576 					  list->kctl->private_value);
577 }
578 
579 static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
580 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
581 	.name = "Digital Playback Switch",
582 	.info = snd_ctl_boolean_mono_info,
583 	.get = snd_xonar_u1_switch_get,
584 	.put = snd_xonar_u1_switch_put,
585 	.private_value = 0x05,
586 };
587 
588 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
589 {
590 	return add_single_ctl_with_resume(mixer, 0,
591 					  snd_xonar_u1_switch_resume,
592 					  &snd_xonar_u1_output_switch, NULL);
593 }
594 
595 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
596 
597 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
598 				struct snd_ctl_elem_value *ucontrol)
599 {
600 	ucontrol->value.enumerated.item[0] = kctl->private_value;
601 	return 0;
602 }
603 
604 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
605 {
606 	struct snd_usb_audio *chip = mixer->chip;
607 	int err;
608 	unsigned char buff[3];
609 
610 	err = snd_usb_lock_shutdown(chip);
611 	if (err < 0)
612 		return err;
613 
614 	/* Prepare for magic command to toggle clock source */
615 	err = snd_usb_ctl_msg(chip->dev,
616 				usb_rcvctrlpipe(chip->dev, 0), 0x81,
617 				USB_DIR_IN |
618 				USB_TYPE_CLASS |
619 				USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
620 	if (err < 0)
621 		goto err;
622 	err = snd_usb_ctl_msg(chip->dev,
623 				usb_rcvctrlpipe(chip->dev, 0), 0x81,
624 				USB_DIR_IN |
625 				USB_TYPE_CLASS |
626 				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
627 	if (err < 0)
628 		goto err;
629 
630 	/* 2 possibilities:	Internal    -> send sample rate
631 	 *			S/PDIF sync -> send zeroes
632 	 * NB: Sample rate locked to 48kHz on purpose to
633 	 *     prevent user from resetting the sample rate
634 	 *     while S/PDIF sync is enabled and confusing
635 	 *     this configuration.
636 	 */
637 	if (val == 0) {
638 		buff[0] = 0x80;
639 		buff[1] = 0xbb;
640 		buff[2] = 0x00;
641 	} else {
642 		buff[0] = buff[1] = buff[2] = 0x00;
643 	}
644 
645 	/* Send the magic command to toggle the clock source */
646 	err = snd_usb_ctl_msg(chip->dev,
647 				usb_sndctrlpipe(chip->dev, 0), 0x1,
648 				USB_TYPE_CLASS |
649 				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
650 	if (err < 0)
651 		goto err;
652 	err = snd_usb_ctl_msg(chip->dev,
653 				usb_rcvctrlpipe(chip->dev, 0), 0x81,
654 				USB_DIR_IN |
655 				USB_TYPE_CLASS |
656 				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
657 	if (err < 0)
658 		goto err;
659 	err = snd_usb_ctl_msg(chip->dev,
660 				usb_rcvctrlpipe(chip->dev, 0), 0x81,
661 				USB_DIR_IN |
662 				USB_TYPE_CLASS |
663 				USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
664 	if (err < 0)
665 		goto err;
666 
667 err:
668 	snd_usb_unlock_shutdown(chip);
669 	return err;
670 }
671 
672 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
673 				struct snd_ctl_elem_value *ucontrol)
674 {
675 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
676 	struct usb_mixer_interface *mixer = list->mixer;
677 	int err;
678 	bool cur_val, new_val;
679 
680 	cur_val = kctl->private_value;
681 	new_val = ucontrol->value.enumerated.item[0];
682 	if (cur_val == new_val)
683 		return 0;
684 
685 	kctl->private_value = new_val;
686 	err = snd_mbox1_switch_update(mixer, new_val);
687 	return err < 0 ? err : 1;
688 }
689 
690 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
691 				 struct snd_ctl_elem_info *uinfo)
692 {
693 	static const char *const texts[2] = {
694 		"Internal",
695 		"S/PDIF"
696 	};
697 
698 	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
699 }
700 
701 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
702 {
703 	return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
704 }
705 
706 static const struct snd_kcontrol_new snd_mbox1_switch = {
707 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
708 	.name = "Clock Source",
709 	.index = 0,
710 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
711 	.info = snd_mbox1_switch_info,
712 	.get = snd_mbox1_switch_get,
713 	.put = snd_mbox1_switch_put,
714 	.private_value = 0
715 };
716 
717 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
718 {
719 	return add_single_ctl_with_resume(mixer, 0,
720 					  snd_mbox1_switch_resume,
721 					  &snd_mbox1_switch, NULL);
722 }
723 
724 /* Native Instruments device quirks */
725 
726 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
727 
728 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
729 				   struct snd_kcontrol *kctl)
730 {
731 	struct usb_device *dev = mixer->chip->dev;
732 	unsigned int pval = kctl->private_value;
733 	u8 value;
734 	int err;
735 
736 	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
737 			      (pval >> 16) & 0xff,
738 			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
739 			      0, pval & 0xffff, &value, 1);
740 	if (err < 0) {
741 		dev_err(&dev->dev,
742 			"unable to issue vendor read request (ret = %d)", err);
743 		return err;
744 	}
745 
746 	kctl->private_value |= ((unsigned int)value << 24);
747 	return 0;
748 }
749 
750 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
751 					     struct snd_ctl_elem_value *ucontrol)
752 {
753 	ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
754 	return 0;
755 }
756 
757 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
758 {
759 	struct snd_usb_audio *chip = list->mixer->chip;
760 	unsigned int pval = list->kctl->private_value;
761 	int err;
762 
763 	err = snd_usb_lock_shutdown(chip);
764 	if (err < 0)
765 		return err;
766 	err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
767 			      (pval >> 16) & 0xff,
768 			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
769 			      pval >> 24, pval & 0xffff, NULL, 0, 1000);
770 	snd_usb_unlock_shutdown(chip);
771 	return err;
772 }
773 
774 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
775 					     struct snd_ctl_elem_value *ucontrol)
776 {
777 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
778 	u8 oldval = (kcontrol->private_value >> 24) & 0xff;
779 	u8 newval = ucontrol->value.integer.value[0];
780 	int err;
781 
782 	if (oldval == newval)
783 		return 0;
784 
785 	kcontrol->private_value &= ~(0xff << 24);
786 	kcontrol->private_value |= (unsigned int)newval << 24;
787 	err = snd_ni_update_cur_val(list);
788 	return err < 0 ? err : 1;
789 }
790 
791 static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
792 	{
793 		.name = "Direct Thru Channel A",
794 		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
795 	},
796 	{
797 		.name = "Direct Thru Channel B",
798 		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
799 	},
800 	{
801 		.name = "Phono Input Channel A",
802 		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
803 	},
804 	{
805 		.name = "Phono Input Channel B",
806 		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
807 	},
808 };
809 
810 static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
811 	{
812 		.name = "Direct Thru Channel A",
813 		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
814 	},
815 	{
816 		.name = "Direct Thru Channel B",
817 		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
818 	},
819 	{
820 		.name = "Direct Thru Channel C",
821 		.private_value = _MAKE_NI_CONTROL(0x01, 0x07),
822 	},
823 	{
824 		.name = "Direct Thru Channel D",
825 		.private_value = _MAKE_NI_CONTROL(0x01, 0x09),
826 	},
827 	{
828 		.name = "Phono Input Channel A",
829 		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
830 	},
831 	{
832 		.name = "Phono Input Channel B",
833 		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
834 	},
835 	{
836 		.name = "Phono Input Channel C",
837 		.private_value = _MAKE_NI_CONTROL(0x02, 0x07),
838 	},
839 	{
840 		.name = "Phono Input Channel D",
841 		.private_value = _MAKE_NI_CONTROL(0x02, 0x09),
842 	},
843 };
844 
845 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
846 					      const struct snd_kcontrol_new *kc,
847 					      unsigned int count)
848 {
849 	int i, err = 0;
850 	struct snd_kcontrol_new template = {
851 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
853 		.get = snd_nativeinstruments_control_get,
854 		.put = snd_nativeinstruments_control_put,
855 		.info = snd_ctl_boolean_mono_info,
856 	};
857 
858 	for (i = 0; i < count; i++) {
859 		struct usb_mixer_elem_list *list;
860 
861 		template.name = kc[i].name;
862 		template.private_value = kc[i].private_value;
863 
864 		err = add_single_ctl_with_resume(mixer, 0,
865 						 snd_ni_update_cur_val,
866 						 &template, &list);
867 		if (err < 0)
868 			break;
869 		snd_ni_control_init_val(mixer, list->kctl);
870 	}
871 
872 	return err;
873 }
874 
875 /* M-Audio FastTrack Ultra quirks */
876 /* FTU Effect switch (also used by C400/C600) */
877 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
878 					struct snd_ctl_elem_info *uinfo)
879 {
880 	static const char *const texts[8] = {
881 		"Room 1", "Room 2", "Room 3", "Hall 1",
882 		"Hall 2", "Plate", "Delay", "Echo"
883 	};
884 
885 	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
886 }
887 
888 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
889 				   struct snd_kcontrol *kctl)
890 {
891 	struct usb_device *dev = mixer->chip->dev;
892 	unsigned int pval = kctl->private_value;
893 	int err;
894 	unsigned char value[2];
895 
896 	value[0] = 0x00;
897 	value[1] = 0x00;
898 
899 	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
900 			      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
901 			      pval & 0xff00,
902 			      snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
903 			      value, 2);
904 	if (err < 0)
905 		return err;
906 
907 	kctl->private_value |= (unsigned int)value[0] << 24;
908 	return 0;
909 }
910 
911 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
912 					struct snd_ctl_elem_value *ucontrol)
913 {
914 	ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
915 	return 0;
916 }
917 
918 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
919 {
920 	struct snd_usb_audio *chip = list->mixer->chip;
921 	unsigned int pval = list->kctl->private_value;
922 	unsigned char value[2];
923 	int err;
924 
925 	value[0] = pval >> 24;
926 	value[1] = 0;
927 
928 	err = snd_usb_lock_shutdown(chip);
929 	if (err < 0)
930 		return err;
931 	err = snd_usb_ctl_msg(chip->dev,
932 			      usb_sndctrlpipe(chip->dev, 0),
933 			      UAC_SET_CUR,
934 			      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
935 			      pval & 0xff00,
936 			      snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
937 			      value, 2);
938 	snd_usb_unlock_shutdown(chip);
939 	return err;
940 }
941 
942 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
943 					struct snd_ctl_elem_value *ucontrol)
944 {
945 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
946 	unsigned int pval = list->kctl->private_value;
947 	int cur_val, err, new_val;
948 
949 	cur_val = pval >> 24;
950 	new_val = ucontrol->value.enumerated.item[0];
951 	if (cur_val == new_val)
952 		return 0;
953 
954 	kctl->private_value &= ~(0xff << 24);
955 	kctl->private_value |= new_val << 24;
956 	err = snd_ftu_eff_switch_update(list);
957 	return err < 0 ? err : 1;
958 }
959 
960 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
961 	int validx, int bUnitID)
962 {
963 	static struct snd_kcontrol_new template = {
964 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
965 		.name = "Effect Program Switch",
966 		.index = 0,
967 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
968 		.info = snd_ftu_eff_switch_info,
969 		.get = snd_ftu_eff_switch_get,
970 		.put = snd_ftu_eff_switch_put
971 	};
972 	struct usb_mixer_elem_list *list;
973 	int err;
974 
975 	err = add_single_ctl_with_resume(mixer, bUnitID,
976 					 snd_ftu_eff_switch_update,
977 					 &template, &list);
978 	if (err < 0)
979 		return err;
980 	list->kctl->private_value = (validx << 8) | bUnitID;
981 	snd_ftu_eff_switch_init(mixer, list->kctl);
982 	return 0;
983 }
984 
985 /* Create volume controls for FTU devices*/
986 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
987 {
988 	char name[64];
989 	unsigned int control, cmask;
990 	int in, out, err;
991 
992 	const unsigned int id = 5;
993 	const int val_type = USB_MIXER_S16;
994 
995 	for (out = 0; out < 8; out++) {
996 		control = out + 1;
997 		for (in = 0; in < 8; in++) {
998 			cmask = 1 << in;
999 			snprintf(name, sizeof(name),
1000 				"AIn%d - Out%d Capture Volume",
1001 				in  + 1, out + 1);
1002 			err = snd_create_std_mono_ctl(mixer, id, control,
1003 							cmask, val_type, name,
1004 							&snd_usb_mixer_vol_tlv);
1005 			if (err < 0)
1006 				return err;
1007 		}
1008 		for (in = 8; in < 16; in++) {
1009 			cmask = 1 << in;
1010 			snprintf(name, sizeof(name),
1011 				"DIn%d - Out%d Playback Volume",
1012 				in - 7, out + 1);
1013 			err = snd_create_std_mono_ctl(mixer, id, control,
1014 							cmask, val_type, name,
1015 							&snd_usb_mixer_vol_tlv);
1016 			if (err < 0)
1017 				return err;
1018 		}
1019 	}
1020 
1021 	return 0;
1022 }
1023 
1024 /* This control needs a volume quirk, see mixer.c */
1025 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1026 {
1027 	static const char name[] = "Effect Volume";
1028 	const unsigned int id = 6;
1029 	const int val_type = USB_MIXER_U8;
1030 	const unsigned int control = 2;
1031 	const unsigned int cmask = 0;
1032 
1033 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1034 					name, snd_usb_mixer_vol_tlv);
1035 }
1036 
1037 /* This control needs a volume quirk, see mixer.c */
1038 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1039 {
1040 	static const char name[] = "Effect Duration";
1041 	const unsigned int id = 6;
1042 	const int val_type = USB_MIXER_S16;
1043 	const unsigned int control = 3;
1044 	const unsigned int cmask = 0;
1045 
1046 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1047 					name, snd_usb_mixer_vol_tlv);
1048 }
1049 
1050 /* This control needs a volume quirk, see mixer.c */
1051 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1052 {
1053 	static const char name[] = "Effect Feedback Volume";
1054 	const unsigned int id = 6;
1055 	const int val_type = USB_MIXER_U8;
1056 	const unsigned int control = 4;
1057 	const unsigned int cmask = 0;
1058 
1059 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1060 					name, NULL);
1061 }
1062 
1063 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1064 {
1065 	unsigned int cmask;
1066 	int err, ch;
1067 	char name[48];
1068 
1069 	const unsigned int id = 7;
1070 	const int val_type = USB_MIXER_S16;
1071 	const unsigned int control = 7;
1072 
1073 	for (ch = 0; ch < 4; ++ch) {
1074 		cmask = 1 << ch;
1075 		snprintf(name, sizeof(name),
1076 			"Effect Return %d Volume", ch + 1);
1077 		err = snd_create_std_mono_ctl(mixer, id, control,
1078 						cmask, val_type, name,
1079 						snd_usb_mixer_vol_tlv);
1080 		if (err < 0)
1081 			return err;
1082 	}
1083 
1084 	return 0;
1085 }
1086 
1087 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1088 {
1089 	unsigned int  cmask;
1090 	int err, ch;
1091 	char name[48];
1092 
1093 	const unsigned int id = 5;
1094 	const int val_type = USB_MIXER_S16;
1095 	const unsigned int control = 9;
1096 
1097 	for (ch = 0; ch < 8; ++ch) {
1098 		cmask = 1 << ch;
1099 		snprintf(name, sizeof(name),
1100 			"Effect Send AIn%d Volume", ch + 1);
1101 		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1102 						val_type, name,
1103 						snd_usb_mixer_vol_tlv);
1104 		if (err < 0)
1105 			return err;
1106 	}
1107 	for (ch = 8; ch < 16; ++ch) {
1108 		cmask = 1 << ch;
1109 		snprintf(name, sizeof(name),
1110 			"Effect Send DIn%d Volume", ch - 7);
1111 		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1112 						val_type, name,
1113 						snd_usb_mixer_vol_tlv);
1114 		if (err < 0)
1115 			return err;
1116 	}
1117 	return 0;
1118 }
1119 
1120 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1121 {
1122 	int err;
1123 
1124 	err = snd_ftu_create_volume_ctls(mixer);
1125 	if (err < 0)
1126 		return err;
1127 
1128 	err = snd_ftu_create_effect_switch(mixer, 1, 6);
1129 	if (err < 0)
1130 		return err;
1131 
1132 	err = snd_ftu_create_effect_volume_ctl(mixer);
1133 	if (err < 0)
1134 		return err;
1135 
1136 	err = snd_ftu_create_effect_duration_ctl(mixer);
1137 	if (err < 0)
1138 		return err;
1139 
1140 	err = snd_ftu_create_effect_feedback_ctl(mixer);
1141 	if (err < 0)
1142 		return err;
1143 
1144 	err = snd_ftu_create_effect_return_ctls(mixer);
1145 	if (err < 0)
1146 		return err;
1147 
1148 	err = snd_ftu_create_effect_send_ctls(mixer);
1149 	if (err < 0)
1150 		return err;
1151 
1152 	return 0;
1153 }
1154 
1155 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1156 			       unsigned char samplerate_id)
1157 {
1158 	struct usb_mixer_interface *mixer;
1159 	struct usb_mixer_elem_info *cval;
1160 	int unitid = 12; /* SampleRate ExtensionUnit ID */
1161 
1162 	list_for_each_entry(mixer, &chip->mixer_list, list) {
1163 		if (mixer->id_elems[unitid]) {
1164 			cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1165 			snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1166 						    cval->control << 8,
1167 						    samplerate_id);
1168 			snd_usb_mixer_notify_id(mixer, unitid);
1169 			break;
1170 		}
1171 	}
1172 }
1173 
1174 /* M-Audio Fast Track C400/C600 */
1175 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1176 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1177 {
1178 	char name[64];
1179 	unsigned int cmask, offset;
1180 	int out, chan, err;
1181 	int num_outs = 0;
1182 	int num_ins = 0;
1183 
1184 	const unsigned int id = 0x40;
1185 	const int val_type = USB_MIXER_S16;
1186 	const int control = 1;
1187 
1188 	switch (mixer->chip->usb_id) {
1189 	case USB_ID(0x0763, 0x2030):
1190 		num_outs = 6;
1191 		num_ins = 4;
1192 		break;
1193 	case USB_ID(0x0763, 0x2031):
1194 		num_outs = 8;
1195 		num_ins = 6;
1196 		break;
1197 	}
1198 
1199 	for (chan = 0; chan < num_outs + num_ins; chan++) {
1200 		for (out = 0; out < num_outs; out++) {
1201 			if (chan < num_outs) {
1202 				snprintf(name, sizeof(name),
1203 					"PCM%d-Out%d Playback Volume",
1204 					chan + 1, out + 1);
1205 			} else {
1206 				snprintf(name, sizeof(name),
1207 					"In%d-Out%d Playback Volume",
1208 					chan - num_outs + 1, out + 1);
1209 			}
1210 
1211 			cmask = (out == 0) ? 0 : 1 << (out - 1);
1212 			offset = chan * num_outs;
1213 			err = snd_create_std_mono_ctl_offset(mixer, id, control,
1214 						cmask, val_type, offset, name,
1215 						&snd_usb_mixer_vol_tlv);
1216 			if (err < 0)
1217 				return err;
1218 		}
1219 	}
1220 
1221 	return 0;
1222 }
1223 
1224 /* This control needs a volume quirk, see mixer.c */
1225 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1226 {
1227 	static const char name[] = "Effect Volume";
1228 	const unsigned int id = 0x43;
1229 	const int val_type = USB_MIXER_U8;
1230 	const unsigned int control = 3;
1231 	const unsigned int cmask = 0;
1232 
1233 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1234 					name, snd_usb_mixer_vol_tlv);
1235 }
1236 
1237 /* This control needs a volume quirk, see mixer.c */
1238 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1239 {
1240 	static const char name[] = "Effect Duration";
1241 	const unsigned int id = 0x43;
1242 	const int val_type = USB_MIXER_S16;
1243 	const unsigned int control = 4;
1244 	const unsigned int cmask = 0;
1245 
1246 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1247 					name, snd_usb_mixer_vol_tlv);
1248 }
1249 
1250 /* This control needs a volume quirk, see mixer.c */
1251 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1252 {
1253 	static const char name[] = "Effect Feedback Volume";
1254 	const unsigned int id = 0x43;
1255 	const int val_type = USB_MIXER_U8;
1256 	const unsigned int control = 5;
1257 	const unsigned int cmask = 0;
1258 
1259 	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1260 					name, NULL);
1261 }
1262 
1263 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1264 {
1265 	char name[64];
1266 	unsigned int cmask;
1267 	int chan, err;
1268 	int num_outs = 0;
1269 	int num_ins = 0;
1270 
1271 	const unsigned int id = 0x42;
1272 	const int val_type = USB_MIXER_S16;
1273 	const int control = 1;
1274 
1275 	switch (mixer->chip->usb_id) {
1276 	case USB_ID(0x0763, 0x2030):
1277 		num_outs = 6;
1278 		num_ins = 4;
1279 		break;
1280 	case USB_ID(0x0763, 0x2031):
1281 		num_outs = 8;
1282 		num_ins = 6;
1283 		break;
1284 	}
1285 
1286 	for (chan = 0; chan < num_outs + num_ins; chan++) {
1287 		if (chan < num_outs) {
1288 			snprintf(name, sizeof(name),
1289 				"Effect Send DOut%d",
1290 				chan + 1);
1291 		} else {
1292 			snprintf(name, sizeof(name),
1293 				"Effect Send AIn%d",
1294 				chan - num_outs + 1);
1295 		}
1296 
1297 		cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1298 		err = snd_create_std_mono_ctl(mixer, id, control,
1299 						cmask, val_type, name,
1300 						&snd_usb_mixer_vol_tlv);
1301 		if (err < 0)
1302 			return err;
1303 	}
1304 
1305 	return 0;
1306 }
1307 
1308 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1309 {
1310 	char name[64];
1311 	unsigned int cmask;
1312 	int chan, err;
1313 	int num_outs = 0;
1314 	int offset = 0;
1315 
1316 	const unsigned int id = 0x40;
1317 	const int val_type = USB_MIXER_S16;
1318 	const int control = 1;
1319 
1320 	switch (mixer->chip->usb_id) {
1321 	case USB_ID(0x0763, 0x2030):
1322 		num_outs = 6;
1323 		offset = 0x3c;
1324 		/* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1325 		break;
1326 	case USB_ID(0x0763, 0x2031):
1327 		num_outs = 8;
1328 		offset = 0x70;
1329 		/* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1330 		break;
1331 	}
1332 
1333 	for (chan = 0; chan < num_outs; chan++) {
1334 		snprintf(name, sizeof(name),
1335 			"Effect Return %d",
1336 			chan + 1);
1337 
1338 		cmask = (chan == 0) ? 0 :
1339 			1 << (chan + (chan % 2) * num_outs - 1);
1340 		err = snd_create_std_mono_ctl_offset(mixer, id, control,
1341 						cmask, val_type, offset, name,
1342 						&snd_usb_mixer_vol_tlv);
1343 		if (err < 0)
1344 			return err;
1345 	}
1346 
1347 	return 0;
1348 }
1349 
1350 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1351 {
1352 	int err;
1353 
1354 	err = snd_c400_create_vol_ctls(mixer);
1355 	if (err < 0)
1356 		return err;
1357 
1358 	err = snd_c400_create_effect_vol_ctls(mixer);
1359 	if (err < 0)
1360 		return err;
1361 
1362 	err = snd_c400_create_effect_ret_vol_ctls(mixer);
1363 	if (err < 0)
1364 		return err;
1365 
1366 	err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1367 	if (err < 0)
1368 		return err;
1369 
1370 	err = snd_c400_create_effect_volume_ctl(mixer);
1371 	if (err < 0)
1372 		return err;
1373 
1374 	err = snd_c400_create_effect_duration_ctl(mixer);
1375 	if (err < 0)
1376 		return err;
1377 
1378 	err = snd_c400_create_effect_feedback_ctl(mixer);
1379 	if (err < 0)
1380 		return err;
1381 
1382 	return 0;
1383 }
1384 
1385 /*
1386  * The mixer units for Ebox-44 are corrupt, and even where they
1387  * are valid they presents mono controls as L and R channels of
1388  * stereo. So we provide a good mixer here.
1389  */
1390 static const struct std_mono_table ebox44_table[] = {
1391 	{
1392 		.unitid = 4,
1393 		.control = 1,
1394 		.cmask = 0x0,
1395 		.val_type = USB_MIXER_INV_BOOLEAN,
1396 		.name = "Headphone Playback Switch"
1397 	},
1398 	{
1399 		.unitid = 4,
1400 		.control = 2,
1401 		.cmask = 0x1,
1402 		.val_type = USB_MIXER_S16,
1403 		.name = "Headphone A Mix Playback Volume"
1404 	},
1405 	{
1406 		.unitid = 4,
1407 		.control = 2,
1408 		.cmask = 0x2,
1409 		.val_type = USB_MIXER_S16,
1410 		.name = "Headphone B Mix Playback Volume"
1411 	},
1412 
1413 	{
1414 		.unitid = 7,
1415 		.control = 1,
1416 		.cmask = 0x0,
1417 		.val_type = USB_MIXER_INV_BOOLEAN,
1418 		.name = "Output Playback Switch"
1419 	},
1420 	{
1421 		.unitid = 7,
1422 		.control = 2,
1423 		.cmask = 0x1,
1424 		.val_type = USB_MIXER_S16,
1425 		.name = "Output A Playback Volume"
1426 	},
1427 	{
1428 		.unitid = 7,
1429 		.control = 2,
1430 		.cmask = 0x2,
1431 		.val_type = USB_MIXER_S16,
1432 		.name = "Output B Playback Volume"
1433 	},
1434 
1435 	{
1436 		.unitid = 10,
1437 		.control = 1,
1438 		.cmask = 0x0,
1439 		.val_type = USB_MIXER_INV_BOOLEAN,
1440 		.name = "Input Capture Switch"
1441 	},
1442 	{
1443 		.unitid = 10,
1444 		.control = 2,
1445 		.cmask = 0x1,
1446 		.val_type = USB_MIXER_S16,
1447 		.name = "Input A Capture Volume"
1448 	},
1449 	{
1450 		.unitid = 10,
1451 		.control = 2,
1452 		.cmask = 0x2,
1453 		.val_type = USB_MIXER_S16,
1454 		.name = "Input B Capture Volume"
1455 	},
1456 
1457 	{}
1458 };
1459 
1460 /* Audio Advantage Micro II findings:
1461  *
1462  * Mapping spdif AES bits to vendor register.bit:
1463  * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1464  * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1465  * AES2: [0 0 0 0 0 0 0 0]
1466  * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1467  *                           (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1468  *
1469  * power on values:
1470  * r2: 0x10
1471  * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1472  *           just after it to 0xa0, presumably it disables/mutes some analog
1473  *           parts when there is no audio.)
1474  * r9: 0x28
1475  *
1476  * Optical transmitter on/off:
1477  * vendor register.bit: 9.1
1478  * 0 - on (0x28 register value)
1479  * 1 - off (0x2a register value)
1480  *
1481  */
1482 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1483 	struct snd_ctl_elem_info *uinfo)
1484 {
1485 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1486 	uinfo->count = 1;
1487 	return 0;
1488 }
1489 
1490 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1491 	struct snd_ctl_elem_value *ucontrol)
1492 {
1493 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1494 	struct snd_usb_audio *chip = list->mixer->chip;
1495 	int err;
1496 	struct usb_interface *iface;
1497 	struct usb_host_interface *alts;
1498 	unsigned int ep;
1499 	unsigned char data[3];
1500 	int rate;
1501 
1502 	err = snd_usb_lock_shutdown(chip);
1503 	if (err < 0)
1504 		return err;
1505 
1506 	ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1507 	ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1508 	ucontrol->value.iec958.status[2] = 0x00;
1509 
1510 	/* use known values for that card: interface#1 altsetting#1 */
1511 	iface = usb_ifnum_to_if(chip->dev, 1);
1512 	if (!iface || iface->num_altsetting < 2)
1513 		return -EINVAL;
1514 	alts = &iface->altsetting[1];
1515 	if (get_iface_desc(alts)->bNumEndpoints < 1)
1516 		return -EINVAL;
1517 	ep = get_endpoint(alts, 0)->bEndpointAddress;
1518 
1519 	err = snd_usb_ctl_msg(chip->dev,
1520 			usb_rcvctrlpipe(chip->dev, 0),
1521 			UAC_GET_CUR,
1522 			USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1523 			UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1524 			ep,
1525 			data,
1526 			sizeof(data));
1527 	if (err < 0)
1528 		goto end;
1529 
1530 	rate = data[0] | (data[1] << 8) | (data[2] << 16);
1531 	ucontrol->value.iec958.status[3] = (rate == 48000) ?
1532 			IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1533 
1534 	err = 0;
1535  end:
1536 	snd_usb_unlock_shutdown(chip);
1537 	return err;
1538 }
1539 
1540 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1541 {
1542 	struct snd_usb_audio *chip = list->mixer->chip;
1543 	unsigned int pval = list->kctl->private_value;
1544 	u8 reg;
1545 	int err;
1546 
1547 	err = snd_usb_lock_shutdown(chip);
1548 	if (err < 0)
1549 		return err;
1550 
1551 	reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1552 	err = snd_usb_ctl_msg(chip->dev,
1553 			usb_sndctrlpipe(chip->dev, 0),
1554 			UAC_SET_CUR,
1555 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1556 			reg,
1557 			2,
1558 			NULL,
1559 			0);
1560 	if (err < 0)
1561 		goto end;
1562 
1563 	reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1564 	reg |= (pval >> 12) & 0x0f;
1565 	err = snd_usb_ctl_msg(chip->dev,
1566 			usb_sndctrlpipe(chip->dev, 0),
1567 			UAC_SET_CUR,
1568 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1569 			reg,
1570 			3,
1571 			NULL,
1572 			0);
1573 	if (err < 0)
1574 		goto end;
1575 
1576  end:
1577 	snd_usb_unlock_shutdown(chip);
1578 	return err;
1579 }
1580 
1581 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1582 	struct snd_ctl_elem_value *ucontrol)
1583 {
1584 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1585 	unsigned int pval, pval_old;
1586 	int err;
1587 
1588 	pval = pval_old = kcontrol->private_value;
1589 	pval &= 0xfffff0f0;
1590 	pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1591 	pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1592 
1593 	pval &= 0xffff0fff;
1594 	pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1595 
1596 	/* The frequency bits in AES3 cannot be set via register access. */
1597 
1598 	/* Silently ignore any bits from the request that cannot be set. */
1599 
1600 	if (pval == pval_old)
1601 		return 0;
1602 
1603 	kcontrol->private_value = pval;
1604 	err = snd_microii_spdif_default_update(list);
1605 	return err < 0 ? err : 1;
1606 }
1607 
1608 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1609 	struct snd_ctl_elem_value *ucontrol)
1610 {
1611 	ucontrol->value.iec958.status[0] = 0x0f;
1612 	ucontrol->value.iec958.status[1] = 0xff;
1613 	ucontrol->value.iec958.status[2] = 0x00;
1614 	ucontrol->value.iec958.status[3] = 0x00;
1615 
1616 	return 0;
1617 }
1618 
1619 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1620 	struct snd_ctl_elem_value *ucontrol)
1621 {
1622 	ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1623 
1624 	return 0;
1625 }
1626 
1627 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1628 {
1629 	struct snd_usb_audio *chip = list->mixer->chip;
1630 	u8 reg = list->kctl->private_value;
1631 	int err;
1632 
1633 	err = snd_usb_lock_shutdown(chip);
1634 	if (err < 0)
1635 		return err;
1636 
1637 	err = snd_usb_ctl_msg(chip->dev,
1638 			usb_sndctrlpipe(chip->dev, 0),
1639 			UAC_SET_CUR,
1640 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1641 			reg,
1642 			9,
1643 			NULL,
1644 			0);
1645 
1646 	snd_usb_unlock_shutdown(chip);
1647 	return err;
1648 }
1649 
1650 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1651 	struct snd_ctl_elem_value *ucontrol)
1652 {
1653 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1654 	u8 reg;
1655 	int err;
1656 
1657 	reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1658 	if (reg != list->kctl->private_value)
1659 		return 0;
1660 
1661 	kcontrol->private_value = reg;
1662 	err = snd_microii_spdif_switch_update(list);
1663 	return err < 0 ? err : 1;
1664 }
1665 
1666 static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1667 	{
1668 		.iface =    SNDRV_CTL_ELEM_IFACE_PCM,
1669 		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1670 		.info =     snd_microii_spdif_info,
1671 		.get =      snd_microii_spdif_default_get,
1672 		.put =      snd_microii_spdif_default_put,
1673 		.private_value = 0x00000100UL,/* reset value */
1674 	},
1675 	{
1676 		.access =   SNDRV_CTL_ELEM_ACCESS_READ,
1677 		.iface =    SNDRV_CTL_ELEM_IFACE_PCM,
1678 		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1679 		.info =     snd_microii_spdif_info,
1680 		.get =      snd_microii_spdif_mask_get,
1681 	},
1682 	{
1683 		.iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
1684 		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1685 		.info =     snd_ctl_boolean_mono_info,
1686 		.get =      snd_microii_spdif_switch_get,
1687 		.put =      snd_microii_spdif_switch_put,
1688 		.private_value = 0x00000028UL,/* reset value */
1689 	}
1690 };
1691 
1692 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1693 {
1694 	int err, i;
1695 	static const usb_mixer_elem_resume_func_t resume_funcs[] = {
1696 		snd_microii_spdif_default_update,
1697 		NULL,
1698 		snd_microii_spdif_switch_update
1699 	};
1700 
1701 	for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1702 		err = add_single_ctl_with_resume(mixer, 0,
1703 						 resume_funcs[i],
1704 						 &snd_microii_mixer_spdif[i],
1705 						 NULL);
1706 		if (err < 0)
1707 			return err;
1708 	}
1709 
1710 	return 0;
1711 }
1712 
1713 /* Creative Sound Blaster E1 */
1714 
1715 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1716 					  struct snd_ctl_elem_value *ucontrol)
1717 {
1718 	ucontrol->value.integer.value[0] = kcontrol->private_value;
1719 	return 0;
1720 }
1721 
1722 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1723 					     unsigned char state)
1724 {
1725 	struct snd_usb_audio *chip = mixer->chip;
1726 	int err;
1727 	unsigned char buff[2];
1728 
1729 	buff[0] = 0x02;
1730 	buff[1] = state ? 0x02 : 0x00;
1731 
1732 	err = snd_usb_lock_shutdown(chip);
1733 	if (err < 0)
1734 		return err;
1735 	err = snd_usb_ctl_msg(chip->dev,
1736 			usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1737 			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1738 			0x0202, 3, buff, 2);
1739 	snd_usb_unlock_shutdown(chip);
1740 	return err;
1741 }
1742 
1743 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1744 					  struct snd_ctl_elem_value *ucontrol)
1745 {
1746 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1747 	unsigned char value = !!ucontrol->value.integer.value[0];
1748 	int err;
1749 
1750 	if (kcontrol->private_value == value)
1751 		return 0;
1752 	kcontrol->private_value = value;
1753 	err = snd_soundblaster_e1_switch_update(list->mixer, value);
1754 	return err < 0 ? err : 1;
1755 }
1756 
1757 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1758 {
1759 	return snd_soundblaster_e1_switch_update(list->mixer,
1760 						 list->kctl->private_value);
1761 }
1762 
1763 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1764 					   struct snd_ctl_elem_info *uinfo)
1765 {
1766 	static const char *const texts[2] = {
1767 		"Mic", "Aux"
1768 	};
1769 
1770 	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1771 }
1772 
1773 static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1774 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1775 	.name = "Input Source",
1776 	.info = snd_soundblaster_e1_switch_info,
1777 	.get = snd_soundblaster_e1_switch_get,
1778 	.put = snd_soundblaster_e1_switch_put,
1779 	.private_value = 0,
1780 };
1781 
1782 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1783 {
1784 	return add_single_ctl_with_resume(mixer, 0,
1785 					  snd_soundblaster_e1_switch_resume,
1786 					  &snd_soundblaster_e1_input_switch,
1787 					  NULL);
1788 }
1789 
1790 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1791 {
1792 	u16 buf = 0;
1793 
1794 	snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1795 			USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1796 			ch, snd_usb_ctrl_intf(chip) | (id << 8),
1797 			&buf, 2);
1798 }
1799 
1800 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1801 {
1802 	/* fix to 0dB playback volumes */
1803 	dell_dock_init_vol(mixer->chip, 1, 16);
1804 	dell_dock_init_vol(mixer->chip, 2, 16);
1805 	dell_dock_init_vol(mixer->chip, 1, 19);
1806 	dell_dock_init_vol(mixer->chip, 2, 19);
1807 	return 0;
1808 }
1809 
1810 /* RME Class Compliant device quirks */
1811 
1812 #define SND_RME_GET_STATUS1			23
1813 #define SND_RME_GET_CURRENT_FREQ		17
1814 #define SND_RME_CLK_SYSTEM_SHIFT		16
1815 #define SND_RME_CLK_SYSTEM_MASK			0x1f
1816 #define SND_RME_CLK_AES_SHIFT			8
1817 #define SND_RME_CLK_SPDIF_SHIFT			12
1818 #define SND_RME_CLK_AES_SPDIF_MASK		0xf
1819 #define SND_RME_CLK_SYNC_SHIFT			6
1820 #define SND_RME_CLK_SYNC_MASK			0x3
1821 #define SND_RME_CLK_FREQMUL_SHIFT		18
1822 #define SND_RME_CLK_FREQMUL_MASK		0x7
1823 #define SND_RME_CLK_SYSTEM(x) \
1824 	((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1825 #define SND_RME_CLK_AES(x) \
1826 	((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1827 #define SND_RME_CLK_SPDIF(x) \
1828 	((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1829 #define SND_RME_CLK_SYNC(x) \
1830 	((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1831 #define SND_RME_CLK_FREQMUL(x) \
1832 	((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1833 #define SND_RME_CLK_AES_LOCK			0x1
1834 #define SND_RME_CLK_AES_SYNC			0x4
1835 #define SND_RME_CLK_SPDIF_LOCK			0x2
1836 #define SND_RME_CLK_SPDIF_SYNC			0x8
1837 #define SND_RME_SPDIF_IF_SHIFT			4
1838 #define SND_RME_SPDIF_FORMAT_SHIFT		5
1839 #define SND_RME_BINARY_MASK			0x1
1840 #define SND_RME_SPDIF_IF(x) \
1841 	((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1842 #define SND_RME_SPDIF_FORMAT(x) \
1843 	((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1844 
1845 static const u32 snd_rme_rate_table[] = {
1846 	32000, 44100, 48000, 50000,
1847 	64000, 88200, 96000, 100000,
1848 	128000, 176400, 192000, 200000,
1849 	256000,	352800, 384000, 400000,
1850 	512000, 705600, 768000, 800000
1851 };
1852 /* maximum number of items for AES and S/PDIF rates for above table */
1853 #define SND_RME_RATE_IDX_AES_SPDIF_NUM		12
1854 
1855 enum snd_rme_domain {
1856 	SND_RME_DOMAIN_SYSTEM,
1857 	SND_RME_DOMAIN_AES,
1858 	SND_RME_DOMAIN_SPDIF
1859 };
1860 
1861 enum snd_rme_clock_status {
1862 	SND_RME_CLOCK_NOLOCK,
1863 	SND_RME_CLOCK_LOCK,
1864 	SND_RME_CLOCK_SYNC
1865 };
1866 
1867 static int snd_rme_read_value(struct snd_usb_audio *chip,
1868 			      unsigned int item,
1869 			      u32 *value)
1870 {
1871 	struct usb_device *dev = chip->dev;
1872 	int err;
1873 
1874 	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1875 			      item,
1876 			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1877 			      0, 0,
1878 			      value, sizeof(*value));
1879 	if (err < 0)
1880 		dev_err(&dev->dev,
1881 			"unable to issue vendor read request %d (ret = %d)",
1882 			item, err);
1883 	return err;
1884 }
1885 
1886 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1887 			       u32 *status1)
1888 {
1889 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1890 	struct snd_usb_audio *chip = list->mixer->chip;
1891 	int err;
1892 
1893 	err = snd_usb_lock_shutdown(chip);
1894 	if (err < 0)
1895 		return err;
1896 	err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1897 	snd_usb_unlock_shutdown(chip);
1898 	return err;
1899 }
1900 
1901 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1902 			    struct snd_ctl_elem_value *ucontrol)
1903 {
1904 	u32 status1;
1905 	u32 rate = 0;
1906 	int idx;
1907 	int err;
1908 
1909 	err = snd_rme_get_status1(kcontrol, &status1);
1910 	if (err < 0)
1911 		return err;
1912 	switch (kcontrol->private_value) {
1913 	case SND_RME_DOMAIN_SYSTEM:
1914 		idx = SND_RME_CLK_SYSTEM(status1);
1915 		if (idx < ARRAY_SIZE(snd_rme_rate_table))
1916 			rate = snd_rme_rate_table[idx];
1917 		break;
1918 	case SND_RME_DOMAIN_AES:
1919 		idx = SND_RME_CLK_AES(status1);
1920 		if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1921 			rate = snd_rme_rate_table[idx];
1922 		break;
1923 	case SND_RME_DOMAIN_SPDIF:
1924 		idx = SND_RME_CLK_SPDIF(status1);
1925 		if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1926 			rate = snd_rme_rate_table[idx];
1927 		break;
1928 	default:
1929 		return -EINVAL;
1930 	}
1931 	ucontrol->value.integer.value[0] = rate;
1932 	return 0;
1933 }
1934 
1935 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1936 				  struct snd_ctl_elem_value *ucontrol)
1937 {
1938 	u32 status1;
1939 	int idx = SND_RME_CLOCK_NOLOCK;
1940 	int err;
1941 
1942 	err = snd_rme_get_status1(kcontrol, &status1);
1943 	if (err < 0)
1944 		return err;
1945 	switch (kcontrol->private_value) {
1946 	case SND_RME_DOMAIN_AES:  /* AES */
1947 		if (status1 & SND_RME_CLK_AES_SYNC)
1948 			idx = SND_RME_CLOCK_SYNC;
1949 		else if (status1 & SND_RME_CLK_AES_LOCK)
1950 			idx = SND_RME_CLOCK_LOCK;
1951 		break;
1952 	case SND_RME_DOMAIN_SPDIF:  /* SPDIF */
1953 		if (status1 & SND_RME_CLK_SPDIF_SYNC)
1954 			idx = SND_RME_CLOCK_SYNC;
1955 		else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1956 			idx = SND_RME_CLOCK_LOCK;
1957 		break;
1958 	default:
1959 		return -EINVAL;
1960 	}
1961 	ucontrol->value.enumerated.item[0] = idx;
1962 	return 0;
1963 }
1964 
1965 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1966 				struct snd_ctl_elem_value *ucontrol)
1967 {
1968 	u32 status1;
1969 	int err;
1970 
1971 	err = snd_rme_get_status1(kcontrol, &status1);
1972 	if (err < 0)
1973 		return err;
1974 	ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1975 	return 0;
1976 }
1977 
1978 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1979 				    struct snd_ctl_elem_value *ucontrol)
1980 {
1981 	u32 status1;
1982 	int err;
1983 
1984 	err = snd_rme_get_status1(kcontrol, &status1);
1985 	if (err < 0)
1986 		return err;
1987 	ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1988 	return 0;
1989 }
1990 
1991 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1992 				   struct snd_ctl_elem_value *ucontrol)
1993 {
1994 	u32 status1;
1995 	int err;
1996 
1997 	err = snd_rme_get_status1(kcontrol, &status1);
1998 	if (err < 0)
1999 		return err;
2000 	ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2001 	return 0;
2002 }
2003 
2004 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2005 				    struct snd_ctl_elem_value *ucontrol)
2006 {
2007 	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2008 	struct snd_usb_audio *chip = list->mixer->chip;
2009 	u32 status1;
2010 	const u64 num = 104857600000000ULL;
2011 	u32 den;
2012 	unsigned int freq;
2013 	int err;
2014 
2015 	err = snd_usb_lock_shutdown(chip);
2016 	if (err < 0)
2017 		return err;
2018 	err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2019 	if (err < 0)
2020 		goto end;
2021 	err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2022 	if (err < 0)
2023 		goto end;
2024 	freq = (den == 0) ? 0 : div64_u64(num, den);
2025 	freq <<= SND_RME_CLK_FREQMUL(status1);
2026 	ucontrol->value.integer.value[0] = freq;
2027 
2028 end:
2029 	snd_usb_unlock_shutdown(chip);
2030 	return err;
2031 }
2032 
2033 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2034 			     struct snd_ctl_elem_info *uinfo)
2035 {
2036 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2037 	uinfo->count = 1;
2038 	switch (kcontrol->private_value) {
2039 	case SND_RME_DOMAIN_SYSTEM:
2040 		uinfo->value.integer.min = 32000;
2041 		uinfo->value.integer.max = 800000;
2042 		break;
2043 	case SND_RME_DOMAIN_AES:
2044 	case SND_RME_DOMAIN_SPDIF:
2045 	default:
2046 		uinfo->value.integer.min = 0;
2047 		uinfo->value.integer.max = 200000;
2048 	}
2049 	uinfo->value.integer.step = 0;
2050 	return 0;
2051 }
2052 
2053 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2054 				   struct snd_ctl_elem_info *uinfo)
2055 {
2056 	static const char *const sync_states[] = {
2057 		"No Lock", "Lock", "Sync"
2058 	};
2059 
2060 	return snd_ctl_enum_info(uinfo, 1,
2061 				 ARRAY_SIZE(sync_states), sync_states);
2062 }
2063 
2064 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2065 				 struct snd_ctl_elem_info *uinfo)
2066 {
2067 	static const char *const spdif_if[] = {
2068 		"Coaxial", "Optical"
2069 	};
2070 
2071 	return snd_ctl_enum_info(uinfo, 1,
2072 				 ARRAY_SIZE(spdif_if), spdif_if);
2073 }
2074 
2075 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2076 				     struct snd_ctl_elem_info *uinfo)
2077 {
2078 	static const char *const optical_type[] = {
2079 		"Consumer", "Professional"
2080 	};
2081 
2082 	return snd_ctl_enum_info(uinfo, 1,
2083 				 ARRAY_SIZE(optical_type), optical_type);
2084 }
2085 
2086 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2087 				    struct snd_ctl_elem_info *uinfo)
2088 {
2089 	static const char *const sync_sources[] = {
2090 		"Internal", "AES", "SPDIF", "Internal"
2091 	};
2092 
2093 	return snd_ctl_enum_info(uinfo, 1,
2094 				 ARRAY_SIZE(sync_sources), sync_sources);
2095 }
2096 
2097 static const struct snd_kcontrol_new snd_rme_controls[] = {
2098 	{
2099 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2100 		.name = "AES Rate",
2101 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2102 		.info = snd_rme_rate_info,
2103 		.get = snd_rme_rate_get,
2104 		.private_value = SND_RME_DOMAIN_AES
2105 	},
2106 	{
2107 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2108 		.name = "AES Sync",
2109 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2110 		.info = snd_rme_sync_state_info,
2111 		.get = snd_rme_sync_state_get,
2112 		.private_value = SND_RME_DOMAIN_AES
2113 	},
2114 	{
2115 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2116 		.name = "SPDIF Rate",
2117 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2118 		.info = snd_rme_rate_info,
2119 		.get = snd_rme_rate_get,
2120 		.private_value = SND_RME_DOMAIN_SPDIF
2121 	},
2122 	{
2123 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2124 		.name = "SPDIF Sync",
2125 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2126 		.info = snd_rme_sync_state_info,
2127 		.get = snd_rme_sync_state_get,
2128 		.private_value = SND_RME_DOMAIN_SPDIF
2129 	},
2130 	{
2131 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2132 		.name = "SPDIF Interface",
2133 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2134 		.info = snd_rme_spdif_if_info,
2135 		.get = snd_rme_spdif_if_get,
2136 	},
2137 	{
2138 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2139 		.name = "SPDIF Format",
2140 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2141 		.info = snd_rme_spdif_format_info,
2142 		.get = snd_rme_spdif_format_get,
2143 	},
2144 	{
2145 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2146 		.name = "Sync Source",
2147 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2148 		.info = snd_rme_sync_source_info,
2149 		.get = snd_rme_sync_source_get
2150 	},
2151 	{
2152 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2153 		.name = "System Rate",
2154 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2155 		.info = snd_rme_rate_info,
2156 		.get = snd_rme_rate_get,
2157 		.private_value = SND_RME_DOMAIN_SYSTEM
2158 	},
2159 	{
2160 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2161 		.name = "Current Frequency",
2162 		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2163 		.info = snd_rme_rate_info,
2164 		.get = snd_rme_current_freq_get
2165 	}
2166 };
2167 
2168 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2169 {
2170 	int err, i;
2171 
2172 	for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2173 		err = add_single_ctl_with_resume(mixer, 0,
2174 						 NULL,
2175 						 &snd_rme_controls[i],
2176 						 NULL);
2177 		if (err < 0)
2178 			return err;
2179 	}
2180 
2181 	return 0;
2182 }
2183 
2184 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2185 {
2186 	int err = 0;
2187 
2188 	err = snd_usb_soundblaster_remote_init(mixer);
2189 	if (err < 0)
2190 		return err;
2191 
2192 	switch (mixer->chip->usb_id) {
2193 	/* Tascam US-16x08 */
2194 	case USB_ID(0x0644, 0x8047):
2195 		err = snd_us16x08_controls_create(mixer);
2196 		break;
2197 	case USB_ID(0x041e, 0x3020):
2198 	case USB_ID(0x041e, 0x3040):
2199 	case USB_ID(0x041e, 0x3042):
2200 	case USB_ID(0x041e, 0x30df):
2201 	case USB_ID(0x041e, 0x3048):
2202 		err = snd_audigy2nx_controls_create(mixer);
2203 		if (err < 0)
2204 			break;
2205 		snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2206 				     mixer, snd_audigy2nx_proc_read);
2207 		break;
2208 
2209 	/* EMU0204 */
2210 	case USB_ID(0x041e, 0x3f19):
2211 		err = snd_emu0204_controls_create(mixer);
2212 		break;
2213 
2214 	case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2215 	case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2216 		err = snd_c400_create_mixer(mixer);
2217 		break;
2218 
2219 	case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2220 	case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2221 		err = snd_ftu_create_mixer(mixer);
2222 		break;
2223 
2224 	case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2225 	case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2226 	case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2227 		err = snd_xonar_u1_controls_create(mixer);
2228 		break;
2229 
2230 	case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2231 		err = snd_microii_controls_create(mixer);
2232 		break;
2233 
2234 	case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2235 		err = snd_mbox1_create_sync_switch(mixer);
2236 		break;
2237 
2238 	case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2239 		err = snd_nativeinstruments_create_mixer(mixer,
2240 				snd_nativeinstruments_ta6_mixers,
2241 				ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2242 		break;
2243 
2244 	case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2245 		err = snd_nativeinstruments_create_mixer(mixer,
2246 				snd_nativeinstruments_ta10_mixers,
2247 				ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2248 		break;
2249 
2250 	case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2251 		/* detection is disabled in mixer_maps.c */
2252 		err = snd_create_std_mono_table(mixer, ebox44_table);
2253 		break;
2254 
2255 	case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2256 	case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2257 	case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2258 	case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2259 	case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2260 		err = snd_scarlett_controls_create(mixer);
2261 		break;
2262 
2263 	case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
2264 	case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
2265 	case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
2266 		err = snd_scarlett_gen2_controls_create(mixer);
2267 		break;
2268 
2269 	case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2270 		err = snd_soundblaster_e1_switch_create(mixer);
2271 		break;
2272 	case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2273 		err = dell_dock_mixer_init(mixer);
2274 		break;
2275 
2276 	case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2277 	case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2278 	case USB_ID(0x2a39, 0x3fd4): /* RME */
2279 		err = snd_rme_controls_create(mixer);
2280 		break;
2281 
2282 	case USB_ID(0x0194f, 0x010c): /* Presonus Studio 1810c */
2283 		err = snd_sc1810_init_mixer(mixer);
2284 		break;
2285 	}
2286 
2287 	return err;
2288 }
2289 
2290 #ifdef CONFIG_PM
2291 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2292 {
2293 	switch (mixer->chip->usb_id) {
2294 	case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2295 		dell_dock_mixer_init(mixer);
2296 		break;
2297 	}
2298 }
2299 #endif
2300 
2301 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2302 				    int unitid)
2303 {
2304 	if (!mixer->rc_cfg)
2305 		return;
2306 	/* unit ids specific to Extigy/Audigy 2 NX: */
2307 	switch (unitid) {
2308 	case 0: /* remote control */
2309 		mixer->rc_urb->dev = mixer->chip->dev;
2310 		usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2311 		break;
2312 	case 4: /* digital in jack */
2313 	case 7: /* line in jacks */
2314 	case 19: /* speaker out jacks */
2315 	case 20: /* headphones out jack */
2316 		break;
2317 	/* live24ext: 4 = line-in jack */
2318 	case 3:	/* hp-out jack (may actuate Mute) */
2319 		if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2320 		    mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2321 			snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2322 		break;
2323 	default:
2324 		usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2325 		break;
2326 	}
2327 }
2328 
2329 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2330 					 struct usb_mixer_elem_info *cval,
2331 					 struct snd_kcontrol *kctl)
2332 {
2333 	/* Approximation using 10 ranges based on output measurement on hw v1.2.
2334 	 * This seems close to the cubic mapping e.g. alsamixer uses. */
2335 	static const DECLARE_TLV_DB_RANGE(scale,
2336 		 0,  1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2337 		 2,  5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2338 		 6,  7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2339 		 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2340 		15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2341 		17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2342 		20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2343 		27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2344 		32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2345 		41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2346 	);
2347 
2348 	if (cval->min == 0 && cval->max == 50) {
2349 		usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2350 		kctl->tlv.p = scale;
2351 		kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2352 		kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2353 
2354 	} else if (cval->min == 0 && cval->max <= 1000) {
2355 		/* Some other clearly broken DragonFly variant.
2356 		 * At least a 0..53 variant (hw v1.0) exists.
2357 		 */
2358 		usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2359 		kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2360 	}
2361 }
2362 
2363 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2364 				  struct usb_mixer_elem_info *cval, int unitid,
2365 				  struct snd_kcontrol *kctl)
2366 {
2367 	switch (mixer->chip->usb_id) {
2368 	case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2369 		if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2370 			snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2371 		break;
2372 	/* lowest playback value is muted on C-Media devices */
2373 	case USB_ID(0x0d8c, 0x000c):
2374 	case USB_ID(0x0d8c, 0x0014):
2375 		if (strstr(kctl->id.name, "Playback"))
2376 			cval->min_mute = 1;
2377 		break;
2378 	}
2379 }
2380 
2381