ALSA: usb-audio: skip UAC2 EFFECT_UNIT
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / usb / mixer_quirks.c
CommitLineData
7b1eda22
DM
1/*
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>
36db0456 29#include <linux/slab.h>
7b1eda22
DM
30#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"
f0b5e634 39#include "mixer.h"
7b1eda22
DM
40#include "mixer_quirks.h"
41#include "helper.h"
42
d5a0bf6c
DM
43extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
44
b71dad18
MH
45struct 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;
50};
51
8a4d1d39
FH
52/* private_free callback */
53static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
54{
55 kfree(kctl->private_data);
56 kctl->private_data = NULL;
57}
58
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.
62 *
63 * Since there doesn't seem to be a devices that needs a multichannel
64 * version, we keep it mono for simplicity.
65 */
9f814105 66static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
8a4d1d39
FH
67 unsigned int unitid,
68 unsigned int control,
69 unsigned int cmask,
70 int val_type,
9f814105 71 unsigned int idx_off,
8a4d1d39
FH
72 const char *name,
73 snd_kcontrol_tlv_rw_t *tlv_callback)
74{
75 int err;
76 struct usb_mixer_elem_info *cval;
77 struct snd_kcontrol *kctl;
78
79 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
80 if (!cval)
81 return -ENOMEM;
82
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;
9f814105 89 cval->idx_off = idx_off;
8a4d1d39 90
7df4a691
MH
91 /* get_min_max() is called only for integer volumes later,
92 * so provide a short-cut for booleans */
8a4d1d39
FH
93 cval->min = 0;
94 cval->max = 1;
95 cval->res = 0;
96 cval->dBmin = 0;
97 cval->dBmax = 0;
98
99 /* Create control */
100 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
101 if (!kctl) {
102 kfree(cval);
103 return -ENOMEM;
104 }
105
106 /* Set name */
107 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
108 kctl->private_free = usb_mixer_elem_free;
109
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;
116 }
117 /* Add control to mixer */
118 err = snd_usb_mixer_add_control(mixer, kctl);
119 if (err < 0)
120 return err;
121
122 return 0;
123}
124
9f814105
EZ
125static 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)
132{
133 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
134 val_type, 0 /* Offset */, name, tlv_callback);
135}
136
b71dad18
MH
137/*
138 * Create a set of standard UAC controls from a table
139 */
140static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
141 struct std_mono_table *t)
142{
143 int err;
144
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++;
151 }
152
153 return 0;
154}
155
7b1eda22
DM
156/*
157 * Sound Blaster remote control configuration
158 *
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
163 */
164static 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 */
ca8dc34e 176 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
7cdd8d73 177 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
7b1eda22
DM
178 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
179};
180
181static void snd_usb_soundblaster_remote_complete(struct urb *urb)
182{
183 struct usb_mixer_interface *mixer = urb->context;
184 const struct rc_config *rc = mixer->rc_cfg;
185 u32 code;
186
187 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
188 return;
189
190 code = mixer->rc_buffer[rc->offset];
191 if (rc->length == 2)
192 code |= mixer->rc_buffer[rc->offset + 1] << 8;
193
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);
200}
201
202static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
203 long count, loff_t *offset)
204{
205 struct usb_mixer_interface *mixer = hw->private_data;
206 int err;
207 u32 rc_code;
208
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);
218 }
219 return err < 0 ? err : count;
220}
221
222static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
223 poll_table *wait)
224{
225 struct usb_mixer_interface *mixer = hw->private_data;
226
227 poll_wait(file, &mixer->rc_waitq, wait);
228 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
229}
230
231static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
232{
233 struct snd_hwdep *hwdep;
234 int err, len, i;
235
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];
242
243 len = mixer->rc_cfg->packet_length;
244
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;
256
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;
265 }
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;
277}
278
279#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
280
281static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
282{
283 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
284 int index = kcontrol->private_value;
285
286 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
287 return 0;
288}
289
290static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291{
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;
296
297 if (value > 1)
298 return -EINVAL;
299 changed = value != mixer->audigy2nx_leds[index];
888ea7d5
TI
300 down_read(&mixer->chip->shutdown_rwsem);
301 if (mixer->chip->shutdown) {
302 err = -ENODEV;
303 goto out;
304 }
ca8dc34e
MJ
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,
17d900c4 309 !value, 0, NULL, 0);
7cdd8d73
MB
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,
17d900c4 315 !value, 0, NULL, 0);
ca8dc34e
MJ
316 else
317 err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda22
DM
318 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
319 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4 320 value, index + 2, NULL, 0);
888ea7d5
TI
321 out:
322 up_read(&mixer->chip->shutdown_rwsem);
7b1eda22
DM
323 if (err < 0)
324 return err;
325 mixer->audigy2nx_leds[index] = value;
326 return changed;
327}
328
329static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
330 {
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,
337 },
338 {
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,
345 },
346 {
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,
353 },
354};
355
356static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
357{
358 int i, err;
359
360 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
ca8dc34e
MJ
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;
7cdd8d73
MB
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;
7b1eda22
DM
367 if (i > 1 && /* Live24ext has 2 LEDs only */
368 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
ca8dc34e 369 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
7cdd8d73 370 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
7b1eda22
DM
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;
377 }
378 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
379 return 0;
380}
381
382static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
383 struct snd_info_buffer *buffer)
384{
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}
399 };
400 const struct sb_jack *jacks;
401 struct usb_mixer_interface *mixer = entry->private_data;
402 int i, err;
403 u8 buf[3];
404
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;
413
414 for (i = 0; jacks[i].name; ++i) {
415 snd_iprintf(buffer, "%s: ", jacks[i].name);
888ea7d5
TI
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,
7b1eda22
DM
421 usb_rcvctrlpipe(mixer->chip->dev, 0),
422 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
423 USB_RECIP_INTERFACE, 0,
17d900c4 424 jacks[i].unitid << 8, buf, 3);
888ea7d5 425 up_read(&mixer->chip->shutdown_rwsem);
7b1eda22
DM
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");
430 }
431}
432
433static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
434 struct snd_ctl_elem_value *ucontrol)
435{
436 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
437
438 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
439 return 0;
440}
441
442static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
443 struct snd_ctl_elem_value *ucontrol)
444{
445 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
446 u8 old_status, new_status;
447 int err, changed;
448
449 old_status = mixer->xonar_u1_status;
450 if (ucontrol->value.integer.value[0])
451 new_status = old_status | 0x02;
452 else
453 new_status = old_status & ~0x02;
454 changed = new_status != old_status;
888ea7d5
TI
455 down_read(&mixer->chip->shutdown_rwsem);
456 if (mixer->chip->shutdown)
457 err = -ENODEV;
458 else
459 err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda22
DM
460 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
461 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4 462 50, 0, &new_status, 1);
888ea7d5 463 up_read(&mixer->chip->shutdown_rwsem);
7b1eda22
DM
464 if (err < 0)
465 return err;
466 mixer->xonar_u1_status = new_status;
467 return changed;
468}
469
470static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
471 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
472 .name = "Digital Playback Switch",
473 .info = snd_ctl_boolean_mono_info,
474 .get = snd_xonar_u1_switch_get,
475 .put = snd_xonar_u1_switch_put,
476};
477
478static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
479{
480 int err;
481
482 err = snd_ctl_add(mixer->chip->card,
483 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
484 if (err < 0)
485 return err;
486 mixer->xonar_u1_status = 0x05;
487 return 0;
488}
489
54a8c500
DM
490/* Native Instruments device quirks */
491
492#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
493
494static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
495 struct snd_ctl_elem_value *ucontrol)
496{
497 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
498 struct usb_device *dev = mixer->chip->dev;
499 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
500 u16 wIndex = kcontrol->private_value & 0xffff;
501 u8 tmp;
888ea7d5 502 int ret;
54a8c500 503
888ea7d5
TI
504 down_read(&mixer->chip->shutdown_rwsem);
505 if (mixer->chip->shutdown)
506 ret = -ENODEV;
507 else
508 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
54a8c500
DM
509 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
510 0, cpu_to_le16(wIndex),
511 &tmp, sizeof(tmp), 1000);
888ea7d5 512 up_read(&mixer->chip->shutdown_rwsem);
54a8c500
DM
513
514 if (ret < 0) {
515 snd_printk(KERN_ERR
516 "unable to issue vendor read request (ret = %d)", ret);
517 return ret;
518 }
519
520 ucontrol->value.integer.value[0] = tmp;
521
522 return 0;
523}
524
525static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
526 struct snd_ctl_elem_value *ucontrol)
527{
528 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
529 struct usb_device *dev = mixer->chip->dev;
530 u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
531 u16 wIndex = kcontrol->private_value & 0xffff;
532 u16 wValue = ucontrol->value.integer.value[0];
888ea7d5 533 int ret;
54a8c500 534
888ea7d5
TI
535 down_read(&mixer->chip->shutdown_rwsem);
536 if (mixer->chip->shutdown)
537 ret = -ENODEV;
538 else
539 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
54a8c500
DM
540 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
541 cpu_to_le16(wValue), cpu_to_le16(wIndex),
542 NULL, 0, 1000);
888ea7d5 543 up_read(&mixer->chip->shutdown_rwsem);
54a8c500
DM
544
545 if (ret < 0) {
546 snd_printk(KERN_ERR
547 "unable to issue vendor write request (ret = %d)", ret);
548 return ret;
549 }
550
551 return 0;
552}
553
554static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
555 {
556 .name = "Direct Thru Channel A",
557 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
558 },
559 {
560 .name = "Direct Thru Channel B",
561 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
562 },
563 {
564 .name = "Phono Input Channel A",
565 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
566 },
567 {
568 .name = "Phono Input Channel B",
569 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
570 },
571};
572
573static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
574 {
575 .name = "Direct Thru Channel A",
576 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
577 },
578 {
579 .name = "Direct Thru Channel B",
580 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
581 },
582 {
583 .name = "Direct Thru Channel C",
584 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
585 },
586 {
587 .name = "Direct Thru Channel D",
588 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
589 },
590 {
591 .name = "Phono Input Channel A",
592 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
593 },
594 {
595 .name = "Phono Input Channel B",
596 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
597 },
598 {
599 .name = "Phono Input Channel C",
600 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
601 },
602 {
603 .name = "Phono Input Channel D",
604 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
605 },
606};
607
608static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
609 const struct snd_kcontrol_new *kc,
610 unsigned int count)
611{
612 int i, err = 0;
613 struct snd_kcontrol_new template = {
614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
615 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
616 .get = snd_nativeinstruments_control_get,
617 .put = snd_nativeinstruments_control_put,
618 .info = snd_ctl_boolean_mono_info,
619 };
620
621 for (i = 0; i < count; i++) {
622 struct snd_kcontrol *c;
623
624 template.name = kc[i].name;
625 template.private_value = kc[i].private_value;
626
627 c = snd_ctl_new1(&template, mixer);
628 err = snd_ctl_add(mixer->chip->card, c);
629
630 if (err < 0)
631 break;
632 }
633
634 return err;
635}
636
d5a0bf6c 637/* M-Audio FastTrack Ultra quirks */
d34bf148
FH
638/* FTU Effect switch */
639struct snd_ftu_eff_switch_priv_val {
640 struct usb_mixer_interface *mixer;
641 int cached_value;
642 int is_cached;
643};
644
645static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_info *uinfo)
647{
648 static const char *texts[8] = {"Room 1",
649 "Room 2",
650 "Room 3",
651 "Hall 1",
652 "Hall 2",
653 "Plate",
654 "Delay",
655 "Echo"
656 };
657
658 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
659 uinfo->count = 1;
660 uinfo->value.enumerated.items = 8;
661 if (uinfo->value.enumerated.item > 7)
662 uinfo->value.enumerated.item = 7;
663 strcpy(uinfo->value.enumerated.name,
664 texts[uinfo->value.enumerated.item]);
665
666 return 0;
667}
668
669static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
670 struct snd_ctl_elem_value *ucontrol)
671{
672 struct snd_usb_audio *chip;
673 struct usb_mixer_interface *mixer;
674 struct snd_ftu_eff_switch_priv_val *pval;
675 int err;
676 unsigned char value[2];
677
678 const int id = 6;
679 const int validx = 1;
680 const int val_len = 2;
681
682 value[0] = 0x00;
683 value[1] = 0x00;
684
685 pval = (struct snd_ftu_eff_switch_priv_val *)
686 kctl->private_value;
687
688 if (pval->is_cached) {
689 ucontrol->value.enumerated.item[0] = pval->cached_value;
690 return 0;
691 }
692
693 mixer = (struct usb_mixer_interface *) pval->mixer;
694 if (snd_BUG_ON(!mixer))
695 return -EINVAL;
696
697 chip = (struct snd_usb_audio *) mixer->chip;
698 if (snd_BUG_ON(!chip))
699 return -EINVAL;
700
701
888ea7d5
TI
702 down_read(&mixer->chip->shutdown_rwsem);
703 if (mixer->chip->shutdown)
704 err = -ENODEV;
705 else
706 err = snd_usb_ctl_msg(chip->dev,
d34bf148
FH
707 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
708 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
709 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
710 value, val_len);
888ea7d5 711 up_read(&mixer->chip->shutdown_rwsem);
d34bf148
FH
712 if (err < 0)
713 return err;
714
715 ucontrol->value.enumerated.item[0] = value[0];
716 pval->cached_value = value[0];
717 pval->is_cached = 1;
718
719 return 0;
720}
721
722static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
723 struct snd_ctl_elem_value *ucontrol)
724{
725 struct snd_usb_audio *chip;
726 struct snd_ftu_eff_switch_priv_val *pval;
727
728 struct usb_mixer_interface *mixer;
729 int changed, cur_val, err, new_val;
730 unsigned char value[2];
731
732
733 const int id = 6;
734 const int validx = 1;
735 const int val_len = 2;
736
737 changed = 0;
738
739 pval = (struct snd_ftu_eff_switch_priv_val *)
740 kctl->private_value;
741 cur_val = pval->cached_value;
742 new_val = ucontrol->value.enumerated.item[0];
743
744 mixer = (struct usb_mixer_interface *) pval->mixer;
745 if (snd_BUG_ON(!mixer))
746 return -EINVAL;
747
748 chip = (struct snd_usb_audio *) mixer->chip;
749 if (snd_BUG_ON(!chip))
750 return -EINVAL;
751
752 if (!pval->is_cached) {
753 /* Read current value */
888ea7d5
TI
754 down_read(&mixer->chip->shutdown_rwsem);
755 if (mixer->chip->shutdown)
756 err = -ENODEV;
757 else
758 err = snd_usb_ctl_msg(chip->dev,
d34bf148
FH
759 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
760 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
761 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
762 value, val_len);
888ea7d5 763 up_read(&mixer->chip->shutdown_rwsem);
d34bf148
FH
764 if (err < 0)
765 return err;
766
767 cur_val = value[0];
768 pval->cached_value = cur_val;
769 pval->is_cached = 1;
770 }
771 /* update value if needed */
772 if (cur_val != new_val) {
773 value[0] = new_val;
774 value[1] = 0;
888ea7d5
TI
775 down_read(&mixer->chip->shutdown_rwsem);
776 if (mixer->chip->shutdown)
777 err = -ENODEV;
778 else
779 err = snd_usb_ctl_msg(chip->dev,
d34bf148
FH
780 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
781 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
782 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
783 value, val_len);
888ea7d5 784 up_read(&mixer->chip->shutdown_rwsem);
d34bf148
FH
785 if (err < 0)
786 return err;
787
788 pval->cached_value = new_val;
789 pval->is_cached = 1;
790 changed = 1;
791 }
792
793 return changed;
794}
795
796static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer)
797{
798 static struct snd_kcontrol_new template = {
799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
800 .name = "Effect Program Switch",
801 .index = 0,
802 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
803 .info = snd_ftu_eff_switch_info,
804 .get = snd_ftu_eff_switch_get,
805 .put = snd_ftu_eff_switch_put
806 };
807
808 int err;
809 struct snd_kcontrol *kctl;
810 struct snd_ftu_eff_switch_priv_val *pval;
811
812 pval = kzalloc(sizeof(*pval), GFP_KERNEL);
813 if (!pval)
814 return -ENOMEM;
815
816 pval->cached_value = 0;
817 pval->is_cached = 0;
818 pval->mixer = mixer;
819
820 template.private_value = (unsigned long) pval;
821 kctl = snd_ctl_new1(&template, mixer->chip);
822 if (!kctl) {
823 kfree(pval);
824 return -ENOMEM;
825 }
826
827 err = snd_ctl_add(mixer->chip->card, kctl);
828 if (err < 0)
829 return err;
830
831 return 0;
832}
d5a0bf6c 833
cfe8f97c
FH
834/* Create volume controls for FTU devices*/
835static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
d5a0bf6c
DM
836{
837 char name[64];
8a4d1d39 838 unsigned int control, cmask;
d5a0bf6c
DM
839 int in, out, err;
840
8a4d1d39
FH
841 const unsigned int id = 5;
842 const int val_type = USB_MIXER_S16;
843
d5a0bf6c 844 for (out = 0; out < 8; out++) {
8a4d1d39 845 control = out + 1;
d5a0bf6c 846 for (in = 0; in < 8; in++) {
8a4d1d39 847 cmask = 1 << in;
d5a0bf6c 848 snprintf(name, sizeof(name),
8a4d1d39
FH
849 "AIn%d - Out%d Capture Volume",
850 in + 1, out + 1);
851 err = snd_create_std_mono_ctl(mixer, id, control,
852 cmask, val_type, name,
25ee7ef8 853 &snd_usb_mixer_vol_tlv);
d5a0bf6c
DM
854 if (err < 0)
855 return err;
856 }
d5a0bf6c 857 for (in = 8; in < 16; in++) {
8a4d1d39 858 cmask = 1 << in;
d5a0bf6c 859 snprintf(name, sizeof(name),
8a4d1d39
FH
860 "DIn%d - Out%d Playback Volume",
861 in - 7, out + 1);
862 err = snd_create_std_mono_ctl(mixer, id, control,
863 cmask, val_type, name,
25ee7ef8 864 &snd_usb_mixer_vol_tlv);
d5a0bf6c
DM
865 if (err < 0)
866 return err;
867 }
868 }
869
870 return 0;
871}
872
d34bf148
FH
873/* This control needs a volume quirk, see mixer.c */
874static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
875{
876 static const char name[] = "Effect Volume";
877 const unsigned int id = 6;
878 const int val_type = USB_MIXER_U8;
879 const unsigned int control = 2;
880 const unsigned int cmask = 0;
881
882 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
883 name, snd_usb_mixer_vol_tlv);
884}
885
886/* This control needs a volume quirk, see mixer.c */
887static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
888{
889 static const char name[] = "Effect Duration";
890 const unsigned int id = 6;
891 const int val_type = USB_MIXER_S16;
892 const unsigned int control = 3;
893 const unsigned int cmask = 0;
894
895 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
896 name, snd_usb_mixer_vol_tlv);
897}
898
899/* This control needs a volume quirk, see mixer.c */
900static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
901{
902 static const char name[] = "Effect Feedback Volume";
903 const unsigned int id = 6;
904 const int val_type = USB_MIXER_U8;
905 const unsigned int control = 4;
906 const unsigned int cmask = 0;
907
908 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
909 name, NULL);
910}
911
912static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
913{
914 unsigned int cmask;
915 int err, ch;
916 char name[48];
917
918 const unsigned int id = 7;
919 const int val_type = USB_MIXER_S16;
920 const unsigned int control = 7;
921
922 for (ch = 0; ch < 4; ++ch) {
923 cmask = 1 << ch;
924 snprintf(name, sizeof(name),
925 "Effect Return %d Volume", ch + 1);
926 err = snd_create_std_mono_ctl(mixer, id, control,
927 cmask, val_type, name,
928 snd_usb_mixer_vol_tlv);
929 if (err < 0)
930 return err;
931 }
932
933 return 0;
934}
935
936static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
937{
938 unsigned int cmask;
939 int err, ch;
940 char name[48];
941
942 const unsigned int id = 5;
943 const int val_type = USB_MIXER_S16;
944 const unsigned int control = 9;
945
946 for (ch = 0; ch < 8; ++ch) {
947 cmask = 1 << ch;
948 snprintf(name, sizeof(name),
949 "Effect Send AIn%d Volume", ch + 1);
950 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
951 val_type, name,
952 snd_usb_mixer_vol_tlv);
953 if (err < 0)
954 return err;
955 }
956 for (ch = 8; ch < 16; ++ch) {
957 cmask = 1 << ch;
958 snprintf(name, sizeof(name),
959 "Effect Send DIn%d Volume", ch - 7);
960 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
961 val_type, name,
962 snd_usb_mixer_vol_tlv);
963 if (err < 0)
964 return err;
965 }
966 return 0;
967}
968
cfe8f97c 969static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
7536c301 970{
8a4d1d39 971 int err;
7536c301 972
cfe8f97c 973 err = snd_ftu_create_volume_ctls(mixer);
8a4d1d39
FH
974 if (err < 0)
975 return err;
7536c301 976
d34bf148
FH
977 err = snd_ftu_create_effect_switch(mixer);
978 if (err < 0)
979 return err;
980 err = snd_ftu_create_effect_volume_ctl(mixer);
981 if (err < 0)
982 return err;
983
984 err = snd_ftu_create_effect_duration_ctl(mixer);
985 if (err < 0)
986 return err;
987
988 err = snd_ftu_create_effect_feedback_ctl(mixer);
989 if (err < 0)
990 return err;
991
992 err = snd_ftu_create_effect_return_ctls(mixer);
993 if (err < 0)
994 return err;
995
996 err = snd_ftu_create_effect_send_ctls(mixer);
997 if (err < 0)
998 return err;
999
8a4d1d39 1000 return 0;
7536c301
MH
1001}
1002
7b1eda22
DM
1003void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1004 unsigned char samplerate_id)
1005{
1006 struct usb_mixer_interface *mixer;
1007 struct usb_mixer_elem_info *cval;
1008 int unitid = 12; /* SamleRate ExtensionUnit ID */
1009
1010 list_for_each_entry(mixer, &chip->mixer_list, list) {
1011 cval = mixer->id_elems[unitid];
1012 if (cval) {
1013 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1014 cval->control << 8,
1015 samplerate_id);
1016 snd_usb_mixer_notify_id(mixer, unitid);
1017 }
1018 break;
1019 }
1020}
1021
b71dad18
MH
1022/*
1023 * The mixer units for Ebox-44 are corrupt, and even where they
1024 * are valid they presents mono controls as L and R channels of
1025 * stereo. So we provide a good mixer here.
1026 */
1027struct std_mono_table ebox44_table[] = {
989b0138
MH
1028 {
1029 .unitid = 4,
1030 .control = 1,
1031 .cmask = 0x0,
1032 .val_type = USB_MIXER_INV_BOOLEAN,
1033 .name = "Headphone Playback Switch"
1034 },
1035 {
1036 .unitid = 4,
1037 .control = 2,
1038 .cmask = 0x1,
1039 .val_type = USB_MIXER_S16,
1040 .name = "Headphone A Mix Playback Volume"
1041 },
1042 {
1043 .unitid = 4,
1044 .control = 2,
1045 .cmask = 0x2,
1046 .val_type = USB_MIXER_S16,
1047 .name = "Headphone B Mix Playback Volume"
1048 },
b71dad18 1049
989b0138
MH
1050 {
1051 .unitid = 7,
1052 .control = 1,
1053 .cmask = 0x0,
1054 .val_type = USB_MIXER_INV_BOOLEAN,
1055 .name = "Output Playback Switch"
1056 },
1057 {
1058 .unitid = 7,
1059 .control = 2,
1060 .cmask = 0x1,
1061 .val_type = USB_MIXER_S16,
1062 .name = "Output A Playback Volume"
1063 },
1064 {
1065 .unitid = 7,
1066 .control = 2,
1067 .cmask = 0x2,
1068 .val_type = USB_MIXER_S16,
1069 .name = "Output B Playback Volume"
1070 },
b71dad18 1071
989b0138
MH
1072 {
1073 .unitid = 10,
1074 .control = 1,
1075 .cmask = 0x0,
1076 .val_type = USB_MIXER_INV_BOOLEAN,
1077 .name = "Input Capture Switch"
1078 },
1079 {
1080 .unitid = 10,
1081 .control = 2,
1082 .cmask = 0x1,
1083 .val_type = USB_MIXER_S16,
1084 .name = "Input A Capture Volume"
1085 },
1086 {
1087 .unitid = 10,
1088 .control = 2,
1089 .cmask = 0x2,
1090 .val_type = USB_MIXER_S16,
1091 .name = "Input B Capture Volume"
1092 },
b71dad18 1093
989b0138 1094 {}
b71dad18
MH
1095};
1096
7b1eda22
DM
1097int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1098{
3347b26c 1099 int err = 0;
7b1eda22
DM
1100 struct snd_info_entry *entry;
1101
1102 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1103 return err;
1104
3347b26c
DM
1105 switch (mixer->chip->usb_id) {
1106 case USB_ID(0x041e, 0x3020):
1107 case USB_ID(0x041e, 0x3040):
1108 case USB_ID(0x041e, 0x3042):
7cdd8d73 1109 case USB_ID(0x041e, 0x30df):
3347b26c
DM
1110 case USB_ID(0x041e, 0x3048):
1111 err = snd_audigy2nx_controls_create(mixer);
1112 if (err < 0)
1113 break;
7b1eda22
DM
1114 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1115 snd_info_set_text_ops(entry, mixer,
1116 snd_audigy2nx_proc_read);
3347b26c 1117 break;
7b1eda22 1118
d5a0bf6c
DM
1119 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1120 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
cfe8f97c 1121 err = snd_ftu_create_mixer(mixer);
d5a0bf6c
DM
1122 break;
1123
3347b26c
DM
1124 case USB_ID(0x0b05, 0x1739):
1125 case USB_ID(0x0b05, 0x1743):
7b1eda22 1126 err = snd_xonar_u1_controls_create(mixer);
3347b26c 1127 break;
7b1eda22 1128
3347b26c 1129 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
54a8c500
DM
1130 err = snd_nativeinstruments_create_mixer(mixer,
1131 snd_nativeinstruments_ta6_mixers,
1132 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
3347b26c 1133 break;
54a8c500 1134
3347b26c 1135 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
54a8c500
DM
1136 err = snd_nativeinstruments_create_mixer(mixer,
1137 snd_nativeinstruments_ta10_mixers,
1138 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
3347b26c 1139 break;
7536c301
MH
1140
1141 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
b71dad18
MH
1142 /* detection is disabled in mixer_maps.c */
1143 err = snd_create_std_mono_table(mixer, ebox44_table);
7536c301 1144 break;
54a8c500
DM
1145 }
1146
3347b26c 1147 return err;
7b1eda22
DM
1148}
1149
1150void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1151 int unitid)
1152{
1153 if (!mixer->rc_cfg)
1154 return;
1155 /* unit ids specific to Extigy/Audigy 2 NX: */
1156 switch (unitid) {
1157 case 0: /* remote control */
1158 mixer->rc_urb->dev = mixer->chip->dev;
1159 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1160 break;
1161 case 4: /* digital in jack */
1162 case 7: /* line in jacks */
1163 case 19: /* speaker out jacks */
1164 case 20: /* headphones out jack */
1165 break;
1166 /* live24ext: 4 = line-in jack */
1167 case 3: /* hp-out jack (may actuate Mute) */
1168 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1169 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1170 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1171 break;
1172 default:
1173 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1174 break;
1175 }
1176}
1177