2 * USB Audio Driver for ALSA
4 * Quirks and vendor-specific extensions for mixer interfaces
8 * Many codes borrowed from audio.c by
12 * Audio Advantage Micro II support added by:
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/hid.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/usb.h>
34 #include <linux/usb/audio.h>
36 #include <sound/asoundef.h>
37 #include <sound/core.h>
38 #include <sound/control.h>
39 #include <sound/hwdep.h>
40 #include <sound/info.h>
41 #include <sound/tlv.h>
45 #include "mixer_quirks.h"
46 #include "mixer_scarlett.h"
47 #include "mixer_us16x08.h"
50 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
52 struct std_mono_table {
53 unsigned int unitid, control, cmask;
56 snd_kcontrol_tlv_rw_t *tlv_callback;
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.
63 * Since there doesn't seem to be a devices that needs a multichannel
64 * version, we keep it mono for simplicity.
66 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
73 snd_kcontrol_tlv_rw_t *tlv_callback)
75 struct usb_mixer_elem_info *cval;
76 struct snd_kcontrol *kctl;
78 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
82 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
83 cval->val_type = val_type;
85 cval->control = control;
87 cval->idx_off = idx_off;
89 /* get_min_max() is called only for integer volumes later,
90 * so provide a short-cut for booleans */
98 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
105 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
106 kctl->private_free = snd_usb_mixer_elem_free;
110 kctl->tlv.c = tlv_callback;
111 kctl->vd[0].access |=
112 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
113 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
115 /* Add control to mixer */
116 return snd_usb_mixer_add_control(&cval->head, kctl);
119 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
121 unsigned int control,
125 snd_kcontrol_tlv_rw_t *tlv_callback)
127 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
128 val_type, 0 /* Offset */, name, tlv_callback);
132 * Create a set of standard UAC controls from a table
134 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
135 struct std_mono_table *t)
139 while (t->name != NULL) {
140 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
141 t->cmask, t->val_type, t->name, t->tlv_callback);
150 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
152 usb_mixer_elem_resume_func_t resume,
153 const struct snd_kcontrol_new *knew,
154 struct usb_mixer_elem_list **listp)
156 struct usb_mixer_elem_list *list;
157 struct snd_kcontrol *kctl;
159 list = kzalloc(sizeof(*list), GFP_KERNEL);
166 list->resume = resume;
167 kctl = snd_ctl_new1(knew, list);
172 kctl->private_free = snd_usb_mixer_elem_free;
173 return snd_usb_mixer_add_control(list, kctl);
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, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
202 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
204 struct usb_mixer_interface *mixer = urb->context;
205 const struct rc_config *rc = mixer->rc_cfg;
208 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
211 code = mixer->rc_buffer[rc->offset];
213 code |= mixer->rc_buffer[rc->offset + 1] << 8;
215 /* the Mute button actually changes the mixer control */
216 if (code == rc->mute_code)
217 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
218 mixer->rc_code = code;
220 wake_up(&mixer->rc_waitq);
223 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
224 long count, loff_t *offset)
226 struct usb_mixer_interface *mixer = hw->private_data;
230 if (count != 1 && count != 4)
232 err = wait_event_interruptible(mixer->rc_waitq,
233 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
236 err = put_user(rc_code, buf);
238 err = put_user(rc_code, (u32 __user *)buf);
240 return err < 0 ? err : count;
243 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
246 struct usb_mixer_interface *mixer = hw->private_data;
248 poll_wait(file, &mixer->rc_waitq, wait);
249 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
252 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
254 struct snd_hwdep *hwdep;
257 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
258 if (rc_configs[i].usb_id == mixer->chip->usb_id)
260 if (i >= ARRAY_SIZE(rc_configs))
262 mixer->rc_cfg = &rc_configs[i];
264 len = mixer->rc_cfg->packet_length;
266 init_waitqueue_head(&mixer->rc_waitq);
267 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
270 snprintf(hwdep->name, sizeof(hwdep->name),
271 "%s remote control", mixer->chip->card->shortname);
272 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
273 hwdep->private_data = mixer;
274 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
275 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
276 hwdep->exclusive = 1;
278 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
281 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
282 if (!mixer->rc_setup_packet) {
283 usb_free_urb(mixer->rc_urb);
284 mixer->rc_urb = NULL;
287 mixer->rc_setup_packet->bRequestType =
288 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
289 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
290 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
291 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
292 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
293 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
294 usb_rcvctrlpipe(mixer->chip->dev, 0),
295 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
296 snd_usb_soundblaster_remote_complete, mixer);
300 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
302 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
304 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
308 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
309 int value, int index)
311 struct snd_usb_audio *chip = mixer->chip;
314 err = snd_usb_lock_shutdown(chip);
318 if (chip->usb_id == USB_ID(0x041e, 0x3042))
319 err = snd_usb_ctl_msg(chip->dev,
320 usb_sndctrlpipe(chip->dev, 0), 0x24,
321 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
323 /* USB X-Fi S51 Pro */
324 if (chip->usb_id == USB_ID(0x041e, 0x30df))
325 err = snd_usb_ctl_msg(chip->dev,
326 usb_sndctrlpipe(chip->dev, 0), 0x24,
327 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
330 err = snd_usb_ctl_msg(chip->dev,
331 usb_sndctrlpipe(chip->dev, 0), 0x24,
332 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
333 value, index + 2, NULL, 0);
334 snd_usb_unlock_shutdown(chip);
338 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_value *ucontrol)
341 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
342 struct usb_mixer_interface *mixer = list->mixer;
343 int index = kcontrol->private_value & 0xff;
344 unsigned int value = ucontrol->value.integer.value[0];
345 int old_value = kcontrol->private_value >> 8;
350 if (value == old_value)
352 kcontrol->private_value = (value << 8) | index;
353 err = snd_audigy2nx_led_update(mixer, value, index);
354 return err < 0 ? err : 1;
357 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
359 int priv_value = list->kctl->private_value;
361 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
365 /* name and private_value are set dynamically */
366 static const struct snd_kcontrol_new snd_audigy2nx_control = {
367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
368 .info = snd_audigy2nx_led_info,
369 .get = snd_audigy2nx_led_get,
370 .put = snd_audigy2nx_led_put,
373 static const char * const snd_audigy2nx_led_names[] = {
376 "Dolby Digital LED Switch",
379 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
383 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
384 struct snd_kcontrol_new knew;
386 /* USB X-Fi S51 doesn't have a CMSS LED */
387 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
389 /* USB X-Fi S51 Pro doesn't have one either */
390 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
392 if (i > 1 && /* Live24ext has 2 LEDs only */
393 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
394 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
395 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
396 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
399 knew = snd_audigy2nx_control;
400 knew.name = snd_audigy2nx_led_names[i];
401 knew.private_value = (1 << 8) | i; /* LED on as default */
402 err = add_single_ctl_with_resume(mixer, 0,
403 snd_audigy2nx_led_resume,
411 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
412 struct snd_info_buffer *buffer)
414 static const struct sb_jack {
417 } jacks_audigy2nx[] = {
423 }, jacks_live24ext[] = {
424 {4, "line in"}, /* &1=Line, &2=Mic*/
425 {3, "hph out"}, /* headphones */
426 {0, "RC "}, /* last command, 6 bytes see rc_config above */
429 const struct sb_jack *jacks;
430 struct usb_mixer_interface *mixer = entry->private_data;
434 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
435 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
436 jacks = jacks_audigy2nx;
437 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
438 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
439 jacks = jacks_live24ext;
443 for (i = 0; jacks[i].name; ++i) {
444 snd_iprintf(buffer, "%s: ", jacks[i].name);
445 err = snd_usb_lock_shutdown(mixer->chip);
448 err = snd_usb_ctl_msg(mixer->chip->dev,
449 usb_rcvctrlpipe(mixer->chip->dev, 0),
450 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
451 USB_RECIP_INTERFACE, 0,
452 jacks[i].unitid << 8, buf, 3);
453 snd_usb_unlock_shutdown(mixer->chip);
454 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
455 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
457 snd_iprintf(buffer, "?\n");
462 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_info *uinfo)
465 static const char * const texts[2] = {"1/2", "3/4"};
467 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
470 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
473 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
477 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
480 struct snd_usb_audio *chip = mixer->chip;
482 unsigned char buf[2];
484 err = snd_usb_lock_shutdown(chip);
489 buf[1] = value ? 0x02 : 0x01;
490 err = snd_usb_ctl_msg(chip->dev,
491 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
492 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
493 0x0400, 0x0e00, buf, 2);
494 snd_usb_unlock_shutdown(chip);
498 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
499 struct snd_ctl_elem_value *ucontrol)
501 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
502 struct usb_mixer_interface *mixer = list->mixer;
503 unsigned int value = ucontrol->value.enumerated.item[0];
509 if (value == kcontrol->private_value)
512 kcontrol->private_value = value;
513 err = snd_emu0204_ch_switch_update(mixer, value);
514 return err < 0 ? err : 1;
517 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
519 return snd_emu0204_ch_switch_update(list->mixer,
520 list->kctl->private_value);
523 static struct snd_kcontrol_new snd_emu0204_control = {
524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
525 .name = "Front Jack Channels",
526 .info = snd_emu0204_ch_switch_info,
527 .get = snd_emu0204_ch_switch_get,
528 .put = snd_emu0204_ch_switch_put,
532 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
534 return add_single_ctl_with_resume(mixer, 0,
535 snd_emu0204_ch_switch_resume,
536 &snd_emu0204_control, NULL);
539 /* ASUS Xonar U1 / U3 controls */
541 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
542 struct snd_ctl_elem_value *ucontrol)
544 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
548 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
549 unsigned char status)
551 struct snd_usb_audio *chip = mixer->chip;
554 err = snd_usb_lock_shutdown(chip);
557 err = snd_usb_ctl_msg(chip->dev,
558 usb_sndctrlpipe(chip->dev, 0), 0x08,
559 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
561 snd_usb_unlock_shutdown(chip);
565 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
568 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
569 u8 old_status, new_status;
572 old_status = kcontrol->private_value;
573 if (ucontrol->value.integer.value[0])
574 new_status = old_status | 0x02;
576 new_status = old_status & ~0x02;
577 if (new_status == old_status)
580 kcontrol->private_value = new_status;
581 err = snd_xonar_u1_switch_update(list->mixer, new_status);
582 return err < 0 ? err : 1;
585 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
587 return snd_xonar_u1_switch_update(list->mixer,
588 list->kctl->private_value);
591 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
592 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
593 .name = "Digital Playback Switch",
594 .info = snd_ctl_boolean_mono_info,
595 .get = snd_xonar_u1_switch_get,
596 .put = snd_xonar_u1_switch_put,
597 .private_value = 0x05,
600 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
602 return add_single_ctl_with_resume(mixer, 0,
603 snd_xonar_u1_switch_resume,
604 &snd_xonar_u1_output_switch, NULL);
607 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
609 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
610 struct snd_ctl_elem_value *ucontrol)
612 ucontrol->value.enumerated.item[0] = kctl->private_value;
616 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
618 struct snd_usb_audio *chip = mixer->chip;
620 unsigned char buff[3];
622 err = snd_usb_lock_shutdown(chip);
626 /* Prepare for magic command to toggle clock source */
627 err = snd_usb_ctl_msg(chip->dev,
628 usb_rcvctrlpipe(chip->dev, 0), 0x81,
631 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
634 err = snd_usb_ctl_msg(chip->dev,
635 usb_rcvctrlpipe(chip->dev, 0), 0x81,
638 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
642 /* 2 possibilities: Internal -> send sample rate
643 * S/PDIF sync -> send zeroes
644 * NB: Sample rate locked to 48kHz on purpose to
645 * prevent user from resetting the sample rate
646 * while S/PDIF sync is enabled and confusing
647 * this configuration.
654 buff[0] = buff[1] = buff[2] = 0x00;
657 /* Send the magic command to toggle the clock source */
658 err = snd_usb_ctl_msg(chip->dev,
659 usb_sndctrlpipe(chip->dev, 0), 0x1,
661 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
664 err = snd_usb_ctl_msg(chip->dev,
665 usb_rcvctrlpipe(chip->dev, 0), 0x81,
668 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
671 err = snd_usb_ctl_msg(chip->dev,
672 usb_rcvctrlpipe(chip->dev, 0), 0x81,
675 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
680 snd_usb_unlock_shutdown(chip);
684 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
685 struct snd_ctl_elem_value *ucontrol)
687 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
688 struct usb_mixer_interface *mixer = list->mixer;
690 bool cur_val, new_val;
692 cur_val = kctl->private_value;
693 new_val = ucontrol->value.enumerated.item[0];
694 if (cur_val == new_val)
697 kctl->private_value = new_val;
698 err = snd_mbox1_switch_update(mixer, new_val);
699 return err < 0 ? err : 1;
702 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_info *uinfo)
705 static const char *const texts[2] = {
710 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
713 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
715 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
718 static struct snd_kcontrol_new snd_mbox1_switch = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .name = "Clock Source",
722 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
723 .info = snd_mbox1_switch_info,
724 .get = snd_mbox1_switch_get,
725 .put = snd_mbox1_switch_put,
729 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
731 return add_single_ctl_with_resume(mixer, 0,
732 snd_mbox1_switch_resume,
733 &snd_mbox1_switch, NULL);
736 /* Native Instruments device quirks */
738 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
740 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
741 struct snd_kcontrol *kctl)
743 struct usb_device *dev = mixer->chip->dev;
744 unsigned int pval = kctl->private_value;
748 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
750 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
751 0, pval & 0xffff, &value, 1);
754 "unable to issue vendor read request (ret = %d)", err);
758 kctl->private_value |= (value << 24);
762 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
763 struct snd_ctl_elem_value *ucontrol)
765 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
769 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
771 struct snd_usb_audio *chip = list->mixer->chip;
772 unsigned int pval = list->kctl->private_value;
775 err = snd_usb_lock_shutdown(chip);
778 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
780 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
781 pval >> 24, pval & 0xffff, NULL, 0, 1000);
782 snd_usb_unlock_shutdown(chip);
786 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
789 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
790 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
791 u8 newval = ucontrol->value.integer.value[0];
794 if (oldval == newval)
797 kcontrol->private_value &= ~(0xff << 24);
798 kcontrol->private_value |= (unsigned int)newval << 24;
799 err = snd_ni_update_cur_val(list);
800 return err < 0 ? err : 1;
803 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
805 .name = "Direct Thru Channel A",
806 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
809 .name = "Direct Thru Channel B",
810 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
813 .name = "Phono Input Channel A",
814 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
817 .name = "Phono Input Channel B",
818 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
822 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
824 .name = "Direct Thru Channel A",
825 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
828 .name = "Direct Thru Channel B",
829 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
832 .name = "Direct Thru Channel C",
833 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
836 .name = "Direct Thru Channel D",
837 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
840 .name = "Phono Input Channel A",
841 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
844 .name = "Phono Input Channel B",
845 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
848 .name = "Phono Input Channel C",
849 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
852 .name = "Phono Input Channel D",
853 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
857 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
858 const struct snd_kcontrol_new *kc,
862 struct snd_kcontrol_new template = {
863 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
864 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
865 .get = snd_nativeinstruments_control_get,
866 .put = snd_nativeinstruments_control_put,
867 .info = snd_ctl_boolean_mono_info,
870 for (i = 0; i < count; i++) {
871 struct usb_mixer_elem_list *list;
873 template.name = kc[i].name;
874 template.private_value = kc[i].private_value;
876 err = add_single_ctl_with_resume(mixer, 0,
877 snd_ni_update_cur_val,
881 snd_ni_control_init_val(mixer, list->kctl);
887 /* M-Audio FastTrack Ultra quirks */
888 /* FTU Effect switch (also used by C400/C600) */
889 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
890 struct snd_ctl_elem_info *uinfo)
892 static const char *const texts[8] = {
893 "Room 1", "Room 2", "Room 3", "Hall 1",
894 "Hall 2", "Plate", "Delay", "Echo"
897 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
900 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
901 struct snd_kcontrol *kctl)
903 struct usb_device *dev = mixer->chip->dev;
904 unsigned int pval = kctl->private_value;
906 unsigned char value[2];
911 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
912 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
914 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
919 kctl->private_value |= value[0] << 24;
923 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
924 struct snd_ctl_elem_value *ucontrol)
926 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
930 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
932 struct snd_usb_audio *chip = list->mixer->chip;
933 unsigned int pval = list->kctl->private_value;
934 unsigned char value[2];
937 value[0] = pval >> 24;
940 err = snd_usb_lock_shutdown(chip);
943 err = snd_usb_ctl_msg(chip->dev,
944 usb_sndctrlpipe(chip->dev, 0),
946 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
948 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
950 snd_usb_unlock_shutdown(chip);
954 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
955 struct snd_ctl_elem_value *ucontrol)
957 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
958 unsigned int pval = list->kctl->private_value;
959 int cur_val, err, new_val;
961 cur_val = pval >> 24;
962 new_val = ucontrol->value.enumerated.item[0];
963 if (cur_val == new_val)
966 kctl->private_value &= ~(0xff << 24);
967 kctl->private_value |= new_val << 24;
968 err = snd_ftu_eff_switch_update(list);
969 return err < 0 ? err : 1;
972 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
973 int validx, int bUnitID)
975 static struct snd_kcontrol_new template = {
976 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
977 .name = "Effect Program Switch",
979 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
980 .info = snd_ftu_eff_switch_info,
981 .get = snd_ftu_eff_switch_get,
982 .put = snd_ftu_eff_switch_put
984 struct usb_mixer_elem_list *list;
987 err = add_single_ctl_with_resume(mixer, bUnitID,
988 snd_ftu_eff_switch_update,
992 list->kctl->private_value = (validx << 8) | bUnitID;
993 snd_ftu_eff_switch_init(mixer, list->kctl);
997 /* Create volume controls for FTU devices*/
998 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1001 unsigned int control, cmask;
1004 const unsigned int id = 5;
1005 const int val_type = USB_MIXER_S16;
1007 for (out = 0; out < 8; out++) {
1009 for (in = 0; in < 8; in++) {
1011 snprintf(name, sizeof(name),
1012 "AIn%d - Out%d Capture Volume",
1014 err = snd_create_std_mono_ctl(mixer, id, control,
1015 cmask, val_type, name,
1016 &snd_usb_mixer_vol_tlv);
1020 for (in = 8; in < 16; in++) {
1022 snprintf(name, sizeof(name),
1023 "DIn%d - Out%d Playback Volume",
1025 err = snd_create_std_mono_ctl(mixer, id, control,
1026 cmask, val_type, name,
1027 &snd_usb_mixer_vol_tlv);
1036 /* This control needs a volume quirk, see mixer.c */
1037 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1039 static const char name[] = "Effect Volume";
1040 const unsigned int id = 6;
1041 const int val_type = USB_MIXER_U8;
1042 const unsigned int control = 2;
1043 const unsigned int cmask = 0;
1045 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1046 name, snd_usb_mixer_vol_tlv);
1049 /* This control needs a volume quirk, see mixer.c */
1050 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1052 static const char name[] = "Effect Duration";
1053 const unsigned int id = 6;
1054 const int val_type = USB_MIXER_S16;
1055 const unsigned int control = 3;
1056 const unsigned int cmask = 0;
1058 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1059 name, snd_usb_mixer_vol_tlv);
1062 /* This control needs a volume quirk, see mixer.c */
1063 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1065 static const char name[] = "Effect Feedback Volume";
1066 const unsigned int id = 6;
1067 const int val_type = USB_MIXER_U8;
1068 const unsigned int control = 4;
1069 const unsigned int cmask = 0;
1071 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1075 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1081 const unsigned int id = 7;
1082 const int val_type = USB_MIXER_S16;
1083 const unsigned int control = 7;
1085 for (ch = 0; ch < 4; ++ch) {
1087 snprintf(name, sizeof(name),
1088 "Effect Return %d Volume", ch + 1);
1089 err = snd_create_std_mono_ctl(mixer, id, control,
1090 cmask, val_type, name,
1091 snd_usb_mixer_vol_tlv);
1099 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1105 const unsigned int id = 5;
1106 const int val_type = USB_MIXER_S16;
1107 const unsigned int control = 9;
1109 for (ch = 0; ch < 8; ++ch) {
1111 snprintf(name, sizeof(name),
1112 "Effect Send AIn%d Volume", ch + 1);
1113 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1115 snd_usb_mixer_vol_tlv);
1119 for (ch = 8; ch < 16; ++ch) {
1121 snprintf(name, sizeof(name),
1122 "Effect Send DIn%d Volume", ch - 7);
1123 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1125 snd_usb_mixer_vol_tlv);
1132 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1136 err = snd_ftu_create_volume_ctls(mixer);
1140 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1144 err = snd_ftu_create_effect_volume_ctl(mixer);
1148 err = snd_ftu_create_effect_duration_ctl(mixer);
1152 err = snd_ftu_create_effect_feedback_ctl(mixer);
1156 err = snd_ftu_create_effect_return_ctls(mixer);
1160 err = snd_ftu_create_effect_send_ctls(mixer);
1167 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1168 unsigned char samplerate_id)
1170 struct usb_mixer_interface *mixer;
1171 struct usb_mixer_elem_info *cval;
1172 int unitid = 12; /* SamleRate ExtensionUnit ID */
1174 list_for_each_entry(mixer, &chip->mixer_list, list) {
1175 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1177 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1180 snd_usb_mixer_notify_id(mixer, unitid);
1186 /* M-Audio Fast Track C400/C600 */
1187 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1188 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1191 unsigned int cmask, offset;
1196 const unsigned int id = 0x40;
1197 const int val_type = USB_MIXER_S16;
1198 const int control = 1;
1200 switch (mixer->chip->usb_id) {
1201 case USB_ID(0x0763, 0x2030):
1205 case USB_ID(0x0763, 0x2031):
1211 for (chan = 0; chan < num_outs + num_ins; chan++) {
1212 for (out = 0; out < num_outs; out++) {
1213 if (chan < num_outs) {
1214 snprintf(name, sizeof(name),
1215 "PCM%d-Out%d Playback Volume",
1218 snprintf(name, sizeof(name),
1219 "In%d-Out%d Playback Volume",
1220 chan - num_outs + 1, out + 1);
1223 cmask = (out == 0) ? 0 : 1 << (out - 1);
1224 offset = chan * num_outs;
1225 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1226 cmask, val_type, offset, name,
1227 &snd_usb_mixer_vol_tlv);
1236 /* This control needs a volume quirk, see mixer.c */
1237 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1239 static const char name[] = "Effect Volume";
1240 const unsigned int id = 0x43;
1241 const int val_type = USB_MIXER_U8;
1242 const unsigned int control = 3;
1243 const unsigned int cmask = 0;
1245 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1246 name, snd_usb_mixer_vol_tlv);
1249 /* This control needs a volume quirk, see mixer.c */
1250 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1252 static const char name[] = "Effect Duration";
1253 const unsigned int id = 0x43;
1254 const int val_type = USB_MIXER_S16;
1255 const unsigned int control = 4;
1256 const unsigned int cmask = 0;
1258 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1259 name, snd_usb_mixer_vol_tlv);
1262 /* This control needs a volume quirk, see mixer.c */
1263 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1265 static const char name[] = "Effect Feedback Volume";
1266 const unsigned int id = 0x43;
1267 const int val_type = USB_MIXER_U8;
1268 const unsigned int control = 5;
1269 const unsigned int cmask = 0;
1271 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1275 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1283 const unsigned int id = 0x42;
1284 const int val_type = USB_MIXER_S16;
1285 const int control = 1;
1287 switch (mixer->chip->usb_id) {
1288 case USB_ID(0x0763, 0x2030):
1292 case USB_ID(0x0763, 0x2031):
1298 for (chan = 0; chan < num_outs + num_ins; chan++) {
1299 if (chan < num_outs) {
1300 snprintf(name, sizeof(name),
1301 "Effect Send DOut%d",
1304 snprintf(name, sizeof(name),
1305 "Effect Send AIn%d",
1306 chan - num_outs + 1);
1309 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1310 err = snd_create_std_mono_ctl(mixer, id, control,
1311 cmask, val_type, name,
1312 &snd_usb_mixer_vol_tlv);
1320 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1328 const unsigned int id = 0x40;
1329 const int val_type = USB_MIXER_S16;
1330 const int control = 1;
1332 switch (mixer->chip->usb_id) {
1333 case USB_ID(0x0763, 0x2030):
1336 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1338 case USB_ID(0x0763, 0x2031):
1341 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1345 for (chan = 0; chan < num_outs; chan++) {
1346 snprintf(name, sizeof(name),
1350 cmask = (chan == 0) ? 0 :
1351 1 << (chan + (chan % 2) * num_outs - 1);
1352 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1353 cmask, val_type, offset, name,
1354 &snd_usb_mixer_vol_tlv);
1362 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1366 err = snd_c400_create_vol_ctls(mixer);
1370 err = snd_c400_create_effect_vol_ctls(mixer);
1374 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1378 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1382 err = snd_c400_create_effect_volume_ctl(mixer);
1386 err = snd_c400_create_effect_duration_ctl(mixer);
1390 err = snd_c400_create_effect_feedback_ctl(mixer);
1398 * The mixer units for Ebox-44 are corrupt, and even where they
1399 * are valid they presents mono controls as L and R channels of
1400 * stereo. So we provide a good mixer here.
1402 static struct std_mono_table ebox44_table[] = {
1407 .val_type = USB_MIXER_INV_BOOLEAN,
1408 .name = "Headphone Playback Switch"
1414 .val_type = USB_MIXER_S16,
1415 .name = "Headphone A Mix Playback Volume"
1421 .val_type = USB_MIXER_S16,
1422 .name = "Headphone B Mix Playback Volume"
1429 .val_type = USB_MIXER_INV_BOOLEAN,
1430 .name = "Output Playback Switch"
1436 .val_type = USB_MIXER_S16,
1437 .name = "Output A Playback Volume"
1443 .val_type = USB_MIXER_S16,
1444 .name = "Output B Playback Volume"
1451 .val_type = USB_MIXER_INV_BOOLEAN,
1452 .name = "Input Capture Switch"
1458 .val_type = USB_MIXER_S16,
1459 .name = "Input A Capture Volume"
1465 .val_type = USB_MIXER_S16,
1466 .name = "Input B Capture Volume"
1472 /* Audio Advantage Micro II findings:
1474 * Mapping spdif AES bits to vendor register.bit:
1475 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1476 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1477 * AES2: [0 0 0 0 0 0 0 0]
1478 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1479 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1483 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1484 * just after it to 0xa0, presumably it disables/mutes some analog
1485 * parts when there is no audio.)
1488 * Optical transmitter on/off:
1489 * vendor register.bit: 9.1
1490 * 0 - on (0x28 register value)
1491 * 1 - off (0x2a register value)
1494 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1495 struct snd_ctl_elem_info *uinfo)
1497 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1502 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1503 struct snd_ctl_elem_value *ucontrol)
1505 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1506 struct snd_usb_audio *chip = list->mixer->chip;
1508 struct usb_interface *iface;
1509 struct usb_host_interface *alts;
1511 unsigned char data[3];
1514 err = snd_usb_lock_shutdown(chip);
1518 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1519 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1520 ucontrol->value.iec958.status[2] = 0x00;
1522 /* use known values for that card: interface#1 altsetting#1 */
1523 iface = usb_ifnum_to_if(chip->dev, 1);
1524 if (!iface || iface->num_altsetting < 2)
1526 alts = &iface->altsetting[1];
1527 if (get_iface_desc(alts)->bNumEndpoints < 1)
1529 ep = get_endpoint(alts, 0)->bEndpointAddress;
1531 err = snd_usb_ctl_msg(chip->dev,
1532 usb_rcvctrlpipe(chip->dev, 0),
1534 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1535 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1542 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1543 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1544 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1548 snd_usb_unlock_shutdown(chip);
1552 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1554 struct snd_usb_audio *chip = list->mixer->chip;
1555 unsigned int pval = list->kctl->private_value;
1559 err = snd_usb_lock_shutdown(chip);
1563 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1564 err = snd_usb_ctl_msg(chip->dev,
1565 usb_sndctrlpipe(chip->dev, 0),
1567 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1575 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1576 reg |= (pval >> 12) & 0x0f;
1577 err = snd_usb_ctl_msg(chip->dev,
1578 usb_sndctrlpipe(chip->dev, 0),
1580 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1589 snd_usb_unlock_shutdown(chip);
1593 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1594 struct snd_ctl_elem_value *ucontrol)
1596 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1597 unsigned int pval, pval_old;
1600 pval = pval_old = kcontrol->private_value;
1602 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1603 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1606 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1608 /* The frequency bits in AES3 cannot be set via register access. */
1610 /* Silently ignore any bits from the request that cannot be set. */
1612 if (pval == pval_old)
1615 kcontrol->private_value = pval;
1616 err = snd_microii_spdif_default_update(list);
1617 return err < 0 ? err : 1;
1620 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1621 struct snd_ctl_elem_value *ucontrol)
1623 ucontrol->value.iec958.status[0] = 0x0f;
1624 ucontrol->value.iec958.status[1] = 0xff;
1625 ucontrol->value.iec958.status[2] = 0x00;
1626 ucontrol->value.iec958.status[3] = 0x00;
1631 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1632 struct snd_ctl_elem_value *ucontrol)
1634 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1639 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1641 struct snd_usb_audio *chip = list->mixer->chip;
1642 u8 reg = list->kctl->private_value;
1645 err = snd_usb_lock_shutdown(chip);
1649 err = snd_usb_ctl_msg(chip->dev,
1650 usb_sndctrlpipe(chip->dev, 0),
1652 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1658 snd_usb_unlock_shutdown(chip);
1662 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_value *ucontrol)
1665 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1669 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1670 if (reg != list->kctl->private_value)
1673 kcontrol->private_value = reg;
1674 err = snd_microii_spdif_switch_update(list);
1675 return err < 0 ? err : 1;
1678 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1680 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1681 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1682 .info = snd_microii_spdif_info,
1683 .get = snd_microii_spdif_default_get,
1684 .put = snd_microii_spdif_default_put,
1685 .private_value = 0x00000100UL,/* reset value */
1688 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1689 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1690 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1691 .info = snd_microii_spdif_info,
1692 .get = snd_microii_spdif_mask_get,
1695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1696 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1697 .info = snd_ctl_boolean_mono_info,
1698 .get = snd_microii_spdif_switch_get,
1699 .put = snd_microii_spdif_switch_put,
1700 .private_value = 0x00000028UL,/* reset value */
1704 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1707 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1708 snd_microii_spdif_default_update,
1710 snd_microii_spdif_switch_update
1713 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1714 err = add_single_ctl_with_resume(mixer, 0,
1716 &snd_microii_mixer_spdif[i],
1725 /* Creative Sound Blaster E1 */
1727 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1728 struct snd_ctl_elem_value *ucontrol)
1730 ucontrol->value.integer.value[0] = kcontrol->private_value;
1734 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1735 unsigned char state)
1737 struct snd_usb_audio *chip = mixer->chip;
1739 unsigned char buff[2];
1742 buff[1] = state ? 0x02 : 0x00;
1744 err = snd_usb_lock_shutdown(chip);
1747 err = snd_usb_ctl_msg(chip->dev,
1748 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1749 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1750 0x0202, 3, buff, 2);
1751 snd_usb_unlock_shutdown(chip);
1755 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1758 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1759 unsigned char value = !!ucontrol->value.integer.value[0];
1762 if (kcontrol->private_value == value)
1764 kcontrol->private_value = value;
1765 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1766 return err < 0 ? err : 1;
1769 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1771 return snd_soundblaster_e1_switch_update(list->mixer,
1772 list->kctl->private_value);
1775 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1776 struct snd_ctl_elem_info *uinfo)
1778 static const char *const texts[2] = {
1782 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1785 static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1786 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1787 .name = "Input Source",
1788 .info = snd_soundblaster_e1_switch_info,
1789 .get = snd_soundblaster_e1_switch_get,
1790 .put = snd_soundblaster_e1_switch_put,
1794 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1796 return add_single_ctl_with_resume(mixer, 0,
1797 snd_soundblaster_e1_switch_resume,
1798 &snd_soundblaster_e1_input_switch,
1802 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1806 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1807 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1808 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1812 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1814 /* fix to 0dB playback volumes */
1815 dell_dock_init_vol(mixer->chip, 1, 16);
1816 dell_dock_init_vol(mixer->chip, 2, 16);
1817 dell_dock_init_vol(mixer->chip, 1, 19);
1818 dell_dock_init_vol(mixer->chip, 2, 19);
1822 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1825 struct snd_info_entry *entry;
1827 err = snd_usb_soundblaster_remote_init(mixer);
1831 switch (mixer->chip->usb_id) {
1832 /* Tascam US-16x08 */
1833 case USB_ID(0x0644, 0x8047):
1834 err = snd_us16x08_controls_create(mixer);
1836 case USB_ID(0x041e, 0x3020):
1837 case USB_ID(0x041e, 0x3040):
1838 case USB_ID(0x041e, 0x3042):
1839 case USB_ID(0x041e, 0x30df):
1840 case USB_ID(0x041e, 0x3048):
1841 err = snd_audigy2nx_controls_create(mixer);
1844 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1845 snd_info_set_text_ops(entry, mixer,
1846 snd_audigy2nx_proc_read);
1850 case USB_ID(0x041e, 0x3f19):
1851 err = snd_emu0204_controls_create(mixer);
1854 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1855 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1856 err = snd_c400_create_mixer(mixer);
1859 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1860 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1861 err = snd_ftu_create_mixer(mixer);
1864 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1865 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1866 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1867 err = snd_xonar_u1_controls_create(mixer);
1870 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1871 err = snd_microii_controls_create(mixer);
1874 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1875 err = snd_mbox1_create_sync_switch(mixer);
1878 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1879 err = snd_nativeinstruments_create_mixer(mixer,
1880 snd_nativeinstruments_ta6_mixers,
1881 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
1884 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1885 err = snd_nativeinstruments_create_mixer(mixer,
1886 snd_nativeinstruments_ta10_mixers,
1887 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
1890 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1891 /* detection is disabled in mixer_maps.c */
1892 err = snd_create_std_mono_table(mixer, ebox44_table);
1895 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1896 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1897 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1898 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1899 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1900 err = snd_scarlett_controls_create(mixer);
1903 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
1904 err = snd_soundblaster_e1_switch_create(mixer);
1906 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
1907 err = dell_dock_mixer_init(mixer);
1915 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
1917 switch (mixer->chip->usb_id) {
1918 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
1919 dell_dock_mixer_init(mixer);
1925 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1930 /* unit ids specific to Extigy/Audigy 2 NX: */
1932 case 0: /* remote control */
1933 mixer->rc_urb->dev = mixer->chip->dev;
1934 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1936 case 4: /* digital in jack */
1937 case 7: /* line in jacks */
1938 case 19: /* speaker out jacks */
1939 case 20: /* headphones out jack */
1941 /* live24ext: 4 = line-in jack */
1942 case 3: /* hp-out jack (may actuate Mute) */
1943 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1944 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1945 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1948 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
1953 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
1954 struct usb_mixer_elem_info *cval,
1955 struct snd_kcontrol *kctl)
1957 /* Approximation using 10 ranges based on output measurement on hw v1.2.
1958 * This seems close to the cubic mapping e.g. alsamixer uses. */
1959 static const DECLARE_TLV_DB_RANGE(scale,
1960 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
1961 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
1962 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
1963 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
1964 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
1965 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
1966 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
1967 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
1968 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
1969 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
1972 if (cval->min == 0 && cval->max == 50) {
1973 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
1974 kctl->tlv.p = scale;
1975 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1976 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1978 } else if (cval->min == 0 && cval->max <= 1000) {
1979 /* Some other clearly broken DragonFly variant.
1980 * At least a 0..53 variant (hw v1.0) exists.
1982 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
1983 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1987 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
1988 struct usb_mixer_elem_info *cval, int unitid,
1989 struct snd_kcontrol *kctl)
1991 switch (mixer->chip->usb_id) {
1992 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
1993 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
1994 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
1996 /* lowest playback value is muted on C-Media devices */
1997 case USB_ID(0x0d8c, 0x000c):
1998 case USB_ID(0x0d8c, 0x0014):
1999 if (strstr(kctl->id.name, "Playback"))