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