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, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
181 static void snd_usb_soundblaster_remote_complete(struct urb
*urb
)
183 struct usb_mixer_interface
*mixer
= urb
->context
;
184 const struct rc_config
*rc
= mixer
->rc_cfg
;
187 if (urb
->status
< 0 || urb
->actual_length
< rc
->min_packet_length
)
190 code
= mixer
->rc_buffer
[rc
->offset
];
192 code
|= mixer
->rc_buffer
[rc
->offset
+ 1] << 8;
194 /* the Mute button actually changes the mixer control */
195 if (code
== rc
->mute_code
)
196 snd_usb_mixer_notify_id(mixer
, rc
->mute_mixer_id
);
197 mixer
->rc_code
= code
;
199 wake_up(&mixer
->rc_waitq
);
202 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep
*hw
, char __user
*buf
,
203 long count
, loff_t
*offset
)
205 struct usb_mixer_interface
*mixer
= hw
->private_data
;
209 if (count
!= 1 && count
!= 4)
211 err
= wait_event_interruptible(mixer
->rc_waitq
,
212 (rc_code
= xchg(&mixer
->rc_code
, 0)) != 0);
215 err
= put_user(rc_code
, buf
);
217 err
= put_user(rc_code
, (u32 __user
*)buf
);
219 return err
< 0 ? err
: count
;
222 static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep
*hw
, struct file
*file
,
225 struct usb_mixer_interface
*mixer
= hw
->private_data
;
227 poll_wait(file
, &mixer
->rc_waitq
, wait
);
228 return mixer
->rc_code
? POLLIN
| POLLRDNORM
: 0;
231 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface
*mixer
)
233 struct snd_hwdep
*hwdep
;
236 for (i
= 0; i
< ARRAY_SIZE(rc_configs
); ++i
)
237 if (rc_configs
[i
].usb_id
== mixer
->chip
->usb_id
)
239 if (i
>= ARRAY_SIZE(rc_configs
))
241 mixer
->rc_cfg
= &rc_configs
[i
];
243 len
= mixer
->rc_cfg
->packet_length
;
245 init_waitqueue_head(&mixer
->rc_waitq
);
246 err
= snd_hwdep_new(mixer
->chip
->card
, "SB remote control", 0, &hwdep
);
249 snprintf(hwdep
->name
, sizeof(hwdep
->name
),
250 "%s remote control", mixer
->chip
->card
->shortname
);
251 hwdep
->iface
= SNDRV_HWDEP_IFACE_SB_RC
;
252 hwdep
->private_data
= mixer
;
253 hwdep
->ops
.read
= snd_usb_sbrc_hwdep_read
;
254 hwdep
->ops
.poll
= snd_usb_sbrc_hwdep_poll
;
255 hwdep
->exclusive
= 1;
257 mixer
->rc_urb
= usb_alloc_urb(0, GFP_KERNEL
);
260 mixer
->rc_setup_packet
= kmalloc(sizeof(*mixer
->rc_setup_packet
), GFP_KERNEL
);
261 if (!mixer
->rc_setup_packet
) {
262 usb_free_urb(mixer
->rc_urb
);
263 mixer
->rc_urb
= NULL
;
266 mixer
->rc_setup_packet
->bRequestType
=
267 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
268 mixer
->rc_setup_packet
->bRequest
= UAC_GET_MEM
;
269 mixer
->rc_setup_packet
->wValue
= cpu_to_le16(0);
270 mixer
->rc_setup_packet
->wIndex
= cpu_to_le16(0);
271 mixer
->rc_setup_packet
->wLength
= cpu_to_le16(len
);
272 usb_fill_control_urb(mixer
->rc_urb
, mixer
->chip
->dev
,
273 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
274 (u8
*)mixer
->rc_setup_packet
, mixer
->rc_buffer
, len
,
275 snd_usb_soundblaster_remote_complete
, mixer
);
279 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
281 static int snd_audigy2nx_led_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
283 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
284 int index
= kcontrol
->private_value
;
286 ucontrol
->value
.integer
.value
[0] = mixer
->audigy2nx_leds
[index
];
290 static int snd_audigy2nx_led_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
292 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
293 int index
= kcontrol
->private_value
;
294 int value
= ucontrol
->value
.integer
.value
[0];
299 changed
= value
!= mixer
->audigy2nx_leds
[index
];
300 down_read(&mixer
->chip
->shutdown_rwsem
);
301 if (mixer
->chip
->shutdown
) {
305 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042))
306 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
307 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
308 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
310 /* USB X-Fi S51 Pro */
311 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df))
312 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
313 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
314 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
317 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
318 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x24,
319 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
320 value
, index
+ 2, NULL
, 0);
322 up_read(&mixer
->chip
->shutdown_rwsem
);
325 mixer
->audigy2nx_leds
[index
] = value
;
329 static struct snd_kcontrol_new snd_audigy2nx_controls
[] = {
331 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
332 .name
= "CMSS LED Switch",
333 .info
= snd_audigy2nx_led_info
,
334 .get
= snd_audigy2nx_led_get
,
335 .put
= snd_audigy2nx_led_put
,
339 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
340 .name
= "Power LED Switch",
341 .info
= snd_audigy2nx_led_info
,
342 .get
= snd_audigy2nx_led_get
,
343 .put
= snd_audigy2nx_led_put
,
347 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
348 .name
= "Dolby Digital LED Switch",
349 .info
= snd_audigy2nx_led_info
,
350 .get
= snd_audigy2nx_led_get
,
351 .put
= snd_audigy2nx_led_put
,
356 static int snd_audigy2nx_controls_create(struct usb_mixer_interface
*mixer
)
360 for (i
= 0; i
< ARRAY_SIZE(snd_audigy2nx_controls
); ++i
) {
361 /* USB X-Fi S51 doesn't have a CMSS LED */
362 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042)) && i
== 0)
364 /* USB X-Fi S51 Pro doesn't have one either */
365 if ((mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df)) && i
== 0)
367 if (i
> 1 && /* Live24ext has 2 LEDs only */
368 (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
369 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3042) ||
370 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x30df) ||
371 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048)))
373 err
= snd_ctl_add(mixer
->chip
->card
,
374 snd_ctl_new1(&snd_audigy2nx_controls
[i
], mixer
));
378 mixer
->audigy2nx_leds
[1] = 1; /* Power LED is on by default */
382 static void snd_audigy2nx_proc_read(struct snd_info_entry
*entry
,
383 struct snd_info_buffer
*buffer
)
385 static const struct sb_jack
{
388 } jacks_audigy2nx
[] = {
394 }, jacks_live24ext
[] = {
395 {4, "line in"}, /* &1=Line, &2=Mic*/
396 {3, "hph out"}, /* headphones */
397 {0, "RC "}, /* last command, 6 bytes see rc_config above */
400 const struct sb_jack
*jacks
;
401 struct usb_mixer_interface
*mixer
= entry
->private_data
;
405 snd_iprintf(buffer
, "%s jacks\n\n", mixer
->chip
->card
->shortname
);
406 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3020))
407 jacks
= jacks_audigy2nx
;
408 else if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
409 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
410 jacks
= jacks_live24ext
;
414 for (i
= 0; jacks
[i
].name
; ++i
) {
415 snd_iprintf(buffer
, "%s: ", jacks
[i
].name
);
416 down_read(&mixer
->chip
->shutdown_rwsem
);
417 if (mixer
->chip
->shutdown
)
420 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
421 usb_rcvctrlpipe(mixer
->chip
->dev
, 0),
422 UAC_GET_MEM
, USB_DIR_IN
| USB_TYPE_CLASS
|
423 USB_RECIP_INTERFACE
, 0,
424 jacks
[i
].unitid
<< 8, buf
, 3);
425 up_read(&mixer
->chip
->shutdown_rwsem
);
426 if (err
== 3 && (buf
[0] == 3 || buf
[0] == 6))
427 snd_iprintf(buffer
, "%02x %02x\n", buf
[1], buf
[2]);
429 snd_iprintf(buffer
, "?\n");
433 /* ASUS Xonar U1 / U3 controls */
435 static int snd_xonar_u1_switch_get(struct snd_kcontrol
*kcontrol
,
436 struct snd_ctl_elem_value
*ucontrol
)
438 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
440 ucontrol
->value
.integer
.value
[0] = !!(mixer
->xonar_u1_status
& 0x02);
444 static int snd_xonar_u1_switch_put(struct snd_kcontrol
*kcontrol
,
445 struct snd_ctl_elem_value
*ucontrol
)
447 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
448 u8 old_status
, new_status
;
451 old_status
= mixer
->xonar_u1_status
;
452 if (ucontrol
->value
.integer
.value
[0])
453 new_status
= old_status
| 0x02;
455 new_status
= old_status
& ~0x02;
456 changed
= new_status
!= old_status
;
457 down_read(&mixer
->chip
->shutdown_rwsem
);
458 if (mixer
->chip
->shutdown
)
461 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
462 usb_sndctrlpipe(mixer
->chip
->dev
, 0), 0x08,
463 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
464 50, 0, &new_status
, 1);
465 up_read(&mixer
->chip
->shutdown_rwsem
);
468 mixer
->xonar_u1_status
= new_status
;
472 static struct snd_kcontrol_new snd_xonar_u1_output_switch
= {
473 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
474 .name
= "Digital Playback Switch",
475 .info
= snd_ctl_boolean_mono_info
,
476 .get
= snd_xonar_u1_switch_get
,
477 .put
= snd_xonar_u1_switch_put
,
480 static int snd_xonar_u1_controls_create(struct usb_mixer_interface
*mixer
)
484 err
= snd_ctl_add(mixer
->chip
->card
,
485 snd_ctl_new1(&snd_xonar_u1_output_switch
, mixer
));
488 mixer
->xonar_u1_status
= 0x05;
492 /* Native Instruments device quirks */
494 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
496 static int snd_nativeinstruments_control_get(struct snd_kcontrol
*kcontrol
,
497 struct snd_ctl_elem_value
*ucontrol
)
499 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
500 struct usb_device
*dev
= mixer
->chip
->dev
;
501 u8 bRequest
= (kcontrol
->private_value
>> 16) & 0xff;
502 u16 wIndex
= kcontrol
->private_value
& 0xffff;
506 down_read(&mixer
->chip
->shutdown_rwsem
);
507 if (mixer
->chip
->shutdown
)
510 ret
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0), bRequest
,
511 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
513 &tmp
, sizeof(tmp
), 1000);
514 up_read(&mixer
->chip
->shutdown_rwsem
);
518 "unable to issue vendor read request (ret = %d)", ret
);
522 ucontrol
->value
.integer
.value
[0] = tmp
;
527 static int snd_nativeinstruments_control_put(struct snd_kcontrol
*kcontrol
,
528 struct snd_ctl_elem_value
*ucontrol
)
530 struct usb_mixer_interface
*mixer
= snd_kcontrol_chip(kcontrol
);
531 struct usb_device
*dev
= mixer
->chip
->dev
;
532 u8 bRequest
= (kcontrol
->private_value
>> 16) & 0xff;
533 u16 wIndex
= kcontrol
->private_value
& 0xffff;
534 u16 wValue
= ucontrol
->value
.integer
.value
[0];
537 down_read(&mixer
->chip
->shutdown_rwsem
);
538 if (mixer
->chip
->shutdown
)
541 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0), bRequest
,
542 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
545 up_read(&mixer
->chip
->shutdown_rwsem
);
549 "unable to issue vendor write request (ret = %d)", ret
);
556 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers
[] = {
558 .name
= "Direct Thru Channel A",
559 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
562 .name
= "Direct Thru Channel B",
563 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
566 .name
= "Phono Input Channel A",
567 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
570 .name
= "Phono Input Channel B",
571 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
575 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers
[] = {
577 .name
= "Direct Thru Channel A",
578 .private_value
= _MAKE_NI_CONTROL(0x01, 0x03),
581 .name
= "Direct Thru Channel B",
582 .private_value
= _MAKE_NI_CONTROL(0x01, 0x05),
585 .name
= "Direct Thru Channel C",
586 .private_value
= _MAKE_NI_CONTROL(0x01, 0x07),
589 .name
= "Direct Thru Channel D",
590 .private_value
= _MAKE_NI_CONTROL(0x01, 0x09),
593 .name
= "Phono Input Channel A",
594 .private_value
= _MAKE_NI_CONTROL(0x02, 0x03),
597 .name
= "Phono Input Channel B",
598 .private_value
= _MAKE_NI_CONTROL(0x02, 0x05),
601 .name
= "Phono Input Channel C",
602 .private_value
= _MAKE_NI_CONTROL(0x02, 0x07),
605 .name
= "Phono Input Channel D",
606 .private_value
= _MAKE_NI_CONTROL(0x02, 0x09),
610 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface
*mixer
,
611 const struct snd_kcontrol_new
*kc
,
615 struct snd_kcontrol_new
template = {
616 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
617 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
618 .get
= snd_nativeinstruments_control_get
,
619 .put
= snd_nativeinstruments_control_put
,
620 .info
= snd_ctl_boolean_mono_info
,
623 for (i
= 0; i
< count
; i
++) {
624 struct snd_kcontrol
*c
;
626 template.name
= kc
[i
].name
;
627 template.private_value
= kc
[i
].private_value
;
629 c
= snd_ctl_new1(&template, mixer
);
630 err
= snd_ctl_add(mixer
->chip
->card
, c
);
639 /* M-Audio FastTrack Ultra quirks */
640 /* FTU Effect switch (also used by C400/C600) */
641 struct snd_ftu_eff_switch_priv_val
{
642 struct usb_mixer_interface
*mixer
;
649 static int snd_ftu_eff_switch_info(struct snd_kcontrol
*kcontrol
,
650 struct snd_ctl_elem_info
*uinfo
)
652 static const char *texts
[8] = {"Room 1",
662 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
664 uinfo
->value
.enumerated
.items
= 8;
665 if (uinfo
->value
.enumerated
.item
> 7)
666 uinfo
->value
.enumerated
.item
= 7;
667 strcpy(uinfo
->value
.enumerated
.name
,
668 texts
[uinfo
->value
.enumerated
.item
]);
673 static int snd_ftu_eff_switch_get(struct snd_kcontrol
*kctl
,
674 struct snd_ctl_elem_value
*ucontrol
)
676 struct snd_usb_audio
*chip
;
677 struct usb_mixer_interface
*mixer
;
678 struct snd_ftu_eff_switch_priv_val
*pval
;
680 unsigned char value
[2];
683 const int val_len
= 2;
688 pval
= (struct snd_ftu_eff_switch_priv_val
*)
691 if (pval
->is_cached
) {
692 ucontrol
->value
.enumerated
.item
[0] = pval
->cached_value
;
696 mixer
= (struct usb_mixer_interface
*) pval
->mixer
;
697 if (snd_BUG_ON(!mixer
))
700 chip
= (struct snd_usb_audio
*) mixer
->chip
;
701 if (snd_BUG_ON(!chip
))
705 validx
= pval
->validx
;
707 down_read(&mixer
->chip
->shutdown_rwsem
);
708 if (mixer
->chip
->shutdown
)
711 err
= snd_usb_ctl_msg(chip
->dev
,
712 usb_rcvctrlpipe(chip
->dev
, 0), UAC_GET_CUR
,
713 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
714 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
716 up_read(&mixer
->chip
->shutdown_rwsem
);
720 ucontrol
->value
.enumerated
.item
[0] = value
[0];
721 pval
->cached_value
= value
[0];
727 static int snd_ftu_eff_switch_put(struct snd_kcontrol
*kctl
,
728 struct snd_ctl_elem_value
*ucontrol
)
730 struct snd_usb_audio
*chip
;
731 struct snd_ftu_eff_switch_priv_val
*pval
;
733 struct usb_mixer_interface
*mixer
;
734 int changed
, cur_val
, err
, new_val
;
735 unsigned char value
[2];
738 const int val_len
= 2;
742 pval
= (struct snd_ftu_eff_switch_priv_val
*)
744 cur_val
= pval
->cached_value
;
745 new_val
= ucontrol
->value
.enumerated
.item
[0];
747 mixer
= (struct usb_mixer_interface
*) pval
->mixer
;
748 if (snd_BUG_ON(!mixer
))
751 chip
= (struct snd_usb_audio
*) mixer
->chip
;
752 if (snd_BUG_ON(!chip
))
756 validx
= pval
->validx
;
758 if (!pval
->is_cached
) {
759 /* Read current value */
760 down_read(&mixer
->chip
->shutdown_rwsem
);
761 if (mixer
->chip
->shutdown
)
764 err
= snd_usb_ctl_msg(chip
->dev
,
765 usb_rcvctrlpipe(chip
->dev
, 0), UAC_GET_CUR
,
766 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_IN
,
767 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
769 up_read(&mixer
->chip
->shutdown_rwsem
);
774 pval
->cached_value
= cur_val
;
777 /* update value if needed */
778 if (cur_val
!= new_val
) {
781 down_read(&mixer
->chip
->shutdown_rwsem
);
782 if (mixer
->chip
->shutdown
)
785 err
= snd_usb_ctl_msg(chip
->dev
,
786 usb_sndctrlpipe(chip
->dev
, 0), UAC_SET_CUR
,
787 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
788 validx
<< 8, snd_usb_ctrl_intf(chip
) | (id
<< 8),
790 up_read(&mixer
->chip
->shutdown_rwsem
);
794 pval
->cached_value
= new_val
;
802 static int snd_ftu_create_effect_switch(struct usb_mixer_interface
*mixer
,
803 int validx
, int bUnitID
)
805 static struct snd_kcontrol_new
template = {
806 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
807 .name
= "Effect Program Switch",
809 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
810 .info
= snd_ftu_eff_switch_info
,
811 .get
= snd_ftu_eff_switch_get
,
812 .put
= snd_ftu_eff_switch_put
816 struct snd_kcontrol
*kctl
;
817 struct snd_ftu_eff_switch_priv_val
*pval
;
819 pval
= kzalloc(sizeof(*pval
), GFP_KERNEL
);
823 pval
->cached_value
= 0;
826 pval
->bUnitID
= bUnitID
;
827 pval
->validx
= validx
;
829 template.private_value
= (unsigned long) pval
;
830 kctl
= snd_ctl_new1(&template, mixer
->chip
);
836 err
= snd_ctl_add(mixer
->chip
->card
, kctl
);
843 /* Create volume controls for FTU devices*/
844 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface
*mixer
)
847 unsigned int control
, cmask
;
850 const unsigned int id
= 5;
851 const int val_type
= USB_MIXER_S16
;
853 for (out
= 0; out
< 8; out
++) {
855 for (in
= 0; in
< 8; in
++) {
857 snprintf(name
, sizeof(name
),
858 "AIn%d - Out%d Capture Volume",
860 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
861 cmask
, val_type
, name
,
862 &snd_usb_mixer_vol_tlv
);
866 for (in
= 8; in
< 16; in
++) {
868 snprintf(name
, sizeof(name
),
869 "DIn%d - Out%d Playback Volume",
871 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
872 cmask
, val_type
, name
,
873 &snd_usb_mixer_vol_tlv
);
882 /* This control needs a volume quirk, see mixer.c */
883 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
885 static const char name
[] = "Effect Volume";
886 const unsigned int id
= 6;
887 const int val_type
= USB_MIXER_U8
;
888 const unsigned int control
= 2;
889 const unsigned int cmask
= 0;
891 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
892 name
, snd_usb_mixer_vol_tlv
);
895 /* This control needs a volume quirk, see mixer.c */
896 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
898 static const char name
[] = "Effect Duration";
899 const unsigned int id
= 6;
900 const int val_type
= USB_MIXER_S16
;
901 const unsigned int control
= 3;
902 const unsigned int cmask
= 0;
904 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
905 name
, snd_usb_mixer_vol_tlv
);
908 /* This control needs a volume quirk, see mixer.c */
909 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
911 static const char name
[] = "Effect Feedback Volume";
912 const unsigned int id
= 6;
913 const int val_type
= USB_MIXER_U8
;
914 const unsigned int control
= 4;
915 const unsigned int cmask
= 0;
917 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
921 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface
*mixer
)
927 const unsigned int id
= 7;
928 const int val_type
= USB_MIXER_S16
;
929 const unsigned int control
= 7;
931 for (ch
= 0; ch
< 4; ++ch
) {
933 snprintf(name
, sizeof(name
),
934 "Effect Return %d Volume", ch
+ 1);
935 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
936 cmask
, val_type
, name
,
937 snd_usb_mixer_vol_tlv
);
945 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface
*mixer
)
951 const unsigned int id
= 5;
952 const int val_type
= USB_MIXER_S16
;
953 const unsigned int control
= 9;
955 for (ch
= 0; ch
< 8; ++ch
) {
957 snprintf(name
, sizeof(name
),
958 "Effect Send AIn%d Volume", ch
+ 1);
959 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
961 snd_usb_mixer_vol_tlv
);
965 for (ch
= 8; ch
< 16; ++ch
) {
967 snprintf(name
, sizeof(name
),
968 "Effect Send DIn%d Volume", ch
- 7);
969 err
= snd_create_std_mono_ctl(mixer
, id
, control
, cmask
,
971 snd_usb_mixer_vol_tlv
);
978 static int snd_ftu_create_mixer(struct usb_mixer_interface
*mixer
)
982 err
= snd_ftu_create_volume_ctls(mixer
);
986 err
= snd_ftu_create_effect_switch(mixer
, 1, 6);
990 err
= snd_ftu_create_effect_volume_ctl(mixer
);
994 err
= snd_ftu_create_effect_duration_ctl(mixer
);
998 err
= snd_ftu_create_effect_feedback_ctl(mixer
);
1002 err
= snd_ftu_create_effect_return_ctls(mixer
);
1006 err
= snd_ftu_create_effect_send_ctls(mixer
);
1013 void snd_emuusb_set_samplerate(struct snd_usb_audio
*chip
,
1014 unsigned char samplerate_id
)
1016 struct usb_mixer_interface
*mixer
;
1017 struct usb_mixer_elem_info
*cval
;
1018 int unitid
= 12; /* SamleRate ExtensionUnit ID */
1020 list_for_each_entry(mixer
, &chip
->mixer_list
, list
) {
1021 cval
= mixer
->id_elems
[unitid
];
1023 snd_usb_mixer_set_ctl_value(cval
, UAC_SET_CUR
,
1026 snd_usb_mixer_notify_id(mixer
, unitid
);
1032 /* M-Audio Fast Track C400/C600 */
1033 /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1034 static int snd_c400_create_vol_ctls(struct usb_mixer_interface
*mixer
)
1037 unsigned int cmask
, offset
;
1042 const unsigned int id
= 0x40;
1043 const int val_type
= USB_MIXER_S16
;
1044 const int control
= 1;
1046 switch (mixer
->chip
->usb_id
) {
1047 case USB_ID(0x0763, 0x2030):
1051 case USB_ID(0x0763, 0x2031):
1057 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1058 for (out
= 0; out
< num_outs
; out
++) {
1059 if (chan
< num_outs
) {
1060 snprintf(name
, sizeof(name
),
1061 "PCM%d-Out%d Playback Volume",
1064 snprintf(name
, sizeof(name
),
1065 "In%d-Out%d Playback Volume",
1066 chan
- num_outs
+ 1, out
+ 1);
1069 cmask
= (out
== 0) ? 0 : 1 << (out
- 1);
1070 offset
= chan
* num_outs
;
1071 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1072 cmask
, val_type
, offset
, name
,
1073 &snd_usb_mixer_vol_tlv
);
1082 /* This control needs a volume quirk, see mixer.c */
1083 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface
*mixer
)
1085 static const char name
[] = "Effect Volume";
1086 const unsigned int id
= 0x43;
1087 const int val_type
= USB_MIXER_U8
;
1088 const unsigned int control
= 3;
1089 const unsigned int cmask
= 0;
1091 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1092 name
, snd_usb_mixer_vol_tlv
);
1095 /* This control needs a volume quirk, see mixer.c */
1096 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface
*mixer
)
1098 static const char name
[] = "Effect Duration";
1099 const unsigned int id
= 0x43;
1100 const int val_type
= USB_MIXER_S16
;
1101 const unsigned int control
= 4;
1102 const unsigned int cmask
= 0;
1104 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1105 name
, snd_usb_mixer_vol_tlv
);
1108 /* This control needs a volume quirk, see mixer.c */
1109 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface
*mixer
)
1111 static const char name
[] = "Effect Feedback Volume";
1112 const unsigned int id
= 0x43;
1113 const int val_type
= USB_MIXER_U8
;
1114 const unsigned int control
= 5;
1115 const unsigned int cmask
= 0;
1117 return snd_create_std_mono_ctl(mixer
, id
, control
, cmask
, val_type
,
1121 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface
*mixer
)
1129 const unsigned int id
= 0x42;
1130 const int val_type
= USB_MIXER_S16
;
1131 const int control
= 1;
1133 switch (mixer
->chip
->usb_id
) {
1134 case USB_ID(0x0763, 0x2030):
1138 case USB_ID(0x0763, 0x2031):
1144 for (chan
= 0; chan
< num_outs
+ num_ins
; chan
++) {
1145 if (chan
< num_outs
) {
1146 snprintf(name
, sizeof(name
),
1147 "Effect Send DOut%d",
1150 snprintf(name
, sizeof(name
),
1151 "Effect Send AIn%d",
1152 chan
- num_outs
+ 1);
1155 cmask
= (chan
== 0) ? 0 : 1 << (chan
- 1);
1156 err
= snd_create_std_mono_ctl(mixer
, id
, control
,
1157 cmask
, val_type
, name
,
1158 &snd_usb_mixer_vol_tlv
);
1166 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface
*mixer
)
1174 const unsigned int id
= 0x40;
1175 const int val_type
= USB_MIXER_S16
;
1176 const int control
= 1;
1178 switch (mixer
->chip
->usb_id
) {
1179 case USB_ID(0x0763, 0x2030):
1182 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1184 case USB_ID(0x0763, 0x2031):
1187 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1191 for (chan
= 0; chan
< num_outs
; chan
++) {
1192 snprintf(name
, sizeof(name
),
1196 cmask
= (chan
== 0) ? 0 :
1197 1 << (chan
+ (chan
% 2) * num_outs
- 1);
1198 err
= snd_create_std_mono_ctl_offset(mixer
, id
, control
,
1199 cmask
, val_type
, offset
, name
,
1200 &snd_usb_mixer_vol_tlv
);
1208 static int snd_c400_create_mixer(struct usb_mixer_interface
*mixer
)
1212 err
= snd_c400_create_vol_ctls(mixer
);
1216 err
= snd_c400_create_effect_vol_ctls(mixer
);
1220 err
= snd_c400_create_effect_ret_vol_ctls(mixer
);
1224 err
= snd_ftu_create_effect_switch(mixer
, 2, 0x43);
1228 err
= snd_c400_create_effect_volume_ctl(mixer
);
1232 err
= snd_c400_create_effect_duration_ctl(mixer
);
1236 err
= snd_c400_create_effect_feedback_ctl(mixer
);
1244 * The mixer units for Ebox-44 are corrupt, and even where they
1245 * are valid they presents mono controls as L and R channels of
1246 * stereo. So we provide a good mixer here.
1248 static struct std_mono_table ebox44_table
[] = {
1253 .val_type
= USB_MIXER_INV_BOOLEAN
,
1254 .name
= "Headphone Playback Switch"
1260 .val_type
= USB_MIXER_S16
,
1261 .name
= "Headphone A Mix Playback Volume"
1267 .val_type
= USB_MIXER_S16
,
1268 .name
= "Headphone B Mix Playback Volume"
1275 .val_type
= USB_MIXER_INV_BOOLEAN
,
1276 .name
= "Output Playback Switch"
1282 .val_type
= USB_MIXER_S16
,
1283 .name
= "Output A Playback Volume"
1289 .val_type
= USB_MIXER_S16
,
1290 .name
= "Output B Playback Volume"
1297 .val_type
= USB_MIXER_INV_BOOLEAN
,
1298 .name
= "Input Capture Switch"
1304 .val_type
= USB_MIXER_S16
,
1305 .name
= "Input A Capture Volume"
1311 .val_type
= USB_MIXER_S16
,
1312 .name
= "Input B Capture Volume"
1318 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface
*mixer
)
1321 struct snd_info_entry
*entry
;
1323 if ((err
= snd_usb_soundblaster_remote_init(mixer
)) < 0)
1326 switch (mixer
->chip
->usb_id
) {
1327 case USB_ID(0x041e, 0x3020):
1328 case USB_ID(0x041e, 0x3040):
1329 case USB_ID(0x041e, 0x3042):
1330 case USB_ID(0x041e, 0x30df):
1331 case USB_ID(0x041e, 0x3048):
1332 err
= snd_audigy2nx_controls_create(mixer
);
1335 if (!snd_card_proc_new(mixer
->chip
->card
, "audigy2nx", &entry
))
1336 snd_info_set_text_ops(entry
, mixer
,
1337 snd_audigy2nx_proc_read
);
1340 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1341 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1342 err
= snd_c400_create_mixer(mixer
);
1345 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1346 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
1347 err
= snd_ftu_create_mixer(mixer
);
1350 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1351 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1352 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
1353 err
= snd_xonar_u1_controls_create(mixer
);
1356 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
1357 err
= snd_nativeinstruments_create_mixer(mixer
,
1358 snd_nativeinstruments_ta6_mixers
,
1359 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers
));
1362 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
1363 err
= snd_nativeinstruments_create_mixer(mixer
,
1364 snd_nativeinstruments_ta10_mixers
,
1365 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers
));
1368 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1369 /* detection is disabled in mixer_maps.c */
1370 err
= snd_create_std_mono_table(mixer
, ebox44_table
);
1377 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface
*mixer
,
1382 /* unit ids specific to Extigy/Audigy 2 NX: */
1384 case 0: /* remote control */
1385 mixer
->rc_urb
->dev
= mixer
->chip
->dev
;
1386 usb_submit_urb(mixer
->rc_urb
, GFP_ATOMIC
);
1388 case 4: /* digital in jack */
1389 case 7: /* line in jacks */
1390 case 19: /* speaker out jacks */
1391 case 20: /* headphones out jack */
1393 /* live24ext: 4 = line-in jack */
1394 case 3: /* hp-out jack (may actuate Mute) */
1395 if (mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3040) ||
1396 mixer
->chip
->usb_id
== USB_ID(0x041e, 0x3048))
1397 snd_usb_mixer_notify_id(mixer
, mixer
->rc_cfg
->mute_mixer_id
);
1400 snd_printd(KERN_DEBUG
"memory change in unknown unit %d\n", unitid
);