2 * USB Audio Driver for ALSA
4 * Quirks and vendor-specific extensions for mixer interfaces
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
12 * Audio Advantage Micro II support added by:
13 * Przemek Rudy (prudy1@o2.pl)
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.
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.
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
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/usb.h>
33 #include <linux/usb/audio.h>
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>
44 #include "mixer_quirks.h"
45 #include "mixer_scarlett.h"
46 #include "mixer_us16x08.h"
49 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
51 struct std_mono_table {
52 unsigned int unitid, control, cmask;
55 snd_kcontrol_tlv_rw_t *tlv_callback;
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.
62 * Since there doesn't seem to be a devices that needs a multichannel
63 * version, we keep it mono for simplicity.
65 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
72 snd_kcontrol_tlv_rw_t *tlv_callback)
74 struct usb_mixer_elem_info *cval;
75 struct snd_kcontrol *kctl;
77 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
81 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
82 cval->val_type = val_type;
84 cval->control = control;
86 cval->idx_off = idx_off;
88 /* get_min_max() is called only for integer volumes later,
89 * so provide a short-cut for booleans */
97 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
104 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
105 kctl->private_free = snd_usb_mixer_elem_free;
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;
114 /* Add control to mixer */
115 return snd_usb_mixer_add_control(&cval->head, kctl);
118 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
120 unsigned int control,
124 snd_kcontrol_tlv_rw_t *tlv_callback)
126 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
127 val_type, 0 /* Offset */, name, tlv_callback);
131 * Create a set of standard UAC controls from a table
133 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
134 struct std_mono_table *t)
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);
149 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
151 usb_mixer_elem_resume_func_t resume,
152 const struct snd_kcontrol_new *knew,
153 struct usb_mixer_elem_list **listp)
155 struct usb_mixer_elem_list *list;
156 struct snd_kcontrol *kctl;
158 list = kzalloc(sizeof(*list), GFP_KERNEL);
165 list->resume = resume;
166 kctl = snd_ctl_new1(knew, list);
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);
177 * Sound Blaster remote control configuration
179 * format of remote control data:
181 * Audigy 2 NX: 06 80 xx 00 00 00
182 * Live! 24-bit: 06 80 xx yy 22 83
184 static const struct rc_config {
189 u8 min_packet_length; /* minimum accepted length of the URB result */
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 */
203 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
205 struct usb_mixer_interface *mixer = urb->context;
206 const struct rc_config *rc = mixer->rc_cfg;
209 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
212 code = mixer->rc_buffer[rc->offset];
214 code |= mixer->rc_buffer[rc->offset + 1] << 8;
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;
221 wake_up(&mixer->rc_waitq);
224 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
225 long count, loff_t *offset)
227 struct usb_mixer_interface *mixer = hw->private_data;
231 if (count != 1 && count != 4)
233 err = wait_event_interruptible(mixer->rc_waitq,
234 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
237 err = put_user(rc_code, buf);
239 err = put_user(rc_code, (u32 __user *)buf);
241 return err < 0 ? err : count;
244 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
247 struct usb_mixer_interface *mixer = hw->private_data;
249 poll_wait(file, &mixer->rc_waitq, wait);
250 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
253 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
255 struct snd_hwdep *hwdep;
258 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
259 if (rc_configs[i].usb_id == mixer->chip->usb_id)
261 if (i >= ARRAY_SIZE(rc_configs))
263 mixer->rc_cfg = &rc_configs[i];
265 len = mixer->rc_cfg->packet_length;
267 init_waitqueue_head(&mixer->rc_waitq);
268 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
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;
279 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
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;
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);
301 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
303 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
305 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
309 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
310 int value, int index)
312 struct snd_usb_audio *chip = mixer->chip;
315 err = snd_usb_lock_shutdown(chip);
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,
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,
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);
339 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_value *ucontrol)
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;
351 if (value == old_value)
353 kcontrol->private_value = (value << 8) | index;
354 err = snd_audigy2nx_led_update(mixer, value, index);
355 return err < 0 ? err : 1;
358 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
360 int priv_value = list->kctl->private_value;
362 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
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,
374 static const char * const snd_audigy2nx_led_names[] = {
377 "Dolby Digital LED Switch",
380 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
384 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
385 struct snd_kcontrol_new knew;
387 /* USB X-Fi S51 doesn't have a CMSS LED */
388 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
390 /* USB X-Fi S51 Pro doesn't have one either */
391 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
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)))
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,
412 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
413 struct snd_info_buffer *buffer)
415 static const struct sb_jack {
418 } jacks_audigy2nx[] = {
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 */
430 const struct sb_jack *jacks;
431 struct usb_mixer_interface *mixer = entry->private_data;
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;
444 for (i = 0; jacks[i].name; ++i) {
445 snd_iprintf(buffer, "%s: ", jacks[i].name);
446 err = snd_usb_lock_shutdown(mixer->chip);
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]);
458 snd_iprintf(buffer, "?\n");
463 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_info *uinfo)
466 static const char * const texts[2] = {"1/2", "3/4"};
468 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
471 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
472 struct snd_ctl_elem_value *ucontrol)
474 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
478 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
481 struct snd_usb_audio *chip = mixer->chip;
483 unsigned char buf[2];
485 err = snd_usb_lock_shutdown(chip);
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);
499 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol)
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];
510 if (value == kcontrol->private_value)
513 kcontrol->private_value = value;
514 err = snd_emu0204_ch_switch_update(mixer, value);
515 return err < 0 ? err : 1;
518 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
520 return snd_emu0204_ch_switch_update(list->mixer,
521 list->kctl->private_value);
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,
533 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
535 return add_single_ctl_with_resume(mixer, 0,
536 snd_emu0204_ch_switch_resume,
537 &snd_emu0204_control, NULL);
540 /* ASUS Xonar U1 / U3 controls */
542 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
543 struct snd_ctl_elem_value *ucontrol)
545 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
549 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
550 unsigned char status)
552 struct snd_usb_audio *chip = mixer->chip;
555 err = snd_usb_lock_shutdown(chip);
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,
562 snd_usb_unlock_shutdown(chip);
566 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
569 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
570 u8 old_status, new_status;
573 old_status = kcontrol->private_value;
574 if (ucontrol->value.integer.value[0])
575 new_status = old_status | 0x02;
577 new_status = old_status & ~0x02;
578 if (new_status == old_status)
581 kcontrol->private_value = new_status;
582 err = snd_xonar_u1_switch_update(list->mixer, new_status);
583 return err < 0 ? err : 1;
586 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
588 return snd_xonar_u1_switch_update(list->mixer,
589 list->kctl->private_value);
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,
601 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
603 return add_single_ctl_with_resume(mixer, 0,
604 snd_xonar_u1_switch_resume,
605 &snd_xonar_u1_output_switch, NULL);
608 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
610 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
611 struct snd_ctl_elem_value *ucontrol)
613 ucontrol->value.enumerated.item[0] = kctl->private_value;
617 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
619 struct snd_usb_audio *chip = mixer->chip;
621 unsigned char buff[3];
623 err = snd_usb_lock_shutdown(chip);
627 /* Prepare for magic command to toggle clock source */
628 err = snd_usb_ctl_msg(chip->dev,
629 usb_rcvctrlpipe(chip->dev, 0), 0x81,
632 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
635 err = snd_usb_ctl_msg(chip->dev,
636 usb_rcvctrlpipe(chip->dev, 0), 0x81,
639 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
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.
655 buff[0] = buff[1] = buff[2] = 0x00;
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,
662 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
665 err = snd_usb_ctl_msg(chip->dev,
666 usb_rcvctrlpipe(chip->dev, 0), 0x81,
669 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
672 err = snd_usb_ctl_msg(chip->dev,
673 usb_rcvctrlpipe(chip->dev, 0), 0x81,
676 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
681 snd_usb_unlock_shutdown(chip);
685 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
686 struct snd_ctl_elem_value *ucontrol)
688 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
689 struct usb_mixer_interface *mixer = list->mixer;
691 bool cur_val, new_val;
693 cur_val = kctl->private_value;
694 new_val = ucontrol->value.enumerated.item[0];
695 if (cur_val == new_val)
698 kctl->private_value = new_val;
699 err = snd_mbox1_switch_update(mixer, new_val);
700 return err < 0 ? err : 1;
703 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
704 struct snd_ctl_elem_info *uinfo)
706 static const char *const texts[2] = {
711 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
714 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
716 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
719 static struct snd_kcontrol_new snd_mbox1_switch = {
720 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
721 .name = "Clock Source",
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,
730 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
732 return add_single_ctl_with_resume(mixer, 0,
733 snd_mbox1_switch_resume,
734 &snd_mbox1_switch, NULL);
737 /* Native Instruments device quirks */
739 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
741 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
742 struct snd_kcontrol *kctl)
744 struct usb_device *dev = mixer->chip->dev;
745 unsigned int pval = kctl->private_value;
749 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
751 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
752 0, pval & 0xffff, &value, 1);
755 "unable to issue vendor read request (ret = %d)", err);
759 kctl->private_value |= ((unsigned int)value << 24);
763 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_value *ucontrol)
766 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
770 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
772 struct snd_usb_audio *chip = list->mixer->chip;
773 unsigned int pval = list->kctl->private_value;
776 err = snd_usb_lock_shutdown(chip);
779 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
781 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
782 pval >> 24, pval & 0xffff, NULL, 0, 1000);
783 snd_usb_unlock_shutdown(chip);
787 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
788 struct snd_ctl_elem_value *ucontrol)
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];
795 if (oldval == newval)
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;
804 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
806 .name = "Direct Thru Channel A",
807 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
810 .name = "Direct Thru Channel B",
811 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
814 .name = "Phono Input Channel A",
815 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
818 .name = "Phono Input Channel B",
819 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
823 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
825 .name = "Direct Thru Channel A",
826 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
829 .name = "Direct Thru Channel B",
830 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
833 .name = "Direct Thru Channel C",
834 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
837 .name = "Direct Thru Channel D",
838 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
841 .name = "Phono Input Channel A",
842 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
845 .name = "Phono Input Channel B",
846 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
849 .name = "Phono Input Channel C",
850 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
853 .name = "Phono Input Channel D",
854 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
858 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
859 const struct snd_kcontrol_new *kc,
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,
871 for (i = 0; i < count; i++) {
872 struct usb_mixer_elem_list *list;
874 template.name = kc[i].name;
875 template.private_value = kc[i].private_value;
877 err = add_single_ctl_with_resume(mixer, 0,
878 snd_ni_update_cur_val,
882 snd_ni_control_init_val(mixer, list->kctl);
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)
893 static const char *const texts[8] = {
894 "Room 1", "Room 2", "Room 3", "Hall 1",
895 "Hall 2", "Plate", "Delay", "Echo"
898 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
901 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
902 struct snd_kcontrol *kctl)
904 struct usb_device *dev = mixer->chip->dev;
905 unsigned int pval = kctl->private_value;
907 unsigned char value[2];
912 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
913 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
915 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
920 kctl->private_value |= (unsigned int)value[0] << 24;
924 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
925 struct snd_ctl_elem_value *ucontrol)
927 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
931 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
933 struct snd_usb_audio *chip = list->mixer->chip;
934 unsigned int pval = list->kctl->private_value;
935 unsigned char value[2];
938 value[0] = pval >> 24;
941 err = snd_usb_lock_shutdown(chip);
944 err = snd_usb_ctl_msg(chip->dev,
945 usb_sndctrlpipe(chip->dev, 0),
947 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
949 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
951 snd_usb_unlock_shutdown(chip);
955 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
956 struct snd_ctl_elem_value *ucontrol)
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;
962 cur_val = pval >> 24;
963 new_val = ucontrol->value.enumerated.item[0];
964 if (cur_val == new_val)
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;
973 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
974 int validx, int bUnitID)
976 static struct snd_kcontrol_new template = {
977 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
978 .name = "Effect Program Switch",
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
985 struct usb_mixer_elem_list *list;
988 err = add_single_ctl_with_resume(mixer, bUnitID,
989 snd_ftu_eff_switch_update,
993 list->kctl->private_value = (validx << 8) | bUnitID;
994 snd_ftu_eff_switch_init(mixer, list->kctl);
998 /* Create volume controls for FTU devices*/
999 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1002 unsigned int control, cmask;
1005 const unsigned int id = 5;
1006 const int val_type = USB_MIXER_S16;
1008 for (out = 0; out < 8; out++) {
1010 for (in = 0; in < 8; in++) {
1012 snprintf(name, sizeof(name),
1013 "AIn%d - Out%d Capture Volume",
1015 err = snd_create_std_mono_ctl(mixer, id, control,
1016 cmask, val_type, name,
1017 &snd_usb_mixer_vol_tlv);
1021 for (in = 8; in < 16; in++) {
1023 snprintf(name, sizeof(name),
1024 "DIn%d - Out%d Playback Volume",
1026 err = snd_create_std_mono_ctl(mixer, id, control,
1027 cmask, val_type, name,
1028 &snd_usb_mixer_vol_tlv);
1037 /* This control needs a volume quirk, see mixer.c */
1038 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
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;
1046 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1047 name, snd_usb_mixer_vol_tlv);
1050 /* This control needs a volume quirk, see mixer.c */
1051 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
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;
1059 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1060 name, snd_usb_mixer_vol_tlv);
1063 /* This control needs a volume quirk, see mixer.c */
1064 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
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;
1072 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1076 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1082 const unsigned int id = 7;
1083 const int val_type = USB_MIXER_S16;
1084 const unsigned int control = 7;
1086 for (ch = 0; ch < 4; ++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);
1100 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1106 const unsigned int id = 5;
1107 const int val_type = USB_MIXER_S16;
1108 const unsigned int control = 9;
1110 for (ch = 0; ch < 8; ++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,
1116 snd_usb_mixer_vol_tlv);
1120 for (ch = 8; ch < 16; ++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,
1126 snd_usb_mixer_vol_tlv);
1133 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1137 err = snd_ftu_create_volume_ctls(mixer);
1141 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1145 err = snd_ftu_create_effect_volume_ctl(mixer);
1149 err = snd_ftu_create_effect_duration_ctl(mixer);
1153 err = snd_ftu_create_effect_feedback_ctl(mixer);
1157 err = snd_ftu_create_effect_return_ctls(mixer);
1161 err = snd_ftu_create_effect_send_ctls(mixer);
1168 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1169 unsigned char samplerate_id)
1171 struct usb_mixer_interface *mixer;
1172 struct usb_mixer_elem_info *cval;
1173 int unitid = 12; /* SamleRate ExtensionUnit ID */
1175 list_for_each_entry(mixer, &chip->mixer_list, list) {
1176 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1178 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1181 snd_usb_mixer_notify_id(mixer, unitid);
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)
1192 unsigned int cmask, offset;
1197 const unsigned int id = 0x40;
1198 const int val_type = USB_MIXER_S16;
1199 const int control = 1;
1201 switch (mixer->chip->usb_id) {
1202 case USB_ID(0x0763, 0x2030):
1206 case USB_ID(0x0763, 0x2031):
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",
1219 snprintf(name, sizeof(name),
1220 "In%d-Out%d Playback Volume",
1221 chan - num_outs + 1, out + 1);
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);
1237 /* This control needs a volume quirk, see mixer.c */
1238 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
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;
1246 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1247 name, snd_usb_mixer_vol_tlv);
1250 /* This control needs a volume quirk, see mixer.c */
1251 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
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;
1259 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1260 name, snd_usb_mixer_vol_tlv);
1263 /* This control needs a volume quirk, see mixer.c */
1264 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
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;
1272 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1276 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1284 const unsigned int id = 0x42;
1285 const int val_type = USB_MIXER_S16;
1286 const int control = 1;
1288 switch (mixer->chip->usb_id) {
1289 case USB_ID(0x0763, 0x2030):
1293 case USB_ID(0x0763, 0x2031):
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",
1305 snprintf(name, sizeof(name),
1306 "Effect Send AIn%d",
1307 chan - num_outs + 1);
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);
1321 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1329 const unsigned int id = 0x40;
1330 const int val_type = USB_MIXER_S16;
1331 const int control = 1;
1333 switch (mixer->chip->usb_id) {
1334 case USB_ID(0x0763, 0x2030):
1337 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1339 case USB_ID(0x0763, 0x2031):
1342 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1346 for (chan = 0; chan < num_outs; chan++) {
1347 snprintf(name, sizeof(name),
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);
1363 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1367 err = snd_c400_create_vol_ctls(mixer);
1371 err = snd_c400_create_effect_vol_ctls(mixer);
1375 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1379 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1383 err = snd_c400_create_effect_volume_ctl(mixer);
1387 err = snd_c400_create_effect_duration_ctl(mixer);
1391 err = snd_c400_create_effect_feedback_ctl(mixer);
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.
1403 static struct std_mono_table ebox44_table[] = {
1408 .val_type = USB_MIXER_INV_BOOLEAN,
1409 .name = "Headphone Playback Switch"
1415 .val_type = USB_MIXER_S16,
1416 .name = "Headphone A Mix Playback Volume"
1422 .val_type = USB_MIXER_S16,
1423 .name = "Headphone B Mix Playback Volume"
1430 .val_type = USB_MIXER_INV_BOOLEAN,
1431 .name = "Output Playback Switch"
1437 .val_type = USB_MIXER_S16,
1438 .name = "Output A Playback Volume"
1444 .val_type = USB_MIXER_S16,
1445 .name = "Output B Playback Volume"
1452 .val_type = USB_MIXER_INV_BOOLEAN,
1453 .name = "Input Capture Switch"
1459 .val_type = USB_MIXER_S16,
1460 .name = "Input A Capture Volume"
1466 .val_type = USB_MIXER_S16,
1467 .name = "Input B Capture Volume"
1473 /* Audio Advantage Micro II findings:
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
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.)
1489 * Optical transmitter on/off:
1490 * vendor register.bit: 9.1
1491 * 0 - on (0x28 register value)
1492 * 1 - off (0x2a register value)
1495 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1496 struct snd_ctl_elem_info *uinfo)
1498 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1503 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1504 struct snd_ctl_elem_value *ucontrol)
1506 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1507 struct snd_usb_audio *chip = list->mixer->chip;
1509 struct usb_interface *iface;
1510 struct usb_host_interface *alts;
1512 unsigned char data[3];
1515 err = snd_usb_lock_shutdown(chip);
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;
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) {
1529 alts = &iface->altsetting[1];
1530 if (get_iface_desc(alts)->bNumEndpoints < 1) {
1534 ep = get_endpoint(alts, 0)->bEndpointAddress;
1536 err = snd_usb_ctl_msg(chip->dev,
1537 usb_rcvctrlpipe(chip->dev, 0),
1539 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1540 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
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;
1553 snd_usb_unlock_shutdown(chip);
1557 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1559 struct snd_usb_audio *chip = list->mixer->chip;
1560 unsigned int pval = list->kctl->private_value;
1564 err = snd_usb_lock_shutdown(chip);
1568 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1569 err = snd_usb_ctl_msg(chip->dev,
1570 usb_sndctrlpipe(chip->dev, 0),
1572 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
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),
1585 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1594 snd_usb_unlock_shutdown(chip);
1598 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1599 struct snd_ctl_elem_value *ucontrol)
1601 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1602 unsigned int pval, pval_old;
1605 pval = pval_old = kcontrol->private_value;
1607 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1608 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1611 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1613 /* The frequency bits in AES3 cannot be set via register access. */
1615 /* Silently ignore any bits from the request that cannot be set. */
1617 if (pval == pval_old)
1620 kcontrol->private_value = pval;
1621 err = snd_microii_spdif_default_update(list);
1622 return err < 0 ? err : 1;
1625 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_value *ucontrol)
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;
1636 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1639 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1644 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1646 struct snd_usb_audio *chip = list->mixer->chip;
1647 u8 reg = list->kctl->private_value;
1650 err = snd_usb_lock_shutdown(chip);
1654 err = snd_usb_ctl_msg(chip->dev,
1655 usb_sndctrlpipe(chip->dev, 0),
1657 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1663 snd_usb_unlock_shutdown(chip);
1667 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1668 struct snd_ctl_elem_value *ucontrol)
1670 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1674 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1675 if (reg != list->kctl->private_value)
1678 kcontrol->private_value = reg;
1679 err = snd_microii_spdif_switch_update(list);
1680 return err < 0 ? err : 1;
1683 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
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 */
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,
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 */
1709 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1712 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1713 snd_microii_spdif_default_update,
1715 snd_microii_spdif_switch_update
1718 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1719 err = add_single_ctl_with_resume(mixer, 0,
1721 &snd_microii_mixer_spdif[i],
1730 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1733 struct snd_info_entry *entry;
1735 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1738 switch (mixer->chip->usb_id) {
1739 /* Tascam US-16x08 */
1740 case USB_ID(0x0644, 0x8047):
1741 err = snd_us16x08_controls_create(mixer);
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);
1751 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1752 snd_info_set_text_ops(entry, mixer,
1753 snd_audigy2nx_proc_read);
1757 case USB_ID(0x041e, 0x3f19):
1758 err = snd_emu0204_controls_create(mixer);
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);
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);
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);
1779 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1780 err = snd_microii_controls_create(mixer);
1783 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1784 err = snd_mbox1_create_sync_switch(mixer);
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));
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));
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);
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);
1816 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1821 /* unit ids specific to Extigy/Audigy 2 NX: */
1823 case 0: /* remote control */
1824 mixer->rc_urb->dev = mixer->chip->dev;
1825 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1827 case 4: /* digital in jack */
1828 case 7: /* line in jacks */
1829 case 19: /* speaker out jacks */
1830 case 20: /* headphones out jack */
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);
1839 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
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)
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),
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;
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.
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;
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)
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);
1887 /* lowest playback value is muted on some devices */
1888 case USB_ID(0x0d8c, 0x000c): /* C-Media */
1889 case USB_ID(0x0d8c, 0x0014): /* C-Media */
1890 case USB_ID(0x19f7, 0x0003): /* RODE NT-USB */
1891 if (strstr(kctl->id.name, "Playback"))