Linux 3.9-rc4
[linux-2.6/cjktty.git] / sound / usb / mixer_quirks.c
blob497d2741d1192f7b5b8eea43d9347023faa220f2
1 /*
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>
38 #include "usbaudio.h"
39 #include "mixer.h"
40 #include "mixer_quirks.h"
41 #include "helper.h"
43 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
45 struct std_mono_table {
46 unsigned int unitid, control, cmask;
47 int val_type;
48 const char *name;
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,
67 unsigned int unitid,
68 unsigned int control,
69 unsigned int cmask,
70 int val_type,
71 unsigned int idx_off,
72 const char *name,
73 snd_kcontrol_tlv_rw_t *tlv_callback)
75 int err;
76 struct usb_mixer_elem_info *cval;
77 struct snd_kcontrol *kctl;
79 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
80 if (!cval)
81 return -ENOMEM;
83 cval->id = unitid;
84 cval->mixer = mixer;
85 cval->val_type = val_type;
86 cval->channels = 1;
87 cval->control = control;
88 cval->cmask = cmask;
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 */
93 cval->min = 0;
94 cval->max = 1;
95 cval->res = 0;
96 cval->dBmin = 0;
97 cval->dBmax = 0;
99 /* Create control */
100 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
101 if (!kctl) {
102 kfree(cval);
103 return -ENOMEM;
106 /* Set name */
107 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
108 kctl->private_free = usb_mixer_elem_free;
110 /* set TLV */
111 if (tlv_callback) {
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);
119 if (err < 0)
120 return err;
122 return 0;
125 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
126 unsigned int unitid,
127 unsigned int control,
128 unsigned int cmask,
129 int val_type,
130 const char *name,
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)
143 int err;
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);
148 if (err < 0)
149 return err;
150 t++;
153 return 0;
157 * Sound Blaster remote control configuration
159 * format of remote control data:
160 * Extigy: xx 00
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 {
165 u32 usb_id;
166 u8 offset;
167 u8 length;
168 u8 packet_length;
169 u8 min_packet_length; /* minimum accepted length of the URB result */
170 u8 mute_mixer_id;
171 u32 mute_code;
172 } rc_configs[] = {
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;
185 u32 code;
187 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
188 return;
190 code = mixer->rc_buffer[rc->offset];
191 if (rc->length == 2)
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;
198 wmb();
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;
206 int err;
207 u32 rc_code;
209 if (count != 1 && count != 4)
210 return -EINVAL;
211 err = wait_event_interruptible(mixer->rc_waitq,
212 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
213 if (err == 0) {
214 if (count == 1)
215 err = put_user(rc_code, buf);
216 else
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,
223 poll_table *wait)
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;
234 int err, len, i;
236 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
237 if (rc_configs[i].usb_id == mixer->chip->usb_id)
238 break;
239 if (i >= ARRAY_SIZE(rc_configs))
240 return 0;
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);
247 if (err < 0)
248 return err;
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);
258 if (!mixer->rc_urb)
259 return -ENOMEM;
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;
264 return -ENOMEM;
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);
276 return 0;
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];
287 return 0;
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];
295 int err, changed;
297 if (value > 1)
298 return -EINVAL;
299 changed = value != mixer->audigy2nx_leds[index];
300 down_read(&mixer->chip->shutdown_rwsem);
301 if (mixer->chip->shutdown) {
302 err = -ENODEV;
303 goto out;
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,
309 !value, 0, NULL, 0);
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,
315 !value, 0, NULL, 0);
316 else
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);
321 out:
322 up_read(&mixer->chip->shutdown_rwsem);
323 if (err < 0)
324 return err;
325 mixer->audigy2nx_leds[index] = value;
326 return changed;
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,
336 .private_value = 0,
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,
344 .private_value = 1,
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,
352 .private_value = 2,
356 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
358 int i, err;
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)
363 continue;
364 /* USB X-Fi S51 Pro doesn't have one either */
365 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
366 continue;
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)))
372 break;
373 err = snd_ctl_add(mixer->chip->card,
374 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
375 if (err < 0)
376 return err;
378 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
379 return 0;
382 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
383 struct snd_info_buffer *buffer)
385 static const struct sb_jack {
386 int unitid;
387 const char *name;
388 } jacks_audigy2nx[] = {
389 {4, "dig in "},
390 {7, "line in"},
391 {19, "spk out"},
392 {20, "hph out"},
393 {-1, NULL}
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 */
398 {-1, NULL}
400 const struct sb_jack *jacks;
401 struct usb_mixer_interface *mixer = entry->private_data;
402 int i, err;
403 u8 buf[3];
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;
411 else
412 return;
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)
418 err = 0;
419 else
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]);
428 else
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);
441 return 0;
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;
449 int err, changed;
451 old_status = mixer->xonar_u1_status;
452 if (ucontrol->value.integer.value[0])
453 new_status = old_status | 0x02;
454 else
455 new_status = old_status & ~0x02;
456 changed = new_status != old_status;
457 down_read(&mixer->chip->shutdown_rwsem);
458 if (mixer->chip->shutdown)
459 err = -ENODEV;
460 else
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);
466 if (err < 0)
467 return err;
468 mixer->xonar_u1_status = new_status;
469 return changed;
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)
482 int err;
484 err = snd_ctl_add(mixer->chip->card,
485 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
486 if (err < 0)
487 return err;
488 mixer->xonar_u1_status = 0x05;
489 return 0;
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;
503 u8 tmp;
504 int ret;
506 down_read(&mixer->chip->shutdown_rwsem);
507 if (mixer->chip->shutdown)
508 ret = -ENODEV;
509 else
510 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
511 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
512 0, cpu_to_le16(wIndex),
513 &tmp, sizeof(tmp), 1000);
514 up_read(&mixer->chip->shutdown_rwsem);
516 if (ret < 0) {
517 snd_printk(KERN_ERR
518 "unable to issue vendor read request (ret = %d)", ret);
519 return ret;
522 ucontrol->value.integer.value[0] = tmp;
524 return 0;
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];
535 int ret;
537 down_read(&mixer->chip->shutdown_rwsem);
538 if (mixer->chip->shutdown)
539 ret = -ENODEV;
540 else
541 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
542 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
543 cpu_to_le16(wValue), cpu_to_le16(wIndex),
544 NULL, 0, 1000);
545 up_read(&mixer->chip->shutdown_rwsem);
547 if (ret < 0) {
548 snd_printk(KERN_ERR
549 "unable to issue vendor write request (ret = %d)", ret);
550 return ret;
553 return 0;
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,
612 unsigned int count)
614 int i, err = 0;
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);
632 if (err < 0)
633 break;
636 return err;
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;
643 int cached_value;
644 int is_cached;
645 int bUnitID;
646 int validx;
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",
653 "Room 2",
654 "Room 3",
655 "Hall 1",
656 "Hall 2",
657 "Plate",
658 "Delay",
659 "Echo"
662 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
663 uinfo->count = 1;
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]);
670 return 0;
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;
679 int err;
680 unsigned char value[2];
681 int id, validx;
683 const int val_len = 2;
685 value[0] = 0x00;
686 value[1] = 0x00;
688 pval = (struct snd_ftu_eff_switch_priv_val *)
689 kctl->private_value;
691 if (pval->is_cached) {
692 ucontrol->value.enumerated.item[0] = pval->cached_value;
693 return 0;
696 mixer = (struct usb_mixer_interface *) pval->mixer;
697 if (snd_BUG_ON(!mixer))
698 return -EINVAL;
700 chip = (struct snd_usb_audio *) mixer->chip;
701 if (snd_BUG_ON(!chip))
702 return -EINVAL;
704 id = pval->bUnitID;
705 validx = pval->validx;
707 down_read(&mixer->chip->shutdown_rwsem);
708 if (mixer->chip->shutdown)
709 err = -ENODEV;
710 else
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),
715 value, val_len);
716 up_read(&mixer->chip->shutdown_rwsem);
717 if (err < 0)
718 return err;
720 ucontrol->value.enumerated.item[0] = value[0];
721 pval->cached_value = value[0];
722 pval->is_cached = 1;
724 return 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];
736 int id, validx;
738 const int val_len = 2;
740 changed = 0;
742 pval = (struct snd_ftu_eff_switch_priv_val *)
743 kctl->private_value;
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))
749 return -EINVAL;
751 chip = (struct snd_usb_audio *) mixer->chip;
752 if (snd_BUG_ON(!chip))
753 return -EINVAL;
755 id = pval->bUnitID;
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)
762 err = -ENODEV;
763 else
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),
768 value, val_len);
769 up_read(&mixer->chip->shutdown_rwsem);
770 if (err < 0)
771 return err;
773 cur_val = value[0];
774 pval->cached_value = cur_val;
775 pval->is_cached = 1;
777 /* update value if needed */
778 if (cur_val != new_val) {
779 value[0] = new_val;
780 value[1] = 0;
781 down_read(&mixer->chip->shutdown_rwsem);
782 if (mixer->chip->shutdown)
783 err = -ENODEV;
784 else
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),
789 value, val_len);
790 up_read(&mixer->chip->shutdown_rwsem);
791 if (err < 0)
792 return err;
794 pval->cached_value = new_val;
795 pval->is_cached = 1;
796 changed = 1;
799 return changed;
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",
808 .index = 0,
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
815 int err;
816 struct snd_kcontrol *kctl;
817 struct snd_ftu_eff_switch_priv_val *pval;
819 pval = kzalloc(sizeof(*pval), GFP_KERNEL);
820 if (!pval)
821 return -ENOMEM;
823 pval->cached_value = 0;
824 pval->is_cached = 0;
825 pval->mixer = mixer;
826 pval->bUnitID = bUnitID;
827 pval->validx = validx;
829 template.private_value = (unsigned long) pval;
830 kctl = snd_ctl_new1(&template, mixer->chip);
831 if (!kctl) {
832 kfree(pval);
833 return -ENOMEM;
836 err = snd_ctl_add(mixer->chip->card, kctl);
837 if (err < 0)
838 return err;
840 return 0;
843 /* Create volume controls for FTU devices*/
844 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
846 char name[64];
847 unsigned int control, cmask;
848 int in, out, err;
850 const unsigned int id = 5;
851 const int val_type = USB_MIXER_S16;
853 for (out = 0; out < 8; out++) {
854 control = out + 1;
855 for (in = 0; in < 8; in++) {
856 cmask = 1 << in;
857 snprintf(name, sizeof(name),
858 "AIn%d - Out%d Capture Volume",
859 in + 1, out + 1);
860 err = snd_create_std_mono_ctl(mixer, id, control,
861 cmask, val_type, name,
862 &snd_usb_mixer_vol_tlv);
863 if (err < 0)
864 return err;
866 for (in = 8; in < 16; in++) {
867 cmask = 1 << in;
868 snprintf(name, sizeof(name),
869 "DIn%d - Out%d Playback Volume",
870 in - 7, out + 1);
871 err = snd_create_std_mono_ctl(mixer, id, control,
872 cmask, val_type, name,
873 &snd_usb_mixer_vol_tlv);
874 if (err < 0)
875 return err;
879 return 0;
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,
918 name, NULL);
921 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
923 unsigned int cmask;
924 int err, ch;
925 char name[48];
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) {
932 cmask = 1 << 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);
938 if (err < 0)
939 return err;
942 return 0;
945 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
947 unsigned int cmask;
948 int err, ch;
949 char name[48];
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) {
956 cmask = 1 << 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,
960 val_type, name,
961 snd_usb_mixer_vol_tlv);
962 if (err < 0)
963 return err;
965 for (ch = 8; ch < 16; ++ch) {
966 cmask = 1 << 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,
970 val_type, name,
971 snd_usb_mixer_vol_tlv);
972 if (err < 0)
973 return err;
975 return 0;
978 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
980 int err;
982 err = snd_ftu_create_volume_ctls(mixer);
983 if (err < 0)
984 return err;
986 err = snd_ftu_create_effect_switch(mixer, 1, 6);
987 if (err < 0)
988 return err;
990 err = snd_ftu_create_effect_volume_ctl(mixer);
991 if (err < 0)
992 return err;
994 err = snd_ftu_create_effect_duration_ctl(mixer);
995 if (err < 0)
996 return err;
998 err = snd_ftu_create_effect_feedback_ctl(mixer);
999 if (err < 0)
1000 return err;
1002 err = snd_ftu_create_effect_return_ctls(mixer);
1003 if (err < 0)
1004 return err;
1006 err = snd_ftu_create_effect_send_ctls(mixer);
1007 if (err < 0)
1008 return err;
1010 return 0;
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];
1022 if (cval) {
1023 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1024 cval->control << 8,
1025 samplerate_id);
1026 snd_usb_mixer_notify_id(mixer, unitid);
1028 break;
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)
1036 char name[64];
1037 unsigned int cmask, offset;
1038 int out, chan, err;
1039 int num_outs = 0;
1040 int num_ins = 0;
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):
1048 num_outs = 6;
1049 num_ins = 4;
1050 break;
1051 case USB_ID(0x0763, 0x2031):
1052 num_outs = 8;
1053 num_ins = 6;
1054 break;
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",
1062 chan + 1, out + 1);
1063 } else {
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);
1074 if (err < 0)
1075 return err;
1079 return 0;
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,
1118 name, NULL);
1121 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1123 char name[64];
1124 unsigned int cmask;
1125 int chan, err;
1126 int num_outs = 0;
1127 int num_ins = 0;
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):
1135 num_outs = 6;
1136 num_ins = 4;
1137 break;
1138 case USB_ID(0x0763, 0x2031):
1139 num_outs = 8;
1140 num_ins = 6;
1141 break;
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",
1148 chan + 1);
1149 } else {
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);
1159 if (err < 0)
1160 return err;
1163 return 0;
1166 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1168 char name[64];
1169 unsigned int cmask;
1170 int chan, err;
1171 int num_outs = 0;
1172 int offset = 0;
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):
1180 num_outs = 6;
1181 offset = 0x3c;
1182 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1183 break;
1184 case USB_ID(0x0763, 0x2031):
1185 num_outs = 8;
1186 offset = 0x70;
1187 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1188 break;
1191 for (chan = 0; chan < num_outs; chan++) {
1192 snprintf(name, sizeof(name),
1193 "Effect Return %d",
1194 chan + 1);
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);
1201 if (err < 0)
1202 return err;
1205 return 0;
1208 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1210 int err;
1212 err = snd_c400_create_vol_ctls(mixer);
1213 if (err < 0)
1214 return err;
1216 err = snd_c400_create_effect_vol_ctls(mixer);
1217 if (err < 0)
1218 return err;
1220 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1221 if (err < 0)
1222 return err;
1224 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1225 if (err < 0)
1226 return err;
1228 err = snd_c400_create_effect_volume_ctl(mixer);
1229 if (err < 0)
1230 return err;
1232 err = snd_c400_create_effect_duration_ctl(mixer);
1233 if (err < 0)
1234 return err;
1236 err = snd_c400_create_effect_feedback_ctl(mixer);
1237 if (err < 0)
1238 return err;
1240 return 0;
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[] = {
1250 .unitid = 4,
1251 .control = 1,
1252 .cmask = 0x0,
1253 .val_type = USB_MIXER_INV_BOOLEAN,
1254 .name = "Headphone Playback Switch"
1257 .unitid = 4,
1258 .control = 2,
1259 .cmask = 0x1,
1260 .val_type = USB_MIXER_S16,
1261 .name = "Headphone A Mix Playback Volume"
1264 .unitid = 4,
1265 .control = 2,
1266 .cmask = 0x2,
1267 .val_type = USB_MIXER_S16,
1268 .name = "Headphone B Mix Playback Volume"
1272 .unitid = 7,
1273 .control = 1,
1274 .cmask = 0x0,
1275 .val_type = USB_MIXER_INV_BOOLEAN,
1276 .name = "Output Playback Switch"
1279 .unitid = 7,
1280 .control = 2,
1281 .cmask = 0x1,
1282 .val_type = USB_MIXER_S16,
1283 .name = "Output A Playback Volume"
1286 .unitid = 7,
1287 .control = 2,
1288 .cmask = 0x2,
1289 .val_type = USB_MIXER_S16,
1290 .name = "Output B Playback Volume"
1294 .unitid = 10,
1295 .control = 1,
1296 .cmask = 0x0,
1297 .val_type = USB_MIXER_INV_BOOLEAN,
1298 .name = "Input Capture Switch"
1301 .unitid = 10,
1302 .control = 2,
1303 .cmask = 0x1,
1304 .val_type = USB_MIXER_S16,
1305 .name = "Input A Capture Volume"
1308 .unitid = 10,
1309 .control = 2,
1310 .cmask = 0x2,
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)
1320 int err = 0;
1321 struct snd_info_entry *entry;
1323 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1324 return err;
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);
1333 if (err < 0)
1334 break;
1335 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1336 snd_info_set_text_ops(entry, mixer,
1337 snd_audigy2nx_proc_read);
1338 break;
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);
1343 break;
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);
1348 break;
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);
1354 break;
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));
1360 break;
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));
1366 break;
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);
1371 break;
1374 return err;
1377 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1378 int unitid)
1380 if (!mixer->rc_cfg)
1381 return;
1382 /* unit ids specific to Extigy/Audigy 2 NX: */
1383 switch (unitid) {
1384 case 0: /* remote control */
1385 mixer->rc_urb->dev = mixer->chip->dev;
1386 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1387 break;
1388 case 4: /* digital in jack */
1389 case 7: /* line in jacks */
1390 case 19: /* speaker out jacks */
1391 case 20: /* headphones out jack */
1392 break;
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);
1398 break;
1399 default:
1400 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1401 break;