blob: 12125ca7167fb820d7352e1de8d0f90d9a792520 [file] [log] [blame]
Daniel Mack7b1eda22010-03-11 21:13:22 +01001/*
2 * USB Audio Driver for ALSA
3 *
4 * Quirks and vendor-specific extensions for mixer interfaces
5 *
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7 *
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
11 *
12 *
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.
17 *
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.
22 *
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
26 */
27
28#include <linux/init.h>
Stephen Rothwell36db0452010-03-29 16:02:50 +110029#include <linux/slab.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010030#include <linux/usb.h>
31#include <linux/usb/audio.h>
32
33#include <sound/core.h>
34#include <sound/control.h>
35#include <sound/hwdep.h>
36#include <sound/info.h>
37
38#include "usbaudio.h"
Daniel Mackf0b5e632010-03-11 21:13:23 +010039#include "mixer.h"
Daniel Mack7b1eda22010-03-11 21:13:22 +010040#include "mixer_quirks.h"
41#include "helper.h"
42
Daniel Mackd5a0bf62011-05-25 09:09:03 +020043extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
44
Felix Homann8a4d1d32012-04-23 20:24:23 +020045/* private_free callback */
46static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
47{
48 kfree(kctl->private_data);
49 kctl->private_data = NULL;
50}
51
52/* This function allows for the creation of standard UAC controls.
53 * See the quirks for M-Audio FTUs or Ebox-44.
54 * If you don't want to set a TLV callback pass NULL.
55 *
56 * Since there doesn't seem to be a devices that needs a multichannel
57 * version, we keep it mono for simplicity.
58 */
59static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
60 unsigned int unitid,
61 unsigned int control,
62 unsigned int cmask,
63 int val_type,
64 const char *name,
65 snd_kcontrol_tlv_rw_t *tlv_callback)
66{
67 int err;
68 struct usb_mixer_elem_info *cval;
69 struct snd_kcontrol *kctl;
70
71 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
72 if (!cval)
73 return -ENOMEM;
74
75 cval->id = unitid;
76 cval->mixer = mixer;
77 cval->val_type = val_type;
78 cval->channels = 1;
79 cval->control = control;
80 cval->cmask = cmask;
81
82 /* FIXME: Do we need this?
83 * The following values are for compatibility with
84 * Ebox-44 mixer.
85 * But the corresponding ebox-44 function says:
86 * "Volume controls will override these values"
87 *
88 * These values don't have any effect at all for
89 * M-Audio FTUs.
90 * So I think, we can safely omit the range settings here.
91 */
92 cval->min = 0;
93 cval->max = 1;
94 cval->res = 0;
95 cval->dBmin = 0;
96 cval->dBmax = 0;
97
98 /* Create control */
99 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
100 if (!kctl) {
101 kfree(cval);
102 return -ENOMEM;
103 }
104
105 /* Set name */
106 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
107 kctl->private_free = usb_mixer_elem_free;
108
109 /* set TLV */
110 if (tlv_callback) {
111 kctl->tlv.c = tlv_callback;
112 kctl->vd[0].access |=
113 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
114 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
115 }
116 /* Add control to mixer */
117 err = snd_usb_mixer_add_control(mixer, kctl);
118 if (err < 0)
119 return err;
120
121 return 0;
122}
123
Daniel Mack7b1eda22010-03-11 21:13:22 +0100124/*
125 * Sound Blaster remote control configuration
126 *
127 * format of remote control data:
128 * Extigy: xx 00
129 * Audigy 2 NX: 06 80 xx 00 00 00
130 * Live! 24-bit: 06 80 xx yy 22 83
131 */
132static const struct rc_config {
133 u32 usb_id;
134 u8 offset;
135 u8 length;
136 u8 packet_length;
137 u8 min_packet_length; /* minimum accepted length of the URB result */
138 u8 mute_mixer_id;
139 u32 mute_code;
140} rc_configs[] = {
141 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
142 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
143 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
Mandar Joshica8dc342010-11-02 14:43:19 +0000144 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200145 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Daniel Mack7b1eda22010-03-11 21:13:22 +0100146 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
147};
148
149static void snd_usb_soundblaster_remote_complete(struct urb *urb)
150{
151 struct usb_mixer_interface *mixer = urb->context;
152 const struct rc_config *rc = mixer->rc_cfg;
153 u32 code;
154
155 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
156 return;
157
158 code = mixer->rc_buffer[rc->offset];
159 if (rc->length == 2)
160 code |= mixer->rc_buffer[rc->offset + 1] << 8;
161
162 /* the Mute button actually changes the mixer control */
163 if (code == rc->mute_code)
164 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
165 mixer->rc_code = code;
166 wmb();
167 wake_up(&mixer->rc_waitq);
168}
169
170static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
171 long count, loff_t *offset)
172{
173 struct usb_mixer_interface *mixer = hw->private_data;
174 int err;
175 u32 rc_code;
176
177 if (count != 1 && count != 4)
178 return -EINVAL;
179 err = wait_event_interruptible(mixer->rc_waitq,
180 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
181 if (err == 0) {
182 if (count == 1)
183 err = put_user(rc_code, buf);
184 else
185 err = put_user(rc_code, (u32 __user *)buf);
186 }
187 return err < 0 ? err : count;
188}
189
190static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
191 poll_table *wait)
192{
193 struct usb_mixer_interface *mixer = hw->private_data;
194
195 poll_wait(file, &mixer->rc_waitq, wait);
196 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
197}
198
199static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
200{
201 struct snd_hwdep *hwdep;
202 int err, len, i;
203
204 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
205 if (rc_configs[i].usb_id == mixer->chip->usb_id)
206 break;
207 if (i >= ARRAY_SIZE(rc_configs))
208 return 0;
209 mixer->rc_cfg = &rc_configs[i];
210
211 len = mixer->rc_cfg->packet_length;
212
213 init_waitqueue_head(&mixer->rc_waitq);
214 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
215 if (err < 0)
216 return err;
217 snprintf(hwdep->name, sizeof(hwdep->name),
218 "%s remote control", mixer->chip->card->shortname);
219 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
220 hwdep->private_data = mixer;
221 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
222 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
223 hwdep->exclusive = 1;
224
225 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
226 if (!mixer->rc_urb)
227 return -ENOMEM;
228 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
229 if (!mixer->rc_setup_packet) {
230 usb_free_urb(mixer->rc_urb);
231 mixer->rc_urb = NULL;
232 return -ENOMEM;
233 }
234 mixer->rc_setup_packet->bRequestType =
235 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
236 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
237 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
238 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
239 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
240 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
241 usb_rcvctrlpipe(mixer->chip->dev, 0),
242 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
243 snd_usb_soundblaster_remote_complete, mixer);
244 return 0;
245}
246
247#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
248
249static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
250{
251 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
252 int index = kcontrol->private_value;
253
254 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
255 return 0;
256}
257
258static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
259{
260 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
261 int index = kcontrol->private_value;
262 int value = ucontrol->value.integer.value[0];
263 int err, changed;
264
265 if (value > 1)
266 return -EINVAL;
267 changed = value != mixer->audigy2nx_leds[index];
Mandar Joshica8dc342010-11-02 14:43:19 +0000268 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
269 err = snd_usb_ctl_msg(mixer->chip->dev,
270 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
271 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200272 !value, 0, NULL, 0);
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200273 /* USB X-Fi S51 Pro */
274 if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
275 err = snd_usb_ctl_msg(mixer->chip->dev,
276 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
277 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200278 !value, 0, NULL, 0);
Mandar Joshica8dc342010-11-02 14:43:19 +0000279 else
280 err = snd_usb_ctl_msg(mixer->chip->dev,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100281 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
282 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200283 value, index + 2, NULL, 0);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100284 if (err < 0)
285 return err;
286 mixer->audigy2nx_leds[index] = value;
287 return changed;
288}
289
290static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
291 {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "CMSS LED Switch",
294 .info = snd_audigy2nx_led_info,
295 .get = snd_audigy2nx_led_get,
296 .put = snd_audigy2nx_led_put,
297 .private_value = 0,
298 },
299 {
300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
301 .name = "Power LED Switch",
302 .info = snd_audigy2nx_led_info,
303 .get = snd_audigy2nx_led_get,
304 .put = snd_audigy2nx_led_put,
305 .private_value = 1,
306 },
307 {
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Dolby Digital LED Switch",
310 .info = snd_audigy2nx_led_info,
311 .get = snd_audigy2nx_led_get,
312 .put = snd_audigy2nx_led_put,
313 .private_value = 2,
314 },
315};
316
317static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
318{
319 int i, err;
320
321 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
Mandar Joshica8dc342010-11-02 14:43:19 +0000322 /* USB X-Fi S51 doesn't have a CMSS LED */
323 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
324 continue;
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200325 /* USB X-Fi S51 Pro doesn't have one either */
326 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
327 continue;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100328 if (i > 1 && /* Live24ext has 2 LEDs only */
329 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
Mandar Joshica8dc342010-11-02 14:43:19 +0000330 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200331 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
Daniel Mack7b1eda22010-03-11 21:13:22 +0100332 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
333 break;
334 err = snd_ctl_add(mixer->chip->card,
335 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
336 if (err < 0)
337 return err;
338 }
339 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
340 return 0;
341}
342
343static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
344 struct snd_info_buffer *buffer)
345{
346 static const struct sb_jack {
347 int unitid;
348 const char *name;
349 } jacks_audigy2nx[] = {
350 {4, "dig in "},
351 {7, "line in"},
352 {19, "spk out"},
353 {20, "hph out"},
354 {-1, NULL}
355 }, jacks_live24ext[] = {
356 {4, "line in"}, /* &1=Line, &2=Mic*/
357 {3, "hph out"}, /* headphones */
358 {0, "RC "}, /* last command, 6 bytes see rc_config above */
359 {-1, NULL}
360 };
361 const struct sb_jack *jacks;
362 struct usb_mixer_interface *mixer = entry->private_data;
363 int i, err;
364 u8 buf[3];
365
366 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
367 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
368 jacks = jacks_audigy2nx;
369 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
370 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
371 jacks = jacks_live24ext;
372 else
373 return;
374
375 for (i = 0; jacks[i].name; ++i) {
376 snd_iprintf(buffer, "%s: ", jacks[i].name);
377 err = snd_usb_ctl_msg(mixer->chip->dev,
378 usb_rcvctrlpipe(mixer->chip->dev, 0),
379 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
380 USB_RECIP_INTERFACE, 0,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200381 jacks[i].unitid << 8, buf, 3);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100382 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
383 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
384 else
385 snd_iprintf(buffer, "?\n");
386 }
387}
388
389static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_value *ucontrol)
391{
392 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
393
394 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
395 return 0;
396}
397
398static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
402 u8 old_status, new_status;
403 int err, changed;
404
405 old_status = mixer->xonar_u1_status;
406 if (ucontrol->value.integer.value[0])
407 new_status = old_status | 0x02;
408 else
409 new_status = old_status & ~0x02;
410 changed = new_status != old_status;
411 err = snd_usb_ctl_msg(mixer->chip->dev,
412 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
413 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200414 50, 0, &new_status, 1);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100415 if (err < 0)
416 return err;
417 mixer->xonar_u1_status = new_status;
418 return changed;
419}
420
421static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
423 .name = "Digital Playback Switch",
424 .info = snd_ctl_boolean_mono_info,
425 .get = snd_xonar_u1_switch_get,
426 .put = snd_xonar_u1_switch_put,
427};
428
429static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
430{
431 int err;
432
433 err = snd_ctl_add(mixer->chip->card,
434 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
435 if (err < 0)
436 return err;
437 mixer->xonar_u1_status = 0x05;
438 return 0;
439}
440
Daniel Mack54a8c502011-02-11 11:08:06 +0000441/* Native Instruments device quirks */
442
443#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
444
445static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_value *ucontrol)
447{
448 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
449 struct usb_device *dev = mixer->chip->dev;
450 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
451 u16 wIndex = kcontrol->private_value & 0xffff;
452 u8 tmp;
453
454 int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
455 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
456 0, cpu_to_le16(wIndex),
457 &tmp, sizeof(tmp), 1000);
458
459 if (ret < 0) {
460 snd_printk(KERN_ERR
461 "unable to issue vendor read request (ret = %d)", ret);
462 return ret;
463 }
464
465 ucontrol->value.integer.value[0] = tmp;
466
467 return 0;
468}
469
470static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
472{
473 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
474 struct usb_device *dev = mixer->chip->dev;
475 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
476 u16 wIndex = kcontrol->private_value & 0xffff;
477 u16 wValue = ucontrol->value.integer.value[0];
478
479 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
480 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
481 cpu_to_le16(wValue), cpu_to_le16(wIndex),
482 NULL, 0, 1000);
483
484 if (ret < 0) {
485 snd_printk(KERN_ERR
486 "unable to issue vendor write request (ret = %d)", ret);
487 return ret;
488 }
489
490 return 0;
491}
492
493static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
494 {
495 .name = "Direct Thru Channel A",
496 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
497 },
498 {
499 .name = "Direct Thru Channel B",
500 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
501 },
502 {
503 .name = "Phono Input Channel A",
504 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
505 },
506 {
507 .name = "Phono Input Channel B",
508 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
509 },
510};
511
512static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
513 {
514 .name = "Direct Thru Channel A",
515 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
516 },
517 {
518 .name = "Direct Thru Channel B",
519 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
520 },
521 {
522 .name = "Direct Thru Channel C",
523 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
524 },
525 {
526 .name = "Direct Thru Channel D",
527 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
528 },
529 {
530 .name = "Phono Input Channel A",
531 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
532 },
533 {
534 .name = "Phono Input Channel B",
535 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
536 },
537 {
538 .name = "Phono Input Channel C",
539 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
540 },
541 {
542 .name = "Phono Input Channel D",
543 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
544 },
545};
546
547static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
548 const struct snd_kcontrol_new *kc,
549 unsigned int count)
550{
551 int i, err = 0;
552 struct snd_kcontrol_new template = {
553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
554 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
555 .get = snd_nativeinstruments_control_get,
556 .put = snd_nativeinstruments_control_put,
557 .info = snd_ctl_boolean_mono_info,
558 };
559
560 for (i = 0; i < count; i++) {
561 struct snd_kcontrol *c;
562
563 template.name = kc[i].name;
564 template.private_value = kc[i].private_value;
565
566 c = snd_ctl_new1(&template, mixer);
567 err = snd_ctl_add(mixer->chip->card, c);
568
569 if (err < 0)
570 break;
571 }
572
573 return err;
574}
575
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200576/* M-Audio FastTrack Ultra quirks */
Felix Homannd34bf142012-04-23 20:24:27 +0200577/* FTU Effect switch */
578struct snd_ftu_eff_switch_priv_val {
579 struct usb_mixer_interface *mixer;
580 int cached_value;
581 int is_cached;
582};
583
584static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
585 struct snd_ctl_elem_info *uinfo)
586{
587 static const char *texts[8] = {"Room 1",
588 "Room 2",
589 "Room 3",
590 "Hall 1",
591 "Hall 2",
592 "Plate",
593 "Delay",
594 "Echo"
595 };
596
597 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
598 uinfo->count = 1;
599 uinfo->value.enumerated.items = 8;
600 if (uinfo->value.enumerated.item > 7)
601 uinfo->value.enumerated.item = 7;
602 strcpy(uinfo->value.enumerated.name,
603 texts[uinfo->value.enumerated.item]);
604
605 return 0;
606}
607
608static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
609 struct snd_ctl_elem_value *ucontrol)
610{
611 struct snd_usb_audio *chip;
612 struct usb_mixer_interface *mixer;
613 struct snd_ftu_eff_switch_priv_val *pval;
614 int err;
615 unsigned char value[2];
616
617 const int id = 6;
618 const int validx = 1;
619 const int val_len = 2;
620
621 value[0] = 0x00;
622 value[1] = 0x00;
623
624 pval = (struct snd_ftu_eff_switch_priv_val *)
625 kctl->private_value;
626
627 if (pval->is_cached) {
628 ucontrol->value.enumerated.item[0] = pval->cached_value;
629 return 0;
630 }
631
632 mixer = (struct usb_mixer_interface *) pval->mixer;
633 if (snd_BUG_ON(!mixer))
634 return -EINVAL;
635
636 chip = (struct snd_usb_audio *) mixer->chip;
637 if (snd_BUG_ON(!chip))
638 return -EINVAL;
639
640
641 err = snd_usb_ctl_msg(chip->dev,
642 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
643 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
644 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
645 value, val_len);
646 if (err < 0)
647 return err;
648
649 ucontrol->value.enumerated.item[0] = value[0];
650 pval->cached_value = value[0];
651 pval->is_cached = 1;
652
653 return 0;
654}
655
656static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
657 struct snd_ctl_elem_value *ucontrol)
658{
659 struct snd_usb_audio *chip;
660 struct snd_ftu_eff_switch_priv_val *pval;
661
662 struct usb_mixer_interface *mixer;
663 int changed, cur_val, err, new_val;
664 unsigned char value[2];
665
666
667 const int id = 6;
668 const int validx = 1;
669 const int val_len = 2;
670
671 changed = 0;
672
673 pval = (struct snd_ftu_eff_switch_priv_val *)
674 kctl->private_value;
675 cur_val = pval->cached_value;
676 new_val = ucontrol->value.enumerated.item[0];
677
678 mixer = (struct usb_mixer_interface *) pval->mixer;
679 if (snd_BUG_ON(!mixer))
680 return -EINVAL;
681
682 chip = (struct snd_usb_audio *) mixer->chip;
683 if (snd_BUG_ON(!chip))
684 return -EINVAL;
685
686 if (!pval->is_cached) {
687 /* Read current value */
688 err = snd_usb_ctl_msg(chip->dev,
689 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
690 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
691 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
692 value, val_len);
693 if (err < 0)
694 return err;
695
696 cur_val = value[0];
697 pval->cached_value = cur_val;
698 pval->is_cached = 1;
699 }
700 /* update value if needed */
701 if (cur_val != new_val) {
702 value[0] = new_val;
703 value[1] = 0;
704 err = snd_usb_ctl_msg(chip->dev,
705 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
706 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
707 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
708 value, val_len);
709 if (err < 0)
710 return err;
711
712 pval->cached_value = new_val;
713 pval->is_cached = 1;
714 changed = 1;
715 }
716
717 return changed;
718}
719
720static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer)
721{
722 static struct snd_kcontrol_new template = {
723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724 .name = "Effect Program Switch",
725 .index = 0,
726 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
727 .info = snd_ftu_eff_switch_info,
728 .get = snd_ftu_eff_switch_get,
729 .put = snd_ftu_eff_switch_put
730 };
731
732 int err;
733 struct snd_kcontrol *kctl;
734 struct snd_ftu_eff_switch_priv_val *pval;
735
736 pval = kzalloc(sizeof(*pval), GFP_KERNEL);
737 if (!pval)
738 return -ENOMEM;
739
740 pval->cached_value = 0;
741 pval->is_cached = 0;
742 pval->mixer = mixer;
743
744 template.private_value = (unsigned long) pval;
745 kctl = snd_ctl_new1(&template, mixer->chip);
746 if (!kctl) {
747 kfree(pval);
748 return -ENOMEM;
749 }
750
751 err = snd_ctl_add(mixer->chip->card, kctl);
752 if (err < 0)
753 return err;
754
755 return 0;
756}
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200757
Felix Homanncfe8f972012-04-23 20:24:26 +0200758/* Create volume controls for FTU devices*/
759static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200760{
761 char name[64];
Felix Homann8a4d1d32012-04-23 20:24:23 +0200762 unsigned int control, cmask;
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200763 int in, out, err;
764
Felix Homann8a4d1d32012-04-23 20:24:23 +0200765 const unsigned int id = 5;
766 const int val_type = USB_MIXER_S16;
767
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200768 for (out = 0; out < 8; out++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +0200769 control = out + 1;
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200770 for (in = 0; in < 8; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +0200771 cmask = 1 << in;
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200772 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +0200773 "AIn%d - Out%d Capture Volume",
774 in + 1, out + 1);
775 err = snd_create_std_mono_ctl(mixer, id, control,
776 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +0200777 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200778 if (err < 0)
779 return err;
780 }
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200781 for (in = 8; in < 16; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +0200782 cmask = 1 << in;
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200783 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +0200784 "DIn%d - Out%d Playback Volume",
785 in - 7, out + 1);
786 err = snd_create_std_mono_ctl(mixer, id, control,
787 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +0200788 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf62011-05-25 09:09:03 +0200789 if (err < 0)
790 return err;
791 }
792 }
793
794 return 0;
795}
796
Felix Homannd34bf142012-04-23 20:24:27 +0200797/* This control needs a volume quirk, see mixer.c */
798static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
799{
800 static const char name[] = "Effect Volume";
801 const unsigned int id = 6;
802 const int val_type = USB_MIXER_U8;
803 const unsigned int control = 2;
804 const unsigned int cmask = 0;
805
806 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
807 name, snd_usb_mixer_vol_tlv);
808}
809
810/* This control needs a volume quirk, see mixer.c */
811static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
812{
813 static const char name[] = "Effect Duration";
814 const unsigned int id = 6;
815 const int val_type = USB_MIXER_S16;
816 const unsigned int control = 3;
817 const unsigned int cmask = 0;
818
819 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
820 name, snd_usb_mixer_vol_tlv);
821}
822
823/* This control needs a volume quirk, see mixer.c */
824static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
825{
826 static const char name[] = "Effect Feedback Volume";
827 const unsigned int id = 6;
828 const int val_type = USB_MIXER_U8;
829 const unsigned int control = 4;
830 const unsigned int cmask = 0;
831
832 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
833 name, NULL);
834}
835
836static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
837{
838 unsigned int cmask;
839 int err, ch;
840 char name[48];
841
842 const unsigned int id = 7;
843 const int val_type = USB_MIXER_S16;
844 const unsigned int control = 7;
845
846 for (ch = 0; ch < 4; ++ch) {
847 cmask = 1 << ch;
848 snprintf(name, sizeof(name),
849 "Effect Return %d Volume", ch + 1);
850 err = snd_create_std_mono_ctl(mixer, id, control,
851 cmask, val_type, name,
852 snd_usb_mixer_vol_tlv);
853 if (err < 0)
854 return err;
855 }
856
857 return 0;
858}
859
860static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
861{
862 unsigned int cmask;
863 int err, ch;
864 char name[48];
865
866 const unsigned int id = 5;
867 const int val_type = USB_MIXER_S16;
868 const unsigned int control = 9;
869
870 for (ch = 0; ch < 8; ++ch) {
871 cmask = 1 << ch;
872 snprintf(name, sizeof(name),
873 "Effect Send AIn%d Volume", ch + 1);
874 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
875 val_type, name,
876 snd_usb_mixer_vol_tlv);
877 if (err < 0)
878 return err;
879 }
880 for (ch = 8; ch < 16; ++ch) {
881 cmask = 1 << ch;
882 snprintf(name, sizeof(name),
883 "Effect Send DIn%d Volume", ch - 7);
884 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
885 val_type, name,
886 snd_usb_mixer_vol_tlv);
887 if (err < 0)
888 return err;
889 }
890 return 0;
891}
892
Felix Homanncfe8f972012-04-23 20:24:26 +0200893static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
Mark Hills7536c302012-04-14 17:19:24 +0100894{
Felix Homann8a4d1d32012-04-23 20:24:23 +0200895 int err;
Mark Hills7536c302012-04-14 17:19:24 +0100896
Felix Homanncfe8f972012-04-23 20:24:26 +0200897 err = snd_ftu_create_volume_ctls(mixer);
Felix Homann8a4d1d32012-04-23 20:24:23 +0200898 if (err < 0)
899 return err;
Mark Hills7536c302012-04-14 17:19:24 +0100900
Felix Homannd34bf142012-04-23 20:24:27 +0200901 err = snd_ftu_create_effect_switch(mixer);
902 if (err < 0)
903 return err;
904 err = snd_ftu_create_effect_volume_ctl(mixer);
905 if (err < 0)
906 return err;
907
908 err = snd_ftu_create_effect_duration_ctl(mixer);
909 if (err < 0)
910 return err;
911
912 err = snd_ftu_create_effect_feedback_ctl(mixer);
913 if (err < 0)
914 return err;
915
916 err = snd_ftu_create_effect_return_ctls(mixer);
917 if (err < 0)
918 return err;
919
920 err = snd_ftu_create_effect_send_ctls(mixer);
921 if (err < 0)
922 return err;
923
Felix Homann8a4d1d32012-04-23 20:24:23 +0200924 return 0;
Mark Hills7536c302012-04-14 17:19:24 +0100925}
926
Felix Homann8a4d1d32012-04-23 20:24:23 +0200927
Mark Hills7536c302012-04-14 17:19:24 +0100928/*
929 * Create mixer for Electrix Ebox-44
930 *
931 * The mixer units from this device are corrupt, and even where they
932 * are valid they presents mono controls as L and R channels of
933 * stereo. So we create a good mixer in code.
934 */
935
936static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer)
937{
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200938 int err;
939
940 err = snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200941 "Headphone Playback Switch", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200942 if (err < 0)
943 return err;
944 err = snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200945 "Headphone A Mix Playback Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200946 if (err < 0)
947 return err;
948 err = snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200949 "Headphone B Mix Playback Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200950 if (err < 0)
951 return err;
Mark Hills7536c302012-04-14 17:19:24 +0100952
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200953 err = snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200954 "Output Playback Switch", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200955 if (err < 0)
956 return err;
957 err = snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200958 "Output A Playback Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200959 if (err < 0)
960 return err;
961 err = snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200962 "Output B Playback Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200963 if (err < 0)
964 return err;
Mark Hills7536c302012-04-14 17:19:24 +0100965
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200966 err = snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200967 "Input Capture Switch", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200968 if (err < 0)
969 return err;
970 err = snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200971 "Input A Capture Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200972 if (err < 0)
973 return err;
974 err = snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16,
Felix Homann8a4d1d32012-04-23 20:24:23 +0200975 "Input B Capture Volume", NULL);
Takashi Iwaibaba2e02012-04-24 08:07:38 +0200976 if (err < 0)
977 return err;
Mark Hills7536c302012-04-14 17:19:24 +0100978
979 return 0;
980}
981
Daniel Mack7b1eda22010-03-11 21:13:22 +0100982void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
983 unsigned char samplerate_id)
984{
985 struct usb_mixer_interface *mixer;
986 struct usb_mixer_elem_info *cval;
987 int unitid = 12; /* SamleRate ExtensionUnit ID */
988
989 list_for_each_entry(mixer, &chip->mixer_list, list) {
990 cval = mixer->id_elems[unitid];
991 if (cval) {
992 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
993 cval->control << 8,
994 samplerate_id);
995 snd_usb_mixer_notify_id(mixer, unitid);
996 }
997 break;
998 }
999}
1000
1001int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1002{
Daniel Mack3347b262011-02-11 11:34:12 +00001003 int err = 0;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001004 struct snd_info_entry *entry;
1005
1006 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1007 return err;
1008
Daniel Mack3347b262011-02-11 11:34:12 +00001009 switch (mixer->chip->usb_id) {
1010 case USB_ID(0x041e, 0x3020):
1011 case USB_ID(0x041e, 0x3040):
1012 case USB_ID(0x041e, 0x3042):
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +02001013 case USB_ID(0x041e, 0x30df):
Daniel Mack3347b262011-02-11 11:34:12 +00001014 case USB_ID(0x041e, 0x3048):
1015 err = snd_audigy2nx_controls_create(mixer);
1016 if (err < 0)
1017 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001018 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1019 snd_info_set_text_ops(entry, mixer,
1020 snd_audigy2nx_proc_read);
Daniel Mack3347b262011-02-11 11:34:12 +00001021 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001022
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001023 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1024 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
Felix Homanncfe8f972012-04-23 20:24:26 +02001025 err = snd_ftu_create_mixer(mixer);
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001026 break;
1027
Daniel Mack3347b262011-02-11 11:34:12 +00001028 case USB_ID(0x0b05, 0x1739):
1029 case USB_ID(0x0b05, 0x1743):
Daniel Mack7b1eda22010-03-11 21:13:22 +01001030 err = snd_xonar_u1_controls_create(mixer);
Daniel Mack3347b262011-02-11 11:34:12 +00001031 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001032
Daniel Mack3347b262011-02-11 11:34:12 +00001033 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
Daniel Mack54a8c502011-02-11 11:08:06 +00001034 err = snd_nativeinstruments_create_mixer(mixer,
1035 snd_nativeinstruments_ta6_mixers,
1036 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00001037 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00001038
Daniel Mack3347b262011-02-11 11:34:12 +00001039 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
Daniel Mack54a8c502011-02-11 11:08:06 +00001040 err = snd_nativeinstruments_create_mixer(mixer,
1041 snd_nativeinstruments_ta10_mixers,
1042 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00001043 break;
Mark Hills7536c302012-04-14 17:19:24 +01001044
1045 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1046 err = snd_ebox44_create_mixer(mixer);
1047 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00001048 }
1049
Daniel Mack3347b262011-02-11 11:34:12 +00001050 return err;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001051}
1052
1053void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1054 int unitid)
1055{
1056 if (!mixer->rc_cfg)
1057 return;
1058 /* unit ids specific to Extigy/Audigy 2 NX: */
1059 switch (unitid) {
1060 case 0: /* remote control */
1061 mixer->rc_urb->dev = mixer->chip->dev;
1062 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1063 break;
1064 case 4: /* digital in jack */
1065 case 7: /* line in jacks */
1066 case 19: /* speaker out jacks */
1067 case 20: /* headphones out jack */
1068 break;
1069 /* live24ext: 4 = line-in jack */
1070 case 3: /* hp-out jack (may actuate Mute) */
1071 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1072 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1073 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1074 break;
1075 default:
1076 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1077 break;
1078 }
1079}
1080