1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * USB Audio Driver for ALSA
5 * Quirks and vendor-specific extensions for mixer interfaces
7 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
9 * Many codes borrowed from audio.c by
10 * Alan Cox (alan@lxorguk.ukuu.org.uk)
11 * Thomas Sailer (sailer@ife.ee.ethz.ch)
13 * Audio Advantage Micro II support added by:
14 * Przemek Rudy (prudy1@o2.pl)
17 #include <linux/hid.h>
18 #include <linux/init.h>
19 #include <linux/math64.h>
20 #include <linux/slab.h>
21 #include <linux/usb.h>
22 #include <linux/usb/audio.h>
24 #include <sound/asoundef.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/hwdep.h>
28 #include <sound/info.h>
29 #include <sound/tlv.h>
33 #include "mixer_quirks.h"
34 #include "mixer_scarlett.h"
35 #include "mixer_scarlett_gen2.h"
36 #include "mixer_us16x08.h"
37 #include "mixer_s1810c.h"
40 struct std_mono_table {
41 unsigned int unitid, control, cmask;
44 snd_kcontrol_tlv_rw_t *tlv_callback;
47 /* This function allows for the creation of standard UAC controls.
48 * See the quirks for M-Audio FTUs or Ebox-44.
49 * If you don't want to set a TLV callback pass NULL.
51 * Since there doesn't seem to be a devices that needs a multichannel
52 * version, we keep it mono for simplicity.
54 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
61 snd_kcontrol_tlv_rw_t *tlv_callback)
63 struct usb_mixer_elem_info *cval;
64 struct snd_kcontrol *kctl;
66 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
70 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
71 cval->val_type = val_type;
73 cval->control = control;
75 cval->idx_off = idx_off;
77 /* get_min_max() is called only for integer volumes later,
78 * so provide a short-cut for booleans */
86 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
93 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
94 kctl->private_free = snd_usb_mixer_elem_free;
98 kctl->tlv.c = tlv_callback;
100 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
101 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
103 /* Add control to mixer */
104 return snd_usb_mixer_add_control(&cval->head, kctl);
107 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
109 unsigned int control,
113 snd_kcontrol_tlv_rw_t *tlv_callback)
115 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
116 val_type, 0 /* Offset */, name, tlv_callback);
120 * Create a set of standard UAC controls from a table
122 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
123 const struct std_mono_table *t)
127 while (t->name != NULL) {
128 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
129 t->cmask, t->val_type, t->name, t->tlv_callback);
138 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
140 usb_mixer_elem_resume_func_t resume,
141 const struct snd_kcontrol_new *knew,
142 struct usb_mixer_elem_list **listp)
144 struct usb_mixer_elem_list *list;
145 struct snd_kcontrol *kctl;
147 list = kzalloc(sizeof(*list), GFP_KERNEL);
154 list->resume = resume;
155 kctl = snd_ctl_new1(knew, list);
160 kctl->private_free = snd_usb_mixer_elem_free;
161 /* don't use snd_usb_mixer_add_control() here, this is a special list element */
162 return snd_usb_mixer_add_list(list, kctl, false);
166 * Sound Blaster remote control configuration
168 * format of remote control data:
170 * Audigy 2 NX: 06 80 xx 00 00 00
171 * Live! 24-bit: 06 80 xx yy 22 83
173 static const struct rc_config {
178 u8 min_packet_length; /* minimum accepted length of the URB result */
182 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
183 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
184 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
185 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
186 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
187 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
188 { USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
189 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
192 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
194 struct usb_mixer_interface *mixer = urb->context;
195 const struct rc_config *rc = mixer->rc_cfg;
198 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
201 code = mixer->rc_buffer[rc->offset];
203 code |= mixer->rc_buffer[rc->offset + 1] << 8;
205 /* the Mute button actually changes the mixer control */
206 if (code == rc->mute_code)
207 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
208 mixer->rc_code = code;
210 wake_up(&mixer->rc_waitq);
213 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
214 long count, loff_t *offset)
216 struct usb_mixer_interface *mixer = hw->private_data;
220 if (count != 1 && count != 4)
222 err = wait_event_interruptible(mixer->rc_waitq,
223 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
226 err = put_user(rc_code, buf);
228 err = put_user(rc_code, (u32 __user *)buf);
230 return err < 0 ? err : count;
233 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
236 struct usb_mixer_interface *mixer = hw->private_data;
238 poll_wait(file, &mixer->rc_waitq, wait);
239 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
242 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
244 struct snd_hwdep *hwdep;
247 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
248 if (rc_configs[i].usb_id == mixer->chip->usb_id)
250 if (i >= ARRAY_SIZE(rc_configs))
252 mixer->rc_cfg = &rc_configs[i];
254 len = mixer->rc_cfg->packet_length;
256 init_waitqueue_head(&mixer->rc_waitq);
257 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
260 snprintf(hwdep->name, sizeof(hwdep->name),
261 "%s remote control", mixer->chip->card->shortname);
262 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
263 hwdep->private_data = mixer;
264 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
265 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
266 hwdep->exclusive = 1;
268 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
271 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
272 if (!mixer->rc_setup_packet) {
273 usb_free_urb(mixer->rc_urb);
274 mixer->rc_urb = NULL;
277 mixer->rc_setup_packet->bRequestType =
278 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
279 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
280 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
281 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
282 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
283 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
284 usb_rcvctrlpipe(mixer->chip->dev, 0),
285 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
286 snd_usb_soundblaster_remote_complete, mixer);
290 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
292 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
294 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
298 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
299 int value, int index)
301 struct snd_usb_audio *chip = mixer->chip;
304 err = snd_usb_lock_shutdown(chip);
308 if (chip->usb_id == USB_ID(0x041e, 0x3042))
309 err = snd_usb_ctl_msg(chip->dev,
310 usb_sndctrlpipe(chip->dev, 0), 0x24,
311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
313 /* USB X-Fi S51 Pro */
314 if (chip->usb_id == USB_ID(0x041e, 0x30df))
315 err = snd_usb_ctl_msg(chip->dev,
316 usb_sndctrlpipe(chip->dev, 0), 0x24,
317 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
320 err = snd_usb_ctl_msg(chip->dev,
321 usb_sndctrlpipe(chip->dev, 0), 0x24,
322 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
323 value, index + 2, NULL, 0);
324 snd_usb_unlock_shutdown(chip);
328 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
331 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
332 struct usb_mixer_interface *mixer = list->mixer;
333 int index = kcontrol->private_value & 0xff;
334 unsigned int value = ucontrol->value.integer.value[0];
335 int old_value = kcontrol->private_value >> 8;
340 if (value == old_value)
342 kcontrol->private_value = (value << 8) | index;
343 err = snd_audigy2nx_led_update(mixer, value, index);
344 return err < 0 ? err : 1;
347 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
349 int priv_value = list->kctl->private_value;
351 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
355 /* name and private_value are set dynamically */
356 static const struct snd_kcontrol_new snd_audigy2nx_control = {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .info = snd_audigy2nx_led_info,
359 .get = snd_audigy2nx_led_get,
360 .put = snd_audigy2nx_led_put,
363 static const char * const snd_audigy2nx_led_names[] = {
366 "Dolby Digital LED Switch",
369 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
373 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
374 struct snd_kcontrol_new knew;
376 /* USB X-Fi S51 doesn't have a CMSS LED */
377 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
379 /* USB X-Fi S51 Pro doesn't have one either */
380 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
382 if (i > 1 && /* Live24ext has 2 LEDs only */
383 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
384 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
385 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
386 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
389 knew = snd_audigy2nx_control;
390 knew.name = snd_audigy2nx_led_names[i];
391 knew.private_value = (1 << 8) | i; /* LED on as default */
392 err = add_single_ctl_with_resume(mixer, 0,
393 snd_audigy2nx_led_resume,
401 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
402 struct snd_info_buffer *buffer)
404 static const struct sb_jack {
407 } jacks_audigy2nx[] = {
413 }, jacks_live24ext[] = {
414 {4, "line in"}, /* &1=Line, &2=Mic*/
415 {3, "hph out"}, /* headphones */
416 {0, "RC "}, /* last command, 6 bytes see rc_config above */
419 const struct sb_jack *jacks;
420 struct usb_mixer_interface *mixer = entry->private_data;
424 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
425 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
426 jacks = jacks_audigy2nx;
427 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
428 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
429 jacks = jacks_live24ext;
433 for (i = 0; jacks[i].name; ++i) {
434 snd_iprintf(buffer, "%s: ", jacks[i].name);
435 err = snd_usb_lock_shutdown(mixer->chip);
438 err = snd_usb_ctl_msg(mixer->chip->dev,
439 usb_rcvctrlpipe(mixer->chip->dev, 0),
440 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
441 USB_RECIP_INTERFACE, 0,
442 jacks[i].unitid << 8, buf, 3);
443 snd_usb_unlock_shutdown(mixer->chip);
444 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
445 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
447 snd_iprintf(buffer, "?\n");
452 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
453 struct snd_ctl_elem_info *uinfo)
455 static const char * const texts[2] = {"1/2", "3/4"};
457 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
460 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
467 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
470 struct snd_usb_audio *chip = mixer->chip;
472 unsigned char buf[2];
474 err = snd_usb_lock_shutdown(chip);
479 buf[1] = value ? 0x02 : 0x01;
480 err = snd_usb_ctl_msg(chip->dev,
481 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
482 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
483 0x0400, 0x0e00, buf, 2);
484 snd_usb_unlock_shutdown(chip);
488 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
489 struct snd_ctl_elem_value *ucontrol)
491 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
492 struct usb_mixer_interface *mixer = list->mixer;
493 unsigned int value = ucontrol->value.enumerated.item[0];
499 if (value == kcontrol->private_value)
502 kcontrol->private_value = value;
503 err = snd_emu0204_ch_switch_update(mixer, value);
504 return err < 0 ? err : 1;
507 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
509 return snd_emu0204_ch_switch_update(list->mixer,
510 list->kctl->private_value);
513 static const struct snd_kcontrol_new snd_emu0204_control = {
514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
515 .name = "Front Jack Channels",
516 .info = snd_emu0204_ch_switch_info,
517 .get = snd_emu0204_ch_switch_get,
518 .put = snd_emu0204_ch_switch_put,
522 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
524 return add_single_ctl_with_resume(mixer, 0,
525 snd_emu0204_ch_switch_resume,
526 &snd_emu0204_control, NULL);
529 /* ASUS Xonar U1 / U3 controls */
531 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
534 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
538 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
539 unsigned char status)
541 struct snd_usb_audio *chip = mixer->chip;
544 err = snd_usb_lock_shutdown(chip);
547 err = snd_usb_ctl_msg(chip->dev,
548 usb_sndctrlpipe(chip->dev, 0), 0x08,
549 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
551 snd_usb_unlock_shutdown(chip);
555 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
556 struct snd_ctl_elem_value *ucontrol)
558 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
559 u8 old_status, new_status;
562 old_status = kcontrol->private_value;
563 if (ucontrol->value.integer.value[0])
564 new_status = old_status | 0x02;
566 new_status = old_status & ~0x02;
567 if (new_status == old_status)
570 kcontrol->private_value = new_status;
571 err = snd_xonar_u1_switch_update(list->mixer, new_status);
572 return err < 0 ? err : 1;
575 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
577 return snd_xonar_u1_switch_update(list->mixer,
578 list->kctl->private_value);
581 static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
583 .name = "Digital Playback Switch",
584 .info = snd_ctl_boolean_mono_info,
585 .get = snd_xonar_u1_switch_get,
586 .put = snd_xonar_u1_switch_put,
587 .private_value = 0x05,
590 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
592 return add_single_ctl_with_resume(mixer, 0,
593 snd_xonar_u1_switch_resume,
594 &snd_xonar_u1_output_switch, NULL);
597 /* Digidesign Mbox 1 helper functions */
599 static int snd_mbox1_is_spdif_synced(struct snd_usb_audio *chip)
601 unsigned char buff[3];
605 /* Read clock source */
606 err = snd_usb_ctl_msg(chip->dev,
607 usb_rcvctrlpipe(chip->dev, 0), 0x81,
610 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
614 /* spdif sync: buff is all zeroes */
615 is_spdif_synced = !(buff[0] | buff[1] | buff[2]);
616 return is_spdif_synced;
619 static int snd_mbox1_set_clk_source(struct snd_usb_audio *chip, int rate_or_zero)
621 /* 2 possibilities: Internal -> expects sample rate
622 * S/PDIF sync -> expects rate = 0
624 unsigned char buff[3];
626 buff[0] = (rate_or_zero >> 0) & 0xff;
627 buff[1] = (rate_or_zero >> 8) & 0xff;
628 buff[2] = (rate_or_zero >> 16) & 0xff;
630 /* Set clock source */
631 return snd_usb_ctl_msg(chip->dev,
632 usb_sndctrlpipe(chip->dev, 0), 0x1,
634 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
637 static int snd_mbox1_is_spdif_input(struct snd_usb_audio *chip)
639 /* Hardware gives 2 possibilities: ANALOG Source -> 0x01
640 * S/PDIF Source -> 0x02
643 unsigned char source[1];
645 /* Read input source */
646 err = snd_usb_ctl_msg(chip->dev,
647 usb_rcvctrlpipe(chip->dev, 0), 0x81,
650 USB_RECIP_INTERFACE, 0x00, 0x500, source, 1);
654 return (source[0] == 2);
657 static int snd_mbox1_set_input_source(struct snd_usb_audio *chip, int is_spdif)
659 /* NB: Setting the input source to S/PDIF resets the clock source to S/PDIF
660 * Hardware expects 2 possibilities: ANALOG Source -> 0x01
661 * S/PDIF Source -> 0x02
663 unsigned char buff[1];
665 buff[0] = (is_spdif & 1) + 1;
667 /* Set input source */
668 return snd_usb_ctl_msg(chip->dev,
669 usb_sndctrlpipe(chip->dev, 0), 0x1,
671 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
674 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
676 static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl,
677 struct snd_ctl_elem_value *ucontrol)
679 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
680 struct snd_usb_audio *chip = list->mixer->chip;
683 err = snd_usb_lock_shutdown(chip);
687 err = snd_mbox1_is_spdif_synced(chip);
691 kctl->private_value = err;
693 ucontrol->value.enumerated.item[0] = kctl->private_value;
695 snd_usb_unlock_shutdown(chip);
699 static int snd_mbox1_clk_switch_update(struct usb_mixer_interface *mixer, int is_spdif_sync)
701 struct snd_usb_audio *chip = mixer->chip;
704 err = snd_usb_lock_shutdown(chip);
708 err = snd_mbox1_is_spdif_input(chip);
712 err = snd_mbox1_is_spdif_synced(chip);
716 /* FIXME: hardcoded sample rate */
717 err = snd_mbox1_set_clk_source(chip, is_spdif_sync ? 0 : 48000);
721 err = snd_mbox1_is_spdif_synced(chip);
723 snd_usb_unlock_shutdown(chip);
727 static int snd_mbox1_clk_switch_put(struct snd_kcontrol *kctl,
728 struct snd_ctl_elem_value *ucontrol)
730 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
731 struct usb_mixer_interface *mixer = list->mixer;
733 bool cur_val, new_val;
735 cur_val = kctl->private_value;
736 new_val = ucontrol->value.enumerated.item[0];
737 if (cur_val == new_val)
740 kctl->private_value = new_val;
741 err = snd_mbox1_clk_switch_update(mixer, new_val);
742 return err < 0 ? err : 1;
745 static int snd_mbox1_clk_switch_info(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_info *uinfo)
748 static const char *const texts[2] = {
753 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
756 static int snd_mbox1_clk_switch_resume(struct usb_mixer_elem_list *list)
758 return snd_mbox1_clk_switch_update(list->mixer, list->kctl->private_value);
761 /* Digidesign Mbox 1 input source switch (analog/spdif) */
763 static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl,
764 struct snd_ctl_elem_value *ucontrol)
766 ucontrol->value.enumerated.item[0] = kctl->private_value;
770 static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int is_spdif_input)
772 struct snd_usb_audio *chip = mixer->chip;
775 err = snd_usb_lock_shutdown(chip);
779 err = snd_mbox1_is_spdif_input(chip);
783 err = snd_mbox1_set_input_source(chip, is_spdif_input);
787 err = snd_mbox1_is_spdif_input(chip);
791 err = snd_mbox1_is_spdif_synced(chip);
793 snd_usb_unlock_shutdown(chip);
797 static int snd_mbox1_src_switch_put(struct snd_kcontrol *kctl,
798 struct snd_ctl_elem_value *ucontrol)
800 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
801 struct usb_mixer_interface *mixer = list->mixer;
803 bool cur_val, new_val;
805 cur_val = kctl->private_value;
806 new_val = ucontrol->value.enumerated.item[0];
807 if (cur_val == new_val)
810 kctl->private_value = new_val;
811 err = snd_mbox1_src_switch_update(mixer, new_val);
812 return err < 0 ? err : 1;
815 static int snd_mbox1_src_switch_info(struct snd_kcontrol *kcontrol,
816 struct snd_ctl_elem_info *uinfo)
818 static const char *const texts[2] = {
823 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
826 static int snd_mbox1_src_switch_resume(struct usb_mixer_elem_list *list)
828 return snd_mbox1_src_switch_update(list->mixer, list->kctl->private_value);
831 static const struct snd_kcontrol_new snd_mbox1_clk_switch = {
832 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
833 .name = "Clock Source",
835 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
836 .info = snd_mbox1_clk_switch_info,
837 .get = snd_mbox1_clk_switch_get,
838 .put = snd_mbox1_clk_switch_put,
842 static const struct snd_kcontrol_new snd_mbox1_src_switch = {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "Input Source",
846 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
847 .info = snd_mbox1_src_switch_info,
848 .get = snd_mbox1_src_switch_get,
849 .put = snd_mbox1_src_switch_put,
853 static int snd_mbox1_controls_create(struct usb_mixer_interface *mixer)
856 err = add_single_ctl_with_resume(mixer, 0,
857 snd_mbox1_clk_switch_resume,
858 &snd_mbox1_clk_switch, NULL);
862 return add_single_ctl_with_resume(mixer, 1,
863 snd_mbox1_src_switch_resume,
864 &snd_mbox1_src_switch, NULL);
867 /* Native Instruments device quirks */
869 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
871 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
872 struct snd_kcontrol *kctl)
874 struct usb_device *dev = mixer->chip->dev;
875 unsigned int pval = kctl->private_value;
879 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
881 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
882 0, pval & 0xffff, &value, 1);
885 "unable to issue vendor read request (ret = %d)", err);
889 kctl->private_value |= ((unsigned int)value << 24);
893 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
894 struct snd_ctl_elem_value *ucontrol)
896 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
900 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
902 struct snd_usb_audio *chip = list->mixer->chip;
903 unsigned int pval = list->kctl->private_value;
906 err = snd_usb_lock_shutdown(chip);
909 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
911 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
912 pval >> 24, pval & 0xffff, NULL, 0, 1000);
913 snd_usb_unlock_shutdown(chip);
917 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
918 struct snd_ctl_elem_value *ucontrol)
920 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
921 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
922 u8 newval = ucontrol->value.integer.value[0];
925 if (oldval == newval)
928 kcontrol->private_value &= ~(0xff << 24);
929 kcontrol->private_value |= (unsigned int)newval << 24;
930 err = snd_ni_update_cur_val(list);
931 return err < 0 ? err : 1;
934 static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
936 .name = "Direct Thru Channel A",
937 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
940 .name = "Direct Thru Channel B",
941 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
944 .name = "Phono Input Channel A",
945 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
948 .name = "Phono Input Channel B",
949 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
953 static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
955 .name = "Direct Thru Channel A",
956 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
959 .name = "Direct Thru Channel B",
960 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
963 .name = "Direct Thru Channel C",
964 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
967 .name = "Direct Thru Channel D",
968 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
971 .name = "Phono Input Channel A",
972 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
975 .name = "Phono Input Channel B",
976 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
979 .name = "Phono Input Channel C",
980 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
983 .name = "Phono Input Channel D",
984 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
988 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
989 const struct snd_kcontrol_new *kc,
993 struct snd_kcontrol_new template = {
994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
995 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
996 .get = snd_nativeinstruments_control_get,
997 .put = snd_nativeinstruments_control_put,
998 .info = snd_ctl_boolean_mono_info,
1001 for (i = 0; i < count; i++) {
1002 struct usb_mixer_elem_list *list;
1004 template.name = kc[i].name;
1005 template.private_value = kc[i].private_value;
1007 err = add_single_ctl_with_resume(mixer, 0,
1008 snd_ni_update_cur_val,
1012 snd_ni_control_init_val(mixer, list->kctl);
1018 /* M-Audio FastTrack Ultra quirks */
1019 /* FTU Effect switch (also used by C400/C600) */
1020 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
1021 struct snd_ctl_elem_info *uinfo)
1023 static const char *const texts[8] = {
1024 "Room 1", "Room 2", "Room 3", "Hall 1",
1025 "Hall 2", "Plate", "Delay", "Echo"
1028 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1031 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
1032 struct snd_kcontrol *kctl)
1034 struct usb_device *dev = mixer->chip->dev;
1035 unsigned int pval = kctl->private_value;
1037 unsigned char value[2];
1042 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
1043 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1045 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
1050 kctl->private_value |= (unsigned int)value[0] << 24;
1054 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
1055 struct snd_ctl_elem_value *ucontrol)
1057 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
1061 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
1063 struct snd_usb_audio *chip = list->mixer->chip;
1064 unsigned int pval = list->kctl->private_value;
1065 unsigned char value[2];
1068 value[0] = pval >> 24;
1071 err = snd_usb_lock_shutdown(chip);
1074 err = snd_usb_ctl_msg(chip->dev,
1075 usb_sndctrlpipe(chip->dev, 0),
1077 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1079 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
1081 snd_usb_unlock_shutdown(chip);
1085 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
1086 struct snd_ctl_elem_value *ucontrol)
1088 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
1089 unsigned int pval = list->kctl->private_value;
1090 int cur_val, err, new_val;
1092 cur_val = pval >> 24;
1093 new_val = ucontrol->value.enumerated.item[0];
1094 if (cur_val == new_val)
1097 kctl->private_value &= ~(0xff << 24);
1098 kctl->private_value |= new_val << 24;
1099 err = snd_ftu_eff_switch_update(list);
1100 return err < 0 ? err : 1;
1103 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
1104 int validx, int bUnitID)
1106 static struct snd_kcontrol_new template = {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108 .name = "Effect Program Switch",
1110 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1111 .info = snd_ftu_eff_switch_info,
1112 .get = snd_ftu_eff_switch_get,
1113 .put = snd_ftu_eff_switch_put
1115 struct usb_mixer_elem_list *list;
1118 err = add_single_ctl_with_resume(mixer, bUnitID,
1119 snd_ftu_eff_switch_update,
1123 list->kctl->private_value = (validx << 8) | bUnitID;
1124 snd_ftu_eff_switch_init(mixer, list->kctl);
1128 /* Create volume controls for FTU devices*/
1129 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1132 unsigned int control, cmask;
1135 const unsigned int id = 5;
1136 const int val_type = USB_MIXER_S16;
1138 for (out = 0; out < 8; out++) {
1140 for (in = 0; in < 8; in++) {
1142 snprintf(name, sizeof(name),
1143 "AIn%d - Out%d Capture Volume",
1145 err = snd_create_std_mono_ctl(mixer, id, control,
1146 cmask, val_type, name,
1147 &snd_usb_mixer_vol_tlv);
1151 for (in = 8; in < 16; in++) {
1153 snprintf(name, sizeof(name),
1154 "DIn%d - Out%d Playback Volume",
1156 err = snd_create_std_mono_ctl(mixer, id, control,
1157 cmask, val_type, name,
1158 &snd_usb_mixer_vol_tlv);
1167 /* This control needs a volume quirk, see mixer.c */
1168 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1170 static const char name[] = "Effect Volume";
1171 const unsigned int id = 6;
1172 const int val_type = USB_MIXER_U8;
1173 const unsigned int control = 2;
1174 const unsigned int cmask = 0;
1176 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1177 name, snd_usb_mixer_vol_tlv);
1180 /* This control needs a volume quirk, see mixer.c */
1181 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1183 static const char name[] = "Effect Duration";
1184 const unsigned int id = 6;
1185 const int val_type = USB_MIXER_S16;
1186 const unsigned int control = 3;
1187 const unsigned int cmask = 0;
1189 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1190 name, snd_usb_mixer_vol_tlv);
1193 /* This control needs a volume quirk, see mixer.c */
1194 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1196 static const char name[] = "Effect Feedback Volume";
1197 const unsigned int id = 6;
1198 const int val_type = USB_MIXER_U8;
1199 const unsigned int control = 4;
1200 const unsigned int cmask = 0;
1202 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1206 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1212 const unsigned int id = 7;
1213 const int val_type = USB_MIXER_S16;
1214 const unsigned int control = 7;
1216 for (ch = 0; ch < 4; ++ch) {
1218 snprintf(name, sizeof(name),
1219 "Effect Return %d Volume", ch + 1);
1220 err = snd_create_std_mono_ctl(mixer, id, control,
1221 cmask, val_type, name,
1222 snd_usb_mixer_vol_tlv);
1230 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1236 const unsigned int id = 5;
1237 const int val_type = USB_MIXER_S16;
1238 const unsigned int control = 9;
1240 for (ch = 0; ch < 8; ++ch) {
1242 snprintf(name, sizeof(name),
1243 "Effect Send AIn%d Volume", ch + 1);
1244 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1246 snd_usb_mixer_vol_tlv);
1250 for (ch = 8; ch < 16; ++ch) {
1252 snprintf(name, sizeof(name),
1253 "Effect Send DIn%d Volume", ch - 7);
1254 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1256 snd_usb_mixer_vol_tlv);
1263 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1267 err = snd_ftu_create_volume_ctls(mixer);
1271 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1275 err = snd_ftu_create_effect_volume_ctl(mixer);
1279 err = snd_ftu_create_effect_duration_ctl(mixer);
1283 err = snd_ftu_create_effect_feedback_ctl(mixer);
1287 err = snd_ftu_create_effect_return_ctls(mixer);
1291 err = snd_ftu_create_effect_send_ctls(mixer);
1298 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1299 unsigned char samplerate_id)
1301 struct usb_mixer_interface *mixer;
1302 struct usb_mixer_elem_info *cval;
1303 int unitid = 12; /* SampleRate ExtensionUnit ID */
1305 list_for_each_entry(mixer, &chip->mixer_list, list) {
1306 if (mixer->id_elems[unitid]) {
1307 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1308 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1311 snd_usb_mixer_notify_id(mixer, unitid);
1317 /* M-Audio Fast Track C400/C600 */
1318 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1319 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1322 unsigned int cmask, offset;
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):
1336 case USB_ID(0x0763, 0x2031):
1342 for (chan = 0; chan < num_outs + num_ins; chan++) {
1343 for (out = 0; out < num_outs; out++) {
1344 if (chan < num_outs) {
1345 snprintf(name, sizeof(name),
1346 "PCM%d-Out%d Playback Volume",
1349 snprintf(name, sizeof(name),
1350 "In%d-Out%d Playback Volume",
1351 chan - num_outs + 1, out + 1);
1354 cmask = (out == 0) ? 0 : 1 << (out - 1);
1355 offset = chan * num_outs;
1356 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1357 cmask, val_type, offset, name,
1358 &snd_usb_mixer_vol_tlv);
1367 /* This control needs a volume quirk, see mixer.c */
1368 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1370 static const char name[] = "Effect Volume";
1371 const unsigned int id = 0x43;
1372 const int val_type = USB_MIXER_U8;
1373 const unsigned int control = 3;
1374 const unsigned int cmask = 0;
1376 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1377 name, snd_usb_mixer_vol_tlv);
1380 /* This control needs a volume quirk, see mixer.c */
1381 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1383 static const char name[] = "Effect Duration";
1384 const unsigned int id = 0x43;
1385 const int val_type = USB_MIXER_S16;
1386 const unsigned int control = 4;
1387 const unsigned int cmask = 0;
1389 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1390 name, snd_usb_mixer_vol_tlv);
1393 /* This control needs a volume quirk, see mixer.c */
1394 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1396 static const char name[] = "Effect Feedback Volume";
1397 const unsigned int id = 0x43;
1398 const int val_type = USB_MIXER_U8;
1399 const unsigned int control = 5;
1400 const unsigned int cmask = 0;
1402 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1406 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1414 const unsigned int id = 0x42;
1415 const int val_type = USB_MIXER_S16;
1416 const int control = 1;
1418 switch (mixer->chip->usb_id) {
1419 case USB_ID(0x0763, 0x2030):
1423 case USB_ID(0x0763, 0x2031):
1429 for (chan = 0; chan < num_outs + num_ins; chan++) {
1430 if (chan < num_outs) {
1431 snprintf(name, sizeof(name),
1432 "Effect Send DOut%d",
1435 snprintf(name, sizeof(name),
1436 "Effect Send AIn%d",
1437 chan - num_outs + 1);
1440 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1441 err = snd_create_std_mono_ctl(mixer, id, control,
1442 cmask, val_type, name,
1443 &snd_usb_mixer_vol_tlv);
1451 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1459 const unsigned int id = 0x40;
1460 const int val_type = USB_MIXER_S16;
1461 const int control = 1;
1463 switch (mixer->chip->usb_id) {
1464 case USB_ID(0x0763, 0x2030):
1467 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1469 case USB_ID(0x0763, 0x2031):
1472 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1476 for (chan = 0; chan < num_outs; chan++) {
1477 snprintf(name, sizeof(name),
1481 cmask = (chan == 0) ? 0 :
1482 1 << (chan + (chan % 2) * num_outs - 1);
1483 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1484 cmask, val_type, offset, name,
1485 &snd_usb_mixer_vol_tlv);
1493 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1497 err = snd_c400_create_vol_ctls(mixer);
1501 err = snd_c400_create_effect_vol_ctls(mixer);
1505 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1509 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1513 err = snd_c400_create_effect_volume_ctl(mixer);
1517 err = snd_c400_create_effect_duration_ctl(mixer);
1521 err = snd_c400_create_effect_feedback_ctl(mixer);
1529 * The mixer units for Ebox-44 are corrupt, and even where they
1530 * are valid they presents mono controls as L and R channels of
1531 * stereo. So we provide a good mixer here.
1533 static const struct std_mono_table ebox44_table[] = {
1538 .val_type = USB_MIXER_INV_BOOLEAN,
1539 .name = "Headphone Playback Switch"
1545 .val_type = USB_MIXER_S16,
1546 .name = "Headphone A Mix Playback Volume"
1552 .val_type = USB_MIXER_S16,
1553 .name = "Headphone B Mix Playback Volume"
1560 .val_type = USB_MIXER_INV_BOOLEAN,
1561 .name = "Output Playback Switch"
1567 .val_type = USB_MIXER_S16,
1568 .name = "Output A Playback Volume"
1574 .val_type = USB_MIXER_S16,
1575 .name = "Output B Playback Volume"
1582 .val_type = USB_MIXER_INV_BOOLEAN,
1583 .name = "Input Capture Switch"
1589 .val_type = USB_MIXER_S16,
1590 .name = "Input A Capture Volume"
1596 .val_type = USB_MIXER_S16,
1597 .name = "Input B Capture Volume"
1603 /* Audio Advantage Micro II findings:
1605 * Mapping spdif AES bits to vendor register.bit:
1606 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1607 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1608 * AES2: [0 0 0 0 0 0 0 0]
1609 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1610 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1614 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1615 * just after it to 0xa0, presumably it disables/mutes some analog
1616 * parts when there is no audio.)
1619 * Optical transmitter on/off:
1620 * vendor register.bit: 9.1
1621 * 0 - on (0x28 register value)
1622 * 1 - off (0x2a register value)
1625 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_info *uinfo)
1628 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1633 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1636 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1637 struct snd_usb_audio *chip = list->mixer->chip;
1639 struct usb_interface *iface;
1640 struct usb_host_interface *alts;
1642 unsigned char data[3];
1645 err = snd_usb_lock_shutdown(chip);
1649 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1650 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1651 ucontrol->value.iec958.status[2] = 0x00;
1653 /* use known values for that card: interface#1 altsetting#1 */
1654 iface = usb_ifnum_to_if(chip->dev, 1);
1655 if (!iface || iface->num_altsetting < 2) {
1659 alts = &iface->altsetting[1];
1660 if (get_iface_desc(alts)->bNumEndpoints < 1) {
1664 ep = get_endpoint(alts, 0)->bEndpointAddress;
1666 err = snd_usb_ctl_msg(chip->dev,
1667 usb_rcvctrlpipe(chip->dev, 0),
1669 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1670 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1677 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1678 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1679 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1683 snd_usb_unlock_shutdown(chip);
1687 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1689 struct snd_usb_audio *chip = list->mixer->chip;
1690 unsigned int pval = list->kctl->private_value;
1694 err = snd_usb_lock_shutdown(chip);
1698 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1699 err = snd_usb_ctl_msg(chip->dev,
1700 usb_sndctrlpipe(chip->dev, 0),
1702 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1710 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1711 reg |= (pval >> 12) & 0x0f;
1712 err = snd_usb_ctl_msg(chip->dev,
1713 usb_sndctrlpipe(chip->dev, 0),
1715 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1724 snd_usb_unlock_shutdown(chip);
1728 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol)
1731 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1732 unsigned int pval, pval_old;
1735 pval = pval_old = kcontrol->private_value;
1737 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1738 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1741 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1743 /* The frequency bits in AES3 cannot be set via register access. */
1745 /* Silently ignore any bits from the request that cannot be set. */
1747 if (pval == pval_old)
1750 kcontrol->private_value = pval;
1751 err = snd_microii_spdif_default_update(list);
1752 return err < 0 ? err : 1;
1755 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1758 ucontrol->value.iec958.status[0] = 0x0f;
1759 ucontrol->value.iec958.status[1] = 0xff;
1760 ucontrol->value.iec958.status[2] = 0x00;
1761 ucontrol->value.iec958.status[3] = 0x00;
1766 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1769 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1774 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1776 struct snd_usb_audio *chip = list->mixer->chip;
1777 u8 reg = list->kctl->private_value;
1780 err = snd_usb_lock_shutdown(chip);
1784 err = snd_usb_ctl_msg(chip->dev,
1785 usb_sndctrlpipe(chip->dev, 0),
1787 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1793 snd_usb_unlock_shutdown(chip);
1797 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1798 struct snd_ctl_elem_value *ucontrol)
1800 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1804 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1805 if (reg != list->kctl->private_value)
1808 kcontrol->private_value = reg;
1809 err = snd_microii_spdif_switch_update(list);
1810 return err < 0 ? err : 1;
1813 static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1815 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1816 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1817 .info = snd_microii_spdif_info,
1818 .get = snd_microii_spdif_default_get,
1819 .put = snd_microii_spdif_default_put,
1820 .private_value = 0x00000100UL,/* reset value */
1823 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1824 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1825 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1826 .info = snd_microii_spdif_info,
1827 .get = snd_microii_spdif_mask_get,
1830 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1831 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1832 .info = snd_ctl_boolean_mono_info,
1833 .get = snd_microii_spdif_switch_get,
1834 .put = snd_microii_spdif_switch_put,
1835 .private_value = 0x00000028UL,/* reset value */
1839 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1842 static const usb_mixer_elem_resume_func_t resume_funcs[] = {
1843 snd_microii_spdif_default_update,
1845 snd_microii_spdif_switch_update
1848 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1849 err = add_single_ctl_with_resume(mixer, 0,
1851 &snd_microii_mixer_spdif[i],
1860 /* Creative Sound Blaster E1 */
1862 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1863 struct snd_ctl_elem_value *ucontrol)
1865 ucontrol->value.integer.value[0] = kcontrol->private_value;
1869 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1870 unsigned char state)
1872 struct snd_usb_audio *chip = mixer->chip;
1874 unsigned char buff[2];
1877 buff[1] = state ? 0x02 : 0x00;
1879 err = snd_usb_lock_shutdown(chip);
1882 err = snd_usb_ctl_msg(chip->dev,
1883 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1884 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1885 0x0202, 3, buff, 2);
1886 snd_usb_unlock_shutdown(chip);
1890 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1891 struct snd_ctl_elem_value *ucontrol)
1893 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1894 unsigned char value = !!ucontrol->value.integer.value[0];
1897 if (kcontrol->private_value == value)
1899 kcontrol->private_value = value;
1900 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1901 return err < 0 ? err : 1;
1904 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1906 return snd_soundblaster_e1_switch_update(list->mixer,
1907 list->kctl->private_value);
1910 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1911 struct snd_ctl_elem_info *uinfo)
1913 static const char *const texts[2] = {
1917 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1920 static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1921 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1922 .name = "Input Source",
1923 .info = snd_soundblaster_e1_switch_info,
1924 .get = snd_soundblaster_e1_switch_get,
1925 .put = snd_soundblaster_e1_switch_put,
1929 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1931 return add_single_ctl_with_resume(mixer, 0,
1932 snd_soundblaster_e1_switch_resume,
1933 &snd_soundblaster_e1_input_switch,
1937 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1941 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1942 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1943 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1947 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1949 /* fix to 0dB playback volumes */
1950 dell_dock_init_vol(mixer->chip, 1, 16);
1951 dell_dock_init_vol(mixer->chip, 2, 16);
1952 dell_dock_init_vol(mixer->chip, 1, 19);
1953 dell_dock_init_vol(mixer->chip, 2, 19);
1957 /* RME Class Compliant device quirks */
1959 #define SND_RME_GET_STATUS1 23
1960 #define SND_RME_GET_CURRENT_FREQ 17
1961 #define SND_RME_CLK_SYSTEM_SHIFT 16
1962 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1963 #define SND_RME_CLK_AES_SHIFT 8
1964 #define SND_RME_CLK_SPDIF_SHIFT 12
1965 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1966 #define SND_RME_CLK_SYNC_SHIFT 6
1967 #define SND_RME_CLK_SYNC_MASK 0x3
1968 #define SND_RME_CLK_FREQMUL_SHIFT 18
1969 #define SND_RME_CLK_FREQMUL_MASK 0x7
1970 #define SND_RME_CLK_SYSTEM(x) \
1971 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1972 #define SND_RME_CLK_AES(x) \
1973 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1974 #define SND_RME_CLK_SPDIF(x) \
1975 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1976 #define SND_RME_CLK_SYNC(x) \
1977 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1978 #define SND_RME_CLK_FREQMUL(x) \
1979 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1980 #define SND_RME_CLK_AES_LOCK 0x1
1981 #define SND_RME_CLK_AES_SYNC 0x4
1982 #define SND_RME_CLK_SPDIF_LOCK 0x2
1983 #define SND_RME_CLK_SPDIF_SYNC 0x8
1984 #define SND_RME_SPDIF_IF_SHIFT 4
1985 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1986 #define SND_RME_BINARY_MASK 0x1
1987 #define SND_RME_SPDIF_IF(x) \
1988 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1989 #define SND_RME_SPDIF_FORMAT(x) \
1990 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1992 static const u32 snd_rme_rate_table[] = {
1993 32000, 44100, 48000, 50000,
1994 64000, 88200, 96000, 100000,
1995 128000, 176400, 192000, 200000,
1996 256000, 352800, 384000, 400000,
1997 512000, 705600, 768000, 800000
1999 /* maximum number of items for AES and S/PDIF rates for above table */
2000 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
2002 enum snd_rme_domain {
2003 SND_RME_DOMAIN_SYSTEM,
2005 SND_RME_DOMAIN_SPDIF
2008 enum snd_rme_clock_status {
2009 SND_RME_CLOCK_NOLOCK,
2014 static int snd_rme_read_value(struct snd_usb_audio *chip,
2018 struct usb_device *dev = chip->dev;
2021 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
2023 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2025 value, sizeof(*value));
2028 "unable to issue vendor read request %d (ret = %d)",
2033 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
2036 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2037 struct snd_usb_audio *chip = list->mixer->chip;
2040 err = snd_usb_lock_shutdown(chip);
2043 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
2044 snd_usb_unlock_shutdown(chip);
2048 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
2049 struct snd_ctl_elem_value *ucontrol)
2056 err = snd_rme_get_status1(kcontrol, &status1);
2059 switch (kcontrol->private_value) {
2060 case SND_RME_DOMAIN_SYSTEM:
2061 idx = SND_RME_CLK_SYSTEM(status1);
2062 if (idx < ARRAY_SIZE(snd_rme_rate_table))
2063 rate = snd_rme_rate_table[idx];
2065 case SND_RME_DOMAIN_AES:
2066 idx = SND_RME_CLK_AES(status1);
2067 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2068 rate = snd_rme_rate_table[idx];
2070 case SND_RME_DOMAIN_SPDIF:
2071 idx = SND_RME_CLK_SPDIF(status1);
2072 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2073 rate = snd_rme_rate_table[idx];
2078 ucontrol->value.integer.value[0] = rate;
2082 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
2083 struct snd_ctl_elem_value *ucontrol)
2086 int idx = SND_RME_CLOCK_NOLOCK;
2089 err = snd_rme_get_status1(kcontrol, &status1);
2092 switch (kcontrol->private_value) {
2093 case SND_RME_DOMAIN_AES: /* AES */
2094 if (status1 & SND_RME_CLK_AES_SYNC)
2095 idx = SND_RME_CLOCK_SYNC;
2096 else if (status1 & SND_RME_CLK_AES_LOCK)
2097 idx = SND_RME_CLOCK_LOCK;
2099 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
2100 if (status1 & SND_RME_CLK_SPDIF_SYNC)
2101 idx = SND_RME_CLOCK_SYNC;
2102 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
2103 idx = SND_RME_CLOCK_LOCK;
2108 ucontrol->value.enumerated.item[0] = idx;
2112 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
2113 struct snd_ctl_elem_value *ucontrol)
2118 err = snd_rme_get_status1(kcontrol, &status1);
2121 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
2125 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
2126 struct snd_ctl_elem_value *ucontrol)
2131 err = snd_rme_get_status1(kcontrol, &status1);
2134 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
2138 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
2139 struct snd_ctl_elem_value *ucontrol)
2144 err = snd_rme_get_status1(kcontrol, &status1);
2147 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2151 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2152 struct snd_ctl_elem_value *ucontrol)
2154 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2155 struct snd_usb_audio *chip = list->mixer->chip;
2157 const u64 num = 104857600000000ULL;
2162 err = snd_usb_lock_shutdown(chip);
2165 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2168 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2171 freq = (den == 0) ? 0 : div64_u64(num, den);
2172 freq <<= SND_RME_CLK_FREQMUL(status1);
2173 ucontrol->value.integer.value[0] = freq;
2176 snd_usb_unlock_shutdown(chip);
2180 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2181 struct snd_ctl_elem_info *uinfo)
2183 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2185 switch (kcontrol->private_value) {
2186 case SND_RME_DOMAIN_SYSTEM:
2187 uinfo->value.integer.min = 32000;
2188 uinfo->value.integer.max = 800000;
2190 case SND_RME_DOMAIN_AES:
2191 case SND_RME_DOMAIN_SPDIF:
2193 uinfo->value.integer.min = 0;
2194 uinfo->value.integer.max = 200000;
2196 uinfo->value.integer.step = 0;
2200 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2201 struct snd_ctl_elem_info *uinfo)
2203 static const char *const sync_states[] = {
2204 "No Lock", "Lock", "Sync"
2207 return snd_ctl_enum_info(uinfo, 1,
2208 ARRAY_SIZE(sync_states), sync_states);
2211 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2212 struct snd_ctl_elem_info *uinfo)
2214 static const char *const spdif_if[] = {
2215 "Coaxial", "Optical"
2218 return snd_ctl_enum_info(uinfo, 1,
2219 ARRAY_SIZE(spdif_if), spdif_if);
2222 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2223 struct snd_ctl_elem_info *uinfo)
2225 static const char *const optical_type[] = {
2226 "Consumer", "Professional"
2229 return snd_ctl_enum_info(uinfo, 1,
2230 ARRAY_SIZE(optical_type), optical_type);
2233 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2234 struct snd_ctl_elem_info *uinfo)
2236 static const char *const sync_sources[] = {
2237 "Internal", "AES", "SPDIF", "Internal"
2240 return snd_ctl_enum_info(uinfo, 1,
2241 ARRAY_SIZE(sync_sources), sync_sources);
2244 static const struct snd_kcontrol_new snd_rme_controls[] = {
2246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2248 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2249 .info = snd_rme_rate_info,
2250 .get = snd_rme_rate_get,
2251 .private_value = SND_RME_DOMAIN_AES
2254 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2256 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2257 .info = snd_rme_sync_state_info,
2258 .get = snd_rme_sync_state_get,
2259 .private_value = SND_RME_DOMAIN_AES
2262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2263 .name = "SPDIF Rate",
2264 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2265 .info = snd_rme_rate_info,
2266 .get = snd_rme_rate_get,
2267 .private_value = SND_RME_DOMAIN_SPDIF
2270 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2271 .name = "SPDIF Sync",
2272 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2273 .info = snd_rme_sync_state_info,
2274 .get = snd_rme_sync_state_get,
2275 .private_value = SND_RME_DOMAIN_SPDIF
2278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2279 .name = "SPDIF Interface",
2280 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2281 .info = snd_rme_spdif_if_info,
2282 .get = snd_rme_spdif_if_get,
2285 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2286 .name = "SPDIF Format",
2287 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2288 .info = snd_rme_spdif_format_info,
2289 .get = snd_rme_spdif_format_get,
2292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2293 .name = "Sync Source",
2294 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2295 .info = snd_rme_sync_source_info,
2296 .get = snd_rme_sync_source_get
2299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2300 .name = "System Rate",
2301 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2302 .info = snd_rme_rate_info,
2303 .get = snd_rme_rate_get,
2304 .private_value = SND_RME_DOMAIN_SYSTEM
2307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2308 .name = "Current Frequency",
2309 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2310 .info = snd_rme_rate_info,
2311 .get = snd_rme_current_freq_get
2315 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2319 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2320 err = add_single_ctl_with_resume(mixer, 0,
2322 &snd_rme_controls[i],
2332 * RME Babyface Pro (FS)
2334 * These devices exposes a couple of DSP functions via request to EP0.
2335 * Switches are available via control registers, while routing is controlled
2336 * by controlling the volume on each possible crossing point.
2337 * Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with
2338 * 0dB being at dec. 32768.
2341 SND_BBFPRO_CTL_REG1 = 0,
2345 #define SND_BBFPRO_CTL_REG_MASK 1
2346 #define SND_BBFPRO_CTL_IDX_MASK 0xff
2347 #define SND_BBFPRO_CTL_IDX_SHIFT 1
2348 #define SND_BBFPRO_CTL_VAL_MASK 1
2349 #define SND_BBFPRO_CTL_VAL_SHIFT 9
2350 #define SND_BBFPRO_CTL_REG1_CLK_MASTER 0
2351 #define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1
2352 #define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7
2353 #define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8
2354 #define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10
2355 #define SND_BBFPRO_CTL_REG2_48V_AN1 0
2356 #define SND_BBFPRO_CTL_REG2_48V_AN2 1
2357 #define SND_BBFPRO_CTL_REG2_SENS_IN3 2
2358 #define SND_BBFPRO_CTL_REG2_SENS_IN4 3
2359 #define SND_BBFPRO_CTL_REG2_PAD_AN1 4
2360 #define SND_BBFPRO_CTL_REG2_PAD_AN2 5
2362 #define SND_BBFPRO_MIXER_IDX_MASK 0x1ff
2363 #define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff
2364 #define SND_BBFPRO_MIXER_VAL_SHIFT 9
2365 #define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf
2366 #define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB
2368 #define SND_BBFPRO_USBREQ_CTL_REG1 0x10
2369 #define SND_BBFPRO_USBREQ_CTL_REG2 0x17
2370 #define SND_BBFPRO_USBREQ_MIXER 0x12
2372 static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
2376 u16 usb_req, usb_idx, usb_val;
2377 struct snd_usb_audio *chip = mixer->chip;
2379 err = snd_usb_lock_shutdown(chip);
2383 if (reg == SND_BBFPRO_CTL_REG1) {
2384 usb_req = SND_BBFPRO_USBREQ_CTL_REG1;
2385 if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2387 usb_val = value ? 3 : 0;
2389 usb_idx = 1 << index;
2390 usb_val = value ? usb_idx : 0;
2393 usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
2394 usb_idx = 1 << index;
2395 usb_val = value ? usb_idx : 0;
2398 err = snd_usb_ctl_msg(chip->dev,
2399 usb_sndctrlpipe(chip->dev, 0), usb_req,
2400 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2401 usb_val, usb_idx, NULL, 0);
2403 snd_usb_unlock_shutdown(chip);
2407 static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol,
2408 struct snd_ctl_elem_value *ucontrol)
2413 pv = kcontrol->private_value;
2414 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2415 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2416 val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT;
2418 if ((reg == SND_BBFPRO_CTL_REG1 &&
2419 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2420 (reg == SND_BBFPRO_CTL_REG2 &&
2421 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2422 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2423 ucontrol->value.enumerated.item[0] = val;
2425 ucontrol->value.integer.value[0] = val;
2430 static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol,
2431 struct snd_ctl_elem_info *uinfo)
2436 pv = kcontrol->private_value;
2437 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2438 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2440 if (reg == SND_BBFPRO_CTL_REG1 &&
2441 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2442 static const char * const texts[2] = {
2446 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2447 } else if (reg == SND_BBFPRO_CTL_REG2 &&
2448 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2449 idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) {
2450 static const char * const texts[2] = {
2454 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2458 uinfo->value.integer.min = 0;
2459 uinfo->value.integer.max = 1;
2460 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2464 static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol,
2465 struct snd_ctl_elem_value *ucontrol)
2469 int old_value, pv, val;
2471 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2472 struct usb_mixer_interface *mixer = list->mixer;
2474 pv = kcontrol->private_value;
2475 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2476 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2477 old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2479 if ((reg == SND_BBFPRO_CTL_REG1 &&
2480 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2481 (reg == SND_BBFPRO_CTL_REG2 &&
2482 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2483 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2484 val = ucontrol->value.enumerated.item[0];
2486 val = ucontrol->value.integer.value[0];
2492 if (val == old_value)
2495 kcontrol->private_value = reg
2496 | ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT)
2497 | ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT);
2499 err = snd_bbfpro_ctl_update(mixer, reg, idx, val);
2500 return err < 0 ? err : 1;
2503 static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list)
2508 pv = list->kctl->private_value;
2509 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2510 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2511 value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2513 return snd_bbfpro_ctl_update(list->mixer, reg, idx, value);
2516 static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index,
2519 struct snd_usb_audio *chip = mixer->chip;
2522 u16 usb_idx, usb_val;
2525 err = snd_usb_lock_shutdown(chip);
2529 idx = index & SND_BBFPRO_MIXER_IDX_MASK;
2530 // 18 bit linear volume, split so 2 bits end up in index.
2531 v = value & SND_BBFPRO_MIXER_VAL_MASK;
2532 usb_idx = idx | (v & 0x3) << 14;
2533 usb_val = (v >> 2) & 0xffff;
2535 err = snd_usb_ctl_msg(chip->dev,
2536 usb_sndctrlpipe(chip->dev, 0),
2537 SND_BBFPRO_USBREQ_MIXER,
2538 USB_DIR_OUT | USB_TYPE_VENDOR |
2540 usb_val, usb_idx, NULL, 0);
2542 snd_usb_unlock_shutdown(chip);
2546 static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2549 ucontrol->value.integer.value[0] =
2550 kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2554 static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2557 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2559 uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN;
2560 uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX;
2564 static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_value *ucontrol)
2569 u32 new_val, old_value, uvalue;
2570 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2571 struct usb_mixer_interface *mixer = list->mixer;
2573 uvalue = ucontrol->value.integer.value[0];
2574 idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK;
2575 old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2577 if (uvalue > SND_BBFPRO_MIXER_VAL_MAX)
2580 if (uvalue == old_value)
2583 new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK;
2585 kcontrol->private_value = idx
2586 | (new_val << SND_BBFPRO_MIXER_VAL_SHIFT);
2588 err = snd_bbfpro_vol_update(mixer, idx, new_val);
2589 return err < 0 ? err : 1;
2592 static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list)
2594 int pv = list->kctl->private_value;
2595 u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK;
2596 u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT)
2597 & SND_BBFPRO_MIXER_VAL_MASK;
2598 return snd_bbfpro_vol_update(list->mixer, idx, val);
2601 // Predfine elements
2602 static const struct snd_kcontrol_new snd_bbfpro_ctl_control = {
2603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2604 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2606 .info = snd_bbfpro_ctl_info,
2607 .get = snd_bbfpro_ctl_get,
2608 .put = snd_bbfpro_ctl_put
2611 static const struct snd_kcontrol_new snd_bbfpro_vol_control = {
2612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2613 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2615 .info = snd_bbfpro_vol_info,
2616 .get = snd_bbfpro_vol_get,
2617 .put = snd_bbfpro_vol_put
2620 static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg,
2621 u8 index, char *name)
2623 struct snd_kcontrol_new knew = snd_bbfpro_ctl_control;
2626 knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK)
2627 | ((index & SND_BBFPRO_CTL_IDX_MASK)
2628 << SND_BBFPRO_CTL_IDX_SHIFT);
2630 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume,
2634 static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index,
2637 struct snd_kcontrol_new knew = snd_bbfpro_vol_control;
2640 knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK;
2642 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume,
2646 static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)
2651 static const char * const input[] = {
2652 "AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3",
2653 "ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2655 static const char * const output[] = {
2656 "AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4",
2657 "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2659 for (o = 0 ; o < 12 ; ++o) {
2660 for (i = 0 ; i < 12 ; ++i) {
2662 snprintf(name, sizeof(name),
2663 "%s-%s-%s Playback Volume",
2664 (i < 2 ? "Mic" : "Line"),
2665 input[i], output[o]);
2666 err = snd_bbfpro_vol_add(mixer, (26 * o + i), name);
2670 // PCM routing... yes, it is output remapping
2671 snprintf(name, sizeof(name),
2672 "PCM-%s-%s Playback Volume",
2673 output[i], output[o]);
2674 err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i),
2682 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2683 SND_BBFPRO_CTL_REG1_CLK_OPTICAL,
2684 "Sample Clock Source");
2688 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2689 SND_BBFPRO_CTL_REG1_SPDIF_PRO,
2694 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2695 SND_BBFPRO_CTL_REG1_SPDIF_EMPH,
2700 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2701 SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL,
2707 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2708 SND_BBFPRO_CTL_REG2_48V_AN1,
2713 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2714 SND_BBFPRO_CTL_REG2_48V_AN2,
2719 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2720 SND_BBFPRO_CTL_REG2_SENS_IN3,
2725 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2726 SND_BBFPRO_CTL_REG2_SENS_IN4,
2731 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2732 SND_BBFPRO_CTL_REG2_PAD_AN1,
2737 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2738 SND_BBFPRO_CTL_REG2_PAD_AN2,
2747 * Pioneer DJ DJM Mixers
2749 * These devices generally have options for soft-switching the playback and
2750 * capture sources in addition to the recording level. Although different
2751 * devices have different configurations, there seems to be canonical values
2752 * for specific capture/playback types: See the definitions of these below.
2754 * The wValue is masked with the stereo channel number. e.g. Setting Ch2 to
2755 * capture phono would be 0x0203. Capture, playback and capture level have
2756 * different wIndexes.
2760 #define SND_DJM_CAP_LINE 0x00
2761 #define SND_DJM_CAP_CDLINE 0x01
2762 #define SND_DJM_CAP_DIGITAL 0x02
2763 #define SND_DJM_CAP_PHONO 0x03
2764 #define SND_DJM_CAP_PFADER 0x06
2765 #define SND_DJM_CAP_XFADERA 0x07
2766 #define SND_DJM_CAP_XFADERB 0x08
2767 #define SND_DJM_CAP_MIC 0x09
2768 #define SND_DJM_CAP_AUX 0x0d
2769 #define SND_DJM_CAP_RECOUT 0x0a
2770 #define SND_DJM_CAP_NONE 0x0f
2771 #define SND_DJM_CAP_CH1PFADER 0x11
2772 #define SND_DJM_CAP_CH2PFADER 0x12
2773 #define SND_DJM_CAP_CH3PFADER 0x13
2774 #define SND_DJM_CAP_CH4PFADER 0x14
2777 #define SND_DJM_PB_CH1 0x00
2778 #define SND_DJM_PB_CH2 0x01
2779 #define SND_DJM_PB_AUX 0x04
2781 #define SND_DJM_WINDEX_CAP 0x8002
2782 #define SND_DJM_WINDEX_CAPLVL 0x8003
2783 #define SND_DJM_WINDEX_PB 0x8016
2785 // kcontrol->private_value layout
2786 #define SND_DJM_VALUE_MASK 0x0000ffff
2787 #define SND_DJM_GROUP_MASK 0x00ff0000
2788 #define SND_DJM_DEVICE_MASK 0xff000000
2789 #define SND_DJM_GROUP_SHIFT 16
2790 #define SND_DJM_DEVICE_SHIFT 24
2792 // device table index
2793 // used for the snd_djm_devices table, so please update accordingly
2794 #define SND_DJM_250MK2_IDX 0x0
2795 #define SND_DJM_750_IDX 0x1
2796 #define SND_DJM_850_IDX 0x2
2797 #define SND_DJM_900NXS2_IDX 0x3
2800 #define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \
2802 .options = snd_djm_opts_##suffix, \
2803 .noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \
2804 .default_value = _default_value, \
2807 #define SND_DJM_DEVICE(suffix) { \
2808 .controls = snd_djm_ctls_##suffix, \
2809 .ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) }
2812 struct snd_djm_device {
2814 const struct snd_djm_ctl *controls;
2818 struct snd_djm_ctl {
2826 static const char *snd_djm_get_label_caplevel(u16 wvalue)
2829 case 0x0000: return "-19dB";
2830 case 0x0100: return "-15dB";
2831 case 0x0200: return "-10dB";
2832 case 0x0300: return "-5dB";
2833 default: return NULL;
2837 static const char *snd_djm_get_label_cap_common(u16 wvalue)
2839 switch (wvalue & 0x00ff) {
2840 case SND_DJM_CAP_LINE: return "Control Tone LINE";
2841 case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE";
2842 case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL";
2843 case SND_DJM_CAP_PHONO: return "Control Tone PHONO";
2844 case SND_DJM_CAP_PFADER: return "Post Fader";
2845 case SND_DJM_CAP_XFADERA: return "Cross Fader A";
2846 case SND_DJM_CAP_XFADERB: return "Cross Fader B";
2847 case SND_DJM_CAP_MIC: return "Mic";
2848 case SND_DJM_CAP_RECOUT: return "Rec Out";
2849 case SND_DJM_CAP_AUX: return "Aux";
2850 case SND_DJM_CAP_NONE: return "None";
2851 case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1";
2852 case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2";
2853 case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3";
2854 case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4";
2855 default: return NULL;
2859 // The DJM-850 has different values for CD/LINE and LINE capture
2860 // control options than the other DJM declared in this file.
2861 static const char *snd_djm_get_label_cap_850(u16 wvalue)
2863 switch (wvalue & 0x00ff) {
2864 case 0x00: return "Control Tone CD/LINE";
2865 case 0x01: return "Control Tone LINE";
2866 default: return snd_djm_get_label_cap_common(wvalue);
2870 static const char *snd_djm_get_label_cap(u8 device_idx, u16 wvalue)
2872 switch (device_idx) {
2873 case SND_DJM_850_IDX: return snd_djm_get_label_cap_850(wvalue);
2874 default: return snd_djm_get_label_cap_common(wvalue);
2878 static const char *snd_djm_get_label_pb(u16 wvalue)
2880 switch (wvalue & 0x00ff) {
2881 case SND_DJM_PB_CH1: return "Ch1";
2882 case SND_DJM_PB_CH2: return "Ch2";
2883 case SND_DJM_PB_AUX: return "Aux";
2884 default: return NULL;
2888 static const char *snd_djm_get_label(u8 device_idx, u16 wvalue, u16 windex)
2891 case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue);
2892 case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(device_idx, wvalue);
2893 case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue);
2894 default: return NULL;
2898 // common DJM capture level option values
2899 static const u16 snd_djm_opts_cap_level[] = {
2900 0x0000, 0x0100, 0x0200, 0x0300 };
2904 static const u16 snd_djm_opts_250mk2_cap1[] = {
2905 0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a };
2907 static const u16 snd_djm_opts_250mk2_cap2[] = {
2908 0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a };
2910 static const u16 snd_djm_opts_250mk2_cap3[] = {
2911 0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d };
2913 static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 };
2914 static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 };
2915 static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 };
2917 static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = {
2918 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2919 SND_DJM_CTL("Ch1 Input", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP),
2920 SND_DJM_CTL("Ch2 Input", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP),
2921 SND_DJM_CTL("Ch3 Input", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP),
2922 SND_DJM_CTL("Ch1 Output", 250mk2_pb1, 0, SND_DJM_WINDEX_PB),
2923 SND_DJM_CTL("Ch2 Output", 250mk2_pb2, 1, SND_DJM_WINDEX_PB),
2924 SND_DJM_CTL("Ch3 Output", 250mk2_pb3, 2, SND_DJM_WINDEX_PB)
2929 static const u16 snd_djm_opts_750_cap1[] = {
2930 0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
2931 static const u16 snd_djm_opts_750_cap2[] = {
2932 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
2933 static const u16 snd_djm_opts_750_cap3[] = {
2934 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
2935 static const u16 snd_djm_opts_750_cap4[] = {
2936 0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
2938 static const struct snd_djm_ctl snd_djm_ctls_750[] = {
2939 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2940 SND_DJM_CTL("Ch1 Input", 750_cap1, 2, SND_DJM_WINDEX_CAP),
2941 SND_DJM_CTL("Ch2 Input", 750_cap2, 2, SND_DJM_WINDEX_CAP),
2942 SND_DJM_CTL("Ch3 Input", 750_cap3, 0, SND_DJM_WINDEX_CAP),
2943 SND_DJM_CTL("Ch4 Input", 750_cap4, 0, SND_DJM_WINDEX_CAP)
2948 static const u16 snd_djm_opts_850_cap1[] = {
2949 0x0100, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
2950 static const u16 snd_djm_opts_850_cap2[] = {
2951 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
2952 static const u16 snd_djm_opts_850_cap3[] = {
2953 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
2954 static const u16 snd_djm_opts_850_cap4[] = {
2955 0x0400, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
2957 static const struct snd_djm_ctl snd_djm_ctls_850[] = {
2958 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2959 SND_DJM_CTL("Ch1 Input", 850_cap1, 1, SND_DJM_WINDEX_CAP),
2960 SND_DJM_CTL("Ch2 Input", 850_cap2, 0, SND_DJM_WINDEX_CAP),
2961 SND_DJM_CTL("Ch3 Input", 850_cap3, 0, SND_DJM_WINDEX_CAP),
2962 SND_DJM_CTL("Ch4 Input", 850_cap4, 1, SND_DJM_WINDEX_CAP)
2967 static const u16 snd_djm_opts_900nxs2_cap1[] = {
2968 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a };
2969 static const u16 snd_djm_opts_900nxs2_cap2[] = {
2970 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a };
2971 static const u16 snd_djm_opts_900nxs2_cap3[] = {
2972 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a };
2973 static const u16 snd_djm_opts_900nxs2_cap4[] = {
2974 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a };
2975 static const u16 snd_djm_opts_900nxs2_cap5[] = {
2976 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 };
2978 static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = {
2979 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2980 SND_DJM_CTL("Ch1 Input", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP),
2981 SND_DJM_CTL("Ch2 Input", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP),
2982 SND_DJM_CTL("Ch3 Input", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP),
2983 SND_DJM_CTL("Ch4 Input", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP),
2984 SND_DJM_CTL("Ch5 Input", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP)
2988 static const struct snd_djm_device snd_djm_devices[] = {
2989 SND_DJM_DEVICE(250mk2),
2990 SND_DJM_DEVICE(750),
2991 SND_DJM_DEVICE(850),
2992 SND_DJM_DEVICE(900nxs2)
2996 static int snd_djm_controls_info(struct snd_kcontrol *kctl,
2997 struct snd_ctl_elem_info *info)
2999 unsigned long private_value = kctl->private_value;
3000 u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3001 u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
3002 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
3004 const struct snd_djm_ctl *ctl;
3007 if (ctl_idx >= device->ncontrols)
3010 ctl = &device->controls[ctl_idx];
3011 noptions = ctl->noptions;
3012 if (info->value.enumerated.item >= noptions)
3013 info->value.enumerated.item = noptions - 1;
3015 name = snd_djm_get_label(device_idx,
3016 ctl->options[info->value.enumerated.item],
3021 strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name));
3022 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3024 info->value.enumerated.items = noptions;
3028 static int snd_djm_controls_update(struct usb_mixer_interface *mixer,
3029 u8 device_idx, u8 group, u16 value)
3032 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
3034 if ((group >= device->ncontrols) || value >= device->controls[group].noptions)
3037 err = snd_usb_lock_shutdown(mixer->chip);
3041 err = snd_usb_ctl_msg(
3042 mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0),
3043 USB_REQ_SET_FEATURE,
3044 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
3045 device->controls[group].options[value],
3046 device->controls[group].wIndex,
3049 snd_usb_unlock_shutdown(mixer->chip);
3053 static int snd_djm_controls_get(struct snd_kcontrol *kctl,
3054 struct snd_ctl_elem_value *elem)
3056 elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK;
3060 static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem)
3062 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
3063 struct usb_mixer_interface *mixer = list->mixer;
3064 unsigned long private_value = kctl->private_value;
3066 u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3067 u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
3068 u16 value = elem->value.enumerated.item[0];
3070 kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) |
3071 (group << SND_DJM_GROUP_SHIFT) |
3074 return snd_djm_controls_update(mixer, device, group, value);
3077 static int snd_djm_controls_resume(struct usb_mixer_elem_list *list)
3079 unsigned long private_value = list->kctl->private_value;
3080 u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3081 u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
3082 u16 value = (private_value & SND_DJM_VALUE_MASK);
3084 return snd_djm_controls_update(list->mixer, device, group, value);
3087 static int snd_djm_controls_create(struct usb_mixer_interface *mixer,
3088 const u8 device_idx)
3093 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
3095 struct snd_kcontrol_new knew = {
3096 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3097 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3099 .info = snd_djm_controls_info,
3100 .get = snd_djm_controls_get,
3101 .put = snd_djm_controls_put
3104 for (i = 0; i < device->ncontrols; i++) {
3105 value = device->controls[i].default_value;
3106 knew.name = device->controls[i].name;
3107 knew.private_value = (
3108 ((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) |
3109 (i << SND_DJM_GROUP_SHIFT) |
3111 err = snd_djm_controls_update(mixer, device_idx, i, value);
3114 err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume,
3122 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
3126 err = snd_usb_soundblaster_remote_init(mixer);
3130 switch (mixer->chip->usb_id) {
3131 /* Tascam US-16x08 */
3132 case USB_ID(0x0644, 0x8047):
3133 err = snd_us16x08_controls_create(mixer);
3135 case USB_ID(0x041e, 0x3020):
3136 case USB_ID(0x041e, 0x3040):
3137 case USB_ID(0x041e, 0x3042):
3138 case USB_ID(0x041e, 0x30df):
3139 case USB_ID(0x041e, 0x3048):
3140 err = snd_audigy2nx_controls_create(mixer);
3143 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
3144 mixer, snd_audigy2nx_proc_read);
3148 case USB_ID(0x041e, 0x3f19):
3149 err = snd_emu0204_controls_create(mixer);
3152 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
3153 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
3154 err = snd_c400_create_mixer(mixer);
3157 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
3158 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
3159 err = snd_ftu_create_mixer(mixer);
3162 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
3163 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
3164 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
3165 err = snd_xonar_u1_controls_create(mixer);
3168 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
3169 err = snd_microii_controls_create(mixer);
3172 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
3173 err = snd_mbox1_controls_create(mixer);
3176 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
3177 err = snd_nativeinstruments_create_mixer(mixer,
3178 snd_nativeinstruments_ta6_mixers,
3179 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
3182 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
3183 err = snd_nativeinstruments_create_mixer(mixer,
3184 snd_nativeinstruments_ta10_mixers,
3185 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
3188 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
3189 /* detection is disabled in mixer_maps.c */
3190 err = snd_create_std_mono_table(mixer, ebox44_table);
3193 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
3194 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
3195 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
3196 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
3197 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
3198 err = snd_scarlett_controls_create(mixer);
3201 case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
3202 case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
3203 case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
3204 case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */
3205 case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */
3206 case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */
3207 case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */
3208 case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */
3209 case USB_ID(0x1235, 0x8215): /* Focusrite Scarlett 18i20 3rd Gen */
3210 err = snd_scarlett_gen2_init(mixer);
3213 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
3214 err = snd_soundblaster_e1_switch_create(mixer);
3216 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
3217 err = dell_dock_mixer_init(mixer);
3220 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
3221 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
3222 case USB_ID(0x2a39, 0x3fd4): /* RME */
3223 err = snd_rme_controls_create(mixer);
3226 case USB_ID(0x0194f, 0x010c): /* Presonus Studio 1810c */
3227 err = snd_sc1810_init_mixer(mixer);
3229 case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */
3230 err = snd_bbfpro_controls_create(mixer);
3232 case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */
3233 err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX);
3235 case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */
3236 err = snd_djm_controls_create(mixer, SND_DJM_750_IDX);
3238 case USB_ID(0x08e4, 0x0163): /* Pioneer DJ DJM-850 */
3239 err = snd_djm_controls_create(mixer, SND_DJM_850_IDX);
3241 case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */
3242 err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX);
3250 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
3252 switch (mixer->chip->usb_id) {
3253 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
3254 dell_dock_mixer_init(mixer);
3260 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
3265 /* unit ids specific to Extigy/Audigy 2 NX: */
3267 case 0: /* remote control */
3268 mixer->rc_urb->dev = mixer->chip->dev;
3269 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
3271 case 4: /* digital in jack */
3272 case 7: /* line in jacks */
3273 case 19: /* speaker out jacks */
3274 case 20: /* headphones out jack */
3276 /* live24ext: 4 = line-in jack */
3277 case 3: /* hp-out jack (may actuate Mute) */
3278 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
3279 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
3280 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
3283 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
3288 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
3289 struct usb_mixer_elem_info *cval,
3290 struct snd_kcontrol *kctl)
3292 /* Approximation using 10 ranges based on output measurement on hw v1.2.
3293 * This seems close to the cubic mapping e.g. alsamixer uses. */
3294 static const DECLARE_TLV_DB_RANGE(scale,
3295 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
3296 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
3297 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
3298 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
3299 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
3300 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
3301 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
3302 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
3303 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
3304 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
3307 if (cval->min == 0 && cval->max == 50) {
3308 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
3309 kctl->tlv.p = scale;
3310 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3311 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
3313 } else if (cval->min == 0 && cval->max <= 1000) {
3314 /* Some other clearly broken DragonFly variant.
3315 * At least a 0..53 variant (hw v1.0) exists.
3317 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
3318 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
3322 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
3323 struct usb_mixer_elem_info *cval, int unitid,
3324 struct snd_kcontrol *kctl)
3326 switch (mixer->chip->usb_id) {
3327 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
3328 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
3329 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
3331 /* lowest playback value is muted on C-Media devices */
3332 case USB_ID(0x0d8c, 0x000c):
3333 case USB_ID(0x0d8c, 0x0014):
3334 if (strstr(kctl->id.name, "Playback"))