GNU Linux-libre 4.14.259-gnu1
[releases.git] / sound / usb / mixer_quirks.c
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  *   Audio Advantage Micro II support added by:
13  *          Przemek Rudy (prudy1@o2.pl)
14  *
15  *   This program is free software; you can redistribute it and/or modify
16  *   it under the terms of the GNU General Public License as published by
17  *   the Free Software Foundation; either version 2 of the License, or
18  *   (at your option) any later version.
19  *
20  *   This program is distributed in the hope that it will be useful,
21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   GNU General Public License for more details.
24  *
25  *   You should have received a copy of the GNU General Public License
26  *   along with this program; if not, write to the Free Software
27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28  */
29
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/usb.h>
33 #include <linux/usb/audio.h>
34
35 #include <sound/asoundef.h>
36 #include <sound/core.h>
37 #include <sound/control.h>
38 #include <sound/hwdep.h>
39 #include <sound/info.h>
40 #include <sound/tlv.h>
41
42 #include "usbaudio.h"
43 #include "mixer.h"
44 #include "mixer_quirks.h"
45 #include "mixer_scarlett.h"
46 #include "mixer_us16x08.h"
47 #include "helper.h"
48
49 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
50
51 struct std_mono_table {
52         unsigned int unitid, control, cmask;
53         int val_type;
54         const char *name;
55         snd_kcontrol_tlv_rw_t *tlv_callback;
56 };
57
58 /* This function allows for the creation of standard UAC controls.
59  * See the quirks for M-Audio FTUs or Ebox-44.
60  * If you don't want to set a TLV callback pass NULL.
61  *
62  * Since there doesn't seem to be a devices that needs a multichannel
63  * version, we keep it mono for simplicity.
64  */
65 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
66                                 unsigned int unitid,
67                                 unsigned int control,
68                                 unsigned int cmask,
69                                 int val_type,
70                                 unsigned int idx_off,
71                                 const char *name,
72                                 snd_kcontrol_tlv_rw_t *tlv_callback)
73 {
74         struct usb_mixer_elem_info *cval;
75         struct snd_kcontrol *kctl;
76
77         cval = kzalloc(sizeof(*cval), GFP_KERNEL);
78         if (!cval)
79                 return -ENOMEM;
80
81         snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
82         cval->val_type = val_type;
83         cval->channels = 1;
84         cval->control = control;
85         cval->cmask = cmask;
86         cval->idx_off = idx_off;
87
88         /* get_min_max() is called only for integer volumes later,
89          * so provide a short-cut for booleans */
90         cval->min = 0;
91         cval->max = 1;
92         cval->res = 0;
93         cval->dBmin = 0;
94         cval->dBmax = 0;
95
96         /* Create control */
97         kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
98         if (!kctl) {
99                 kfree(cval);
100                 return -ENOMEM;
101         }
102
103         /* Set name */
104         snprintf(kctl->id.name, sizeof(kctl->id.name), name);
105         kctl->private_free = snd_usb_mixer_elem_free;
106
107         /* set TLV */
108         if (tlv_callback) {
109                 kctl->tlv.c = tlv_callback;
110                 kctl->vd[0].access |=
111                         SNDRV_CTL_ELEM_ACCESS_TLV_READ |
112                         SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
113         }
114         /* Add control to mixer */
115         return snd_usb_mixer_add_control(&cval->head, kctl);
116 }
117
118 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
119                                 unsigned int unitid,
120                                 unsigned int control,
121                                 unsigned int cmask,
122                                 int val_type,
123                                 const char *name,
124                                 snd_kcontrol_tlv_rw_t *tlv_callback)
125 {
126         return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
127                 val_type, 0 /* Offset */, name, tlv_callback);
128 }
129
130 /*
131  * Create a set of standard UAC controls from a table
132  */
133 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
134                                 struct std_mono_table *t)
135 {
136         int err;
137
138         while (t->name != NULL) {
139                 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
140                                 t->cmask, t->val_type, t->name, t->tlv_callback);
141                 if (err < 0)
142                         return err;
143                 t++;
144         }
145
146         return 0;
147 }
148
149 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
150                                       int id,
151                                       usb_mixer_elem_resume_func_t resume,
152                                       const struct snd_kcontrol_new *knew,
153                                       struct usb_mixer_elem_list **listp)
154 {
155         struct usb_mixer_elem_list *list;
156         struct snd_kcontrol *kctl;
157
158         list = kzalloc(sizeof(*list), GFP_KERNEL);
159         if (!list)
160                 return -ENOMEM;
161         if (listp)
162                 *listp = list;
163         list->mixer = mixer;
164         list->id = id;
165         list->resume = resume;
166         kctl = snd_ctl_new1(knew, list);
167         if (!kctl) {
168                 kfree(list);
169                 return -ENOMEM;
170         }
171         kctl->private_free = snd_usb_mixer_elem_free;
172         /* don't use snd_usb_mixer_add_control() here, this is a special list element */
173         return snd_usb_mixer_add_list(list, kctl, false);
174 }
175
176 /*
177  * Sound Blaster remote control configuration
178  *
179  * format of remote control data:
180  * Extigy:       xx 00
181  * Audigy 2 NX:  06 80 xx 00 00 00
182  * Live! 24-bit: 06 80 xx yy 22 83
183  */
184 static const struct rc_config {
185         u32 usb_id;
186         u8  offset;
187         u8  length;
188         u8  packet_length;
189         u8  min_packet_length; /* minimum accepted length of the URB result */
190         u8  mute_mixer_id;
191         u32 mute_code;
192 } rc_configs[] = {
193         { USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
194         { USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
195         { USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
196         { USB_ID(0x041e, 0x3042), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 */
197         { USB_ID(0x041e, 0x30df), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
198         { USB_ID(0x041e, 0x3237), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
199         { USB_ID(0x041e, 0x3263), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
200         { USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
201 };
202
203 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
204 {
205         struct usb_mixer_interface *mixer = urb->context;
206         const struct rc_config *rc = mixer->rc_cfg;
207         u32 code;
208
209         if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
210                 return;
211
212         code = mixer->rc_buffer[rc->offset];
213         if (rc->length == 2)
214                 code |= mixer->rc_buffer[rc->offset + 1] << 8;
215
216         /* the Mute button actually changes the mixer control */
217         if (code == rc->mute_code)
218                 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
219         mixer->rc_code = code;
220         wmb();
221         wake_up(&mixer->rc_waitq);
222 }
223
224 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
225                                      long count, loff_t *offset)
226 {
227         struct usb_mixer_interface *mixer = hw->private_data;
228         int err;
229         u32 rc_code;
230
231         if (count != 1 && count != 4)
232                 return -EINVAL;
233         err = wait_event_interruptible(mixer->rc_waitq,
234                                        (rc_code = xchg(&mixer->rc_code, 0)) != 0);
235         if (err == 0) {
236                 if (count == 1)
237                         err = put_user(rc_code, buf);
238                 else
239                         err = put_user(rc_code, (u32 __user *)buf);
240         }
241         return err < 0 ? err : count;
242 }
243
244 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
245                                             poll_table *wait)
246 {
247         struct usb_mixer_interface *mixer = hw->private_data;
248
249         poll_wait(file, &mixer->rc_waitq, wait);
250         return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
251 }
252
253 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
254 {
255         struct snd_hwdep *hwdep;
256         int err, len, i;
257
258         for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
259                 if (rc_configs[i].usb_id == mixer->chip->usb_id)
260                         break;
261         if (i >= ARRAY_SIZE(rc_configs))
262                 return 0;
263         mixer->rc_cfg = &rc_configs[i];
264
265         len = mixer->rc_cfg->packet_length;
266
267         init_waitqueue_head(&mixer->rc_waitq);
268         err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
269         if (err < 0)
270                 return err;
271         snprintf(hwdep->name, sizeof(hwdep->name),
272                  "%s remote control", mixer->chip->card->shortname);
273         hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
274         hwdep->private_data = mixer;
275         hwdep->ops.read = snd_usb_sbrc_hwdep_read;
276         hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
277         hwdep->exclusive = 1;
278
279         mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
280         if (!mixer->rc_urb)
281                 return -ENOMEM;
282         mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
283         if (!mixer->rc_setup_packet) {
284                 usb_free_urb(mixer->rc_urb);
285                 mixer->rc_urb = NULL;
286                 return -ENOMEM;
287         }
288         mixer->rc_setup_packet->bRequestType =
289                 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
290         mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
291         mixer->rc_setup_packet->wValue = cpu_to_le16(0);
292         mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
293         mixer->rc_setup_packet->wLength = cpu_to_le16(len);
294         usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
295                              usb_rcvctrlpipe(mixer->chip->dev, 0),
296                              (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
297                              snd_usb_soundblaster_remote_complete, mixer);
298         return 0;
299 }
300
301 #define snd_audigy2nx_led_info          snd_ctl_boolean_mono_info
302
303 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
304 {
305         ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
306         return 0;
307 }
308
309 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
310                                     int value, int index)
311 {
312         struct snd_usb_audio *chip = mixer->chip;
313         int err;
314
315         err = snd_usb_lock_shutdown(chip);
316         if (err < 0)
317                 return err;
318
319         if (chip->usb_id == USB_ID(0x041e, 0x3042))
320                 err = snd_usb_ctl_msg(chip->dev,
321                               usb_sndctrlpipe(chip->dev, 0), 0x24,
322                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
323                               !value, 0, NULL, 0);
324         /* USB X-Fi S51 Pro */
325         if (chip->usb_id == USB_ID(0x041e, 0x30df))
326                 err = snd_usb_ctl_msg(chip->dev,
327                               usb_sndctrlpipe(chip->dev, 0), 0x24,
328                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
329                               !value, 0, NULL, 0);
330         else
331                 err = snd_usb_ctl_msg(chip->dev,
332                               usb_sndctrlpipe(chip->dev, 0), 0x24,
333                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
334                               value, index + 2, NULL, 0);
335         snd_usb_unlock_shutdown(chip);
336         return err;
337 }
338
339 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
340                                  struct snd_ctl_elem_value *ucontrol)
341 {
342         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
343         struct usb_mixer_interface *mixer = list->mixer;
344         int index = kcontrol->private_value & 0xff;
345         unsigned int value = ucontrol->value.integer.value[0];
346         int old_value = kcontrol->private_value >> 8;
347         int err;
348
349         if (value > 1)
350                 return -EINVAL;
351         if (value == old_value)
352                 return 0;
353         kcontrol->private_value = (value << 8) | index;
354         err = snd_audigy2nx_led_update(mixer, value, index);
355         return err < 0 ? err : 1;
356 }
357
358 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
359 {
360         int priv_value = list->kctl->private_value;
361
362         return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
363                                         priv_value & 0xff);
364 }
365
366 /* name and private_value are set dynamically */
367 static const struct snd_kcontrol_new snd_audigy2nx_control = {
368         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
369         .info = snd_audigy2nx_led_info,
370         .get = snd_audigy2nx_led_get,
371         .put = snd_audigy2nx_led_put,
372 };
373
374 static const char * const snd_audigy2nx_led_names[] = {
375         "CMSS LED Switch",
376         "Power LED Switch",
377         "Dolby Digital LED Switch",
378 };
379
380 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
381 {
382         int i, err;
383
384         for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
385                 struct snd_kcontrol_new knew;
386
387                 /* USB X-Fi S51 doesn't have a CMSS LED */
388                 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
389                         continue;
390                 /* USB X-Fi S51 Pro doesn't have one either */
391                 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
392                         continue;
393                 if (i > 1 && /* Live24ext has 2 LEDs only */
394                         (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
395                          mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
396                          mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
397                          mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
398                         break; 
399
400                 knew = snd_audigy2nx_control;
401                 knew.name = snd_audigy2nx_led_names[i];
402                 knew.private_value = (1 << 8) | i; /* LED on as default */
403                 err = add_single_ctl_with_resume(mixer, 0,
404                                                  snd_audigy2nx_led_resume,
405                                                  &knew, NULL);
406                 if (err < 0)
407                         return err;
408         }
409         return 0;
410 }
411
412 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
413                                     struct snd_info_buffer *buffer)
414 {
415         static const struct sb_jack {
416                 int unitid;
417                 const char *name;
418         }  jacks_audigy2nx[] = {
419                 {4,  "dig in "},
420                 {7,  "line in"},
421                 {19, "spk out"},
422                 {20, "hph out"},
423                 {-1, NULL}
424         }, jacks_live24ext[] = {
425                 {4,  "line in"}, /* &1=Line, &2=Mic*/
426                 {3,  "hph out"}, /* headphones */
427                 {0,  "RC     "}, /* last command, 6 bytes see rc_config above */
428                 {-1, NULL}
429         };
430         const struct sb_jack *jacks;
431         struct usb_mixer_interface *mixer = entry->private_data;
432         int i, err;
433         u8 buf[3];
434
435         snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
436         if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
437                 jacks = jacks_audigy2nx;
438         else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
439                  mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
440                 jacks = jacks_live24ext;
441         else
442                 return;
443
444         for (i = 0; jacks[i].name; ++i) {
445                 snd_iprintf(buffer, "%s: ", jacks[i].name);
446                 err = snd_usb_lock_shutdown(mixer->chip);
447                 if (err < 0)
448                         return;
449                 err = snd_usb_ctl_msg(mixer->chip->dev,
450                                       usb_rcvctrlpipe(mixer->chip->dev, 0),
451                                       UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
452                                       USB_RECIP_INTERFACE, 0,
453                                       jacks[i].unitid << 8, buf, 3);
454                 snd_usb_unlock_shutdown(mixer->chip);
455                 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
456                         snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
457                 else
458                         snd_iprintf(buffer, "?\n");
459         }
460 }
461
462 /* EMU0204 */
463 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
464                                       struct snd_ctl_elem_info *uinfo)
465 {
466         static const char * const texts[2] = {"1/2", "3/4"};
467
468         return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
469 }
470
471 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
472                                      struct snd_ctl_elem_value *ucontrol)
473 {
474         ucontrol->value.enumerated.item[0] = kcontrol->private_value;
475         return 0;
476 }
477
478 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
479                                         int value)
480 {
481         struct snd_usb_audio *chip = mixer->chip;
482         int err;
483         unsigned char buf[2];
484
485         err = snd_usb_lock_shutdown(chip);
486         if (err < 0)
487                 return err;
488
489         buf[0] = 0x01;
490         buf[1] = value ? 0x02 : 0x01;
491         err = snd_usb_ctl_msg(chip->dev,
492                       usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
493                       USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
494                       0x0400, 0x0e00, buf, 2);
495         snd_usb_unlock_shutdown(chip);
496         return err;
497 }
498
499 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
500                                      struct snd_ctl_elem_value *ucontrol)
501 {
502         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
503         struct usb_mixer_interface *mixer = list->mixer;
504         unsigned int value = ucontrol->value.enumerated.item[0];
505         int err;
506
507         if (value > 1)
508                 return -EINVAL;
509
510         if (value == kcontrol->private_value)
511                 return 0;
512
513         kcontrol->private_value = value;
514         err = snd_emu0204_ch_switch_update(mixer, value);
515         return err < 0 ? err : 1;
516 }
517
518 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
519 {
520         return snd_emu0204_ch_switch_update(list->mixer,
521                                             list->kctl->private_value);
522 }
523
524 static struct snd_kcontrol_new snd_emu0204_control = {
525         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
526         .name = "Front Jack Channels",
527         .info = snd_emu0204_ch_switch_info,
528         .get = snd_emu0204_ch_switch_get,
529         .put = snd_emu0204_ch_switch_put,
530         .private_value = 0,
531 };
532
533 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
534 {
535         return add_single_ctl_with_resume(mixer, 0,
536                                           snd_emu0204_ch_switch_resume,
537                                           &snd_emu0204_control, NULL);
538 }
539
540 /* ASUS Xonar U1 / U3 controls */
541
542 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
543                                    struct snd_ctl_elem_value *ucontrol)
544 {
545         ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
546         return 0;
547 }
548
549 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
550                                       unsigned char status)
551 {
552         struct snd_usb_audio *chip = mixer->chip;
553         int err;
554
555         err = snd_usb_lock_shutdown(chip);
556         if (err < 0)
557                 return err;
558         err = snd_usb_ctl_msg(chip->dev,
559                               usb_sndctrlpipe(chip->dev, 0), 0x08,
560                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
561                               50, 0, &status, 1);
562         snd_usb_unlock_shutdown(chip);
563         return err;
564 }
565
566 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
567                                    struct snd_ctl_elem_value *ucontrol)
568 {
569         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
570         u8 old_status, new_status;
571         int err;
572
573         old_status = kcontrol->private_value;
574         if (ucontrol->value.integer.value[0])
575                 new_status = old_status | 0x02;
576         else
577                 new_status = old_status & ~0x02;
578         if (new_status == old_status)
579                 return 0;
580
581         kcontrol->private_value = new_status;
582         err = snd_xonar_u1_switch_update(list->mixer, new_status);
583         return err < 0 ? err : 1;
584 }
585
586 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
587 {
588         return snd_xonar_u1_switch_update(list->mixer,
589                                           list->kctl->private_value);
590 }
591
592 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
593         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
594         .name = "Digital Playback Switch",
595         .info = snd_ctl_boolean_mono_info,
596         .get = snd_xonar_u1_switch_get,
597         .put = snd_xonar_u1_switch_put,
598         .private_value = 0x05,
599 };
600
601 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
602 {
603         return add_single_ctl_with_resume(mixer, 0,
604                                           snd_xonar_u1_switch_resume,
605                                           &snd_xonar_u1_output_switch, NULL);
606 }
607
608 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
609
610 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
611                                 struct snd_ctl_elem_value *ucontrol)
612 {
613         ucontrol->value.enumerated.item[0] = kctl->private_value;
614         return 0;
615 }
616
617 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
618 {
619         struct snd_usb_audio *chip = mixer->chip;
620         int err;
621         unsigned char buff[3];
622
623         err = snd_usb_lock_shutdown(chip);
624         if (err < 0)
625                 return err;
626
627         /* Prepare for magic command to toggle clock source */
628         err = snd_usb_ctl_msg(chip->dev,
629                                 usb_rcvctrlpipe(chip->dev, 0), 0x81,
630                                 USB_DIR_IN |
631                                 USB_TYPE_CLASS |
632                                 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
633         if (err < 0)
634                 goto err;
635         err = snd_usb_ctl_msg(chip->dev,
636                                 usb_rcvctrlpipe(chip->dev, 0), 0x81,
637                                 USB_DIR_IN |
638                                 USB_TYPE_CLASS |
639                                 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
640         if (err < 0)
641                 goto err;
642
643         /* 2 possibilities:     Internal    -> send sample rate
644          *                      S/PDIF sync -> send zeroes
645          * NB: Sample rate locked to 48kHz on purpose to
646          *     prevent user from resetting the sample rate
647          *     while S/PDIF sync is enabled and confusing
648          *     this configuration.
649          */
650         if (val == 0) {
651                 buff[0] = 0x80;
652                 buff[1] = 0xbb;
653                 buff[2] = 0x00;
654         } else {
655                 buff[0] = buff[1] = buff[2] = 0x00;
656         }
657
658         /* Send the magic command to toggle the clock source */
659         err = snd_usb_ctl_msg(chip->dev,
660                                 usb_sndctrlpipe(chip->dev, 0), 0x1,
661                                 USB_TYPE_CLASS |
662                                 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
663         if (err < 0)
664                 goto err;
665         err = snd_usb_ctl_msg(chip->dev,
666                                 usb_rcvctrlpipe(chip->dev, 0), 0x81,
667                                 USB_DIR_IN |
668                                 USB_TYPE_CLASS |
669                                 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
670         if (err < 0)
671                 goto err;
672         err = snd_usb_ctl_msg(chip->dev,
673                                 usb_rcvctrlpipe(chip->dev, 0), 0x81,
674                                 USB_DIR_IN |
675                                 USB_TYPE_CLASS |
676                                 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
677         if (err < 0)
678                 goto err;
679
680 err:
681         snd_usb_unlock_shutdown(chip);
682         return err;
683 }
684
685 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
686                                 struct snd_ctl_elem_value *ucontrol)
687 {
688         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
689         struct usb_mixer_interface *mixer = list->mixer;
690         int err;
691         bool cur_val, new_val;
692
693         cur_val = kctl->private_value;
694         new_val = ucontrol->value.enumerated.item[0];
695         if (cur_val == new_val)
696                 return 0;
697
698         kctl->private_value = new_val;
699         err = snd_mbox1_switch_update(mixer, new_val);
700         return err < 0 ? err : 1;
701 }
702
703 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
704                                  struct snd_ctl_elem_info *uinfo)
705 {
706         static const char *const texts[2] = {
707                 "Internal",
708                 "S/PDIF"
709         };
710
711         return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
712 }
713
714 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
715 {
716         return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
717 }
718
719 static struct snd_kcontrol_new snd_mbox1_switch = {
720         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
721         .name = "Clock Source",
722         .index = 0,
723         .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
724         .info = snd_mbox1_switch_info,
725         .get = snd_mbox1_switch_get,
726         .put = snd_mbox1_switch_put,
727         .private_value = 0
728 };
729
730 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
731 {
732         return add_single_ctl_with_resume(mixer, 0,
733                                           snd_mbox1_switch_resume,
734                                           &snd_mbox1_switch, NULL);
735 }
736
737 /* Native Instruments device quirks */
738
739 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
740
741 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
742                                    struct snd_kcontrol *kctl)
743 {
744         struct usb_device *dev = mixer->chip->dev;
745         unsigned int pval = kctl->private_value;
746         u8 value;
747         int err;
748
749         err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
750                               (pval >> 16) & 0xff,
751                               USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
752                               0, pval & 0xffff, &value, 1);
753         if (err < 0) {
754                 dev_err(&dev->dev,
755                         "unable to issue vendor read request (ret = %d)", err);
756                 return err;
757         }
758
759         kctl->private_value |= ((unsigned int)value << 24);
760         return 0;
761 }
762
763 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
764                                              struct snd_ctl_elem_value *ucontrol)
765 {
766         ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
767         return 0;
768 }
769
770 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
771 {
772         struct snd_usb_audio *chip = list->mixer->chip;
773         unsigned int pval = list->kctl->private_value;
774         int err;
775
776         err = snd_usb_lock_shutdown(chip);
777         if (err < 0)
778                 return err;
779         err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
780                               (pval >> 16) & 0xff,
781                               USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
782                               pval >> 24, pval & 0xffff, NULL, 0, 1000);
783         snd_usb_unlock_shutdown(chip);
784         return err;
785 }
786
787 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
788                                              struct snd_ctl_elem_value *ucontrol)
789 {
790         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
791         u8 oldval = (kcontrol->private_value >> 24) & 0xff;
792         u8 newval = ucontrol->value.integer.value[0];
793         int err;
794
795         if (oldval == newval)
796                 return 0;
797
798         kcontrol->private_value &= ~(0xff << 24);
799         kcontrol->private_value |= (unsigned int)newval << 24;
800         err = snd_ni_update_cur_val(list);
801         return err < 0 ? err : 1;
802 }
803
804 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
805         {
806                 .name = "Direct Thru Channel A",
807                 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
808         },
809         {
810                 .name = "Direct Thru Channel B",
811                 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
812         },
813         {
814                 .name = "Phono Input Channel A",
815                 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
816         },
817         {
818                 .name = "Phono Input Channel B",
819                 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
820         },
821 };
822
823 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
824         {
825                 .name = "Direct Thru Channel A",
826                 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
827         },
828         {
829                 .name = "Direct Thru Channel B",
830                 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
831         },
832         {
833                 .name = "Direct Thru Channel C",
834                 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
835         },
836         {
837                 .name = "Direct Thru Channel D",
838                 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
839         },
840         {
841                 .name = "Phono Input Channel A",
842                 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
843         },
844         {
845                 .name = "Phono Input Channel B",
846                 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
847         },
848         {
849                 .name = "Phono Input Channel C",
850                 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
851         },
852         {
853                 .name = "Phono Input Channel D",
854                 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
855         },
856 };
857
858 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
859                                               const struct snd_kcontrol_new *kc,
860                                               unsigned int count)
861 {
862         int i, err = 0;
863         struct snd_kcontrol_new template = {
864                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
865                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
866                 .get = snd_nativeinstruments_control_get,
867                 .put = snd_nativeinstruments_control_put,
868                 .info = snd_ctl_boolean_mono_info,
869         };
870
871         for (i = 0; i < count; i++) {
872                 struct usb_mixer_elem_list *list;
873
874                 template.name = kc[i].name;
875                 template.private_value = kc[i].private_value;
876
877                 err = add_single_ctl_with_resume(mixer, 0,
878                                                  snd_ni_update_cur_val,
879                                                  &template, &list);
880                 if (err < 0)
881                         break;
882                 snd_ni_control_init_val(mixer, list->kctl);
883         }
884
885         return err;
886 }
887
888 /* M-Audio FastTrack Ultra quirks */
889 /* FTU Effect switch (also used by C400/C600) */
890 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
891                                         struct snd_ctl_elem_info *uinfo)
892 {
893         static const char *const texts[8] = {
894                 "Room 1", "Room 2", "Room 3", "Hall 1",
895                 "Hall 2", "Plate", "Delay", "Echo"
896         };
897
898         return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
899 }
900
901 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
902                                    struct snd_kcontrol *kctl)
903 {
904         struct usb_device *dev = mixer->chip->dev;
905         unsigned int pval = kctl->private_value;
906         int err;
907         unsigned char value[2];
908
909         value[0] = 0x00;
910         value[1] = 0x00;
911
912         err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
913                               USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
914                               pval & 0xff00,
915                               snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
916                               value, 2);
917         if (err < 0)
918                 return err;
919
920         kctl->private_value |= (unsigned int)value[0] << 24;
921         return 0;
922 }
923
924 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
925                                         struct snd_ctl_elem_value *ucontrol)
926 {
927         ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
928         return 0;
929 }
930
931 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
932 {
933         struct snd_usb_audio *chip = list->mixer->chip;
934         unsigned int pval = list->kctl->private_value;
935         unsigned char value[2];
936         int err;
937
938         value[0] = pval >> 24;
939         value[1] = 0;
940
941         err = snd_usb_lock_shutdown(chip);
942         if (err < 0)
943                 return err;
944         err = snd_usb_ctl_msg(chip->dev,
945                               usb_sndctrlpipe(chip->dev, 0),
946                               UAC_SET_CUR,
947                               USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
948                               pval & 0xff00,
949                               snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
950                               value, 2);
951         snd_usb_unlock_shutdown(chip);
952         return err;
953 }
954
955 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
956                                         struct snd_ctl_elem_value *ucontrol)
957 {
958         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
959         unsigned int pval = list->kctl->private_value;
960         int cur_val, err, new_val;
961
962         cur_val = pval >> 24;
963         new_val = ucontrol->value.enumerated.item[0];
964         if (cur_val == new_val)
965                 return 0;
966
967         kctl->private_value &= ~(0xff << 24);
968         kctl->private_value |= new_val << 24;
969         err = snd_ftu_eff_switch_update(list);
970         return err < 0 ? err : 1;
971 }
972
973 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
974         int validx, int bUnitID)
975 {
976         static struct snd_kcontrol_new template = {
977                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
978                 .name = "Effect Program Switch",
979                 .index = 0,
980                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
981                 .info = snd_ftu_eff_switch_info,
982                 .get = snd_ftu_eff_switch_get,
983                 .put = snd_ftu_eff_switch_put
984         };
985         struct usb_mixer_elem_list *list;
986         int err;
987
988         err = add_single_ctl_with_resume(mixer, bUnitID,
989                                          snd_ftu_eff_switch_update,
990                                          &template, &list);
991         if (err < 0)
992                 return err;
993         list->kctl->private_value = (validx << 8) | bUnitID;
994         snd_ftu_eff_switch_init(mixer, list->kctl);
995         return 0;
996 }
997
998 /* Create volume controls for FTU devices*/
999 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1000 {
1001         char name[64];
1002         unsigned int control, cmask;
1003         int in, out, err;
1004
1005         const unsigned int id = 5;
1006         const int val_type = USB_MIXER_S16;
1007
1008         for (out = 0; out < 8; out++) {
1009                 control = out + 1;
1010                 for (in = 0; in < 8; in++) {
1011                         cmask = 1 << in;
1012                         snprintf(name, sizeof(name),
1013                                 "AIn%d - Out%d Capture Volume",
1014                                 in  + 1, out + 1);
1015                         err = snd_create_std_mono_ctl(mixer, id, control,
1016                                                         cmask, val_type, name,
1017                                                         &snd_usb_mixer_vol_tlv);
1018                         if (err < 0)
1019                                 return err;
1020                 }
1021                 for (in = 8; in < 16; in++) {
1022                         cmask = 1 << in;
1023                         snprintf(name, sizeof(name),
1024                                 "DIn%d - Out%d Playback Volume",
1025                                 in - 7, out + 1);
1026                         err = snd_create_std_mono_ctl(mixer, id, control,
1027                                                         cmask, val_type, name,
1028                                                         &snd_usb_mixer_vol_tlv);
1029                         if (err < 0)
1030                                 return err;
1031                 }
1032         }
1033
1034         return 0;
1035 }
1036
1037 /* This control needs a volume quirk, see mixer.c */
1038 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1039 {
1040         static const char name[] = "Effect Volume";
1041         const unsigned int id = 6;
1042         const int val_type = USB_MIXER_U8;
1043         const unsigned int control = 2;
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_duration_ctl(struct usb_mixer_interface *mixer)
1052 {
1053         static const char name[] = "Effect Duration";
1054         const unsigned int id = 6;
1055         const int val_type = USB_MIXER_S16;
1056         const unsigned int control = 3;
1057         const unsigned int cmask = 0;
1058
1059         return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1060                                         name, snd_usb_mixer_vol_tlv);
1061 }
1062
1063 /* This control needs a volume quirk, see mixer.c */
1064 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1065 {
1066         static const char name[] = "Effect Feedback Volume";
1067         const unsigned int id = 6;
1068         const int val_type = USB_MIXER_U8;
1069         const unsigned int control = 4;
1070         const unsigned int cmask = 0;
1071
1072         return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1073                                         name, NULL);
1074 }
1075
1076 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1077 {
1078         unsigned int cmask;
1079         int err, ch;
1080         char name[48];
1081
1082         const unsigned int id = 7;
1083         const int val_type = USB_MIXER_S16;
1084         const unsigned int control = 7;
1085
1086         for (ch = 0; ch < 4; ++ch) {
1087                 cmask = 1 << ch;
1088                 snprintf(name, sizeof(name),
1089                         "Effect Return %d Volume", ch + 1);
1090                 err = snd_create_std_mono_ctl(mixer, id, control,
1091                                                 cmask, val_type, name,
1092                                                 snd_usb_mixer_vol_tlv);
1093                 if (err < 0)
1094                         return err;
1095         }
1096
1097         return 0;
1098 }
1099
1100 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1101 {
1102         unsigned int  cmask;
1103         int err, ch;
1104         char name[48];
1105
1106         const unsigned int id = 5;
1107         const int val_type = USB_MIXER_S16;
1108         const unsigned int control = 9;
1109
1110         for (ch = 0; ch < 8; ++ch) {
1111                 cmask = 1 << ch;
1112                 snprintf(name, sizeof(name),
1113                         "Effect Send AIn%d Volume", ch + 1);
1114                 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1115                                                 val_type, name,
1116                                                 snd_usb_mixer_vol_tlv);
1117                 if (err < 0)
1118                         return err;
1119         }
1120         for (ch = 8; ch < 16; ++ch) {
1121                 cmask = 1 << ch;
1122                 snprintf(name, sizeof(name),
1123                         "Effect Send DIn%d Volume", ch - 7);
1124                 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1125                                                 val_type, name,
1126                                                 snd_usb_mixer_vol_tlv);
1127                 if (err < 0)
1128                         return err;
1129         }
1130         return 0;
1131 }
1132
1133 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1134 {
1135         int err;
1136
1137         err = snd_ftu_create_volume_ctls(mixer);
1138         if (err < 0)
1139                 return err;
1140
1141         err = snd_ftu_create_effect_switch(mixer, 1, 6);
1142         if (err < 0)
1143                 return err;
1144
1145         err = snd_ftu_create_effect_volume_ctl(mixer);
1146         if (err < 0)
1147                 return err;
1148
1149         err = snd_ftu_create_effect_duration_ctl(mixer);
1150         if (err < 0)
1151                 return err;
1152
1153         err = snd_ftu_create_effect_feedback_ctl(mixer);
1154         if (err < 0)
1155                 return err;
1156
1157         err = snd_ftu_create_effect_return_ctls(mixer);
1158         if (err < 0)
1159                 return err;
1160
1161         err = snd_ftu_create_effect_send_ctls(mixer);
1162         if (err < 0)
1163                 return err;
1164
1165         return 0;
1166 }
1167
1168 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1169                                unsigned char samplerate_id)
1170 {
1171         struct usb_mixer_interface *mixer;
1172         struct usb_mixer_elem_info *cval;
1173         int unitid = 12; /* SamleRate ExtensionUnit ID */
1174
1175         list_for_each_entry(mixer, &chip->mixer_list, list) {
1176                 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1177                 if (cval) {
1178                         snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1179                                                     cval->control << 8,
1180                                                     samplerate_id);
1181                         snd_usb_mixer_notify_id(mixer, unitid);
1182                 }
1183                 break;
1184         }
1185 }
1186
1187 /* M-Audio Fast Track C400/C600 */
1188 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1189 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1190 {
1191         char name[64];
1192         unsigned int cmask, offset;
1193         int out, chan, err;
1194         int num_outs = 0;
1195         int num_ins = 0;
1196
1197         const unsigned int id = 0x40;
1198         const int val_type = USB_MIXER_S16;
1199         const int control = 1;
1200
1201         switch (mixer->chip->usb_id) {
1202         case USB_ID(0x0763, 0x2030):
1203                 num_outs = 6;
1204                 num_ins = 4;
1205                 break;
1206         case USB_ID(0x0763, 0x2031):
1207                 num_outs = 8;
1208                 num_ins = 6;
1209                 break;
1210         }
1211
1212         for (chan = 0; chan < num_outs + num_ins; chan++) {
1213                 for (out = 0; out < num_outs; out++) {
1214                         if (chan < num_outs) {
1215                                 snprintf(name, sizeof(name),
1216                                         "PCM%d-Out%d Playback Volume",
1217                                         chan + 1, out + 1);
1218                         } else {
1219                                 snprintf(name, sizeof(name),
1220                                         "In%d-Out%d Playback Volume",
1221                                         chan - num_outs + 1, out + 1);
1222                         }
1223
1224                         cmask = (out == 0) ? 0 : 1 << (out - 1);
1225                         offset = chan * num_outs;
1226                         err = snd_create_std_mono_ctl_offset(mixer, id, control,
1227                                                 cmask, val_type, offset, name,
1228                                                 &snd_usb_mixer_vol_tlv);
1229                         if (err < 0)
1230                                 return err;
1231                 }
1232         }
1233
1234         return 0;
1235 }
1236
1237 /* This control needs a volume quirk, see mixer.c */
1238 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1239 {
1240         static const char name[] = "Effect Volume";
1241         const unsigned int id = 0x43;
1242         const int val_type = USB_MIXER_U8;
1243         const unsigned int control = 3;
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_duration_ctl(struct usb_mixer_interface *mixer)
1252 {
1253         static const char name[] = "Effect Duration";
1254         const unsigned int id = 0x43;
1255         const int val_type = USB_MIXER_S16;
1256         const unsigned int control = 4;
1257         const unsigned int cmask = 0;
1258
1259         return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1260                                         name, snd_usb_mixer_vol_tlv);
1261 }
1262
1263 /* This control needs a volume quirk, see mixer.c */
1264 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1265 {
1266         static const char name[] = "Effect Feedback Volume";
1267         const unsigned int id = 0x43;
1268         const int val_type = USB_MIXER_U8;
1269         const unsigned int control = 5;
1270         const unsigned int cmask = 0;
1271
1272         return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1273                                         name, NULL);
1274 }
1275
1276 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1277 {
1278         char name[64];
1279         unsigned int cmask;
1280         int chan, err;
1281         int num_outs = 0;
1282         int num_ins = 0;
1283
1284         const unsigned int id = 0x42;
1285         const int val_type = USB_MIXER_S16;
1286         const int control = 1;
1287
1288         switch (mixer->chip->usb_id) {
1289         case USB_ID(0x0763, 0x2030):
1290                 num_outs = 6;
1291                 num_ins = 4;
1292                 break;
1293         case USB_ID(0x0763, 0x2031):
1294                 num_outs = 8;
1295                 num_ins = 6;
1296                 break;
1297         }
1298
1299         for (chan = 0; chan < num_outs + num_ins; chan++) {
1300                 if (chan < num_outs) {
1301                         snprintf(name, sizeof(name),
1302                                 "Effect Send DOut%d",
1303                                 chan + 1);
1304                 } else {
1305                         snprintf(name, sizeof(name),
1306                                 "Effect Send AIn%d",
1307                                 chan - num_outs + 1);
1308                 }
1309
1310                 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1311                 err = snd_create_std_mono_ctl(mixer, id, control,
1312                                                 cmask, val_type, name,
1313                                                 &snd_usb_mixer_vol_tlv);
1314                 if (err < 0)
1315                         return err;
1316         }
1317
1318         return 0;
1319 }
1320
1321 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1322 {
1323         char name[64];
1324         unsigned int cmask;
1325         int chan, err;
1326         int num_outs = 0;
1327         int offset = 0;
1328
1329         const unsigned int id = 0x40;
1330         const int val_type = USB_MIXER_S16;
1331         const int control = 1;
1332
1333         switch (mixer->chip->usb_id) {
1334         case USB_ID(0x0763, 0x2030):
1335                 num_outs = 6;
1336                 offset = 0x3c;
1337                 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1338                 break;
1339         case USB_ID(0x0763, 0x2031):
1340                 num_outs = 8;
1341                 offset = 0x70;
1342                 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1343                 break;
1344         }
1345
1346         for (chan = 0; chan < num_outs; chan++) {
1347                 snprintf(name, sizeof(name),
1348                         "Effect Return %d",
1349                         chan + 1);
1350
1351                 cmask = (chan == 0) ? 0 :
1352                         1 << (chan + (chan % 2) * num_outs - 1);
1353                 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1354                                                 cmask, val_type, offset, name,
1355                                                 &snd_usb_mixer_vol_tlv);
1356                 if (err < 0)
1357                         return err;
1358         }
1359
1360         return 0;
1361 }
1362
1363 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1364 {
1365         int err;
1366
1367         err = snd_c400_create_vol_ctls(mixer);
1368         if (err < 0)
1369                 return err;
1370
1371         err = snd_c400_create_effect_vol_ctls(mixer);
1372         if (err < 0)
1373                 return err;
1374
1375         err = snd_c400_create_effect_ret_vol_ctls(mixer);
1376         if (err < 0)
1377                 return err;
1378
1379         err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1380         if (err < 0)
1381                 return err;
1382
1383         err = snd_c400_create_effect_volume_ctl(mixer);
1384         if (err < 0)
1385                 return err;
1386
1387         err = snd_c400_create_effect_duration_ctl(mixer);
1388         if (err < 0)
1389                 return err;
1390
1391         err = snd_c400_create_effect_feedback_ctl(mixer);
1392         if (err < 0)
1393                 return err;
1394
1395         return 0;
1396 }
1397
1398 /*
1399  * The mixer units for Ebox-44 are corrupt, and even where they
1400  * are valid they presents mono controls as L and R channels of
1401  * stereo. So we provide a good mixer here.
1402  */
1403 static struct std_mono_table ebox44_table[] = {
1404         {
1405                 .unitid = 4,
1406                 .control = 1,
1407                 .cmask = 0x0,
1408                 .val_type = USB_MIXER_INV_BOOLEAN,
1409                 .name = "Headphone Playback Switch"
1410         },
1411         {
1412                 .unitid = 4,
1413                 .control = 2,
1414                 .cmask = 0x1,
1415                 .val_type = USB_MIXER_S16,
1416                 .name = "Headphone A Mix Playback Volume"
1417         },
1418         {
1419                 .unitid = 4,
1420                 .control = 2,
1421                 .cmask = 0x2,
1422                 .val_type = USB_MIXER_S16,
1423                 .name = "Headphone B Mix Playback Volume"
1424         },
1425
1426         {
1427                 .unitid = 7,
1428                 .control = 1,
1429                 .cmask = 0x0,
1430                 .val_type = USB_MIXER_INV_BOOLEAN,
1431                 .name = "Output Playback Switch"
1432         },
1433         {
1434                 .unitid = 7,
1435                 .control = 2,
1436                 .cmask = 0x1,
1437                 .val_type = USB_MIXER_S16,
1438                 .name = "Output A Playback Volume"
1439         },
1440         {
1441                 .unitid = 7,
1442                 .control = 2,
1443                 .cmask = 0x2,
1444                 .val_type = USB_MIXER_S16,
1445                 .name = "Output B Playback Volume"
1446         },
1447
1448         {
1449                 .unitid = 10,
1450                 .control = 1,
1451                 .cmask = 0x0,
1452                 .val_type = USB_MIXER_INV_BOOLEAN,
1453                 .name = "Input Capture Switch"
1454         },
1455         {
1456                 .unitid = 10,
1457                 .control = 2,
1458                 .cmask = 0x1,
1459                 .val_type = USB_MIXER_S16,
1460                 .name = "Input A Capture Volume"
1461         },
1462         {
1463                 .unitid = 10,
1464                 .control = 2,
1465                 .cmask = 0x2,
1466                 .val_type = USB_MIXER_S16,
1467                 .name = "Input B Capture Volume"
1468         },
1469
1470         {}
1471 };
1472
1473 /* Audio Advantage Micro II findings:
1474  *
1475  * Mapping spdif AES bits to vendor register.bit:
1476  * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1477  * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1478  * AES2: [0 0 0 0 0 0 0 0]
1479  * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1480  *                           (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1481  *
1482  * power on values:
1483  * r2: 0x10
1484  * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1485  *           just after it to 0xa0, presumably it disables/mutes some analog
1486  *           parts when there is no audio.)
1487  * r9: 0x28
1488  *
1489  * Optical transmitter on/off:
1490  * vendor register.bit: 9.1
1491  * 0 - on (0x28 register value)
1492  * 1 - off (0x2a register value)
1493  *
1494  */
1495 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1496         struct snd_ctl_elem_info *uinfo)
1497 {
1498         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1499         uinfo->count = 1;
1500         return 0;
1501 }
1502
1503 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1504         struct snd_ctl_elem_value *ucontrol)
1505 {
1506         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1507         struct snd_usb_audio *chip = list->mixer->chip;
1508         int err;
1509         struct usb_interface *iface;
1510         struct usb_host_interface *alts;
1511         unsigned int ep;
1512         unsigned char data[3];
1513         int rate;
1514
1515         err = snd_usb_lock_shutdown(chip);
1516         if (err < 0)
1517                 return err;
1518
1519         ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1520         ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1521         ucontrol->value.iec958.status[2] = 0x00;
1522
1523         /* use known values for that card: interface#1 altsetting#1 */
1524         iface = usb_ifnum_to_if(chip->dev, 1);
1525         if (!iface || iface->num_altsetting < 2) {
1526                 err = -EINVAL;
1527                 goto end;
1528         }
1529         alts = &iface->altsetting[1];
1530         if (get_iface_desc(alts)->bNumEndpoints < 1) {
1531                 err = -EINVAL;
1532                 goto end;
1533         }
1534         ep = get_endpoint(alts, 0)->bEndpointAddress;
1535
1536         err = snd_usb_ctl_msg(chip->dev,
1537                         usb_rcvctrlpipe(chip->dev, 0),
1538                         UAC_GET_CUR,
1539                         USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1540                         UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1541                         ep,
1542                         data,
1543                         sizeof(data));
1544         if (err < 0)
1545                 goto end;
1546
1547         rate = data[0] | (data[1] << 8) | (data[2] << 16);
1548         ucontrol->value.iec958.status[3] = (rate == 48000) ?
1549                         IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1550
1551         err = 0;
1552  end:
1553         snd_usb_unlock_shutdown(chip);
1554         return err;
1555 }
1556
1557 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1558 {
1559         struct snd_usb_audio *chip = list->mixer->chip;
1560         unsigned int pval = list->kctl->private_value;
1561         u8 reg;
1562         int err;
1563
1564         err = snd_usb_lock_shutdown(chip);
1565         if (err < 0)
1566                 return err;
1567
1568         reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1569         err = snd_usb_ctl_msg(chip->dev,
1570                         usb_sndctrlpipe(chip->dev, 0),
1571                         UAC_SET_CUR,
1572                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1573                         reg,
1574                         2,
1575                         NULL,
1576                         0);
1577         if (err < 0)
1578                 goto end;
1579
1580         reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1581         reg |= (pval >> 12) & 0x0f;
1582         err = snd_usb_ctl_msg(chip->dev,
1583                         usb_sndctrlpipe(chip->dev, 0),
1584                         UAC_SET_CUR,
1585                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1586                         reg,
1587                         3,
1588                         NULL,
1589                         0);
1590         if (err < 0)
1591                 goto end;
1592
1593  end:
1594         snd_usb_unlock_shutdown(chip);
1595         return err;
1596 }
1597
1598 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1599         struct snd_ctl_elem_value *ucontrol)
1600 {
1601         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1602         unsigned int pval, pval_old;
1603         int err;
1604
1605         pval = pval_old = kcontrol->private_value;
1606         pval &= 0xfffff0f0;
1607         pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1608         pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1609
1610         pval &= 0xffff0fff;
1611         pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1612
1613         /* The frequency bits in AES3 cannot be set via register access. */
1614
1615         /* Silently ignore any bits from the request that cannot be set. */
1616
1617         if (pval == pval_old)
1618                 return 0;
1619
1620         kcontrol->private_value = pval;
1621         err = snd_microii_spdif_default_update(list);
1622         return err < 0 ? err : 1;
1623 }
1624
1625 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1626         struct snd_ctl_elem_value *ucontrol)
1627 {
1628         ucontrol->value.iec958.status[0] = 0x0f;
1629         ucontrol->value.iec958.status[1] = 0xff;
1630         ucontrol->value.iec958.status[2] = 0x00;
1631         ucontrol->value.iec958.status[3] = 0x00;
1632
1633         return 0;
1634 }
1635
1636 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1637         struct snd_ctl_elem_value *ucontrol)
1638 {
1639         ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1640
1641         return 0;
1642 }
1643
1644 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1645 {
1646         struct snd_usb_audio *chip = list->mixer->chip;
1647         u8 reg = list->kctl->private_value;
1648         int err;
1649
1650         err = snd_usb_lock_shutdown(chip);
1651         if (err < 0)
1652                 return err;
1653
1654         err = snd_usb_ctl_msg(chip->dev,
1655                         usb_sndctrlpipe(chip->dev, 0),
1656                         UAC_SET_CUR,
1657                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1658                         reg,
1659                         9,
1660                         NULL,
1661                         0);
1662
1663         snd_usb_unlock_shutdown(chip);
1664         return err;
1665 }
1666
1667 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1668         struct snd_ctl_elem_value *ucontrol)
1669 {
1670         struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1671         u8 reg;
1672         int err;
1673
1674         reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1675         if (reg != list->kctl->private_value)
1676                 return 0;
1677
1678         kcontrol->private_value = reg;
1679         err = snd_microii_spdif_switch_update(list);
1680         return err < 0 ? err : 1;
1681 }
1682
1683 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1684         {
1685                 .iface =    SNDRV_CTL_ELEM_IFACE_PCM,
1686                 .name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1687                 .info =     snd_microii_spdif_info,
1688                 .get =      snd_microii_spdif_default_get,
1689                 .put =      snd_microii_spdif_default_put,
1690                 .private_value = 0x00000100UL,/* reset value */
1691         },
1692         {
1693                 .access =   SNDRV_CTL_ELEM_ACCESS_READ,
1694                 .iface =    SNDRV_CTL_ELEM_IFACE_PCM,
1695                 .name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1696                 .info =     snd_microii_spdif_info,
1697                 .get =      snd_microii_spdif_mask_get,
1698         },
1699         {
1700                 .iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
1701                 .name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1702                 .info =     snd_ctl_boolean_mono_info,
1703                 .get =      snd_microii_spdif_switch_get,
1704                 .put =      snd_microii_spdif_switch_put,
1705                 .private_value = 0x00000028UL,/* reset value */
1706         }
1707 };
1708
1709 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1710 {
1711         int err, i;
1712         static usb_mixer_elem_resume_func_t resume_funcs[] = {
1713                 snd_microii_spdif_default_update,
1714                 NULL,
1715                 snd_microii_spdif_switch_update
1716         };
1717
1718         for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1719                 err = add_single_ctl_with_resume(mixer, 0,
1720                                                  resume_funcs[i],
1721                                                  &snd_microii_mixer_spdif[i],
1722                                                  NULL);
1723                 if (err < 0)
1724                         return err;
1725         }
1726
1727         return 0;
1728 }
1729
1730 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1731 {
1732         int err = 0;
1733         struct snd_info_entry *entry;
1734
1735         if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1736                 return err;
1737
1738         switch (mixer->chip->usb_id) {
1739         /* Tascam US-16x08 */
1740         case USB_ID(0x0644, 0x8047):
1741                 err = snd_us16x08_controls_create(mixer);
1742                 break;
1743         case USB_ID(0x041e, 0x3020):
1744         case USB_ID(0x041e, 0x3040):
1745         case USB_ID(0x041e, 0x3042):
1746         case USB_ID(0x041e, 0x30df):
1747         case USB_ID(0x041e, 0x3048):
1748                 err = snd_audigy2nx_controls_create(mixer);
1749                 if (err < 0)
1750                         break;
1751                 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1752                         snd_info_set_text_ops(entry, mixer,
1753                                               snd_audigy2nx_proc_read);
1754                 break;
1755
1756         /* EMU0204 */
1757         case USB_ID(0x041e, 0x3f19):
1758                 err = snd_emu0204_controls_create(mixer);
1759                 if (err < 0)
1760                         break;
1761                 break;
1762
1763         case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1764         case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1765                 err = snd_c400_create_mixer(mixer);
1766                 break;
1767
1768         case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1769         case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1770                 err = snd_ftu_create_mixer(mixer);
1771                 break;
1772
1773         case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1774         case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1775         case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1776                 err = snd_xonar_u1_controls_create(mixer);
1777                 break;
1778
1779         case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1780                 err = snd_microii_controls_create(mixer);
1781                 break;
1782
1783         case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1784                 err = snd_mbox1_create_sync_switch(mixer);
1785                 break;
1786
1787         case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1788                 err = snd_nativeinstruments_create_mixer(mixer,
1789                                 snd_nativeinstruments_ta6_mixers,
1790                                 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
1791                 break;
1792
1793         case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1794                 err = snd_nativeinstruments_create_mixer(mixer,
1795                                 snd_nativeinstruments_ta10_mixers,
1796                                 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
1797                 break;
1798
1799         case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1800                 /* detection is disabled in mixer_maps.c */
1801                 err = snd_create_std_mono_table(mixer, ebox44_table);
1802                 break;
1803
1804         case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1805         case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1806         case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1807         case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1808         case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1809                 err = snd_scarlett_controls_create(mixer);
1810                 break;
1811         }
1812
1813         return err;
1814 }
1815
1816 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1817                                     int unitid)
1818 {
1819         if (!mixer->rc_cfg)
1820                 return;
1821         /* unit ids specific to Extigy/Audigy 2 NX: */
1822         switch (unitid) {
1823         case 0: /* remote control */
1824                 mixer->rc_urb->dev = mixer->chip->dev;
1825                 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1826                 break;
1827         case 4: /* digital in jack */
1828         case 7: /* line in jacks */
1829         case 19: /* speaker out jacks */
1830         case 20: /* headphones out jack */
1831                 break;
1832         /* live24ext: 4 = line-in jack */
1833         case 3: /* hp-out jack (may actuate Mute) */
1834                 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1835                     mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1836                         snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1837                 break;
1838         default:
1839                 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
1840                 break;
1841         }
1842 }
1843
1844 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
1845                                          struct usb_mixer_elem_info *cval,
1846                                          struct snd_kcontrol *kctl)
1847 {
1848         /* Approximation using 10 ranges based on output measurement on hw v1.2.
1849          * This seems close to the cubic mapping e.g. alsamixer uses. */
1850         static const DECLARE_TLV_DB_RANGE(scale,
1851                  0,  1, TLV_DB_MINMAX_ITEM(-5300, -4970),
1852                  2,  5, TLV_DB_MINMAX_ITEM(-4710, -4160),
1853                  6,  7, TLV_DB_MINMAX_ITEM(-3884, -3710),
1854                  8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
1855                 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
1856                 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
1857                 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
1858                 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
1859                 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
1860                 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
1861         );
1862
1863         if (cval->min == 0 && cval->max == 50) {
1864                 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
1865                 kctl->tlv.p = scale;
1866                 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1867                 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1868
1869         } else if (cval->min == 0 && cval->max <= 1000) {
1870                 /* Some other clearly broken DragonFly variant.
1871                  * At least a 0..53 variant (hw v1.0) exists.
1872                  */
1873                 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
1874                 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1875         }
1876 }
1877
1878 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
1879                                   struct usb_mixer_elem_info *cval, int unitid,
1880                                   struct snd_kcontrol *kctl)
1881 {
1882         switch (mixer->chip->usb_id) {
1883         case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
1884                 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
1885                         snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
1886                 break;
1887         /* lowest playback value is muted on C-Media devices */
1888         case USB_ID(0x0d8c, 0x000c):
1889         case USB_ID(0x0d8c, 0x0014):
1890                 if (strstr(kctl->id.name, "Playback"))
1891                         cval->min_mute = 1;
1892                 break;
1893         }
1894 }
1895