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"
39 struct std_mono_table {
40 unsigned int unitid, control, cmask;
43 snd_kcontrol_tlv_rw_t *tlv_callback;
46 /* This function allows for the creation of standard UAC controls.
47 * See the quirks for M-Audio FTUs or Ebox-44.
48 * If you don't want to set a TLV callback pass NULL.
50 * Since there doesn't seem to be a devices that needs a multichannel
51 * version, we keep it mono for simplicity.
53 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
60 snd_kcontrol_tlv_rw_t *tlv_callback)
62 struct usb_mixer_elem_info *cval;
63 struct snd_kcontrol *kctl;
65 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
69 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
70 cval->val_type = val_type;
72 cval->control = control;
74 cval->idx_off = idx_off;
76 /* get_min_max() is called only for integer volumes later,
77 * so provide a short-cut for booleans */
85 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
92 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
93 kctl->private_free = snd_usb_mixer_elem_free;
97 kctl->tlv.c = tlv_callback;
99 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
100 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
102 /* Add control to mixer */
103 return snd_usb_mixer_add_control(&cval->head, kctl);
106 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
108 unsigned int control,
112 snd_kcontrol_tlv_rw_t *tlv_callback)
114 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
115 val_type, 0 /* Offset */, name, tlv_callback);
119 * Create a set of standard UAC controls from a table
121 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
122 struct std_mono_table *t)
126 while (t->name != NULL) {
127 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
128 t->cmask, t->val_type, t->name, t->tlv_callback);
137 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
139 usb_mixer_elem_resume_func_t resume,
140 const struct snd_kcontrol_new *knew,
141 struct usb_mixer_elem_list **listp)
143 struct usb_mixer_elem_list *list;
144 struct snd_kcontrol *kctl;
146 list = kzalloc(sizeof(*list), GFP_KERNEL);
153 list->resume = resume;
154 kctl = snd_ctl_new1(knew, list);
159 kctl->private_free = snd_usb_mixer_elem_free;
160 return snd_usb_mixer_add_control(list, kctl);
164 * Sound Blaster remote control configuration
166 * format of remote control data:
168 * Audigy 2 NX: 06 80 xx 00 00 00
169 * Live! 24-bit: 06 80 xx yy 22 83
171 static const struct rc_config {
176 u8 min_packet_length; /* minimum accepted length of the URB result */
180 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
181 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
182 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
183 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
184 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
185 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
186 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
189 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
191 struct usb_mixer_interface *mixer = urb->context;
192 const struct rc_config *rc = mixer->rc_cfg;
195 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
198 code = mixer->rc_buffer[rc->offset];
200 code |= mixer->rc_buffer[rc->offset + 1] << 8;
202 /* the Mute button actually changes the mixer control */
203 if (code == rc->mute_code)
204 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
205 mixer->rc_code = code;
207 wake_up(&mixer->rc_waitq);
210 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
211 long count, loff_t *offset)
213 struct usb_mixer_interface *mixer = hw->private_data;
217 if (count != 1 && count != 4)
219 err = wait_event_interruptible(mixer->rc_waitq,
220 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
223 err = put_user(rc_code, buf);
225 err = put_user(rc_code, (u32 __user *)buf);
227 return err < 0 ? err : count;
230 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
233 struct usb_mixer_interface *mixer = hw->private_data;
235 poll_wait(file, &mixer->rc_waitq, wait);
236 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
239 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
241 struct snd_hwdep *hwdep;
244 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
245 if (rc_configs[i].usb_id == mixer->chip->usb_id)
247 if (i >= ARRAY_SIZE(rc_configs))
249 mixer->rc_cfg = &rc_configs[i];
251 len = mixer->rc_cfg->packet_length;
253 init_waitqueue_head(&mixer->rc_waitq);
254 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
257 snprintf(hwdep->name, sizeof(hwdep->name),
258 "%s remote control", mixer->chip->card->shortname);
259 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
260 hwdep->private_data = mixer;
261 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
262 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
263 hwdep->exclusive = 1;
265 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
268 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
269 if (!mixer->rc_setup_packet) {
270 usb_free_urb(mixer->rc_urb);
271 mixer->rc_urb = NULL;
274 mixer->rc_setup_packet->bRequestType =
275 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
276 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
277 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
278 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
279 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
280 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
281 usb_rcvctrlpipe(mixer->chip->dev, 0),
282 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
283 snd_usb_soundblaster_remote_complete, mixer);
287 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
289 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
295 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
296 int value, int index)
298 struct snd_usb_audio *chip = mixer->chip;
301 err = snd_usb_lock_shutdown(chip);
305 if (chip->usb_id == USB_ID(0x041e, 0x3042))
306 err = snd_usb_ctl_msg(chip->dev,
307 usb_sndctrlpipe(chip->dev, 0), 0x24,
308 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
310 /* USB X-Fi S51 Pro */
311 if (chip->usb_id == USB_ID(0x041e, 0x30df))
312 err = snd_usb_ctl_msg(chip->dev,
313 usb_sndctrlpipe(chip->dev, 0), 0x24,
314 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
317 err = snd_usb_ctl_msg(chip->dev,
318 usb_sndctrlpipe(chip->dev, 0), 0x24,
319 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
320 value, index + 2, NULL, 0);
321 snd_usb_unlock_shutdown(chip);
325 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
328 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
329 struct usb_mixer_interface *mixer = list->mixer;
330 int index = kcontrol->private_value & 0xff;
331 unsigned int value = ucontrol->value.integer.value[0];
332 int old_value = kcontrol->private_value >> 8;
337 if (value == old_value)
339 kcontrol->private_value = (value << 8) | index;
340 err = snd_audigy2nx_led_update(mixer, value, index);
341 return err < 0 ? err : 1;
344 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
346 int priv_value = list->kctl->private_value;
348 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
352 /* name and private_value are set dynamically */
353 static const struct snd_kcontrol_new snd_audigy2nx_control = {
354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
355 .info = snd_audigy2nx_led_info,
356 .get = snd_audigy2nx_led_get,
357 .put = snd_audigy2nx_led_put,
360 static const char * const snd_audigy2nx_led_names[] = {
363 "Dolby Digital LED Switch",
366 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
370 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
371 struct snd_kcontrol_new knew;
373 /* USB X-Fi S51 doesn't have a CMSS LED */
374 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
376 /* USB X-Fi S51 Pro doesn't have one either */
377 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
379 if (i > 1 && /* Live24ext has 2 LEDs only */
380 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
381 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
382 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
383 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
386 knew = snd_audigy2nx_control;
387 knew.name = snd_audigy2nx_led_names[i];
388 knew.private_value = (1 << 8) | i; /* LED on as default */
389 err = add_single_ctl_with_resume(mixer, 0,
390 snd_audigy2nx_led_resume,
398 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
399 struct snd_info_buffer *buffer)
401 static const struct sb_jack {
404 } jacks_audigy2nx[] = {
410 }, jacks_live24ext[] = {
411 {4, "line in"}, /* &1=Line, &2=Mic*/
412 {3, "hph out"}, /* headphones */
413 {0, "RC "}, /* last command, 6 bytes see rc_config above */
416 const struct sb_jack *jacks;
417 struct usb_mixer_interface *mixer = entry->private_data;
421 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
422 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
423 jacks = jacks_audigy2nx;
424 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
425 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
426 jacks = jacks_live24ext;
430 for (i = 0; jacks[i].name; ++i) {
431 snd_iprintf(buffer, "%s: ", jacks[i].name);
432 err = snd_usb_lock_shutdown(mixer->chip);
435 err = snd_usb_ctl_msg(mixer->chip->dev,
436 usb_rcvctrlpipe(mixer->chip->dev, 0),
437 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
438 USB_RECIP_INTERFACE, 0,
439 jacks[i].unitid << 8, buf, 3);
440 snd_usb_unlock_shutdown(mixer->chip);
441 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
442 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
444 snd_iprintf(buffer, "?\n");
449 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_info *uinfo)
452 static const char * const texts[2] = {"1/2", "3/4"};
454 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
457 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
458 struct snd_ctl_elem_value *ucontrol)
460 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
464 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
467 struct snd_usb_audio *chip = mixer->chip;
469 unsigned char buf[2];
471 err = snd_usb_lock_shutdown(chip);
476 buf[1] = value ? 0x02 : 0x01;
477 err = snd_usb_ctl_msg(chip->dev,
478 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
479 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
480 0x0400, 0x0e00, buf, 2);
481 snd_usb_unlock_shutdown(chip);
485 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
486 struct snd_ctl_elem_value *ucontrol)
488 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
489 struct usb_mixer_interface *mixer = list->mixer;
490 unsigned int value = ucontrol->value.enumerated.item[0];
496 if (value == kcontrol->private_value)
499 kcontrol->private_value = value;
500 err = snd_emu0204_ch_switch_update(mixer, value);
501 return err < 0 ? err : 1;
504 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
506 return snd_emu0204_ch_switch_update(list->mixer,
507 list->kctl->private_value);
510 static struct snd_kcontrol_new snd_emu0204_control = {
511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
512 .name = "Front Jack Channels",
513 .info = snd_emu0204_ch_switch_info,
514 .get = snd_emu0204_ch_switch_get,
515 .put = snd_emu0204_ch_switch_put,
519 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
521 return add_single_ctl_with_resume(mixer, 0,
522 snd_emu0204_ch_switch_resume,
523 &snd_emu0204_control, NULL);
526 /* ASUS Xonar U1 / U3 controls */
528 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
529 struct snd_ctl_elem_value *ucontrol)
531 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
535 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
536 unsigned char status)
538 struct snd_usb_audio *chip = mixer->chip;
541 err = snd_usb_lock_shutdown(chip);
544 err = snd_usb_ctl_msg(chip->dev,
545 usb_sndctrlpipe(chip->dev, 0), 0x08,
546 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
548 snd_usb_unlock_shutdown(chip);
552 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
553 struct snd_ctl_elem_value *ucontrol)
555 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
556 u8 old_status, new_status;
559 old_status = kcontrol->private_value;
560 if (ucontrol->value.integer.value[0])
561 new_status = old_status | 0x02;
563 new_status = old_status & ~0x02;
564 if (new_status == old_status)
567 kcontrol->private_value = new_status;
568 err = snd_xonar_u1_switch_update(list->mixer, new_status);
569 return err < 0 ? err : 1;
572 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
574 return snd_xonar_u1_switch_update(list->mixer,
575 list->kctl->private_value);
578 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
580 .name = "Digital Playback Switch",
581 .info = snd_ctl_boolean_mono_info,
582 .get = snd_xonar_u1_switch_get,
583 .put = snd_xonar_u1_switch_put,
584 .private_value = 0x05,
587 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
589 return add_single_ctl_with_resume(mixer, 0,
590 snd_xonar_u1_switch_resume,
591 &snd_xonar_u1_output_switch, NULL);
594 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
596 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
597 struct snd_ctl_elem_value *ucontrol)
599 ucontrol->value.enumerated.item[0] = kctl->private_value;
603 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
605 struct snd_usb_audio *chip = mixer->chip;
607 unsigned char buff[3];
609 err = snd_usb_lock_shutdown(chip);
613 /* Prepare for magic command to toggle clock source */
614 err = snd_usb_ctl_msg(chip->dev,
615 usb_rcvctrlpipe(chip->dev, 0), 0x81,
618 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
621 err = snd_usb_ctl_msg(chip->dev,
622 usb_rcvctrlpipe(chip->dev, 0), 0x81,
625 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
629 /* 2 possibilities: Internal -> send sample rate
630 * S/PDIF sync -> send zeroes
631 * NB: Sample rate locked to 48kHz on purpose to
632 * prevent user from resetting the sample rate
633 * while S/PDIF sync is enabled and confusing
634 * this configuration.
641 buff[0] = buff[1] = buff[2] = 0x00;
644 /* Send the magic command to toggle the clock source */
645 err = snd_usb_ctl_msg(chip->dev,
646 usb_sndctrlpipe(chip->dev, 0), 0x1,
648 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
651 err = snd_usb_ctl_msg(chip->dev,
652 usb_rcvctrlpipe(chip->dev, 0), 0x81,
655 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
658 err = snd_usb_ctl_msg(chip->dev,
659 usb_rcvctrlpipe(chip->dev, 0), 0x81,
662 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
667 snd_usb_unlock_shutdown(chip);
671 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
672 struct snd_ctl_elem_value *ucontrol)
674 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
675 struct usb_mixer_interface *mixer = list->mixer;
677 bool cur_val, new_val;
679 cur_val = kctl->private_value;
680 new_val = ucontrol->value.enumerated.item[0];
681 if (cur_val == new_val)
684 kctl->private_value = new_val;
685 err = snd_mbox1_switch_update(mixer, new_val);
686 return err < 0 ? err : 1;
689 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
690 struct snd_ctl_elem_info *uinfo)
692 static const char *const texts[2] = {
697 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
700 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
702 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
705 static struct snd_kcontrol_new snd_mbox1_switch = {
706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
707 .name = "Clock Source",
709 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
710 .info = snd_mbox1_switch_info,
711 .get = snd_mbox1_switch_get,
712 .put = snd_mbox1_switch_put,
716 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
718 return add_single_ctl_with_resume(mixer, 0,
719 snd_mbox1_switch_resume,
720 &snd_mbox1_switch, NULL);
723 /* Native Instruments device quirks */
725 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
727 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
728 struct snd_kcontrol *kctl)
730 struct usb_device *dev = mixer->chip->dev;
731 unsigned int pval = kctl->private_value;
735 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
737 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
738 0, pval & 0xffff, &value, 1);
741 "unable to issue vendor read request (ret = %d)", err);
745 kctl->private_value |= ((unsigned int)value << 24);
749 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
752 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
756 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
758 struct snd_usb_audio *chip = list->mixer->chip;
759 unsigned int pval = list->kctl->private_value;
762 err = snd_usb_lock_shutdown(chip);
765 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
767 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
768 pval >> 24, pval & 0xffff, NULL, 0, 1000);
769 snd_usb_unlock_shutdown(chip);
773 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
776 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
777 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
778 u8 newval = ucontrol->value.integer.value[0];
781 if (oldval == newval)
784 kcontrol->private_value &= ~(0xff << 24);
785 kcontrol->private_value |= (unsigned int)newval << 24;
786 err = snd_ni_update_cur_val(list);
787 return err < 0 ? err : 1;
790 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
792 .name = "Direct Thru Channel A",
793 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
796 .name = "Direct Thru Channel B",
797 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
800 .name = "Phono Input Channel A",
801 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
804 .name = "Phono Input Channel B",
805 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
809 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
811 .name = "Direct Thru Channel A",
812 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
815 .name = "Direct Thru Channel B",
816 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
819 .name = "Direct Thru Channel C",
820 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
823 .name = "Direct Thru Channel D",
824 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
827 .name = "Phono Input Channel A",
828 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
831 .name = "Phono Input Channel B",
832 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
835 .name = "Phono Input Channel C",
836 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
839 .name = "Phono Input Channel D",
840 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
844 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
845 const struct snd_kcontrol_new *kc,
849 struct snd_kcontrol_new template = {
850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
851 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
852 .get = snd_nativeinstruments_control_get,
853 .put = snd_nativeinstruments_control_put,
854 .info = snd_ctl_boolean_mono_info,
857 for (i = 0; i < count; i++) {
858 struct usb_mixer_elem_list *list;
860 template.name = kc[i].name;
861 template.private_value = kc[i].private_value;
863 err = add_single_ctl_with_resume(mixer, 0,
864 snd_ni_update_cur_val,
868 snd_ni_control_init_val(mixer, list->kctl);
874 /* M-Audio FastTrack Ultra quirks */
875 /* FTU Effect switch (also used by C400/C600) */
876 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_info *uinfo)
879 static const char *const texts[8] = {
880 "Room 1", "Room 2", "Room 3", "Hall 1",
881 "Hall 2", "Plate", "Delay", "Echo"
884 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
887 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
888 struct snd_kcontrol *kctl)
890 struct usb_device *dev = mixer->chip->dev;
891 unsigned int pval = kctl->private_value;
893 unsigned char value[2];
898 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
899 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
901 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
906 kctl->private_value |= (unsigned int)value[0] << 24;
910 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
911 struct snd_ctl_elem_value *ucontrol)
913 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
917 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
919 struct snd_usb_audio *chip = list->mixer->chip;
920 unsigned int pval = list->kctl->private_value;
921 unsigned char value[2];
924 value[0] = pval >> 24;
927 err = snd_usb_lock_shutdown(chip);
930 err = snd_usb_ctl_msg(chip->dev,
931 usb_sndctrlpipe(chip->dev, 0),
933 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
935 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
937 snd_usb_unlock_shutdown(chip);
941 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
942 struct snd_ctl_elem_value *ucontrol)
944 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
945 unsigned int pval = list->kctl->private_value;
946 int cur_val, err, new_val;
948 cur_val = pval >> 24;
949 new_val = ucontrol->value.enumerated.item[0];
950 if (cur_val == new_val)
953 kctl->private_value &= ~(0xff << 24);
954 kctl->private_value |= new_val << 24;
955 err = snd_ftu_eff_switch_update(list);
956 return err < 0 ? err : 1;
959 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
960 int validx, int bUnitID)
962 static struct snd_kcontrol_new template = {
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
964 .name = "Effect Program Switch",
966 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
967 .info = snd_ftu_eff_switch_info,
968 .get = snd_ftu_eff_switch_get,
969 .put = snd_ftu_eff_switch_put
971 struct usb_mixer_elem_list *list;
974 err = add_single_ctl_with_resume(mixer, bUnitID,
975 snd_ftu_eff_switch_update,
979 list->kctl->private_value = (validx << 8) | bUnitID;
980 snd_ftu_eff_switch_init(mixer, list->kctl);
984 /* Create volume controls for FTU devices*/
985 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
988 unsigned int control, cmask;
991 const unsigned int id = 5;
992 const int val_type = USB_MIXER_S16;
994 for (out = 0; out < 8; out++) {
996 for (in = 0; in < 8; in++) {
998 snprintf(name, sizeof(name),
999 "AIn%d - Out%d Capture Volume",
1001 err = snd_create_std_mono_ctl(mixer, id, control,
1002 cmask, val_type, name,
1003 &snd_usb_mixer_vol_tlv);
1007 for (in = 8; in < 16; in++) {
1009 snprintf(name, sizeof(name),
1010 "DIn%d - Out%d Playback Volume",
1012 err = snd_create_std_mono_ctl(mixer, id, control,
1013 cmask, val_type, name,
1014 &snd_usb_mixer_vol_tlv);
1023 /* This control needs a volume quirk, see mixer.c */
1024 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1026 static const char name[] = "Effect Volume";
1027 const unsigned int id = 6;
1028 const int val_type = USB_MIXER_U8;
1029 const unsigned int control = 2;
1030 const unsigned int cmask = 0;
1032 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1033 name, snd_usb_mixer_vol_tlv);
1036 /* This control needs a volume quirk, see mixer.c */
1037 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1039 static const char name[] = "Effect Duration";
1040 const unsigned int id = 6;
1041 const int val_type = USB_MIXER_S16;
1042 const unsigned int control = 3;
1043 const unsigned int cmask = 0;
1045 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1046 name, snd_usb_mixer_vol_tlv);
1049 /* This control needs a volume quirk, see mixer.c */
1050 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1052 static const char name[] = "Effect Feedback Volume";
1053 const unsigned int id = 6;
1054 const int val_type = USB_MIXER_U8;
1055 const unsigned int control = 4;
1056 const unsigned int cmask = 0;
1058 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1062 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1068 const unsigned int id = 7;
1069 const int val_type = USB_MIXER_S16;
1070 const unsigned int control = 7;
1072 for (ch = 0; ch < 4; ++ch) {
1074 snprintf(name, sizeof(name),
1075 "Effect Return %d Volume", ch + 1);
1076 err = snd_create_std_mono_ctl(mixer, id, control,
1077 cmask, val_type, name,
1078 snd_usb_mixer_vol_tlv);
1086 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1092 const unsigned int id = 5;
1093 const int val_type = USB_MIXER_S16;
1094 const unsigned int control = 9;
1096 for (ch = 0; ch < 8; ++ch) {
1098 snprintf(name, sizeof(name),
1099 "Effect Send AIn%d Volume", ch + 1);
1100 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1102 snd_usb_mixer_vol_tlv);
1106 for (ch = 8; ch < 16; ++ch) {
1108 snprintf(name, sizeof(name),
1109 "Effect Send DIn%d Volume", ch - 7);
1110 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1112 snd_usb_mixer_vol_tlv);
1119 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1123 err = snd_ftu_create_volume_ctls(mixer);
1127 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1131 err = snd_ftu_create_effect_volume_ctl(mixer);
1135 err = snd_ftu_create_effect_duration_ctl(mixer);
1139 err = snd_ftu_create_effect_feedback_ctl(mixer);
1143 err = snd_ftu_create_effect_return_ctls(mixer);
1147 err = snd_ftu_create_effect_send_ctls(mixer);
1154 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1155 unsigned char samplerate_id)
1157 struct usb_mixer_interface *mixer;
1158 struct usb_mixer_elem_info *cval;
1159 int unitid = 12; /* SampleRate ExtensionUnit ID */
1161 list_for_each_entry(mixer, &chip->mixer_list, list) {
1162 if (mixer->id_elems[unitid]) {
1163 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1164 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1167 snd_usb_mixer_notify_id(mixer, unitid);
1173 /* M-Audio Fast Track C400/C600 */
1174 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1175 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1178 unsigned int cmask, offset;
1183 const unsigned int id = 0x40;
1184 const int val_type = USB_MIXER_S16;
1185 const int control = 1;
1187 switch (mixer->chip->usb_id) {
1188 case USB_ID(0x0763, 0x2030):
1192 case USB_ID(0x0763, 0x2031):
1198 for (chan = 0; chan < num_outs + num_ins; chan++) {
1199 for (out = 0; out < num_outs; out++) {
1200 if (chan < num_outs) {
1201 snprintf(name, sizeof(name),
1202 "PCM%d-Out%d Playback Volume",
1205 snprintf(name, sizeof(name),
1206 "In%d-Out%d Playback Volume",
1207 chan - num_outs + 1, out + 1);
1210 cmask = (out == 0) ? 0 : 1 << (out - 1);
1211 offset = chan * num_outs;
1212 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1213 cmask, val_type, offset, name,
1214 &snd_usb_mixer_vol_tlv);
1223 /* This control needs a volume quirk, see mixer.c */
1224 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1226 static const char name[] = "Effect Volume";
1227 const unsigned int id = 0x43;
1228 const int val_type = USB_MIXER_U8;
1229 const unsigned int control = 3;
1230 const unsigned int cmask = 0;
1232 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1233 name, snd_usb_mixer_vol_tlv);
1236 /* This control needs a volume quirk, see mixer.c */
1237 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1239 static const char name[] = "Effect Duration";
1240 const unsigned int id = 0x43;
1241 const int val_type = USB_MIXER_S16;
1242 const unsigned int control = 4;
1243 const unsigned int cmask = 0;
1245 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1246 name, snd_usb_mixer_vol_tlv);
1249 /* This control needs a volume quirk, see mixer.c */
1250 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1252 static const char name[] = "Effect Feedback Volume";
1253 const unsigned int id = 0x43;
1254 const int val_type = USB_MIXER_U8;
1255 const unsigned int control = 5;
1256 const unsigned int cmask = 0;
1258 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1262 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1270 const unsigned int id = 0x42;
1271 const int val_type = USB_MIXER_S16;
1272 const int control = 1;
1274 switch (mixer->chip->usb_id) {
1275 case USB_ID(0x0763, 0x2030):
1279 case USB_ID(0x0763, 0x2031):
1285 for (chan = 0; chan < num_outs + num_ins; chan++) {
1286 if (chan < num_outs) {
1287 snprintf(name, sizeof(name),
1288 "Effect Send DOut%d",
1291 snprintf(name, sizeof(name),
1292 "Effect Send AIn%d",
1293 chan - num_outs + 1);
1296 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1297 err = snd_create_std_mono_ctl(mixer, id, control,
1298 cmask, val_type, name,
1299 &snd_usb_mixer_vol_tlv);
1307 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1315 const unsigned int id = 0x40;
1316 const int val_type = USB_MIXER_S16;
1317 const int control = 1;
1319 switch (mixer->chip->usb_id) {
1320 case USB_ID(0x0763, 0x2030):
1323 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1325 case USB_ID(0x0763, 0x2031):
1328 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1332 for (chan = 0; chan < num_outs; chan++) {
1333 snprintf(name, sizeof(name),
1337 cmask = (chan == 0) ? 0 :
1338 1 << (chan + (chan % 2) * num_outs - 1);
1339 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1340 cmask, val_type, offset, name,
1341 &snd_usb_mixer_vol_tlv);
1349 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1353 err = snd_c400_create_vol_ctls(mixer);
1357 err = snd_c400_create_effect_vol_ctls(mixer);
1361 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1365 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1369 err = snd_c400_create_effect_volume_ctl(mixer);
1373 err = snd_c400_create_effect_duration_ctl(mixer);
1377 err = snd_c400_create_effect_feedback_ctl(mixer);
1385 * The mixer units for Ebox-44 are corrupt, and even where they
1386 * are valid they presents mono controls as L and R channels of
1387 * stereo. So we provide a good mixer here.
1389 static struct std_mono_table ebox44_table[] = {
1394 .val_type = USB_MIXER_INV_BOOLEAN,
1395 .name = "Headphone Playback Switch"
1401 .val_type = USB_MIXER_S16,
1402 .name = "Headphone A Mix Playback Volume"
1408 .val_type = USB_MIXER_S16,
1409 .name = "Headphone B Mix Playback Volume"
1416 .val_type = USB_MIXER_INV_BOOLEAN,
1417 .name = "Output Playback Switch"
1423 .val_type = USB_MIXER_S16,
1424 .name = "Output A Playback Volume"
1430 .val_type = USB_MIXER_S16,
1431 .name = "Output B Playback Volume"
1438 .val_type = USB_MIXER_INV_BOOLEAN,
1439 .name = "Input Capture Switch"
1445 .val_type = USB_MIXER_S16,
1446 .name = "Input A Capture Volume"
1452 .val_type = USB_MIXER_S16,
1453 .name = "Input B Capture Volume"
1459 /* Audio Advantage Micro II findings:
1461 * Mapping spdif AES bits to vendor register.bit:
1462 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1463 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1464 * AES2: [0 0 0 0 0 0 0 0]
1465 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1466 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1470 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1471 * just after it to 0xa0, presumably it disables/mutes some analog
1472 * parts when there is no audio.)
1475 * Optical transmitter on/off:
1476 * vendor register.bit: 9.1
1477 * 0 - on (0x28 register value)
1478 * 1 - off (0x2a register value)
1481 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1482 struct snd_ctl_elem_info *uinfo)
1484 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1489 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1492 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1493 struct snd_usb_audio *chip = list->mixer->chip;
1495 struct usb_interface *iface;
1496 struct usb_host_interface *alts;
1498 unsigned char data[3];
1501 err = snd_usb_lock_shutdown(chip);
1505 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1506 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1507 ucontrol->value.iec958.status[2] = 0x00;
1509 /* use known values for that card: interface#1 altsetting#1 */
1510 iface = usb_ifnum_to_if(chip->dev, 1);
1511 if (!iface || iface->num_altsetting < 2)
1513 alts = &iface->altsetting[1];
1514 if (get_iface_desc(alts)->bNumEndpoints < 1)
1516 ep = get_endpoint(alts, 0)->bEndpointAddress;
1518 err = snd_usb_ctl_msg(chip->dev,
1519 usb_rcvctrlpipe(chip->dev, 0),
1521 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1522 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1529 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1530 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1531 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1535 snd_usb_unlock_shutdown(chip);
1539 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1541 struct snd_usb_audio *chip = list->mixer->chip;
1542 unsigned int pval = list->kctl->private_value;
1546 err = snd_usb_lock_shutdown(chip);
1550 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1551 err = snd_usb_ctl_msg(chip->dev,
1552 usb_sndctrlpipe(chip->dev, 0),
1554 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1562 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1563 reg |= (pval >> 12) & 0x0f;
1564 err = snd_usb_ctl_msg(chip->dev,
1565 usb_sndctrlpipe(chip->dev, 0),
1567 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1576 snd_usb_unlock_shutdown(chip);
1580 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1581 struct snd_ctl_elem_value *ucontrol)
1583 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1584 unsigned int pval, pval_old;
1587 pval = pval_old = kcontrol->private_value;
1589 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1590 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1593 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1595 /* The frequency bits in AES3 cannot be set via register access. */
1597 /* Silently ignore any bits from the request that cannot be set. */
1599 if (pval == pval_old)
1602 kcontrol->private_value = pval;
1603 err = snd_microii_spdif_default_update(list);
1604 return err < 0 ? err : 1;
1607 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_value *ucontrol)
1610 ucontrol->value.iec958.status[0] = 0x0f;
1611 ucontrol->value.iec958.status[1] = 0xff;
1612 ucontrol->value.iec958.status[2] = 0x00;
1613 ucontrol->value.iec958.status[3] = 0x00;
1618 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_value *ucontrol)
1621 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1626 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1628 struct snd_usb_audio *chip = list->mixer->chip;
1629 u8 reg = list->kctl->private_value;
1632 err = snd_usb_lock_shutdown(chip);
1636 err = snd_usb_ctl_msg(chip->dev,
1637 usb_sndctrlpipe(chip->dev, 0),
1639 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1645 snd_usb_unlock_shutdown(chip);
1649 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1650 struct snd_ctl_elem_value *ucontrol)
1652 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1656 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1657 if (reg != list->kctl->private_value)
1660 kcontrol->private_value = reg;
1661 err = snd_microii_spdif_switch_update(list);
1662 return err < 0 ? err : 1;
1665 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1667 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1668 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1669 .info = snd_microii_spdif_info,
1670 .get = snd_microii_spdif_default_get,
1671 .put = snd_microii_spdif_default_put,
1672 .private_value = 0x00000100UL,/* reset value */
1675 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1676 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1677 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1678 .info = snd_microii_spdif_info,
1679 .get = snd_microii_spdif_mask_get,
1682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1683 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1684 .info = snd_ctl_boolean_mono_info,
1685 .get = snd_microii_spdif_switch_get,
1686 .put = snd_microii_spdif_switch_put,
1687 .private_value = 0x00000028UL,/* reset value */
1691 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1694 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1695 snd_microii_spdif_default_update,
1697 snd_microii_spdif_switch_update
1700 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1701 err = add_single_ctl_with_resume(mixer, 0,
1703 &snd_microii_mixer_spdif[i],
1712 /* Creative Sound Blaster E1 */
1714 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1715 struct snd_ctl_elem_value *ucontrol)
1717 ucontrol->value.integer.value[0] = kcontrol->private_value;
1721 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1722 unsigned char state)
1724 struct snd_usb_audio *chip = mixer->chip;
1726 unsigned char buff[2];
1729 buff[1] = state ? 0x02 : 0x00;
1731 err = snd_usb_lock_shutdown(chip);
1734 err = snd_usb_ctl_msg(chip->dev,
1735 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1736 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1737 0x0202, 3, buff, 2);
1738 snd_usb_unlock_shutdown(chip);
1742 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1743 struct snd_ctl_elem_value *ucontrol)
1745 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1746 unsigned char value = !!ucontrol->value.integer.value[0];
1749 if (kcontrol->private_value == value)
1751 kcontrol->private_value = value;
1752 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1753 return err < 0 ? err : 1;
1756 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1758 return snd_soundblaster_e1_switch_update(list->mixer,
1759 list->kctl->private_value);
1762 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_info *uinfo)
1765 static const char *const texts[2] = {
1769 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1772 static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1773 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1774 .name = "Input Source",
1775 .info = snd_soundblaster_e1_switch_info,
1776 .get = snd_soundblaster_e1_switch_get,
1777 .put = snd_soundblaster_e1_switch_put,
1781 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1783 return add_single_ctl_with_resume(mixer, 0,
1784 snd_soundblaster_e1_switch_resume,
1785 &snd_soundblaster_e1_input_switch,
1789 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1793 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1794 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1795 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1799 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1801 /* fix to 0dB playback volumes */
1802 dell_dock_init_vol(mixer->chip, 1, 16);
1803 dell_dock_init_vol(mixer->chip, 2, 16);
1804 dell_dock_init_vol(mixer->chip, 1, 19);
1805 dell_dock_init_vol(mixer->chip, 2, 19);
1809 /* RME Class Compliant device quirks */
1811 #define SND_RME_GET_STATUS1 23
1812 #define SND_RME_GET_CURRENT_FREQ 17
1813 #define SND_RME_CLK_SYSTEM_SHIFT 16
1814 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1815 #define SND_RME_CLK_AES_SHIFT 8
1816 #define SND_RME_CLK_SPDIF_SHIFT 12
1817 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1818 #define SND_RME_CLK_SYNC_SHIFT 6
1819 #define SND_RME_CLK_SYNC_MASK 0x3
1820 #define SND_RME_CLK_FREQMUL_SHIFT 18
1821 #define SND_RME_CLK_FREQMUL_MASK 0x7
1822 #define SND_RME_CLK_SYSTEM(x) \
1823 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1824 #define SND_RME_CLK_AES(x) \
1825 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1826 #define SND_RME_CLK_SPDIF(x) \
1827 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1828 #define SND_RME_CLK_SYNC(x) \
1829 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1830 #define SND_RME_CLK_FREQMUL(x) \
1831 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1832 #define SND_RME_CLK_AES_LOCK 0x1
1833 #define SND_RME_CLK_AES_SYNC 0x4
1834 #define SND_RME_CLK_SPDIF_LOCK 0x2
1835 #define SND_RME_CLK_SPDIF_SYNC 0x8
1836 #define SND_RME_SPDIF_IF_SHIFT 4
1837 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1838 #define SND_RME_BINARY_MASK 0x1
1839 #define SND_RME_SPDIF_IF(x) \
1840 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1841 #define SND_RME_SPDIF_FORMAT(x) \
1842 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1844 static const u32 snd_rme_rate_table[] = {
1845 32000, 44100, 48000, 50000,
1846 64000, 88200, 96000, 100000,
1847 128000, 176400, 192000, 200000,
1848 256000, 352800, 384000, 400000,
1849 512000, 705600, 768000, 800000
1851 /* maximum number of items for AES and S/PDIF rates for above table */
1852 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1854 enum snd_rme_domain {
1855 SND_RME_DOMAIN_SYSTEM,
1857 SND_RME_DOMAIN_SPDIF
1860 enum snd_rme_clock_status {
1861 SND_RME_CLOCK_NOLOCK,
1866 static int snd_rme_read_value(struct snd_usb_audio *chip,
1870 struct usb_device *dev = chip->dev;
1873 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1875 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1877 value, sizeof(*value));
1880 "unable to issue vendor read request %d (ret = %d)",
1885 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1888 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1889 struct snd_usb_audio *chip = list->mixer->chip;
1892 err = snd_usb_lock_shutdown(chip);
1895 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1896 snd_usb_unlock_shutdown(chip);
1900 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1901 struct snd_ctl_elem_value *ucontrol)
1908 err = snd_rme_get_status1(kcontrol, &status1);
1911 switch (kcontrol->private_value) {
1912 case SND_RME_DOMAIN_SYSTEM:
1913 idx = SND_RME_CLK_SYSTEM(status1);
1914 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1915 rate = snd_rme_rate_table[idx];
1917 case SND_RME_DOMAIN_AES:
1918 idx = SND_RME_CLK_AES(status1);
1919 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1920 rate = snd_rme_rate_table[idx];
1922 case SND_RME_DOMAIN_SPDIF:
1923 idx = SND_RME_CLK_SPDIF(status1);
1924 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1925 rate = snd_rme_rate_table[idx];
1930 ucontrol->value.integer.value[0] = rate;
1934 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1935 struct snd_ctl_elem_value *ucontrol)
1938 int idx = SND_RME_CLOCK_NOLOCK;
1941 err = snd_rme_get_status1(kcontrol, &status1);
1944 switch (kcontrol->private_value) {
1945 case SND_RME_DOMAIN_AES: /* AES */
1946 if (status1 & SND_RME_CLK_AES_SYNC)
1947 idx = SND_RME_CLOCK_SYNC;
1948 else if (status1 & SND_RME_CLK_AES_LOCK)
1949 idx = SND_RME_CLOCK_LOCK;
1951 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
1952 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1953 idx = SND_RME_CLOCK_SYNC;
1954 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1955 idx = SND_RME_CLOCK_LOCK;
1960 ucontrol->value.enumerated.item[0] = idx;
1964 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1965 struct snd_ctl_elem_value *ucontrol)
1970 err = snd_rme_get_status1(kcontrol, &status1);
1973 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1977 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1978 struct snd_ctl_elem_value *ucontrol)
1983 err = snd_rme_get_status1(kcontrol, &status1);
1986 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1990 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1991 struct snd_ctl_elem_value *ucontrol)
1996 err = snd_rme_get_status1(kcontrol, &status1);
1999 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2003 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2004 struct snd_ctl_elem_value *ucontrol)
2006 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2007 struct snd_usb_audio *chip = list->mixer->chip;
2009 const u64 num = 104857600000000ULL;
2014 err = snd_usb_lock_shutdown(chip);
2017 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2020 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2023 freq = (den == 0) ? 0 : div64_u64(num, den);
2024 freq <<= SND_RME_CLK_FREQMUL(status1);
2025 ucontrol->value.integer.value[0] = freq;
2028 snd_usb_unlock_shutdown(chip);
2032 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2033 struct snd_ctl_elem_info *uinfo)
2035 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2037 switch (kcontrol->private_value) {
2038 case SND_RME_DOMAIN_SYSTEM:
2039 uinfo->value.integer.min = 32000;
2040 uinfo->value.integer.max = 800000;
2042 case SND_RME_DOMAIN_AES:
2043 case SND_RME_DOMAIN_SPDIF:
2045 uinfo->value.integer.min = 0;
2046 uinfo->value.integer.max = 200000;
2048 uinfo->value.integer.step = 0;
2052 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2053 struct snd_ctl_elem_info *uinfo)
2055 static const char *const sync_states[] = {
2056 "No Lock", "Lock", "Sync"
2059 return snd_ctl_enum_info(uinfo, 1,
2060 ARRAY_SIZE(sync_states), sync_states);
2063 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2064 struct snd_ctl_elem_info *uinfo)
2066 static const char *const spdif_if[] = {
2067 "Coaxial", "Optical"
2070 return snd_ctl_enum_info(uinfo, 1,
2071 ARRAY_SIZE(spdif_if), spdif_if);
2074 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2075 struct snd_ctl_elem_info *uinfo)
2077 static const char *const optical_type[] = {
2078 "Consumer", "Professional"
2081 return snd_ctl_enum_info(uinfo, 1,
2082 ARRAY_SIZE(optical_type), optical_type);
2085 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2086 struct snd_ctl_elem_info *uinfo)
2088 static const char *const sync_sources[] = {
2089 "Internal", "AES", "SPDIF", "Internal"
2092 return snd_ctl_enum_info(uinfo, 1,
2093 ARRAY_SIZE(sync_sources), sync_sources);
2096 static struct snd_kcontrol_new snd_rme_controls[] = {
2098 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2100 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2101 .info = snd_rme_rate_info,
2102 .get = snd_rme_rate_get,
2103 .private_value = SND_RME_DOMAIN_AES
2106 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2108 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2109 .info = snd_rme_sync_state_info,
2110 .get = snd_rme_sync_state_get,
2111 .private_value = SND_RME_DOMAIN_AES
2114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2115 .name = "SPDIF Rate",
2116 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2117 .info = snd_rme_rate_info,
2118 .get = snd_rme_rate_get,
2119 .private_value = SND_RME_DOMAIN_SPDIF
2122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2123 .name = "SPDIF Sync",
2124 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2125 .info = snd_rme_sync_state_info,
2126 .get = snd_rme_sync_state_get,
2127 .private_value = SND_RME_DOMAIN_SPDIF
2130 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2131 .name = "SPDIF Interface",
2132 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2133 .info = snd_rme_spdif_if_info,
2134 .get = snd_rme_spdif_if_get,
2137 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2138 .name = "SPDIF Format",
2139 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2140 .info = snd_rme_spdif_format_info,
2141 .get = snd_rme_spdif_format_get,
2144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2145 .name = "Sync Source",
2146 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2147 .info = snd_rme_sync_source_info,
2148 .get = snd_rme_sync_source_get
2151 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2152 .name = "System Rate",
2153 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2154 .info = snd_rme_rate_info,
2155 .get = snd_rme_rate_get,
2156 .private_value = SND_RME_DOMAIN_SYSTEM
2159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2160 .name = "Current Frequency",
2161 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2162 .info = snd_rme_rate_info,
2163 .get = snd_rme_current_freq_get
2167 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2171 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2172 err = add_single_ctl_with_resume(mixer, 0,
2174 &snd_rme_controls[i],
2183 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2187 err = snd_usb_soundblaster_remote_init(mixer);
2191 switch (mixer->chip->usb_id) {
2192 /* Tascam US-16x08 */
2193 case USB_ID(0x0644, 0x8047):
2194 err = snd_us16x08_controls_create(mixer);
2196 case USB_ID(0x041e, 0x3020):
2197 case USB_ID(0x041e, 0x3040):
2198 case USB_ID(0x041e, 0x3042):
2199 case USB_ID(0x041e, 0x30df):
2200 case USB_ID(0x041e, 0x3048):
2201 err = snd_audigy2nx_controls_create(mixer);
2204 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2205 mixer, snd_audigy2nx_proc_read);
2209 case USB_ID(0x041e, 0x3f19):
2210 err = snd_emu0204_controls_create(mixer);
2213 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2214 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2215 err = snd_c400_create_mixer(mixer);
2218 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2219 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2220 err = snd_ftu_create_mixer(mixer);
2223 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2224 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2225 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2226 err = snd_xonar_u1_controls_create(mixer);
2229 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2230 err = snd_microii_controls_create(mixer);
2233 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2234 err = snd_mbox1_create_sync_switch(mixer);
2237 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2238 err = snd_nativeinstruments_create_mixer(mixer,
2239 snd_nativeinstruments_ta6_mixers,
2240 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2243 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2244 err = snd_nativeinstruments_create_mixer(mixer,
2245 snd_nativeinstruments_ta10_mixers,
2246 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2249 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2250 /* detection is disabled in mixer_maps.c */
2251 err = snd_create_std_mono_table(mixer, ebox44_table);
2254 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2255 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2256 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2257 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2258 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2259 err = snd_scarlett_controls_create(mixer);
2262 case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
2263 case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
2264 case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
2265 err = snd_scarlett_gen2_controls_create(mixer);
2268 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2269 err = snd_soundblaster_e1_switch_create(mixer);
2271 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2272 err = dell_dock_mixer_init(mixer);
2275 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2276 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2277 case USB_ID(0x2a39, 0x3fd4): /* RME */
2278 err = snd_rme_controls_create(mixer);
2286 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2288 switch (mixer->chip->usb_id) {
2289 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2290 dell_dock_mixer_init(mixer);
2296 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2301 /* unit ids specific to Extigy/Audigy 2 NX: */
2303 case 0: /* remote control */
2304 mixer->rc_urb->dev = mixer->chip->dev;
2305 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2307 case 4: /* digital in jack */
2308 case 7: /* line in jacks */
2309 case 19: /* speaker out jacks */
2310 case 20: /* headphones out jack */
2312 /* live24ext: 4 = line-in jack */
2313 case 3: /* hp-out jack (may actuate Mute) */
2314 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2315 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2316 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2319 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2324 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2325 struct usb_mixer_elem_info *cval,
2326 struct snd_kcontrol *kctl)
2328 /* Approximation using 10 ranges based on output measurement on hw v1.2.
2329 * This seems close to the cubic mapping e.g. alsamixer uses. */
2330 static const DECLARE_TLV_DB_RANGE(scale,
2331 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2332 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2333 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2334 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2335 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2336 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2337 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2338 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2339 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2340 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2343 if (cval->min == 0 && cval->max == 50) {
2344 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2345 kctl->tlv.p = scale;
2346 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2347 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2349 } else if (cval->min == 0 && cval->max <= 1000) {
2350 /* Some other clearly broken DragonFly variant.
2351 * At least a 0..53 variant (hw v1.0) exists.
2353 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2354 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2358 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2359 struct usb_mixer_elem_info *cval, int unitid,
2360 struct snd_kcontrol *kctl)
2362 switch (mixer->chip->usb_id) {
2363 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2364 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2365 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2367 /* lowest playback value is muted on C-Media devices */
2368 case USB_ID(0x0d8c, 0x000c):
2369 case USB_ID(0x0d8c, 0x0014):
2370 if (strstr(kctl->id.name, "Playback"))