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"
46 #include "mixer_us16x08.h"
49 extern struct snd_kcontrol_new
*snd_usb_feature_unit_ctl
;
51 struct std_mono_table
{
52 unsigned int unitid
, control
, cmask
;
55 snd_kcontrol_tlv_rw_t
*tlv_callback
;
58 /* This function allows for the creation of standard UAC controls.
59 * See the quirks for M-Audio FTUs or Ebox-44.
60 * If you don't want to set a TLV callback pass NULL.
62 * Since there doesn't seem to be a devices that needs a multichannel
63 * version, we keep it mono for simplicity.
65 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface
*mixer
,
72 snd_kcontrol_tlv_rw_t
*tlv_callback
)
74 struct usb_mixer_elem_info
*cval
;
75 struct snd_kcontrol
*kctl
;
77 cval
= kzalloc(sizeof(*cval
), GFP_KERNEL
);
81 snd_usb_mixer_elem_init_std(&cval
->head
, mixer
, unitid
);
82 cval
->val_type
= val_type
;
84 cval
->control
= control
;
86 cval
->idx_off
= idx_off
;
88 /* get_min_max() is called only for integer volumes later,
89 * so provide a short-cut for booleans */
97 kctl
= snd_ctl_new1(snd_usb_feature_unit_ctl
, cval
);
104 snprintf(kctl
->id
.name
, sizeof(kctl
->id
.name
), name
);
105 kctl
->private_free
= snd_usb_mixer_elem_free
;
109 kctl
->tlv
.c
= tlv_callback
;
110 kctl
->vd
[0].access
|=
111 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
112 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
114 /* Add control to mixer */
115 return snd_usb_mixer_add_control(&cval
->head
, kctl
);
118 static int snd_create_std_mono_ctl(struct usb_mixer_interface
*mixer
,
120 unsigned int control
,
124 snd_kcontrol_tlv_rw_t
*tlv_callback
)
126 return snd_create_std_mono_ctl_offset(mixer
, unitid
, control
, cmask
,
127 val_type
, 0 /* Offset */, name
, tlv_callback
);
131 * Create a set of standard UAC controls from a table
133 static int snd_create_std_mono_table(struct usb_mixer_interface
*mixer
,
134 struct std_mono_table
*t
)
138 while (t
->name
!= NULL
) {
139 err
= snd_create_std_mono_ctl(mixer
, t
->unitid
, t
->control
,
140 t
->cmask
, t
->val_type
, t
->name
, t
->tlv_callback
);
149 static int add_single_ctl_with_resume(struct usb_mixer_interface
*mixer
,
151 usb_mixer_elem_resume_func_t resume
,
152 const struct snd_kcontrol_new
*knew
,
153 struct usb_mixer_elem_list
**listp
)
155 struct usb_mixer_elem_list
*list
;
156 struct snd_kcontrol
*kctl
;
158 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
165 list
->resume
= resume
;
166 kctl
= snd_ctl_new1(knew
, list
);
171 kctl
->private_free
= snd_usb_mixer_elem_free
;
172 return snd_usb_mixer_add_control(list
, kctl
);
176 * Sound Blaster remote control configuration
178 * format of remote control data:
180 * Audigy 2 NX: 06 80 xx 00 00 00
181 * Live! 24-bit: 06 80 xx yy 22 83
183 static const struct rc_config
{
188 u8 min_packet_length
; /* minimum accepted length of the URB result */
192 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
193 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
194 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
195 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
196 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
197 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
198 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
201 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
203 struct usb_mixer_interface
*mixer
= urb
->context
;
204 const struct rc_config
*rc
= mixer
->rc_cfg
;
207 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
210 code
= mixer
->rc_buffer
[rc
->offset
];
212 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
214 /* the Mute button actually changes the mixer control */
215 if (code
== rc
->mute_code
)
216 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
217 mixer
->rc_code
= code
;
219 wake_up(&mixer
->rc_waitq
);
222 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
223 long count
, loff_t
*offset
)
225 struct usb_mixer_interface
*mixer
= hw
->private_data
;
229 if (count
!= 1 && count
!= 4)
231 err
= wait_event_interruptible(mixer
->rc_waitq
,
232 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
235 err
= put_user(rc_code
, buf
);
237 err
= put_user(rc_code
, (u32 __user
*)buf
);
239 return err
< 0 ? err
: count
;
242 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
245 struct usb_mixer_interface
*mixer
= hw
->private_data
;
247 poll_wait(file
, &mixer
->rc_waitq
, wait
);
248 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
251 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
253 struct snd_hwdep
*hwdep
;
256 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
257 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
259 if (i
>= ARRAY_SIZE(rc_configs
))
261 mixer
->rc_cfg
= &rc_configs
[i
];
263 len
= mixer
->rc_cfg
->packet_length
;
265 init_waitqueue_head(&mixer
->rc_waitq
);
266 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
269 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
270 "%s remote control", mixer
->chip
->card
->shortname
);
271 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
272 hwdep
->private_data
= mixer
;
273 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
274 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
275 hwdep
->exclusive
= 1;
277 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
280 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
281 if (!mixer
->rc_setup_packet
) {
282 usb_free_urb(mixer
->rc_urb
);
283 mixer
->rc_urb
= NULL
;
286 mixer
->rc_setup_packet
->bRequestType
=
287 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
288 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
289 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
290 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
291 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
292 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
293 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
294 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
295 snd_usb_soundblaster_remote_complete
, mixer
);
299 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
301 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
303 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 8;
307 static int snd_audigy2nx_led_update(struct usb_mixer_interface
*mixer
,
308 int value
, int index
)
310 struct snd_usb_audio
*chip
= mixer
->chip
;
313 err
= snd_usb_lock_shutdown(chip
);
317 if (chip
->usb_id
== USB_ID(0x041e, 0x3042))
318 err
= snd_usb_ctl_msg(chip
->dev
,
319 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
320 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
322 /* USB X-Fi S51 Pro */
323 if (chip
->usb_id
== USB_ID(0x041e, 0x30df))
324 err
= snd_usb_ctl_msg(chip
->dev
,
325 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
326 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
329 err
= snd_usb_ctl_msg(chip
->dev
,
330 usb_sndctrlpipe(chip
->dev
, 0), 0x24,
331 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
332 value
, index
+ 2, NULL
, 0);
333 snd_usb_unlock_shutdown(chip
);
337 static int snd_audigy2nx_led_put(struct snd_kcontrol
*kcontrol
,
338 struct snd_ctl_elem_value
*ucontrol
)
340 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
341 struct usb_mixer_interface
*mixer
= list
->mixer
;
342 int index
= kcontrol
->private_value
& 0xff;
343 unsigned int value
= ucontrol
->value
.integer
.value
[0];
344 int old_value
= kcontrol
->private_value
>> 8;
349 if (value
== old_value
)
351 kcontrol
->private_value
= (value
<< 8) | index
;
352 err
= snd_audigy2nx_led_update(mixer
, value
, index
);
353 return err
< 0 ? err
: 1;
356 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list
*list
)
358 int priv_value
= list
->kctl
->private_value
;
360 return snd_audigy2nx_led_update(list
->mixer
, priv_value
>> 8,
364 /* name and private_value are set dynamically */
365 static const struct snd_kcontrol_new snd_audigy2nx_control
= {
366 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
367 .info
= snd_audigy2nx_led_info
,
368 .get
= snd_audigy2nx_led_get
,
369 .put
= snd_audigy2nx_led_put
,
372 static const char * const snd_audigy2nx_led_names
[] = {
375 "Dolby Digital LED Switch",
378 static int snd_audigy2nx_controls_create(struct usb_mixer_interface
*mixer
)
382 for (i
= 0; i
< ARRAY_SIZE(snd_audigy2nx_led_names
); ++i
) {
383 struct snd_kcontrol_new knew
;
385 /* USB X-Fi S51 doesn't have a CMSS LED */
386 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042)) && i
== 0)
388 /* USB X-Fi S51 Pro doesn't have one either */
389 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df)) && i
== 0)
391 if (i
> 1 && /* Live24ext has 2 LEDs only */
392 (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
393 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042) ||
394 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df) ||
395 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048)))
398 knew
= snd_audigy2nx_control
;
399 knew
.name
= snd_audigy2nx_led_names
[i
];
400 knew
.private_value
= (1 << 8) | i
; /* LED on as default */
401 err
= add_single_ctl_with_resume(mixer
, 0,
402 snd_audigy2nx_led_resume
,
410 static void snd_audigy2nx_proc_read(struct snd_info_entry
*entry
,
411 struct snd_info_buffer
*buffer
)
413 static const struct sb_jack
{
416 } jacks_audigy2nx
[] = {
422 }, jacks_live24ext
[] = {
423 {4, "line in"}, /* &1=Line, &2=Mic*/
424 {3, "hph out"}, /* headphones */
425 {0, "RC "}, /* last command, 6 bytes see rc_config above */
428 const struct sb_jack
*jacks
;
429 struct usb_mixer_interface
*mixer
= entry
->private_data
;
433 snd_iprintf(buffer
, "%s jacks\n\n", mixer
->chip
->card
->shortname
);
434 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3020))
435 jacks
= jacks_audigy2nx
;
436 else if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
437 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
438 jacks
= jacks_live24ext
;
442 for (i
= 0; jacks
[i
].name
; ++i
) {
443 snd_iprintf(buffer
, "%s: ", jacks
[i
].name
);
444 err
= snd_usb_lock_shutdown(mixer
->chip
);
447 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
448 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
449 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
450 USB_RECIP_INTERFACE
, 0,
451 jacks
[i
].unitid
<< 8, buf
, 3);
452 snd_usb_unlock_shutdown(mixer
->chip
);
453 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
454 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
456 snd_iprintf(buffer
, "?\n");
461 static int snd_emu0204_ch_switch_info(struct snd_kcontrol
*kcontrol
,
462 struct snd_ctl_elem_info
*uinfo
)
464 static const char * const texts
[2] = {"1/2", "3/4"};
466 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
469 static int snd_emu0204_ch_switch_get(struct snd_kcontrol
*kcontrol
,
470 struct snd_ctl_elem_value
*ucontrol
)
472 ucontrol
->value
.enumerated
.item
[0] = kcontrol
->private_value
;
476 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface
*mixer
,
479 struct snd_usb_audio
*chip
= mixer
->chip
;
481 unsigned char buf
[2];
483 err
= snd_usb_lock_shutdown(chip
);
488 buf
[1] = value
? 0x02 : 0x01;
489 err
= snd_usb_ctl_msg(chip
->dev
,
490 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
491 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
492 0x0400, 0x0e00, buf
, 2);
493 snd_usb_unlock_shutdown(chip
);
497 static int snd_emu0204_ch_switch_put(struct snd_kcontrol
*kcontrol
,
498 struct snd_ctl_elem_value
*ucontrol
)
500 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
501 struct usb_mixer_interface
*mixer
= list
->mixer
;
502 unsigned int value
= ucontrol
->value
.enumerated
.item
[0];
508 if (value
== kcontrol
->private_value
)
511 kcontrol
->private_value
= value
;
512 err
= snd_emu0204_ch_switch_update(mixer
, value
);
513 return err
< 0 ? err
: 1;
516 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list
*list
)
518 return snd_emu0204_ch_switch_update(list
->mixer
,
519 list
->kctl
->private_value
);
522 static struct snd_kcontrol_new snd_emu0204_control
= {
523 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
524 .name
= "Front Jack Channels",
525 .info
= snd_emu0204_ch_switch_info
,
526 .get
= snd_emu0204_ch_switch_get
,
527 .put
= snd_emu0204_ch_switch_put
,
531 static int snd_emu0204_controls_create(struct usb_mixer_interface
*mixer
)
533 return add_single_ctl_with_resume(mixer
, 0,
534 snd_emu0204_ch_switch_resume
,
535 &snd_emu0204_control
, NULL
);
538 /* ASUS Xonar U1 / U3 controls */
540 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
541 struct snd_ctl_elem_value
*ucontrol
)
543 ucontrol
->value
.integer
.value
[0] = !!(kcontrol
->private_value
& 0x02);
547 static int snd_xonar_u1_switch_update(struct usb_mixer_interface
*mixer
,
548 unsigned char status
)
550 struct snd_usb_audio
*chip
= mixer
->chip
;
553 err
= snd_usb_lock_shutdown(chip
);
556 err
= snd_usb_ctl_msg(chip
->dev
,
557 usb_sndctrlpipe(chip
->dev
, 0), 0x08,
558 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
560 snd_usb_unlock_shutdown(chip
);
564 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
565 struct snd_ctl_elem_value
*ucontrol
)
567 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
568 u8 old_status
, new_status
;
571 old_status
= kcontrol
->private_value
;
572 if (ucontrol
->value
.integer
.value
[0])
573 new_status
= old_status
| 0x02;
575 new_status
= old_status
& ~0x02;
576 if (new_status
== old_status
)
579 kcontrol
->private_value
= new_status
;
580 err
= snd_xonar_u1_switch_update(list
->mixer
, new_status
);
581 return err
< 0 ? err
: 1;
584 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list
*list
)
586 return snd_xonar_u1_switch_update(list
->mixer
,
587 list
->kctl
->private_value
);
590 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
591 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
592 .name
= "Digital Playback Switch",
593 .info
= snd_ctl_boolean_mono_info
,
594 .get
= snd_xonar_u1_switch_get
,
595 .put
= snd_xonar_u1_switch_put
,
596 .private_value
= 0x05,
599 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
601 return add_single_ctl_with_resume(mixer
, 0,
602 snd_xonar_u1_switch_resume
,
603 &snd_xonar_u1_output_switch
, NULL
);
606 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
608 static int snd_mbox1_switch_get(struct snd_kcontrol
*kctl
,
609 struct snd_ctl_elem_value
*ucontrol
)
611 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
;
615 static int snd_mbox1_switch_update(struct usb_mixer_interface
*mixer
, int val
)
617 struct snd_usb_audio
*chip
= mixer
->chip
;
619 unsigned char buff
[3];
621 err
= snd_usb_lock_shutdown(chip
);
625 /* Prepare for magic command to toggle clock source */
626 err
= snd_usb_ctl_msg(chip
->dev
,
627 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
630 USB_RECIP_INTERFACE
, 0x00, 0x500, buff
, 1);
633 err
= snd_usb_ctl_msg(chip
->dev
,
634 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
637 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
641 /* 2 possibilities: Internal -> send sample rate
642 * S/PDIF sync -> send zeroes
643 * NB: Sample rate locked to 48kHz on purpose to
644 * prevent user from resetting the sample rate
645 * while S/PDIF sync is enabled and confusing
646 * this configuration.
653 buff
[0] = buff
[1] = buff
[2] = 0x00;
656 /* Send the magic command to toggle the clock source */
657 err
= snd_usb_ctl_msg(chip
->dev
,
658 usb_sndctrlpipe(chip
->dev
, 0), 0x1,
660 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
663 err
= snd_usb_ctl_msg(chip
->dev
,
664 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
667 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
670 err
= snd_usb_ctl_msg(chip
->dev
,
671 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
674 USB_RECIP_ENDPOINT
, 0x100, 0x2, buff
, 3);
679 snd_usb_unlock_shutdown(chip
);
683 static int snd_mbox1_switch_put(struct snd_kcontrol
*kctl
,
684 struct snd_ctl_elem_value
*ucontrol
)
686 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
687 struct usb_mixer_interface
*mixer
= list
->mixer
;
689 bool cur_val
, new_val
;
691 cur_val
= kctl
->private_value
;
692 new_val
= ucontrol
->value
.enumerated
.item
[0];
693 if (cur_val
== new_val
)
696 kctl
->private_value
= new_val
;
697 err
= snd_mbox1_switch_update(mixer
, new_val
);
698 return err
< 0 ? err
: 1;
701 static int snd_mbox1_switch_info(struct snd_kcontrol
*kcontrol
,
702 struct snd_ctl_elem_info
*uinfo
)
704 static const char *const texts
[2] = {
709 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
712 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list
*list
)
714 return snd_mbox1_switch_update(list
->mixer
, list
->kctl
->private_value
);
717 static struct snd_kcontrol_new snd_mbox1_switch
= {
718 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
719 .name
= "Clock Source",
721 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
722 .info
= snd_mbox1_switch_info
,
723 .get
= snd_mbox1_switch_get
,
724 .put
= snd_mbox1_switch_put
,
728 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface
*mixer
)
730 return add_single_ctl_with_resume(mixer
, 0,
731 snd_mbox1_switch_resume
,
732 &snd_mbox1_switch
, NULL
);
735 /* Native Instruments device quirks */
737 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
739 static int snd_ni_control_init_val(struct usb_mixer_interface
*mixer
,
740 struct snd_kcontrol
*kctl
)
742 struct usb_device
*dev
= mixer
->chip
->dev
;
743 unsigned int pval
= kctl
->private_value
;
747 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
749 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
750 0, pval
& 0xffff, &value
, 1);
753 "unable to issue vendor read request (ret = %d)", err
);
757 kctl
->private_value
|= (value
<< 24);
761 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
762 struct snd_ctl_elem_value
*ucontrol
)
764 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 24;
768 static int snd_ni_update_cur_val(struct usb_mixer_elem_list
*list
)
770 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
771 unsigned int pval
= list
->kctl
->private_value
;
774 err
= snd_usb_lock_shutdown(chip
);
777 err
= usb_control_msg(chip
->dev
, usb_sndctrlpipe(chip
->dev
, 0),
779 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
780 pval
>> 24, pval
& 0xffff, NULL
, 0, 1000);
781 snd_usb_unlock_shutdown(chip
);
785 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
786 struct snd_ctl_elem_value
*ucontrol
)
788 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
789 u8 oldval
= (kcontrol
->private_value
>> 24) & 0xff;
790 u8 newval
= ucontrol
->value
.integer
.value
[0];
793 if (oldval
== newval
)
796 kcontrol
->private_value
&= ~(0xff << 24);
797 kcontrol
->private_value
|= (unsigned int)newval
<< 24;
798 err
= snd_ni_update_cur_val(list
);
799 return err
< 0 ? err
: 1;
802 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
804 .name
= "Direct Thru Channel A",
805 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
808 .name
= "Direct Thru Channel B",
809 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
812 .name
= "Phono Input Channel A",
813 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
816 .name
= "Phono Input Channel B",
817 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
821 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
823 .name
= "Direct Thru Channel A",
824 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
827 .name
= "Direct Thru Channel B",
828 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
831 .name
= "Direct Thru Channel C",
832 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
835 .name
= "Direct Thru Channel D",
836 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
839 .name
= "Phono Input Channel A",
840 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
843 .name
= "Phono Input Channel B",
844 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
847 .name
= "Phono Input Channel C",
848 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
851 .name
= "Phono Input Channel D",
852 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
856 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
857 const struct snd_kcontrol_new
*kc
,
861 struct snd_kcontrol_new
template = {
862 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
863 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
864 .get
= snd_nativeinstruments_control_get
,
865 .put
= snd_nativeinstruments_control_put
,
866 .info
= snd_ctl_boolean_mono_info
,
869 for (i
= 0; i
< count
; i
++) {
870 struct usb_mixer_elem_list
*list
;
872 template.name
= kc
[i
].name
;
873 template.private_value
= kc
[i
].private_value
;
875 err
= add_single_ctl_with_resume(mixer
, 0,
876 snd_ni_update_cur_val
,
880 snd_ni_control_init_val(mixer
, list
->kctl
);
886 /* M-Audio FastTrack Ultra quirks */
887 /* FTU Effect switch (also used by C400/C600) */
888 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
889 struct snd_ctl_elem_info
*uinfo
)
891 static const char *const texts
[8] = {
892 "Room 1", "Room 2", "Room 3", "Hall 1",
893 "Hall 2", "Plate", "Delay", "Echo"
896 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
899 static int snd_ftu_eff_switch_init(struct usb_mixer_interface
*mixer
,
900 struct snd_kcontrol
*kctl
)
902 struct usb_device
*dev
= mixer
->chip
->dev
;
903 unsigned int pval
= kctl
->private_value
;
905 unsigned char value
[2];
910 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), UAC_GET_CUR
,
911 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
913 snd_usb_ctrl_intf(mixer
->chip
) | ((pval
& 0xff) << 8),
918 kctl
->private_value
|= value
[0] << 24;
922 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
923 struct snd_ctl_elem_value
*ucontrol
)
925 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
>> 24;
929 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list
*list
)
931 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
932 unsigned int pval
= list
->kctl
->private_value
;
933 unsigned char value
[2];
936 value
[0] = pval
>> 24;
939 err
= snd_usb_lock_shutdown(chip
);
942 err
= snd_usb_ctl_msg(chip
->dev
,
943 usb_sndctrlpipe(chip
->dev
, 0),
945 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
947 snd_usb_ctrl_intf(chip
) | ((pval
& 0xff) << 8),
949 snd_usb_unlock_shutdown(chip
);
953 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
954 struct snd_ctl_elem_value
*ucontrol
)
956 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
957 unsigned int pval
= list
->kctl
->private_value
;
958 int cur_val
, err
, new_val
;
960 cur_val
= pval
>> 24;
961 new_val
= ucontrol
->value
.enumerated
.item
[0];
962 if (cur_val
== new_val
)
965 kctl
->private_value
&= ~(0xff << 24);
966 kctl
->private_value
|= new_val
<< 24;
967 err
= snd_ftu_eff_switch_update(list
);
968 return err
< 0 ? err
: 1;
971 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
972 int validx
, int bUnitID
)
974 static struct snd_kcontrol_new
template = {
975 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
976 .name
= "Effect Program Switch",
978 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
979 .info
= snd_ftu_eff_switch_info
,
980 .get
= snd_ftu_eff_switch_get
,
981 .put
= snd_ftu_eff_switch_put
983 struct usb_mixer_elem_list
*list
;
986 err
= add_single_ctl_with_resume(mixer
, bUnitID
,
987 snd_ftu_eff_switch_update
,
991 list
->kctl
->private_value
= (validx
<< 8) | bUnitID
;
992 snd_ftu_eff_switch_init(mixer
, list
->kctl
);
996 /* Create volume controls for FTU devices*/
997 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
1000 unsigned int control
, cmask
;
1003 const unsigned int id
= 5;
1004 const int val_type
= USB_MIXER_S16
;
1006 for (out
= 0; out
< 8; out
++) {
1008 for (in
= 0; in
< 8; in
++) {
1010 snprintf(name
, sizeof(name
),
1011 "AIn%d - Out%d Capture Volume",
1013 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1014 cmask
, val_type
, name
,
1015 &snd_usb_mixer_vol_tlv
);
1019 for (in
= 8; in
< 16; in
++) {
1021 snprintf(name
, sizeof(name
),
1022 "DIn%d - Out%d Playback Volume",
1024 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1025 cmask
, val_type
, name
,
1026 &snd_usb_mixer_vol_tlv
);
1035 /* This control needs a volume quirk, see mixer.c */
1036 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1038 static const char name
[] = "Effect Volume";
1039 const unsigned int id
= 6;
1040 const int val_type
= USB_MIXER_U8
;
1041 const unsigned int control
= 2;
1042 const unsigned int cmask
= 0;
1044 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1045 name
, snd_usb_mixer_vol_tlv
);
1048 /* This control needs a volume quirk, see mixer.c */
1049 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1051 static const char name
[] = "Effect Duration";
1052 const unsigned int id
= 6;
1053 const int val_type
= USB_MIXER_S16
;
1054 const unsigned int control
= 3;
1055 const unsigned int cmask
= 0;
1057 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1058 name
, snd_usb_mixer_vol_tlv
);
1061 /* This control needs a volume quirk, see mixer.c */
1062 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1064 static const char name
[] = "Effect Feedback Volume";
1065 const unsigned int id
= 6;
1066 const int val_type
= USB_MIXER_U8
;
1067 const unsigned int control
= 4;
1068 const unsigned int cmask
= 0;
1070 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1074 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
1080 const unsigned int id
= 7;
1081 const int val_type
= USB_MIXER_S16
;
1082 const unsigned int control
= 7;
1084 for (ch
= 0; ch
< 4; ++ch
) {
1086 snprintf(name
, sizeof(name
),
1087 "Effect Return %d Volume", ch
+ 1);
1088 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1089 cmask
, val_type
, name
,
1090 snd_usb_mixer_vol_tlv
);
1098 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
1104 const unsigned int id
= 5;
1105 const int val_type
= USB_MIXER_S16
;
1106 const unsigned int control
= 9;
1108 for (ch
= 0; ch
< 8; ++ch
) {
1110 snprintf(name
, sizeof(name
),
1111 "Effect Send AIn%d Volume", ch
+ 1);
1112 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1114 snd_usb_mixer_vol_tlv
);
1118 for (ch
= 8; ch
< 16; ++ch
) {
1120 snprintf(name
, sizeof(name
),
1121 "Effect Send DIn%d Volume", ch
- 7);
1122 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1124 snd_usb_mixer_vol_tlv
);
1131 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
1135 err
= snd_ftu_create_volume_ctls(mixer
);
1139 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
1143 err
= snd_ftu_create_effect_volume_ctl(mixer
);
1147 err
= snd_ftu_create_effect_duration_ctl(mixer
);
1151 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1155 err
= snd_ftu_create_effect_return_ctls(mixer
);
1159 err
= snd_ftu_create_effect_send_ctls(mixer
);
1166 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1167 unsigned char samplerate_id
)
1169 struct usb_mixer_interface
*mixer
;
1170 struct usb_mixer_elem_info
*cval
;
1171 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1173 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1174 cval
= (struct usb_mixer_elem_info
*)mixer
->id_elems
[unitid
];
1176 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1179 snd_usb_mixer_notify_id(mixer
, unitid
);
1185 /* M-Audio Fast Track C400/C600 */
1186 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1187 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1190 unsigned int cmask
, offset
;
1195 const unsigned int id
= 0x40;
1196 const int val_type
= USB_MIXER_S16
;
1197 const int control
= 1;
1199 switch (mixer
->chip
->usb_id
) {
1200 case USB_ID(0x0763, 0x2030):
1204 case USB_ID(0x0763, 0x2031):
1210 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1211 for (out
= 0; out
< num_outs
; out
++) {
1212 if (chan
< num_outs
) {
1213 snprintf(name
, sizeof(name
),
1214 "PCM%d-Out%d Playback Volume",
1217 snprintf(name
, sizeof(name
),
1218 "In%d-Out%d Playback Volume",
1219 chan
- num_outs
+ 1, out
+ 1);
1222 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1223 offset
= chan
* num_outs
;
1224 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1225 cmask
, val_type
, offset
, name
,
1226 &snd_usb_mixer_vol_tlv
);
1235 /* This control needs a volume quirk, see mixer.c */
1236 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1238 static const char name
[] = "Effect Volume";
1239 const unsigned int id
= 0x43;
1240 const int val_type
= USB_MIXER_U8
;
1241 const unsigned int control
= 3;
1242 const unsigned int cmask
= 0;
1244 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1245 name
, snd_usb_mixer_vol_tlv
);
1248 /* This control needs a volume quirk, see mixer.c */
1249 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1251 static const char name
[] = "Effect Duration";
1252 const unsigned int id
= 0x43;
1253 const int val_type
= USB_MIXER_S16
;
1254 const unsigned int control
= 4;
1255 const unsigned int cmask
= 0;
1257 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1258 name
, snd_usb_mixer_vol_tlv
);
1261 /* This control needs a volume quirk, see mixer.c */
1262 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1264 static const char name
[] = "Effect Feedback Volume";
1265 const unsigned int id
= 0x43;
1266 const int val_type
= USB_MIXER_U8
;
1267 const unsigned int control
= 5;
1268 const unsigned int cmask
= 0;
1270 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1274 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1282 const unsigned int id
= 0x42;
1283 const int val_type
= USB_MIXER_S16
;
1284 const int control
= 1;
1286 switch (mixer
->chip
->usb_id
) {
1287 case USB_ID(0x0763, 0x2030):
1291 case USB_ID(0x0763, 0x2031):
1297 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1298 if (chan
< num_outs
) {
1299 snprintf(name
, sizeof(name
),
1300 "Effect Send DOut%d",
1303 snprintf(name
, sizeof(name
),
1304 "Effect Send AIn%d",
1305 chan
- num_outs
+ 1);
1308 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1309 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1310 cmask
, val_type
, name
,
1311 &snd_usb_mixer_vol_tlv
);
1319 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1327 const unsigned int id
= 0x40;
1328 const int val_type
= USB_MIXER_S16
;
1329 const int control
= 1;
1331 switch (mixer
->chip
->usb_id
) {
1332 case USB_ID(0x0763, 0x2030):
1335 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1337 case USB_ID(0x0763, 0x2031):
1340 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1344 for (chan
= 0; chan
< num_outs
; chan
++) {
1345 snprintf(name
, sizeof(name
),
1349 cmask
= (chan
== 0) ? 0 :
1350 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1351 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1352 cmask
, val_type
, offset
, name
,
1353 &snd_usb_mixer_vol_tlv
);
1361 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1365 err
= snd_c400_create_vol_ctls(mixer
);
1369 err
= snd_c400_create_effect_vol_ctls(mixer
);
1373 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1377 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1381 err
= snd_c400_create_effect_volume_ctl(mixer
);
1385 err
= snd_c400_create_effect_duration_ctl(mixer
);
1389 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1397 * The mixer units for Ebox-44 are corrupt, and even where they
1398 * are valid they presents mono controls as L and R channels of
1399 * stereo. So we provide a good mixer here.
1401 static struct std_mono_table ebox44_table
[] = {
1406 .val_type
= USB_MIXER_INV_BOOLEAN
,
1407 .name
= "Headphone Playback Switch"
1413 .val_type
= USB_MIXER_S16
,
1414 .name
= "Headphone A Mix Playback Volume"
1420 .val_type
= USB_MIXER_S16
,
1421 .name
= "Headphone B Mix Playback Volume"
1428 .val_type
= USB_MIXER_INV_BOOLEAN
,
1429 .name
= "Output Playback Switch"
1435 .val_type
= USB_MIXER_S16
,
1436 .name
= "Output A Playback Volume"
1442 .val_type
= USB_MIXER_S16
,
1443 .name
= "Output B Playback Volume"
1450 .val_type
= USB_MIXER_INV_BOOLEAN
,
1451 .name
= "Input Capture Switch"
1457 .val_type
= USB_MIXER_S16
,
1458 .name
= "Input A Capture Volume"
1464 .val_type
= USB_MIXER_S16
,
1465 .name
= "Input B Capture Volume"
1471 /* Audio Advantage Micro II findings:
1473 * Mapping spdif AES bits to vendor register.bit:
1474 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1475 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1476 * AES2: [0 0 0 0 0 0 0 0]
1477 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1478 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1482 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1483 * just after it to 0xa0, presumably it disables/mutes some analog
1484 * parts when there is no audio.)
1487 * Optical transmitter on/off:
1488 * vendor register.bit: 9.1
1489 * 0 - on (0x28 register value)
1490 * 1 - off (0x2a register value)
1493 static int snd_microii_spdif_info(struct snd_kcontrol
*kcontrol
,
1494 struct snd_ctl_elem_info
*uinfo
)
1496 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1501 static int snd_microii_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1502 struct snd_ctl_elem_value
*ucontrol
)
1504 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1505 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1507 struct usb_interface
*iface
;
1508 struct usb_host_interface
*alts
;
1510 unsigned char data
[3];
1513 err
= snd_usb_lock_shutdown(chip
);
1517 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
& 0xff;
1518 ucontrol
->value
.iec958
.status
[1] = (kcontrol
->private_value
>> 8) & 0xff;
1519 ucontrol
->value
.iec958
.status
[2] = 0x00;
1521 /* use known values for that card: interface#1 altsetting#1 */
1522 iface
= usb_ifnum_to_if(chip
->dev
, 1);
1523 if (!iface
|| iface
->num_altsetting
< 2)
1525 alts
= &iface
->altsetting
[1];
1526 if (get_iface_desc(alts
)->bNumEndpoints
< 1)
1528 ep
= get_endpoint(alts
, 0)->bEndpointAddress
;
1530 err
= snd_usb_ctl_msg(chip
->dev
,
1531 usb_rcvctrlpipe(chip
->dev
, 0),
1533 USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
1534 UAC_EP_CS_ATTR_SAMPLE_RATE
<< 8,
1541 rate
= data
[0] | (data
[1] << 8) | (data
[2] << 16);
1542 ucontrol
->value
.iec958
.status
[3] = (rate
== 48000) ?
1543 IEC958_AES3_CON_FS_48000
: IEC958_AES3_CON_FS_44100
;
1547 snd_usb_unlock_shutdown(chip
);
1551 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list
*list
)
1553 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1554 unsigned int pval
= list
->kctl
->private_value
;
1558 err
= snd_usb_lock_shutdown(chip
);
1562 reg
= ((pval
>> 4) & 0xf0) | (pval
& 0x0f);
1563 err
= snd_usb_ctl_msg(chip
->dev
,
1564 usb_sndctrlpipe(chip
->dev
, 0),
1566 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1574 reg
= (pval
& IEC958_AES0_NONAUDIO
) ? 0xa0 : 0x20;
1575 reg
|= (pval
>> 12) & 0x0f;
1576 err
= snd_usb_ctl_msg(chip
->dev
,
1577 usb_sndctrlpipe(chip
->dev
, 0),
1579 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1588 snd_usb_unlock_shutdown(chip
);
1592 static int snd_microii_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1593 struct snd_ctl_elem_value
*ucontrol
)
1595 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1596 unsigned int pval
, pval_old
;
1599 pval
= pval_old
= kcontrol
->private_value
;
1601 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0x0f) << 8;
1602 pval
|= (ucontrol
->value
.iec958
.status
[0] & 0x0f);
1605 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0xf0) << 8;
1607 /* The frequency bits in AES3 cannot be set via register access. */
1609 /* Silently ignore any bits from the request that cannot be set. */
1611 if (pval
== pval_old
)
1614 kcontrol
->private_value
= pval
;
1615 err
= snd_microii_spdif_default_update(list
);
1616 return err
< 0 ? err
: 1;
1619 static int snd_microii_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
1620 struct snd_ctl_elem_value
*ucontrol
)
1622 ucontrol
->value
.iec958
.status
[0] = 0x0f;
1623 ucontrol
->value
.iec958
.status
[1] = 0xff;
1624 ucontrol
->value
.iec958
.status
[2] = 0x00;
1625 ucontrol
->value
.iec958
.status
[3] = 0x00;
1630 static int snd_microii_spdif_switch_get(struct snd_kcontrol
*kcontrol
,
1631 struct snd_ctl_elem_value
*ucontrol
)
1633 ucontrol
->value
.integer
.value
[0] = !(kcontrol
->private_value
& 0x02);
1638 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list
*list
)
1640 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1641 u8 reg
= list
->kctl
->private_value
;
1644 err
= snd_usb_lock_shutdown(chip
);
1648 err
= snd_usb_ctl_msg(chip
->dev
,
1649 usb_sndctrlpipe(chip
->dev
, 0),
1651 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1657 snd_usb_unlock_shutdown(chip
);
1661 static int snd_microii_spdif_switch_put(struct snd_kcontrol
*kcontrol
,
1662 struct snd_ctl_elem_value
*ucontrol
)
1664 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1668 reg
= ucontrol
->value
.integer
.value
[0] ? 0x28 : 0x2a;
1669 if (reg
!= list
->kctl
->private_value
)
1672 kcontrol
->private_value
= reg
;
1673 err
= snd_microii_spdif_switch_update(list
);
1674 return err
< 0 ? err
: 1;
1677 static struct snd_kcontrol_new snd_microii_mixer_spdif
[] = {
1679 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1680 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, DEFAULT
),
1681 .info
= snd_microii_spdif_info
,
1682 .get
= snd_microii_spdif_default_get
,
1683 .put
= snd_microii_spdif_default_put
,
1684 .private_value
= 0x00000100UL
,/* reset value */
1687 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1688 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1689 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, MASK
),
1690 .info
= snd_microii_spdif_info
,
1691 .get
= snd_microii_spdif_mask_get
,
1694 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1695 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, SWITCH
),
1696 .info
= snd_ctl_boolean_mono_info
,
1697 .get
= snd_microii_spdif_switch_get
,
1698 .put
= snd_microii_spdif_switch_put
,
1699 .private_value
= 0x00000028UL
,/* reset value */
1703 static int snd_microii_controls_create(struct usb_mixer_interface
*mixer
)
1706 static usb_mixer_elem_resume_func_t resume_funcs
[] = {
1707 snd_microii_spdif_default_update
,
1709 snd_microii_spdif_switch_update
1712 for (i
= 0; i
< ARRAY_SIZE(snd_microii_mixer_spdif
); ++i
) {
1713 err
= add_single_ctl_with_resume(mixer
, 0,
1715 &snd_microii_mixer_spdif
[i
],
1724 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1727 struct snd_info_entry
*entry
;
1729 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1732 switch (mixer
->chip
->usb_id
) {
1733 /* Tascam US-16x08 */
1734 case USB_ID(0x0644, 0x8047):
1735 err
= snd_us16x08_controls_create(mixer
);
1737 case USB_ID(0x041e, 0x3020):
1738 case USB_ID(0x041e, 0x3040):
1739 case USB_ID(0x041e, 0x3042):
1740 case USB_ID(0x041e, 0x30df):
1741 case USB_ID(0x041e, 0x3048):
1742 err
= snd_audigy2nx_controls_create(mixer
);
1745 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1746 snd_info_set_text_ops(entry
, mixer
,
1747 snd_audigy2nx_proc_read
);
1751 case USB_ID(0x041e, 0x3f19):
1752 err
= snd_emu0204_controls_create(mixer
);
1757 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1758 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1759 err
= snd_c400_create_mixer(mixer
);
1762 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1763 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1764 err
= snd_ftu_create_mixer(mixer
);
1767 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1768 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1769 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1770 err
= snd_xonar_u1_controls_create(mixer
);
1773 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1774 err
= snd_microii_controls_create(mixer
);
1777 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1778 err
= snd_mbox1_create_sync_switch(mixer
);
1781 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1782 err
= snd_nativeinstruments_create_mixer(mixer
,
1783 snd_nativeinstruments_ta6_mixers
,
1784 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1787 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1788 err
= snd_nativeinstruments_create_mixer(mixer
,
1789 snd_nativeinstruments_ta10_mixers
,
1790 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1793 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1794 /* detection is disabled in mixer_maps.c */
1795 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1798 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1799 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1800 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1801 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1802 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1803 err
= snd_scarlett_controls_create(mixer
);
1810 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1815 /* unit ids specific to Extigy/Audigy 2 NX: */
1817 case 0: /* remote control */
1818 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1819 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1821 case 4: /* digital in jack */
1822 case 7: /* line in jacks */
1823 case 19: /* speaker out jacks */
1824 case 20: /* headphones out jack */
1826 /* live24ext: 4 = line-in jack */
1827 case 3: /* hp-out jack (may actuate Mute) */
1828 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1829 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1830 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1833 usb_audio_dbg(mixer
->chip
, "memory change in unknown unit %d\n", unitid
);
1838 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface
*mixer
,
1839 struct usb_mixer_elem_info
*cval
,
1840 struct snd_kcontrol
*kctl
)
1842 /* Approximation using 10 ranges based on output measurement on hw v1.2.
1843 * This seems close to the cubic mapping e.g. alsamixer uses. */
1844 static const DECLARE_TLV_DB_RANGE(scale
,
1845 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
1846 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
1847 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
1848 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
1849 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
1850 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
1851 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
1852 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
1853 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
1854 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
1857 if (cval
->min
== 0 && cval
->max
== 50) {
1858 usb_audio_info(mixer
->chip
, "applying DragonFly dB scale quirk (0-50 variant)\n");
1859 kctl
->tlv
.p
= scale
;
1860 kctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1861 kctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
1863 } else if (cval
->min
== 0 && cval
->max
<= 1000) {
1864 /* Some other clearly broken DragonFly variant.
1865 * At least a 0..53 variant (hw v1.0) exists.
1867 usb_audio_info(mixer
->chip
, "ignoring too narrow dB range on a DragonFly device");
1868 kctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
1872 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface
*mixer
,
1873 struct usb_mixer_elem_info
*cval
, int unitid
,
1874 struct snd_kcontrol
*kctl
)
1876 switch (mixer
->chip
->usb_id
) {
1877 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
1878 if (unitid
== 7 && cval
->control
== UAC_FU_VOLUME
)
1879 snd_dragonfly_quirk_db_scale(mixer
, cval
, kctl
);
1881 /* lowest playback value is muted on C-Media devices */
1882 case USB_ID(0x0d8c, 0x000c):
1883 case USB_ID(0x0d8c, 0x0014):
1884 if (strstr(kctl
->id
.name
, "Playback"))