Blame view

sound/usb/mixer_quirks.c 40.7 KB
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1
2
3
4
5
6
7
8
9
10
11
  /*
   *   USB Audio Driver for ALSA
   *
   *   Quirks and vendor-specific extensions for mixer interfaces
   *
   *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
   *
   *   Many codes borrowed from audio.c by
   *	    Alan Cox (alan@lxorguk.ukuu.org.uk)
   *	    Thomas Sailer (sailer@ife.ee.ethz.ch)
   *
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
12
13
   *   Audio Advantage Micro II support added by:
   *	    Przemek Rudy (prudy1@o2.pl)
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   */
  
  #include <linux/init.h>
36db04565   Stephen Rothwell   ALSA: usb - use o...
31
  #include <linux/slab.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
32
33
  #include <linux/usb.h>
  #include <linux/usb/audio.h>
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
34
  #include <sound/asoundef.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
35
36
37
38
39
40
  #include <sound/core.h>
  #include <sound/control.h>
  #include <sound/hwdep.h>
  #include <sound/info.h>
  
  #include "usbaudio.h"
f0b5e634f   Daniel Mack   ALSA: usbmixer: r...
41
  #include "mixer.h"
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
42
43
  #include "mixer_quirks.h"
  #include "helper.h"
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
44
  extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
b71dad181   Mark Hills   ALSA: usb-audio: ...
45
46
47
48
49
50
  struct std_mono_table {
  	unsigned int unitid, control, cmask;
  	int val_type;
  	const char *name;
  	snd_kcontrol_tlv_rw_t *tlv_callback;
  };
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  /* private_free callback */
  static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
  {
  	kfree(kctl->private_data);
  	kctl->private_data = NULL;
  }
  
  /* This function allows for the creation of standard UAC controls.
   * See the quirks for M-Audio FTUs or Ebox-44.
   * If you don't want to set a TLV callback pass NULL.
   *
   * Since there doesn't seem to be a devices that needs a multichannel
   * version, we keep it mono for simplicity.
   */
9f8141059   Eldad Zack   ALSA: usb-audio: ...
65
  static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
66
67
68
69
  				unsigned int unitid,
  				unsigned int control,
  				unsigned int cmask,
  				int val_type,
9f8141059   Eldad Zack   ALSA: usb-audio: ...
70
  				unsigned int idx_off,
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  				const char *name,
  				snd_kcontrol_tlv_rw_t *tlv_callback)
  {
  	int err;
  	struct usb_mixer_elem_info *cval;
  	struct snd_kcontrol *kctl;
  
  	cval = kzalloc(sizeof(*cval), GFP_KERNEL);
  	if (!cval)
  		return -ENOMEM;
  
  	cval->id = unitid;
  	cval->mixer = mixer;
  	cval->val_type = val_type;
  	cval->channels = 1;
  	cval->control = control;
  	cval->cmask = cmask;
9f8141059   Eldad Zack   ALSA: usb-audio: ...
88
  	cval->idx_off = idx_off;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
89

7df4a691f   Mark Hills   ALSA: usb-audio: ...
90
91
  	/* get_min_max() is called only for integer volumes later,
  	 * so provide a short-cut for booleans */
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  	cval->min = 0;
  	cval->max = 1;
  	cval->res = 0;
  	cval->dBmin = 0;
  	cval->dBmax = 0;
  
  	/* Create control */
  	kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
  	if (!kctl) {
  		kfree(cval);
  		return -ENOMEM;
  	}
  
  	/* Set name */
  	snprintf(kctl->id.name, sizeof(kctl->id.name), name);
  	kctl->private_free = usb_mixer_elem_free;
  
  	/* set TLV */
  	if (tlv_callback) {
  		kctl->tlv.c = tlv_callback;
  		kctl->vd[0].access |=
  			SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  			SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  	}
  	/* Add control to mixer */
  	err = snd_usb_mixer_add_control(mixer, kctl);
  	if (err < 0)
  		return err;
  
  	return 0;
  }
9f8141059   Eldad Zack   ALSA: usb-audio: ...
123
124
125
126
127
128
129
130
131
132
133
  static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
  				unsigned int unitid,
  				unsigned int control,
  				unsigned int cmask,
  				int val_type,
  				const char *name,
  				snd_kcontrol_tlv_rw_t *tlv_callback)
  {
  	return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
  		val_type, 0 /* Offset */, name, tlv_callback);
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
134
  /*
b71dad181   Mark Hills   ALSA: usb-audio: ...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
   * Create a set of standard UAC controls from a table
   */
  static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
  				struct std_mono_table *t)
  {
  	int err;
  
  	while (t->name != NULL) {
  		err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
  				t->cmask, t->val_type, t->name, t->tlv_callback);
  		if (err < 0)
  			return err;
  		t++;
  	}
  
  	return 0;
  }
  
  /*
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
   * Sound Blaster remote control configuration
   *
   * format of remote control data:
   * Extigy:       xx 00
   * Audigy 2 NX:  06 80 xx 00 00 00
   * Live! 24-bit: 06 80 xx yy 22 83
   */
  static const struct rc_config {
  	u32 usb_id;
  	u8  offset;
  	u8  length;
  	u8  packet_length;
  	u8  min_packet_length; /* minimum accepted length of the URB result */
  	u8  mute_mixer_id;
  	u32 mute_code;
  } rc_configs[] = {
  	{ USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
  	{ USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
  	{ USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
173
  	{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 */
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
174
  	{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
  	{ USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
  };
  
  static void snd_usb_soundblaster_remote_complete(struct urb *urb)
  {
  	struct usb_mixer_interface *mixer = urb->context;
  	const struct rc_config *rc = mixer->rc_cfg;
  	u32 code;
  
  	if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
  		return;
  
  	code = mixer->rc_buffer[rc->offset];
  	if (rc->length == 2)
  		code |= mixer->rc_buffer[rc->offset + 1] << 8;
  
  	/* the Mute button actually changes the mixer control */
  	if (code == rc->mute_code)
  		snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
  	mixer->rc_code = code;
  	wmb();
  	wake_up(&mixer->rc_waitq);
  }
  
  static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
  				     long count, loff_t *offset)
  {
  	struct usb_mixer_interface *mixer = hw->private_data;
  	int err;
  	u32 rc_code;
  
  	if (count != 1 && count != 4)
  		return -EINVAL;
  	err = wait_event_interruptible(mixer->rc_waitq,
  				       (rc_code = xchg(&mixer->rc_code, 0)) != 0);
  	if (err == 0) {
  		if (count == 1)
  			err = put_user(rc_code, buf);
  		else
  			err = put_user(rc_code, (u32 __user *)buf);
  	}
  	return err < 0 ? err : count;
  }
  
  static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
  					    poll_table *wait)
  {
  	struct usb_mixer_interface *mixer = hw->private_data;
  
  	poll_wait(file, &mixer->rc_waitq, wait);
  	return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
  }
  
  static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
  {
  	struct snd_hwdep *hwdep;
  	int err, len, i;
  
  	for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
  		if (rc_configs[i].usb_id == mixer->chip->usb_id)
  			break;
  	if (i >= ARRAY_SIZE(rc_configs))
  		return 0;
  	mixer->rc_cfg = &rc_configs[i];
  
  	len = mixer->rc_cfg->packet_length;
  
  	init_waitqueue_head(&mixer->rc_waitq);
  	err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
  	if (err < 0)
  		return err;
  	snprintf(hwdep->name, sizeof(hwdep->name),
  		 "%s remote control", mixer->chip->card->shortname);
  	hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
  	hwdep->private_data = mixer;
  	hwdep->ops.read = snd_usb_sbrc_hwdep_read;
  	hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
  	hwdep->exclusive = 1;
  
  	mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
  	if (!mixer->rc_urb)
  		return -ENOMEM;
  	mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
  	if (!mixer->rc_setup_packet) {
  		usb_free_urb(mixer->rc_urb);
  		mixer->rc_urb = NULL;
  		return -ENOMEM;
  	}
  	mixer->rc_setup_packet->bRequestType =
  		USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
  	mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
  	mixer->rc_setup_packet->wValue = cpu_to_le16(0);
  	mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
  	mixer->rc_setup_packet->wLength = cpu_to_le16(len);
  	usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
  			     usb_rcvctrlpipe(mixer->chip->dev, 0),
  			     (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
  			     snd_usb_soundblaster_remote_complete, mixer);
  	return 0;
  }
  
  #define snd_audigy2nx_led_info		snd_ctl_boolean_mono_info
  
  static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	int index = kcontrol->private_value;
  
  	ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
  	return 0;
  }
  
  static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	int index = kcontrol->private_value;
  	int value = ucontrol->value.integer.value[0];
  	int err, changed;
  
  	if (value > 1)
  		return -EINVAL;
  	changed = value != mixer->audigy2nx_leds[index];
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
297
298
299
300
301
  	down_read(&mixer->chip->shutdown_rwsem);
  	if (mixer->chip->shutdown) {
  		err = -ENODEV;
  		goto out;
  	}
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
302
303
304
305
  	if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
  		err = snd_usb_ctl_msg(mixer->chip->dev,
  			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
306
  			      !value, 0, NULL, 0);
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
307
308
309
310
311
  	/* USB X-Fi S51 Pro */
  	if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
  		err = snd_usb_ctl_msg(mixer->chip->dev,
  			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
312
  			      !value, 0, NULL, 0);
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
313
314
  	else
  		err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
315
316
  			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
317
  			      value, index + 2, NULL, 0);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
318
319
   out:
  	up_read(&mixer->chip->shutdown_rwsem);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  	if (err < 0)
  		return err;
  	mixer->audigy2nx_leds[index] = value;
  	return changed;
  }
  
  static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "CMSS LED Switch",
  		.info = snd_audigy2nx_led_info,
  		.get = snd_audigy2nx_led_get,
  		.put = snd_audigy2nx_led_put,
  		.private_value = 0,
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Power LED Switch",
  		.info = snd_audigy2nx_led_info,
  		.get = snd_audigy2nx_led_get,
  		.put = snd_audigy2nx_led_put,
  		.private_value = 1,
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Dolby Digital LED Switch",
  		.info = snd_audigy2nx_led_info,
  		.get = snd_audigy2nx_led_get,
  		.put = snd_audigy2nx_led_put,
  		.private_value = 2,
  	},
  };
  
  static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
  {
  	int i, err;
  
  	for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
358
359
360
  		/* USB X-Fi S51 doesn't have a CMSS LED */
  		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
  			continue;
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
361
362
363
  		/* USB X-Fi S51 Pro doesn't have one either */
  		if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
  			continue;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
364
365
  		if (i > 1 && /* Live24ext has 2 LEDs only */
  			(mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
366
  			 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
367
  			 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  			 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
  			break; 
  		err = snd_ctl_add(mixer->chip->card,
  				  snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
  		if (err < 0)
  			return err;
  	}
  	mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
  	return 0;
  }
  
  static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
  				    struct snd_info_buffer *buffer)
  {
  	static const struct sb_jack {
  		int unitid;
  		const char *name;
  	}  jacks_audigy2nx[] = {
  		{4,  "dig in "},
  		{7,  "line in"},
  		{19, "spk out"},
  		{20, "hph out"},
  		{-1, NULL}
  	}, jacks_live24ext[] = {
  		{4,  "line in"}, /* &1=Line, &2=Mic*/
  		{3,  "hph out"}, /* headphones */
  		{0,  "RC     "}, /* last command, 6 bytes see rc_config above */
  		{-1, NULL}
  	};
  	const struct sb_jack *jacks;
  	struct usb_mixer_interface *mixer = entry->private_data;
  	int i, err;
  	u8 buf[3];
  
  	snd_iprintf(buffer, "%s jacks
  
  ", mixer->chip->card->shortname);
  	if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
  		jacks = jacks_audigy2nx;
  	else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  		 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  		jacks = jacks_live24ext;
  	else
  		return;
  
  	for (i = 0; jacks[i].name; ++i) {
  		snd_iprintf(buffer, "%s: ", jacks[i].name);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
415
416
417
418
419
  		down_read(&mixer->chip->shutdown_rwsem);
  		if (mixer->chip->shutdown)
  			err = 0;
  		else
  			err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
420
421
422
  				      usb_rcvctrlpipe(mixer->chip->dev, 0),
  				      UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
  				      USB_RECIP_INTERFACE, 0,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
423
  				      jacks[i].unitid << 8, buf, 3);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
424
  		up_read(&mixer->chip->shutdown_rwsem);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
425
426
427
428
429
430
431
432
  		if (err == 3 && (buf[0] == 3 || buf[0] == 6))
  			snd_iprintf(buffer, "%02x %02x
  ", buf[1], buf[2]);
  		else
  			snd_iprintf(buffer, "?
  ");
  	}
  }
1d31affbe   Denis Washington   ALSA: usb-audio: ...
433
  /* ASUS Xonar U1 / U3 controls */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
  static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  
  	ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
  	return 0;
  }
  
  static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	u8 old_status, new_status;
  	int err, changed;
  
  	old_status = mixer->xonar_u1_status;
  	if (ucontrol->value.integer.value[0])
  		new_status = old_status | 0x02;
  	else
  		new_status = old_status & ~0x02;
  	changed = new_status != old_status;
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
456
457
458
459
460
  	down_read(&mixer->chip->shutdown_rwsem);
  	if (mixer->chip->shutdown)
  		err = -ENODEV;
  	else
  		err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
461
462
  			      usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
463
  			      50, 0, &new_status, 1);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
464
  	up_read(&mixer->chip->shutdown_rwsem);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
  	if (err < 0)
  		return err;
  	mixer->xonar_u1_status = new_status;
  	return changed;
  }
  
  static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Digital Playback Switch",
  	.info = snd_ctl_boolean_mono_info,
  	.get = snd_xonar_u1_switch_get,
  	.put = snd_xonar_u1_switch_put,
  };
  
  static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  {
  	int err;
  
  	err = snd_ctl_add(mixer->chip->card,
  			  snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
  	if (err < 0)
  		return err;
  	mixer->xonar_u1_status = 0x05;
  	return 0;
  }
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
490
491
492
493
494
495
496
497
498
499
500
501
  /* Native Instruments device quirks */
  
  #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
  
  static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	struct usb_device *dev = mixer->chip->dev;
  	u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  	u16 wIndex = kcontrol->private_value & 0xffff;
  	u8 tmp;
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
502
  	int ret;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
503

888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
504
505
506
507
508
  	down_read(&mixer->chip->shutdown_rwsem);
  	if (mixer->chip->shutdown)
  		ret = -ENODEV;
  	else
  		ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
509
  				  USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
889d66848   Eldad Zack   ALSA: usb-audio: ...
510
  				  0, wIndex,
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
511
  				  &tmp, sizeof(tmp), 1000);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
512
  	up_read(&mixer->chip->shutdown_rwsem);
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
  
  	if (ret < 0) {
  		snd_printk(KERN_ERR
  			   "unable to issue vendor read request (ret = %d)", ret);
  		return ret;
  	}
  
  	ucontrol->value.integer.value[0] = tmp;
  
  	return 0;
  }
  
  static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	struct usb_device *dev = mixer->chip->dev;
  	u8 bRequest = (kcontrol->private_value >> 16) & 0xff;
  	u16 wIndex = kcontrol->private_value & 0xffff;
  	u16 wValue = ucontrol->value.integer.value[0];
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
533
  	int ret;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
534

888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
535
536
537
538
539
  	down_read(&mixer->chip->shutdown_rwsem);
  	if (mixer->chip->shutdown)
  		ret = -ENODEV;
  	else
  		ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest,
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
540
  				  USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
889d66848   Eldad Zack   ALSA: usb-audio: ...
541
  				  wValue, wIndex,
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
542
  				  NULL, 0, 1000);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
543
  	up_read(&mixer->chip->shutdown_rwsem);
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
  
  	if (ret < 0) {
  		snd_printk(KERN_ERR
  			   "unable to issue vendor write request (ret = %d)", ret);
  		return ret;
  	}
  
  	return 0;
  }
  
  static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
  	{
  		.name = "Direct Thru Channel A",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  	},
  	{
  		.name = "Direct Thru Channel B",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  	},
  	{
  		.name = "Phono Input Channel A",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  	},
  	{
  		.name = "Phono Input Channel B",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  	},
  };
  
  static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
  	{
  		.name = "Direct Thru Channel A",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
  	},
  	{
  		.name = "Direct Thru Channel B",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
  	},
  	{
  		.name = "Direct Thru Channel C",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x07),
  	},
  	{
  		.name = "Direct Thru Channel D",
  		.private_value = _MAKE_NI_CONTROL(0x01, 0x09),
  	},
  	{
  		.name = "Phono Input Channel A",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
  	},
  	{
  		.name = "Phono Input Channel B",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
  	},
  	{
  		.name = "Phono Input Channel C",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x07),
  	},
  	{
  		.name = "Phono Input Channel D",
  		.private_value = _MAKE_NI_CONTROL(0x02, 0x09),
  	},
  };
  
  static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
  					      const struct snd_kcontrol_new *kc,
  					      unsigned int count)
  {
  	int i, err = 0;
  	struct snd_kcontrol_new template = {
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  		.get = snd_nativeinstruments_control_get,
  		.put = snd_nativeinstruments_control_put,
  		.info = snd_ctl_boolean_mono_info,
  	};
  
  	for (i = 0; i < count; i++) {
  		struct snd_kcontrol *c;
  
  		template.name = kc[i].name;
  		template.private_value = kc[i].private_value;
  
  		c = snd_ctl_new1(&template, mixer);
  		err = snd_ctl_add(mixer->chip->card, c);
  
  		if (err < 0)
  			break;
  	}
  
  	return err;
  }
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
636
  /* M-Audio FastTrack Ultra quirks */
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
637
  /* FTU Effect switch (also used by C400/C600) */
d34bf1485   Felix Homann   ALSA: usb-audio: ...
638
639
640
641
  struct snd_ftu_eff_switch_priv_val {
  	struct usb_mixer_interface *mixer;
  	int cached_value;
  	int is_cached;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
642
643
  	int bUnitID;
  	int validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  };
  
  static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_info *uinfo)
  {
  	static const char *texts[8] = {"Room 1",
  				       "Room 2",
  				       "Room 3",
  				       "Hall 1",
  				       "Hall 2",
  				       "Plate",
  				       "Delay",
  				       "Echo"
  	};
  
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	uinfo->value.enumerated.items = 8;
  	if (uinfo->value.enumerated.item > 7)
  		uinfo->value.enumerated.item = 7;
  	strcpy(uinfo->value.enumerated.name,
  		texts[uinfo->value.enumerated.item]);
  
  	return 0;
  }
  
  static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  					struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_usb_audio *chip;
  	struct usb_mixer_interface *mixer;
  	struct snd_ftu_eff_switch_priv_val *pval;
  	int err;
  	unsigned char value[2];
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
678
  	int id, validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
679

d34bf1485   Felix Homann   ALSA: usb-audio: ...
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
  	const int val_len = 2;
  
  	value[0] = 0x00;
  	value[1] = 0x00;
  
  	pval = (struct snd_ftu_eff_switch_priv_val *)
  		kctl->private_value;
  
  	if (pval->is_cached) {
  		ucontrol->value.enumerated.item[0] = pval->cached_value;
  		return 0;
  	}
  
  	mixer = (struct usb_mixer_interface *) pval->mixer;
  	if (snd_BUG_ON(!mixer))
  		return -EINVAL;
  
  	chip = (struct snd_usb_audio *) mixer->chip;
  	if (snd_BUG_ON(!chip))
  		return -EINVAL;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
700
701
  	id = pval->bUnitID;
  	validx = pval->validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
702

888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
703
704
705
706
707
  	down_read(&mixer->chip->shutdown_rwsem);
  	if (mixer->chip->shutdown)
  		err = -ENODEV;
  	else
  		err = snd_usb_ctl_msg(chip->dev,
d34bf1485   Felix Homann   ALSA: usb-audio: ...
708
709
710
711
  			usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  			USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  			validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  			value, val_len);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
712
  	up_read(&mixer->chip->shutdown_rwsem);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  	if (err < 0)
  		return err;
  
  	ucontrol->value.enumerated.item[0] = value[0];
  	pval->cached_value = value[0];
  	pval->is_cached = 1;
  
  	return 0;
  }
  
  static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  					struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_usb_audio *chip;
  	struct snd_ftu_eff_switch_priv_val *pval;
  
  	struct usb_mixer_interface *mixer;
  	int changed, cur_val, err, new_val;
  	unsigned char value[2];
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
732
  	int id, validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
733

d34bf1485   Felix Homann   ALSA: usb-audio: ...
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
  	const int val_len = 2;
  
  	changed = 0;
  
  	pval = (struct snd_ftu_eff_switch_priv_val *)
  		kctl->private_value;
  	cur_val = pval->cached_value;
  	new_val = ucontrol->value.enumerated.item[0];
  
  	mixer = (struct usb_mixer_interface *) pval->mixer;
  	if (snd_BUG_ON(!mixer))
  		return -EINVAL;
  
  	chip = (struct snd_usb_audio *) mixer->chip;
  	if (snd_BUG_ON(!chip))
  		return -EINVAL;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
750
751
  	id = pval->bUnitID;
  	validx = pval->validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
752
753
  	if (!pval->is_cached) {
  		/* Read current value */
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
754
755
756
757
758
  		down_read(&mixer->chip->shutdown_rwsem);
  		if (mixer->chip->shutdown)
  			err = -ENODEV;
  		else
  			err = snd_usb_ctl_msg(chip->dev,
d34bf1485   Felix Homann   ALSA: usb-audio: ...
759
760
761
762
  				usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
  				USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  				validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  				value, val_len);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
763
  		up_read(&mixer->chip->shutdown_rwsem);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
764
765
766
767
768
769
770
771
772
773
774
  		if (err < 0)
  			return err;
  
  		cur_val = value[0];
  		pval->cached_value = cur_val;
  		pval->is_cached = 1;
  	}
  	/* update value if needed */
  	if (cur_val != new_val) {
  		value[0] = new_val;
  		value[1] = 0;
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
775
776
777
778
779
  		down_read(&mixer->chip->shutdown_rwsem);
  		if (mixer->chip->shutdown)
  			err = -ENODEV;
  		else
  			err = snd_usb_ctl_msg(chip->dev,
d34bf1485   Felix Homann   ALSA: usb-audio: ...
780
781
782
783
  				usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  				USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  				validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
  				value, val_len);
888ea7d5a   Takashi Iwai   ALSA: usb-audio: ...
784
  		up_read(&mixer->chip->shutdown_rwsem);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
785
786
787
788
789
790
791
792
793
794
  		if (err < 0)
  			return err;
  
  		pval->cached_value = new_val;
  		pval->is_cached = 1;
  		changed = 1;
  	}
  
  	return changed;
  }
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
795
796
  static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
  	int validx, int bUnitID)
d34bf1485   Felix Homann   ALSA: usb-audio: ...
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
  {
  	static struct snd_kcontrol_new template = {
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Effect Program Switch",
  		.index = 0,
  		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  		.info = snd_ftu_eff_switch_info,
  		.get = snd_ftu_eff_switch_get,
  		.put = snd_ftu_eff_switch_put
  	};
  
  	int err;
  	struct snd_kcontrol *kctl;
  	struct snd_ftu_eff_switch_priv_val *pval;
  
  	pval = kzalloc(sizeof(*pval), GFP_KERNEL);
  	if (!pval)
  		return -ENOMEM;
  
  	pval->cached_value = 0;
  	pval->is_cached = 0;
  	pval->mixer = mixer;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
819
820
  	pval->bUnitID = bUnitID;
  	pval->validx = validx;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
821
822
823
824
825
826
827
828
829
830
831
832
833
834
  
  	template.private_value = (unsigned long) pval;
  	kctl = snd_ctl_new1(&template, mixer->chip);
  	if (!kctl) {
  		kfree(pval);
  		return -ENOMEM;
  	}
  
  	err = snd_ctl_add(mixer->chip->card, kctl);
  	if (err < 0)
  		return err;
  
  	return 0;
  }
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
835

cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
836
837
  /* Create volume controls for FTU devices*/
  static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
838
839
  {
  	char name[64];
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
840
  	unsigned int control, cmask;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
841
  	int in, out, err;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
842
843
  	const unsigned int id = 5;
  	const int val_type = USB_MIXER_S16;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
844
  	for (out = 0; out < 8; out++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
845
  		control = out + 1;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
846
  		for (in = 0; in < 8; in++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
847
  			cmask = 1 << in;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
848
  			snprintf(name, sizeof(name),
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
849
850
851
852
  				"AIn%d - Out%d Capture Volume",
  				in  + 1, out + 1);
  			err = snd_create_std_mono_ctl(mixer, id, control,
  							cmask, val_type, name,
25ee7ef8f   Felix Homann   ALSA: usb-audio: ...
853
  							&snd_usb_mixer_vol_tlv);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
854
855
856
  			if (err < 0)
  				return err;
  		}
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
857
  		for (in = 8; in < 16; in++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
858
  			cmask = 1 << in;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
859
  			snprintf(name, sizeof(name),
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
860
861
862
863
  				"DIn%d - Out%d Playback Volume",
  				in - 7, out + 1);
  			err = snd_create_std_mono_ctl(mixer, id, control,
  							cmask, val_type, name,
25ee7ef8f   Felix Homann   ALSA: usb-audio: ...
864
  							&snd_usb_mixer_vol_tlv);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
865
866
867
868
869
870
871
  			if (err < 0)
  				return err;
  		}
  	}
  
  	return 0;
  }
d34bf1485   Felix Homann   ALSA: usb-audio: ...
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
  /* This control needs a volume quirk, see mixer.c */
  static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Volume";
  	const unsigned int id = 6;
  	const int val_type = USB_MIXER_U8;
  	const unsigned int control = 2;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, snd_usb_mixer_vol_tlv);
  }
  
  /* This control needs a volume quirk, see mixer.c */
  static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Duration";
  	const unsigned int id = 6;
  	const int val_type = USB_MIXER_S16;
  	const unsigned int control = 3;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, snd_usb_mixer_vol_tlv);
  }
  
  /* This control needs a volume quirk, see mixer.c */
  static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Feedback Volume";
  	const unsigned int id = 6;
  	const int val_type = USB_MIXER_U8;
  	const unsigned int control = 4;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, NULL);
  }
  
  static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
  {
  	unsigned int cmask;
  	int err, ch;
  	char name[48];
  
  	const unsigned int id = 7;
  	const int val_type = USB_MIXER_S16;
  	const unsigned int control = 7;
  
  	for (ch = 0; ch < 4; ++ch) {
  		cmask = 1 << ch;
  		snprintf(name, sizeof(name),
  			"Effect Return %d Volume", ch + 1);
  		err = snd_create_std_mono_ctl(mixer, id, control,
  						cmask, val_type, name,
  						snd_usb_mixer_vol_tlv);
  		if (err < 0)
  			return err;
  	}
  
  	return 0;
  }
  
  static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
  {
  	unsigned int  cmask;
  	int err, ch;
  	char name[48];
  
  	const unsigned int id = 5;
  	const int val_type = USB_MIXER_S16;
  	const unsigned int control = 9;
  
  	for (ch = 0; ch < 8; ++ch) {
  		cmask = 1 << ch;
  		snprintf(name, sizeof(name),
  			"Effect Send AIn%d Volume", ch + 1);
  		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  						val_type, name,
  						snd_usb_mixer_vol_tlv);
  		if (err < 0)
  			return err;
  	}
  	for (ch = 8; ch < 16; ++ch) {
  		cmask = 1 << ch;
  		snprintf(name, sizeof(name),
  			"Effect Send DIn%d Volume", ch - 7);
  		err = snd_create_std_mono_ctl(mixer, id, control, cmask,
  						val_type, name,
  						snd_usb_mixer_vol_tlv);
  		if (err < 0)
  			return err;
  	}
  	return 0;
  }
cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
967
  static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
7536c301f   Mark Hills   ALSA: snd-usb-aud...
968
  {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
969
  	int err;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
970

cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
971
  	err = snd_ftu_create_volume_ctls(mixer);
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
972
973
  	if (err < 0)
  		return err;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
974

d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
975
  	err = snd_ftu_create_effect_switch(mixer, 1, 6);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
976
977
  	if (err < 0)
  		return err;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
978

d34bf1485   Felix Homann   ALSA: usb-audio: ...
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
  	err = snd_ftu_create_effect_volume_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_ftu_create_effect_duration_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_ftu_create_effect_feedback_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_ftu_create_effect_return_ctls(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_ftu_create_effect_send_ctls(mixer);
  	if (err < 0)
  		return err;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
998
  	return 0;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
999
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
  void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
  			       unsigned char samplerate_id)
  {
  	struct usb_mixer_interface *mixer;
  	struct usb_mixer_elem_info *cval;
  	int unitid = 12; /* SamleRate ExtensionUnit ID */
  
  	list_for_each_entry(mixer, &chip->mixer_list, list) {
  		cval = mixer->id_elems[unitid];
  		if (cval) {
  			snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  						    cval->control << 8,
  						    samplerate_id);
  			snd_usb_mixer_notify_id(mixer, unitid);
  		}
  		break;
  	}
  }
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1018
1019
  /* M-Audio Fast Track C400/C600 */
  /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1020
1021
1022
1023
1024
  static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
  {
  	char name[64];
  	unsigned int cmask, offset;
  	int out, chan, err;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1025
1026
  	int num_outs = 0;
  	int num_ins = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1027
1028
1029
1030
  
  	const unsigned int id = 0x40;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x0763, 0x2030):
  		num_outs = 6;
  		num_ins = 4;
  		break;
  	case USB_ID(0x0763, 0x2031):
  		num_outs = 8;
  		num_ins = 6;
  		break;
  	}
  
  	for (chan = 0; chan < num_outs + num_ins; chan++) {
  		for (out = 0; out < num_outs; out++) {
  			if (chan < num_outs) {
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1045
1046
1047
1048
1049
1050
  				snprintf(name, sizeof(name),
  					"PCM%d-Out%d Playback Volume",
  					chan + 1, out + 1);
  			} else {
  				snprintf(name, sizeof(name),
  					"In%d-Out%d Playback Volume",
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1051
  					chan - num_outs + 1, out + 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1052
1053
1054
  			}
  
  			cmask = (out == 0) ? 0 : 1 << (out - 1);
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1055
  			offset = chan * num_outs;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
  			err = snd_create_std_mono_ctl_offset(mixer, id, control,
  						cmask, val_type, offset, name,
  						&snd_usb_mixer_vol_tlv);
  			if (err < 0)
  				return err;
  		}
  	}
  
  	return 0;
  }
  
  /* This control needs a volume quirk, see mixer.c */
  static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Volume";
  	const unsigned int id = 0x43;
  	const int val_type = USB_MIXER_U8;
  	const unsigned int control = 3;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, snd_usb_mixer_vol_tlv);
  }
  
  /* This control needs a volume quirk, see mixer.c */
  static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Duration";
  	const unsigned int id = 0x43;
  	const int val_type = USB_MIXER_S16;
  	const unsigned int control = 4;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, snd_usb_mixer_vol_tlv);
  }
  
  /* This control needs a volume quirk, see mixer.c */
  static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
  {
  	static const char name[] = "Effect Feedback Volume";
  	const unsigned int id = 0x43;
  	const int val_type = USB_MIXER_U8;
  	const unsigned int control = 5;
  	const unsigned int cmask = 0;
  
  	return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
  					name, NULL);
  }
  
  static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
  {
  	char name[64];
  	unsigned int cmask;
  	int chan, err;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1111
1112
  	int num_outs = 0;
  	int num_ins = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1113
1114
1115
1116
  
  	const unsigned int id = 0x42;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x0763, 0x2030):
  		num_outs = 6;
  		num_ins = 4;
  		break;
  	case USB_ID(0x0763, 0x2031):
  		num_outs = 8;
  		num_ins = 6;
  		break;
  	}
  
  	for (chan = 0; chan < num_outs + num_ins; chan++) {
  		if (chan < num_outs) {
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1130
1131
1132
1133
1134
1135
  			snprintf(name, sizeof(name),
  				"Effect Send DOut%d",
  				chan + 1);
  		} else {
  			snprintf(name, sizeof(name),
  				"Effect Send AIn%d",
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1136
  				chan - num_outs + 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
  		}
  
  		cmask = (chan == 0) ? 0 : 1 << (chan - 1);
  		err = snd_create_std_mono_ctl(mixer, id, control,
  						cmask, val_type, name,
  						&snd_usb_mixer_vol_tlv);
  		if (err < 0)
  			return err;
  	}
  
  	return 0;
  }
  
  static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
  {
  	char name[64];
  	unsigned int cmask;
  	int chan, err;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1155
1156
  	int num_outs = 0;
  	int offset = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1157
1158
1159
1160
  
  	const unsigned int id = 0x40;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1161

e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x0763, 0x2030):
  		num_outs = 6;
  		offset = 0x3c;
  		/* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
  		break;
  	case USB_ID(0x0763, 0x2031):
  		num_outs = 8;
  		offset = 0x70;
  		/* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
  		break;
  	}
  
  	for (chan = 0; chan < num_outs; chan++) {
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1176
1177
1178
  		snprintf(name, sizeof(name),
  			"Effect Return %d",
  			chan + 1);
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1179
1180
  		cmask = (chan == 0) ? 0 :
  			1 << (chan + (chan % 2) * num_outs - 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
  		err = snd_create_std_mono_ctl_offset(mixer, id, control,
  						cmask, val_type, offset, name,
  						&snd_usb_mixer_vol_tlv);
  		if (err < 0)
  			return err;
  	}
  
  	return 0;
  }
  
  static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
  {
  	int err;
  
  	err = snd_c400_create_vol_ctls(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_c400_create_effect_vol_ctls(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_c400_create_effect_ret_vol_ctls(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
  	if (err < 0)
  		return err;
  
  	err = snd_c400_create_effect_volume_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_c400_create_effect_duration_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	err = snd_c400_create_effect_feedback_ctl(mixer);
  	if (err < 0)
  		return err;
  
  	return 0;
  }
b71dad181   Mark Hills   ALSA: usb-audio: ...
1225
1226
1227
1228
1229
  /*
   * The mixer units for Ebox-44 are corrupt, and even where they
   * are valid they presents mono controls as L and R channels of
   * stereo. So we provide a good mixer here.
   */
e8e7da23c   Sachin Kamat   ALSA: usb-audio: ...
1230
  static struct std_mono_table ebox44_table[] = {
989b01385   Mark Hills   ALSA: usb-audio: ...
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
  	{
  		.unitid = 4,
  		.control = 1,
  		.cmask = 0x0,
  		.val_type = USB_MIXER_INV_BOOLEAN,
  		.name = "Headphone Playback Switch"
  	},
  	{
  		.unitid = 4,
  		.control = 2,
  		.cmask = 0x1,
  		.val_type = USB_MIXER_S16,
  		.name = "Headphone A Mix Playback Volume"
  	},
  	{
  		.unitid = 4,
  		.control = 2,
  		.cmask = 0x2,
  		.val_type = USB_MIXER_S16,
  		.name = "Headphone B Mix Playback Volume"
  	},
b71dad181   Mark Hills   ALSA: usb-audio: ...
1252

989b01385   Mark Hills   ALSA: usb-audio: ...
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
  	{
  		.unitid = 7,
  		.control = 1,
  		.cmask = 0x0,
  		.val_type = USB_MIXER_INV_BOOLEAN,
  		.name = "Output Playback Switch"
  	},
  	{
  		.unitid = 7,
  		.control = 2,
  		.cmask = 0x1,
  		.val_type = USB_MIXER_S16,
  		.name = "Output A Playback Volume"
  	},
  	{
  		.unitid = 7,
  		.control = 2,
  		.cmask = 0x2,
  		.val_type = USB_MIXER_S16,
  		.name = "Output B Playback Volume"
  	},
b71dad181   Mark Hills   ALSA: usb-audio: ...
1274

989b01385   Mark Hills   ALSA: usb-audio: ...
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
  	{
  		.unitid = 10,
  		.control = 1,
  		.cmask = 0x0,
  		.val_type = USB_MIXER_INV_BOOLEAN,
  		.name = "Input Capture Switch"
  	},
  	{
  		.unitid = 10,
  		.control = 2,
  		.cmask = 0x1,
  		.val_type = USB_MIXER_S16,
  		.name = "Input A Capture Volume"
  	},
  	{
  		.unitid = 10,
  		.control = 2,
  		.cmask = 0x2,
  		.val_type = USB_MIXER_S16,
  		.name = "Input B Capture Volume"
  	},
b71dad181   Mark Hills   ALSA: usb-audio: ...
1296

989b01385   Mark Hills   ALSA: usb-audio: ...
1297
  	{}
b71dad181   Mark Hills   ALSA: usb-audio: ...
1298
  };
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
  /* Audio Advantage Micro II findings:
   *
   * Mapping spdif AES bits to vendor register.bit:
   * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
   * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
   * AES2: [0 0 0 0 0 0 0 0]
   * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
   *                           (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
   *
   * power on values:
   * r2: 0x10
   * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
   *           just after it to 0xa0, presumably it disables/mutes some analog
   *           parts when there is no audio.)
   * r9: 0x28
   *
   * Optical transmitter on/off:
   * vendor register.bit: 9.1
   * 0 - on (0x28 register value)
   * 1 - off (0x2a register value)
   *
   */
  static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_info *uinfo)
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  	uinfo->count = 1;
  	return 0;
  }
  
  static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	int err;
  	struct usb_interface *iface;
  	struct usb_host_interface *alts;
  	unsigned int ep;
  	unsigned char data[3];
  	int rate;
  
  	ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
  	ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
  	ucontrol->value.iec958.status[2] = 0x00;
  
  	/* use known values for that card: interface#1 altsetting#1 */
  	iface = usb_ifnum_to_if(mixer->chip->dev, 1);
  	alts = &iface->altsetting[1];
  	ep = get_endpoint(alts, 0)->bEndpointAddress;
  
  	err = snd_usb_ctl_msg(mixer->chip->dev,
  			usb_rcvctrlpipe(mixer->chip->dev, 0),
  			UAC_GET_CUR,
  			USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
  			UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
  			ep,
  			data,
  			sizeof(data));
  	if (err < 0)
  		goto end;
  
  	rate = data[0] | (data[1] << 8) | (data[2] << 16);
  	ucontrol->value.iec958.status[3] = (rate == 48000) ?
  			IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
  
  	err = 0;
  end:
  	return err;
  }
  
  static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	int err;
  	u8 reg;
  	unsigned long priv_backup = kcontrol->private_value;
  
  	reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) |
  			(ucontrol->value.iec958.status[0] & 0x0f);
  	err = snd_usb_ctl_msg(mixer->chip->dev,
  			usb_sndctrlpipe(mixer->chip->dev, 0),
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			2,
  			NULL,
  			0);
  	if (err < 0)
  		goto end;
  
  	kcontrol->private_value &= 0xfffff0f0;
  	kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
  	kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f);
  
  	reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ?
  			0xa0 : 0x20;
  	reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f;
  	err = snd_usb_ctl_msg(mixer->chip->dev,
  			usb_sndctrlpipe(mixer->chip->dev, 0),
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			3,
  			NULL,
  			0);
  	if (err < 0)
  		goto end;
  
  	kcontrol->private_value &= 0xffff0fff;
  	kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
  
  	/* The frequency bits in AES3 cannot be set via register access. */
  
  	/* Silently ignore any bits from the request that cannot be set. */
  
  	err = (priv_backup != kcontrol->private_value);
  end:
  	return err;
  }
  
  static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.iec958.status[0] = 0x0f;
  	ucontrol->value.iec958.status[1] = 0xff;
  	ucontrol->value.iec958.status[2] = 0x00;
  	ucontrol->value.iec958.status[3] = 0x00;
  
  	return 0;
  }
  
  static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
  
  	return 0;
  }
  
  static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
  	int err;
  	u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
  
  	err = snd_usb_ctl_msg(mixer->chip->dev,
  			usb_sndctrlpipe(mixer->chip->dev, 0),
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			9,
  			NULL,
  			0);
  
  	if (!err) {
  		err = (reg != (kcontrol->private_value & 0x0ff));
  		if (err)
  			kcontrol->private_value = reg;
  	}
  
  	return err;
  }
  
  static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
  	{
  		.iface =    SNDRV_CTL_ELEM_IFACE_PCM,
  		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  		.info =     snd_microii_spdif_info,
  		.get =      snd_microii_spdif_default_get,
  		.put =      snd_microii_spdif_default_put,
  		.private_value = 0x00000100UL,/* reset value */
  	},
  	{
  		.access =   SNDRV_CTL_ELEM_ACCESS_READ,
  		.iface =    SNDRV_CTL_ELEM_IFACE_PCM,
  		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
  		.info =     snd_microii_spdif_info,
  		.get =      snd_microii_spdif_mask_get,
  	},
  	{
  		.iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name =     SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
  		.info =     snd_ctl_boolean_mono_info,
  		.get =      snd_microii_spdif_switch_get,
  		.put =      snd_microii_spdif_switch_put,
  		.private_value = 0x00000028UL,/* reset value */
  	}
  };
  
  static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
  {
  	int err, i;
  
  	for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
  		err = snd_ctl_add(mixer->chip->card,
  			snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer));
  		if (err < 0)
  			return err;
  	}
  
  	return err;
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1503
1504
  int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  {
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1505
  	int err = 0;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1506
1507
1508
1509
  	struct snd_info_entry *entry;
  
  	if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
  		return err;
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1510
1511
1512
1513
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x041e, 0x3020):
  	case USB_ID(0x041e, 0x3040):
  	case USB_ID(0x041e, 0x3042):
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
1514
  	case USB_ID(0x041e, 0x30df):
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1515
1516
1517
1518
  	case USB_ID(0x041e, 0x3048):
  		err = snd_audigy2nx_controls_create(mixer);
  		if (err < 0)
  			break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1519
1520
1521
  		if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
  			snd_info_set_text_ops(entry, mixer,
  					      snd_audigy2nx_proc_read);
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1522
  		break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1523

09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1524
  	case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1525
  	case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1526
1527
  		err = snd_c400_create_mixer(mixer);
  		break;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
1528
1529
  	case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
  	case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
1530
  		err = snd_ftu_create_mixer(mixer);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
1531
  		break;
1d31affbe   Denis Washington   ALSA: usb-audio: ...
1532
1533
1534
  	case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
  	case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
  	case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1535
  		err = snd_xonar_u1_controls_create(mixer);
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1536
  		break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1537

066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1538
1539
1540
  	case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
  		err = snd_microii_controls_create(mixer);
  		break;
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1541
  	case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
1542
1543
1544
  		err = snd_nativeinstruments_create_mixer(mixer,
  				snd_nativeinstruments_ta6_mixers,
  				ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1545
  		break;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
1546

3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1547
  	case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
1548
1549
1550
  		err = snd_nativeinstruments_create_mixer(mixer,
  				snd_nativeinstruments_ta10_mixers,
  				ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1551
  		break;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1552
1553
  
  	case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
b71dad181   Mark Hills   ALSA: usb-audio: ...
1554
1555
  		/* detection is disabled in mixer_maps.c */
  		err = snd_create_std_mono_table(mixer, ebox44_table);
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1556
  		break;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
1557
  	}
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
1558
  	return err;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
  }
  
  void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
  				    int unitid)
  {
  	if (!mixer->rc_cfg)
  		return;
  	/* unit ids specific to Extigy/Audigy 2 NX: */
  	switch (unitid) {
  	case 0: /* remote control */
  		mixer->rc_urb->dev = mixer->chip->dev;
  		usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
  		break;
  	case 4: /* digital in jack */
  	case 7: /* line in jacks */
  	case 19: /* speaker out jacks */
  	case 20: /* headphones out jack */
  		break;
  	/* live24ext: 4 = line-in jack */
  	case 3:	/* hp-out jack (may actuate Mute) */
  		if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
  		    mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
  			snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
  		break;
  	default:
  		snd_printd(KERN_DEBUG "memory change in unknown unit %d
  ", unitid);
  		break;
  	}
  }