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, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
196 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
199 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
201 struct usb_mixer_interface
*mixer
= urb
->context
;
202 const struct rc_config
*rc
= mixer
->rc_cfg
;
205 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
208 code
= mixer
->rc_buffer
[rc
->offset
];
210 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
212 /* the Mute button actually changes the mixer control */
213 if (code
== rc
->mute_code
)
214 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
215 mixer
->rc_code
= code
;
217 wake_up(&mixer
->rc_waitq
);
220 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
221 long count
, loff_t
*offset
)
223 struct usb_mixer_interface
*mixer
= hw
->private_data
;
227 if (count
!= 1 && count
!= 4)
229 err
= wait_event_interruptible(mixer
->rc_waitq
,
230 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
233 err
= put_user(rc_code
, buf
);
235 err
= put_user(rc_code
, (u32 __user
*)buf
);
237 return err
< 0 ? err
: count
;
240 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
243 struct usb_mixer_interface
*mixer
= hw
->private_data
;
245 poll_wait(file
, &mixer
->rc_waitq
, wait
);
246 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
249 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
251 struct snd_hwdep
*hwdep
;
254 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
255 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
257 if (i
>= ARRAY_SIZE(rc_configs
))
259 mixer
->rc_cfg
= &rc_configs
[i
];
261 len
= mixer
->rc_cfg
->packet_length
;
263 init_waitqueue_head(&mixer
->rc_waitq
);
264 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
267 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
268 "%s remote control", mixer
->chip
->card
->shortname
);
269 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
270 hwdep
->private_data
= mixer
;
271 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
272 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
273 hwdep
->exclusive
= 1;
275 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
278 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
279 if (!mixer
->rc_setup_packet
) {
280 usb_free_urb(mixer
->rc_urb
);
281 mixer
->rc_urb
= NULL
;
284 mixer
->rc_setup_packet
->bRequestType
=
285 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
286 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
287 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
288 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
289 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
290 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
291 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
292 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
293 snd_usb_soundblaster_remote_complete
, mixer
);
297 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
299 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
301 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 8;
305 static int snd_audigy2nx_led_update(struct usb_mixer_interface
*mixer
,
306 int value
, int index
)
308 struct snd_usb_audio
*chip
= mixer
->chip
;
311 err
= snd_usb_lock_shutdown(chip
);
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);
331 snd_usb_unlock_shutdown(chip
);
335 static int snd_audigy2nx_led_put(struct snd_kcontrol
*kcontrol
,
336 struct snd_ctl_elem_value
*ucontrol
)
338 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
339 struct usb_mixer_interface
*mixer
= list
->mixer
;
340 int index
= kcontrol
->private_value
& 0xff;
341 unsigned int value
= ucontrol
->value
.integer
.value
[0];
342 int old_value
= kcontrol
->private_value
>> 8;
347 if (value
== old_value
)
349 kcontrol
->private_value
= (value
<< 8) | index
;
350 err
= snd_audigy2nx_led_update(mixer
, value
, index
);
351 return err
< 0 ? err
: 1;
354 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list
*list
)
356 int priv_value
= list
->kctl
->private_value
;
358 return snd_audigy2nx_led_update(list
->mixer
, priv_value
>> 8,
362 /* name and private_value are set dynamically */
363 static struct snd_kcontrol_new snd_audigy2nx_control
= {
364 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
365 .info
= snd_audigy2nx_led_info
,
366 .get
= snd_audigy2nx_led_get
,
367 .put
= snd_audigy2nx_led_put
,
370 static const char * const snd_audigy2nx_led_names
[] = {
373 "Dolby Digital LED Switch",
376 static int snd_audigy2nx_controls_create(struct usb_mixer_interface
*mixer
)
380 for (i
= 0; i
< ARRAY_SIZE(snd_audigy2nx_led_names
); ++i
) {
381 struct snd_kcontrol_new knew
;
383 /* USB X-Fi S51 doesn't have a CMSS LED */
384 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042)) && i
== 0)
386 /* USB X-Fi S51 Pro doesn't have one either */
387 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df)) && i
== 0)
389 if (i
> 1 && /* Live24ext has 2 LEDs only */
390 (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
391 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042) ||
392 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df) ||
393 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048)))
396 knew
= snd_audigy2nx_control
;
397 knew
.name
= snd_audigy2nx_led_names
[i
];
398 knew
.private_value
= (1 << 8) | i
; /* LED on as default */
399 err
= add_single_ctl_with_resume(mixer
, 0,
400 snd_audigy2nx_led_resume
,
408 static void snd_audigy2nx_proc_read(struct snd_info_entry
*entry
,
409 struct snd_info_buffer
*buffer
)
411 static const struct sb_jack
{
414 } jacks_audigy2nx
[] = {
420 }, jacks_live24ext
[] = {
421 {4, "line in"}, /* &1=Line, &2=Mic*/
422 {3, "hph out"}, /* headphones */
423 {0, "RC "}, /* last command, 6 bytes see rc_config above */
426 const struct sb_jack
*jacks
;
427 struct usb_mixer_interface
*mixer
= entry
->private_data
;
431 snd_iprintf(buffer
, "%s jacks\n\n", mixer
->chip
->card
->shortname
);
432 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3020))
433 jacks
= jacks_audigy2nx
;
434 else if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
435 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
436 jacks
= jacks_live24ext
;
440 for (i
= 0; jacks
[i
].name
; ++i
) {
441 snd_iprintf(buffer
, "%s: ", jacks
[i
].name
);
442 err
= snd_usb_lock_shutdown(mixer
->chip
);
445 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
446 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
447 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
448 USB_RECIP_INTERFACE
, 0,
449 jacks
[i
].unitid
<< 8, buf
, 3);
450 snd_usb_unlock_shutdown(mixer
->chip
);
451 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
452 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
454 snd_iprintf(buffer
, "?\n");
459 static int snd_emu0204_ch_switch_info(struct snd_kcontrol
*kcontrol
,
460 struct snd_ctl_elem_info
*uinfo
)
462 static const char * const texts
[2] = {"1/2", "3/4"};
464 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
467 static int snd_emu0204_ch_switch_get(struct snd_kcontrol
*kcontrol
,
468 struct snd_ctl_elem_value
*ucontrol
)
470 ucontrol
->value
.enumerated
.item
[0] = kcontrol
->private_value
;
474 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface
*mixer
,
477 struct snd_usb_audio
*chip
= mixer
->chip
;
479 unsigned char buf
[2];
481 err
= snd_usb_lock_shutdown(chip
);
486 buf
[1] = value
? 0x02 : 0x01;
487 err
= snd_usb_ctl_msg(chip
->dev
,
488 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
489 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
490 0x0400, 0x0e00, buf
, 2);
491 snd_usb_unlock_shutdown(chip
);
495 static int snd_emu0204_ch_switch_put(struct snd_kcontrol
*kcontrol
,
496 struct snd_ctl_elem_value
*ucontrol
)
498 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
499 struct usb_mixer_interface
*mixer
= list
->mixer
;
500 unsigned int value
= ucontrol
->value
.enumerated
.item
[0];
506 if (value
== kcontrol
->private_value
)
509 kcontrol
->private_value
= value
;
510 err
= snd_emu0204_ch_switch_update(mixer
, value
);
511 return err
< 0 ? err
: 1;
514 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list
*list
)
516 return snd_emu0204_ch_switch_update(list
->mixer
,
517 list
->kctl
->private_value
);
520 static struct snd_kcontrol_new snd_emu0204_control
= {
521 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
522 .name
= "Front Jack Channels",
523 .info
= snd_emu0204_ch_switch_info
,
524 .get
= snd_emu0204_ch_switch_get
,
525 .put
= snd_emu0204_ch_switch_put
,
529 static int snd_emu0204_controls_create(struct usb_mixer_interface
*mixer
)
531 return add_single_ctl_with_resume(mixer
, 0,
532 snd_emu0204_ch_switch_resume
,
533 &snd_emu0204_control
, NULL
);
536 /* ASUS Xonar U1 / U3 controls */
538 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
539 struct snd_ctl_elem_value
*ucontrol
)
541 ucontrol
->value
.integer
.value
[0] = !!(kcontrol
->private_value
& 0x02);
545 static int snd_xonar_u1_switch_update(struct usb_mixer_interface
*mixer
,
546 unsigned char status
)
548 struct snd_usb_audio
*chip
= mixer
->chip
;
551 err
= snd_usb_lock_shutdown(chip
);
554 err
= snd_usb_ctl_msg(chip
->dev
,
555 usb_sndctrlpipe(chip
->dev
, 0), 0x08,
556 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
558 snd_usb_unlock_shutdown(chip
);
562 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
563 struct snd_ctl_elem_value
*ucontrol
)
565 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
566 u8 old_status
, new_status
;
569 old_status
= kcontrol
->private_value
;
570 if (ucontrol
->value
.integer
.value
[0])
571 new_status
= old_status
| 0x02;
573 new_status
= old_status
& ~0x02;
574 if (new_status
== old_status
)
577 kcontrol
->private_value
= new_status
;
578 err
= snd_xonar_u1_switch_update(list
->mixer
, new_status
);
579 return err
< 0 ? err
: 1;
582 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list
*list
)
584 return snd_xonar_u1_switch_update(list
->mixer
,
585 list
->kctl
->private_value
);
588 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
589 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
590 .name
= "Digital Playback Switch",
591 .info
= snd_ctl_boolean_mono_info
,
592 .get
= snd_xonar_u1_switch_get
,
593 .put
= snd_xonar_u1_switch_put
,
594 .private_value
= 0x05,
597 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
599 return add_single_ctl_with_resume(mixer
, 0,
600 snd_xonar_u1_switch_resume
,
601 &snd_xonar_u1_output_switch
, NULL
);
604 /* Digidesign Mbox 1 clock source switch (internal/spdif) */
606 static int snd_mbox1_switch_get(struct snd_kcontrol
*kctl
,
607 struct snd_ctl_elem_value
*ucontrol
)
609 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
;
613 static int snd_mbox1_switch_update(struct usb_mixer_interface
*mixer
, int val
)
615 struct snd_usb_audio
*chip
= mixer
->chip
;
617 unsigned char buff
[3];
619 err
= snd_usb_lock_shutdown(chip
);
623 /* Prepare for magic command to toggle clock source */
624 err
= snd_usb_ctl_msg(chip
->dev
,
625 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
628 USB_RECIP_INTERFACE
, 0x00, 0x500, buff
, 1);
631 err
= snd_usb_ctl_msg(chip
->dev
,
632 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
635 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
639 /* 2 possibilities: Internal -> send sample rate
640 * S/PDIF sync -> send zeroes
641 * NB: Sample rate locked to 48kHz on purpose to
642 * prevent user from resetting the sample rate
643 * while S/PDIF sync is enabled and confusing
644 * this configuration.
651 buff
[0] = buff
[1] = buff
[2] = 0x00;
654 /* Send the magic command to toggle the clock source */
655 err
= snd_usb_ctl_msg(chip
->dev
,
656 usb_sndctrlpipe(chip
->dev
, 0), 0x1,
658 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
661 err
= snd_usb_ctl_msg(chip
->dev
,
662 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
665 USB_RECIP_ENDPOINT
, 0x100, 0x81, buff
, 3);
668 err
= snd_usb_ctl_msg(chip
->dev
,
669 usb_rcvctrlpipe(chip
->dev
, 0), 0x81,
672 USB_RECIP_ENDPOINT
, 0x100, 0x2, buff
, 3);
677 snd_usb_unlock_shutdown(chip
);
681 static int snd_mbox1_switch_put(struct snd_kcontrol
*kctl
,
682 struct snd_ctl_elem_value
*ucontrol
)
684 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
685 struct usb_mixer_interface
*mixer
= list
->mixer
;
687 bool cur_val
, new_val
;
689 cur_val
= kctl
->private_value
;
690 new_val
= ucontrol
->value
.enumerated
.item
[0];
691 if (cur_val
== new_val
)
694 kctl
->private_value
= new_val
;
695 err
= snd_mbox1_switch_update(mixer
, new_val
);
696 return err
< 0 ? err
: 1;
699 static int snd_mbox1_switch_info(struct snd_kcontrol
*kcontrol
,
700 struct snd_ctl_elem_info
*uinfo
)
702 static const char *const texts
[2] = {
707 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
710 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list
*list
)
712 return snd_mbox1_switch_update(list
->mixer
, list
->kctl
->private_value
);
715 static struct snd_kcontrol_new snd_mbox1_switch
= {
716 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
717 .name
= "Clock Source",
719 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
720 .info
= snd_mbox1_switch_info
,
721 .get
= snd_mbox1_switch_get
,
722 .put
= snd_mbox1_switch_put
,
726 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface
*mixer
)
728 return add_single_ctl_with_resume(mixer
, 0,
729 snd_mbox1_switch_resume
,
730 &snd_mbox1_switch
, NULL
);
733 /* Native Instruments device quirks */
735 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
737 static int snd_ni_control_init_val(struct usb_mixer_interface
*mixer
,
738 struct snd_kcontrol
*kctl
)
740 struct usb_device
*dev
= mixer
->chip
->dev
;
741 unsigned int pval
= kctl
->private_value
;
745 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
747 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
748 0, pval
& 0xffff, &value
, 1);
751 "unable to issue vendor read request (ret = %d)", err
);
755 kctl
->private_value
|= (value
<< 24);
759 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
760 struct snd_ctl_elem_value
*ucontrol
)
762 ucontrol
->value
.integer
.value
[0] = kcontrol
->private_value
>> 24;
766 static int snd_ni_update_cur_val(struct usb_mixer_elem_list
*list
)
768 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
769 unsigned int pval
= list
->kctl
->private_value
;
772 err
= snd_usb_lock_shutdown(chip
);
775 err
= usb_control_msg(chip
->dev
, usb_sndctrlpipe(chip
->dev
, 0),
777 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
778 pval
>> 24, pval
& 0xffff, NULL
, 0, 1000);
779 snd_usb_unlock_shutdown(chip
);
783 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
784 struct snd_ctl_elem_value
*ucontrol
)
786 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
787 u8 oldval
= (kcontrol
->private_value
>> 24) & 0xff;
788 u8 newval
= ucontrol
->value
.integer
.value
[0];
791 if (oldval
== newval
)
794 kcontrol
->private_value
&= ~(0xff << 24);
795 kcontrol
->private_value
|= newval
;
796 err
= snd_ni_update_cur_val(list
);
797 return err
< 0 ? err
: 1;
800 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
802 .name
= "Direct Thru Channel A",
803 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
806 .name
= "Direct Thru Channel B",
807 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
810 .name
= "Phono Input Channel A",
811 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
814 .name
= "Phono Input Channel B",
815 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
819 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
821 .name
= "Direct Thru Channel A",
822 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
825 .name
= "Direct Thru Channel B",
826 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
829 .name
= "Direct Thru Channel C",
830 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
833 .name
= "Direct Thru Channel D",
834 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
837 .name
= "Phono Input Channel A",
838 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
841 .name
= "Phono Input Channel B",
842 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
845 .name
= "Phono Input Channel C",
846 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
849 .name
= "Phono Input Channel D",
850 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
854 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
855 const struct snd_kcontrol_new
*kc
,
859 struct snd_kcontrol_new
template = {
860 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
861 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
862 .get
= snd_nativeinstruments_control_get
,
863 .put
= snd_nativeinstruments_control_put
,
864 .info
= snd_ctl_boolean_mono_info
,
867 for (i
= 0; i
< count
; i
++) {
868 struct usb_mixer_elem_list
*list
;
870 template.name
= kc
[i
].name
;
871 template.private_value
= kc
[i
].private_value
;
873 err
= add_single_ctl_with_resume(mixer
, 0,
874 snd_ni_update_cur_val
,
878 snd_ni_control_init_val(mixer
, list
->kctl
);
884 /* M-Audio FastTrack Ultra quirks */
885 /* FTU Effect switch (also used by C400/C600) */
886 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
887 struct snd_ctl_elem_info
*uinfo
)
889 static const char *const texts
[8] = {
890 "Room 1", "Room 2", "Room 3", "Hall 1",
891 "Hall 2", "Plate", "Delay", "Echo"
894 return snd_ctl_enum_info(uinfo
, 1, ARRAY_SIZE(texts
), texts
);
897 static int snd_ftu_eff_switch_init(struct usb_mixer_interface
*mixer
,
898 struct snd_kcontrol
*kctl
)
900 struct usb_device
*dev
= mixer
->chip
->dev
;
901 unsigned int pval
= kctl
->private_value
;
903 unsigned char value
[2];
908 err
= snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), UAC_GET_CUR
,
909 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
911 snd_usb_ctrl_intf(mixer
->chip
) | ((pval
& 0xff) << 8),
916 kctl
->private_value
|= value
[0] << 24;
920 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
921 struct snd_ctl_elem_value
*ucontrol
)
923 ucontrol
->value
.enumerated
.item
[0] = kctl
->private_value
>> 24;
927 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list
*list
)
929 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
930 unsigned int pval
= list
->kctl
->private_value
;
931 unsigned char value
[2];
934 value
[0] = pval
>> 24;
937 err
= snd_usb_lock_shutdown(chip
);
940 err
= snd_usb_ctl_msg(chip
->dev
,
941 usb_sndctrlpipe(chip
->dev
, 0),
943 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
945 snd_usb_ctrl_intf(chip
) | ((pval
& 0xff) << 8),
947 snd_usb_unlock_shutdown(chip
);
951 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
952 struct snd_ctl_elem_value
*ucontrol
)
954 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kctl
);
955 unsigned int pval
= list
->kctl
->private_value
;
956 int cur_val
, err
, new_val
;
958 cur_val
= pval
>> 24;
959 new_val
= ucontrol
->value
.enumerated
.item
[0];
960 if (cur_val
== new_val
)
963 kctl
->private_value
&= ~(0xff << 24);
964 kctl
->private_value
|= new_val
<< 24;
965 err
= snd_ftu_eff_switch_update(list
);
966 return err
< 0 ? err
: 1;
969 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
970 int validx
, int bUnitID
)
972 static struct snd_kcontrol_new
template = {
973 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
974 .name
= "Effect Program Switch",
976 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
977 .info
= snd_ftu_eff_switch_info
,
978 .get
= snd_ftu_eff_switch_get
,
979 .put
= snd_ftu_eff_switch_put
981 struct usb_mixer_elem_list
*list
;
984 err
= add_single_ctl_with_resume(mixer
, bUnitID
,
985 snd_ftu_eff_switch_update
,
989 list
->kctl
->private_value
= (validx
<< 8) | bUnitID
;
990 snd_ftu_eff_switch_init(mixer
, list
->kctl
);
994 /* Create volume controls for FTU devices*/
995 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
998 unsigned int control
, cmask
;
1001 const unsigned int id
= 5;
1002 const int val_type
= USB_MIXER_S16
;
1004 for (out
= 0; out
< 8; out
++) {
1006 for (in
= 0; in
< 8; in
++) {
1008 snprintf(name
, sizeof(name
),
1009 "AIn%d - Out%d Capture Volume",
1011 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1012 cmask
, val_type
, name
,
1013 &snd_usb_mixer_vol_tlv
);
1017 for (in
= 8; in
< 16; in
++) {
1019 snprintf(name
, sizeof(name
),
1020 "DIn%d - Out%d Playback Volume",
1022 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1023 cmask
, val_type
, name
,
1024 &snd_usb_mixer_vol_tlv
);
1033 /* This control needs a volume quirk, see mixer.c */
1034 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1036 static const char name
[] = "Effect Volume";
1037 const unsigned int id
= 6;
1038 const int val_type
= USB_MIXER_U8
;
1039 const unsigned int control
= 2;
1040 const unsigned int cmask
= 0;
1042 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1043 name
, snd_usb_mixer_vol_tlv
);
1046 /* This control needs a volume quirk, see mixer.c */
1047 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1049 static const char name
[] = "Effect Duration";
1050 const unsigned int id
= 6;
1051 const int val_type
= USB_MIXER_S16
;
1052 const unsigned int control
= 3;
1053 const unsigned int cmask
= 0;
1055 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1056 name
, snd_usb_mixer_vol_tlv
);
1059 /* This control needs a volume quirk, see mixer.c */
1060 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1062 static const char name
[] = "Effect Feedback Volume";
1063 const unsigned int id
= 6;
1064 const int val_type
= USB_MIXER_U8
;
1065 const unsigned int control
= 4;
1066 const unsigned int cmask
= 0;
1068 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1072 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
1078 const unsigned int id
= 7;
1079 const int val_type
= USB_MIXER_S16
;
1080 const unsigned int control
= 7;
1082 for (ch
= 0; ch
< 4; ++ch
) {
1084 snprintf(name
, sizeof(name
),
1085 "Effect Return %d Volume", ch
+ 1);
1086 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1087 cmask
, val_type
, name
,
1088 snd_usb_mixer_vol_tlv
);
1096 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
1102 const unsigned int id
= 5;
1103 const int val_type
= USB_MIXER_S16
;
1104 const unsigned int control
= 9;
1106 for (ch
= 0; ch
< 8; ++ch
) {
1108 snprintf(name
, sizeof(name
),
1109 "Effect Send AIn%d Volume", ch
+ 1);
1110 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1112 snd_usb_mixer_vol_tlv
);
1116 for (ch
= 8; ch
< 16; ++ch
) {
1118 snprintf(name
, sizeof(name
),
1119 "Effect Send DIn%d Volume", ch
- 7);
1120 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
1122 snd_usb_mixer_vol_tlv
);
1129 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
1133 err
= snd_ftu_create_volume_ctls(mixer
);
1137 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
1141 err
= snd_ftu_create_effect_volume_ctl(mixer
);
1145 err
= snd_ftu_create_effect_duration_ctl(mixer
);
1149 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1153 err
= snd_ftu_create_effect_return_ctls(mixer
);
1157 err
= snd_ftu_create_effect_send_ctls(mixer
);
1164 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1165 unsigned char samplerate_id
)
1167 struct usb_mixer_interface
*mixer
;
1168 struct usb_mixer_elem_info
*cval
;
1169 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1171 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1172 cval
= (struct usb_mixer_elem_info
*)mixer
->id_elems
[unitid
];
1174 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1177 snd_usb_mixer_notify_id(mixer
, unitid
);
1183 /* M-Audio Fast Track C400/C600 */
1184 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1185 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1188 unsigned int cmask
, offset
;
1193 const unsigned int id
= 0x40;
1194 const int val_type
= USB_MIXER_S16
;
1195 const int control
= 1;
1197 switch (mixer
->chip
->usb_id
) {
1198 case USB_ID(0x0763, 0x2030):
1202 case USB_ID(0x0763, 0x2031):
1208 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1209 for (out
= 0; out
< num_outs
; out
++) {
1210 if (chan
< num_outs
) {
1211 snprintf(name
, sizeof(name
),
1212 "PCM%d-Out%d Playback Volume",
1215 snprintf(name
, sizeof(name
),
1216 "In%d-Out%d Playback Volume",
1217 chan
- num_outs
+ 1, out
+ 1);
1220 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1221 offset
= chan
* num_outs
;
1222 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1223 cmask
, val_type
, offset
, name
,
1224 &snd_usb_mixer_vol_tlv
);
1233 /* This control needs a volume quirk, see mixer.c */
1234 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1236 static const char name
[] = "Effect Volume";
1237 const unsigned int id
= 0x43;
1238 const int val_type
= USB_MIXER_U8
;
1239 const unsigned int control
= 3;
1240 const unsigned int cmask
= 0;
1242 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1243 name
, snd_usb_mixer_vol_tlv
);
1246 /* This control needs a volume quirk, see mixer.c */
1247 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1249 static const char name
[] = "Effect Duration";
1250 const unsigned int id
= 0x43;
1251 const int val_type
= USB_MIXER_S16
;
1252 const unsigned int control
= 4;
1253 const unsigned int cmask
= 0;
1255 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1256 name
, snd_usb_mixer_vol_tlv
);
1259 /* This control needs a volume quirk, see mixer.c */
1260 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1262 static const char name
[] = "Effect Feedback Volume";
1263 const unsigned int id
= 0x43;
1264 const int val_type
= USB_MIXER_U8
;
1265 const unsigned int control
= 5;
1266 const unsigned int cmask
= 0;
1268 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1272 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1280 const unsigned int id
= 0x42;
1281 const int val_type
= USB_MIXER_S16
;
1282 const int control
= 1;
1284 switch (mixer
->chip
->usb_id
) {
1285 case USB_ID(0x0763, 0x2030):
1289 case USB_ID(0x0763, 0x2031):
1295 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1296 if (chan
< num_outs
) {
1297 snprintf(name
, sizeof(name
),
1298 "Effect Send DOut%d",
1301 snprintf(name
, sizeof(name
),
1302 "Effect Send AIn%d",
1303 chan
- num_outs
+ 1);
1306 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1307 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1308 cmask
, val_type
, name
,
1309 &snd_usb_mixer_vol_tlv
);
1317 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1325 const unsigned int id
= 0x40;
1326 const int val_type
= USB_MIXER_S16
;
1327 const int control
= 1;
1329 switch (mixer
->chip
->usb_id
) {
1330 case USB_ID(0x0763, 0x2030):
1333 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1335 case USB_ID(0x0763, 0x2031):
1338 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1342 for (chan
= 0; chan
< num_outs
; chan
++) {
1343 snprintf(name
, sizeof(name
),
1347 cmask
= (chan
== 0) ? 0 :
1348 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1349 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1350 cmask
, val_type
, offset
, name
,
1351 &snd_usb_mixer_vol_tlv
);
1359 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1363 err
= snd_c400_create_vol_ctls(mixer
);
1367 err
= snd_c400_create_effect_vol_ctls(mixer
);
1371 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1375 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1379 err
= snd_c400_create_effect_volume_ctl(mixer
);
1383 err
= snd_c400_create_effect_duration_ctl(mixer
);
1387 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1395 * The mixer units for Ebox-44 are corrupt, and even where they
1396 * are valid they presents mono controls as L and R channels of
1397 * stereo. So we provide a good mixer here.
1399 static struct std_mono_table ebox44_table
[] = {
1404 .val_type
= USB_MIXER_INV_BOOLEAN
,
1405 .name
= "Headphone Playback Switch"
1411 .val_type
= USB_MIXER_S16
,
1412 .name
= "Headphone A Mix Playback Volume"
1418 .val_type
= USB_MIXER_S16
,
1419 .name
= "Headphone B Mix Playback Volume"
1426 .val_type
= USB_MIXER_INV_BOOLEAN
,
1427 .name
= "Output Playback Switch"
1433 .val_type
= USB_MIXER_S16
,
1434 .name
= "Output A Playback Volume"
1440 .val_type
= USB_MIXER_S16
,
1441 .name
= "Output B Playback Volume"
1448 .val_type
= USB_MIXER_INV_BOOLEAN
,
1449 .name
= "Input Capture Switch"
1455 .val_type
= USB_MIXER_S16
,
1456 .name
= "Input A Capture Volume"
1462 .val_type
= USB_MIXER_S16
,
1463 .name
= "Input B Capture Volume"
1469 /* Audio Advantage Micro II findings:
1471 * Mapping spdif AES bits to vendor register.bit:
1472 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1473 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1474 * AES2: [0 0 0 0 0 0 0 0]
1475 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1476 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1480 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1481 * just after it to 0xa0, presumably it disables/mutes some analog
1482 * parts when there is no audio.)
1485 * Optical transmitter on/off:
1486 * vendor register.bit: 9.1
1487 * 0 - on (0x28 register value)
1488 * 1 - off (0x2a register value)
1491 static int snd_microii_spdif_info(struct snd_kcontrol
*kcontrol
,
1492 struct snd_ctl_elem_info
*uinfo
)
1494 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1499 static int snd_microii_spdif_default_get(struct snd_kcontrol
*kcontrol
,
1500 struct snd_ctl_elem_value
*ucontrol
)
1502 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1503 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1505 struct usb_interface
*iface
;
1506 struct usb_host_interface
*alts
;
1508 unsigned char data
[3];
1511 err
= snd_usb_lock_shutdown(chip
);
1515 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
& 0xff;
1516 ucontrol
->value
.iec958
.status
[1] = (kcontrol
->private_value
>> 8) & 0xff;
1517 ucontrol
->value
.iec958
.status
[2] = 0x00;
1519 /* use known values for that card: interface#1 altsetting#1 */
1520 iface
= usb_ifnum_to_if(chip
->dev
, 1);
1521 alts
= &iface
->altsetting
[1];
1522 ep
= get_endpoint(alts
, 0)->bEndpointAddress
;
1524 err
= snd_usb_ctl_msg(chip
->dev
,
1525 usb_rcvctrlpipe(chip
->dev
, 0),
1527 USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
1528 UAC_EP_CS_ATTR_SAMPLE_RATE
<< 8,
1535 rate
= data
[0] | (data
[1] << 8) | (data
[2] << 16);
1536 ucontrol
->value
.iec958
.status
[3] = (rate
== 48000) ?
1537 IEC958_AES3_CON_FS_48000
: IEC958_AES3_CON_FS_44100
;
1541 snd_usb_unlock_shutdown(chip
);
1545 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list
*list
)
1547 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1548 unsigned int pval
= list
->kctl
->private_value
;
1552 err
= snd_usb_lock_shutdown(chip
);
1556 reg
= ((pval
>> 4) & 0xf0) | (pval
& 0x0f);
1557 err
= snd_usb_ctl_msg(chip
->dev
,
1558 usb_sndctrlpipe(chip
->dev
, 0),
1560 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1568 reg
= (pval
& IEC958_AES0_NONAUDIO
) ? 0xa0 : 0x20;
1569 reg
|= (pval
>> 12) & 0x0f;
1570 err
= snd_usb_ctl_msg(chip
->dev
,
1571 usb_sndctrlpipe(chip
->dev
, 0),
1573 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1582 snd_usb_unlock_shutdown(chip
);
1586 static int snd_microii_spdif_default_put(struct snd_kcontrol
*kcontrol
,
1587 struct snd_ctl_elem_value
*ucontrol
)
1589 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1590 unsigned int pval
, pval_old
;
1593 pval
= pval_old
= kcontrol
->private_value
;
1595 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0x0f) << 8;
1596 pval
|= (ucontrol
->value
.iec958
.status
[0] & 0x0f);
1599 pval
|= (ucontrol
->value
.iec958
.status
[1] & 0xf0) << 8;
1601 /* The frequency bits in AES3 cannot be set via register access. */
1603 /* Silently ignore any bits from the request that cannot be set. */
1605 if (pval
== pval_old
)
1608 kcontrol
->private_value
= pval
;
1609 err
= snd_microii_spdif_default_update(list
);
1610 return err
< 0 ? err
: 1;
1613 static int snd_microii_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
1614 struct snd_ctl_elem_value
*ucontrol
)
1616 ucontrol
->value
.iec958
.status
[0] = 0x0f;
1617 ucontrol
->value
.iec958
.status
[1] = 0xff;
1618 ucontrol
->value
.iec958
.status
[2] = 0x00;
1619 ucontrol
->value
.iec958
.status
[3] = 0x00;
1624 static int snd_microii_spdif_switch_get(struct snd_kcontrol
*kcontrol
,
1625 struct snd_ctl_elem_value
*ucontrol
)
1627 ucontrol
->value
.integer
.value
[0] = !(kcontrol
->private_value
& 0x02);
1632 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list
*list
)
1634 struct snd_usb_audio
*chip
= list
->mixer
->chip
;
1635 u8 reg
= list
->kctl
->private_value
;
1638 err
= snd_usb_lock_shutdown(chip
);
1642 err
= snd_usb_ctl_msg(chip
->dev
,
1643 usb_sndctrlpipe(chip
->dev
, 0),
1645 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
1651 snd_usb_unlock_shutdown(chip
);
1655 static int snd_microii_spdif_switch_put(struct snd_kcontrol
*kcontrol
,
1656 struct snd_ctl_elem_value
*ucontrol
)
1658 struct usb_mixer_elem_list
*list
= snd_kcontrol_chip(kcontrol
);
1662 reg
= ucontrol
->value
.integer
.value
[0] ? 0x28 : 0x2a;
1663 if (reg
!= list
->kctl
->private_value
)
1666 kcontrol
->private_value
= reg
;
1667 err
= snd_microii_spdif_switch_update(list
);
1668 return err
< 0 ? err
: 1;
1671 static struct snd_kcontrol_new snd_microii_mixer_spdif
[] = {
1673 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1674 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, DEFAULT
),
1675 .info
= snd_microii_spdif_info
,
1676 .get
= snd_microii_spdif_default_get
,
1677 .put
= snd_microii_spdif_default_put
,
1678 .private_value
= 0x00000100UL
,/* reset value */
1681 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1682 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1683 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, MASK
),
1684 .info
= snd_microii_spdif_info
,
1685 .get
= snd_microii_spdif_mask_get
,
1688 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1689 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, SWITCH
),
1690 .info
= snd_ctl_boolean_mono_info
,
1691 .get
= snd_microii_spdif_switch_get
,
1692 .put
= snd_microii_spdif_switch_put
,
1693 .private_value
= 0x00000028UL
,/* reset value */
1697 static int snd_microii_controls_create(struct usb_mixer_interface
*mixer
)
1700 static usb_mixer_elem_resume_func_t resume_funcs
[] = {
1701 snd_microii_spdif_default_update
,
1703 snd_microii_spdif_switch_update
1706 for (i
= 0; i
< ARRAY_SIZE(snd_microii_mixer_spdif
); ++i
) {
1707 err
= add_single_ctl_with_resume(mixer
, 0,
1709 &snd_microii_mixer_spdif
[i
],
1718 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1721 struct snd_info_entry
*entry
;
1723 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1726 switch (mixer
->chip
->usb_id
) {
1727 case USB_ID(0x041e, 0x3020):
1728 case USB_ID(0x041e, 0x3040):
1729 case USB_ID(0x041e, 0x3042):
1730 case USB_ID(0x041e, 0x30df):
1731 case USB_ID(0x041e, 0x3048):
1732 err
= snd_audigy2nx_controls_create(mixer
);
1735 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1736 snd_info_set_text_ops(entry
, mixer
,
1737 snd_audigy2nx_proc_read
);
1741 case USB_ID(0x041e, 0x3f19):
1742 err
= snd_emu0204_controls_create(mixer
);
1747 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1748 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1749 err
= snd_c400_create_mixer(mixer
);
1752 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1753 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1754 err
= snd_ftu_create_mixer(mixer
);
1757 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1758 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1759 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1760 err
= snd_xonar_u1_controls_create(mixer
);
1763 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1764 err
= snd_microii_controls_create(mixer
);
1767 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1768 err
= snd_mbox1_create_sync_switch(mixer
);
1771 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1772 err
= snd_nativeinstruments_create_mixer(mixer
,
1773 snd_nativeinstruments_ta6_mixers
,
1774 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1777 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1778 err
= snd_nativeinstruments_create_mixer(mixer
,
1779 snd_nativeinstruments_ta10_mixers
,
1780 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1783 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1784 /* detection is disabled in mixer_maps.c */
1785 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1788 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1789 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1790 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1791 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1792 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1793 err
= snd_scarlett_controls_create(mixer
);
1800 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1805 /* unit ids specific to Extigy/Audigy 2 NX: */
1807 case 0: /* remote control */
1808 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1809 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1811 case 4: /* digital in jack */
1812 case 7: /* line in jacks */
1813 case 19: /* speaker out jacks */
1814 case 20: /* headphones out jack */
1816 /* live24ext: 4 = line-in jack */
1817 case 3: /* hp-out jack (may actuate Mute) */
1818 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1819 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1820 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1823 usb_audio_dbg(mixer
->chip
, "memory change in unknown unit %d\n", unitid
);