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)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/usb.h>
31 #include <linux/usb/audio.h>
33 #include <sound/core.h>
34 #include <sound/control.h>
35 #include <sound/hwdep.h>
36 #include <sound/info.h>
40 #include "mixer_quirks.h"
43 extern struct snd_kcontrol_new
*snd_usb_feature_unit_ctl
;
45 struct std_mono_table
{
46 unsigned int unitid
, control
, cmask
;
49 snd_kcontrol_tlv_rw_t
*tlv_callback
;
52 /* private_free callback */
53 static void usb_mixer_elem_free(struct snd_kcontrol
*kctl
)
55 kfree(kctl
->private_data
);
56 kctl
->private_data
= NULL
;
59 /* This function allows for the creation of standard UAC controls.
60 * See the quirks for M-Audio FTUs or Ebox-44.
61 * If you don't want to set a TLV callback pass NULL.
63 * Since there doesn't seem to be a devices that needs a multichannel
64 * version, we keep it mono for simplicity.
66 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface
*mixer
,
73 snd_kcontrol_tlv_rw_t
*tlv_callback
)
76 struct usb_mixer_elem_info
*cval
;
77 struct snd_kcontrol
*kctl
;
79 cval
= kzalloc(sizeof(*cval
), GFP_KERNEL
);
85 cval
->val_type
= val_type
;
87 cval
->control
= control
;
89 cval
->idx_off
= idx_off
;
91 /* get_min_max() is called only for integer volumes later,
92 * so provide a short-cut for booleans */
100 kctl
= snd_ctl_new1(snd_usb_feature_unit_ctl
, cval
);
107 snprintf(kctl
->id
.name
, sizeof(kctl
->id
.name
), name
);
108 kctl
->private_free
= usb_mixer_elem_free
;
112 kctl
->tlv
.c
= tlv_callback
;
113 kctl
->vd
[0].access
|=
114 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
115 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
;
117 /* Add control to mixer */
118 err
= snd_usb_mixer_add_control(mixer
, kctl
);
125 static int snd_create_std_mono_ctl(struct usb_mixer_interface
*mixer
,
127 unsigned int control
,
131 snd_kcontrol_tlv_rw_t
*tlv_callback
)
133 return snd_create_std_mono_ctl_offset(mixer
, unitid
, control
, cmask
,
134 val_type
, 0 /* Offset */, name
, tlv_callback
);
138 * Create a set of standard UAC controls from a table
140 static int snd_create_std_mono_table(struct usb_mixer_interface
*mixer
,
141 struct std_mono_table
*t
)
145 while (t
->name
!= NULL
) {
146 err
= snd_create_std_mono_ctl(mixer
, t
->unitid
, t
->control
,
147 t
->cmask
, t
->val_type
, t
->name
, t
->tlv_callback
);
157 * Sound Blaster remote control configuration
159 * format of remote control data:
161 * Audigy 2 NX: 06 80 xx 00 00 00
162 * Live! 24-bit: 06 80 xx yy 22 83
164 static const struct rc_config
{
169 u8 min_packet_length
; /* minimum accepted length of the URB result */
173 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
174 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
175 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
176 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
177 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
178 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
179 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
182 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
184 struct usb_mixer_interface
*mixer
= urb
->context
;
185 const struct rc_config
*rc
= mixer
->rc_cfg
;
188 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
191 code
= mixer
->rc_buffer
[rc
->offset
];
193 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
195 /* the Mute button actually changes the mixer control */
196 if (code
== rc
->mute_code
)
197 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
198 mixer
->rc_code
= code
;
200 wake_up(&mixer
->rc_waitq
);
203 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
204 long count
, loff_t
*offset
)
206 struct usb_mixer_interface
*mixer
= hw
->private_data
;
210 if (count
!= 1 && count
!= 4)
212 err
= wait_event_interruptible(mixer
->rc_waitq
,
213 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
216 err
= put_user(rc_code
, buf
);
218 err
= put_user(rc_code
, (u32 __user
*)buf
);
220 return err
< 0 ? err
: count
;
223 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
226 struct usb_mixer_interface
*mixer
= hw
->private_data
;
228 poll_wait(file
, &mixer
->rc_waitq
, wait
);
229 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
232 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
234 struct snd_hwdep
*hwdep
;
237 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
238 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
240 if (i
>= ARRAY_SIZE(rc_configs
))
242 mixer
->rc_cfg
= &rc_configs
[i
];
244 len
= mixer
->rc_cfg
->packet_length
;
246 init_waitqueue_head(&mixer
->rc_waitq
);
247 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
250 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
251 "%s remote control", mixer
->chip
->card
->shortname
);
252 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
253 hwdep
->private_data
= mixer
;
254 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
255 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
256 hwdep
->exclusive
= 1;
258 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
261 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
262 if (!mixer
->rc_setup_packet
) {
263 usb_free_urb(mixer
->rc_urb
);
264 mixer
->rc_urb
= NULL
;
267 mixer
->rc_setup_packet
->bRequestType
=
268 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
269 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
270 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
271 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
272 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
273 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
274 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
275 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
276 snd_usb_soundblaster_remote_complete
, mixer
);
280 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
282 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
284 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
285 int index
= kcontrol
->private_value
;
287 ucontrol
->value
.integer
.value
[0] = mixer
->audigy2nx_leds
[index
];
291 static int snd_audigy2nx_led_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
293 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
294 int index
= kcontrol
->private_value
;
295 int value
= ucontrol
->value
.integer
.value
[0];
300 changed
= value
!= mixer
->audigy2nx_leds
[index
];
301 down_read(&mixer
->chip
->shutdown_rwsem
);
302 if (mixer
->chip
->shutdown
) {
306 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042))
307 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
308 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
309 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
311 /* USB X-Fi S51 Pro */
312 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df))
313 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
314 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
315 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
318 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
319 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
320 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
321 value
, index
+ 2, NULL
, 0);
323 up_read(&mixer
->chip
->shutdown_rwsem
);
326 mixer
->audigy2nx_leds
[index
] = value
;
330 static struct snd_kcontrol_new snd_audigy2nx_controls
[] = {
332 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
333 .name
= "CMSS LED Switch",
334 .info
= snd_audigy2nx_led_info
,
335 .get
= snd_audigy2nx_led_get
,
336 .put
= snd_audigy2nx_led_put
,
340 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
341 .name
= "Power LED Switch",
342 .info
= snd_audigy2nx_led_info
,
343 .get
= snd_audigy2nx_led_get
,
344 .put
= snd_audigy2nx_led_put
,
348 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
349 .name
= "Dolby Digital LED Switch",
350 .info
= snd_audigy2nx_led_info
,
351 .get
= snd_audigy2nx_led_get
,
352 .put
= snd_audigy2nx_led_put
,
357 static int snd_audigy2nx_controls_create(struct usb_mixer_interface
*mixer
)
361 for (i
= 0; i
< ARRAY_SIZE(snd_audigy2nx_controls
); ++i
) {
362 /* USB X-Fi S51 doesn't have a CMSS LED */
363 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042)) && i
== 0)
365 /* USB X-Fi S51 Pro doesn't have one either */
366 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df)) && i
== 0)
368 if (i
> 1 && /* Live24ext has 2 LEDs only */
369 (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
370 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042) ||
371 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df) ||
372 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048)))
374 err
= snd_ctl_add(mixer
->chip
->card
,
375 snd_ctl_new1(&snd_audigy2nx_controls
[i
], mixer
));
379 mixer
->audigy2nx_leds
[1] = 1; /* Power LED is on by default */
383 static void snd_audigy2nx_proc_read(struct snd_info_entry
*entry
,
384 struct snd_info_buffer
*buffer
)
386 static const struct sb_jack
{
389 } jacks_audigy2nx
[] = {
395 }, jacks_live24ext
[] = {
396 {4, "line in"}, /* &1=Line, &2=Mic*/
397 {3, "hph out"}, /* headphones */
398 {0, "RC "}, /* last command, 6 bytes see rc_config above */
401 const struct sb_jack
*jacks
;
402 struct usb_mixer_interface
*mixer
= entry
->private_data
;
406 snd_iprintf(buffer
, "%s jacks\n\n", mixer
->chip
->card
->shortname
);
407 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3020))
408 jacks
= jacks_audigy2nx
;
409 else if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
410 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
411 jacks
= jacks_live24ext
;
415 for (i
= 0; jacks
[i
].name
; ++i
) {
416 snd_iprintf(buffer
, "%s: ", jacks
[i
].name
);
417 down_read(&mixer
->chip
->shutdown_rwsem
);
418 if (mixer
->chip
->shutdown
)
421 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
422 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
423 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
424 USB_RECIP_INTERFACE
, 0,
425 jacks
[i
].unitid
<< 8, buf
, 3);
426 up_read(&mixer
->chip
->shutdown_rwsem
);
427 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
428 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
430 snd_iprintf(buffer
, "?\n");
434 /* ASUS Xonar U1 / U3 controls */
436 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
437 struct snd_ctl_elem_value
*ucontrol
)
439 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
441 ucontrol
->value
.integer
.value
[0] = !!(mixer
->xonar_u1_status
& 0x02);
445 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
446 struct snd_ctl_elem_value
*ucontrol
)
448 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
449 u8 old_status
, new_status
;
452 old_status
= mixer
->xonar_u1_status
;
453 if (ucontrol
->value
.integer
.value
[0])
454 new_status
= old_status
| 0x02;
456 new_status
= old_status
& ~0x02;
457 changed
= new_status
!= old_status
;
458 down_read(&mixer
->chip
->shutdown_rwsem
);
459 if (mixer
->chip
->shutdown
)
462 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
463 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x08,
464 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
465 50, 0, &new_status
, 1);
466 up_read(&mixer
->chip
->shutdown_rwsem
);
469 mixer
->xonar_u1_status
= new_status
;
473 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
474 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
475 .name
= "Digital Playback Switch",
476 .info
= snd_ctl_boolean_mono_info
,
477 .get
= snd_xonar_u1_switch_get
,
478 .put
= snd_xonar_u1_switch_put
,
481 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
485 err
= snd_ctl_add(mixer
->chip
->card
,
486 snd_ctl_new1(&snd_xonar_u1_output_switch
, mixer
));
489 mixer
->xonar_u1_status
= 0x05;
493 /* Native Instruments device quirks */
495 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
497 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
498 struct snd_ctl_elem_value
*ucontrol
)
500 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
501 struct usb_device
*dev
= mixer
->chip
->dev
;
502 u8 bRequest
= (kcontrol
->private_value
>> 16) & 0xff;
503 u16 wIndex
= kcontrol
->private_value
& 0xffff;
507 down_read(&mixer
->chip
->shutdown_rwsem
);
508 if (mixer
->chip
->shutdown
)
511 ret
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0), bRequest
,
512 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
514 &tmp
, sizeof(tmp
), 1000);
515 up_read(&mixer
->chip
->shutdown_rwsem
);
519 "unable to issue vendor read request (ret = %d)", ret
);
523 ucontrol
->value
.integer
.value
[0] = tmp
;
528 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
529 struct snd_ctl_elem_value
*ucontrol
)
531 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
532 struct usb_device
*dev
= mixer
->chip
->dev
;
533 u8 bRequest
= (kcontrol
->private_value
>> 16) & 0xff;
534 u16 wIndex
= kcontrol
->private_value
& 0xffff;
535 u16 wValue
= ucontrol
->value
.integer
.value
[0];
538 down_read(&mixer
->chip
->shutdown_rwsem
);
539 if (mixer
->chip
->shutdown
)
542 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0), bRequest
,
543 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
546 up_read(&mixer
->chip
->shutdown_rwsem
);
550 "unable to issue vendor write request (ret = %d)", ret
);
557 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
559 .name
= "Direct Thru Channel A",
560 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
563 .name
= "Direct Thru Channel B",
564 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
567 .name
= "Phono Input Channel A",
568 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
571 .name
= "Phono Input Channel B",
572 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
576 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
578 .name
= "Direct Thru Channel A",
579 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
582 .name
= "Direct Thru Channel B",
583 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
586 .name
= "Direct Thru Channel C",
587 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
590 .name
= "Direct Thru Channel D",
591 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
594 .name
= "Phono Input Channel A",
595 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
598 .name
= "Phono Input Channel B",
599 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
602 .name
= "Phono Input Channel C",
603 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
606 .name
= "Phono Input Channel D",
607 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
611 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
612 const struct snd_kcontrol_new
*kc
,
616 struct snd_kcontrol_new
template = {
617 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
618 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
619 .get
= snd_nativeinstruments_control_get
,
620 .put
= snd_nativeinstruments_control_put
,
621 .info
= snd_ctl_boolean_mono_info
,
624 for (i
= 0; i
< count
; i
++) {
625 struct snd_kcontrol
*c
;
627 template.name
= kc
[i
].name
;
628 template.private_value
= kc
[i
].private_value
;
630 c
= snd_ctl_new1(&template, mixer
);
631 err
= snd_ctl_add(mixer
->chip
->card
, c
);
640 /* M-Audio FastTrack Ultra quirks */
641 /* FTU Effect switch (also used by C400/C600) */
642 struct snd_ftu_eff_switch_priv_val
{
643 struct usb_mixer_interface
*mixer
;
650 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
651 struct snd_ctl_elem_info
*uinfo
)
653 static const char *texts
[8] = {"Room 1",
663 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
665 uinfo
->value
.enumerated
.items
= 8;
666 if (uinfo
->value
.enumerated
.item
> 7)
667 uinfo
->value
.enumerated
.item
= 7;
668 strcpy(uinfo
->value
.enumerated
.name
,
669 texts
[uinfo
->value
.enumerated
.item
]);
674 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
675 struct snd_ctl_elem_value
*ucontrol
)
677 struct snd_usb_audio
*chip
;
678 struct usb_mixer_interface
*mixer
;
679 struct snd_ftu_eff_switch_priv_val
*pval
;
681 unsigned char value
[2];
684 const int val_len
= 2;
689 pval
= (struct snd_ftu_eff_switch_priv_val
*)
692 if (pval
->is_cached
) {
693 ucontrol
->value
.enumerated
.item
[0] = pval
->cached_value
;
697 mixer
= (struct usb_mixer_interface
*) pval
->mixer
;
698 if (snd_BUG_ON(!mixer
))
701 chip
= (struct snd_usb_audio
*) mixer
->chip
;
702 if (snd_BUG_ON(!chip
))
706 validx
= pval
->validx
;
708 down_read(&mixer
->chip
->shutdown_rwsem
);
709 if (mixer
->chip
->shutdown
)
712 err
= snd_usb_ctl_msg(chip
->dev
,
713 usb_rcvctrlpipe(chip
->dev
, 0), UAC_GET_CUR
,
714 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
715 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
717 up_read(&mixer
->chip
->shutdown_rwsem
);
721 ucontrol
->value
.enumerated
.item
[0] = value
[0];
722 pval
->cached_value
= value
[0];
728 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
729 struct snd_ctl_elem_value
*ucontrol
)
731 struct snd_usb_audio
*chip
;
732 struct snd_ftu_eff_switch_priv_val
*pval
;
734 struct usb_mixer_interface
*mixer
;
735 int changed
, cur_val
, err
, new_val
;
736 unsigned char value
[2];
739 const int val_len
= 2;
743 pval
= (struct snd_ftu_eff_switch_priv_val
*)
745 cur_val
= pval
->cached_value
;
746 new_val
= ucontrol
->value
.enumerated
.item
[0];
748 mixer
= (struct usb_mixer_interface
*) pval
->mixer
;
749 if (snd_BUG_ON(!mixer
))
752 chip
= (struct snd_usb_audio
*) mixer
->chip
;
753 if (snd_BUG_ON(!chip
))
757 validx
= pval
->validx
;
759 if (!pval
->is_cached
) {
760 /* Read current value */
761 down_read(&mixer
->chip
->shutdown_rwsem
);
762 if (mixer
->chip
->shutdown
)
765 err
= snd_usb_ctl_msg(chip
->dev
,
766 usb_rcvctrlpipe(chip
->dev
, 0), UAC_GET_CUR
,
767 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
768 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
770 up_read(&mixer
->chip
->shutdown_rwsem
);
775 pval
->cached_value
= cur_val
;
778 /* update value if needed */
779 if (cur_val
!= new_val
) {
782 down_read(&mixer
->chip
->shutdown_rwsem
);
783 if (mixer
->chip
->shutdown
)
786 err
= snd_usb_ctl_msg(chip
->dev
,
787 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
788 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
789 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
791 up_read(&mixer
->chip
->shutdown_rwsem
);
795 pval
->cached_value
= new_val
;
803 static void kctl_private_value_free(struct snd_kcontrol
*kctl
)
805 kfree((void *)kctl
->private_value
);
808 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
809 int validx
, int bUnitID
)
811 static struct snd_kcontrol_new
template = {
812 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
813 .name
= "Effect Program Switch",
815 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
816 .info
= snd_ftu_eff_switch_info
,
817 .get
= snd_ftu_eff_switch_get
,
818 .put
= snd_ftu_eff_switch_put
822 struct snd_kcontrol
*kctl
;
823 struct snd_ftu_eff_switch_priv_val
*pval
;
825 pval
= kzalloc(sizeof(*pval
), GFP_KERNEL
);
829 pval
->cached_value
= 0;
832 pval
->bUnitID
= bUnitID
;
833 pval
->validx
= validx
;
835 template.private_value
= (unsigned long) pval
;
836 kctl
= snd_ctl_new1(&template, mixer
->chip
);
842 kctl
->private_free
= kctl_private_value_free
;
843 err
= snd_ctl_add(mixer
->chip
->card
, kctl
);
850 /* Create volume controls for FTU devices*/
851 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
854 unsigned int control
, cmask
;
857 const unsigned int id
= 5;
858 const int val_type
= USB_MIXER_S16
;
860 for (out
= 0; out
< 8; out
++) {
862 for (in
= 0; in
< 8; in
++) {
864 snprintf(name
, sizeof(name
),
865 "AIn%d - Out%d Capture Volume",
867 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
868 cmask
, val_type
, name
,
869 &snd_usb_mixer_vol_tlv
);
873 for (in
= 8; in
< 16; in
++) {
875 snprintf(name
, sizeof(name
),
876 "DIn%d - Out%d Playback Volume",
878 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
879 cmask
, val_type
, name
,
880 &snd_usb_mixer_vol_tlv
);
889 /* This control needs a volume quirk, see mixer.c */
890 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
892 static const char name
[] = "Effect Volume";
893 const unsigned int id
= 6;
894 const int val_type
= USB_MIXER_U8
;
895 const unsigned int control
= 2;
896 const unsigned int cmask
= 0;
898 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
899 name
, snd_usb_mixer_vol_tlv
);
902 /* This control needs a volume quirk, see mixer.c */
903 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
905 static const char name
[] = "Effect Duration";
906 const unsigned int id
= 6;
907 const int val_type
= USB_MIXER_S16
;
908 const unsigned int control
= 3;
909 const unsigned int cmask
= 0;
911 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
912 name
, snd_usb_mixer_vol_tlv
);
915 /* This control needs a volume quirk, see mixer.c */
916 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
918 static const char name
[] = "Effect Feedback Volume";
919 const unsigned int id
= 6;
920 const int val_type
= USB_MIXER_U8
;
921 const unsigned int control
= 4;
922 const unsigned int cmask
= 0;
924 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
928 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
934 const unsigned int id
= 7;
935 const int val_type
= USB_MIXER_S16
;
936 const unsigned int control
= 7;
938 for (ch
= 0; ch
< 4; ++ch
) {
940 snprintf(name
, sizeof(name
),
941 "Effect Return %d Volume", ch
+ 1);
942 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
943 cmask
, val_type
, name
,
944 snd_usb_mixer_vol_tlv
);
952 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
958 const unsigned int id
= 5;
959 const int val_type
= USB_MIXER_S16
;
960 const unsigned int control
= 9;
962 for (ch
= 0; ch
< 8; ++ch
) {
964 snprintf(name
, sizeof(name
),
965 "Effect Send AIn%d Volume", ch
+ 1);
966 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
968 snd_usb_mixer_vol_tlv
);
972 for (ch
= 8; ch
< 16; ++ch
) {
974 snprintf(name
, sizeof(name
),
975 "Effect Send DIn%d Volume", ch
- 7);
976 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
978 snd_usb_mixer_vol_tlv
);
985 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
989 err
= snd_ftu_create_volume_ctls(mixer
);
993 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
997 err
= snd_ftu_create_effect_volume_ctl(mixer
);
1001 err
= snd_ftu_create_effect_duration_ctl(mixer
);
1005 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1009 err
= snd_ftu_create_effect_return_ctls(mixer
);
1013 err
= snd_ftu_create_effect_send_ctls(mixer
);
1020 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1021 unsigned char samplerate_id
)
1023 struct usb_mixer_interface
*mixer
;
1024 struct usb_mixer_elem_info
*cval
;
1025 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1027 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1028 cval
= mixer
->id_elems
[unitid
];
1030 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1033 snd_usb_mixer_notify_id(mixer
, unitid
);
1039 /* M-Audio Fast Track C400/C600 */
1040 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1041 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1044 unsigned int cmask
, offset
;
1049 const unsigned int id
= 0x40;
1050 const int val_type
= USB_MIXER_S16
;
1051 const int control
= 1;
1053 switch (mixer
->chip
->usb_id
) {
1054 case USB_ID(0x0763, 0x2030):
1058 case USB_ID(0x0763, 0x2031):
1064 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1065 for (out
= 0; out
< num_outs
; out
++) {
1066 if (chan
< num_outs
) {
1067 snprintf(name
, sizeof(name
),
1068 "PCM%d-Out%d Playback Volume",
1071 snprintf(name
, sizeof(name
),
1072 "In%d-Out%d Playback Volume",
1073 chan
- num_outs
+ 1, out
+ 1);
1076 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1077 offset
= chan
* num_outs
;
1078 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1079 cmask
, val_type
, offset
, name
,
1080 &snd_usb_mixer_vol_tlv
);
1089 /* This control needs a volume quirk, see mixer.c */
1090 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1092 static const char name
[] = "Effect Volume";
1093 const unsigned int id
= 0x43;
1094 const int val_type
= USB_MIXER_U8
;
1095 const unsigned int control
= 3;
1096 const unsigned int cmask
= 0;
1098 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1099 name
, snd_usb_mixer_vol_tlv
);
1102 /* This control needs a volume quirk, see mixer.c */
1103 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1105 static const char name
[] = "Effect Duration";
1106 const unsigned int id
= 0x43;
1107 const int val_type
= USB_MIXER_S16
;
1108 const unsigned int control
= 4;
1109 const unsigned int cmask
= 0;
1111 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1112 name
, snd_usb_mixer_vol_tlv
);
1115 /* This control needs a volume quirk, see mixer.c */
1116 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1118 static const char name
[] = "Effect Feedback Volume";
1119 const unsigned int id
= 0x43;
1120 const int val_type
= USB_MIXER_U8
;
1121 const unsigned int control
= 5;
1122 const unsigned int cmask
= 0;
1124 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1128 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1136 const unsigned int id
= 0x42;
1137 const int val_type
= USB_MIXER_S16
;
1138 const int control
= 1;
1140 switch (mixer
->chip
->usb_id
) {
1141 case USB_ID(0x0763, 0x2030):
1145 case USB_ID(0x0763, 0x2031):
1151 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1152 if (chan
< num_outs
) {
1153 snprintf(name
, sizeof(name
),
1154 "Effect Send DOut%d",
1157 snprintf(name
, sizeof(name
),
1158 "Effect Send AIn%d",
1159 chan
- num_outs
+ 1);
1162 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1163 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1164 cmask
, val_type
, name
,
1165 &snd_usb_mixer_vol_tlv
);
1173 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1181 const unsigned int id
= 0x40;
1182 const int val_type
= USB_MIXER_S16
;
1183 const int control
= 1;
1185 switch (mixer
->chip
->usb_id
) {
1186 case USB_ID(0x0763, 0x2030):
1189 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1191 case USB_ID(0x0763, 0x2031):
1194 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1198 for (chan
= 0; chan
< num_outs
; chan
++) {
1199 snprintf(name
, sizeof(name
),
1203 cmask
= (chan
== 0) ? 0 :
1204 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1205 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1206 cmask
, val_type
, offset
, name
,
1207 &snd_usb_mixer_vol_tlv
);
1215 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1219 err
= snd_c400_create_vol_ctls(mixer
);
1223 err
= snd_c400_create_effect_vol_ctls(mixer
);
1227 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1231 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1235 err
= snd_c400_create_effect_volume_ctl(mixer
);
1239 err
= snd_c400_create_effect_duration_ctl(mixer
);
1243 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1251 * The mixer units for Ebox-44 are corrupt, and even where they
1252 * are valid they presents mono controls as L and R channels of
1253 * stereo. So we provide a good mixer here.
1255 static struct std_mono_table ebox44_table
[] = {
1260 .val_type
= USB_MIXER_INV_BOOLEAN
,
1261 .name
= "Headphone Playback Switch"
1267 .val_type
= USB_MIXER_S16
,
1268 .name
= "Headphone A Mix Playback Volume"
1274 .val_type
= USB_MIXER_S16
,
1275 .name
= "Headphone B Mix Playback Volume"
1282 .val_type
= USB_MIXER_INV_BOOLEAN
,
1283 .name
= "Output Playback Switch"
1289 .val_type
= USB_MIXER_S16
,
1290 .name
= "Output A Playback Volume"
1296 .val_type
= USB_MIXER_S16
,
1297 .name
= "Output B Playback Volume"
1304 .val_type
= USB_MIXER_INV_BOOLEAN
,
1305 .name
= "Input Capture Switch"
1311 .val_type
= USB_MIXER_S16
,
1312 .name
= "Input A Capture Volume"
1318 .val_type
= USB_MIXER_S16
,
1319 .name
= "Input B Capture Volume"
1325 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1328 struct snd_info_entry
*entry
;
1330 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1333 switch (mixer
->chip
->usb_id
) {
1334 case USB_ID(0x041e, 0x3020):
1335 case USB_ID(0x041e, 0x3040):
1336 case USB_ID(0x041e, 0x3042):
1337 case USB_ID(0x041e, 0x30df):
1338 case USB_ID(0x041e, 0x3048):
1339 err
= snd_audigy2nx_controls_create(mixer
);
1342 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1343 snd_info_set_text_ops(entry
, mixer
,
1344 snd_audigy2nx_proc_read
);
1347 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1348 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1349 err
= snd_c400_create_mixer(mixer
);
1352 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1353 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1354 err
= snd_ftu_create_mixer(mixer
);
1357 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1358 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1359 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1360 err
= snd_xonar_u1_controls_create(mixer
);
1363 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1364 err
= snd_nativeinstruments_create_mixer(mixer
,
1365 snd_nativeinstruments_ta6_mixers
,
1366 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1369 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1370 err
= snd_nativeinstruments_create_mixer(mixer
,
1371 snd_nativeinstruments_ta10_mixers
,
1372 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1375 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1376 /* detection is disabled in mixer_maps.c */
1377 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1384 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1389 /* unit ids specific to Extigy/Audigy 2 NX: */
1391 case 0: /* remote control */
1392 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1393 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1395 case 4: /* digital in jack */
1396 case 7: /* line in jacks */
1397 case 19: /* speaker out jacks */
1398 case 20: /* headphones out jack */
1400 /* live24ext: 4 = line-in jack */
1401 case 3: /* hp-out jack (may actuate Mute) */
1402 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1403 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1404 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1407 snd_printd(KERN_DEBUG
"memory change in unknown unit %d\n", unitid
);