mmc: core: Clarify sdio_irq_pending flag for MMC_CAP2_SDIO_IRQ_NOTHREAD
[linux/fpc-iii.git] / sound / usb / mixer_quirks.c
blob27dcb3743690f7c29764fb978823f0f37ad9c977
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
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>
31 #include "usbaudio.h"
32 #include "mixer.h"
33 #include "mixer_quirks.h"
34 #include "mixer_scarlett.h"
35 #include "mixer_us16x08.h"
36 #include "helper.h"
38 struct std_mono_table {
39 unsigned int unitid, control, cmask;
40 int val_type;
41 const char *name;
42 snd_kcontrol_tlv_rw_t *tlv_callback;
45 /* This function allows for the creation of standard UAC controls.
46 * See the quirks for M-Audio FTUs or Ebox-44.
47 * If you don't want to set a TLV callback pass NULL.
49 * Since there doesn't seem to be a devices that needs a multichannel
50 * version, we keep it mono for simplicity.
52 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
53 unsigned int unitid,
54 unsigned int control,
55 unsigned int cmask,
56 int val_type,
57 unsigned int idx_off,
58 const char *name,
59 snd_kcontrol_tlv_rw_t *tlv_callback)
61 struct usb_mixer_elem_info *cval;
62 struct snd_kcontrol *kctl;
64 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
65 if (!cval)
66 return -ENOMEM;
68 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
69 cval->val_type = val_type;
70 cval->channels = 1;
71 cval->control = control;
72 cval->cmask = cmask;
73 cval->idx_off = idx_off;
75 /* get_min_max() is called only for integer volumes later,
76 * so provide a short-cut for booleans */
77 cval->min = 0;
78 cval->max = 1;
79 cval->res = 0;
80 cval->dBmin = 0;
81 cval->dBmax = 0;
83 /* Create control */
84 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
85 if (!kctl) {
86 kfree(cval);
87 return -ENOMEM;
90 /* Set name */
91 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
92 kctl->private_free = snd_usb_mixer_elem_free;
94 /* set TLV */
95 if (tlv_callback) {
96 kctl->tlv.c = tlv_callback;
97 kctl->vd[0].access |=
98 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
99 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
101 /* Add control to mixer */
102 return snd_usb_mixer_add_control(&cval->head, kctl);
105 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
106 unsigned int unitid,
107 unsigned int control,
108 unsigned int cmask,
109 int val_type,
110 const char *name,
111 snd_kcontrol_tlv_rw_t *tlv_callback)
113 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
114 val_type, 0 /* Offset */, name, tlv_callback);
118 * Create a set of standard UAC controls from a table
120 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
121 struct std_mono_table *t)
123 int err;
125 while (t->name != NULL) {
126 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
127 t->cmask, t->val_type, t->name, t->tlv_callback);
128 if (err < 0)
129 return err;
130 t++;
133 return 0;
136 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
137 int id,
138 usb_mixer_elem_resume_func_t resume,
139 const struct snd_kcontrol_new *knew,
140 struct usb_mixer_elem_list **listp)
142 struct usb_mixer_elem_list *list;
143 struct snd_kcontrol *kctl;
145 list = kzalloc(sizeof(*list), GFP_KERNEL);
146 if (!list)
147 return -ENOMEM;
148 if (listp)
149 *listp = list;
150 list->mixer = mixer;
151 list->id = id;
152 list->resume = resume;
153 kctl = snd_ctl_new1(knew, list);
154 if (!kctl) {
155 kfree(list);
156 return -ENOMEM;
158 kctl->private_free = snd_usb_mixer_elem_free;
159 return snd_usb_mixer_add_control(list, kctl);
163 * Sound Blaster remote control configuration
165 * format of remote control data:
166 * Extigy: xx 00
167 * Audigy 2 NX: 06 80 xx 00 00 00
168 * Live! 24-bit: 06 80 xx yy 22 83
170 static const struct rc_config {
171 u32 usb_id;
172 u8 offset;
173 u8 length;
174 u8 packet_length;
175 u8 min_packet_length; /* minimum accepted length of the URB result */
176 u8 mute_mixer_id;
177 u32 mute_code;
178 } rc_configs[] = {
179 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
180 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
181 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
182 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
183 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
184 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
185 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
188 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
190 struct usb_mixer_interface *mixer = urb->context;
191 const struct rc_config *rc = mixer->rc_cfg;
192 u32 code;
194 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
195 return;
197 code = mixer->rc_buffer[rc->offset];
198 if (rc->length == 2)
199 code |= mixer->rc_buffer[rc->offset + 1] << 8;
201 /* the Mute button actually changes the mixer control */
202 if (code == rc->mute_code)
203 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
204 mixer->rc_code = code;
205 wmb();
206 wake_up(&mixer->rc_waitq);
209 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
210 long count, loff_t *offset)
212 struct usb_mixer_interface *mixer = hw->private_data;
213 int err;
214 u32 rc_code;
216 if (count != 1 && count != 4)
217 return -EINVAL;
218 err = wait_event_interruptible(mixer->rc_waitq,
219 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
220 if (err == 0) {
221 if (count == 1)
222 err = put_user(rc_code, buf);
223 else
224 err = put_user(rc_code, (u32 __user *)buf);
226 return err < 0 ? err : count;
229 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
230 poll_table *wait)
232 struct usb_mixer_interface *mixer = hw->private_data;
234 poll_wait(file, &mixer->rc_waitq, wait);
235 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
238 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
240 struct snd_hwdep *hwdep;
241 int err, len, i;
243 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
244 if (rc_configs[i].usb_id == mixer->chip->usb_id)
245 break;
246 if (i >= ARRAY_SIZE(rc_configs))
247 return 0;
248 mixer->rc_cfg = &rc_configs[i];
250 len = mixer->rc_cfg->packet_length;
252 init_waitqueue_head(&mixer->rc_waitq);
253 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
254 if (err < 0)
255 return err;
256 snprintf(hwdep->name, sizeof(hwdep->name),
257 "%s remote control", mixer->chip->card->shortname);
258 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
259 hwdep->private_data = mixer;
260 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
261 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
262 hwdep->exclusive = 1;
264 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
265 if (!mixer->rc_urb)
266 return -ENOMEM;
267 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
268 if (!mixer->rc_setup_packet) {
269 usb_free_urb(mixer->rc_urb);
270 mixer->rc_urb = NULL;
271 return -ENOMEM;
273 mixer->rc_setup_packet->bRequestType =
274 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
275 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
276 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
277 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
278 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
279 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
280 usb_rcvctrlpipe(mixer->chip->dev, 0),
281 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
282 snd_usb_soundblaster_remote_complete, mixer);
283 return 0;
286 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
288 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
290 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
291 return 0;
294 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
295 int value, int index)
297 struct snd_usb_audio *chip = mixer->chip;
298 int err;
300 err = snd_usb_lock_shutdown(chip);
301 if (err < 0)
302 return err;
304 if (chip->usb_id == USB_ID(0x041e, 0x3042))
305 err = snd_usb_ctl_msg(chip->dev,
306 usb_sndctrlpipe(chip->dev, 0), 0x24,
307 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
308 !value, 0, NULL, 0);
309 /* USB X-Fi S51 Pro */
310 if (chip->usb_id == USB_ID(0x041e, 0x30df))
311 err = snd_usb_ctl_msg(chip->dev,
312 usb_sndctrlpipe(chip->dev, 0), 0x24,
313 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
314 !value, 0, NULL, 0);
315 else
316 err = snd_usb_ctl_msg(chip->dev,
317 usb_sndctrlpipe(chip->dev, 0), 0x24,
318 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
319 value, index + 2, NULL, 0);
320 snd_usb_unlock_shutdown(chip);
321 return err;
324 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
327 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
328 struct usb_mixer_interface *mixer = list->mixer;
329 int index = kcontrol->private_value & 0xff;
330 unsigned int value = ucontrol->value.integer.value[0];
331 int old_value = kcontrol->private_value >> 8;
332 int err;
334 if (value > 1)
335 return -EINVAL;
336 if (value == old_value)
337 return 0;
338 kcontrol->private_value = (value << 8) | index;
339 err = snd_audigy2nx_led_update(mixer, value, index);
340 return err < 0 ? err : 1;
343 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
345 int priv_value = list->kctl->private_value;
347 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
348 priv_value & 0xff);
351 /* name and private_value are set dynamically */
352 static const struct snd_kcontrol_new snd_audigy2nx_control = {
353 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
354 .info = snd_audigy2nx_led_info,
355 .get = snd_audigy2nx_led_get,
356 .put = snd_audigy2nx_led_put,
359 static const char * const snd_audigy2nx_led_names[] = {
360 "CMSS LED Switch",
361 "Power LED Switch",
362 "Dolby Digital LED Switch",
365 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
367 int i, err;
369 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
370 struct snd_kcontrol_new knew;
372 /* USB X-Fi S51 doesn't have a CMSS LED */
373 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
374 continue;
375 /* USB X-Fi S51 Pro doesn't have one either */
376 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
377 continue;
378 if (i > 1 && /* Live24ext has 2 LEDs only */
379 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
380 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
381 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
382 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
383 break;
385 knew = snd_audigy2nx_control;
386 knew.name = snd_audigy2nx_led_names[i];
387 knew.private_value = (1 << 8) | i; /* LED on as default */
388 err = add_single_ctl_with_resume(mixer, 0,
389 snd_audigy2nx_led_resume,
390 &knew, NULL);
391 if (err < 0)
392 return err;
394 return 0;
397 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
398 struct snd_info_buffer *buffer)
400 static const struct sb_jack {
401 int unitid;
402 const char *name;
403 } jacks_audigy2nx[] = {
404 {4, "dig in "},
405 {7, "line in"},
406 {19, "spk out"},
407 {20, "hph out"},
408 {-1, NULL}
409 }, jacks_live24ext[] = {
410 {4, "line in"}, /* &1=Line, &2=Mic*/
411 {3, "hph out"}, /* headphones */
412 {0, "RC "}, /* last command, 6 bytes see rc_config above */
413 {-1, NULL}
415 const struct sb_jack *jacks;
416 struct usb_mixer_interface *mixer = entry->private_data;
417 int i, err;
418 u8 buf[3];
420 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
421 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
422 jacks = jacks_audigy2nx;
423 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
424 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
425 jacks = jacks_live24ext;
426 else
427 return;
429 for (i = 0; jacks[i].name; ++i) {
430 snd_iprintf(buffer, "%s: ", jacks[i].name);
431 err = snd_usb_lock_shutdown(mixer->chip);
432 if (err < 0)
433 return;
434 err = snd_usb_ctl_msg(mixer->chip->dev,
435 usb_rcvctrlpipe(mixer->chip->dev, 0),
436 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
437 USB_RECIP_INTERFACE, 0,
438 jacks[i].unitid << 8, buf, 3);
439 snd_usb_unlock_shutdown(mixer->chip);
440 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
441 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
442 else
443 snd_iprintf(buffer, "?\n");
447 /* EMU0204 */
448 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
449 struct snd_ctl_elem_info *uinfo)
451 static const char * const texts[2] = {"1/2", "3/4"};
453 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
456 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
457 struct snd_ctl_elem_value *ucontrol)
459 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
460 return 0;
463 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
464 int value)
466 struct snd_usb_audio *chip = mixer->chip;
467 int err;
468 unsigned char buf[2];
470 err = snd_usb_lock_shutdown(chip);
471 if (err < 0)
472 return err;
474 buf[0] = 0x01;
475 buf[1] = value ? 0x02 : 0x01;
476 err = snd_usb_ctl_msg(chip->dev,
477 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
478 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
479 0x0400, 0x0e00, buf, 2);
480 snd_usb_unlock_shutdown(chip);
481 return err;
484 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
485 struct snd_ctl_elem_value *ucontrol)
487 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
488 struct usb_mixer_interface *mixer = list->mixer;
489 unsigned int value = ucontrol->value.enumerated.item[0];
490 int err;
492 if (value > 1)
493 return -EINVAL;
495 if (value == kcontrol->private_value)
496 return 0;
498 kcontrol->private_value = value;
499 err = snd_emu0204_ch_switch_update(mixer, value);
500 return err < 0 ? err : 1;
503 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
505 return snd_emu0204_ch_switch_update(list->mixer,
506 list->kctl->private_value);
509 static struct snd_kcontrol_new snd_emu0204_control = {
510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
511 .name = "Front Jack Channels",
512 .info = snd_emu0204_ch_switch_info,
513 .get = snd_emu0204_ch_switch_get,
514 .put = snd_emu0204_ch_switch_put,
515 .private_value = 0,
518 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
520 return add_single_ctl_with_resume(mixer, 0,
521 snd_emu0204_ch_switch_resume,
522 &snd_emu0204_control, NULL);
525 /* ASUS Xonar U1 / U3 controls */
527 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
528 struct snd_ctl_elem_value *ucontrol)
530 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
531 return 0;
534 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
535 unsigned char status)
537 struct snd_usb_audio *chip = mixer->chip;
538 int err;
540 err = snd_usb_lock_shutdown(chip);
541 if (err < 0)
542 return err;
543 err = snd_usb_ctl_msg(chip->dev,
544 usb_sndctrlpipe(chip->dev, 0), 0x08,
545 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
546 50, 0, &status, 1);
547 snd_usb_unlock_shutdown(chip);
548 return err;
551 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol)
554 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
555 u8 old_status, new_status;
556 int err;
558 old_status = kcontrol->private_value;
559 if (ucontrol->value.integer.value[0])
560 new_status = old_status | 0x02;
561 else
562 new_status = old_status & ~0x02;
563 if (new_status == old_status)
564 return 0;
566 kcontrol->private_value = new_status;
567 err = snd_xonar_u1_switch_update(list->mixer, new_status);
568 return err < 0 ? err : 1;
571 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
573 return snd_xonar_u1_switch_update(list->mixer,
574 list->kctl->private_value);
577 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
579 .name = "Digital Playback Switch",
580 .info = snd_ctl_boolean_mono_info,
581 .get = snd_xonar_u1_switch_get,
582 .put = snd_xonar_u1_switch_put,
583 .private_value = 0x05,
586 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
588 return add_single_ctl_with_resume(mixer, 0,
589 snd_xonar_u1_switch_resume,
590 &snd_xonar_u1_output_switch, NULL);
593 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
595 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
596 struct snd_ctl_elem_value *ucontrol)
598 ucontrol->value.enumerated.item[0] = kctl->private_value;
599 return 0;
602 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
604 struct snd_usb_audio *chip = mixer->chip;
605 int err;
606 unsigned char buff[3];
608 err = snd_usb_lock_shutdown(chip);
609 if (err < 0)
610 return err;
612 /* Prepare for magic command to toggle clock source */
613 err = snd_usb_ctl_msg(chip->dev,
614 usb_rcvctrlpipe(chip->dev, 0), 0x81,
615 USB_DIR_IN |
616 USB_TYPE_CLASS |
617 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
618 if (err < 0)
619 goto err;
620 err = snd_usb_ctl_msg(chip->dev,
621 usb_rcvctrlpipe(chip->dev, 0), 0x81,
622 USB_DIR_IN |
623 USB_TYPE_CLASS |
624 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
625 if (err < 0)
626 goto err;
628 /* 2 possibilities: Internal -> send sample rate
629 * S/PDIF sync -> send zeroes
630 * NB: Sample rate locked to 48kHz on purpose to
631 * prevent user from resetting the sample rate
632 * while S/PDIF sync is enabled and confusing
633 * this configuration.
635 if (val == 0) {
636 buff[0] = 0x80;
637 buff[1] = 0xbb;
638 buff[2] = 0x00;
639 } else {
640 buff[0] = buff[1] = buff[2] = 0x00;
643 /* Send the magic command to toggle the clock source */
644 err = snd_usb_ctl_msg(chip->dev,
645 usb_sndctrlpipe(chip->dev, 0), 0x1,
646 USB_TYPE_CLASS |
647 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
648 if (err < 0)
649 goto err;
650 err = snd_usb_ctl_msg(chip->dev,
651 usb_rcvctrlpipe(chip->dev, 0), 0x81,
652 USB_DIR_IN |
653 USB_TYPE_CLASS |
654 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
655 if (err < 0)
656 goto err;
657 err = snd_usb_ctl_msg(chip->dev,
658 usb_rcvctrlpipe(chip->dev, 0), 0x81,
659 USB_DIR_IN |
660 USB_TYPE_CLASS |
661 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
662 if (err < 0)
663 goto err;
665 err:
666 snd_usb_unlock_shutdown(chip);
667 return err;
670 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
671 struct snd_ctl_elem_value *ucontrol)
673 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
674 struct usb_mixer_interface *mixer = list->mixer;
675 int err;
676 bool cur_val, new_val;
678 cur_val = kctl->private_value;
679 new_val = ucontrol->value.enumerated.item[0];
680 if (cur_val == new_val)
681 return 0;
683 kctl->private_value = new_val;
684 err = snd_mbox1_switch_update(mixer, new_val);
685 return err < 0 ? err : 1;
688 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
689 struct snd_ctl_elem_info *uinfo)
691 static const char *const texts[2] = {
692 "Internal",
693 "S/PDIF"
696 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
699 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
701 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
704 static struct snd_kcontrol_new snd_mbox1_switch = {
705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
706 .name = "Clock Source",
707 .index = 0,
708 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
709 .info = snd_mbox1_switch_info,
710 .get = snd_mbox1_switch_get,
711 .put = snd_mbox1_switch_put,
712 .private_value = 0
715 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
717 return add_single_ctl_with_resume(mixer, 0,
718 snd_mbox1_switch_resume,
719 &snd_mbox1_switch, NULL);
722 /* Native Instruments device quirks */
724 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
726 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
727 struct snd_kcontrol *kctl)
729 struct usb_device *dev = mixer->chip->dev;
730 unsigned int pval = kctl->private_value;
731 u8 value;
732 int err;
734 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
735 (pval >> 16) & 0xff,
736 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
737 0, pval & 0xffff, &value, 1);
738 if (err < 0) {
739 dev_err(&dev->dev,
740 "unable to issue vendor read request (ret = %d)", err);
741 return err;
744 kctl->private_value |= ((unsigned int)value << 24);
745 return 0;
748 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
749 struct snd_ctl_elem_value *ucontrol)
751 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
752 return 0;
755 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
757 struct snd_usb_audio *chip = list->mixer->chip;
758 unsigned int pval = list->kctl->private_value;
759 int err;
761 err = snd_usb_lock_shutdown(chip);
762 if (err < 0)
763 return err;
764 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
765 (pval >> 16) & 0xff,
766 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
767 pval >> 24, pval & 0xffff, NULL, 0, 1000);
768 snd_usb_unlock_shutdown(chip);
769 return err;
772 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
773 struct snd_ctl_elem_value *ucontrol)
775 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
776 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
777 u8 newval = ucontrol->value.integer.value[0];
778 int err;
780 if (oldval == newval)
781 return 0;
783 kcontrol->private_value &= ~(0xff << 24);
784 kcontrol->private_value |= (unsigned int)newval << 24;
785 err = snd_ni_update_cur_val(list);
786 return err < 0 ? err : 1;
789 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
791 .name = "Direct Thru Channel A",
792 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
795 .name = "Direct Thru Channel B",
796 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
799 .name = "Phono Input Channel A",
800 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
803 .name = "Phono Input Channel B",
804 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
808 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
810 .name = "Direct Thru Channel A",
811 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
814 .name = "Direct Thru Channel B",
815 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
818 .name = "Direct Thru Channel C",
819 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
822 .name = "Direct Thru Channel D",
823 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
826 .name = "Phono Input Channel A",
827 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
830 .name = "Phono Input Channel B",
831 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
834 .name = "Phono Input Channel C",
835 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
838 .name = "Phono Input Channel D",
839 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
843 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
844 const struct snd_kcontrol_new *kc,
845 unsigned int count)
847 int i, err = 0;
848 struct snd_kcontrol_new template = {
849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
850 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
851 .get = snd_nativeinstruments_control_get,
852 .put = snd_nativeinstruments_control_put,
853 .info = snd_ctl_boolean_mono_info,
856 for (i = 0; i < count; i++) {
857 struct usb_mixer_elem_list *list;
859 template.name = kc[i].name;
860 template.private_value = kc[i].private_value;
862 err = add_single_ctl_with_resume(mixer, 0,
863 snd_ni_update_cur_val,
864 &template, &list);
865 if (err < 0)
866 break;
867 snd_ni_control_init_val(mixer, list->kctl);
870 return err;
873 /* M-Audio FastTrack Ultra quirks */
874 /* FTU Effect switch (also used by C400/C600) */
875 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_info *uinfo)
878 static const char *const texts[8] = {
879 "Room 1", "Room 2", "Room 3", "Hall 1",
880 "Hall 2", "Plate", "Delay", "Echo"
883 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
886 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
887 struct snd_kcontrol *kctl)
889 struct usb_device *dev = mixer->chip->dev;
890 unsigned int pval = kctl->private_value;
891 int err;
892 unsigned char value[2];
894 value[0] = 0x00;
895 value[1] = 0x00;
897 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
898 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
899 pval & 0xff00,
900 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
901 value, 2);
902 if (err < 0)
903 return err;
905 kctl->private_value |= (unsigned int)value[0] << 24;
906 return 0;
909 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
910 struct snd_ctl_elem_value *ucontrol)
912 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
913 return 0;
916 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
918 struct snd_usb_audio *chip = list->mixer->chip;
919 unsigned int pval = list->kctl->private_value;
920 unsigned char value[2];
921 int err;
923 value[0] = pval >> 24;
924 value[1] = 0;
926 err = snd_usb_lock_shutdown(chip);
927 if (err < 0)
928 return err;
929 err = snd_usb_ctl_msg(chip->dev,
930 usb_sndctrlpipe(chip->dev, 0),
931 UAC_SET_CUR,
932 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
933 pval & 0xff00,
934 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
935 value, 2);
936 snd_usb_unlock_shutdown(chip);
937 return err;
940 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
941 struct snd_ctl_elem_value *ucontrol)
943 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
944 unsigned int pval = list->kctl->private_value;
945 int cur_val, err, new_val;
947 cur_val = pval >> 24;
948 new_val = ucontrol->value.enumerated.item[0];
949 if (cur_val == new_val)
950 return 0;
952 kctl->private_value &= ~(0xff << 24);
953 kctl->private_value |= new_val << 24;
954 err = snd_ftu_eff_switch_update(list);
955 return err < 0 ? err : 1;
958 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
959 int validx, int bUnitID)
961 static struct snd_kcontrol_new template = {
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
963 .name = "Effect Program Switch",
964 .index = 0,
965 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
966 .info = snd_ftu_eff_switch_info,
967 .get = snd_ftu_eff_switch_get,
968 .put = snd_ftu_eff_switch_put
970 struct usb_mixer_elem_list *list;
971 int err;
973 err = add_single_ctl_with_resume(mixer, bUnitID,
974 snd_ftu_eff_switch_update,
975 &template, &list);
976 if (err < 0)
977 return err;
978 list->kctl->private_value = (validx << 8) | bUnitID;
979 snd_ftu_eff_switch_init(mixer, list->kctl);
980 return 0;
983 /* Create volume controls for FTU devices*/
984 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
986 char name[64];
987 unsigned int control, cmask;
988 int in, out, err;
990 const unsigned int id = 5;
991 const int val_type = USB_MIXER_S16;
993 for (out = 0; out < 8; out++) {
994 control = out + 1;
995 for (in = 0; in < 8; in++) {
996 cmask = 1 << in;
997 snprintf(name, sizeof(name),
998 "AIn%d - Out%d Capture Volume",
999 in + 1, out + 1);
1000 err = snd_create_std_mono_ctl(mixer, id, control,
1001 cmask, val_type, name,
1002 &snd_usb_mixer_vol_tlv);
1003 if (err < 0)
1004 return err;
1006 for (in = 8; in < 16; in++) {
1007 cmask = 1 << in;
1008 snprintf(name, sizeof(name),
1009 "DIn%d - Out%d Playback Volume",
1010 in - 7, out + 1);
1011 err = snd_create_std_mono_ctl(mixer, id, control,
1012 cmask, val_type, name,
1013 &snd_usb_mixer_vol_tlv);
1014 if (err < 0)
1015 return err;
1019 return 0;
1022 /* This control needs a volume quirk, see mixer.c */
1023 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1025 static const char name[] = "Effect Volume";
1026 const unsigned int id = 6;
1027 const int val_type = USB_MIXER_U8;
1028 const unsigned int control = 2;
1029 const unsigned int cmask = 0;
1031 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1032 name, snd_usb_mixer_vol_tlv);
1035 /* This control needs a volume quirk, see mixer.c */
1036 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1038 static const char name[] = "Effect Duration";
1039 const unsigned int id = 6;
1040 const int val_type = USB_MIXER_S16;
1041 const unsigned int control = 3;
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_feedback_ctl(struct usb_mixer_interface *mixer)
1051 static const char name[] = "Effect Feedback Volume";
1052 const unsigned int id = 6;
1053 const int val_type = USB_MIXER_U8;
1054 const unsigned int control = 4;
1055 const unsigned int cmask = 0;
1057 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1058 name, NULL);
1061 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1063 unsigned int cmask;
1064 int err, ch;
1065 char name[48];
1067 const unsigned int id = 7;
1068 const int val_type = USB_MIXER_S16;
1069 const unsigned int control = 7;
1071 for (ch = 0; ch < 4; ++ch) {
1072 cmask = 1 << ch;
1073 snprintf(name, sizeof(name),
1074 "Effect Return %d Volume", ch + 1);
1075 err = snd_create_std_mono_ctl(mixer, id, control,
1076 cmask, val_type, name,
1077 snd_usb_mixer_vol_tlv);
1078 if (err < 0)
1079 return err;
1082 return 0;
1085 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1087 unsigned int cmask;
1088 int err, ch;
1089 char name[48];
1091 const unsigned int id = 5;
1092 const int val_type = USB_MIXER_S16;
1093 const unsigned int control = 9;
1095 for (ch = 0; ch < 8; ++ch) {
1096 cmask = 1 << ch;
1097 snprintf(name, sizeof(name),
1098 "Effect Send AIn%d Volume", ch + 1);
1099 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1100 val_type, name,
1101 snd_usb_mixer_vol_tlv);
1102 if (err < 0)
1103 return err;
1105 for (ch = 8; ch < 16; ++ch) {
1106 cmask = 1 << ch;
1107 snprintf(name, sizeof(name),
1108 "Effect Send DIn%d Volume", ch - 7);
1109 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1110 val_type, name,
1111 snd_usb_mixer_vol_tlv);
1112 if (err < 0)
1113 return err;
1115 return 0;
1118 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1120 int err;
1122 err = snd_ftu_create_volume_ctls(mixer);
1123 if (err < 0)
1124 return err;
1126 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1127 if (err < 0)
1128 return err;
1130 err = snd_ftu_create_effect_volume_ctl(mixer);
1131 if (err < 0)
1132 return err;
1134 err = snd_ftu_create_effect_duration_ctl(mixer);
1135 if (err < 0)
1136 return err;
1138 err = snd_ftu_create_effect_feedback_ctl(mixer);
1139 if (err < 0)
1140 return err;
1142 err = snd_ftu_create_effect_return_ctls(mixer);
1143 if (err < 0)
1144 return err;
1146 err = snd_ftu_create_effect_send_ctls(mixer);
1147 if (err < 0)
1148 return err;
1150 return 0;
1153 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1154 unsigned char samplerate_id)
1156 struct usb_mixer_interface *mixer;
1157 struct usb_mixer_elem_info *cval;
1158 int unitid = 12; /* SampleRate ExtensionUnit ID */
1160 list_for_each_entry(mixer, &chip->mixer_list, list) {
1161 if (mixer->id_elems[unitid]) {
1162 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1163 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1164 cval->control << 8,
1165 samplerate_id);
1166 snd_usb_mixer_notify_id(mixer, unitid);
1167 break;
1172 /* M-Audio Fast Track C400/C600 */
1173 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1174 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1176 char name[64];
1177 unsigned int cmask, offset;
1178 int out, chan, err;
1179 int num_outs = 0;
1180 int num_ins = 0;
1182 const unsigned int id = 0x40;
1183 const int val_type = USB_MIXER_S16;
1184 const int control = 1;
1186 switch (mixer->chip->usb_id) {
1187 case USB_ID(0x0763, 0x2030):
1188 num_outs = 6;
1189 num_ins = 4;
1190 break;
1191 case USB_ID(0x0763, 0x2031):
1192 num_outs = 8;
1193 num_ins = 6;
1194 break;
1197 for (chan = 0; chan < num_outs + num_ins; chan++) {
1198 for (out = 0; out < num_outs; out++) {
1199 if (chan < num_outs) {
1200 snprintf(name, sizeof(name),
1201 "PCM%d-Out%d Playback Volume",
1202 chan + 1, out + 1);
1203 } else {
1204 snprintf(name, sizeof(name),
1205 "In%d-Out%d Playback Volume",
1206 chan - num_outs + 1, out + 1);
1209 cmask = (out == 0) ? 0 : 1 << (out - 1);
1210 offset = chan * num_outs;
1211 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1212 cmask, val_type, offset, name,
1213 &snd_usb_mixer_vol_tlv);
1214 if (err < 0)
1215 return err;
1219 return 0;
1222 /* This control needs a volume quirk, see mixer.c */
1223 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1225 static const char name[] = "Effect Volume";
1226 const unsigned int id = 0x43;
1227 const int val_type = USB_MIXER_U8;
1228 const unsigned int control = 3;
1229 const unsigned int cmask = 0;
1231 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1232 name, snd_usb_mixer_vol_tlv);
1235 /* This control needs a volume quirk, see mixer.c */
1236 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1238 static const char name[] = "Effect Duration";
1239 const unsigned int id = 0x43;
1240 const int val_type = USB_MIXER_S16;
1241 const unsigned int control = 4;
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_feedback_ctl(struct usb_mixer_interface *mixer)
1251 static const char name[] = "Effect Feedback Volume";
1252 const unsigned int id = 0x43;
1253 const int val_type = USB_MIXER_U8;
1254 const unsigned int control = 5;
1255 const unsigned int cmask = 0;
1257 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1258 name, NULL);
1261 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1263 char name[64];
1264 unsigned int cmask;
1265 int chan, err;
1266 int num_outs = 0;
1267 int num_ins = 0;
1269 const unsigned int id = 0x42;
1270 const int val_type = USB_MIXER_S16;
1271 const int control = 1;
1273 switch (mixer->chip->usb_id) {
1274 case USB_ID(0x0763, 0x2030):
1275 num_outs = 6;
1276 num_ins = 4;
1277 break;
1278 case USB_ID(0x0763, 0x2031):
1279 num_outs = 8;
1280 num_ins = 6;
1281 break;
1284 for (chan = 0; chan < num_outs + num_ins; chan++) {
1285 if (chan < num_outs) {
1286 snprintf(name, sizeof(name),
1287 "Effect Send DOut%d",
1288 chan + 1);
1289 } else {
1290 snprintf(name, sizeof(name),
1291 "Effect Send AIn%d",
1292 chan - num_outs + 1);
1295 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1296 err = snd_create_std_mono_ctl(mixer, id, control,
1297 cmask, val_type, name,
1298 &snd_usb_mixer_vol_tlv);
1299 if (err < 0)
1300 return err;
1303 return 0;
1306 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1308 char name[64];
1309 unsigned int cmask;
1310 int chan, err;
1311 int num_outs = 0;
1312 int offset = 0;
1314 const unsigned int id = 0x40;
1315 const int val_type = USB_MIXER_S16;
1316 const int control = 1;
1318 switch (mixer->chip->usb_id) {
1319 case USB_ID(0x0763, 0x2030):
1320 num_outs = 6;
1321 offset = 0x3c;
1322 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1323 break;
1324 case USB_ID(0x0763, 0x2031):
1325 num_outs = 8;
1326 offset = 0x70;
1327 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1328 break;
1331 for (chan = 0; chan < num_outs; chan++) {
1332 snprintf(name, sizeof(name),
1333 "Effect Return %d",
1334 chan + 1);
1336 cmask = (chan == 0) ? 0 :
1337 1 << (chan + (chan % 2) * num_outs - 1);
1338 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1339 cmask, val_type, offset, name,
1340 &snd_usb_mixer_vol_tlv);
1341 if (err < 0)
1342 return err;
1345 return 0;
1348 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1350 int err;
1352 err = snd_c400_create_vol_ctls(mixer);
1353 if (err < 0)
1354 return err;
1356 err = snd_c400_create_effect_vol_ctls(mixer);
1357 if (err < 0)
1358 return err;
1360 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1361 if (err < 0)
1362 return err;
1364 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1365 if (err < 0)
1366 return err;
1368 err = snd_c400_create_effect_volume_ctl(mixer);
1369 if (err < 0)
1370 return err;
1372 err = snd_c400_create_effect_duration_ctl(mixer);
1373 if (err < 0)
1374 return err;
1376 err = snd_c400_create_effect_feedback_ctl(mixer);
1377 if (err < 0)
1378 return err;
1380 return 0;
1384 * The mixer units for Ebox-44 are corrupt, and even where they
1385 * are valid they presents mono controls as L and R channels of
1386 * stereo. So we provide a good mixer here.
1388 static struct std_mono_table ebox44_table[] = {
1390 .unitid = 4,
1391 .control = 1,
1392 .cmask = 0x0,
1393 .val_type = USB_MIXER_INV_BOOLEAN,
1394 .name = "Headphone Playback Switch"
1397 .unitid = 4,
1398 .control = 2,
1399 .cmask = 0x1,
1400 .val_type = USB_MIXER_S16,
1401 .name = "Headphone A Mix Playback Volume"
1404 .unitid = 4,
1405 .control = 2,
1406 .cmask = 0x2,
1407 .val_type = USB_MIXER_S16,
1408 .name = "Headphone B Mix Playback Volume"
1412 .unitid = 7,
1413 .control = 1,
1414 .cmask = 0x0,
1415 .val_type = USB_MIXER_INV_BOOLEAN,
1416 .name = "Output Playback Switch"
1419 .unitid = 7,
1420 .control = 2,
1421 .cmask = 0x1,
1422 .val_type = USB_MIXER_S16,
1423 .name = "Output A Playback Volume"
1426 .unitid = 7,
1427 .control = 2,
1428 .cmask = 0x2,
1429 .val_type = USB_MIXER_S16,
1430 .name = "Output B Playback Volume"
1434 .unitid = 10,
1435 .control = 1,
1436 .cmask = 0x0,
1437 .val_type = USB_MIXER_INV_BOOLEAN,
1438 .name = "Input Capture Switch"
1441 .unitid = 10,
1442 .control = 2,
1443 .cmask = 0x1,
1444 .val_type = USB_MIXER_S16,
1445 .name = "Input A Capture Volume"
1448 .unitid = 10,
1449 .control = 2,
1450 .cmask = 0x2,
1451 .val_type = USB_MIXER_S16,
1452 .name = "Input B Capture Volume"
1458 /* Audio Advantage Micro II findings:
1460 * Mapping spdif AES bits to vendor register.bit:
1461 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1462 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1463 * AES2: [0 0 0 0 0 0 0 0]
1464 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1465 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1467 * power on values:
1468 * r2: 0x10
1469 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1470 * just after it to 0xa0, presumably it disables/mutes some analog
1471 * parts when there is no audio.)
1472 * r9: 0x28
1474 * Optical transmitter on/off:
1475 * vendor register.bit: 9.1
1476 * 0 - on (0x28 register value)
1477 * 1 - off (0x2a register value)
1480 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1481 struct snd_ctl_elem_info *uinfo)
1483 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1484 uinfo->count = 1;
1485 return 0;
1488 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1489 struct snd_ctl_elem_value *ucontrol)
1491 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1492 struct snd_usb_audio *chip = list->mixer->chip;
1493 int err;
1494 struct usb_interface *iface;
1495 struct usb_host_interface *alts;
1496 unsigned int ep;
1497 unsigned char data[3];
1498 int rate;
1500 err = snd_usb_lock_shutdown(chip);
1501 if (err < 0)
1502 return err;
1504 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1505 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1506 ucontrol->value.iec958.status[2] = 0x00;
1508 /* use known values for that card: interface#1 altsetting#1 */
1509 iface = usb_ifnum_to_if(chip->dev, 1);
1510 if (!iface || iface->num_altsetting < 2)
1511 return -EINVAL;
1512 alts = &iface->altsetting[1];
1513 if (get_iface_desc(alts)->bNumEndpoints < 1)
1514 return -EINVAL;
1515 ep = get_endpoint(alts, 0)->bEndpointAddress;
1517 err = snd_usb_ctl_msg(chip->dev,
1518 usb_rcvctrlpipe(chip->dev, 0),
1519 UAC_GET_CUR,
1520 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1521 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1523 data,
1524 sizeof(data));
1525 if (err < 0)
1526 goto end;
1528 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1529 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1530 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1532 err = 0;
1533 end:
1534 snd_usb_unlock_shutdown(chip);
1535 return err;
1538 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1540 struct snd_usb_audio *chip = list->mixer->chip;
1541 unsigned int pval = list->kctl->private_value;
1542 u8 reg;
1543 int err;
1545 err = snd_usb_lock_shutdown(chip);
1546 if (err < 0)
1547 return err;
1549 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1550 err = snd_usb_ctl_msg(chip->dev,
1551 usb_sndctrlpipe(chip->dev, 0),
1552 UAC_SET_CUR,
1553 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1554 reg,
1556 NULL,
1558 if (err < 0)
1559 goto end;
1561 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1562 reg |= (pval >> 12) & 0x0f;
1563 err = snd_usb_ctl_msg(chip->dev,
1564 usb_sndctrlpipe(chip->dev, 0),
1565 UAC_SET_CUR,
1566 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1567 reg,
1569 NULL,
1571 if (err < 0)
1572 goto end;
1574 end:
1575 snd_usb_unlock_shutdown(chip);
1576 return err;
1579 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol)
1582 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1583 unsigned int pval, pval_old;
1584 int err;
1586 pval = pval_old = kcontrol->private_value;
1587 pval &= 0xfffff0f0;
1588 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1589 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1591 pval &= 0xffff0fff;
1592 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1594 /* The frequency bits in AES3 cannot be set via register access. */
1596 /* Silently ignore any bits from the request that cannot be set. */
1598 if (pval == pval_old)
1599 return 0;
1601 kcontrol->private_value = pval;
1602 err = snd_microii_spdif_default_update(list);
1603 return err < 0 ? err : 1;
1606 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1607 struct snd_ctl_elem_value *ucontrol)
1609 ucontrol->value.iec958.status[0] = 0x0f;
1610 ucontrol->value.iec958.status[1] = 0xff;
1611 ucontrol->value.iec958.status[2] = 0x00;
1612 ucontrol->value.iec958.status[3] = 0x00;
1614 return 0;
1617 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1618 struct snd_ctl_elem_value *ucontrol)
1620 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1622 return 0;
1625 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1627 struct snd_usb_audio *chip = list->mixer->chip;
1628 u8 reg = list->kctl->private_value;
1629 int err;
1631 err = snd_usb_lock_shutdown(chip);
1632 if (err < 0)
1633 return err;
1635 err = snd_usb_ctl_msg(chip->dev,
1636 usb_sndctrlpipe(chip->dev, 0),
1637 UAC_SET_CUR,
1638 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1639 reg,
1641 NULL,
1644 snd_usb_unlock_shutdown(chip);
1645 return err;
1648 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1649 struct snd_ctl_elem_value *ucontrol)
1651 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1652 u8 reg;
1653 int err;
1655 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1656 if (reg != list->kctl->private_value)
1657 return 0;
1659 kcontrol->private_value = reg;
1660 err = snd_microii_spdif_switch_update(list);
1661 return err < 0 ? err : 1;
1664 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1666 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1667 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1668 .info = snd_microii_spdif_info,
1669 .get = snd_microii_spdif_default_get,
1670 .put = snd_microii_spdif_default_put,
1671 .private_value = 0x00000100UL,/* reset value */
1674 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1675 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1676 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1677 .info = snd_microii_spdif_info,
1678 .get = snd_microii_spdif_mask_get,
1681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1682 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1683 .info = snd_ctl_boolean_mono_info,
1684 .get = snd_microii_spdif_switch_get,
1685 .put = snd_microii_spdif_switch_put,
1686 .private_value = 0x00000028UL,/* reset value */
1690 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1692 int err, i;
1693 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1694 snd_microii_spdif_default_update,
1695 NULL,
1696 snd_microii_spdif_switch_update
1699 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1700 err = add_single_ctl_with_resume(mixer, 0,
1701 resume_funcs[i],
1702 &snd_microii_mixer_spdif[i],
1703 NULL);
1704 if (err < 0)
1705 return err;
1708 return 0;
1711 /* Creative Sound Blaster E1 */
1713 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_value *ucontrol)
1716 ucontrol->value.integer.value[0] = kcontrol->private_value;
1717 return 0;
1720 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1721 unsigned char state)
1723 struct snd_usb_audio *chip = mixer->chip;
1724 int err;
1725 unsigned char buff[2];
1727 buff[0] = 0x02;
1728 buff[1] = state ? 0x02 : 0x00;
1730 err = snd_usb_lock_shutdown(chip);
1731 if (err < 0)
1732 return err;
1733 err = snd_usb_ctl_msg(chip->dev,
1734 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1735 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1736 0x0202, 3, buff, 2);
1737 snd_usb_unlock_shutdown(chip);
1738 return err;
1741 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1742 struct snd_ctl_elem_value *ucontrol)
1744 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1745 unsigned char value = !!ucontrol->value.integer.value[0];
1746 int err;
1748 if (kcontrol->private_value == value)
1749 return 0;
1750 kcontrol->private_value = value;
1751 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1752 return err < 0 ? err : 1;
1755 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1757 return snd_soundblaster_e1_switch_update(list->mixer,
1758 list->kctl->private_value);
1761 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1762 struct snd_ctl_elem_info *uinfo)
1764 static const char *const texts[2] = {
1765 "Mic", "Aux"
1768 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1771 static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1773 .name = "Input Source",
1774 .info = snd_soundblaster_e1_switch_info,
1775 .get = snd_soundblaster_e1_switch_get,
1776 .put = snd_soundblaster_e1_switch_put,
1777 .private_value = 0,
1780 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1782 return add_single_ctl_with_resume(mixer, 0,
1783 snd_soundblaster_e1_switch_resume,
1784 &snd_soundblaster_e1_input_switch,
1785 NULL);
1788 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1790 u16 buf = 0;
1792 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1793 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1794 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1795 &buf, 2);
1798 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1800 /* fix to 0dB playback volumes */
1801 dell_dock_init_vol(mixer->chip, 1, 16);
1802 dell_dock_init_vol(mixer->chip, 2, 16);
1803 dell_dock_init_vol(mixer->chip, 1, 19);
1804 dell_dock_init_vol(mixer->chip, 2, 19);
1805 return 0;
1808 /* RME Class Compliant device quirks */
1810 #define SND_RME_GET_STATUS1 23
1811 #define SND_RME_GET_CURRENT_FREQ 17
1812 #define SND_RME_CLK_SYSTEM_SHIFT 16
1813 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1814 #define SND_RME_CLK_AES_SHIFT 8
1815 #define SND_RME_CLK_SPDIF_SHIFT 12
1816 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1817 #define SND_RME_CLK_SYNC_SHIFT 6
1818 #define SND_RME_CLK_SYNC_MASK 0x3
1819 #define SND_RME_CLK_FREQMUL_SHIFT 18
1820 #define SND_RME_CLK_FREQMUL_MASK 0x7
1821 #define SND_RME_CLK_SYSTEM(x) \
1822 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1823 #define SND_RME_CLK_AES(x) \
1824 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1825 #define SND_RME_CLK_SPDIF(x) \
1826 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1827 #define SND_RME_CLK_SYNC(x) \
1828 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1829 #define SND_RME_CLK_FREQMUL(x) \
1830 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1831 #define SND_RME_CLK_AES_LOCK 0x1
1832 #define SND_RME_CLK_AES_SYNC 0x4
1833 #define SND_RME_CLK_SPDIF_LOCK 0x2
1834 #define SND_RME_CLK_SPDIF_SYNC 0x8
1835 #define SND_RME_SPDIF_IF_SHIFT 4
1836 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1837 #define SND_RME_BINARY_MASK 0x1
1838 #define SND_RME_SPDIF_IF(x) \
1839 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1840 #define SND_RME_SPDIF_FORMAT(x) \
1841 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1843 static const u32 snd_rme_rate_table[] = {
1844 32000, 44100, 48000, 50000,
1845 64000, 88200, 96000, 100000,
1846 128000, 176400, 192000, 200000,
1847 256000, 352800, 384000, 400000,
1848 512000, 705600, 768000, 800000
1850 /* maximum number of items for AES and S/PDIF rates for above table */
1851 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1853 enum snd_rme_domain {
1854 SND_RME_DOMAIN_SYSTEM,
1855 SND_RME_DOMAIN_AES,
1856 SND_RME_DOMAIN_SPDIF
1859 enum snd_rme_clock_status {
1860 SND_RME_CLOCK_NOLOCK,
1861 SND_RME_CLOCK_LOCK,
1862 SND_RME_CLOCK_SYNC
1865 static int snd_rme_read_value(struct snd_usb_audio *chip,
1866 unsigned int item,
1867 u32 *value)
1869 struct usb_device *dev = chip->dev;
1870 int err;
1872 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1873 item,
1874 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1875 0, 0,
1876 value, sizeof(*value));
1877 if (err < 0)
1878 dev_err(&dev->dev,
1879 "unable to issue vendor read request %d (ret = %d)",
1880 item, err);
1881 return err;
1884 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1885 u32 *status1)
1887 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1888 struct snd_usb_audio *chip = list->mixer->chip;
1889 int err;
1891 err = snd_usb_lock_shutdown(chip);
1892 if (err < 0)
1893 return err;
1894 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1895 snd_usb_unlock_shutdown(chip);
1896 return err;
1899 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1900 struct snd_ctl_elem_value *ucontrol)
1902 u32 status1;
1903 u32 rate = 0;
1904 int idx;
1905 int err;
1907 err = snd_rme_get_status1(kcontrol, &status1);
1908 if (err < 0)
1909 return err;
1910 switch (kcontrol->private_value) {
1911 case SND_RME_DOMAIN_SYSTEM:
1912 idx = SND_RME_CLK_SYSTEM(status1);
1913 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1914 rate = snd_rme_rate_table[idx];
1915 break;
1916 case SND_RME_DOMAIN_AES:
1917 idx = SND_RME_CLK_AES(status1);
1918 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1919 rate = snd_rme_rate_table[idx];
1920 break;
1921 case SND_RME_DOMAIN_SPDIF:
1922 idx = SND_RME_CLK_SPDIF(status1);
1923 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1924 rate = snd_rme_rate_table[idx];
1925 break;
1926 default:
1927 return -EINVAL;
1929 ucontrol->value.integer.value[0] = rate;
1930 return 0;
1933 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1934 struct snd_ctl_elem_value *ucontrol)
1936 u32 status1;
1937 int idx = SND_RME_CLOCK_NOLOCK;
1938 int err;
1940 err = snd_rme_get_status1(kcontrol, &status1);
1941 if (err < 0)
1942 return err;
1943 switch (kcontrol->private_value) {
1944 case SND_RME_DOMAIN_AES: /* AES */
1945 if (status1 & SND_RME_CLK_AES_SYNC)
1946 idx = SND_RME_CLOCK_SYNC;
1947 else if (status1 & SND_RME_CLK_AES_LOCK)
1948 idx = SND_RME_CLOCK_LOCK;
1949 break;
1950 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
1951 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1952 idx = SND_RME_CLOCK_SYNC;
1953 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1954 idx = SND_RME_CLOCK_LOCK;
1955 break;
1956 default:
1957 return -EINVAL;
1959 ucontrol->value.enumerated.item[0] = idx;
1960 return 0;
1963 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1964 struct snd_ctl_elem_value *ucontrol)
1966 u32 status1;
1967 int err;
1969 err = snd_rme_get_status1(kcontrol, &status1);
1970 if (err < 0)
1971 return err;
1972 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1973 return 0;
1976 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1977 struct snd_ctl_elem_value *ucontrol)
1979 u32 status1;
1980 int err;
1982 err = snd_rme_get_status1(kcontrol, &status1);
1983 if (err < 0)
1984 return err;
1985 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1986 return 0;
1989 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1990 struct snd_ctl_elem_value *ucontrol)
1992 u32 status1;
1993 int err;
1995 err = snd_rme_get_status1(kcontrol, &status1);
1996 if (err < 0)
1997 return err;
1998 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
1999 return 0;
2002 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_value *ucontrol)
2005 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2006 struct snd_usb_audio *chip = list->mixer->chip;
2007 u32 status1;
2008 const u64 num = 104857600000000ULL;
2009 u32 den;
2010 unsigned int freq;
2011 int err;
2013 err = snd_usb_lock_shutdown(chip);
2014 if (err < 0)
2015 return err;
2016 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2017 if (err < 0)
2018 goto end;
2019 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2020 if (err < 0)
2021 goto end;
2022 freq = (den == 0) ? 0 : div64_u64(num, den);
2023 freq <<= SND_RME_CLK_FREQMUL(status1);
2024 ucontrol->value.integer.value[0] = freq;
2026 end:
2027 snd_usb_unlock_shutdown(chip);
2028 return err;
2031 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2032 struct snd_ctl_elem_info *uinfo)
2034 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2035 uinfo->count = 1;
2036 switch (kcontrol->private_value) {
2037 case SND_RME_DOMAIN_SYSTEM:
2038 uinfo->value.integer.min = 32000;
2039 uinfo->value.integer.max = 800000;
2040 break;
2041 case SND_RME_DOMAIN_AES:
2042 case SND_RME_DOMAIN_SPDIF:
2043 default:
2044 uinfo->value.integer.min = 0;
2045 uinfo->value.integer.max = 200000;
2047 uinfo->value.integer.step = 0;
2048 return 0;
2051 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2052 struct snd_ctl_elem_info *uinfo)
2054 static const char *const sync_states[] = {
2055 "No Lock", "Lock", "Sync"
2058 return snd_ctl_enum_info(uinfo, 1,
2059 ARRAY_SIZE(sync_states), sync_states);
2062 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2063 struct snd_ctl_elem_info *uinfo)
2065 static const char *const spdif_if[] = {
2066 "Coaxial", "Optical"
2069 return snd_ctl_enum_info(uinfo, 1,
2070 ARRAY_SIZE(spdif_if), spdif_if);
2073 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2074 struct snd_ctl_elem_info *uinfo)
2076 static const char *const optical_type[] = {
2077 "Consumer", "Professional"
2080 return snd_ctl_enum_info(uinfo, 1,
2081 ARRAY_SIZE(optical_type), optical_type);
2084 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2085 struct snd_ctl_elem_info *uinfo)
2087 static const char *const sync_sources[] = {
2088 "Internal", "AES", "SPDIF", "Internal"
2091 return snd_ctl_enum_info(uinfo, 1,
2092 ARRAY_SIZE(sync_sources), sync_sources);
2095 static struct snd_kcontrol_new snd_rme_controls[] = {
2097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2098 .name = "AES Rate",
2099 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2100 .info = snd_rme_rate_info,
2101 .get = snd_rme_rate_get,
2102 .private_value = SND_RME_DOMAIN_AES
2105 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2106 .name = "AES Sync",
2107 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2108 .info = snd_rme_sync_state_info,
2109 .get = snd_rme_sync_state_get,
2110 .private_value = SND_RME_DOMAIN_AES
2113 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2114 .name = "SPDIF Rate",
2115 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2116 .info = snd_rme_rate_info,
2117 .get = snd_rme_rate_get,
2118 .private_value = SND_RME_DOMAIN_SPDIF
2121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2122 .name = "SPDIF Sync",
2123 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2124 .info = snd_rme_sync_state_info,
2125 .get = snd_rme_sync_state_get,
2126 .private_value = SND_RME_DOMAIN_SPDIF
2129 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2130 .name = "SPDIF Interface",
2131 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2132 .info = snd_rme_spdif_if_info,
2133 .get = snd_rme_spdif_if_get,
2136 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2137 .name = "SPDIF Format",
2138 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2139 .info = snd_rme_spdif_format_info,
2140 .get = snd_rme_spdif_format_get,
2143 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2144 .name = "Sync Source",
2145 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2146 .info = snd_rme_sync_source_info,
2147 .get = snd_rme_sync_source_get
2150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151 .name = "System Rate",
2152 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2153 .info = snd_rme_rate_info,
2154 .get = snd_rme_rate_get,
2155 .private_value = SND_RME_DOMAIN_SYSTEM
2158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2159 .name = "Current Frequency",
2160 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2161 .info = snd_rme_rate_info,
2162 .get = snd_rme_current_freq_get
2166 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2168 int err, i;
2170 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2171 err = add_single_ctl_with_resume(mixer, 0,
2172 NULL,
2173 &snd_rme_controls[i],
2174 NULL);
2175 if (err < 0)
2176 return err;
2179 return 0;
2182 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2184 int err = 0;
2186 err = snd_usb_soundblaster_remote_init(mixer);
2187 if (err < 0)
2188 return err;
2190 switch (mixer->chip->usb_id) {
2191 /* Tascam US-16x08 */
2192 case USB_ID(0x0644, 0x8047):
2193 err = snd_us16x08_controls_create(mixer);
2194 break;
2195 case USB_ID(0x041e, 0x3020):
2196 case USB_ID(0x041e, 0x3040):
2197 case USB_ID(0x041e, 0x3042):
2198 case USB_ID(0x041e, 0x30df):
2199 case USB_ID(0x041e, 0x3048):
2200 err = snd_audigy2nx_controls_create(mixer);
2201 if (err < 0)
2202 break;
2203 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2204 mixer, snd_audigy2nx_proc_read);
2205 break;
2207 /* EMU0204 */
2208 case USB_ID(0x041e, 0x3f19):
2209 err = snd_emu0204_controls_create(mixer);
2210 break;
2212 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
2213 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
2214 err = snd_c400_create_mixer(mixer);
2215 break;
2217 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
2218 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
2219 err = snd_ftu_create_mixer(mixer);
2220 break;
2222 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
2223 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
2224 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
2225 err = snd_xonar_u1_controls_create(mixer);
2226 break;
2228 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
2229 err = snd_microii_controls_create(mixer);
2230 break;
2232 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
2233 err = snd_mbox1_create_sync_switch(mixer);
2234 break;
2236 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
2237 err = snd_nativeinstruments_create_mixer(mixer,
2238 snd_nativeinstruments_ta6_mixers,
2239 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2240 break;
2242 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
2243 err = snd_nativeinstruments_create_mixer(mixer,
2244 snd_nativeinstruments_ta10_mixers,
2245 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2246 break;
2248 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
2249 /* detection is disabled in mixer_maps.c */
2250 err = snd_create_std_mono_table(mixer, ebox44_table);
2251 break;
2253 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
2254 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
2255 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
2256 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
2257 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
2258 err = snd_scarlett_controls_create(mixer);
2259 break;
2261 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
2262 err = snd_soundblaster_e1_switch_create(mixer);
2263 break;
2264 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2265 err = dell_dock_mixer_init(mixer);
2266 break;
2268 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
2269 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
2270 case USB_ID(0x2a39, 0x3fd4): /* RME */
2271 err = snd_rme_controls_create(mixer);
2272 break;
2275 return err;
2278 #ifdef CONFIG_PM
2279 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2281 switch (mixer->chip->usb_id) {
2282 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
2283 dell_dock_mixer_init(mixer);
2284 break;
2287 #endif
2289 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2290 int unitid)
2292 if (!mixer->rc_cfg)
2293 return;
2294 /* unit ids specific to Extigy/Audigy 2 NX: */
2295 switch (unitid) {
2296 case 0: /* remote control */
2297 mixer->rc_urb->dev = mixer->chip->dev;
2298 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2299 break;
2300 case 4: /* digital in jack */
2301 case 7: /* line in jacks */
2302 case 19: /* speaker out jacks */
2303 case 20: /* headphones out jack */
2304 break;
2305 /* live24ext: 4 = line-in jack */
2306 case 3: /* hp-out jack (may actuate Mute) */
2307 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2308 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2309 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2310 break;
2311 default:
2312 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2313 break;
2317 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2318 struct usb_mixer_elem_info *cval,
2319 struct snd_kcontrol *kctl)
2321 /* Approximation using 10 ranges based on output measurement on hw v1.2.
2322 * This seems close to the cubic mapping e.g. alsamixer uses. */
2323 static const DECLARE_TLV_DB_RANGE(scale,
2324 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2325 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2326 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2327 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2328 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2329 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2330 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2331 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2332 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2333 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2336 if (cval->min == 0 && cval->max == 50) {
2337 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2338 kctl->tlv.p = scale;
2339 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2340 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2342 } else if (cval->min == 0 && cval->max <= 1000) {
2343 /* Some other clearly broken DragonFly variant.
2344 * At least a 0..53 variant (hw v1.0) exists.
2346 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2347 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2351 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2352 struct usb_mixer_elem_info *cval, int unitid,
2353 struct snd_kcontrol *kctl)
2355 switch (mixer->chip->usb_id) {
2356 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
2357 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2358 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2359 break;
2360 /* lowest playback value is muted on C-Media devices */
2361 case USB_ID(0x0d8c, 0x000c):
2362 case USB_ID(0x0d8c, 0x0014):
2363 if (strstr(kctl->id.name, "Playback"))
2364 cval->min_mute = 1;
2365 break;