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>
43 #include "mixer_quirks.h"
44 #include "mixer_scarlett.h"
47 extern struct snd_kcontrol_new
*snd_usb_feature_unit_ctl
;
49 struct std_mono_table
{
50 unsigned int unitid
, control
, cmask
;
53 snd_kcontrol_tlv_rw_t
*tlv_callback
;
56 /* This function allows for the creation of standard UAC controls.
57 * See the quirks for M-Audio FTUs or Ebox-44.
58 * If you don't want to set a TLV callback pass NULL.
60 * Since there doesn't seem to be a devices that needs a multichannel
61 * version, we keep it mono for simplicity.
63 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface
*mixer
,
70 snd_kcontrol_tlv_rw_t
*tlv_callback
)
72 struct usb_mixer_elem_info
*cval
;
73 struct snd_kcontrol
*kctl
;
75 cval
= kzalloc(sizeof(*cval
), GFP_KERNEL
);
79 snd_usb_mixer_elem_init_std(&cval
->head
, mixer
, unitid
);
80 cval
->val_type
= val_type
;
82 cval
->control
= control
;
84 cval
->idx_off
= idx_off
;
86 /* get_min_max() is called only for integer volumes later,
87 * so provide a short-cut for booleans */
95 kctl
= snd_ctl_new1(snd_usb_feature_unit_ctl
, cval
);
102 snprintf(kctl
->id
.name
, sizeof(kctl
->id
.name
), name
);
103 kctl
->private_free
= snd_usb_mixer_elem_free
;
107 kctl
->tlv
.c
= tlv_callback
;
108 kctl
->vd
[0].access
|=
109 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
110 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
112 /* Add control to mixer */
113 return snd_usb_mixer_add_control(&cval
->head
, kctl
);
116 static int snd_create_std_mono_ctl(struct usb_mixer_interface
*mixer
,
118 unsigned int control
,
122 snd_kcontrol_tlv_rw_t
*tlv_callback
)
124 return snd_create_std_mono_ctl_offset(mixer
, unitid
, control
, cmask
,
125 val_type
, 0 /* Offset */, name
, tlv_callback
);
129 * Create a set of standard UAC controls from a table
131 static int snd_create_std_mono_table(struct usb_mixer_interface
*mixer
,
132 struct std_mono_table
*t
)
136 while (t
->name
!= NULL
) {
137 err
= snd_create_std_mono_ctl(mixer
, t
->unitid
, t
->control
,
138 t
->cmask
, t
->val_type
, t
->name
, t
->tlv_callback
);
147 static int add_single_ctl_with_resume(struct usb_mixer_interface
*mixer
,
149 usb_mixer_elem_resume_func_t resume
,
150 const struct snd_kcontrol_new
*knew
,
151 struct usb_mixer_elem_list
**listp
)
153 struct usb_mixer_elem_list
*list
;
154 struct snd_kcontrol
*kctl
;
156 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
163 list
->resume
= resume
;
164 kctl
= snd_ctl_new1(knew
, list
);
169 kctl
->private_free
= snd_usb_mixer_elem_free
;
170 return snd_usb_mixer_add_control(list
, kctl
);
174 * Sound Blaster remote control configuration
176 * format of remote control data:
178 * Audigy 2 NX: 06 80 xx 00 00 00
179 * Live! 24-bit: 06 80 xx yy 22 83
181 static const struct rc_config
{
186 u8 min_packet_length
; /* minimum accepted length of the URB result */
190 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
191 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
192 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
193 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
194 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
195 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
198 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
200 struct usb_mixer_interface
*mixer
= urb
->context
;
201 const struct rc_config
*rc
= mixer
->rc_cfg
;
204 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
207 code
= mixer
->rc_buffer
[rc
->offset
];
209 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
211 /* the Mute button actually changes the mixer control */
212 if (code
== rc
->mute_code
)
213 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
214 mixer
->rc_code
= code
;
216 wake_up(&mixer
->rc_waitq
);
219 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
220 long count
, loff_t
*offset
)
222 struct usb_mixer_interface
*mixer
= hw
->private_data
;
226 if (count
!= 1 && count
!= 4)
228 err
= wait_event_interruptible(mixer
->rc_waitq
,
229 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
232 err
= put_user(rc_code
, buf
);
234 err
= put_user(rc_code
, (u32 __user
*)buf
);
236 return err
< 0 ? err
: count
;
239 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
242 struct usb_mixer_interface
*mixer
= hw
->private_data
;
244 poll_wait(file
, &mixer
->rc_waitq
, wait
);
245 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
248 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
250 struct snd_hwdep
*hwdep
;
253 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
254 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
256 if (i
>= ARRAY_SIZE(rc_configs
))
258 mixer
->rc_cfg
= &rc_configs
[i
];
260 len
= mixer
->rc_cfg
->packet_length
;
262 init_waitqueue_head(&mixer
->rc_waitq
);
263 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
266 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
267 "%s remote control", mixer
->chip
->card
->shortname
);
268 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
269 hwdep
->private_data
= mixer
;
270 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
271 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
272 hwdep
->exclusive
= 1;
274 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
277 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
278 if (!mixer
->rc_setup_packet
) {
279 usb_free_urb(mixer
->rc_urb
);
280 mixer
->rc_urb
= NULL
;
283 mixer
->rc_setup_packet
->bRequestType
=
284 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
285 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
286 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
287 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
288 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
289 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
290 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
291 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
292 snd_usb_soundblaster_remote_complete
, mixer
);
296 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
298 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
300 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 8;
304 static int snd_audigy2nx_led_update(struct usb_mixer_interface
*mixer
,
305 int value
, int index
)
307 struct snd_usb_audio
*chip
= mixer
->chip
;
310 down_read(&chip
->shutdown_rwsem
);
311 if (chip
->shutdown
) {
315 if (chip
->usb_id
== USB_ID(0x041e, 0x3042))
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
,
320 /* USB X-Fi S51 Pro */
321 if (chip
->usb_id
== USB_ID(0x041e, 0x30df))
322 err
= snd_usb_ctl_msg(chip
->dev
,
323 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
324 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
327 err
= snd_usb_ctl_msg(chip
->dev
,
328 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
329 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
330 value
, index
+ 2, NULL
, 0);
332 up_read(&chip
->shutdown_rwsem
);
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 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 down_read(&mixer
->chip
->shutdown_rwsem
);
444 if (mixer
->chip
->shutdown
)
447 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
448 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
449 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
450 USB_RECIP_INTERFACE
, 0,
451 jacks
[i
].unitid
<< 8, buf
, 3);
452 up_read(&mixer
->chip
->shutdown_rwsem
);
453 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
454 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
456 snd_iprintf(buffer
, "?\n");
461 static int snd_emu0204_ch_switch_info(struct snd_kcontrol
*kcontrol
,
462 struct snd_ctl_elem_info
*uinfo
)
464 static const char * const texts
[2] = {"1/2", "3/4"};
466 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
469 static int snd_emu0204_ch_switch_get(struct snd_kcontrol
*kcontrol
,
470 struct snd_ctl_elem_value
*ucontrol
)
472 ucontrol
->value
.enumerated
.item
[0] = kcontrol
->private_value
;
476 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface
*mixer
,
479 struct snd_usb_audio
*chip
= mixer
->chip
;
481 unsigned char buf
[2];
483 down_read(&chip
->shutdown_rwsem
);
484 if (mixer
->chip
->shutdown
) {
490 buf
[1] = value
? 0x02 : 0x01;
491 err
= snd_usb_ctl_msg(chip
->dev
,
492 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
493 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
494 0x0400, 0x0e00, buf
, 2);
496 up_read(&chip
->shutdown_rwsem
);
500 static int snd_emu0204_ch_switch_put(struct snd_kcontrol
*kcontrol
,
501 struct snd_ctl_elem_value
*ucontrol
)
503 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
504 struct usb_mixer_interface
*mixer
= list
->mixer
;
505 unsigned int value
= ucontrol
->value
.enumerated
.item
[0];
511 if (value
== kcontrol
->private_value
)
514 kcontrol
->private_value
= value
;
515 err
= snd_emu0204_ch_switch_update(mixer
, value
);
516 return err
< 0 ? err
: 1;
519 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list
*list
)
521 return snd_emu0204_ch_switch_update(list
->mixer
,
522 list
->kctl
->private_value
);
525 static struct snd_kcontrol_new snd_emu0204_control
= {
526 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
527 .name
= "Front Jack Channels",
528 .info
= snd_emu0204_ch_switch_info
,
529 .get
= snd_emu0204_ch_switch_get
,
530 .put
= snd_emu0204_ch_switch_put
,
534 static int snd_emu0204_controls_create(struct usb_mixer_interface
*mixer
)
536 return add_single_ctl_with_resume(mixer
, 0,
537 snd_emu0204_ch_switch_resume
,
538 &snd_emu0204_control
, NULL
);
541 /* ASUS Xonar U1 / U3 controls */
543 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
544 struct snd_ctl_elem_value
*ucontrol
)
546 ucontrol
->value
.integer
.value
[0] = !!(kcontrol
->private_value
& 0x02);
550 static int snd_xonar_u1_switch_update(struct usb_mixer_interface
*mixer
,
551 unsigned char status
)
553 struct snd_usb_audio
*chip
= mixer
->chip
;
556 down_read(&chip
->shutdown_rwsem
);
560 err
= snd_usb_ctl_msg(chip
->dev
,
561 usb_sndctrlpipe(chip
->dev
, 0), 0x08,
562 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
564 up_read(&chip
->shutdown_rwsem
);
568 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
569 struct snd_ctl_elem_value
*ucontrol
)
571 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
572 u8 old_status
, new_status
;
575 old_status
= kcontrol
->private_value
;
576 if (ucontrol
->value
.integer
.value
[0])
577 new_status
= old_status
| 0x02;
579 new_status
= old_status
& ~0x02;
580 if (new_status
== old_status
)
583 kcontrol
->private_value
= new_status
;
584 err
= snd_xonar_u1_switch_update(list
->mixer
, new_status
);
585 return err
< 0 ? err
: 1;
588 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list
*list
)
590 return snd_xonar_u1_switch_update(list
->mixer
,
591 list
->kctl
->private_value
);
594 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
595 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
596 .name
= "Digital Playback Switch",
597 .info
= snd_ctl_boolean_mono_info
,
598 .get
= snd_xonar_u1_switch_get
,
599 .put
= snd_xonar_u1_switch_put
,
600 .private_value
= 0x05,
603 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
605 return add_single_ctl_with_resume(mixer
, 0,
606 snd_xonar_u1_switch_resume
,
607 &snd_xonar_u1_output_switch
, NULL
);
610 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
612 static int snd_mbox1_switch_get(struct snd_kcontrol
*kctl
,
613 struct snd_ctl_elem_value
*ucontrol
)
615 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
;
619 static int snd_mbox1_switch_update(struct usb_mixer_interface
*mixer
, int val
)
621 struct snd_usb_audio
*chip
= mixer
->chip
;
623 unsigned char buff
[3];
625 down_read(&chip
->shutdown_rwsem
);
626 if (chip
->shutdown
) {
631 /* Prepare for magic command to toggle clock source */
632 err
= snd_usb_ctl_msg(chip
->dev
,
633 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
636 USB_RECIP_INTERFACE
, 0x00, 0x500, buff
, 1);
639 err
= snd_usb_ctl_msg(chip
->dev
,
640 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
643 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
647 /* 2 possibilities: Internal -> send sample rate
648 * S/PDIF sync -> send zeroes
649 * NB: Sample rate locked to 48kHz on purpose to
650 * prevent user from resetting the sample rate
651 * while S/PDIF sync is enabled and confusing
652 * this configuration.
659 buff
[0] = buff
[1] = buff
[2] = 0x00;
662 /* Send the magic command to toggle the clock source */
663 err
= snd_usb_ctl_msg(chip
->dev
,
664 usb_sndctrlpipe(chip
->dev
, 0), 0x1,
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, 0x81, buff
, 3);
676 err
= snd_usb_ctl_msg(chip
->dev
,
677 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
680 USB_RECIP_ENDPOINT
, 0x100, 0x2, buff
, 3);
685 up_read(&chip
->shutdown_rwsem
);
689 static int snd_mbox1_switch_put(struct snd_kcontrol
*kctl
,
690 struct snd_ctl_elem_value
*ucontrol
)
692 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
693 struct usb_mixer_interface
*mixer
= list
->mixer
;
695 bool cur_val
, new_val
;
697 cur_val
= kctl
->private_value
;
698 new_val
= ucontrol
->value
.enumerated
.item
[0];
699 if (cur_val
== new_val
)
702 kctl
->private_value
= new_val
;
703 err
= snd_mbox1_switch_update(mixer
, new_val
);
704 return err
< 0 ? err
: 1;
707 static int snd_mbox1_switch_info(struct snd_kcontrol
*kcontrol
,
708 struct snd_ctl_elem_info
*uinfo
)
710 static const char *const texts
[2] = {
715 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
718 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list
*list
)
720 return snd_mbox1_switch_update(list
->mixer
, list
->kctl
->private_value
);
723 static struct snd_kcontrol_new snd_mbox1_switch
= {
724 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
725 .name
= "Clock Source",
727 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
728 .info
= snd_mbox1_switch_info
,
729 .get
= snd_mbox1_switch_get
,
730 .put
= snd_mbox1_switch_put
,
734 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface
*mixer
)
736 return add_single_ctl_with_resume(mixer
, 0,
737 snd_mbox1_switch_resume
,
738 &snd_mbox1_switch
, NULL
);
741 /* Native Instruments device quirks */
743 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
745 static int snd_ni_control_init_val(struct usb_mixer_interface
*mixer
,
746 struct snd_kcontrol
*kctl
)
748 struct usb_device
*dev
= mixer
->chip
->dev
;
749 unsigned int pval
= kctl
->private_value
;
753 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
755 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
756 0, pval
& 0xffff, &value
, 1);
759 "unable to issue vendor read request (ret = %d)", err
);
763 kctl
->private_value
|= (value
<< 24);
767 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
768 struct snd_ctl_elem_value
*ucontrol
)
770 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 24;
774 static int snd_ni_update_cur_val(struct usb_mixer_elem_list
*list
)
776 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
777 unsigned int pval
= list
->kctl
->private_value
;
780 down_read(&chip
->shutdown_rwsem
);
784 err
= usb_control_msg(chip
->dev
, usb_sndctrlpipe(chip
->dev
, 0),
786 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
787 pval
>> 24, pval
& 0xffff, NULL
, 0, 1000);
788 up_read(&chip
->shutdown_rwsem
);
792 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
793 struct snd_ctl_elem_value
*ucontrol
)
795 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
796 u8 oldval
= (kcontrol
->private_value
>> 24) & 0xff;
797 u8 newval
= ucontrol
->value
.integer
.value
[0];
800 if (oldval
== newval
)
803 kcontrol
->private_value
&= ~(0xff << 24);
804 kcontrol
->private_value
|= newval
;
805 err
= snd_ni_update_cur_val(list
);
806 return err
< 0 ? err
: 1;
809 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
811 .name
= "Direct Thru Channel A",
812 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
815 .name
= "Direct Thru Channel B",
816 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
819 .name
= "Phono Input Channel A",
820 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
823 .name
= "Phono Input Channel B",
824 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
828 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
830 .name
= "Direct Thru Channel A",
831 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
834 .name
= "Direct Thru Channel B",
835 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
838 .name
= "Direct Thru Channel C",
839 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
842 .name
= "Direct Thru Channel D",
843 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
846 .name
= "Phono Input Channel A",
847 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
850 .name
= "Phono Input Channel B",
851 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
854 .name
= "Phono Input Channel C",
855 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
858 .name
= "Phono Input Channel D",
859 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
863 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
864 const struct snd_kcontrol_new
*kc
,
868 struct snd_kcontrol_new
template = {
869 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
870 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
871 .get
= snd_nativeinstruments_control_get
,
872 .put
= snd_nativeinstruments_control_put
,
873 .info
= snd_ctl_boolean_mono_info
,
876 for (i
= 0; i
< count
; i
++) {
877 struct usb_mixer_elem_list
*list
;
879 template.name
= kc
[i
].name
;
880 template.private_value
= kc
[i
].private_value
;
882 err
= add_single_ctl_with_resume(mixer
, 0,
883 snd_ni_update_cur_val
,
887 snd_ni_control_init_val(mixer
, list
->kctl
);
893 /* M-Audio FastTrack Ultra quirks */
894 /* FTU Effect switch (also used by C400/C600) */
895 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
896 struct snd_ctl_elem_info
*uinfo
)
898 static const char *const texts
[8] = {
899 "Room 1", "Room 2", "Room 3", "Hall 1",
900 "Hall 2", "Plate", "Delay", "Echo"
903 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
906 static int snd_ftu_eff_switch_init(struct usb_mixer_interface
*mixer
,
907 struct snd_kcontrol
*kctl
)
909 struct usb_device
*dev
= mixer
->chip
->dev
;
910 unsigned int pval
= kctl
->private_value
;
912 unsigned char value
[2];
917 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), UAC_GET_CUR
,
918 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
920 snd_usb_ctrl_intf(mixer
->chip
) | ((pval
& 0xff) << 8),
925 kctl
->private_value
|= value
[0] << 24;
929 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
930 struct snd_ctl_elem_value
*ucontrol
)
932 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
>> 24;
936 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list
*list
)
938 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
939 unsigned int pval
= list
->kctl
->private_value
;
940 unsigned char value
[2];
943 value
[0] = pval
>> 24;
946 down_read(&chip
->shutdown_rwsem
);
950 err
= snd_usb_ctl_msg(chip
->dev
,
951 usb_sndctrlpipe(chip
->dev
, 0),
953 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
955 snd_usb_ctrl_intf(chip
) | ((pval
& 0xff) << 8),
957 up_read(&chip
->shutdown_rwsem
);
961 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
962 struct snd_ctl_elem_value
*ucontrol
)
964 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
965 unsigned int pval
= list
->kctl
->private_value
;
966 int cur_val
, err
, new_val
;
968 cur_val
= pval
>> 24;
969 new_val
= ucontrol
->value
.enumerated
.item
[0];
970 if (cur_val
== new_val
)
973 kctl
->private_value
&= ~(0xff << 24);
974 kctl
->private_value
|= new_val
<< 24;
975 err
= snd_ftu_eff_switch_update(list
);
976 return err
< 0 ? err
: 1;
979 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
980 int validx
, int bUnitID
)
982 static struct snd_kcontrol_new
template = {
983 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
984 .name
= "Effect Program Switch",
986 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
987 .info
= snd_ftu_eff_switch_info
,
988 .get
= snd_ftu_eff_switch_get
,
989 .put
= snd_ftu_eff_switch_put
991 struct usb_mixer_elem_list
*list
;
994 err
= add_single_ctl_with_resume(mixer
, bUnitID
,
995 snd_ftu_eff_switch_update
,
999 list
->kctl
->private_value
= (validx
<< 8) | bUnitID
;
1000 snd_ftu_eff_switch_init(mixer
, list
->kctl
);
1004 /* Create volume controls for FTU devices*/
1005 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
1008 unsigned int control
, cmask
;
1011 const unsigned int id
= 5;
1012 const int val_type
= USB_MIXER_S16
;
1014 for (out
= 0; out
< 8; out
++) {
1016 for (in
= 0; in
< 8; in
++) {
1018 snprintf(name
, sizeof(name
),
1019 "AIn%d - Out%d Capture Volume",
1021 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1022 cmask
, val_type
, name
,
1023 &snd_usb_mixer_vol_tlv
);
1027 for (in
= 8; in
< 16; in
++) {
1029 snprintf(name
, sizeof(name
),
1030 "DIn%d - Out%d Playback Volume",
1032 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1033 cmask
, val_type
, name
,
1034 &snd_usb_mixer_vol_tlv
);
1043 /* This control needs a volume quirk, see mixer.c */
1044 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1046 static const char name
[] = "Effect Volume";
1047 const unsigned int id
= 6;
1048 const int val_type
= USB_MIXER_U8
;
1049 const unsigned int control
= 2;
1050 const unsigned int cmask
= 0;
1052 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1053 name
, snd_usb_mixer_vol_tlv
);
1056 /* This control needs a volume quirk, see mixer.c */
1057 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1059 static const char name
[] = "Effect Duration";
1060 const unsigned int id
= 6;
1061 const int val_type
= USB_MIXER_S16
;
1062 const unsigned int control
= 3;
1063 const unsigned int cmask
= 0;
1065 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1066 name
, snd_usb_mixer_vol_tlv
);
1069 /* This control needs a volume quirk, see mixer.c */
1070 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1072 static const char name
[] = "Effect Feedback Volume";
1073 const unsigned int id
= 6;
1074 const int val_type
= USB_MIXER_U8
;
1075 const unsigned int control
= 4;
1076 const unsigned int cmask
= 0;
1078 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1082 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
1088 const unsigned int id
= 7;
1089 const int val_type
= USB_MIXER_S16
;
1090 const unsigned int control
= 7;
1092 for (ch
= 0; ch
< 4; ++ch
) {
1094 snprintf(name
, sizeof(name
),
1095 "Effect Return %d Volume", ch
+ 1);
1096 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1097 cmask
, val_type
, name
,
1098 snd_usb_mixer_vol_tlv
);
1106 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
1112 const unsigned int id
= 5;
1113 const int val_type
= USB_MIXER_S16
;
1114 const unsigned int control
= 9;
1116 for (ch
= 0; ch
< 8; ++ch
) {
1118 snprintf(name
, sizeof(name
),
1119 "Effect Send AIn%d Volume", ch
+ 1);
1120 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1122 snd_usb_mixer_vol_tlv
);
1126 for (ch
= 8; ch
< 16; ++ch
) {
1128 snprintf(name
, sizeof(name
),
1129 "Effect Send DIn%d Volume", ch
- 7);
1130 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1132 snd_usb_mixer_vol_tlv
);
1139 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
1143 err
= snd_ftu_create_volume_ctls(mixer
);
1147 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
1151 err
= snd_ftu_create_effect_volume_ctl(mixer
);
1155 err
= snd_ftu_create_effect_duration_ctl(mixer
);
1159 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1163 err
= snd_ftu_create_effect_return_ctls(mixer
);
1167 err
= snd_ftu_create_effect_send_ctls(mixer
);
1174 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1175 unsigned char samplerate_id
)
1177 struct usb_mixer_interface
*mixer
;
1178 struct usb_mixer_elem_info
*cval
;
1179 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1181 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1182 cval
= (struct usb_mixer_elem_info
*)mixer
->id_elems
[unitid
];
1184 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1187 snd_usb_mixer_notify_id(mixer
, unitid
);
1193 /* M-Audio Fast Track C400/C600 */
1194 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1195 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1198 unsigned int cmask
, offset
;
1203 const unsigned int id
= 0x40;
1204 const int val_type
= USB_MIXER_S16
;
1205 const int control
= 1;
1207 switch (mixer
->chip
->usb_id
) {
1208 case USB_ID(0x0763, 0x2030):
1212 case USB_ID(0x0763, 0x2031):
1218 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1219 for (out
= 0; out
< num_outs
; out
++) {
1220 if (chan
< num_outs
) {
1221 snprintf(name
, sizeof(name
),
1222 "PCM%d-Out%d Playback Volume",
1225 snprintf(name
, sizeof(name
),
1226 "In%d-Out%d Playback Volume",
1227 chan
- num_outs
+ 1, out
+ 1);
1230 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1231 offset
= chan
* num_outs
;
1232 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1233 cmask
, val_type
, offset
, name
,
1234 &snd_usb_mixer_vol_tlv
);
1243 /* This control needs a volume quirk, see mixer.c */
1244 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1246 static const char name
[] = "Effect Volume";
1247 const unsigned int id
= 0x43;
1248 const int val_type
= USB_MIXER_U8
;
1249 const unsigned int control
= 3;
1250 const unsigned int cmask
= 0;
1252 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1253 name
, snd_usb_mixer_vol_tlv
);
1256 /* This control needs a volume quirk, see mixer.c */
1257 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1259 static const char name
[] = "Effect Duration";
1260 const unsigned int id
= 0x43;
1261 const int val_type
= USB_MIXER_S16
;
1262 const unsigned int control
= 4;
1263 const unsigned int cmask
= 0;
1265 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1266 name
, snd_usb_mixer_vol_tlv
);
1269 /* This control needs a volume quirk, see mixer.c */
1270 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1272 static const char name
[] = "Effect Feedback Volume";
1273 const unsigned int id
= 0x43;
1274 const int val_type
= USB_MIXER_U8
;
1275 const unsigned int control
= 5;
1276 const unsigned int cmask
= 0;
1278 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1282 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1290 const unsigned int id
= 0x42;
1291 const int val_type
= USB_MIXER_S16
;
1292 const int control
= 1;
1294 switch (mixer
->chip
->usb_id
) {
1295 case USB_ID(0x0763, 0x2030):
1299 case USB_ID(0x0763, 0x2031):
1305 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1306 if (chan
< num_outs
) {
1307 snprintf(name
, sizeof(name
),
1308 "Effect Send DOut%d",
1311 snprintf(name
, sizeof(name
),
1312 "Effect Send AIn%d",
1313 chan
- num_outs
+ 1);
1316 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1317 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1318 cmask
, val_type
, name
,
1319 &snd_usb_mixer_vol_tlv
);
1327 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1335 const unsigned int id
= 0x40;
1336 const int val_type
= USB_MIXER_S16
;
1337 const int control
= 1;
1339 switch (mixer
->chip
->usb_id
) {
1340 case USB_ID(0x0763, 0x2030):
1343 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1345 case USB_ID(0x0763, 0x2031):
1348 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1352 for (chan
= 0; chan
< num_outs
; chan
++) {
1353 snprintf(name
, sizeof(name
),
1357 cmask
= (chan
== 0) ? 0 :
1358 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1359 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1360 cmask
, val_type
, offset
, name
,
1361 &snd_usb_mixer_vol_tlv
);
1369 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1373 err
= snd_c400_create_vol_ctls(mixer
);
1377 err
= snd_c400_create_effect_vol_ctls(mixer
);
1381 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1385 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1389 err
= snd_c400_create_effect_volume_ctl(mixer
);
1393 err
= snd_c400_create_effect_duration_ctl(mixer
);
1397 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1405 * The mixer units for Ebox-44 are corrupt, and even where they
1406 * are valid they presents mono controls as L and R channels of
1407 * stereo. So we provide a good mixer here.
1409 static struct std_mono_table ebox44_table
[] = {
1414 .val_type
= USB_MIXER_INV_BOOLEAN
,
1415 .name
= "Headphone Playback Switch"
1421 .val_type
= USB_MIXER_S16
,
1422 .name
= "Headphone A Mix Playback Volume"
1428 .val_type
= USB_MIXER_S16
,
1429 .name
= "Headphone B Mix Playback Volume"
1436 .val_type
= USB_MIXER_INV_BOOLEAN
,
1437 .name
= "Output Playback Switch"
1443 .val_type
= USB_MIXER_S16
,
1444 .name
= "Output A Playback Volume"
1450 .val_type
= USB_MIXER_S16
,
1451 .name
= "Output B Playback Volume"
1458 .val_type
= USB_MIXER_INV_BOOLEAN
,
1459 .name
= "Input Capture Switch"
1465 .val_type
= USB_MIXER_S16
,
1466 .name
= "Input A Capture Volume"
1472 .val_type
= USB_MIXER_S16
,
1473 .name
= "Input B Capture Volume"
1479 /* Audio Advantage Micro II findings:
1481 * Mapping spdif AES bits to vendor register.bit:
1482 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1483 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1484 * AES2: [0 0 0 0 0 0 0 0]
1485 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1486 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1490 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1491 * just after it to 0xa0, presumably it disables/mutes some analog
1492 * parts when there is no audio.)
1495 * Optical transmitter on/off:
1496 * vendor register.bit: 9.1
1497 * 0 - on (0x28 register value)
1498 * 1 - off (0x2a register value)
1501 static int snd_microii_spdif_info(struct snd_kcontrol
*kcontrol
,
1502 struct snd_ctl_elem_info
*uinfo
)
1504 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1509 static int snd_microii_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1510 struct snd_ctl_elem_value
*ucontrol
)
1512 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1513 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1515 struct usb_interface
*iface
;
1516 struct usb_host_interface
*alts
;
1518 unsigned char data
[3];
1521 down_read(&chip
->shutdown_rwsem
);
1522 if (chip
->shutdown
) {
1527 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
& 0xff;
1528 ucontrol
->value
.iec958
.status
[1] = (kcontrol
->private_value
>> 8) & 0xff;
1529 ucontrol
->value
.iec958
.status
[2] = 0x00;
1531 /* use known values for that card: interface#1 altsetting#1 */
1532 iface
= usb_ifnum_to_if(chip
->dev
, 1);
1533 alts
= &iface
->altsetting
[1];
1534 ep
= get_endpoint(alts
, 0)->bEndpointAddress
;
1536 err
= snd_usb_ctl_msg(chip
->dev
,
1537 usb_rcvctrlpipe(chip
->dev
, 0),
1539 USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
1540 UAC_EP_CS_ATTR_SAMPLE_RATE
<< 8,
1547 rate
= data
[0] | (data
[1] << 8) | (data
[2] << 16);
1548 ucontrol
->value
.iec958
.status
[3] = (rate
== 48000) ?
1549 IEC958_AES3_CON_FS_48000
: IEC958_AES3_CON_FS_44100
;
1553 up_read(&chip
->shutdown_rwsem
);
1557 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list
*list
)
1559 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1560 unsigned int pval
= list
->kctl
->private_value
;
1564 down_read(&chip
->shutdown_rwsem
);
1565 if (chip
->shutdown
) {
1570 reg
= ((pval
>> 4) & 0xf0) | (pval
& 0x0f);
1571 err
= snd_usb_ctl_msg(chip
->dev
,
1572 usb_sndctrlpipe(chip
->dev
, 0),
1574 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1582 reg
= (pval
& IEC958_AES0_NONAUDIO
) ? 0xa0 : 0x20;
1583 reg
|= (pval
>> 12) & 0x0f;
1584 err
= snd_usb_ctl_msg(chip
->dev
,
1585 usb_sndctrlpipe(chip
->dev
, 0),
1587 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1596 up_read(&chip
->shutdown_rwsem
);
1600 static int snd_microii_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1601 struct snd_ctl_elem_value
*ucontrol
)
1603 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1604 unsigned int pval
, pval_old
;
1607 pval
= pval_old
= kcontrol
->private_value
;
1609 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0x0f) << 8;
1610 pval
|= (ucontrol
->value
.iec958
.status
[0] & 0x0f);
1613 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0xf0) << 8;
1615 /* The frequency bits in AES3 cannot be set via register access. */
1617 /* Silently ignore any bits from the request that cannot be set. */
1619 if (pval
== pval_old
)
1622 kcontrol
->private_value
= pval
;
1623 err
= snd_microii_spdif_default_update(list
);
1624 return err
< 0 ? err
: 1;
1627 static int snd_microii_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
1628 struct snd_ctl_elem_value
*ucontrol
)
1630 ucontrol
->value
.iec958
.status
[0] = 0x0f;
1631 ucontrol
->value
.iec958
.status
[1] = 0xff;
1632 ucontrol
->value
.iec958
.status
[2] = 0x00;
1633 ucontrol
->value
.iec958
.status
[3] = 0x00;
1638 static int snd_microii_spdif_switch_get(struct snd_kcontrol
*kcontrol
,
1639 struct snd_ctl_elem_value
*ucontrol
)
1641 ucontrol
->value
.integer
.value
[0] = !(kcontrol
->private_value
& 0x02);
1646 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list
*list
)
1648 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1649 u8 reg
= list
->kctl
->private_value
;
1652 down_read(&chip
->shutdown_rwsem
);
1653 if (chip
->shutdown
) {
1658 err
= snd_usb_ctl_msg(chip
->dev
,
1659 usb_sndctrlpipe(chip
->dev
, 0),
1661 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1668 up_read(&chip
->shutdown_rwsem
);
1672 static int snd_microii_spdif_switch_put(struct snd_kcontrol
*kcontrol
,
1673 struct snd_ctl_elem_value
*ucontrol
)
1675 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1679 reg
= ucontrol
->value
.integer
.value
[0] ? 0x28 : 0x2a;
1680 if (reg
!= list
->kctl
->private_value
)
1683 kcontrol
->private_value
= reg
;
1684 err
= snd_microii_spdif_switch_update(list
);
1685 return err
< 0 ? err
: 1;
1688 static struct snd_kcontrol_new snd_microii_mixer_spdif
[] = {
1690 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1691 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, DEFAULT
),
1692 .info
= snd_microii_spdif_info
,
1693 .get
= snd_microii_spdif_default_get
,
1694 .put
= snd_microii_spdif_default_put
,
1695 .private_value
= 0x00000100UL
,/* reset value */
1698 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1699 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1700 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, MASK
),
1701 .info
= snd_microii_spdif_info
,
1702 .get
= snd_microii_spdif_mask_get
,
1705 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1706 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, SWITCH
),
1707 .info
= snd_ctl_boolean_mono_info
,
1708 .get
= snd_microii_spdif_switch_get
,
1709 .put
= snd_microii_spdif_switch_put
,
1710 .private_value
= 0x00000028UL
,/* reset value */
1714 static int snd_microii_controls_create(struct usb_mixer_interface
*mixer
)
1717 static usb_mixer_elem_resume_func_t resume_funcs
[] = {
1718 snd_microii_spdif_default_update
,
1720 snd_microii_spdif_switch_update
1723 for (i
= 0; i
< ARRAY_SIZE(snd_microii_mixer_spdif
); ++i
) {
1724 err
= add_single_ctl_with_resume(mixer
, 0,
1726 &snd_microii_mixer_spdif
[i
],
1735 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1738 struct snd_info_entry
*entry
;
1740 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1743 switch (mixer
->chip
->usb_id
) {
1744 case USB_ID(0x041e, 0x3020):
1745 case USB_ID(0x041e, 0x3040):
1746 case USB_ID(0x041e, 0x3042):
1747 case USB_ID(0x041e, 0x30df):
1748 case USB_ID(0x041e, 0x3048):
1749 err
= snd_audigy2nx_controls_create(mixer
);
1752 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1753 snd_info_set_text_ops(entry
, mixer
,
1754 snd_audigy2nx_proc_read
);
1758 case USB_ID(0x041e, 0x3f19):
1759 err
= snd_emu0204_controls_create(mixer
);
1764 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1765 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1766 err
= snd_c400_create_mixer(mixer
);
1769 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1770 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1771 err
= snd_ftu_create_mixer(mixer
);
1774 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1775 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1776 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1777 err
= snd_xonar_u1_controls_create(mixer
);
1780 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1781 err
= snd_microii_controls_create(mixer
);
1784 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1785 err
= snd_mbox1_create_sync_switch(mixer
);
1788 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1789 err
= snd_nativeinstruments_create_mixer(mixer
,
1790 snd_nativeinstruments_ta6_mixers
,
1791 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1794 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1795 err
= snd_nativeinstruments_create_mixer(mixer
,
1796 snd_nativeinstruments_ta10_mixers
,
1797 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1800 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1801 /* detection is disabled in mixer_maps.c */
1802 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1805 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1806 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1807 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1808 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1809 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1810 err
= snd_scarlett_controls_create(mixer
);
1817 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1822 /* unit ids specific to Extigy/Audigy 2 NX: */
1824 case 0: /* remote control */
1825 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1826 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1828 case 4: /* digital in jack */
1829 case 7: /* line in jacks */
1830 case 19: /* speaker out jacks */
1831 case 20: /* headphones out jack */
1833 /* live24ext: 4 = line-in jack */
1834 case 3: /* hp-out jack (may actuate Mute) */
1835 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1836 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1837 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1840 usb_audio_dbg(mixer
->chip
, "memory change in unknown unit %d\n", unitid
);