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 return snd_usb_mixer_add_control(list, kctl);
165 * Sound Blaster remote control configuration
167 * format of remote control data:
169 * Audigy 2 NX: 06 80 xx 00 00 00
170 * Live! 24-bit: 06 80 xx yy 22 83
172 static const struct rc_config {
177 u8 min_packet_length; /* minimum accepted length of the URB result */
181 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
182 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
183 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
184 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
185 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
186 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
187 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
190 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
192 struct usb_mixer_interface *mixer = urb->context;
193 const struct rc_config *rc = mixer->rc_cfg;
196 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
199 code = mixer->rc_buffer[rc->offset];
201 code |= mixer->rc_buffer[rc->offset + 1] << 8;
203 /* the Mute button actually changes the mixer control */
204 if (code == rc->mute_code)
205 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
206 mixer->rc_code = code;
208 wake_up(&mixer->rc_waitq);
211 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
212 long count, loff_t *offset)
214 struct usb_mixer_interface *mixer = hw->private_data;
218 if (count != 1 && count != 4)
220 err = wait_event_interruptible(mixer->rc_waitq,
221 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
224 err = put_user(rc_code, buf);
226 err = put_user(rc_code, (u32 __user *)buf);
228 return err < 0 ? err : count;
231 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
234 struct usb_mixer_interface *mixer = hw->private_data;
236 poll_wait(file, &mixer->rc_waitq, wait);
237 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
240 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
242 struct snd_hwdep *hwdep;
245 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
246 if (rc_configs[i].usb_id == mixer->chip->usb_id)
248 if (i >= ARRAY_SIZE(rc_configs))
250 mixer->rc_cfg = &rc_configs[i];
252 len = mixer->rc_cfg->packet_length;
254 init_waitqueue_head(&mixer->rc_waitq);
255 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
258 snprintf(hwdep->name, sizeof(hwdep->name),
259 "%s remote control", mixer->chip->card->shortname);
260 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
261 hwdep->private_data = mixer;
262 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
263 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
264 hwdep->exclusive = 1;
266 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
269 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
270 if (!mixer->rc_setup_packet) {
271 usb_free_urb(mixer->rc_urb);
272 mixer->rc_urb = NULL;
275 mixer->rc_setup_packet->bRequestType =
276 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
277 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
278 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
279 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
280 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
281 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
282 usb_rcvctrlpipe(mixer->chip->dev, 0),
283 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
284 snd_usb_soundblaster_remote_complete, mixer);
288 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
290 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
292 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
296 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
297 int value, int index)
299 struct snd_usb_audio *chip = mixer->chip;
302 err = snd_usb_lock_shutdown(chip);
306 if (chip->usb_id == USB_ID(0x041e, 0x3042))
307 err = snd_usb_ctl_msg(chip->dev,
308 usb_sndctrlpipe(chip->dev, 0), 0x24,
309 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
311 /* USB X-Fi S51 Pro */
312 if (chip->usb_id == USB_ID(0x041e, 0x30df))
313 err = snd_usb_ctl_msg(chip->dev,
314 usb_sndctrlpipe(chip->dev, 0), 0x24,
315 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
318 err = snd_usb_ctl_msg(chip->dev,
319 usb_sndctrlpipe(chip->dev, 0), 0x24,
320 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
321 value, index + 2, NULL, 0);
322 snd_usb_unlock_shutdown(chip);
326 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
329 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
330 struct usb_mixer_interface *mixer = list->mixer;
331 int index = kcontrol->private_value & 0xff;
332 unsigned int value = ucontrol->value.integer.value[0];
333 int old_value = kcontrol->private_value >> 8;
338 if (value == old_value)
340 kcontrol->private_value = (value << 8) | index;
341 err = snd_audigy2nx_led_update(mixer, value, index);
342 return err < 0 ? err : 1;
345 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
347 int priv_value = list->kctl->private_value;
349 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
353 /* name and private_value are set dynamically */
354 static const struct snd_kcontrol_new snd_audigy2nx_control = {
355 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
356 .info = snd_audigy2nx_led_info,
357 .get = snd_audigy2nx_led_get,
358 .put = snd_audigy2nx_led_put,
361 static const char * const snd_audigy2nx_led_names[] = {
364 "Dolby Digital LED Switch",
367 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
371 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
372 struct snd_kcontrol_new knew;
374 /* USB X-Fi S51 doesn't have a CMSS LED */
375 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
377 /* USB X-Fi S51 Pro doesn't have one either */
378 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
380 if (i > 1 && /* Live24ext has 2 LEDs only */
381 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
382 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
383 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
384 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
387 knew = snd_audigy2nx_control;
388 knew.name = snd_audigy2nx_led_names[i];
389 knew.private_value = (1 << 8) | i; /* LED on as default */
390 err = add_single_ctl_with_resume(mixer, 0,
391 snd_audigy2nx_led_resume,
399 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
400 struct snd_info_buffer *buffer)
402 static const struct sb_jack {
405 } jacks_audigy2nx[] = {
411 }, jacks_live24ext[] = {
412 {4, "line in"}, /* &1=Line, &2=Mic*/
413 {3, "hph out"}, /* headphones */
414 {0, "RC "}, /* last command, 6 bytes see rc_config above */
417 const struct sb_jack *jacks;
418 struct usb_mixer_interface *mixer = entry->private_data;
422 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
423 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
424 jacks = jacks_audigy2nx;
425 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
426 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
427 jacks = jacks_live24ext;
431 for (i = 0; jacks[i].name; ++i) {
432 snd_iprintf(buffer, "%s: ", jacks[i].name);
433 err = snd_usb_lock_shutdown(mixer->chip);
436 err = snd_usb_ctl_msg(mixer->chip->dev,
437 usb_rcvctrlpipe(mixer->chip->dev, 0),
438 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
439 USB_RECIP_INTERFACE, 0,
440 jacks[i].unitid << 8, buf, 3);
441 snd_usb_unlock_shutdown(mixer->chip);
442 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
443 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
445 snd_iprintf(buffer, "?\n");
450 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_info *uinfo)
453 static const char * const texts[2] = {"1/2", "3/4"};
455 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
458 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
459 struct snd_ctl_elem_value *ucontrol)
461 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
465 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
468 struct snd_usb_audio *chip = mixer->chip;
470 unsigned char buf[2];
472 err = snd_usb_lock_shutdown(chip);
477 buf[1] = value ? 0x02 : 0x01;
478 err = snd_usb_ctl_msg(chip->dev,
479 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
480 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
481 0x0400, 0x0e00, buf, 2);
482 snd_usb_unlock_shutdown(chip);
486 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
487 struct snd_ctl_elem_value *ucontrol)
489 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
490 struct usb_mixer_interface *mixer = list->mixer;
491 unsigned int value = ucontrol->value.enumerated.item[0];
497 if (value == kcontrol->private_value)
500 kcontrol->private_value = value;
501 err = snd_emu0204_ch_switch_update(mixer, value);
502 return err < 0 ? err : 1;
505 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
507 return snd_emu0204_ch_switch_update(list->mixer,
508 list->kctl->private_value);
511 static const struct snd_kcontrol_new snd_emu0204_control = {
512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
513 .name = "Front Jack Channels",
514 .info = snd_emu0204_ch_switch_info,
515 .get = snd_emu0204_ch_switch_get,
516 .put = snd_emu0204_ch_switch_put,
520 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
522 return add_single_ctl_with_resume(mixer, 0,
523 snd_emu0204_ch_switch_resume,
524 &snd_emu0204_control, NULL);
527 /* ASUS Xonar U1 / U3 controls */
529 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
530 struct snd_ctl_elem_value *ucontrol)
532 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
536 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
537 unsigned char status)
539 struct snd_usb_audio *chip = mixer->chip;
542 err = snd_usb_lock_shutdown(chip);
545 err = snd_usb_ctl_msg(chip->dev,
546 usb_sndctrlpipe(chip->dev, 0), 0x08,
547 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
549 snd_usb_unlock_shutdown(chip);
553 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
554 struct snd_ctl_elem_value *ucontrol)
556 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
557 u8 old_status, new_status;
560 old_status = kcontrol->private_value;
561 if (ucontrol->value.integer.value[0])
562 new_status = old_status | 0x02;
564 new_status = old_status & ~0x02;
565 if (new_status == old_status)
568 kcontrol->private_value = new_status;
569 err = snd_xonar_u1_switch_update(list->mixer, new_status);
570 return err < 0 ? err : 1;
573 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
575 return snd_xonar_u1_switch_update(list->mixer,
576 list->kctl->private_value);
579 static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
581 .name = "Digital Playback Switch",
582 .info = snd_ctl_boolean_mono_info,
583 .get = snd_xonar_u1_switch_get,
584 .put = snd_xonar_u1_switch_put,
585 .private_value = 0x05,
588 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
590 return add_single_ctl_with_resume(mixer, 0,
591 snd_xonar_u1_switch_resume,
592 &snd_xonar_u1_output_switch, NULL);
595 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
597 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
598 struct snd_ctl_elem_value *ucontrol)
600 ucontrol->value.enumerated.item[0] = kctl->private_value;
604 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
606 struct snd_usb_audio *chip = mixer->chip;
608 unsigned char buff[3];
610 err = snd_usb_lock_shutdown(chip);
614 /* Prepare for magic command to toggle clock source */
615 err = snd_usb_ctl_msg(chip->dev,
616 usb_rcvctrlpipe(chip->dev, 0), 0x81,
619 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
622 err = snd_usb_ctl_msg(chip->dev,
623 usb_rcvctrlpipe(chip->dev, 0), 0x81,
626 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
630 /* 2 possibilities: Internal -> send sample rate
631 * S/PDIF sync -> send zeroes
632 * NB: Sample rate locked to 48kHz on purpose to
633 * prevent user from resetting the sample rate
634 * while S/PDIF sync is enabled and confusing
635 * this configuration.
642 buff[0] = buff[1] = buff[2] = 0x00;
645 /* Send the magic command to toggle the clock source */
646 err = snd_usb_ctl_msg(chip->dev,
647 usb_sndctrlpipe(chip->dev, 0), 0x1,
649 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
652 err = snd_usb_ctl_msg(chip->dev,
653 usb_rcvctrlpipe(chip->dev, 0), 0x81,
656 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
659 err = snd_usb_ctl_msg(chip->dev,
660 usb_rcvctrlpipe(chip->dev, 0), 0x81,
663 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
668 snd_usb_unlock_shutdown(chip);
672 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
673 struct snd_ctl_elem_value *ucontrol)
675 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
676 struct usb_mixer_interface *mixer = list->mixer;
678 bool cur_val, new_val;
680 cur_val = kctl->private_value;
681 new_val = ucontrol->value.enumerated.item[0];
682 if (cur_val == new_val)
685 kctl->private_value = new_val;
686 err = snd_mbox1_switch_update(mixer, new_val);
687 return err < 0 ? err : 1;
690 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
691 struct snd_ctl_elem_info *uinfo)
693 static const char *const texts[2] = {
698 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
701 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
703 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
706 static const struct snd_kcontrol_new snd_mbox1_switch = {
707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
708 .name = "Clock Source",
710 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
711 .info = snd_mbox1_switch_info,
712 .get = snd_mbox1_switch_get,
713 .put = snd_mbox1_switch_put,
717 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
719 return add_single_ctl_with_resume(mixer, 0,
720 snd_mbox1_switch_resume,
721 &snd_mbox1_switch, NULL);
724 /* Native Instruments device quirks */
726 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
728 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
729 struct snd_kcontrol *kctl)
731 struct usb_device *dev = mixer->chip->dev;
732 unsigned int pval = kctl->private_value;
736 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
738 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
739 0, pval & 0xffff, &value, 1);
742 "unable to issue vendor read request (ret = %d)", err);
746 kctl->private_value |= ((unsigned int)value << 24);
750 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
751 struct snd_ctl_elem_value *ucontrol)
753 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
757 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
759 struct snd_usb_audio *chip = list->mixer->chip;
760 unsigned int pval = list->kctl->private_value;
763 err = snd_usb_lock_shutdown(chip);
766 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
768 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
769 pval >> 24, pval & 0xffff, NULL, 0, 1000);
770 snd_usb_unlock_shutdown(chip);
774 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_value *ucontrol)
777 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
778 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
779 u8 newval = ucontrol->value.integer.value[0];
782 if (oldval == newval)
785 kcontrol->private_value &= ~(0xff << 24);
786 kcontrol->private_value |= (unsigned int)newval << 24;
787 err = snd_ni_update_cur_val(list);
788 return err < 0 ? err : 1;
791 static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
793 .name = "Direct Thru Channel A",
794 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
797 .name = "Direct Thru Channel B",
798 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
801 .name = "Phono Input Channel A",
802 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
805 .name = "Phono Input Channel B",
806 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
810 static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
812 .name = "Direct Thru Channel A",
813 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
816 .name = "Direct Thru Channel B",
817 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
820 .name = "Direct Thru Channel C",
821 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
824 .name = "Direct Thru Channel D",
825 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
828 .name = "Phono Input Channel A",
829 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
832 .name = "Phono Input Channel B",
833 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
836 .name = "Phono Input Channel C",
837 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
840 .name = "Phono Input Channel D",
841 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
845 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
846 const struct snd_kcontrol_new *kc,
850 struct snd_kcontrol_new template = {
851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
853 .get = snd_nativeinstruments_control_get,
854 .put = snd_nativeinstruments_control_put,
855 .info = snd_ctl_boolean_mono_info,
858 for (i = 0; i < count; i++) {
859 struct usb_mixer_elem_list *list;
861 template.name = kc[i].name;
862 template.private_value = kc[i].private_value;
864 err = add_single_ctl_with_resume(mixer, 0,
865 snd_ni_update_cur_val,
869 snd_ni_control_init_val(mixer, list->kctl);
875 /* M-Audio FastTrack Ultra quirks */
876 /* FTU Effect switch (also used by C400/C600) */
877 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
878 struct snd_ctl_elem_info *uinfo)
880 static const char *const texts[8] = {
881 "Room 1", "Room 2", "Room 3", "Hall 1",
882 "Hall 2", "Plate", "Delay", "Echo"
885 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
888 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
889 struct snd_kcontrol *kctl)
891 struct usb_device *dev = mixer->chip->dev;
892 unsigned int pval = kctl->private_value;
894 unsigned char value[2];
899 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
900 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
902 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
907 kctl->private_value |= (unsigned int)value[0] << 24;
911 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
912 struct snd_ctl_elem_value *ucontrol)
914 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
918 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
920 struct snd_usb_audio *chip = list->mixer->chip;
921 unsigned int pval = list->kctl->private_value;
922 unsigned char value[2];
925 value[0] = pval >> 24;
928 err = snd_usb_lock_shutdown(chip);
931 err = snd_usb_ctl_msg(chip->dev,
932 usb_sndctrlpipe(chip->dev, 0),
934 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
936 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
938 snd_usb_unlock_shutdown(chip);
942 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
943 struct snd_ctl_elem_value *ucontrol)
945 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
946 unsigned int pval = list->kctl->private_value;
947 int cur_val, err, new_val;
949 cur_val = pval >> 24;
950 new_val = ucontrol->value.enumerated.item[0];
951 if (cur_val == new_val)
954 kctl->private_value &= ~(0xff << 24);
955 kctl->private_value |= new_val << 24;
956 err = snd_ftu_eff_switch_update(list);
957 return err < 0 ? err : 1;
960 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
961 int validx, int bUnitID)
963 static struct snd_kcontrol_new template = {
964 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
965 .name = "Effect Program Switch",
967 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
968 .info = snd_ftu_eff_switch_info,
969 .get = snd_ftu_eff_switch_get,
970 .put = snd_ftu_eff_switch_put
972 struct usb_mixer_elem_list *list;
975 err = add_single_ctl_with_resume(mixer, bUnitID,
976 snd_ftu_eff_switch_update,
980 list->kctl->private_value = (validx << 8) | bUnitID;
981 snd_ftu_eff_switch_init(mixer, list->kctl);
985 /* Create volume controls for FTU devices*/
986 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
989 unsigned int control, cmask;
992 const unsigned int id = 5;
993 const int val_type = USB_MIXER_S16;
995 for (out = 0; out < 8; out++) {
997 for (in = 0; in < 8; in++) {
999 snprintf(name, sizeof(name),
1000 "AIn%d - Out%d Capture Volume",
1002 err = snd_create_std_mono_ctl(mixer, id, control,
1003 cmask, val_type, name,
1004 &snd_usb_mixer_vol_tlv);
1008 for (in = 8; in < 16; in++) {
1010 snprintf(name, sizeof(name),
1011 "DIn%d - Out%d Playback Volume",
1013 err = snd_create_std_mono_ctl(mixer, id, control,
1014 cmask, val_type, name,
1015 &snd_usb_mixer_vol_tlv);
1024 /* This control needs a volume quirk, see mixer.c */
1025 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1027 static const char name[] = "Effect Volume";
1028 const unsigned int id = 6;
1029 const int val_type = USB_MIXER_U8;
1030 const unsigned int control = 2;
1031 const unsigned int cmask = 0;
1033 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1034 name, snd_usb_mixer_vol_tlv);
1037 /* This control needs a volume quirk, see mixer.c */
1038 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1040 static const char name[] = "Effect Duration";
1041 const unsigned int id = 6;
1042 const int val_type = USB_MIXER_S16;
1043 const unsigned int control = 3;
1044 const unsigned int cmask = 0;
1046 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1047 name, snd_usb_mixer_vol_tlv);
1050 /* This control needs a volume quirk, see mixer.c */
1051 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1053 static const char name[] = "Effect Feedback Volume";
1054 const unsigned int id = 6;
1055 const int val_type = USB_MIXER_U8;
1056 const unsigned int control = 4;
1057 const unsigned int cmask = 0;
1059 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1063 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1069 const unsigned int id = 7;
1070 const int val_type = USB_MIXER_S16;
1071 const unsigned int control = 7;
1073 for (ch = 0; ch < 4; ++ch) {
1075 snprintf(name, sizeof(name),
1076 "Effect Return %d Volume", ch + 1);
1077 err = snd_create_std_mono_ctl(mixer, id, control,
1078 cmask, val_type, name,
1079 snd_usb_mixer_vol_tlv);
1087 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1093 const unsigned int id = 5;
1094 const int val_type = USB_MIXER_S16;
1095 const unsigned int control = 9;
1097 for (ch = 0; ch < 8; ++ch) {
1099 snprintf(name, sizeof(name),
1100 "Effect Send AIn%d Volume", ch + 1);
1101 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1103 snd_usb_mixer_vol_tlv);
1107 for (ch = 8; ch < 16; ++ch) {
1109 snprintf(name, sizeof(name),
1110 "Effect Send DIn%d Volume", ch - 7);
1111 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1113 snd_usb_mixer_vol_tlv);
1120 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1124 err = snd_ftu_create_volume_ctls(mixer);
1128 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1132 err = snd_ftu_create_effect_volume_ctl(mixer);
1136 err = snd_ftu_create_effect_duration_ctl(mixer);
1140 err = snd_ftu_create_effect_feedback_ctl(mixer);
1144 err = snd_ftu_create_effect_return_ctls(mixer);
1148 err = snd_ftu_create_effect_send_ctls(mixer);
1155 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1156 unsigned char samplerate_id)
1158 struct usb_mixer_interface *mixer;
1159 struct usb_mixer_elem_info *cval;
1160 int unitid = 12; /* SampleRate ExtensionUnit ID */
1162 list_for_each_entry(mixer, &chip->mixer_list, list) {
1163 if (mixer->id_elems[unitid]) {
1164 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1165 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1168 snd_usb_mixer_notify_id(mixer, unitid);
1174 /* M-Audio Fast Track C400/C600 */
1175 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1176 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1179 unsigned int cmask, offset;
1184 const unsigned int id = 0x40;
1185 const int val_type = USB_MIXER_S16;
1186 const int control = 1;
1188 switch (mixer->chip->usb_id) {
1189 case USB_ID(0x0763, 0x2030):
1193 case USB_ID(0x0763, 0x2031):
1199 for (chan = 0; chan < num_outs + num_ins; chan++) {
1200 for (out = 0; out < num_outs; out++) {
1201 if (chan < num_outs) {
1202 snprintf(name, sizeof(name),
1203 "PCM%d-Out%d Playback Volume",
1206 snprintf(name, sizeof(name),
1207 "In%d-Out%d Playback Volume",
1208 chan - num_outs + 1, out + 1);
1211 cmask = (out == 0) ? 0 : 1 << (out - 1);
1212 offset = chan * num_outs;
1213 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1214 cmask, val_type, offset, name,
1215 &snd_usb_mixer_vol_tlv);
1224 /* This control needs a volume quirk, see mixer.c */
1225 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1227 static const char name[] = "Effect Volume";
1228 const unsigned int id = 0x43;
1229 const int val_type = USB_MIXER_U8;
1230 const unsigned int control = 3;
1231 const unsigned int cmask = 0;
1233 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1234 name, snd_usb_mixer_vol_tlv);
1237 /* This control needs a volume quirk, see mixer.c */
1238 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1240 static const char name[] = "Effect Duration";
1241 const unsigned int id = 0x43;
1242 const int val_type = USB_MIXER_S16;
1243 const unsigned int control = 4;
1244 const unsigned int cmask = 0;
1246 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1247 name, snd_usb_mixer_vol_tlv);
1250 /* This control needs a volume quirk, see mixer.c */
1251 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1253 static const char name[] = "Effect Feedback Volume";
1254 const unsigned int id = 0x43;
1255 const int val_type = USB_MIXER_U8;
1256 const unsigned int control = 5;
1257 const unsigned int cmask = 0;
1259 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1263 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1271 const unsigned int id = 0x42;
1272 const int val_type = USB_MIXER_S16;
1273 const int control = 1;
1275 switch (mixer->chip->usb_id) {
1276 case USB_ID(0x0763, 0x2030):
1280 case USB_ID(0x0763, 0x2031):
1286 for (chan = 0; chan < num_outs + num_ins; chan++) {
1287 if (chan < num_outs) {
1288 snprintf(name, sizeof(name),
1289 "Effect Send DOut%d",
1292 snprintf(name, sizeof(name),
1293 "Effect Send AIn%d",
1294 chan - num_outs + 1);
1297 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1298 err = snd_create_std_mono_ctl(mixer, id, control,
1299 cmask, val_type, name,
1300 &snd_usb_mixer_vol_tlv);
1308 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1316 const unsigned int id = 0x40;
1317 const int val_type = USB_MIXER_S16;
1318 const int control = 1;
1320 switch (mixer->chip->usb_id) {
1321 case USB_ID(0x0763, 0x2030):
1324 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1326 case USB_ID(0x0763, 0x2031):
1329 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1333 for (chan = 0; chan < num_outs; chan++) {
1334 snprintf(name, sizeof(name),
1338 cmask = (chan == 0) ? 0 :
1339 1 << (chan + (chan % 2) * num_outs - 1);
1340 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1341 cmask, val_type, offset, name,
1342 &snd_usb_mixer_vol_tlv);
1350 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1354 err = snd_c400_create_vol_ctls(mixer);
1358 err = snd_c400_create_effect_vol_ctls(mixer);
1362 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1366 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1370 err = snd_c400_create_effect_volume_ctl(mixer);
1374 err = snd_c400_create_effect_duration_ctl(mixer);
1378 err = snd_c400_create_effect_feedback_ctl(mixer);
1386 * The mixer units for Ebox-44 are corrupt, and even where they
1387 * are valid they presents mono controls as L and R channels of
1388 * stereo. So we provide a good mixer here.
1390 static const struct std_mono_table ebox44_table[] = {
1395 .val_type = USB_MIXER_INV_BOOLEAN,
1396 .name = "Headphone Playback Switch"
1402 .val_type = USB_MIXER_S16,
1403 .name = "Headphone A Mix Playback Volume"
1409 .val_type = USB_MIXER_S16,
1410 .name = "Headphone B Mix Playback Volume"
1417 .val_type = USB_MIXER_INV_BOOLEAN,
1418 .name = "Output Playback Switch"
1424 .val_type = USB_MIXER_S16,
1425 .name = "Output A Playback Volume"
1431 .val_type = USB_MIXER_S16,
1432 .name = "Output B Playback Volume"
1439 .val_type = USB_MIXER_INV_BOOLEAN,
1440 .name = "Input Capture Switch"
1446 .val_type = USB_MIXER_S16,
1447 .name = "Input A Capture Volume"
1453 .val_type = USB_MIXER_S16,
1454 .name = "Input B Capture Volume"
1460 /* Audio Advantage Micro II findings:
1462 * Mapping spdif AES bits to vendor register.bit:
1463 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1464 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1465 * AES2: [0 0 0 0 0 0 0 0]
1466 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1467 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1471 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1472 * just after it to 0xa0, presumably it disables/mutes some analog
1473 * parts when there is no audio.)
1476 * Optical transmitter on/off:
1477 * vendor register.bit: 9.1
1478 * 0 - on (0x28 register value)
1479 * 1 - off (0x2a register value)
1482 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1483 struct snd_ctl_elem_info *uinfo)
1485 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1490 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1491 struct snd_ctl_elem_value *ucontrol)
1493 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1494 struct snd_usb_audio *chip = list->mixer->chip;
1496 struct usb_interface *iface;
1497 struct usb_host_interface *alts;
1499 unsigned char data[3];
1502 err = snd_usb_lock_shutdown(chip);
1506 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1507 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1508 ucontrol->value.iec958.status[2] = 0x00;
1510 /* use known values for that card: interface#1 altsetting#1 */
1511 iface = usb_ifnum_to_if(chip->dev, 1);
1512 if (!iface || iface->num_altsetting < 2)
1514 alts = &iface->altsetting[1];
1515 if (get_iface_desc(alts)->bNumEndpoints < 1)
1517 ep = get_endpoint(alts, 0)->bEndpointAddress;
1519 err = snd_usb_ctl_msg(chip->dev,
1520 usb_rcvctrlpipe(chip->dev, 0),
1522 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1523 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1530 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1531 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1532 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1536 snd_usb_unlock_shutdown(chip);
1540 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1542 struct snd_usb_audio *chip = list->mixer->chip;
1543 unsigned int pval = list->kctl->private_value;
1547 err = snd_usb_lock_shutdown(chip);
1551 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1552 err = snd_usb_ctl_msg(chip->dev,
1553 usb_sndctrlpipe(chip->dev, 0),
1555 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1563 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1564 reg |= (pval >> 12) & 0x0f;
1565 err = snd_usb_ctl_msg(chip->dev,
1566 usb_sndctrlpipe(chip->dev, 0),
1568 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1577 snd_usb_unlock_shutdown(chip);
1581 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1584 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1585 unsigned int pval, pval_old;
1588 pval = pval_old = kcontrol->private_value;
1590 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1591 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1594 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1596 /* The frequency bits in AES3 cannot be set via register access. */
1598 /* Silently ignore any bits from the request that cannot be set. */
1600 if (pval == pval_old)
1603 kcontrol->private_value = pval;
1604 err = snd_microii_spdif_default_update(list);
1605 return err < 0 ? err : 1;
1608 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1609 struct snd_ctl_elem_value *ucontrol)
1611 ucontrol->value.iec958.status[0] = 0x0f;
1612 ucontrol->value.iec958.status[1] = 0xff;
1613 ucontrol->value.iec958.status[2] = 0x00;
1614 ucontrol->value.iec958.status[3] = 0x00;
1619 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1622 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1627 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1629 struct snd_usb_audio *chip = list->mixer->chip;
1630 u8 reg = list->kctl->private_value;
1633 err = snd_usb_lock_shutdown(chip);
1637 err = snd_usb_ctl_msg(chip->dev,
1638 usb_sndctrlpipe(chip->dev, 0),
1640 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1646 snd_usb_unlock_shutdown(chip);
1650 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1651 struct snd_ctl_elem_value *ucontrol)
1653 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1657 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1658 if (reg != list->kctl->private_value)
1661 kcontrol->private_value = reg;
1662 err = snd_microii_spdif_switch_update(list);
1663 return err < 0 ? err : 1;
1666 static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1668 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1669 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1670 .info = snd_microii_spdif_info,
1671 .get = snd_microii_spdif_default_get,
1672 .put = snd_microii_spdif_default_put,
1673 .private_value = 0x00000100UL,/* reset value */
1676 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1677 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1678 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1679 .info = snd_microii_spdif_info,
1680 .get = snd_microii_spdif_mask_get,
1683 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1684 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1685 .info = snd_ctl_boolean_mono_info,
1686 .get = snd_microii_spdif_switch_get,
1687 .put = snd_microii_spdif_switch_put,
1688 .private_value = 0x00000028UL,/* reset value */
1692 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1695 static const usb_mixer_elem_resume_func_t resume_funcs[] = {
1696 snd_microii_spdif_default_update,
1698 snd_microii_spdif_switch_update
1701 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1702 err = add_single_ctl_with_resume(mixer, 0,
1704 &snd_microii_mixer_spdif[i],
1713 /* Creative Sound Blaster E1 */
1715 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
1718 ucontrol->value.integer.value[0] = kcontrol->private_value;
1722 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1723 unsigned char state)
1725 struct snd_usb_audio *chip = mixer->chip;
1727 unsigned char buff[2];
1730 buff[1] = state ? 0x02 : 0x00;
1732 err = snd_usb_lock_shutdown(chip);
1735 err = snd_usb_ctl_msg(chip->dev,
1736 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1737 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1738 0x0202, 3, buff, 2);
1739 snd_usb_unlock_shutdown(chip);
1743 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1746 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1747 unsigned char value = !!ucontrol->value.integer.value[0];
1750 if (kcontrol->private_value == value)
1752 kcontrol->private_value = value;
1753 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1754 return err < 0 ? err : 1;
1757 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1759 return snd_soundblaster_e1_switch_update(list->mixer,
1760 list->kctl->private_value);
1763 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_info *uinfo)
1766 static const char *const texts[2] = {
1770 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1773 static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1775 .name = "Input Source",
1776 .info = snd_soundblaster_e1_switch_info,
1777 .get = snd_soundblaster_e1_switch_get,
1778 .put = snd_soundblaster_e1_switch_put,
1782 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1784 return add_single_ctl_with_resume(mixer, 0,
1785 snd_soundblaster_e1_switch_resume,
1786 &snd_soundblaster_e1_input_switch,
1790 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1794 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1795 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1796 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1800 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1802 /* fix to 0dB playback volumes */
1803 dell_dock_init_vol(mixer->chip, 1, 16);
1804 dell_dock_init_vol(mixer->chip, 2, 16);
1805 dell_dock_init_vol(mixer->chip, 1, 19);
1806 dell_dock_init_vol(mixer->chip, 2, 19);
1810 /* RME Class Compliant device quirks */
1812 #define SND_RME_GET_STATUS1 23
1813 #define SND_RME_GET_CURRENT_FREQ 17
1814 #define SND_RME_CLK_SYSTEM_SHIFT 16
1815 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1816 #define SND_RME_CLK_AES_SHIFT 8
1817 #define SND_RME_CLK_SPDIF_SHIFT 12
1818 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1819 #define SND_RME_CLK_SYNC_SHIFT 6
1820 #define SND_RME_CLK_SYNC_MASK 0x3
1821 #define SND_RME_CLK_FREQMUL_SHIFT 18
1822 #define SND_RME_CLK_FREQMUL_MASK 0x7
1823 #define SND_RME_CLK_SYSTEM(x) \
1824 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1825 #define SND_RME_CLK_AES(x) \
1826 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1827 #define SND_RME_CLK_SPDIF(x) \
1828 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1829 #define SND_RME_CLK_SYNC(x) \
1830 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1831 #define SND_RME_CLK_FREQMUL(x) \
1832 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1833 #define SND_RME_CLK_AES_LOCK 0x1
1834 #define SND_RME_CLK_AES_SYNC 0x4
1835 #define SND_RME_CLK_SPDIF_LOCK 0x2
1836 #define SND_RME_CLK_SPDIF_SYNC 0x8
1837 #define SND_RME_SPDIF_IF_SHIFT 4
1838 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1839 #define SND_RME_BINARY_MASK 0x1
1840 #define SND_RME_SPDIF_IF(x) \
1841 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1842 #define SND_RME_SPDIF_FORMAT(x) \
1843 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1845 static const u32 snd_rme_rate_table[] = {
1846 32000, 44100, 48000, 50000,
1847 64000, 88200, 96000, 100000,
1848 128000, 176400, 192000, 200000,
1849 256000, 352800, 384000, 400000,
1850 512000, 705600, 768000, 800000
1852 /* maximum number of items for AES and S/PDIF rates for above table */
1853 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1855 enum snd_rme_domain {
1856 SND_RME_DOMAIN_SYSTEM,
1858 SND_RME_DOMAIN_SPDIF
1861 enum snd_rme_clock_status {
1862 SND_RME_CLOCK_NOLOCK,
1867 static int snd_rme_read_value(struct snd_usb_audio *chip,
1871 struct usb_device *dev = chip->dev;
1874 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1876 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1878 value, sizeof(*value));
1881 "unable to issue vendor read request %d (ret = %d)",
1886 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1889 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1890 struct snd_usb_audio *chip = list->mixer->chip;
1893 err = snd_usb_lock_shutdown(chip);
1896 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1897 snd_usb_unlock_shutdown(chip);
1901 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1902 struct snd_ctl_elem_value *ucontrol)
1909 err = snd_rme_get_status1(kcontrol, &status1);
1912 switch (kcontrol->private_value) {
1913 case SND_RME_DOMAIN_SYSTEM:
1914 idx = SND_RME_CLK_SYSTEM(status1);
1915 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1916 rate = snd_rme_rate_table[idx];
1918 case SND_RME_DOMAIN_AES:
1919 idx = SND_RME_CLK_AES(status1);
1920 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1921 rate = snd_rme_rate_table[idx];
1923 case SND_RME_DOMAIN_SPDIF:
1924 idx = SND_RME_CLK_SPDIF(status1);
1925 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1926 rate = snd_rme_rate_table[idx];
1931 ucontrol->value.integer.value[0] = rate;
1935 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1936 struct snd_ctl_elem_value *ucontrol)
1939 int idx = SND_RME_CLOCK_NOLOCK;
1942 err = snd_rme_get_status1(kcontrol, &status1);
1945 switch (kcontrol->private_value) {
1946 case SND_RME_DOMAIN_AES: /* AES */
1947 if (status1 & SND_RME_CLK_AES_SYNC)
1948 idx = SND_RME_CLOCK_SYNC;
1949 else if (status1 & SND_RME_CLK_AES_LOCK)
1950 idx = SND_RME_CLOCK_LOCK;
1952 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
1953 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1954 idx = SND_RME_CLOCK_SYNC;
1955 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1956 idx = SND_RME_CLOCK_LOCK;
1961 ucontrol->value.enumerated.item[0] = idx;
1965 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1966 struct snd_ctl_elem_value *ucontrol)
1971 err = snd_rme_get_status1(kcontrol, &status1);
1974 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1978 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1979 struct snd_ctl_elem_value *ucontrol)
1984 err = snd_rme_get_status1(kcontrol, &status1);
1987 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1991 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1992 struct snd_ctl_elem_value *ucontrol)
1997 err = snd_rme_get_status1(kcontrol, &status1);
2000 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2004 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2005 struct snd_ctl_elem_value *ucontrol)
2007 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2008 struct snd_usb_audio *chip = list->mixer->chip;
2010 const u64 num = 104857600000000ULL;
2015 err = snd_usb_lock_shutdown(chip);
2018 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2021 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2024 freq = (den == 0) ? 0 : div64_u64(num, den);
2025 freq <<= SND_RME_CLK_FREQMUL(status1);
2026 ucontrol->value.integer.value[0] = freq;
2029 snd_usb_unlock_shutdown(chip);
2033 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2034 struct snd_ctl_elem_info *uinfo)
2036 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2038 switch (kcontrol->private_value) {
2039 case SND_RME_DOMAIN_SYSTEM:
2040 uinfo->value.integer.min = 32000;
2041 uinfo->value.integer.max = 800000;
2043 case SND_RME_DOMAIN_AES:
2044 case SND_RME_DOMAIN_SPDIF:
2046 uinfo->value.integer.min = 0;
2047 uinfo->value.integer.max = 200000;
2049 uinfo->value.integer.step = 0;
2053 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2054 struct snd_ctl_elem_info *uinfo)
2056 static const char *const sync_states[] = {
2057 "No Lock", "Lock", "Sync"
2060 return snd_ctl_enum_info(uinfo, 1,
2061 ARRAY_SIZE(sync_states), sync_states);
2064 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2065 struct snd_ctl_elem_info *uinfo)
2067 static const char *const spdif_if[] = {
2068 "Coaxial", "Optical"
2071 return snd_ctl_enum_info(uinfo, 1,
2072 ARRAY_SIZE(spdif_if), spdif_if);
2075 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2076 struct snd_ctl_elem_info *uinfo)
2078 static const char *const optical_type[] = {
2079 "Consumer", "Professional"
2082 return snd_ctl_enum_info(uinfo, 1,
2083 ARRAY_SIZE(optical_type), optical_type);
2086 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2087 struct snd_ctl_elem_info *uinfo)
2089 static const char *const sync_sources[] = {
2090 "Internal", "AES", "SPDIF", "Internal"
2093 return snd_ctl_enum_info(uinfo, 1,
2094 ARRAY_SIZE(sync_sources), sync_sources);
2097 static const struct snd_kcontrol_new snd_rme_controls[] = {
2099 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2101 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2102 .info = snd_rme_rate_info,
2103 .get = snd_rme_rate_get,
2104 .private_value = SND_RME_DOMAIN_AES
2107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2109 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2110 .info = snd_rme_sync_state_info,
2111 .get = snd_rme_sync_state_get,
2112 .private_value = SND_RME_DOMAIN_AES
2115 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2116 .name = "SPDIF Rate",
2117 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2118 .info = snd_rme_rate_info,
2119 .get = snd_rme_rate_get,
2120 .private_value = SND_RME_DOMAIN_SPDIF
2123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2124 .name = "SPDIF Sync",
2125 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2126 .info = snd_rme_sync_state_info,
2127 .get = snd_rme_sync_state_get,
2128 .private_value = SND_RME_DOMAIN_SPDIF
2131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2132 .name = "SPDIF Interface",
2133 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2134 .info = snd_rme_spdif_if_info,
2135 .get = snd_rme_spdif_if_get,
2138 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2139 .name = "SPDIF Format",
2140 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2141 .info = snd_rme_spdif_format_info,
2142 .get = snd_rme_spdif_format_get,
2145 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2146 .name = "Sync Source",
2147 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2148 .info = snd_rme_sync_source_info,
2149 .get = snd_rme_sync_source_get
2152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2153 .name = "System Rate",
2154 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2155 .info = snd_rme_rate_info,
2156 .get = snd_rme_rate_get,
2157 .private_value = SND_RME_DOMAIN_SYSTEM
2160 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2161 .name = "Current Frequency",
2162 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2163 .info = snd_rme_rate_info,
2164 .get = snd_rme_current_freq_get
2168 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2172 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2173 err = add_single_ctl_with_resume(mixer, 0,
2175 &snd_rme_controls[i],
2184 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2188 err = snd_usb_soundblaster_remote_init(mixer);
2192 switch (mixer->chip->usb_id) {
2193 /* Tascam US-16x08 */
2194 case USB_ID(0x0644, 0x8047):
2195 err = snd_us16x08_controls_create(mixer);
2197 case USB_ID(0x041e, 0x3020):
2198 case USB_ID(0x041e, 0x3040):
2199 case USB_ID(0x041e, 0x3042):
2200 case USB_ID(0x041e, 0x30df):
2201 case USB_ID(0x041e, 0x3048):
2202 err = snd_audigy2nx_controls_create(mixer);
2205 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2206 mixer, snd_audigy2nx_proc_read);
2210 case USB_ID(0x041e, 0x3f19):
2211 err = snd_emu0204_controls_create(mixer);
2214 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2215 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2216 err = snd_c400_create_mixer(mixer);
2219 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2220 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2221 err = snd_ftu_create_mixer(mixer);
2224 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2225 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2226 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2227 err = snd_xonar_u1_controls_create(mixer);
2230 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2231 err = snd_microii_controls_create(mixer);
2234 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2235 err = snd_mbox1_create_sync_switch(mixer);
2238 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2239 err = snd_nativeinstruments_create_mixer(mixer,
2240 snd_nativeinstruments_ta6_mixers,
2241 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2244 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2245 err = snd_nativeinstruments_create_mixer(mixer,
2246 snd_nativeinstruments_ta10_mixers,
2247 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2250 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2251 /* detection is disabled in mixer_maps.c */
2252 err = snd_create_std_mono_table(mixer, ebox44_table);
2255 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2256 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2257 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2258 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2259 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2260 err = snd_scarlett_controls_create(mixer);
2263 case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
2264 case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
2265 case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
2266 err = snd_scarlett_gen2_controls_create(mixer);
2269 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2270 err = snd_soundblaster_e1_switch_create(mixer);
2272 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2273 err = dell_dock_mixer_init(mixer);
2276 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2277 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2278 case USB_ID(0x2a39, 0x3fd4): /* RME */
2279 err = snd_rme_controls_create(mixer);
2282 case USB_ID(0x0194f, 0x010c): /* Presonus Studio 1810c */
2283 err = snd_sc1810_init_mixer(mixer);
2291 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2293 switch (mixer->chip->usb_id) {
2294 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2295 dell_dock_mixer_init(mixer);
2301 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2306 /* unit ids specific to Extigy/Audigy 2 NX: */
2308 case 0: /* remote control */
2309 mixer->rc_urb->dev = mixer->chip->dev;
2310 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2312 case 4: /* digital in jack */
2313 case 7: /* line in jacks */
2314 case 19: /* speaker out jacks */
2315 case 20: /* headphones out jack */
2317 /* live24ext: 4 = line-in jack */
2318 case 3: /* hp-out jack (may actuate Mute) */
2319 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2320 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2321 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2324 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2329 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2330 struct usb_mixer_elem_info *cval,
2331 struct snd_kcontrol *kctl)
2333 /* Approximation using 10 ranges based on output measurement on hw v1.2.
2334 * This seems close to the cubic mapping e.g. alsamixer uses. */
2335 static const DECLARE_TLV_DB_RANGE(scale,
2336 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2337 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2338 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2339 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2340 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2341 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2342 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2343 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2344 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2345 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2348 if (cval->min == 0 && cval->max == 50) {
2349 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2350 kctl->tlv.p = scale;
2351 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2352 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2354 } else if (cval->min == 0 && cval->max <= 1000) {
2355 /* Some other clearly broken DragonFly variant.
2356 * At least a 0..53 variant (hw v1.0) exists.
2358 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2359 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2363 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2364 struct usb_mixer_elem_info *cval, int unitid,
2365 struct snd_kcontrol *kctl)
2367 switch (mixer->chip->usb_id) {
2368 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2369 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2370 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2372 /* lowest playback value is muted on C-Media devices */
2373 case USB_ID(0x0d8c, 0x000c):
2374 case USB_ID(0x0d8c, 0x0014):
2375 if (strstr(kctl->id.name, "Playback"))