1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * USB Audio Driver for ALSA
5 * Quirks and vendor-specific extensions for mixer interfaces
7 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
9 * Many codes borrowed from audio.c by
10 * Alan Cox (alan@lxorguk.ukuu.org.uk)
11 * Thomas Sailer (sailer@ife.ee.ethz.ch)
13 * Audio Advantage Micro II support added by:
14 * Przemek Rudy (prudy1@o2.pl)
17 #include <linux/hid.h>
18 #include <linux/init.h>
19 #include <linux/math64.h>
20 #include <linux/slab.h>
21 #include <linux/usb.h>
22 #include <linux/usb/audio.h>
24 #include <sound/asoundef.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/hwdep.h>
28 #include <sound/info.h>
29 #include <sound/tlv.h>
33 #include "mixer_quirks.h"
34 #include "mixer_scarlett.h"
35 #include "mixer_scarlett_gen2.h"
36 #include "mixer_us16x08.h"
37 #include "mixer_s1810c.h"
40 struct std_mono_table {
41 unsigned int unitid, control, cmask;
44 snd_kcontrol_tlv_rw_t *tlv_callback;
47 /* This function allows for the creation of standard UAC controls.
48 * See the quirks for M-Audio FTUs or Ebox-44.
49 * If you don't want to set a TLV callback pass NULL.
51 * Since there doesn't seem to be a devices that needs a multichannel
52 * version, we keep it mono for simplicity.
54 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
61 snd_kcontrol_tlv_rw_t *tlv_callback)
63 struct usb_mixer_elem_info *cval;
64 struct snd_kcontrol *kctl;
66 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
70 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
71 cval->val_type = val_type;
73 cval->control = control;
75 cval->idx_off = idx_off;
77 /* get_min_max() is called only for integer volumes later,
78 * so provide a short-cut for booleans */
86 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
93 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
94 kctl->private_free = snd_usb_mixer_elem_free;
98 kctl->tlv.c = tlv_callback;
100 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
101 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
103 /* Add control to mixer */
104 return snd_usb_mixer_add_control(&cval->head, kctl);
107 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
109 unsigned int control,
113 snd_kcontrol_tlv_rw_t *tlv_callback)
115 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
116 val_type, 0 /* Offset */, name, tlv_callback);
120 * Create a set of standard UAC controls from a table
122 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
123 const struct std_mono_table *t)
127 while (t->name != NULL) {
128 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
129 t->cmask, t->val_type, t->name, t->tlv_callback);
138 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
140 usb_mixer_elem_resume_func_t resume,
141 const struct snd_kcontrol_new *knew,
142 struct usb_mixer_elem_list **listp)
144 struct usb_mixer_elem_list *list;
145 struct snd_kcontrol *kctl;
147 list = kzalloc(sizeof(*list), GFP_KERNEL);
154 list->resume = resume;
155 kctl = snd_ctl_new1(knew, list);
160 kctl->private_free = snd_usb_mixer_elem_free;
161 /* don't use snd_usb_mixer_add_control() here, this is a special list element */
162 return snd_usb_mixer_add_list(list, kctl, false);
166 * Sound Blaster remote control configuration
168 * format of remote control data:
170 * Audigy 2 NX: 06 80 xx 00 00 00
171 * Live! 24-bit: 06 80 xx yy 22 83
173 static const struct rc_config {
178 u8 min_packet_length; /* minimum accepted length of the URB result */
182 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
183 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
184 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
185 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
186 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
187 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
188 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
191 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
193 struct usb_mixer_interface *mixer = urb->context;
194 const struct rc_config *rc = mixer->rc_cfg;
197 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
200 code = mixer->rc_buffer[rc->offset];
202 code |= mixer->rc_buffer[rc->offset + 1] << 8;
204 /* the Mute button actually changes the mixer control */
205 if (code == rc->mute_code)
206 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
207 mixer->rc_code = code;
209 wake_up(&mixer->rc_waitq);
212 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
213 long count, loff_t *offset)
215 struct usb_mixer_interface *mixer = hw->private_data;
219 if (count != 1 && count != 4)
221 err = wait_event_interruptible(mixer->rc_waitq,
222 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
225 err = put_user(rc_code, buf);
227 err = put_user(rc_code, (u32 __user *)buf);
229 return err < 0 ? err : count;
232 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
235 struct usb_mixer_interface *mixer = hw->private_data;
237 poll_wait(file, &mixer->rc_waitq, wait);
238 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
241 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
243 struct snd_hwdep *hwdep;
246 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
247 if (rc_configs[i].usb_id == mixer->chip->usb_id)
249 if (i >= ARRAY_SIZE(rc_configs))
251 mixer->rc_cfg = &rc_configs[i];
253 len = mixer->rc_cfg->packet_length;
255 init_waitqueue_head(&mixer->rc_waitq);
256 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
259 snprintf(hwdep->name, sizeof(hwdep->name),
260 "%s remote control", mixer->chip->card->shortname);
261 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
262 hwdep->private_data = mixer;
263 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
264 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
265 hwdep->exclusive = 1;
267 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
270 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
271 if (!mixer->rc_setup_packet) {
272 usb_free_urb(mixer->rc_urb);
273 mixer->rc_urb = NULL;
276 mixer->rc_setup_packet->bRequestType =
277 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
278 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
279 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
280 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
281 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
282 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
283 usb_rcvctrlpipe(mixer->chip->dev, 0),
284 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
285 snd_usb_soundblaster_remote_complete, mixer);
289 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
291 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
293 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
297 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
298 int value, int index)
300 struct snd_usb_audio *chip = mixer->chip;
303 err = snd_usb_lock_shutdown(chip);
307 if (chip->usb_id == USB_ID(0x041e, 0x3042))
308 err = snd_usb_ctl_msg(chip->dev,
309 usb_sndctrlpipe(chip->dev, 0), 0x24,
310 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
312 /* USB X-Fi S51 Pro */
313 if (chip->usb_id == USB_ID(0x041e, 0x30df))
314 err = snd_usb_ctl_msg(chip->dev,
315 usb_sndctrlpipe(chip->dev, 0), 0x24,
316 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
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,
322 value, index + 2, NULL, 0);
323 snd_usb_unlock_shutdown(chip);
327 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_value *ucontrol)
330 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
331 struct usb_mixer_interface *mixer = list->mixer;
332 int index = kcontrol->private_value & 0xff;
333 unsigned int value = ucontrol->value.integer.value[0];
334 int old_value = kcontrol->private_value >> 8;
339 if (value == old_value)
341 kcontrol->private_value = (value << 8) | index;
342 err = snd_audigy2nx_led_update(mixer, value, index);
343 return err < 0 ? err : 1;
346 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
348 int priv_value = list->kctl->private_value;
350 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
354 /* name and private_value are set dynamically */
355 static const struct snd_kcontrol_new snd_audigy2nx_control = {
356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
357 .info = snd_audigy2nx_led_info,
358 .get = snd_audigy2nx_led_get,
359 .put = snd_audigy2nx_led_put,
362 static const char * const snd_audigy2nx_led_names[] = {
365 "Dolby Digital LED Switch",
368 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
372 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
373 struct snd_kcontrol_new knew;
375 /* USB X-Fi S51 doesn't have a CMSS LED */
376 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
378 /* USB X-Fi S51 Pro doesn't have one either */
379 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
381 if (i > 1 && /* Live24ext has 2 LEDs only */
382 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
383 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
384 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
385 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
388 knew = snd_audigy2nx_control;
389 knew.name = snd_audigy2nx_led_names[i];
390 knew.private_value = (1 << 8) | i; /* LED on as default */
391 err = add_single_ctl_with_resume(mixer, 0,
392 snd_audigy2nx_led_resume,
400 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
401 struct snd_info_buffer *buffer)
403 static const struct sb_jack {
406 } jacks_audigy2nx[] = {
412 }, jacks_live24ext[] = {
413 {4, "line in"}, /* &1=Line, &2=Mic*/
414 {3, "hph out"}, /* headphones */
415 {0, "RC "}, /* last command, 6 bytes see rc_config above */
418 const struct sb_jack *jacks;
419 struct usb_mixer_interface *mixer = entry->private_data;
423 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
424 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
425 jacks = jacks_audigy2nx;
426 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
427 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
428 jacks = jacks_live24ext;
432 for (i = 0; jacks[i].name; ++i) {
433 snd_iprintf(buffer, "%s: ", jacks[i].name);
434 err = snd_usb_lock_shutdown(mixer->chip);
437 err = snd_usb_ctl_msg(mixer->chip->dev,
438 usb_rcvctrlpipe(mixer->chip->dev, 0),
439 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
440 USB_RECIP_INTERFACE, 0,
441 jacks[i].unitid << 8, buf, 3);
442 snd_usb_unlock_shutdown(mixer->chip);
443 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
444 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
446 snd_iprintf(buffer, "?\n");
451 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
452 struct snd_ctl_elem_info *uinfo)
454 static const char * const texts[2] = {"1/2", "3/4"};
456 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
459 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
460 struct snd_ctl_elem_value *ucontrol)
462 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
466 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
469 struct snd_usb_audio *chip = mixer->chip;
471 unsigned char buf[2];
473 err = snd_usb_lock_shutdown(chip);
478 buf[1] = value ? 0x02 : 0x01;
479 err = snd_usb_ctl_msg(chip->dev,
480 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
481 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
482 0x0400, 0x0e00, buf, 2);
483 snd_usb_unlock_shutdown(chip);
487 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
488 struct snd_ctl_elem_value *ucontrol)
490 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
491 struct usb_mixer_interface *mixer = list->mixer;
492 unsigned int value = ucontrol->value.enumerated.item[0];
498 if (value == kcontrol->private_value)
501 kcontrol->private_value = value;
502 err = snd_emu0204_ch_switch_update(mixer, value);
503 return err < 0 ? err : 1;
506 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
508 return snd_emu0204_ch_switch_update(list->mixer,
509 list->kctl->private_value);
512 static const struct snd_kcontrol_new snd_emu0204_control = {
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
514 .name = "Front Jack Channels",
515 .info = snd_emu0204_ch_switch_info,
516 .get = snd_emu0204_ch_switch_get,
517 .put = snd_emu0204_ch_switch_put,
521 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
523 return add_single_ctl_with_resume(mixer, 0,
524 snd_emu0204_ch_switch_resume,
525 &snd_emu0204_control, NULL);
528 /* ASUS Xonar U1 / U3 controls */
530 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
531 struct snd_ctl_elem_value *ucontrol)
533 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
537 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
538 unsigned char status)
540 struct snd_usb_audio *chip = mixer->chip;
543 err = snd_usb_lock_shutdown(chip);
546 err = snd_usb_ctl_msg(chip->dev,
547 usb_sndctrlpipe(chip->dev, 0), 0x08,
548 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
550 snd_usb_unlock_shutdown(chip);
554 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_value *ucontrol)
557 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
558 u8 old_status, new_status;
561 old_status = kcontrol->private_value;
562 if (ucontrol->value.integer.value[0])
563 new_status = old_status | 0x02;
565 new_status = old_status & ~0x02;
566 if (new_status == old_status)
569 kcontrol->private_value = new_status;
570 err = snd_xonar_u1_switch_update(list->mixer, new_status);
571 return err < 0 ? err : 1;
574 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
576 return snd_xonar_u1_switch_update(list->mixer,
577 list->kctl->private_value);
580 static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
582 .name = "Digital Playback Switch",
583 .info = snd_ctl_boolean_mono_info,
584 .get = snd_xonar_u1_switch_get,
585 .put = snd_xonar_u1_switch_put,
586 .private_value = 0x05,
589 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
591 return add_single_ctl_with_resume(mixer, 0,
592 snd_xonar_u1_switch_resume,
593 &snd_xonar_u1_output_switch, NULL);
596 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
598 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
599 struct snd_ctl_elem_value *ucontrol)
601 ucontrol->value.enumerated.item[0] = kctl->private_value;
605 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
607 struct snd_usb_audio *chip = mixer->chip;
609 unsigned char buff[3];
611 err = snd_usb_lock_shutdown(chip);
615 /* Prepare for magic command to toggle clock source */
616 err = snd_usb_ctl_msg(chip->dev,
617 usb_rcvctrlpipe(chip->dev, 0), 0x81,
620 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
623 err = snd_usb_ctl_msg(chip->dev,
624 usb_rcvctrlpipe(chip->dev, 0), 0x81,
627 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
631 /* 2 possibilities: Internal -> send sample rate
632 * S/PDIF sync -> send zeroes
633 * NB: Sample rate locked to 48kHz on purpose to
634 * prevent user from resetting the sample rate
635 * while S/PDIF sync is enabled and confusing
636 * this configuration.
643 buff[0] = buff[1] = buff[2] = 0x00;
646 /* Send the magic command to toggle the clock source */
647 err = snd_usb_ctl_msg(chip->dev,
648 usb_sndctrlpipe(chip->dev, 0), 0x1,
650 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
653 err = snd_usb_ctl_msg(chip->dev,
654 usb_rcvctrlpipe(chip->dev, 0), 0x81,
657 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
660 err = snd_usb_ctl_msg(chip->dev,
661 usb_rcvctrlpipe(chip->dev, 0), 0x81,
664 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
669 snd_usb_unlock_shutdown(chip);
673 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
674 struct snd_ctl_elem_value *ucontrol)
676 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
677 struct usb_mixer_interface *mixer = list->mixer;
679 bool cur_val, new_val;
681 cur_val = kctl->private_value;
682 new_val = ucontrol->value.enumerated.item[0];
683 if (cur_val == new_val)
686 kctl->private_value = new_val;
687 err = snd_mbox1_switch_update(mixer, new_val);
688 return err < 0 ? err : 1;
691 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
694 static const char *const texts[2] = {
699 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
702 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
704 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
707 static const struct snd_kcontrol_new snd_mbox1_switch = {
708 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
709 .name = "Clock Source",
711 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
712 .info = snd_mbox1_switch_info,
713 .get = snd_mbox1_switch_get,
714 .put = snd_mbox1_switch_put,
718 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
720 return add_single_ctl_with_resume(mixer, 0,
721 snd_mbox1_switch_resume,
722 &snd_mbox1_switch, NULL);
725 /* Native Instruments device quirks */
727 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
729 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
730 struct snd_kcontrol *kctl)
732 struct usb_device *dev = mixer->chip->dev;
733 unsigned int pval = kctl->private_value;
737 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
739 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
740 0, pval & 0xffff, &value, 1);
743 "unable to issue vendor read request (ret = %d)", err);
747 kctl->private_value |= ((unsigned int)value << 24);
751 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
752 struct snd_ctl_elem_value *ucontrol)
754 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
758 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
760 struct snd_usb_audio *chip = list->mixer->chip;
761 unsigned int pval = list->kctl->private_value;
764 err = snd_usb_lock_shutdown(chip);
767 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
769 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
770 pval >> 24, pval & 0xffff, NULL, 0, 1000);
771 snd_usb_unlock_shutdown(chip);
775 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
776 struct snd_ctl_elem_value *ucontrol)
778 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
779 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
780 u8 newval = ucontrol->value.integer.value[0];
783 if (oldval == newval)
786 kcontrol->private_value &= ~(0xff << 24);
787 kcontrol->private_value |= (unsigned int)newval << 24;
788 err = snd_ni_update_cur_val(list);
789 return err < 0 ? err : 1;
792 static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
794 .name = "Direct Thru Channel A",
795 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
798 .name = "Direct Thru Channel B",
799 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
802 .name = "Phono Input Channel A",
803 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
806 .name = "Phono Input Channel B",
807 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
811 static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
813 .name = "Direct Thru Channel A",
814 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
817 .name = "Direct Thru Channel B",
818 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
821 .name = "Direct Thru Channel C",
822 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
825 .name = "Direct Thru Channel D",
826 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
829 .name = "Phono Input Channel A",
830 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
833 .name = "Phono Input Channel B",
834 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
837 .name = "Phono Input Channel C",
838 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
841 .name = "Phono Input Channel D",
842 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
846 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
847 const struct snd_kcontrol_new *kc,
851 struct snd_kcontrol_new template = {
852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
854 .get = snd_nativeinstruments_control_get,
855 .put = snd_nativeinstruments_control_put,
856 .info = snd_ctl_boolean_mono_info,
859 for (i = 0; i < count; i++) {
860 struct usb_mixer_elem_list *list;
862 template.name = kc[i].name;
863 template.private_value = kc[i].private_value;
865 err = add_single_ctl_with_resume(mixer, 0,
866 snd_ni_update_cur_val,
870 snd_ni_control_init_val(mixer, list->kctl);
876 /* M-Audio FastTrack Ultra quirks */
877 /* FTU Effect switch (also used by C400/C600) */
878 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
879 struct snd_ctl_elem_info *uinfo)
881 static const char *const texts[8] = {
882 "Room 1", "Room 2", "Room 3", "Hall 1",
883 "Hall 2", "Plate", "Delay", "Echo"
886 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
889 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
890 struct snd_kcontrol *kctl)
892 struct usb_device *dev = mixer->chip->dev;
893 unsigned int pval = kctl->private_value;
895 unsigned char value[2];
900 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
901 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
903 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
908 kctl->private_value |= (unsigned int)value[0] << 24;
912 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
913 struct snd_ctl_elem_value *ucontrol)
915 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
919 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
921 struct snd_usb_audio *chip = list->mixer->chip;
922 unsigned int pval = list->kctl->private_value;
923 unsigned char value[2];
926 value[0] = pval >> 24;
929 err = snd_usb_lock_shutdown(chip);
932 err = snd_usb_ctl_msg(chip->dev,
933 usb_sndctrlpipe(chip->dev, 0),
935 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
937 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
939 snd_usb_unlock_shutdown(chip);
943 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
944 struct snd_ctl_elem_value *ucontrol)
946 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
947 unsigned int pval = list->kctl->private_value;
948 int cur_val, err, new_val;
950 cur_val = pval >> 24;
951 new_val = ucontrol->value.enumerated.item[0];
952 if (cur_val == new_val)
955 kctl->private_value &= ~(0xff << 24);
956 kctl->private_value |= new_val << 24;
957 err = snd_ftu_eff_switch_update(list);
958 return err < 0 ? err : 1;
961 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
962 int validx, int bUnitID)
964 static struct snd_kcontrol_new template = {
965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
966 .name = "Effect Program Switch",
968 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
969 .info = snd_ftu_eff_switch_info,
970 .get = snd_ftu_eff_switch_get,
971 .put = snd_ftu_eff_switch_put
973 struct usb_mixer_elem_list *list;
976 err = add_single_ctl_with_resume(mixer, bUnitID,
977 snd_ftu_eff_switch_update,
981 list->kctl->private_value = (validx << 8) | bUnitID;
982 snd_ftu_eff_switch_init(mixer, list->kctl);
986 /* Create volume controls for FTU devices*/
987 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
990 unsigned int control, cmask;
993 const unsigned int id = 5;
994 const int val_type = USB_MIXER_S16;
996 for (out = 0; out < 8; out++) {
998 for (in = 0; in < 8; in++) {
1000 snprintf(name, sizeof(name),
1001 "AIn%d - Out%d Capture Volume",
1003 err = snd_create_std_mono_ctl(mixer, id, control,
1004 cmask, val_type, name,
1005 &snd_usb_mixer_vol_tlv);
1009 for (in = 8; in < 16; in++) {
1011 snprintf(name, sizeof(name),
1012 "DIn%d - Out%d Playback Volume",
1014 err = snd_create_std_mono_ctl(mixer, id, control,
1015 cmask, val_type, name,
1016 &snd_usb_mixer_vol_tlv);
1025 /* This control needs a volume quirk, see mixer.c */
1026 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1028 static const char name[] = "Effect Volume";
1029 const unsigned int id = 6;
1030 const int val_type = USB_MIXER_U8;
1031 const unsigned int control = 2;
1032 const unsigned int cmask = 0;
1034 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1035 name, snd_usb_mixer_vol_tlv);
1038 /* This control needs a volume quirk, see mixer.c */
1039 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1041 static const char name[] = "Effect Duration";
1042 const unsigned int id = 6;
1043 const int val_type = USB_MIXER_S16;
1044 const unsigned int control = 3;
1045 const unsigned int cmask = 0;
1047 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1048 name, snd_usb_mixer_vol_tlv);
1051 /* This control needs a volume quirk, see mixer.c */
1052 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1054 static const char name[] = "Effect Feedback Volume";
1055 const unsigned int id = 6;
1056 const int val_type = USB_MIXER_U8;
1057 const unsigned int control = 4;
1058 const unsigned int cmask = 0;
1060 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1064 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1070 const unsigned int id = 7;
1071 const int val_type = USB_MIXER_S16;
1072 const unsigned int control = 7;
1074 for (ch = 0; ch < 4; ++ch) {
1076 snprintf(name, sizeof(name),
1077 "Effect Return %d Volume", ch + 1);
1078 err = snd_create_std_mono_ctl(mixer, id, control,
1079 cmask, val_type, name,
1080 snd_usb_mixer_vol_tlv);
1088 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1094 const unsigned int id = 5;
1095 const int val_type = USB_MIXER_S16;
1096 const unsigned int control = 9;
1098 for (ch = 0; ch < 8; ++ch) {
1100 snprintf(name, sizeof(name),
1101 "Effect Send AIn%d Volume", ch + 1);
1102 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1104 snd_usb_mixer_vol_tlv);
1108 for (ch = 8; ch < 16; ++ch) {
1110 snprintf(name, sizeof(name),
1111 "Effect Send DIn%d Volume", ch - 7);
1112 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1114 snd_usb_mixer_vol_tlv);
1121 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1125 err = snd_ftu_create_volume_ctls(mixer);
1129 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1133 err = snd_ftu_create_effect_volume_ctl(mixer);
1137 err = snd_ftu_create_effect_duration_ctl(mixer);
1141 err = snd_ftu_create_effect_feedback_ctl(mixer);
1145 err = snd_ftu_create_effect_return_ctls(mixer);
1149 err = snd_ftu_create_effect_send_ctls(mixer);
1156 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1157 unsigned char samplerate_id)
1159 struct usb_mixer_interface *mixer;
1160 struct usb_mixer_elem_info *cval;
1161 int unitid = 12; /* SampleRate ExtensionUnit ID */
1163 list_for_each_entry(mixer, &chip->mixer_list, list) {
1164 if (mixer->id_elems[unitid]) {
1165 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1166 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1169 snd_usb_mixer_notify_id(mixer, unitid);
1175 /* M-Audio Fast Track C400/C600 */
1176 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1177 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1180 unsigned int cmask, offset;
1185 const unsigned int id = 0x40;
1186 const int val_type = USB_MIXER_S16;
1187 const int control = 1;
1189 switch (mixer->chip->usb_id) {
1190 case USB_ID(0x0763, 0x2030):
1194 case USB_ID(0x0763, 0x2031):
1200 for (chan = 0; chan < num_outs + num_ins; chan++) {
1201 for (out = 0; out < num_outs; out++) {
1202 if (chan < num_outs) {
1203 snprintf(name, sizeof(name),
1204 "PCM%d-Out%d Playback Volume",
1207 snprintf(name, sizeof(name),
1208 "In%d-Out%d Playback Volume",
1209 chan - num_outs + 1, out + 1);
1212 cmask = (out == 0) ? 0 : 1 << (out - 1);
1213 offset = chan * num_outs;
1214 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1215 cmask, val_type, offset, name,
1216 &snd_usb_mixer_vol_tlv);
1225 /* This control needs a volume quirk, see mixer.c */
1226 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1228 static const char name[] = "Effect Volume";
1229 const unsigned int id = 0x43;
1230 const int val_type = USB_MIXER_U8;
1231 const unsigned int control = 3;
1232 const unsigned int cmask = 0;
1234 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1235 name, snd_usb_mixer_vol_tlv);
1238 /* This control needs a volume quirk, see mixer.c */
1239 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1241 static const char name[] = "Effect Duration";
1242 const unsigned int id = 0x43;
1243 const int val_type = USB_MIXER_S16;
1244 const unsigned int control = 4;
1245 const unsigned int cmask = 0;
1247 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1248 name, snd_usb_mixer_vol_tlv);
1251 /* This control needs a volume quirk, see mixer.c */
1252 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1254 static const char name[] = "Effect Feedback Volume";
1255 const unsigned int id = 0x43;
1256 const int val_type = USB_MIXER_U8;
1257 const unsigned int control = 5;
1258 const unsigned int cmask = 0;
1260 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1264 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1272 const unsigned int id = 0x42;
1273 const int val_type = USB_MIXER_S16;
1274 const int control = 1;
1276 switch (mixer->chip->usb_id) {
1277 case USB_ID(0x0763, 0x2030):
1281 case USB_ID(0x0763, 0x2031):
1287 for (chan = 0; chan < num_outs + num_ins; chan++) {
1288 if (chan < num_outs) {
1289 snprintf(name, sizeof(name),
1290 "Effect Send DOut%d",
1293 snprintf(name, sizeof(name),
1294 "Effect Send AIn%d",
1295 chan - num_outs + 1);
1298 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1299 err = snd_create_std_mono_ctl(mixer, id, control,
1300 cmask, val_type, name,
1301 &snd_usb_mixer_vol_tlv);
1309 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1317 const unsigned int id = 0x40;
1318 const int val_type = USB_MIXER_S16;
1319 const int control = 1;
1321 switch (mixer->chip->usb_id) {
1322 case USB_ID(0x0763, 0x2030):
1325 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1327 case USB_ID(0x0763, 0x2031):
1330 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1334 for (chan = 0; chan < num_outs; chan++) {
1335 snprintf(name, sizeof(name),
1339 cmask = (chan == 0) ? 0 :
1340 1 << (chan + (chan % 2) * num_outs - 1);
1341 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1342 cmask, val_type, offset, name,
1343 &snd_usb_mixer_vol_tlv);
1351 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1355 err = snd_c400_create_vol_ctls(mixer);
1359 err = snd_c400_create_effect_vol_ctls(mixer);
1363 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1367 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1371 err = snd_c400_create_effect_volume_ctl(mixer);
1375 err = snd_c400_create_effect_duration_ctl(mixer);
1379 err = snd_c400_create_effect_feedback_ctl(mixer);
1387 * The mixer units for Ebox-44 are corrupt, and even where they
1388 * are valid they presents mono controls as L and R channels of
1389 * stereo. So we provide a good mixer here.
1391 static const struct std_mono_table ebox44_table[] = {
1396 .val_type = USB_MIXER_INV_BOOLEAN,
1397 .name = "Headphone Playback Switch"
1403 .val_type = USB_MIXER_S16,
1404 .name = "Headphone A Mix Playback Volume"
1410 .val_type = USB_MIXER_S16,
1411 .name = "Headphone B Mix Playback Volume"
1418 .val_type = USB_MIXER_INV_BOOLEAN,
1419 .name = "Output Playback Switch"
1425 .val_type = USB_MIXER_S16,
1426 .name = "Output A Playback Volume"
1432 .val_type = USB_MIXER_S16,
1433 .name = "Output B Playback Volume"
1440 .val_type = USB_MIXER_INV_BOOLEAN,
1441 .name = "Input Capture Switch"
1447 .val_type = USB_MIXER_S16,
1448 .name = "Input A Capture Volume"
1454 .val_type = USB_MIXER_S16,
1455 .name = "Input B Capture Volume"
1461 /* Audio Advantage Micro II findings:
1463 * Mapping spdif AES bits to vendor register.bit:
1464 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1465 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1466 * AES2: [0 0 0 0 0 0 0 0]
1467 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1468 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1472 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1473 * just after it to 0xa0, presumably it disables/mutes some analog
1474 * parts when there is no audio.)
1477 * Optical transmitter on/off:
1478 * vendor register.bit: 9.1
1479 * 0 - on (0x28 register value)
1480 * 1 - off (0x2a register value)
1483 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1484 struct snd_ctl_elem_info *uinfo)
1486 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1491 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1492 struct snd_ctl_elem_value *ucontrol)
1494 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1495 struct snd_usb_audio *chip = list->mixer->chip;
1497 struct usb_interface *iface;
1498 struct usb_host_interface *alts;
1500 unsigned char data[3];
1503 err = snd_usb_lock_shutdown(chip);
1507 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1508 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1509 ucontrol->value.iec958.status[2] = 0x00;
1511 /* use known values for that card: interface#1 altsetting#1 */
1512 iface = usb_ifnum_to_if(chip->dev, 1);
1513 if (!iface || iface->num_altsetting < 2) {
1517 alts = &iface->altsetting[1];
1518 if (get_iface_desc(alts)->bNumEndpoints < 1) {
1522 ep = get_endpoint(alts, 0)->bEndpointAddress;
1524 err = snd_usb_ctl_msg(chip->dev,
1525 usb_rcvctrlpipe(chip->dev, 0),
1527 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1528 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1535 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1536 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1537 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1541 snd_usb_unlock_shutdown(chip);
1545 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1547 struct snd_usb_audio *chip = list->mixer->chip;
1548 unsigned int pval = list->kctl->private_value;
1552 err = snd_usb_lock_shutdown(chip);
1556 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1557 err = snd_usb_ctl_msg(chip->dev,
1558 usb_sndctrlpipe(chip->dev, 0),
1560 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1568 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1569 reg |= (pval >> 12) & 0x0f;
1570 err = snd_usb_ctl_msg(chip->dev,
1571 usb_sndctrlpipe(chip->dev, 0),
1573 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1582 snd_usb_unlock_shutdown(chip);
1586 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1587 struct snd_ctl_elem_value *ucontrol)
1589 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1590 unsigned int pval, pval_old;
1593 pval = pval_old = kcontrol->private_value;
1595 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1596 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1599 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1601 /* The frequency bits in AES3 cannot be set via register access. */
1603 /* Silently ignore any bits from the request that cannot be set. */
1605 if (pval == pval_old)
1608 kcontrol->private_value = pval;
1609 err = snd_microii_spdif_default_update(list);
1610 return err < 0 ? err : 1;
1613 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1614 struct snd_ctl_elem_value *ucontrol)
1616 ucontrol->value.iec958.status[0] = 0x0f;
1617 ucontrol->value.iec958.status[1] = 0xff;
1618 ucontrol->value.iec958.status[2] = 0x00;
1619 ucontrol->value.iec958.status[3] = 0x00;
1624 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol)
1627 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1632 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1634 struct snd_usb_audio *chip = list->mixer->chip;
1635 u8 reg = list->kctl->private_value;
1638 err = snd_usb_lock_shutdown(chip);
1642 err = snd_usb_ctl_msg(chip->dev,
1643 usb_sndctrlpipe(chip->dev, 0),
1645 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1651 snd_usb_unlock_shutdown(chip);
1655 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1656 struct snd_ctl_elem_value *ucontrol)
1658 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1662 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1663 if (reg != list->kctl->private_value)
1666 kcontrol->private_value = reg;
1667 err = snd_microii_spdif_switch_update(list);
1668 return err < 0 ? err : 1;
1671 static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1673 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1674 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1675 .info = snd_microii_spdif_info,
1676 .get = snd_microii_spdif_default_get,
1677 .put = snd_microii_spdif_default_put,
1678 .private_value = 0x00000100UL,/* reset value */
1681 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1682 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1683 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1684 .info = snd_microii_spdif_info,
1685 .get = snd_microii_spdif_mask_get,
1688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1690 .info = snd_ctl_boolean_mono_info,
1691 .get = snd_microii_spdif_switch_get,
1692 .put = snd_microii_spdif_switch_put,
1693 .private_value = 0x00000028UL,/* reset value */
1697 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1700 static const usb_mixer_elem_resume_func_t resume_funcs[] = {
1701 snd_microii_spdif_default_update,
1703 snd_microii_spdif_switch_update
1706 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1707 err = add_single_ctl_with_resume(mixer, 0,
1709 &snd_microii_mixer_spdif[i],
1718 /* Creative Sound Blaster E1 */
1720 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1721 struct snd_ctl_elem_value *ucontrol)
1723 ucontrol->value.integer.value[0] = kcontrol->private_value;
1727 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1728 unsigned char state)
1730 struct snd_usb_audio *chip = mixer->chip;
1732 unsigned char buff[2];
1735 buff[1] = state ? 0x02 : 0x00;
1737 err = snd_usb_lock_shutdown(chip);
1740 err = snd_usb_ctl_msg(chip->dev,
1741 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1742 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1743 0x0202, 3, buff, 2);
1744 snd_usb_unlock_shutdown(chip);
1748 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1749 struct snd_ctl_elem_value *ucontrol)
1751 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1752 unsigned char value = !!ucontrol->value.integer.value[0];
1755 if (kcontrol->private_value == value)
1757 kcontrol->private_value = value;
1758 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1759 return err < 0 ? err : 1;
1762 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1764 return snd_soundblaster_e1_switch_update(list->mixer,
1765 list->kctl->private_value);
1768 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1769 struct snd_ctl_elem_info *uinfo)
1771 static const char *const texts[2] = {
1775 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1778 static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1780 .name = "Input Source",
1781 .info = snd_soundblaster_e1_switch_info,
1782 .get = snd_soundblaster_e1_switch_get,
1783 .put = snd_soundblaster_e1_switch_put,
1787 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1789 return add_single_ctl_with_resume(mixer, 0,
1790 snd_soundblaster_e1_switch_resume,
1791 &snd_soundblaster_e1_input_switch,
1795 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1799 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1800 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1801 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1805 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1807 /* fix to 0dB playback volumes */
1808 dell_dock_init_vol(mixer->chip, 1, 16);
1809 dell_dock_init_vol(mixer->chip, 2, 16);
1810 dell_dock_init_vol(mixer->chip, 1, 19);
1811 dell_dock_init_vol(mixer->chip, 2, 19);
1815 /* RME Class Compliant device quirks */
1817 #define SND_RME_GET_STATUS1 23
1818 #define SND_RME_GET_CURRENT_FREQ 17
1819 #define SND_RME_CLK_SYSTEM_SHIFT 16
1820 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1821 #define SND_RME_CLK_AES_SHIFT 8
1822 #define SND_RME_CLK_SPDIF_SHIFT 12
1823 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1824 #define SND_RME_CLK_SYNC_SHIFT 6
1825 #define SND_RME_CLK_SYNC_MASK 0x3
1826 #define SND_RME_CLK_FREQMUL_SHIFT 18
1827 #define SND_RME_CLK_FREQMUL_MASK 0x7
1828 #define SND_RME_CLK_SYSTEM(x) \
1829 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1830 #define SND_RME_CLK_AES(x) \
1831 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1832 #define SND_RME_CLK_SPDIF(x) \
1833 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1834 #define SND_RME_CLK_SYNC(x) \
1835 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1836 #define SND_RME_CLK_FREQMUL(x) \
1837 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1838 #define SND_RME_CLK_AES_LOCK 0x1
1839 #define SND_RME_CLK_AES_SYNC 0x4
1840 #define SND_RME_CLK_SPDIF_LOCK 0x2
1841 #define SND_RME_CLK_SPDIF_SYNC 0x8
1842 #define SND_RME_SPDIF_IF_SHIFT 4
1843 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1844 #define SND_RME_BINARY_MASK 0x1
1845 #define SND_RME_SPDIF_IF(x) \
1846 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1847 #define SND_RME_SPDIF_FORMAT(x) \
1848 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1850 static const u32 snd_rme_rate_table[] = {
1851 32000, 44100, 48000, 50000,
1852 64000, 88200, 96000, 100000,
1853 128000, 176400, 192000, 200000,
1854 256000, 352800, 384000, 400000,
1855 512000, 705600, 768000, 800000
1857 /* maximum number of items for AES and S/PDIF rates for above table */
1858 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1860 enum snd_rme_domain {
1861 SND_RME_DOMAIN_SYSTEM,
1863 SND_RME_DOMAIN_SPDIF
1866 enum snd_rme_clock_status {
1867 SND_RME_CLOCK_NOLOCK,
1872 static int snd_rme_read_value(struct snd_usb_audio *chip,
1876 struct usb_device *dev = chip->dev;
1879 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1881 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1883 value, sizeof(*value));
1886 "unable to issue vendor read request %d (ret = %d)",
1891 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1894 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1895 struct snd_usb_audio *chip = list->mixer->chip;
1898 err = snd_usb_lock_shutdown(chip);
1901 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1902 snd_usb_unlock_shutdown(chip);
1906 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1907 struct snd_ctl_elem_value *ucontrol)
1914 err = snd_rme_get_status1(kcontrol, &status1);
1917 switch (kcontrol->private_value) {
1918 case SND_RME_DOMAIN_SYSTEM:
1919 idx = SND_RME_CLK_SYSTEM(status1);
1920 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1921 rate = snd_rme_rate_table[idx];
1923 case SND_RME_DOMAIN_AES:
1924 idx = SND_RME_CLK_AES(status1);
1925 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1926 rate = snd_rme_rate_table[idx];
1928 case SND_RME_DOMAIN_SPDIF:
1929 idx = SND_RME_CLK_SPDIF(status1);
1930 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1931 rate = snd_rme_rate_table[idx];
1936 ucontrol->value.integer.value[0] = rate;
1940 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1941 struct snd_ctl_elem_value *ucontrol)
1944 int idx = SND_RME_CLOCK_NOLOCK;
1947 err = snd_rme_get_status1(kcontrol, &status1);
1950 switch (kcontrol->private_value) {
1951 case SND_RME_DOMAIN_AES: /* AES */
1952 if (status1 & SND_RME_CLK_AES_SYNC)
1953 idx = SND_RME_CLOCK_SYNC;
1954 else if (status1 & SND_RME_CLK_AES_LOCK)
1955 idx = SND_RME_CLOCK_LOCK;
1957 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
1958 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1959 idx = SND_RME_CLOCK_SYNC;
1960 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1961 idx = SND_RME_CLOCK_LOCK;
1966 ucontrol->value.enumerated.item[0] = idx;
1970 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1971 struct snd_ctl_elem_value *ucontrol)
1976 err = snd_rme_get_status1(kcontrol, &status1);
1979 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1983 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1984 struct snd_ctl_elem_value *ucontrol)
1989 err = snd_rme_get_status1(kcontrol, &status1);
1992 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1996 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1997 struct snd_ctl_elem_value *ucontrol)
2002 err = snd_rme_get_status1(kcontrol, &status1);
2005 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2009 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2010 struct snd_ctl_elem_value *ucontrol)
2012 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2013 struct snd_usb_audio *chip = list->mixer->chip;
2015 const u64 num = 104857600000000ULL;
2020 err = snd_usb_lock_shutdown(chip);
2023 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2026 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2029 freq = (den == 0) ? 0 : div64_u64(num, den);
2030 freq <<= SND_RME_CLK_FREQMUL(status1);
2031 ucontrol->value.integer.value[0] = freq;
2034 snd_usb_unlock_shutdown(chip);
2038 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2039 struct snd_ctl_elem_info *uinfo)
2041 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2043 switch (kcontrol->private_value) {
2044 case SND_RME_DOMAIN_SYSTEM:
2045 uinfo->value.integer.min = 32000;
2046 uinfo->value.integer.max = 800000;
2048 case SND_RME_DOMAIN_AES:
2049 case SND_RME_DOMAIN_SPDIF:
2051 uinfo->value.integer.min = 0;
2052 uinfo->value.integer.max = 200000;
2054 uinfo->value.integer.step = 0;
2058 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_info *uinfo)
2061 static const char *const sync_states[] = {
2062 "No Lock", "Lock", "Sync"
2065 return snd_ctl_enum_info(uinfo, 1,
2066 ARRAY_SIZE(sync_states), sync_states);
2069 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2070 struct snd_ctl_elem_info *uinfo)
2072 static const char *const spdif_if[] = {
2073 "Coaxial", "Optical"
2076 return snd_ctl_enum_info(uinfo, 1,
2077 ARRAY_SIZE(spdif_if), spdif_if);
2080 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2081 struct snd_ctl_elem_info *uinfo)
2083 static const char *const optical_type[] = {
2084 "Consumer", "Professional"
2087 return snd_ctl_enum_info(uinfo, 1,
2088 ARRAY_SIZE(optical_type), optical_type);
2091 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2092 struct snd_ctl_elem_info *uinfo)
2094 static const char *const sync_sources[] = {
2095 "Internal", "AES", "SPDIF", "Internal"
2098 return snd_ctl_enum_info(uinfo, 1,
2099 ARRAY_SIZE(sync_sources), sync_sources);
2102 static const struct snd_kcontrol_new snd_rme_controls[] = {
2104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2106 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2107 .info = snd_rme_rate_info,
2108 .get = snd_rme_rate_get,
2109 .private_value = SND_RME_DOMAIN_AES
2112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2114 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2115 .info = snd_rme_sync_state_info,
2116 .get = snd_rme_sync_state_get,
2117 .private_value = SND_RME_DOMAIN_AES
2120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2121 .name = "SPDIF Rate",
2122 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2123 .info = snd_rme_rate_info,
2124 .get = snd_rme_rate_get,
2125 .private_value = SND_RME_DOMAIN_SPDIF
2128 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2129 .name = "SPDIF Sync",
2130 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2131 .info = snd_rme_sync_state_info,
2132 .get = snd_rme_sync_state_get,
2133 .private_value = SND_RME_DOMAIN_SPDIF
2136 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2137 .name = "SPDIF Interface",
2138 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2139 .info = snd_rme_spdif_if_info,
2140 .get = snd_rme_spdif_if_get,
2143 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2144 .name = "SPDIF Format",
2145 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2146 .info = snd_rme_spdif_format_info,
2147 .get = snd_rme_spdif_format_get,
2150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151 .name = "Sync Source",
2152 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2153 .info = snd_rme_sync_source_info,
2154 .get = snd_rme_sync_source_get
2157 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2158 .name = "System Rate",
2159 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2160 .info = snd_rme_rate_info,
2161 .get = snd_rme_rate_get,
2162 .private_value = SND_RME_DOMAIN_SYSTEM
2165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2166 .name = "Current Frequency",
2167 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2168 .info = snd_rme_rate_info,
2169 .get = snd_rme_current_freq_get
2173 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2177 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2178 err = add_single_ctl_with_resume(mixer, 0,
2180 &snd_rme_controls[i],
2190 * RME Babyface Pro (FS)
2192 * These devices exposes a couple of DSP functions via request to EP0.
2193 * Switches are available via control registers, while routing is controlled
2194 * by controlling the volume on each possible crossing point.
2195 * Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with
2196 * 0dB being at dec. 32768.
2199 SND_BBFPRO_CTL_REG1 = 0,
2203 #define SND_BBFPRO_CTL_REG_MASK 1
2204 #define SND_BBFPRO_CTL_IDX_MASK 0xff
2205 #define SND_BBFPRO_CTL_IDX_SHIFT 1
2206 #define SND_BBFPRO_CTL_VAL_MASK 1
2207 #define SND_BBFPRO_CTL_VAL_SHIFT 9
2208 #define SND_BBFPRO_CTL_REG1_CLK_MASTER 0
2209 #define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1
2210 #define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7
2211 #define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8
2212 #define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10
2213 #define SND_BBFPRO_CTL_REG2_48V_AN1 0
2214 #define SND_BBFPRO_CTL_REG2_48V_AN2 1
2215 #define SND_BBFPRO_CTL_REG2_SENS_IN3 2
2216 #define SND_BBFPRO_CTL_REG2_SENS_IN4 3
2217 #define SND_BBFPRO_CTL_REG2_PAD_AN1 4
2218 #define SND_BBFPRO_CTL_REG2_PAD_AN2 5
2220 #define SND_BBFPRO_MIXER_IDX_MASK 0x1ff
2221 #define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff
2222 #define SND_BBFPRO_MIXER_VAL_SHIFT 9
2223 #define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf
2224 #define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB
2226 #define SND_BBFPRO_USBREQ_CTL_REG1 0x10
2227 #define SND_BBFPRO_USBREQ_CTL_REG2 0x17
2228 #define SND_BBFPRO_USBREQ_MIXER 0x12
2230 static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
2234 u16 usb_req, usb_idx, usb_val;
2235 struct snd_usb_audio *chip = mixer->chip;
2237 err = snd_usb_lock_shutdown(chip);
2241 if (reg == SND_BBFPRO_CTL_REG1) {
2242 usb_req = SND_BBFPRO_USBREQ_CTL_REG1;
2243 if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2245 usb_val = value ? 3 : 0;
2247 usb_idx = 1 << index;
2248 usb_val = value ? usb_idx : 0;
2251 usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
2252 usb_idx = 1 << index;
2253 usb_val = value ? usb_idx : 0;
2256 err = snd_usb_ctl_msg(chip->dev,
2257 usb_sndctrlpipe(chip->dev, 0), usb_req,
2258 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2259 usb_val, usb_idx, NULL, 0);
2261 snd_usb_unlock_shutdown(chip);
2265 static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol,
2266 struct snd_ctl_elem_value *ucontrol)
2271 pv = kcontrol->private_value;
2272 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2273 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2274 val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT;
2276 if ((reg == SND_BBFPRO_CTL_REG1 &&
2277 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2278 (reg == SND_BBFPRO_CTL_REG2 &&
2279 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2280 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2281 ucontrol->value.enumerated.item[0] = val;
2283 ucontrol->value.integer.value[0] = val;
2288 static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol,
2289 struct snd_ctl_elem_info *uinfo)
2294 pv = kcontrol->private_value;
2295 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2296 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2298 if (reg == SND_BBFPRO_CTL_REG1 &&
2299 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2300 static const char * const texts[2] = {
2304 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2305 } else if (reg == SND_BBFPRO_CTL_REG2 &&
2306 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2307 idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) {
2308 static const char * const texts[2] = {
2312 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2316 uinfo->value.integer.min = 0;
2317 uinfo->value.integer.max = 1;
2318 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2322 static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol,
2323 struct snd_ctl_elem_value *ucontrol)
2327 int old_value, pv, val;
2329 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2330 struct usb_mixer_interface *mixer = list->mixer;
2332 pv = kcontrol->private_value;
2333 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2334 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2335 old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2337 if ((reg == SND_BBFPRO_CTL_REG1 &&
2338 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2339 (reg == SND_BBFPRO_CTL_REG2 &&
2340 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2341 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2342 val = ucontrol->value.enumerated.item[0];
2344 val = ucontrol->value.integer.value[0];
2350 if (val == old_value)
2353 kcontrol->private_value = reg
2354 | ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT)
2355 | ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT);
2357 err = snd_bbfpro_ctl_update(mixer, reg, idx, val);
2358 return err < 0 ? err : 1;
2361 static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list)
2366 pv = list->kctl->private_value;
2367 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2368 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2369 value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2371 return snd_bbfpro_ctl_update(list->mixer, reg, idx, value);
2374 static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index,
2377 struct snd_usb_audio *chip = mixer->chip;
2380 u16 usb_idx, usb_val;
2383 err = snd_usb_lock_shutdown(chip);
2387 idx = index & SND_BBFPRO_MIXER_IDX_MASK;
2388 // 18 bit linear volume, split so 2 bits end up in index.
2389 v = value & SND_BBFPRO_MIXER_VAL_MASK;
2390 usb_idx = idx | (v & 0x3) << 14;
2391 usb_val = (v >> 2) & 0xffff;
2393 err = snd_usb_ctl_msg(chip->dev,
2394 usb_sndctrlpipe(chip->dev, 0),
2395 SND_BBFPRO_USBREQ_MIXER,
2396 USB_DIR_OUT | USB_TYPE_VENDOR |
2398 usb_val, usb_idx, NULL, 0);
2400 snd_usb_unlock_shutdown(chip);
2404 static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2407 ucontrol->value.integer.value[0] =
2408 kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2412 static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_info *uinfo)
2415 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2417 uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN;
2418 uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX;
2422 static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol,
2423 struct snd_ctl_elem_value *ucontrol)
2427 u32 new_val, old_value, uvalue;
2428 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2429 struct usb_mixer_interface *mixer = list->mixer;
2431 uvalue = ucontrol->value.integer.value[0];
2432 idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK;
2433 old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2435 if (uvalue > SND_BBFPRO_MIXER_VAL_MAX)
2438 if (uvalue == old_value)
2441 new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK;
2443 kcontrol->private_value = idx
2444 | (new_val << SND_BBFPRO_MIXER_VAL_SHIFT);
2446 err = snd_bbfpro_vol_update(mixer, idx, new_val);
2447 return err < 0 ? err : 1;
2450 static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list)
2452 int pv = list->kctl->private_value;
2453 u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK;
2454 u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT)
2455 & SND_BBFPRO_MIXER_VAL_MASK;
2456 return snd_bbfpro_vol_update(list->mixer, idx, val);
2459 // Predfine elements
2460 static const struct snd_kcontrol_new snd_bbfpro_ctl_control = {
2461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2462 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2464 .info = snd_bbfpro_ctl_info,
2465 .get = snd_bbfpro_ctl_get,
2466 .put = snd_bbfpro_ctl_put
2469 static const struct snd_kcontrol_new snd_bbfpro_vol_control = {
2470 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2471 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2473 .info = snd_bbfpro_vol_info,
2474 .get = snd_bbfpro_vol_get,
2475 .put = snd_bbfpro_vol_put
2478 static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg,
2479 u8 index, char *name)
2481 struct snd_kcontrol_new knew = snd_bbfpro_ctl_control;
2484 knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK)
2485 | ((index & SND_BBFPRO_CTL_IDX_MASK)
2486 << SND_BBFPRO_CTL_IDX_SHIFT);
2488 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume,
2492 static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index,
2495 struct snd_kcontrol_new knew = snd_bbfpro_vol_control;
2498 knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK;
2500 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume,
2504 static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)
2509 static const char * const input[] = {
2510 "AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3",
2511 "ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2513 static const char * const output[] = {
2514 "AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4",
2515 "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2517 for (o = 0 ; o < 12 ; ++o) {
2518 for (i = 0 ; i < 12 ; ++i) {
2520 snprintf(name, sizeof(name),
2521 "%s-%s-%s Playback Volume",
2522 (i < 2 ? "Mic" : "Line"),
2523 input[i], output[o]);
2524 err = snd_bbfpro_vol_add(mixer, (26 * o + i), name);
2528 // PCM routing... yes, it is output remapping
2529 snprintf(name, sizeof(name),
2530 "PCM-%s-%s Playback Volume",
2531 output[i], output[o]);
2532 err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i),
2540 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2541 SND_BBFPRO_CTL_REG1_CLK_OPTICAL,
2542 "Sample Clock Source");
2546 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2547 SND_BBFPRO_CTL_REG1_SPDIF_PRO,
2552 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2553 SND_BBFPRO_CTL_REG1_SPDIF_EMPH,
2558 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2559 SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL,
2565 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2566 SND_BBFPRO_CTL_REG2_48V_AN1,
2571 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2572 SND_BBFPRO_CTL_REG2_48V_AN2,
2577 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2578 SND_BBFPRO_CTL_REG2_SENS_IN3,
2583 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2584 SND_BBFPRO_CTL_REG2_SENS_IN4,
2589 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2590 SND_BBFPRO_CTL_REG2_PAD_AN1,
2595 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2596 SND_BBFPRO_CTL_REG2_PAD_AN2,
2604 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2608 err = snd_usb_soundblaster_remote_init(mixer);
2612 switch (mixer->chip->usb_id) {
2613 /* Tascam US-16x08 */
2614 case USB_ID(0x0644, 0x8047):
2615 err = snd_us16x08_controls_create(mixer);
2617 case USB_ID(0x041e, 0x3020):
2618 case USB_ID(0x041e, 0x3040):
2619 case USB_ID(0x041e, 0x3042):
2620 case USB_ID(0x041e, 0x30df):
2621 case USB_ID(0x041e, 0x3048):
2622 err = snd_audigy2nx_controls_create(mixer);
2625 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2626 mixer, snd_audigy2nx_proc_read);
2630 case USB_ID(0x041e, 0x3f19):
2631 err = snd_emu0204_controls_create(mixer);
2634 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2635 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2636 err = snd_c400_create_mixer(mixer);
2639 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2640 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2641 err = snd_ftu_create_mixer(mixer);
2644 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2645 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2646 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2647 err = snd_xonar_u1_controls_create(mixer);
2650 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2651 err = snd_microii_controls_create(mixer);
2654 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2655 err = snd_mbox1_create_sync_switch(mixer);
2658 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2659 err = snd_nativeinstruments_create_mixer(mixer,
2660 snd_nativeinstruments_ta6_mixers,
2661 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2664 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2665 err = snd_nativeinstruments_create_mixer(mixer,
2666 snd_nativeinstruments_ta10_mixers,
2667 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2670 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2671 /* detection is disabled in mixer_maps.c */
2672 err = snd_create_std_mono_table(mixer, ebox44_table);
2675 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2676 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2677 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2678 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2679 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2680 err = snd_scarlett_controls_create(mixer);
2683 case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
2684 case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
2685 case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
2686 err = snd_scarlett_gen2_controls_create(mixer);
2689 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2690 err = snd_soundblaster_e1_switch_create(mixer);
2692 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2693 err = dell_dock_mixer_init(mixer);
2696 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2697 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2698 case USB_ID(0x2a39, 0x3fd4): /* RME */
2699 err = snd_rme_controls_create(mixer);
2702 case USB_ID(0x0194f, 0x010c): /* Presonus Studio 1810c */
2703 err = snd_sc1810_init_mixer(mixer);
2705 case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */
2706 err = snd_bbfpro_controls_create(mixer);
2714 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2716 switch (mixer->chip->usb_id) {
2717 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2718 dell_dock_mixer_init(mixer);
2724 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2729 /* unit ids specific to Extigy/Audigy 2 NX: */
2731 case 0: /* remote control */
2732 mixer->rc_urb->dev = mixer->chip->dev;
2733 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2735 case 4: /* digital in jack */
2736 case 7: /* line in jacks */
2737 case 19: /* speaker out jacks */
2738 case 20: /* headphones out jack */
2740 /* live24ext: 4 = line-in jack */
2741 case 3: /* hp-out jack (may actuate Mute) */
2742 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2743 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2744 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2747 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2752 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2753 struct usb_mixer_elem_info *cval,
2754 struct snd_kcontrol *kctl)
2756 /* Approximation using 10 ranges based on output measurement on hw v1.2.
2757 * This seems close to the cubic mapping e.g. alsamixer uses. */
2758 static const DECLARE_TLV_DB_RANGE(scale,
2759 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2760 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2761 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2762 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2763 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2764 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2765 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2766 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2767 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2768 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2771 if (cval->min == 0 && cval->max == 50) {
2772 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2773 kctl->tlv.p = scale;
2774 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2775 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2777 } else if (cval->min == 0 && cval->max <= 1000) {
2778 /* Some other clearly broken DragonFly variant.
2779 * At least a 0..53 variant (hw v1.0) exists.
2781 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2782 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2786 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2787 struct usb_mixer_elem_info *cval, int unitid,
2788 struct snd_kcontrol *kctl)
2790 switch (mixer->chip->usb_id) {
2791 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2792 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2793 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2795 /* lowest playback value is muted on C-Media devices */
2796 case USB_ID(0x0d8c, 0x000c):
2797 case USB_ID(0x0d8c, 0x0014):
2798 if (strstr(kctl->id.name, "Playback"))