2 * USB Audio Driver for ALSA
4 * Quirks and vendor-specific extensions for mixer interfaces
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
12 * Audio Advantage Micro II support added by:
13 * Przemek Rudy (prudy1@o2.pl)
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/hid.h>
31 #include <linux/init.h>
32 #include <linux/math64.h>
33 #include <linux/slab.h>
34 #include <linux/usb.h>
35 #include <linux/usb/audio.h>
37 #include <sound/asoundef.h>
38 #include <sound/core.h>
39 #include <sound/control.h>
40 #include <sound/hwdep.h>
41 #include <sound/info.h>
42 #include <sound/tlv.h>
46 #include "mixer_quirks.h"
47 #include "mixer_scarlett.h"
48 #include "mixer_us16x08.h"
51 struct std_mono_table {
52 unsigned int unitid, control, cmask;
55 snd_kcontrol_tlv_rw_t *tlv_callback;
58 /* This function allows for the creation of standard UAC controls.
59 * See the quirks for M-Audio FTUs or Ebox-44.
60 * If you don't want to set a TLV callback pass NULL.
62 * Since there doesn't seem to be a devices that needs a multichannel
63 * version, we keep it mono for simplicity.
65 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
72 snd_kcontrol_tlv_rw_t *tlv_callback)
74 struct usb_mixer_elem_info *cval;
75 struct snd_kcontrol *kctl;
77 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
81 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
82 cval->val_type = val_type;
84 cval->control = control;
86 cval->idx_off = idx_off;
88 /* get_min_max() is called only for integer volumes later,
89 * so provide a short-cut for booleans */
97 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
104 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
105 kctl->private_free = snd_usb_mixer_elem_free;
109 kctl->tlv.c = tlv_callback;
110 kctl->vd[0].access |=
111 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
112 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
114 /* Add control to mixer */
115 return snd_usb_mixer_add_control(&cval->head, kctl);
118 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
120 unsigned int control,
124 snd_kcontrol_tlv_rw_t *tlv_callback)
126 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
127 val_type, 0 /* Offset */, name, tlv_callback);
131 * Create a set of standard UAC controls from a table
133 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
134 struct std_mono_table *t)
138 while (t->name != NULL) {
139 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
140 t->cmask, t->val_type, t->name, t->tlv_callback);
149 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
151 usb_mixer_elem_resume_func_t resume,
152 const struct snd_kcontrol_new *knew,
153 struct usb_mixer_elem_list **listp)
155 struct usb_mixer_elem_list *list;
156 struct snd_kcontrol *kctl;
158 list = kzalloc(sizeof(*list), GFP_KERNEL);
165 list->resume = resume;
166 kctl = snd_ctl_new1(knew, list);
171 kctl->private_free = snd_usb_mixer_elem_free;
172 return snd_usb_mixer_add_control(list, kctl);
176 * Sound Blaster remote control configuration
178 * format of remote control data:
180 * Audigy 2 NX: 06 80 xx 00 00 00
181 * Live! 24-bit: 06 80 xx yy 22 83
183 static const struct rc_config {
188 u8 min_packet_length; /* minimum accepted length of the URB result */
192 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
193 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
194 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
195 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
196 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
197 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
198 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
201 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
203 struct usb_mixer_interface *mixer = urb->context;
204 const struct rc_config *rc = mixer->rc_cfg;
207 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
210 code = mixer->rc_buffer[rc->offset];
212 code |= mixer->rc_buffer[rc->offset + 1] << 8;
214 /* the Mute button actually changes the mixer control */
215 if (code == rc->mute_code)
216 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
217 mixer->rc_code = code;
219 wake_up(&mixer->rc_waitq);
222 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
223 long count, loff_t *offset)
225 struct usb_mixer_interface *mixer = hw->private_data;
229 if (count != 1 && count != 4)
231 err = wait_event_interruptible(mixer->rc_waitq,
232 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
235 err = put_user(rc_code, buf);
237 err = put_user(rc_code, (u32 __user *)buf);
239 return err < 0 ? err : count;
242 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
245 struct usb_mixer_interface *mixer = hw->private_data;
247 poll_wait(file, &mixer->rc_waitq, wait);
248 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
251 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
253 struct snd_hwdep *hwdep;
256 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
257 if (rc_configs[i].usb_id == mixer->chip->usb_id)
259 if (i >= ARRAY_SIZE(rc_configs))
261 mixer->rc_cfg = &rc_configs[i];
263 len = mixer->rc_cfg->packet_length;
265 init_waitqueue_head(&mixer->rc_waitq);
266 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
269 snprintf(hwdep->name, sizeof(hwdep->name),
270 "%s remote control", mixer->chip->card->shortname);
271 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
272 hwdep->private_data = mixer;
273 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
274 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
275 hwdep->exclusive = 1;
277 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
280 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
281 if (!mixer->rc_setup_packet) {
282 usb_free_urb(mixer->rc_urb);
283 mixer->rc_urb = NULL;
286 mixer->rc_setup_packet->bRequestType =
287 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
288 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
289 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
290 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
291 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
292 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
293 usb_rcvctrlpipe(mixer->chip->dev, 0),
294 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
295 snd_usb_soundblaster_remote_complete, mixer);
299 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
301 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
303 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
307 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
308 int value, int index)
310 struct snd_usb_audio *chip = mixer->chip;
313 err = snd_usb_lock_shutdown(chip);
317 if (chip->usb_id == USB_ID(0x041e, 0x3042))
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,
322 /* USB X-Fi S51 Pro */
323 if (chip->usb_id == USB_ID(0x041e, 0x30df))
324 err = snd_usb_ctl_msg(chip->dev,
325 usb_sndctrlpipe(chip->dev, 0), 0x24,
326 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
329 err = snd_usb_ctl_msg(chip->dev,
330 usb_sndctrlpipe(chip->dev, 0), 0x24,
331 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
332 value, index + 2, NULL, 0);
333 snd_usb_unlock_shutdown(chip);
337 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
340 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
341 struct usb_mixer_interface *mixer = list->mixer;
342 int index = kcontrol->private_value & 0xff;
343 unsigned int value = ucontrol->value.integer.value[0];
344 int old_value = kcontrol->private_value >> 8;
349 if (value == old_value)
351 kcontrol->private_value = (value << 8) | index;
352 err = snd_audigy2nx_led_update(mixer, value, index);
353 return err < 0 ? err : 1;
356 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
358 int priv_value = list->kctl->private_value;
360 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
364 /* name and private_value are set dynamically */
365 static const struct snd_kcontrol_new snd_audigy2nx_control = {
366 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
367 .info = snd_audigy2nx_led_info,
368 .get = snd_audigy2nx_led_get,
369 .put = snd_audigy2nx_led_put,
372 static const char * const snd_audigy2nx_led_names[] = {
375 "Dolby Digital LED Switch",
378 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
382 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
383 struct snd_kcontrol_new knew;
385 /* USB X-Fi S51 doesn't have a CMSS LED */
386 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
388 /* USB X-Fi S51 Pro doesn't have one either */
389 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
391 if (i > 1 && /* Live24ext has 2 LEDs only */
392 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
393 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
394 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
395 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
398 knew = snd_audigy2nx_control;
399 knew.name = snd_audigy2nx_led_names[i];
400 knew.private_value = (1 << 8) | i; /* LED on as default */
401 err = add_single_ctl_with_resume(mixer, 0,
402 snd_audigy2nx_led_resume,
410 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
411 struct snd_info_buffer *buffer)
413 static const struct sb_jack {
416 } jacks_audigy2nx[] = {
422 }, jacks_live24ext[] = {
423 {4, "line in"}, /* &1=Line, &2=Mic*/
424 {3, "hph out"}, /* headphones */
425 {0, "RC "}, /* last command, 6 bytes see rc_config above */
428 const struct sb_jack *jacks;
429 struct usb_mixer_interface *mixer = entry->private_data;
433 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
434 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
435 jacks = jacks_audigy2nx;
436 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
437 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
438 jacks = jacks_live24ext;
442 for (i = 0; jacks[i].name; ++i) {
443 snd_iprintf(buffer, "%s: ", jacks[i].name);
444 err = snd_usb_lock_shutdown(mixer->chip);
447 err = snd_usb_ctl_msg(mixer->chip->dev,
448 usb_rcvctrlpipe(mixer->chip->dev, 0),
449 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
450 USB_RECIP_INTERFACE, 0,
451 jacks[i].unitid << 8, buf, 3);
452 snd_usb_unlock_shutdown(mixer->chip);
453 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
454 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
456 snd_iprintf(buffer, "?\n");
461 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_info *uinfo)
464 static const char * const texts[2] = {"1/2", "3/4"};
466 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
469 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
470 struct snd_ctl_elem_value *ucontrol)
472 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
476 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
479 struct snd_usb_audio *chip = mixer->chip;
481 unsigned char buf[2];
483 err = snd_usb_lock_shutdown(chip);
488 buf[1] = value ? 0x02 : 0x01;
489 err = snd_usb_ctl_msg(chip->dev,
490 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
491 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
492 0x0400, 0x0e00, buf, 2);
493 snd_usb_unlock_shutdown(chip);
497 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
500 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
501 struct usb_mixer_interface *mixer = list->mixer;
502 unsigned int value = ucontrol->value.enumerated.item[0];
508 if (value == kcontrol->private_value)
511 kcontrol->private_value = value;
512 err = snd_emu0204_ch_switch_update(mixer, value);
513 return err < 0 ? err : 1;
516 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
518 return snd_emu0204_ch_switch_update(list->mixer,
519 list->kctl->private_value);
522 static struct snd_kcontrol_new snd_emu0204_control = {
523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524 .name = "Front Jack Channels",
525 .info = snd_emu0204_ch_switch_info,
526 .get = snd_emu0204_ch_switch_get,
527 .put = snd_emu0204_ch_switch_put,
531 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
533 return add_single_ctl_with_resume(mixer, 0,
534 snd_emu0204_ch_switch_resume,
535 &snd_emu0204_control, NULL);
538 /* ASUS Xonar U1 / U3 controls */
540 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
543 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
547 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
548 unsigned char status)
550 struct snd_usb_audio *chip = mixer->chip;
553 err = snd_usb_lock_shutdown(chip);
556 err = snd_usb_ctl_msg(chip->dev,
557 usb_sndctrlpipe(chip->dev, 0), 0x08,
558 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
560 snd_usb_unlock_shutdown(chip);
564 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
565 struct snd_ctl_elem_value *ucontrol)
567 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
568 u8 old_status, new_status;
571 old_status = kcontrol->private_value;
572 if (ucontrol->value.integer.value[0])
573 new_status = old_status | 0x02;
575 new_status = old_status & ~0x02;
576 if (new_status == old_status)
579 kcontrol->private_value = new_status;
580 err = snd_xonar_u1_switch_update(list->mixer, new_status);
581 return err < 0 ? err : 1;
584 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
586 return snd_xonar_u1_switch_update(list->mixer,
587 list->kctl->private_value);
590 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
592 .name = "Digital Playback Switch",
593 .info = snd_ctl_boolean_mono_info,
594 .get = snd_xonar_u1_switch_get,
595 .put = snd_xonar_u1_switch_put,
596 .private_value = 0x05,
599 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
601 return add_single_ctl_with_resume(mixer, 0,
602 snd_xonar_u1_switch_resume,
603 &snd_xonar_u1_output_switch, NULL);
606 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
608 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
609 struct snd_ctl_elem_value *ucontrol)
611 ucontrol->value.enumerated.item[0] = kctl->private_value;
615 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
617 struct snd_usb_audio *chip = mixer->chip;
619 unsigned char buff[3];
621 err = snd_usb_lock_shutdown(chip);
625 /* Prepare for magic command to toggle clock source */
626 err = snd_usb_ctl_msg(chip->dev,
627 usb_rcvctrlpipe(chip->dev, 0), 0x81,
630 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
633 err = snd_usb_ctl_msg(chip->dev,
634 usb_rcvctrlpipe(chip->dev, 0), 0x81,
637 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
641 /* 2 possibilities: Internal -> send sample rate
642 * S/PDIF sync -> send zeroes
643 * NB: Sample rate locked to 48kHz on purpose to
644 * prevent user from resetting the sample rate
645 * while S/PDIF sync is enabled and confusing
646 * this configuration.
653 buff[0] = buff[1] = buff[2] = 0x00;
656 /* Send the magic command to toggle the clock source */
657 err = snd_usb_ctl_msg(chip->dev,
658 usb_sndctrlpipe(chip->dev, 0), 0x1,
660 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
663 err = snd_usb_ctl_msg(chip->dev,
664 usb_rcvctrlpipe(chip->dev, 0), 0x81,
667 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
670 err = snd_usb_ctl_msg(chip->dev,
671 usb_rcvctrlpipe(chip->dev, 0), 0x81,
674 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
679 snd_usb_unlock_shutdown(chip);
683 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
684 struct snd_ctl_elem_value *ucontrol)
686 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
687 struct usb_mixer_interface *mixer = list->mixer;
689 bool cur_val, new_val;
691 cur_val = kctl->private_value;
692 new_val = ucontrol->value.enumerated.item[0];
693 if (cur_val == new_val)
696 kctl->private_value = new_val;
697 err = snd_mbox1_switch_update(mixer, new_val);
698 return err < 0 ? err : 1;
701 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_info *uinfo)
704 static const char *const texts[2] = {
709 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
712 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
714 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
717 static struct snd_kcontrol_new snd_mbox1_switch = {
718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
719 .name = "Clock Source",
721 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
722 .info = snd_mbox1_switch_info,
723 .get = snd_mbox1_switch_get,
724 .put = snd_mbox1_switch_put,
728 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
730 return add_single_ctl_with_resume(mixer, 0,
731 snd_mbox1_switch_resume,
732 &snd_mbox1_switch, NULL);
735 /* Native Instruments device quirks */
737 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
739 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
740 struct snd_kcontrol *kctl)
742 struct usb_device *dev = mixer->chip->dev;
743 unsigned int pval = kctl->private_value;
747 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
749 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
750 0, pval & 0xffff, &value, 1);
753 "unable to issue vendor read request (ret = %d)", err);
757 kctl->private_value |= (value << 24);
761 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
762 struct snd_ctl_elem_value *ucontrol)
764 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
768 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
770 struct snd_usb_audio *chip = list->mixer->chip;
771 unsigned int pval = list->kctl->private_value;
774 err = snd_usb_lock_shutdown(chip);
777 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
779 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
780 pval >> 24, pval & 0xffff, NULL, 0, 1000);
781 snd_usb_unlock_shutdown(chip);
785 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
786 struct snd_ctl_elem_value *ucontrol)
788 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
789 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
790 u8 newval = ucontrol->value.integer.value[0];
793 if (oldval == newval)
796 kcontrol->private_value &= ~(0xff << 24);
797 kcontrol->private_value |= (unsigned int)newval << 24;
798 err = snd_ni_update_cur_val(list);
799 return err < 0 ? err : 1;
802 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
804 .name = "Direct Thru Channel A",
805 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
808 .name = "Direct Thru Channel B",
809 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
812 .name = "Phono Input Channel A",
813 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
816 .name = "Phono Input Channel B",
817 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
821 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
823 .name = "Direct Thru Channel A",
824 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
827 .name = "Direct Thru Channel B",
828 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
831 .name = "Direct Thru Channel C",
832 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
835 .name = "Direct Thru Channel D",
836 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
839 .name = "Phono Input Channel A",
840 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
843 .name = "Phono Input Channel B",
844 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
847 .name = "Phono Input Channel C",
848 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
851 .name = "Phono Input Channel D",
852 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
856 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
857 const struct snd_kcontrol_new *kc,
861 struct snd_kcontrol_new template = {
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
864 .get = snd_nativeinstruments_control_get,
865 .put = snd_nativeinstruments_control_put,
866 .info = snd_ctl_boolean_mono_info,
869 for (i = 0; i < count; i++) {
870 struct usb_mixer_elem_list *list;
872 template.name = kc[i].name;
873 template.private_value = kc[i].private_value;
875 err = add_single_ctl_with_resume(mixer, 0,
876 snd_ni_update_cur_val,
880 snd_ni_control_init_val(mixer, list->kctl);
886 /* M-Audio FastTrack Ultra quirks */
887 /* FTU Effect switch (also used by C400/C600) */
888 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
889 struct snd_ctl_elem_info *uinfo)
891 static const char *const texts[8] = {
892 "Room 1", "Room 2", "Room 3", "Hall 1",
893 "Hall 2", "Plate", "Delay", "Echo"
896 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
899 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
900 struct snd_kcontrol *kctl)
902 struct usb_device *dev = mixer->chip->dev;
903 unsigned int pval = kctl->private_value;
905 unsigned char value[2];
910 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
911 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
913 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
918 kctl->private_value |= value[0] << 24;
922 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
923 struct snd_ctl_elem_value *ucontrol)
925 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
929 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
931 struct snd_usb_audio *chip = list->mixer->chip;
932 unsigned int pval = list->kctl->private_value;
933 unsigned char value[2];
936 value[0] = pval >> 24;
939 err = snd_usb_lock_shutdown(chip);
942 err = snd_usb_ctl_msg(chip->dev,
943 usb_sndctrlpipe(chip->dev, 0),
945 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
947 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
949 snd_usb_unlock_shutdown(chip);
953 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
954 struct snd_ctl_elem_value *ucontrol)
956 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
957 unsigned int pval = list->kctl->private_value;
958 int cur_val, err, new_val;
960 cur_val = pval >> 24;
961 new_val = ucontrol->value.enumerated.item[0];
962 if (cur_val == new_val)
965 kctl->private_value &= ~(0xff << 24);
966 kctl->private_value |= new_val << 24;
967 err = snd_ftu_eff_switch_update(list);
968 return err < 0 ? err : 1;
971 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
972 int validx, int bUnitID)
974 static struct snd_kcontrol_new template = {
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
976 .name = "Effect Program Switch",
978 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
979 .info = snd_ftu_eff_switch_info,
980 .get = snd_ftu_eff_switch_get,
981 .put = snd_ftu_eff_switch_put
983 struct usb_mixer_elem_list *list;
986 err = add_single_ctl_with_resume(mixer, bUnitID,
987 snd_ftu_eff_switch_update,
991 list->kctl->private_value = (validx << 8) | bUnitID;
992 snd_ftu_eff_switch_init(mixer, list->kctl);
996 /* Create volume controls for FTU devices*/
997 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1000 unsigned int control, cmask;
1003 const unsigned int id = 5;
1004 const int val_type = USB_MIXER_S16;
1006 for (out = 0; out < 8; out++) {
1008 for (in = 0; in < 8; in++) {
1010 snprintf(name, sizeof(name),
1011 "AIn%d - Out%d Capture Volume",
1013 err = snd_create_std_mono_ctl(mixer, id, control,
1014 cmask, val_type, name,
1015 &snd_usb_mixer_vol_tlv);
1019 for (in = 8; in < 16; in++) {
1021 snprintf(name, sizeof(name),
1022 "DIn%d - Out%d Playback Volume",
1024 err = snd_create_std_mono_ctl(mixer, id, control,
1025 cmask, val_type, name,
1026 &snd_usb_mixer_vol_tlv);
1035 /* This control needs a volume quirk, see mixer.c */
1036 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1038 static const char name[] = "Effect Volume";
1039 const unsigned int id = 6;
1040 const int val_type = USB_MIXER_U8;
1041 const unsigned int control = 2;
1042 const unsigned int cmask = 0;
1044 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1045 name, snd_usb_mixer_vol_tlv);
1048 /* This control needs a volume quirk, see mixer.c */
1049 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1051 static const char name[] = "Effect Duration";
1052 const unsigned int id = 6;
1053 const int val_type = USB_MIXER_S16;
1054 const unsigned int control = 3;
1055 const unsigned int cmask = 0;
1057 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1058 name, snd_usb_mixer_vol_tlv);
1061 /* This control needs a volume quirk, see mixer.c */
1062 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1064 static const char name[] = "Effect Feedback Volume";
1065 const unsigned int id = 6;
1066 const int val_type = USB_MIXER_U8;
1067 const unsigned int control = 4;
1068 const unsigned int cmask = 0;
1070 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1074 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1080 const unsigned int id = 7;
1081 const int val_type = USB_MIXER_S16;
1082 const unsigned int control = 7;
1084 for (ch = 0; ch < 4; ++ch) {
1086 snprintf(name, sizeof(name),
1087 "Effect Return %d Volume", ch + 1);
1088 err = snd_create_std_mono_ctl(mixer, id, control,
1089 cmask, val_type, name,
1090 snd_usb_mixer_vol_tlv);
1098 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1104 const unsigned int id = 5;
1105 const int val_type = USB_MIXER_S16;
1106 const unsigned int control = 9;
1108 for (ch = 0; ch < 8; ++ch) {
1110 snprintf(name, sizeof(name),
1111 "Effect Send AIn%d Volume", ch + 1);
1112 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1114 snd_usb_mixer_vol_tlv);
1118 for (ch = 8; ch < 16; ++ch) {
1120 snprintf(name, sizeof(name),
1121 "Effect Send DIn%d Volume", ch - 7);
1122 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1124 snd_usb_mixer_vol_tlv);
1131 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1135 err = snd_ftu_create_volume_ctls(mixer);
1139 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1143 err = snd_ftu_create_effect_volume_ctl(mixer);
1147 err = snd_ftu_create_effect_duration_ctl(mixer);
1151 err = snd_ftu_create_effect_feedback_ctl(mixer);
1155 err = snd_ftu_create_effect_return_ctls(mixer);
1159 err = snd_ftu_create_effect_send_ctls(mixer);
1166 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1167 unsigned char samplerate_id)
1169 struct usb_mixer_interface *mixer;
1170 struct usb_mixer_elem_info *cval;
1171 int unitid = 12; /* SamleRate ExtensionUnit ID */
1173 list_for_each_entry(mixer, &chip->mixer_list, list) {
1174 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1176 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1179 snd_usb_mixer_notify_id(mixer, unitid);
1185 /* M-Audio Fast Track C400/C600 */
1186 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1187 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1190 unsigned int cmask, offset;
1195 const unsigned int id = 0x40;
1196 const int val_type = USB_MIXER_S16;
1197 const int control = 1;
1199 switch (mixer->chip->usb_id) {
1200 case USB_ID(0x0763, 0x2030):
1204 case USB_ID(0x0763, 0x2031):
1210 for (chan = 0; chan < num_outs + num_ins; chan++) {
1211 for (out = 0; out < num_outs; out++) {
1212 if (chan < num_outs) {
1213 snprintf(name, sizeof(name),
1214 "PCM%d-Out%d Playback Volume",
1217 snprintf(name, sizeof(name),
1218 "In%d-Out%d Playback Volume",
1219 chan - num_outs + 1, out + 1);
1222 cmask = (out == 0) ? 0 : 1 << (out - 1);
1223 offset = chan * num_outs;
1224 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1225 cmask, val_type, offset, name,
1226 &snd_usb_mixer_vol_tlv);
1235 /* This control needs a volume quirk, see mixer.c */
1236 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1238 static const char name[] = "Effect Volume";
1239 const unsigned int id = 0x43;
1240 const int val_type = USB_MIXER_U8;
1241 const unsigned int control = 3;
1242 const unsigned int cmask = 0;
1244 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1245 name, snd_usb_mixer_vol_tlv);
1248 /* This control needs a volume quirk, see mixer.c */
1249 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1251 static const char name[] = "Effect Duration";
1252 const unsigned int id = 0x43;
1253 const int val_type = USB_MIXER_S16;
1254 const unsigned int control = 4;
1255 const unsigned int cmask = 0;
1257 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1258 name, snd_usb_mixer_vol_tlv);
1261 /* This control needs a volume quirk, see mixer.c */
1262 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1264 static const char name[] = "Effect Feedback Volume";
1265 const unsigned int id = 0x43;
1266 const int val_type = USB_MIXER_U8;
1267 const unsigned int control = 5;
1268 const unsigned int cmask = 0;
1270 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1274 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1282 const unsigned int id = 0x42;
1283 const int val_type = USB_MIXER_S16;
1284 const int control = 1;
1286 switch (mixer->chip->usb_id) {
1287 case USB_ID(0x0763, 0x2030):
1291 case USB_ID(0x0763, 0x2031):
1297 for (chan = 0; chan < num_outs + num_ins; chan++) {
1298 if (chan < num_outs) {
1299 snprintf(name, sizeof(name),
1300 "Effect Send DOut%d",
1303 snprintf(name, sizeof(name),
1304 "Effect Send AIn%d",
1305 chan - num_outs + 1);
1308 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1309 err = snd_create_std_mono_ctl(mixer, id, control,
1310 cmask, val_type, name,
1311 &snd_usb_mixer_vol_tlv);
1319 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1327 const unsigned int id = 0x40;
1328 const int val_type = USB_MIXER_S16;
1329 const int control = 1;
1331 switch (mixer->chip->usb_id) {
1332 case USB_ID(0x0763, 0x2030):
1335 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1337 case USB_ID(0x0763, 0x2031):
1340 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1344 for (chan = 0; chan < num_outs; chan++) {
1345 snprintf(name, sizeof(name),
1349 cmask = (chan == 0) ? 0 :
1350 1 << (chan + (chan % 2) * num_outs - 1);
1351 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1352 cmask, val_type, offset, name,
1353 &snd_usb_mixer_vol_tlv);
1361 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1365 err = snd_c400_create_vol_ctls(mixer);
1369 err = snd_c400_create_effect_vol_ctls(mixer);
1373 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1377 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1381 err = snd_c400_create_effect_volume_ctl(mixer);
1385 err = snd_c400_create_effect_duration_ctl(mixer);
1389 err = snd_c400_create_effect_feedback_ctl(mixer);
1397 * The mixer units for Ebox-44 are corrupt, and even where they
1398 * are valid they presents mono controls as L and R channels of
1399 * stereo. So we provide a good mixer here.
1401 static struct std_mono_table ebox44_table[] = {
1406 .val_type = USB_MIXER_INV_BOOLEAN,
1407 .name = "Headphone Playback Switch"
1413 .val_type = USB_MIXER_S16,
1414 .name = "Headphone A Mix Playback Volume"
1420 .val_type = USB_MIXER_S16,
1421 .name = "Headphone B Mix Playback Volume"
1428 .val_type = USB_MIXER_INV_BOOLEAN,
1429 .name = "Output Playback Switch"
1435 .val_type = USB_MIXER_S16,
1436 .name = "Output A Playback Volume"
1442 .val_type = USB_MIXER_S16,
1443 .name = "Output B Playback Volume"
1450 .val_type = USB_MIXER_INV_BOOLEAN,
1451 .name = "Input Capture Switch"
1457 .val_type = USB_MIXER_S16,
1458 .name = "Input A Capture Volume"
1464 .val_type = USB_MIXER_S16,
1465 .name = "Input B Capture Volume"
1471 /* Audio Advantage Micro II findings:
1473 * Mapping spdif AES bits to vendor register.bit:
1474 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1475 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1476 * AES2: [0 0 0 0 0 0 0 0]
1477 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1478 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1482 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1483 * just after it to 0xa0, presumably it disables/mutes some analog
1484 * parts when there is no audio.)
1487 * Optical transmitter on/off:
1488 * vendor register.bit: 9.1
1489 * 0 - on (0x28 register value)
1490 * 1 - off (0x2a register value)
1493 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1494 struct snd_ctl_elem_info *uinfo)
1496 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1501 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1502 struct snd_ctl_elem_value *ucontrol)
1504 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1505 struct snd_usb_audio *chip = list->mixer->chip;
1507 struct usb_interface *iface;
1508 struct usb_host_interface *alts;
1510 unsigned char data[3];
1513 err = snd_usb_lock_shutdown(chip);
1517 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1518 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1519 ucontrol->value.iec958.status[2] = 0x00;
1521 /* use known values for that card: interface#1 altsetting#1 */
1522 iface = usb_ifnum_to_if(chip->dev, 1);
1523 if (!iface || iface->num_altsetting < 2)
1525 alts = &iface->altsetting[1];
1526 if (get_iface_desc(alts)->bNumEndpoints < 1)
1528 ep = get_endpoint(alts, 0)->bEndpointAddress;
1530 err = snd_usb_ctl_msg(chip->dev,
1531 usb_rcvctrlpipe(chip->dev, 0),
1533 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1534 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1541 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1542 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1543 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1547 snd_usb_unlock_shutdown(chip);
1551 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1553 struct snd_usb_audio *chip = list->mixer->chip;
1554 unsigned int pval = list->kctl->private_value;
1558 err = snd_usb_lock_shutdown(chip);
1562 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1563 err = snd_usb_ctl_msg(chip->dev,
1564 usb_sndctrlpipe(chip->dev, 0),
1566 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1574 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1575 reg |= (pval >> 12) & 0x0f;
1576 err = snd_usb_ctl_msg(chip->dev,
1577 usb_sndctrlpipe(chip->dev, 0),
1579 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1588 snd_usb_unlock_shutdown(chip);
1592 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1595 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1596 unsigned int pval, pval_old;
1599 pval = pval_old = kcontrol->private_value;
1601 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1602 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1605 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1607 /* The frequency bits in AES3 cannot be set via register access. */
1609 /* Silently ignore any bits from the request that cannot be set. */
1611 if (pval == pval_old)
1614 kcontrol->private_value = pval;
1615 err = snd_microii_spdif_default_update(list);
1616 return err < 0 ? err : 1;
1619 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1622 ucontrol->value.iec958.status[0] = 0x0f;
1623 ucontrol->value.iec958.status[1] = 0xff;
1624 ucontrol->value.iec958.status[2] = 0x00;
1625 ucontrol->value.iec958.status[3] = 0x00;
1630 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1631 struct snd_ctl_elem_value *ucontrol)
1633 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1638 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1640 struct snd_usb_audio *chip = list->mixer->chip;
1641 u8 reg = list->kctl->private_value;
1644 err = snd_usb_lock_shutdown(chip);
1648 err = snd_usb_ctl_msg(chip->dev,
1649 usb_sndctrlpipe(chip->dev, 0),
1651 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1657 snd_usb_unlock_shutdown(chip);
1661 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1662 struct snd_ctl_elem_value *ucontrol)
1664 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1668 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1669 if (reg != list->kctl->private_value)
1672 kcontrol->private_value = reg;
1673 err = snd_microii_spdif_switch_update(list);
1674 return err < 0 ? err : 1;
1677 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1679 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1680 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1681 .info = snd_microii_spdif_info,
1682 .get = snd_microii_spdif_default_get,
1683 .put = snd_microii_spdif_default_put,
1684 .private_value = 0x00000100UL,/* reset value */
1687 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1688 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1689 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1690 .info = snd_microii_spdif_info,
1691 .get = snd_microii_spdif_mask_get,
1694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1695 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1696 .info = snd_ctl_boolean_mono_info,
1697 .get = snd_microii_spdif_switch_get,
1698 .put = snd_microii_spdif_switch_put,
1699 .private_value = 0x00000028UL,/* reset value */
1703 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1706 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1707 snd_microii_spdif_default_update,
1709 snd_microii_spdif_switch_update
1712 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1713 err = add_single_ctl_with_resume(mixer, 0,
1715 &snd_microii_mixer_spdif[i],
1724 /* Creative Sound Blaster E1 */
1726 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1729 ucontrol->value.integer.value[0] = kcontrol->private_value;
1733 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1734 unsigned char state)
1736 struct snd_usb_audio *chip = mixer->chip;
1738 unsigned char buff[2];
1741 buff[1] = state ? 0x02 : 0x00;
1743 err = snd_usb_lock_shutdown(chip);
1746 err = snd_usb_ctl_msg(chip->dev,
1747 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1748 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1749 0x0202, 3, buff, 2);
1750 snd_usb_unlock_shutdown(chip);
1754 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1755 struct snd_ctl_elem_value *ucontrol)
1757 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1758 unsigned char value = !!ucontrol->value.integer.value[0];
1761 if (kcontrol->private_value == value)
1763 kcontrol->private_value = value;
1764 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1765 return err < 0 ? err : 1;
1768 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1770 return snd_soundblaster_e1_switch_update(list->mixer,
1771 list->kctl->private_value);
1774 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_info *uinfo)
1777 static const char *const texts[2] = {
1781 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1784 static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1786 .name = "Input Source",
1787 .info = snd_soundblaster_e1_switch_info,
1788 .get = snd_soundblaster_e1_switch_get,
1789 .put = snd_soundblaster_e1_switch_put,
1793 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1795 return add_single_ctl_with_resume(mixer, 0,
1796 snd_soundblaster_e1_switch_resume,
1797 &snd_soundblaster_e1_input_switch,
1801 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1805 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1806 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1807 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1811 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1813 /* fix to 0dB playback volumes */
1814 dell_dock_init_vol(mixer->chip, 1, 16);
1815 dell_dock_init_vol(mixer->chip, 2, 16);
1816 dell_dock_init_vol(mixer->chip, 1, 19);
1817 dell_dock_init_vol(mixer->chip, 2, 19);
1821 /* RME Class Compliant device quirks */
1823 #define SND_RME_GET_STATUS1 23
1824 #define SND_RME_GET_CURRENT_FREQ 17
1825 #define SND_RME_CLK_SYSTEM_SHIFT 16
1826 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1827 #define SND_RME_CLK_AES_SHIFT 8
1828 #define SND_RME_CLK_SPDIF_SHIFT 12
1829 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1830 #define SND_RME_CLK_SYNC_SHIFT 6
1831 #define SND_RME_CLK_SYNC_MASK 0x3
1832 #define SND_RME_CLK_FREQMUL_SHIFT 18
1833 #define SND_RME_CLK_FREQMUL_MASK 0x7
1834 #define SND_RME_CLK_SYSTEM(x) \
1835 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1836 #define SND_RME_CLK_AES(x) \
1837 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1838 #define SND_RME_CLK_SPDIF(x) \
1839 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1840 #define SND_RME_CLK_SYNC(x) \
1841 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1842 #define SND_RME_CLK_FREQMUL(x) \
1843 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1844 #define SND_RME_CLK_AES_LOCK 0x1
1845 #define SND_RME_CLK_AES_SYNC 0x4
1846 #define SND_RME_CLK_SPDIF_LOCK 0x2
1847 #define SND_RME_CLK_SPDIF_SYNC 0x8
1848 #define SND_RME_SPDIF_IF_SHIFT 4
1849 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1850 #define SND_RME_BINARY_MASK 0x1
1851 #define SND_RME_SPDIF_IF(x) \
1852 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1853 #define SND_RME_SPDIF_FORMAT(x) \
1854 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1856 static const u32 snd_rme_rate_table[] = {
1857 32000, 44100, 48000, 50000,
1858 64000, 88200, 96000, 100000,
1859 128000, 176400, 192000, 200000,
1860 256000, 352800, 384000, 400000,
1861 512000, 705600, 768000, 800000
1863 /* maximum number of items for AES and S/PDIF rates for above table */
1864 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1866 enum snd_rme_domain {
1867 SND_RME_DOMAIN_SYSTEM,
1869 SND_RME_DOMAIN_SPDIF
1872 enum snd_rme_clock_status {
1873 SND_RME_CLOCK_NOLOCK,
1878 static int snd_rme_read_value(struct snd_usb_audio *chip,
1882 struct usb_device *dev = chip->dev;
1885 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1887 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1889 value, sizeof(*value));
1892 "unable to issue vendor read request %d (ret = %d)",
1897 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1900 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1901 struct snd_usb_audio *chip = list->mixer->chip;
1904 err = snd_usb_lock_shutdown(chip);
1907 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1908 snd_usb_unlock_shutdown(chip);
1912 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1913 struct snd_ctl_elem_value *ucontrol)
1920 err = snd_rme_get_status1(kcontrol, &status1);
1923 switch (kcontrol->private_value) {
1924 case SND_RME_DOMAIN_SYSTEM:
1925 idx = SND_RME_CLK_SYSTEM(status1);
1926 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1927 rate = snd_rme_rate_table[idx];
1929 case SND_RME_DOMAIN_AES:
1930 idx = SND_RME_CLK_AES(status1);
1931 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1932 rate = snd_rme_rate_table[idx];
1934 case SND_RME_DOMAIN_SPDIF:
1935 idx = SND_RME_CLK_SPDIF(status1);
1936 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1937 rate = snd_rme_rate_table[idx];
1942 ucontrol->value.integer.value[0] = rate;
1946 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1947 struct snd_ctl_elem_value *ucontrol)
1950 int idx = SND_RME_CLOCK_NOLOCK;
1953 err = snd_rme_get_status1(kcontrol, &status1);
1956 switch (kcontrol->private_value) {
1957 case SND_RME_DOMAIN_AES: /* AES */
1958 if (status1 & SND_RME_CLK_AES_SYNC)
1959 idx = SND_RME_CLOCK_SYNC;
1960 else if (status1 & SND_RME_CLK_AES_LOCK)
1961 idx = SND_RME_CLOCK_LOCK;
1963 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
1964 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1965 idx = SND_RME_CLOCK_SYNC;
1966 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1967 idx = SND_RME_CLOCK_LOCK;
1972 ucontrol->value.enumerated.item[0] = idx;
1976 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1977 struct snd_ctl_elem_value *ucontrol)
1982 err = snd_rme_get_status1(kcontrol, &status1);
1985 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1989 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1990 struct snd_ctl_elem_value *ucontrol)
1995 err = snd_rme_get_status1(kcontrol, &status1);
1998 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
2002 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_value *ucontrol)
2008 err = snd_rme_get_status1(kcontrol, &status1);
2011 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2015 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2016 struct snd_ctl_elem_value *ucontrol)
2018 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2019 struct snd_usb_audio *chip = list->mixer->chip;
2021 const u64 num = 104857600000000ULL;
2026 err = snd_usb_lock_shutdown(chip);
2029 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2032 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2035 freq = (den == 0) ? 0 : div64_u64(num, den);
2036 freq <<= SND_RME_CLK_FREQMUL(status1);
2037 ucontrol->value.integer.value[0] = freq;
2040 snd_usb_unlock_shutdown(chip);
2044 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2045 struct snd_ctl_elem_info *uinfo)
2047 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2049 switch (kcontrol->private_value) {
2050 case SND_RME_DOMAIN_SYSTEM:
2051 uinfo->value.integer.min = 32000;
2052 uinfo->value.integer.max = 800000;
2054 case SND_RME_DOMAIN_AES:
2055 case SND_RME_DOMAIN_SPDIF:
2057 uinfo->value.integer.min = 0;
2058 uinfo->value.integer.max = 200000;
2060 uinfo->value.integer.step = 0;
2064 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2065 struct snd_ctl_elem_info *uinfo)
2067 static const char *const sync_states[] = {
2068 "No Lock", "Lock", "Sync"
2071 return snd_ctl_enum_info(uinfo, 1,
2072 ARRAY_SIZE(sync_states), sync_states);
2075 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2076 struct snd_ctl_elem_info *uinfo)
2078 static const char *const spdif_if[] = {
2079 "Coaxial", "Optical"
2082 return snd_ctl_enum_info(uinfo, 1,
2083 ARRAY_SIZE(spdif_if), spdif_if);
2086 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2087 struct snd_ctl_elem_info *uinfo)
2089 static const char *const optical_type[] = {
2090 "Consumer", "Professional"
2093 return snd_ctl_enum_info(uinfo, 1,
2094 ARRAY_SIZE(optical_type), optical_type);
2097 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2098 struct snd_ctl_elem_info *uinfo)
2100 static const char *const sync_sources[] = {
2101 "Internal", "AES", "SPDIF", "Internal"
2104 return snd_ctl_enum_info(uinfo, 1,
2105 ARRAY_SIZE(sync_sources), sync_sources);
2108 static struct snd_kcontrol_new snd_rme_controls[] = {
2110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2112 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2113 .info = snd_rme_rate_info,
2114 .get = snd_rme_rate_get,
2115 .private_value = SND_RME_DOMAIN_AES
2118 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2120 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2121 .info = snd_rme_sync_state_info,
2122 .get = snd_rme_sync_state_get,
2123 .private_value = SND_RME_DOMAIN_AES
2126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2127 .name = "SPDIF Rate",
2128 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2129 .info = snd_rme_rate_info,
2130 .get = snd_rme_rate_get,
2131 .private_value = SND_RME_DOMAIN_SPDIF
2134 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2135 .name = "SPDIF Sync",
2136 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2137 .info = snd_rme_sync_state_info,
2138 .get = snd_rme_sync_state_get,
2139 .private_value = SND_RME_DOMAIN_SPDIF
2142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2143 .name = "SPDIF Interface",
2144 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2145 .info = snd_rme_spdif_if_info,
2146 .get = snd_rme_spdif_if_get,
2149 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2150 .name = "SPDIF Format",
2151 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2152 .info = snd_rme_spdif_format_info,
2153 .get = snd_rme_spdif_format_get,
2156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2157 .name = "Sync Source",
2158 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2159 .info = snd_rme_sync_source_info,
2160 .get = snd_rme_sync_source_get
2163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2164 .name = "System Rate",
2165 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2166 .info = snd_rme_rate_info,
2167 .get = snd_rme_rate_get,
2168 .private_value = SND_RME_DOMAIN_SYSTEM
2171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2172 .name = "Current Frequency",
2173 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2174 .info = snd_rme_rate_info,
2175 .get = snd_rme_current_freq_get
2179 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2183 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2184 err = add_single_ctl_with_resume(mixer, 0,
2186 &snd_rme_controls[i],
2195 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2199 err = snd_usb_soundblaster_remote_init(mixer);
2203 switch (mixer->chip->usb_id) {
2204 /* Tascam US-16x08 */
2205 case USB_ID(0x0644, 0x8047):
2206 err = snd_us16x08_controls_create(mixer);
2208 case USB_ID(0x041e, 0x3020):
2209 case USB_ID(0x041e, 0x3040):
2210 case USB_ID(0x041e, 0x3042):
2211 case USB_ID(0x041e, 0x30df):
2212 case USB_ID(0x041e, 0x3048):
2213 err = snd_audigy2nx_controls_create(mixer);
2216 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2217 mixer, snd_audigy2nx_proc_read);
2221 case USB_ID(0x041e, 0x3f19):
2222 err = snd_emu0204_controls_create(mixer);
2225 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2226 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2227 err = snd_c400_create_mixer(mixer);
2230 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2231 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2232 err = snd_ftu_create_mixer(mixer);
2235 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2236 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2237 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2238 err = snd_xonar_u1_controls_create(mixer);
2241 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2242 err = snd_microii_controls_create(mixer);
2245 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2246 err = snd_mbox1_create_sync_switch(mixer);
2249 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2250 err = snd_nativeinstruments_create_mixer(mixer,
2251 snd_nativeinstruments_ta6_mixers,
2252 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2255 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2256 err = snd_nativeinstruments_create_mixer(mixer,
2257 snd_nativeinstruments_ta10_mixers,
2258 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2261 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2262 /* detection is disabled in mixer_maps.c */
2263 err = snd_create_std_mono_table(mixer, ebox44_table);
2266 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2267 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2268 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2269 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2270 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2271 err = snd_scarlett_controls_create(mixer);
2274 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2275 err = snd_soundblaster_e1_switch_create(mixer);
2277 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2278 err = dell_dock_mixer_init(mixer);
2281 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2282 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2283 case USB_ID(0x2a39, 0x3fd4): /* RME */
2284 err = snd_rme_controls_create(mixer);
2292 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2294 switch (mixer->chip->usb_id) {
2295 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2296 dell_dock_mixer_init(mixer);
2302 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2307 /* unit ids specific to Extigy/Audigy 2 NX: */
2309 case 0: /* remote control */
2310 mixer->rc_urb->dev = mixer->chip->dev;
2311 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2313 case 4: /* digital in jack */
2314 case 7: /* line in jacks */
2315 case 19: /* speaker out jacks */
2316 case 20: /* headphones out jack */
2318 /* live24ext: 4 = line-in jack */
2319 case 3: /* hp-out jack (may actuate Mute) */
2320 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2321 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2322 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2325 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2330 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2331 struct usb_mixer_elem_info *cval,
2332 struct snd_kcontrol *kctl)
2334 /* Approximation using 10 ranges based on output measurement on hw v1.2.
2335 * This seems close to the cubic mapping e.g. alsamixer uses. */
2336 static const DECLARE_TLV_DB_RANGE(scale,
2337 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2338 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2339 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2340 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2341 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2342 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2343 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2344 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2345 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2346 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2349 if (cval->min == 0 && cval->max == 50) {
2350 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2351 kctl->tlv.p = scale;
2352 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2353 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2355 } else if (cval->min == 0 && cval->max <= 1000) {
2356 /* Some other clearly broken DragonFly variant.
2357 * At least a 0..53 variant (hw v1.0) exists.
2359 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2360 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2364 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2365 struct usb_mixer_elem_info *cval, int unitid,
2366 struct snd_kcontrol *kctl)
2368 switch (mixer->chip->usb_id) {
2369 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2370 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2371 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2373 /* lowest playback value is muted on C-Media devices */
2374 case USB_ID(0x0d8c, 0x000c):
2375 case USB_ID(0x0d8c, 0x0014):
2376 if (strstr(kctl->id.name, "Playback"))