2 * USB Audio Driver for ALSA
4 * Quirks and vendor-specific extensions for mixer interfaces
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
12 * Audio Advantage Micro II support added by:
13 * Przemek Rudy (prudy1@o2.pl)
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/usb.h>
33 #include <linux/usb/audio.h>
35 #include <sound/asoundef.h>
36 #include <sound/core.h>
37 #include <sound/control.h>
38 #include <sound/hwdep.h>
39 #include <sound/info.h>
40 #include <sound/tlv.h>
44 #include "mixer_quirks.h"
45 #include "mixer_scarlett.h"
48 extern struct snd_kcontrol_new
*snd_usb_feature_unit_ctl
;
50 struct std_mono_table
{
51 unsigned int unitid
, control
, cmask
;
54 snd_kcontrol_tlv_rw_t
*tlv_callback
;
57 /* This function allows for the creation of standard UAC controls.
58 * See the quirks for M-Audio FTUs or Ebox-44.
59 * If you don't want to set a TLV callback pass NULL.
61 * Since there doesn't seem to be a devices that needs a multichannel
62 * version, we keep it mono for simplicity.
64 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface
*mixer
,
71 snd_kcontrol_tlv_rw_t
*tlv_callback
)
73 struct usb_mixer_elem_info
*cval
;
74 struct snd_kcontrol
*kctl
;
76 cval
= kzalloc(sizeof(*cval
), GFP_KERNEL
);
80 snd_usb_mixer_elem_init_std(&cval
->head
, mixer
, unitid
);
81 cval
->val_type
= val_type
;
83 cval
->control
= control
;
85 cval
->idx_off
= idx_off
;
87 /* get_min_max() is called only for integer volumes later,
88 * so provide a short-cut for booleans */
96 kctl
= snd_ctl_new1(snd_usb_feature_unit_ctl
, cval
);
103 snprintf(kctl
->id
.name
, sizeof(kctl
->id
.name
), name
);
104 kctl
->private_free
= snd_usb_mixer_elem_free
;
108 kctl
->tlv
.c
= tlv_callback
;
109 kctl
->vd
[0].access
|=
110 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
111 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
113 /* Add control to mixer */
114 return snd_usb_mixer_add_control(&cval
->head
, kctl
);
117 static int snd_create_std_mono_ctl(struct usb_mixer_interface
*mixer
,
119 unsigned int control
,
123 snd_kcontrol_tlv_rw_t
*tlv_callback
)
125 return snd_create_std_mono_ctl_offset(mixer
, unitid
, control
, cmask
,
126 val_type
, 0 /* Offset */, name
, tlv_callback
);
130 * Create a set of standard UAC controls from a table
132 static int snd_create_std_mono_table(struct usb_mixer_interface
*mixer
,
133 struct std_mono_table
*t
)
137 while (t
->name
!= NULL
) {
138 err
= snd_create_std_mono_ctl(mixer
, t
->unitid
, t
->control
,
139 t
->cmask
, t
->val_type
, t
->name
, t
->tlv_callback
);
148 static int add_single_ctl_with_resume(struct usb_mixer_interface
*mixer
,
150 usb_mixer_elem_resume_func_t resume
,
151 const struct snd_kcontrol_new
*knew
,
152 struct usb_mixer_elem_list
**listp
)
154 struct usb_mixer_elem_list
*list
;
155 struct snd_kcontrol
*kctl
;
157 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
164 list
->resume
= resume
;
165 kctl
= snd_ctl_new1(knew
, list
);
170 kctl
->private_free
= snd_usb_mixer_elem_free
;
171 return snd_usb_mixer_add_control(list
, kctl
);
175 * Sound Blaster remote control configuration
177 * format of remote control data:
179 * Audigy 2 NX: 06 80 xx 00 00 00
180 * Live! 24-bit: 06 80 xx yy 22 83
182 static const struct rc_config
{
187 u8 min_packet_length
; /* minimum accepted length of the URB result */
191 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
192 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
193 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
194 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
195 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
196 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
197 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
200 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
202 struct usb_mixer_interface
*mixer
= urb
->context
;
203 const struct rc_config
*rc
= mixer
->rc_cfg
;
206 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
209 code
= mixer
->rc_buffer
[rc
->offset
];
211 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
213 /* the Mute button actually changes the mixer control */
214 if (code
== rc
->mute_code
)
215 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
216 mixer
->rc_code
= code
;
218 wake_up(&mixer
->rc_waitq
);
221 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
222 long count
, loff_t
*offset
)
224 struct usb_mixer_interface
*mixer
= hw
->private_data
;
228 if (count
!= 1 && count
!= 4)
230 err
= wait_event_interruptible(mixer
->rc_waitq
,
231 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
234 err
= put_user(rc_code
, buf
);
236 err
= put_user(rc_code
, (u32 __user
*)buf
);
238 return err
< 0 ? err
: count
;
241 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
244 struct usb_mixer_interface
*mixer
= hw
->private_data
;
246 poll_wait(file
, &mixer
->rc_waitq
, wait
);
247 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
250 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
252 struct snd_hwdep
*hwdep
;
255 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
256 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
258 if (i
>= ARRAY_SIZE(rc_configs
))
260 mixer
->rc_cfg
= &rc_configs
[i
];
262 len
= mixer
->rc_cfg
->packet_length
;
264 init_waitqueue_head(&mixer
->rc_waitq
);
265 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
268 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
269 "%s remote control", mixer
->chip
->card
->shortname
);
270 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
271 hwdep
->private_data
= mixer
;
272 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
273 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
274 hwdep
->exclusive
= 1;
276 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
279 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
280 if (!mixer
->rc_setup_packet
) {
281 usb_free_urb(mixer
->rc_urb
);
282 mixer
->rc_urb
= NULL
;
285 mixer
->rc_setup_packet
->bRequestType
=
286 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
287 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
288 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
289 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
290 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
291 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
292 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
293 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
294 snd_usb_soundblaster_remote_complete
, mixer
);
298 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
300 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
302 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 8;
306 static int snd_audigy2nx_led_update(struct usb_mixer_interface
*mixer
,
307 int value
, int index
)
309 struct snd_usb_audio
*chip
= mixer
->chip
;
312 err
= snd_usb_lock_shutdown(chip
);
316 if (chip
->usb_id
== USB_ID(0x041e, 0x3042))
317 err
= snd_usb_ctl_msg(chip
->dev
,
318 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
319 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
321 /* USB X-Fi S51 Pro */
322 if (chip
->usb_id
== USB_ID(0x041e, 0x30df))
323 err
= snd_usb_ctl_msg(chip
->dev
,
324 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
325 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
328 err
= snd_usb_ctl_msg(chip
->dev
,
329 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
330 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
331 value
, index
+ 2, NULL
, 0);
332 snd_usb_unlock_shutdown(chip
);
336 static int snd_audigy2nx_led_put(struct snd_kcontrol
*kcontrol
,
337 struct snd_ctl_elem_value
*ucontrol
)
339 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
340 struct usb_mixer_interface
*mixer
= list
->mixer
;
341 int index
= kcontrol
->private_value
& 0xff;
342 unsigned int value
= ucontrol
->value
.integer
.value
[0];
343 int old_value
= kcontrol
->private_value
>> 8;
348 if (value
== old_value
)
350 kcontrol
->private_value
= (value
<< 8) | index
;
351 err
= snd_audigy2nx_led_update(mixer
, value
, index
);
352 return err
< 0 ? err
: 1;
355 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list
*list
)
357 int priv_value
= list
->kctl
->private_value
;
359 return snd_audigy2nx_led_update(list
->mixer
, priv_value
>> 8,
363 /* name and private_value are set dynamically */
364 static struct snd_kcontrol_new snd_audigy2nx_control
= {
365 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
366 .info
= snd_audigy2nx_led_info
,
367 .get
= snd_audigy2nx_led_get
,
368 .put
= snd_audigy2nx_led_put
,
371 static const char * const snd_audigy2nx_led_names
[] = {
374 "Dolby Digital LED Switch",
377 static int snd_audigy2nx_controls_create(struct usb_mixer_interface
*mixer
)
381 for (i
= 0; i
< ARRAY_SIZE(snd_audigy2nx_led_names
); ++i
) {
382 struct snd_kcontrol_new knew
;
384 /* USB X-Fi S51 doesn't have a CMSS LED */
385 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042)) && i
== 0)
387 /* USB X-Fi S51 Pro doesn't have one either */
388 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df)) && i
== 0)
390 if (i
> 1 && /* Live24ext has 2 LEDs only */
391 (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
392 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042) ||
393 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df) ||
394 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048)))
397 knew
= snd_audigy2nx_control
;
398 knew
.name
= snd_audigy2nx_led_names
[i
];
399 knew
.private_value
= (1 << 8) | i
; /* LED on as default */
400 err
= add_single_ctl_with_resume(mixer
, 0,
401 snd_audigy2nx_led_resume
,
409 static void snd_audigy2nx_proc_read(struct snd_info_entry
*entry
,
410 struct snd_info_buffer
*buffer
)
412 static const struct sb_jack
{
415 } jacks_audigy2nx
[] = {
421 }, jacks_live24ext
[] = {
422 {4, "line in"}, /* &1=Line, &2=Mic*/
423 {3, "hph out"}, /* headphones */
424 {0, "RC "}, /* last command, 6 bytes see rc_config above */
427 const struct sb_jack
*jacks
;
428 struct usb_mixer_interface
*mixer
= entry
->private_data
;
432 snd_iprintf(buffer
, "%s jacks\n\n", mixer
->chip
->card
->shortname
);
433 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3020))
434 jacks
= jacks_audigy2nx
;
435 else if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
436 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
437 jacks
= jacks_live24ext
;
441 for (i
= 0; jacks
[i
].name
; ++i
) {
442 snd_iprintf(buffer
, "%s: ", jacks
[i
].name
);
443 err
= snd_usb_lock_shutdown(mixer
->chip
);
446 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
447 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
448 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
449 USB_RECIP_INTERFACE
, 0,
450 jacks
[i
].unitid
<< 8, buf
, 3);
451 snd_usb_unlock_shutdown(mixer
->chip
);
452 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
453 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
455 snd_iprintf(buffer
, "?\n");
460 static int snd_emu0204_ch_switch_info(struct snd_kcontrol
*kcontrol
,
461 struct snd_ctl_elem_info
*uinfo
)
463 static const char * const texts
[2] = {"1/2", "3/4"};
465 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
468 static int snd_emu0204_ch_switch_get(struct snd_kcontrol
*kcontrol
,
469 struct snd_ctl_elem_value
*ucontrol
)
471 ucontrol
->value
.enumerated
.item
[0] = kcontrol
->private_value
;
475 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface
*mixer
,
478 struct snd_usb_audio
*chip
= mixer
->chip
;
480 unsigned char buf
[2];
482 err
= snd_usb_lock_shutdown(chip
);
487 buf
[1] = value
? 0x02 : 0x01;
488 err
= snd_usb_ctl_msg(chip
->dev
,
489 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
490 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
491 0x0400, 0x0e00, buf
, 2);
492 snd_usb_unlock_shutdown(chip
);
496 static int snd_emu0204_ch_switch_put(struct snd_kcontrol
*kcontrol
,
497 struct snd_ctl_elem_value
*ucontrol
)
499 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
500 struct usb_mixer_interface
*mixer
= list
->mixer
;
501 unsigned int value
= ucontrol
->value
.enumerated
.item
[0];
507 if (value
== kcontrol
->private_value
)
510 kcontrol
->private_value
= value
;
511 err
= snd_emu0204_ch_switch_update(mixer
, value
);
512 return err
< 0 ? err
: 1;
515 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list
*list
)
517 return snd_emu0204_ch_switch_update(list
->mixer
,
518 list
->kctl
->private_value
);
521 static struct snd_kcontrol_new snd_emu0204_control
= {
522 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
523 .name
= "Front Jack Channels",
524 .info
= snd_emu0204_ch_switch_info
,
525 .get
= snd_emu0204_ch_switch_get
,
526 .put
= snd_emu0204_ch_switch_put
,
530 static int snd_emu0204_controls_create(struct usb_mixer_interface
*mixer
)
532 return add_single_ctl_with_resume(mixer
, 0,
533 snd_emu0204_ch_switch_resume
,
534 &snd_emu0204_control
, NULL
);
537 /* ASUS Xonar U1 / U3 controls */
539 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
540 struct snd_ctl_elem_value
*ucontrol
)
542 ucontrol
->value
.integer
.value
[0] = !!(kcontrol
->private_value
& 0x02);
546 static int snd_xonar_u1_switch_update(struct usb_mixer_interface
*mixer
,
547 unsigned char status
)
549 struct snd_usb_audio
*chip
= mixer
->chip
;
552 err
= snd_usb_lock_shutdown(chip
);
555 err
= snd_usb_ctl_msg(chip
->dev
,
556 usb_sndctrlpipe(chip
->dev
, 0), 0x08,
557 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
559 snd_usb_unlock_shutdown(chip
);
563 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
564 struct snd_ctl_elem_value
*ucontrol
)
566 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
567 u8 old_status
, new_status
;
570 old_status
= kcontrol
->private_value
;
571 if (ucontrol
->value
.integer
.value
[0])
572 new_status
= old_status
| 0x02;
574 new_status
= old_status
& ~0x02;
575 if (new_status
== old_status
)
578 kcontrol
->private_value
= new_status
;
579 err
= snd_xonar_u1_switch_update(list
->mixer
, new_status
);
580 return err
< 0 ? err
: 1;
583 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list
*list
)
585 return snd_xonar_u1_switch_update(list
->mixer
,
586 list
->kctl
->private_value
);
589 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
590 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
591 .name
= "Digital Playback Switch",
592 .info
= snd_ctl_boolean_mono_info
,
593 .get
= snd_xonar_u1_switch_get
,
594 .put
= snd_xonar_u1_switch_put
,
595 .private_value
= 0x05,
598 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
600 return add_single_ctl_with_resume(mixer
, 0,
601 snd_xonar_u1_switch_resume
,
602 &snd_xonar_u1_output_switch
, NULL
);
605 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
607 static int snd_mbox1_switch_get(struct snd_kcontrol
*kctl
,
608 struct snd_ctl_elem_value
*ucontrol
)
610 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
;
614 static int snd_mbox1_switch_update(struct usb_mixer_interface
*mixer
, int val
)
616 struct snd_usb_audio
*chip
= mixer
->chip
;
618 unsigned char buff
[3];
620 err
= snd_usb_lock_shutdown(chip
);
624 /* Prepare for magic command to toggle clock source */
625 err
= snd_usb_ctl_msg(chip
->dev
,
626 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
629 USB_RECIP_INTERFACE
, 0x00, 0x500, buff
, 1);
632 err
= snd_usb_ctl_msg(chip
->dev
,
633 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
636 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
640 /* 2 possibilities: Internal -> send sample rate
641 * S/PDIF sync -> send zeroes
642 * NB: Sample rate locked to 48kHz on purpose to
643 * prevent user from resetting the sample rate
644 * while S/PDIF sync is enabled and confusing
645 * this configuration.
652 buff
[0] = buff
[1] = buff
[2] = 0x00;
655 /* Send the magic command to toggle the clock source */
656 err
= snd_usb_ctl_msg(chip
->dev
,
657 usb_sndctrlpipe(chip
->dev
, 0), 0x1,
659 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
662 err
= snd_usb_ctl_msg(chip
->dev
,
663 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
666 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
669 err
= snd_usb_ctl_msg(chip
->dev
,
670 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
673 USB_RECIP_ENDPOINT
, 0x100, 0x2, buff
, 3);
678 snd_usb_unlock_shutdown(chip
);
682 static int snd_mbox1_switch_put(struct snd_kcontrol
*kctl
,
683 struct snd_ctl_elem_value
*ucontrol
)
685 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
686 struct usb_mixer_interface
*mixer
= list
->mixer
;
688 bool cur_val
, new_val
;
690 cur_val
= kctl
->private_value
;
691 new_val
= ucontrol
->value
.enumerated
.item
[0];
692 if (cur_val
== new_val
)
695 kctl
->private_value
= new_val
;
696 err
= snd_mbox1_switch_update(mixer
, new_val
);
697 return err
< 0 ? err
: 1;
700 static int snd_mbox1_switch_info(struct snd_kcontrol
*kcontrol
,
701 struct snd_ctl_elem_info
*uinfo
)
703 static const char *const texts
[2] = {
708 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
711 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list
*list
)
713 return snd_mbox1_switch_update(list
->mixer
, list
->kctl
->private_value
);
716 static struct snd_kcontrol_new snd_mbox1_switch
= {
717 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
718 .name
= "Clock Source",
720 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
721 .info
= snd_mbox1_switch_info
,
722 .get
= snd_mbox1_switch_get
,
723 .put
= snd_mbox1_switch_put
,
727 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface
*mixer
)
729 return add_single_ctl_with_resume(mixer
, 0,
730 snd_mbox1_switch_resume
,
731 &snd_mbox1_switch
, NULL
);
734 /* Native Instruments device quirks */
736 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
738 static int snd_ni_control_init_val(struct usb_mixer_interface
*mixer
,
739 struct snd_kcontrol
*kctl
)
741 struct usb_device
*dev
= mixer
->chip
->dev
;
742 unsigned int pval
= kctl
->private_value
;
746 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
748 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
749 0, pval
& 0xffff, &value
, 1);
752 "unable to issue vendor read request (ret = %d)", err
);
756 kctl
->private_value
|= (value
<< 24);
760 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
761 struct snd_ctl_elem_value
*ucontrol
)
763 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 24;
767 static int snd_ni_update_cur_val(struct usb_mixer_elem_list
*list
)
769 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
770 unsigned int pval
= list
->kctl
->private_value
;
773 err
= snd_usb_lock_shutdown(chip
);
776 err
= usb_control_msg(chip
->dev
, usb_sndctrlpipe(chip
->dev
, 0),
778 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
779 pval
>> 24, pval
& 0xffff, NULL
, 0, 1000);
780 snd_usb_unlock_shutdown(chip
);
784 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
785 struct snd_ctl_elem_value
*ucontrol
)
787 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
788 u8 oldval
= (kcontrol
->private_value
>> 24) & 0xff;
789 u8 newval
= ucontrol
->value
.integer
.value
[0];
792 if (oldval
== newval
)
795 kcontrol
->private_value
&= ~(0xff << 24);
796 kcontrol
->private_value
|= (unsigned int)newval
<< 24;
797 err
= snd_ni_update_cur_val(list
);
798 return err
< 0 ? err
: 1;
801 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
803 .name
= "Direct Thru Channel A",
804 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
807 .name
= "Direct Thru Channel B",
808 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
811 .name
= "Phono Input Channel A",
812 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
815 .name
= "Phono Input Channel B",
816 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
820 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
822 .name
= "Direct Thru Channel A",
823 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
826 .name
= "Direct Thru Channel B",
827 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
830 .name
= "Direct Thru Channel C",
831 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
834 .name
= "Direct Thru Channel D",
835 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
838 .name
= "Phono Input Channel A",
839 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
842 .name
= "Phono Input Channel B",
843 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
846 .name
= "Phono Input Channel C",
847 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
850 .name
= "Phono Input Channel D",
851 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
855 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
856 const struct snd_kcontrol_new
*kc
,
860 struct snd_kcontrol_new
template = {
861 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
862 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
863 .get
= snd_nativeinstruments_control_get
,
864 .put
= snd_nativeinstruments_control_put
,
865 .info
= snd_ctl_boolean_mono_info
,
868 for (i
= 0; i
< count
; i
++) {
869 struct usb_mixer_elem_list
*list
;
871 template.name
= kc
[i
].name
;
872 template.private_value
= kc
[i
].private_value
;
874 err
= add_single_ctl_with_resume(mixer
, 0,
875 snd_ni_update_cur_val
,
879 snd_ni_control_init_val(mixer
, list
->kctl
);
885 /* M-Audio FastTrack Ultra quirks */
886 /* FTU Effect switch (also used by C400/C600) */
887 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
888 struct snd_ctl_elem_info
*uinfo
)
890 static const char *const texts
[8] = {
891 "Room 1", "Room 2", "Room 3", "Hall 1",
892 "Hall 2", "Plate", "Delay", "Echo"
895 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
898 static int snd_ftu_eff_switch_init(struct usb_mixer_interface
*mixer
,
899 struct snd_kcontrol
*kctl
)
901 struct usb_device
*dev
= mixer
->chip
->dev
;
902 unsigned int pval
= kctl
->private_value
;
904 unsigned char value
[2];
909 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), UAC_GET_CUR
,
910 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
912 snd_usb_ctrl_intf(mixer
->chip
) | ((pval
& 0xff) << 8),
917 kctl
->private_value
|= value
[0] << 24;
921 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
922 struct snd_ctl_elem_value
*ucontrol
)
924 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
>> 24;
928 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list
*list
)
930 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
931 unsigned int pval
= list
->kctl
->private_value
;
932 unsigned char value
[2];
935 value
[0] = pval
>> 24;
938 err
= snd_usb_lock_shutdown(chip
);
941 err
= snd_usb_ctl_msg(chip
->dev
,
942 usb_sndctrlpipe(chip
->dev
, 0),
944 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
946 snd_usb_ctrl_intf(chip
) | ((pval
& 0xff) << 8),
948 snd_usb_unlock_shutdown(chip
);
952 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
953 struct snd_ctl_elem_value
*ucontrol
)
955 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
956 unsigned int pval
= list
->kctl
->private_value
;
957 int cur_val
, err
, new_val
;
959 cur_val
= pval
>> 24;
960 new_val
= ucontrol
->value
.enumerated
.item
[0];
961 if (cur_val
== new_val
)
964 kctl
->private_value
&= ~(0xff << 24);
965 kctl
->private_value
|= new_val
<< 24;
966 err
= snd_ftu_eff_switch_update(list
);
967 return err
< 0 ? err
: 1;
970 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
971 int validx
, int bUnitID
)
973 static struct snd_kcontrol_new
template = {
974 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
975 .name
= "Effect Program Switch",
977 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
978 .info
= snd_ftu_eff_switch_info
,
979 .get
= snd_ftu_eff_switch_get
,
980 .put
= snd_ftu_eff_switch_put
982 struct usb_mixer_elem_list
*list
;
985 err
= add_single_ctl_with_resume(mixer
, bUnitID
,
986 snd_ftu_eff_switch_update
,
990 list
->kctl
->private_value
= (validx
<< 8) | bUnitID
;
991 snd_ftu_eff_switch_init(mixer
, list
->kctl
);
995 /* Create volume controls for FTU devices*/
996 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
999 unsigned int control
, cmask
;
1002 const unsigned int id
= 5;
1003 const int val_type
= USB_MIXER_S16
;
1005 for (out
= 0; out
< 8; out
++) {
1007 for (in
= 0; in
< 8; in
++) {
1009 snprintf(name
, sizeof(name
),
1010 "AIn%d - Out%d Capture Volume",
1012 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1013 cmask
, val_type
, name
,
1014 &snd_usb_mixer_vol_tlv
);
1018 for (in
= 8; in
< 16; in
++) {
1020 snprintf(name
, sizeof(name
),
1021 "DIn%d - Out%d Playback Volume",
1023 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1024 cmask
, val_type
, name
,
1025 &snd_usb_mixer_vol_tlv
);
1034 /* This control needs a volume quirk, see mixer.c */
1035 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1037 static const char name
[] = "Effect Volume";
1038 const unsigned int id
= 6;
1039 const int val_type
= USB_MIXER_U8
;
1040 const unsigned int control
= 2;
1041 const unsigned int cmask
= 0;
1043 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1044 name
, snd_usb_mixer_vol_tlv
);
1047 /* This control needs a volume quirk, see mixer.c */
1048 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1050 static const char name
[] = "Effect Duration";
1051 const unsigned int id
= 6;
1052 const int val_type
= USB_MIXER_S16
;
1053 const unsigned int control
= 3;
1054 const unsigned int cmask
= 0;
1056 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1057 name
, snd_usb_mixer_vol_tlv
);
1060 /* This control needs a volume quirk, see mixer.c */
1061 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1063 static const char name
[] = "Effect Feedback Volume";
1064 const unsigned int id
= 6;
1065 const int val_type
= USB_MIXER_U8
;
1066 const unsigned int control
= 4;
1067 const unsigned int cmask
= 0;
1069 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1073 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
1079 const unsigned int id
= 7;
1080 const int val_type
= USB_MIXER_S16
;
1081 const unsigned int control
= 7;
1083 for (ch
= 0; ch
< 4; ++ch
) {
1085 snprintf(name
, sizeof(name
),
1086 "Effect Return %d Volume", ch
+ 1);
1087 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1088 cmask
, val_type
, name
,
1089 snd_usb_mixer_vol_tlv
);
1097 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
1103 const unsigned int id
= 5;
1104 const int val_type
= USB_MIXER_S16
;
1105 const unsigned int control
= 9;
1107 for (ch
= 0; ch
< 8; ++ch
) {
1109 snprintf(name
, sizeof(name
),
1110 "Effect Send AIn%d Volume", ch
+ 1);
1111 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1113 snd_usb_mixer_vol_tlv
);
1117 for (ch
= 8; ch
< 16; ++ch
) {
1119 snprintf(name
, sizeof(name
),
1120 "Effect Send DIn%d Volume", ch
- 7);
1121 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1123 snd_usb_mixer_vol_tlv
);
1130 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
1134 err
= snd_ftu_create_volume_ctls(mixer
);
1138 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
1142 err
= snd_ftu_create_effect_volume_ctl(mixer
);
1146 err
= snd_ftu_create_effect_duration_ctl(mixer
);
1150 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1154 err
= snd_ftu_create_effect_return_ctls(mixer
);
1158 err
= snd_ftu_create_effect_send_ctls(mixer
);
1165 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1166 unsigned char samplerate_id
)
1168 struct usb_mixer_interface
*mixer
;
1169 struct usb_mixer_elem_info
*cval
;
1170 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1172 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1173 cval
= (struct usb_mixer_elem_info
*)mixer
->id_elems
[unitid
];
1175 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1178 snd_usb_mixer_notify_id(mixer
, unitid
);
1184 /* M-Audio Fast Track C400/C600 */
1185 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1186 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1189 unsigned int cmask
, offset
;
1194 const unsigned int id
= 0x40;
1195 const int val_type
= USB_MIXER_S16
;
1196 const int control
= 1;
1198 switch (mixer
->chip
->usb_id
) {
1199 case USB_ID(0x0763, 0x2030):
1203 case USB_ID(0x0763, 0x2031):
1209 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1210 for (out
= 0; out
< num_outs
; out
++) {
1211 if (chan
< num_outs
) {
1212 snprintf(name
, sizeof(name
),
1213 "PCM%d-Out%d Playback Volume",
1216 snprintf(name
, sizeof(name
),
1217 "In%d-Out%d Playback Volume",
1218 chan
- num_outs
+ 1, out
+ 1);
1221 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1222 offset
= chan
* num_outs
;
1223 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1224 cmask
, val_type
, offset
, name
,
1225 &snd_usb_mixer_vol_tlv
);
1234 /* This control needs a volume quirk, see mixer.c */
1235 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1237 static const char name
[] = "Effect Volume";
1238 const unsigned int id
= 0x43;
1239 const int val_type
= USB_MIXER_U8
;
1240 const unsigned int control
= 3;
1241 const unsigned int cmask
= 0;
1243 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1244 name
, snd_usb_mixer_vol_tlv
);
1247 /* This control needs a volume quirk, see mixer.c */
1248 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1250 static const char name
[] = "Effect Duration";
1251 const unsigned int id
= 0x43;
1252 const int val_type
= USB_MIXER_S16
;
1253 const unsigned int control
= 4;
1254 const unsigned int cmask
= 0;
1256 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1257 name
, snd_usb_mixer_vol_tlv
);
1260 /* This control needs a volume quirk, see mixer.c */
1261 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1263 static const char name
[] = "Effect Feedback Volume";
1264 const unsigned int id
= 0x43;
1265 const int val_type
= USB_MIXER_U8
;
1266 const unsigned int control
= 5;
1267 const unsigned int cmask
= 0;
1269 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1273 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1281 const unsigned int id
= 0x42;
1282 const int val_type
= USB_MIXER_S16
;
1283 const int control
= 1;
1285 switch (mixer
->chip
->usb_id
) {
1286 case USB_ID(0x0763, 0x2030):
1290 case USB_ID(0x0763, 0x2031):
1296 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1297 if (chan
< num_outs
) {
1298 snprintf(name
, sizeof(name
),
1299 "Effect Send DOut%d",
1302 snprintf(name
, sizeof(name
),
1303 "Effect Send AIn%d",
1304 chan
- num_outs
+ 1);
1307 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1308 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1309 cmask
, val_type
, name
,
1310 &snd_usb_mixer_vol_tlv
);
1318 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1326 const unsigned int id
= 0x40;
1327 const int val_type
= USB_MIXER_S16
;
1328 const int control
= 1;
1330 switch (mixer
->chip
->usb_id
) {
1331 case USB_ID(0x0763, 0x2030):
1334 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1336 case USB_ID(0x0763, 0x2031):
1339 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1343 for (chan
= 0; chan
< num_outs
; chan
++) {
1344 snprintf(name
, sizeof(name
),
1348 cmask
= (chan
== 0) ? 0 :
1349 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1350 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1351 cmask
, val_type
, offset
, name
,
1352 &snd_usb_mixer_vol_tlv
);
1360 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1364 err
= snd_c400_create_vol_ctls(mixer
);
1368 err
= snd_c400_create_effect_vol_ctls(mixer
);
1372 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1376 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1380 err
= snd_c400_create_effect_volume_ctl(mixer
);
1384 err
= snd_c400_create_effect_duration_ctl(mixer
);
1388 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1396 * The mixer units for Ebox-44 are corrupt, and even where they
1397 * are valid they presents mono controls as L and R channels of
1398 * stereo. So we provide a good mixer here.
1400 static struct std_mono_table ebox44_table
[] = {
1405 .val_type
= USB_MIXER_INV_BOOLEAN
,
1406 .name
= "Headphone Playback Switch"
1412 .val_type
= USB_MIXER_S16
,
1413 .name
= "Headphone A Mix Playback Volume"
1419 .val_type
= USB_MIXER_S16
,
1420 .name
= "Headphone B Mix Playback Volume"
1427 .val_type
= USB_MIXER_INV_BOOLEAN
,
1428 .name
= "Output Playback Switch"
1434 .val_type
= USB_MIXER_S16
,
1435 .name
= "Output A Playback Volume"
1441 .val_type
= USB_MIXER_S16
,
1442 .name
= "Output B Playback Volume"
1449 .val_type
= USB_MIXER_INV_BOOLEAN
,
1450 .name
= "Input Capture Switch"
1456 .val_type
= USB_MIXER_S16
,
1457 .name
= "Input A Capture Volume"
1463 .val_type
= USB_MIXER_S16
,
1464 .name
= "Input B Capture Volume"
1470 /* Audio Advantage Micro II findings:
1472 * Mapping spdif AES bits to vendor register.bit:
1473 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1474 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1475 * AES2: [0 0 0 0 0 0 0 0]
1476 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1477 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1481 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1482 * just after it to 0xa0, presumably it disables/mutes some analog
1483 * parts when there is no audio.)
1486 * Optical transmitter on/off:
1487 * vendor register.bit: 9.1
1488 * 0 - on (0x28 register value)
1489 * 1 - off (0x2a register value)
1492 static int snd_microii_spdif_info(struct snd_kcontrol
*kcontrol
,
1493 struct snd_ctl_elem_info
*uinfo
)
1495 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1500 static int snd_microii_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1501 struct snd_ctl_elem_value
*ucontrol
)
1503 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1504 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1506 struct usb_interface
*iface
;
1507 struct usb_host_interface
*alts
;
1509 unsigned char data
[3];
1512 err
= snd_usb_lock_shutdown(chip
);
1516 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
& 0xff;
1517 ucontrol
->value
.iec958
.status
[1] = (kcontrol
->private_value
>> 8) & 0xff;
1518 ucontrol
->value
.iec958
.status
[2] = 0x00;
1520 /* use known values for that card: interface#1 altsetting#1 */
1521 iface
= usb_ifnum_to_if(chip
->dev
, 1);
1522 if (!iface
|| iface
->num_altsetting
< 2)
1524 alts
= &iface
->altsetting
[1];
1525 if (get_iface_desc(alts
)->bNumEndpoints
< 1)
1527 ep
= get_endpoint(alts
, 0)->bEndpointAddress
;
1529 err
= snd_usb_ctl_msg(chip
->dev
,
1530 usb_rcvctrlpipe(chip
->dev
, 0),
1532 USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
1533 UAC_EP_CS_ATTR_SAMPLE_RATE
<< 8,
1540 rate
= data
[0] | (data
[1] << 8) | (data
[2] << 16);
1541 ucontrol
->value
.iec958
.status
[3] = (rate
== 48000) ?
1542 IEC958_AES3_CON_FS_48000
: IEC958_AES3_CON_FS_44100
;
1546 snd_usb_unlock_shutdown(chip
);
1550 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list
*list
)
1552 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1553 unsigned int pval
= list
->kctl
->private_value
;
1557 err
= snd_usb_lock_shutdown(chip
);
1561 reg
= ((pval
>> 4) & 0xf0) | (pval
& 0x0f);
1562 err
= snd_usb_ctl_msg(chip
->dev
,
1563 usb_sndctrlpipe(chip
->dev
, 0),
1565 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1573 reg
= (pval
& IEC958_AES0_NONAUDIO
) ? 0xa0 : 0x20;
1574 reg
|= (pval
>> 12) & 0x0f;
1575 err
= snd_usb_ctl_msg(chip
->dev
,
1576 usb_sndctrlpipe(chip
->dev
, 0),
1578 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1587 snd_usb_unlock_shutdown(chip
);
1591 static int snd_microii_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1592 struct snd_ctl_elem_value
*ucontrol
)
1594 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1595 unsigned int pval
, pval_old
;
1598 pval
= pval_old
= kcontrol
->private_value
;
1600 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0x0f) << 8;
1601 pval
|= (ucontrol
->value
.iec958
.status
[0] & 0x0f);
1604 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0xf0) << 8;
1606 /* The frequency bits in AES3 cannot be set via register access. */
1608 /* Silently ignore any bits from the request that cannot be set. */
1610 if (pval
== pval_old
)
1613 kcontrol
->private_value
= pval
;
1614 err
= snd_microii_spdif_default_update(list
);
1615 return err
< 0 ? err
: 1;
1618 static int snd_microii_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
1619 struct snd_ctl_elem_value
*ucontrol
)
1621 ucontrol
->value
.iec958
.status
[0] = 0x0f;
1622 ucontrol
->value
.iec958
.status
[1] = 0xff;
1623 ucontrol
->value
.iec958
.status
[2] = 0x00;
1624 ucontrol
->value
.iec958
.status
[3] = 0x00;
1629 static int snd_microii_spdif_switch_get(struct snd_kcontrol
*kcontrol
,
1630 struct snd_ctl_elem_value
*ucontrol
)
1632 ucontrol
->value
.integer
.value
[0] = !(kcontrol
->private_value
& 0x02);
1637 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list
*list
)
1639 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1640 u8 reg
= list
->kctl
->private_value
;
1643 err
= snd_usb_lock_shutdown(chip
);
1647 err
= snd_usb_ctl_msg(chip
->dev
,
1648 usb_sndctrlpipe(chip
->dev
, 0),
1650 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1656 snd_usb_unlock_shutdown(chip
);
1660 static int snd_microii_spdif_switch_put(struct snd_kcontrol
*kcontrol
,
1661 struct snd_ctl_elem_value
*ucontrol
)
1663 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1667 reg
= ucontrol
->value
.integer
.value
[0] ? 0x28 : 0x2a;
1668 if (reg
!= list
->kctl
->private_value
)
1671 kcontrol
->private_value
= reg
;
1672 err
= snd_microii_spdif_switch_update(list
);
1673 return err
< 0 ? err
: 1;
1676 static struct snd_kcontrol_new snd_microii_mixer_spdif
[] = {
1678 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1679 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, DEFAULT
),
1680 .info
= snd_microii_spdif_info
,
1681 .get
= snd_microii_spdif_default_get
,
1682 .put
= snd_microii_spdif_default_put
,
1683 .private_value
= 0x00000100UL
,/* reset value */
1686 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1687 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1688 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, MASK
),
1689 .info
= snd_microii_spdif_info
,
1690 .get
= snd_microii_spdif_mask_get
,
1693 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1694 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, SWITCH
),
1695 .info
= snd_ctl_boolean_mono_info
,
1696 .get
= snd_microii_spdif_switch_get
,
1697 .put
= snd_microii_spdif_switch_put
,
1698 .private_value
= 0x00000028UL
,/* reset value */
1702 static int snd_microii_controls_create(struct usb_mixer_interface
*mixer
)
1705 static usb_mixer_elem_resume_func_t resume_funcs
[] = {
1706 snd_microii_spdif_default_update
,
1708 snd_microii_spdif_switch_update
1711 for (i
= 0; i
< ARRAY_SIZE(snd_microii_mixer_spdif
); ++i
) {
1712 err
= add_single_ctl_with_resume(mixer
, 0,
1714 &snd_microii_mixer_spdif
[i
],
1723 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1726 struct snd_info_entry
*entry
;
1728 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1731 switch (mixer
->chip
->usb_id
) {
1732 case USB_ID(0x041e, 0x3020):
1733 case USB_ID(0x041e, 0x3040):
1734 case USB_ID(0x041e, 0x3042):
1735 case USB_ID(0x041e, 0x30df):
1736 case USB_ID(0x041e, 0x3048):
1737 err
= snd_audigy2nx_controls_create(mixer
);
1740 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1741 snd_info_set_text_ops(entry
, mixer
,
1742 snd_audigy2nx_proc_read
);
1746 case USB_ID(0x041e, 0x3f19):
1747 err
= snd_emu0204_controls_create(mixer
);
1752 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1753 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1754 err
= snd_c400_create_mixer(mixer
);
1757 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1758 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1759 err
= snd_ftu_create_mixer(mixer
);
1762 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1763 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1764 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1765 err
= snd_xonar_u1_controls_create(mixer
);
1768 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1769 err
= snd_microii_controls_create(mixer
);
1772 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1773 err
= snd_mbox1_create_sync_switch(mixer
);
1776 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1777 err
= snd_nativeinstruments_create_mixer(mixer
,
1778 snd_nativeinstruments_ta6_mixers
,
1779 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1782 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1783 err
= snd_nativeinstruments_create_mixer(mixer
,
1784 snd_nativeinstruments_ta10_mixers
,
1785 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1788 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1789 /* detection is disabled in mixer_maps.c */
1790 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1793 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1794 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1795 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1796 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1797 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1798 err
= snd_scarlett_controls_create(mixer
);
1805 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1810 /* unit ids specific to Extigy/Audigy 2 NX: */
1812 case 0: /* remote control */
1813 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1814 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1816 case 4: /* digital in jack */
1817 case 7: /* line in jacks */
1818 case 19: /* speaker out jacks */
1819 case 20: /* headphones out jack */
1821 /* live24ext: 4 = line-in jack */
1822 case 3: /* hp-out jack (may actuate Mute) */
1823 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1824 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1825 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1828 usb_audio_dbg(mixer
->chip
, "memory change in unknown unit %d\n", unitid
);
1833 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface
*mixer
,
1834 struct snd_kcontrol
*kctl
)
1836 /* Approximation using 10 ranges based on output measurement on hw v1.2.
1837 * This seems close to the cubic mapping e.g. alsamixer uses. */
1838 static const DECLARE_TLV_DB_RANGE(scale
,
1839 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
1840 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
1841 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
1842 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
1843 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
1844 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
1845 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
1846 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
1847 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
1848 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
1851 usb_audio_info(mixer
->chip
, "applying DragonFly dB scale quirk\n");
1852 kctl
->tlv
.p
= scale
;
1853 kctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1854 kctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
1857 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface
*mixer
,
1858 struct usb_mixer_elem_info
*cval
, int unitid
,
1859 struct snd_kcontrol
*kctl
)
1861 switch (mixer
->chip
->usb_id
) {
1862 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
1863 if (unitid
== 7 && cval
->min
== 0 && cval
->max
== 50)
1864 snd_dragonfly_quirk_db_scale(mixer
, kctl
);