Blame view

sound/usb/mixer_quirks.c 61.1 KB
1a59d1b8e   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2
3
4
5
6
7
8
9
10
11
12
  /*
   *   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: ...
13
14
   *   Audio Advantage Micro II support added by:
   *	    Przemek Rudy (prudy1@o2.pl)
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
15
   */
388fdb8f8   Ian Douglas Scott   ALSA: usb-audio: ...
16
  #include <linux/hid.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
17
  #include <linux/init.h>
d39f1d68f   Jussi Laako   ALSA: usb-audio: ...
18
  #include <linux/math64.h>
36db04565   Stephen Rothwell   ALSA: usb - use o...
19
  #include <linux/slab.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
20
21
  #include <linux/usb.h>
  #include <linux/usb/audio.h>
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
22
  #include <sound/asoundef.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
23
24
25
26
  #include <sound/core.h>
  #include <sound/control.h>
  #include <sound/hwdep.h>
  #include <sound/info.h>
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
27
  #include <sound/tlv.h>
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
28
29
  
  #include "usbaudio.h"
f0b5e634f   Daniel Mack   ALSA: usbmixer: r...
30
  #include "mixer.h"
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
31
  #include "mixer_quirks.h"
76b188c4b   Chris J Arges   ALSA: usb-audio: ...
32
  #include "mixer_scarlett.h"
9e4d5c1be   Geoffrey D. Bennett   ALSA: usb-audio: ...
33
  #include "mixer_scarlett_gen2.h"
d2bb390a2   Detlef Urban   ALSA: usb-audio: ...
34
  #include "mixer_us16x08.h"
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
35
  #include "helper.h"
b71dad181   Mark Hills   ALSA: usb-audio: ...
36
37
38
39
40
41
  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: ...
42
43
44
45
46
47
48
  /* 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: ...
49
  static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
50
51
52
53
  				unsigned int unitid,
  				unsigned int control,
  				unsigned int cmask,
  				int val_type,
9f8141059   Eldad Zack   ALSA: usb-audio: ...
54
  				unsigned int idx_off,
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
55
56
57
  				const char *name,
  				snd_kcontrol_tlv_rw_t *tlv_callback)
  {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
58
59
60
61
62
63
  	struct usb_mixer_elem_info *cval;
  	struct snd_kcontrol *kctl;
  
  	cval = kzalloc(sizeof(*cval), GFP_KERNEL);
  	if (!cval)
  		return -ENOMEM;
3360b84b8   Takashi Iwai   ALSA: usb-audio: ...
64
  	snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
65
66
67
68
  	cval->val_type = val_type;
  	cval->channels = 1;
  	cval->control = control;
  	cval->cmask = cmask;
9f8141059   Eldad Zack   ALSA: usb-audio: ...
69
  	cval->idx_off = idx_off;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
70

7df4a691f   Mark Hills   ALSA: usb-audio: ...
71
72
  	/* get_min_max() is called only for integer volumes later,
  	 * so provide a short-cut for booleans */
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  	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);
eef904516   Chris J Arges   ALSA: usb-audio: ...
88
  	kctl->private_free = snd_usb_mixer_elem_free;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
89
90
91
92
93
94
95
96
97
  
  	/* 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 */
3360b84b8   Takashi Iwai   ALSA: usb-audio: ...
98
  	return snd_usb_mixer_add_control(&cval->head, kctl);
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
99
  }
9f8141059   Eldad Zack   ALSA: usb-audio: ...
100
101
102
103
104
105
106
107
108
109
110
  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: ...
111
  /*
b71dad181   Mark Hills   ALSA: usb-audio: ...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
   * 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;
  }
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
  				      int id,
  				      usb_mixer_elem_resume_func_t resume,
  				      const struct snd_kcontrol_new *knew,
  				      struct usb_mixer_elem_list **listp)
  {
  	struct usb_mixer_elem_list *list;
  	struct snd_kcontrol *kctl;
  
  	list = kzalloc(sizeof(*list), GFP_KERNEL);
  	if (!list)
  		return -ENOMEM;
  	if (listp)
  		*listp = list;
  	list->mixer = mixer;
  	list->id = id;
  	list->resume = resume;
  	kctl = snd_ctl_new1(knew, list);
  	if (!kctl) {
  		kfree(list);
  		return -ENOMEM;
  	}
  	kctl->private_free = snd_usb_mixer_elem_free;
  	return snd_usb_mixer_add_control(list, kctl);
  }
b71dad181   Mark Hills   ALSA: usb-audio: ...
154
  /*
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
   * 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 -...
174
  	{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 */
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
175
  	{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
3dc8523fa   Dmitry M. Fedin   ALSA: usb - Creat...
176
  	{ USB_ID(0x041e, 0x3237), 0, 1, 1, 1,  1,  0x000d }, /* Usb X-Fi S51 Pro */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
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
  	{ 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;
  }
680ef72ab   Al Viro   sound: annotate -...
220
  static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
221
222
223
224
225
  					    poll_table *wait)
  {
  	struct usb_mixer_interface *mixer = hw->private_data;
  
  	poll_wait(file, &mixer->rc_waitq, wait);
a9a08845e   Linus Torvalds   vfs: do bulk POLL...
226
  	return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
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
  }
  
  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)
  {
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
281
  	ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
282
283
  	return 0;
  }
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
284
285
  static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
  				    int value, int index)
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
286
  {
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
287
288
  	struct snd_usb_audio *chip = mixer->chip;
  	int err;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
289

47ab15459   Takashi Iwai   ALSA: usb-audio: ...
290
291
292
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
293
294
295
  	if (chip->usb_id == USB_ID(0x041e, 0x3042))
  		err = snd_usb_ctl_msg(chip->dev,
  			      usb_sndctrlpipe(chip->dev, 0), 0x24,
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
296
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
297
  			      !value, 0, NULL, 0);
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
298
  	/* USB X-Fi S51 Pro */
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
299
300
301
  	if (chip->usb_id == USB_ID(0x041e, 0x30df))
  		err = snd_usb_ctl_msg(chip->dev,
  			      usb_sndctrlpipe(chip->dev, 0), 0x24,
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
302
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
303
  			      !value, 0, NULL, 0);
ca8dc34ea   Mandar Joshi   ALSA: usb-audio -...
304
  	else
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
305
306
  		err = snd_usb_ctl_msg(chip->dev,
  			      usb_sndctrlpipe(chip->dev, 0), 0x24,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
307
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
17d900c4a   Clemens Ladisch   ALSA: usb-audio: ...
308
  			      value, index + 2, NULL, 0);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
309
  	snd_usb_unlock_shutdown(chip);
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
310
  	return err;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
311
  }
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
312
313
314
315
316
317
  static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	struct usb_mixer_interface *mixer = list->mixer;
  	int index = kcontrol->private_value & 0xff;
e87359efc   Dan Carpenter   ALSA: usb-audio: ...
318
  	unsigned int value = ucontrol->value.integer.value[0];
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  	int old_value = kcontrol->private_value >> 8;
  	int err;
  
  	if (value > 1)
  		return -EINVAL;
  	if (value == old_value)
  		return 0;
  	kcontrol->private_value = (value << 8) | index;
  	err = snd_audigy2nx_led_update(mixer, value, index);
  	return err < 0 ? err : 1;
  }
  
  static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
  {
  	int priv_value = list->kctl->private_value;
  
  	return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
  					priv_value & 0xff);
  }
  
  /* name and private_value are set dynamically */
905e46acd   Bhumika Goyal   ALSA: declare snd...
340
  static const struct snd_kcontrol_new snd_audigy2nx_control = {
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
341
342
343
344
345
346
347
348
349
350
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.info = snd_audigy2nx_led_info,
  	.get = snd_audigy2nx_led_get,
  	.put = snd_audigy2nx_led_put,
  };
  
  static const char * const snd_audigy2nx_led_names[] = {
  	"CMSS LED Switch",
  	"Power LED Switch",
  	"Dolby Digital LED Switch",
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
351
352
353
354
355
  };
  
  static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
  {
  	int i, err;
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
356
357
  	for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
  		struct snd_kcontrol_new knew;
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
  			 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
  			break; 
9cf3689bf   Takashi Iwai   ALSA: usb-audio: ...
370
371
372
373
374
375
376
  
  		knew = snd_audigy2nx_control;
  		knew.name = snd_audigy2nx_led_names[i];
  		knew.private_value = (1 << 8) | i; /* LED on as default */
  		err = add_single_ctl_with_resume(mixer, 0,
  						 snd_audigy2nx_led_resume,
  						 &knew, NULL);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
377
378
379
  		if (err < 0)
  			return err;
  	}
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
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
415
416
417
418
  	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);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
419
420
421
422
  		err = snd_usb_lock_shutdown(mixer->chip);
  		if (err < 0)
  			return;
  		err = snd_usb_ctl_msg(mixer->chip->dev,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
423
424
425
  				      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: ...
426
  				      jacks[i].unitid << 8, buf, 3);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
427
  		snd_usb_unlock_shutdown(mixer->chip);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
428
429
430
431
432
433
434
435
  		if (err == 3 && (buf[0] == 3 || buf[0] == 6))
  			snd_iprintf(buffer, "%02x %02x
  ", buf[1], buf[2]);
  		else
  			snd_iprintf(buffer, "?
  ");
  	}
  }
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
436
437
438
439
  /* EMU0204 */
  static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
  				      struct snd_ctl_elem_info *uinfo)
  {
7bbd03e01   Takashi Iwai   ALSA: usb-audio: ...
440
  	static const char * const texts[2] = {"1/2", "3/4"};
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
441

7bbd03e01   Takashi Iwai   ALSA: usb-audio: ...
442
  	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
443
444
445
446
447
448
449
450
  }
  
  static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
  				     struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.enumerated.item[0] = kcontrol->private_value;
  	return 0;
  }
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
451
452
  static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
  					int value)
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
453
  {
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
454
455
  	struct snd_usb_audio *chip = mixer->chip;
  	int err;
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
456
  	unsigned char buf[2];
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
457
458
459
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
460
461
462
463
464
  
  	buf[0] = 0x01;
  	buf[1] = value ? 0x02 : 0x01;
  	err = snd_usb_ctl_msg(chip->dev,
  		      usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
465
466
  		      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  		      0x0400, 0x0e00, buf, 2);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
467
  	snd_usb_unlock_shutdown(chip);
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
  	return err;
  }
  
  static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
  				     struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	struct usb_mixer_interface *mixer = list->mixer;
  	unsigned int value = ucontrol->value.enumerated.item[0];
  	int err;
  
  	if (value > 1)
  		return -EINVAL;
  
  	if (value == kcontrol->private_value)
  		return 0;
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
484
  	kcontrol->private_value = value;
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
485
486
  	err = snd_emu0204_ch_switch_update(mixer, value);
  	return err < 0 ? err : 1;
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
487
  }
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
488
489
490
491
492
  static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
  {
  	return snd_emu0204_ch_switch_update(list->mixer,
  					    list->kctl->private_value);
  }
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
493

5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
494
495
496
497
498
499
500
  static struct snd_kcontrol_new snd_emu0204_control = {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Front Jack Channels",
  	.info = snd_emu0204_ch_switch_info,
  	.get = snd_emu0204_ch_switch_get,
  	.put = snd_emu0204_ch_switch_put,
  	.private_value = 0,
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
501
502
503
504
  };
  
  static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
  {
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
505
506
507
  	return add_single_ctl_with_resume(mixer, 0,
  					  snd_emu0204_ch_switch_resume,
  					  &snd_emu0204_control, NULL);
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
508
  }
5f503ee9e   Takashi Iwai   ALSA: usb-audio: ...
509

1d31affbe   Denis Washington   ALSA: usb-audio: ...
510
  /* ASUS Xonar U1 / U3 controls */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
511
512
513
  static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
514
  	ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
515
516
  	return 0;
  }
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
517
518
519
520
521
  static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
  				      unsigned char status)
  {
  	struct snd_usb_audio *chip = mixer->chip;
  	int err;
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
522
523
524
525
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = snd_usb_ctl_msg(chip->dev,
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
526
527
528
  			      usb_sndctrlpipe(chip->dev, 0), 0x08,
  			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			      50, 0, &status, 1);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
529
  	snd_usb_unlock_shutdown(chip);
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
530
531
  	return err;
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
532
533
534
  static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
535
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
536
  	u8 old_status, new_status;
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
537
  	int err;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
538

2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
539
  	old_status = kcontrol->private_value;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
540
541
542
543
  	if (ucontrol->value.integer.value[0])
  		new_status = old_status | 0x02;
  	else
  		new_status = old_status & ~0x02;
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
544
545
546
547
548
549
550
551
552
553
554
555
  	if (new_status == old_status)
  		return 0;
  
  	kcontrol->private_value = new_status;
  	err = snd_xonar_u1_switch_update(list->mixer, new_status);
  	return err < 0 ? err : 1;
  }
  
  static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
  {
  	return snd_xonar_u1_switch_update(list->mixer,
  					  list->kctl->private_value);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
556
557
558
559
560
561
562
563
  }
  
  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,
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
564
  	.private_value = 0x05,
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
565
566
567
568
  };
  
  static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
  {
2bfb14c3b   Takashi Iwai   ALSA: usb-audio: ...
569
570
571
  	return add_single_ctl_with_resume(mixer, 0,
  					  snd_xonar_u1_switch_resume,
  					  &snd_xonar_u1_output_switch, NULL);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
572
  }
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
573
574
575
576
577
578
579
580
  /* Digidesign Mbox 1 clock source switch (internal/spdif) */
  
  static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
  				struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.enumerated.item[0] = kctl->private_value;
  	return 0;
  }
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
581
  static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
582
  {
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
583
  	struct snd_usb_audio *chip = mixer->chip;
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
584
  	int err;
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
585
  	unsigned char buff[3];
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
586
587
588
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
  
  	/* Prepare for magic command to toggle clock source */
  	err = snd_usb_ctl_msg(chip->dev,
  				usb_rcvctrlpipe(chip->dev, 0), 0x81,
  				USB_DIR_IN |
  				USB_TYPE_CLASS |
  				USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
  	if (err < 0)
  		goto err;
  	err = snd_usb_ctl_msg(chip->dev,
  				usb_rcvctrlpipe(chip->dev, 0), 0x81,
  				USB_DIR_IN |
  				USB_TYPE_CLASS |
  				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
  	if (err < 0)
  		goto err;
  
  	/* 2 possibilities:	Internal    -> send sample rate
  	 *			S/PDIF sync -> send zeroes
  	 * NB: Sample rate locked to 48kHz on purpose to
  	 *     prevent user from resetting the sample rate
  	 *     while S/PDIF sync is enabled and confusing
  	 *     this configuration.
  	 */
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
613
  	if (val == 0) {
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
  		buff[0] = 0x80;
  		buff[1] = 0xbb;
  		buff[2] = 0x00;
  	} else {
  		buff[0] = buff[1] = buff[2] = 0x00;
  	}
  
  	/* Send the magic command to toggle the clock source */
  	err = snd_usb_ctl_msg(chip->dev,
  				usb_sndctrlpipe(chip->dev, 0), 0x1,
  				USB_TYPE_CLASS |
  				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
  	if (err < 0)
  		goto err;
  	err = snd_usb_ctl_msg(chip->dev,
  				usb_rcvctrlpipe(chip->dev, 0), 0x81,
  				USB_DIR_IN |
  				USB_TYPE_CLASS |
  				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
  	if (err < 0)
  		goto err;
  	err = snd_usb_ctl_msg(chip->dev,
  				usb_rcvctrlpipe(chip->dev, 0), 0x81,
  				USB_DIR_IN |
  				USB_TYPE_CLASS |
  				USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
  	if (err < 0)
  		goto err;
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
642
643
  
  err:
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
644
  	snd_usb_unlock_shutdown(chip);
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
  	return err;
  }
  
  static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
  				struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
  	struct usb_mixer_interface *mixer = list->mixer;
  	int err;
  	bool cur_val, new_val;
  
  	cur_val = kctl->private_value;
  	new_val = ucontrol->value.enumerated.item[0];
  	if (cur_val == new_val)
  		return 0;
  
  	kctl->private_value = new_val;
  	err = snd_mbox1_switch_update(mixer, new_val);
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
663
664
665
666
667
668
669
670
671
672
673
674
675
  	return err < 0 ? err : 1;
  }
  
  static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const texts[2] = {
  		"Internal",
  		"S/PDIF"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
  }
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
676
677
678
679
  static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
  {
  	return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
  }
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
680
681
682
683
684
685
686
687
688
689
690
691
692
  static struct snd_kcontrol_new snd_mbox1_switch = {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Clock Source",
  	.index = 0,
  	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  	.info = snd_mbox1_switch_info,
  	.get = snd_mbox1_switch_get,
  	.put = snd_mbox1_switch_put,
  	.private_value = 0
  };
  
  static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
  {
25a9a4f91   Takashi Iwai   ALSA: usb-audio: ...
693
694
695
  	return add_single_ctl_with_resume(mixer, 0,
  					  snd_mbox1_switch_resume,
  					  &snd_mbox1_switch, NULL);
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
696
  }
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
697
698
699
  /* Native Instruments device quirks */
  
  #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
700
701
  static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
  				   struct snd_kcontrol *kctl)
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
702
  {
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
703
  	struct usb_device *dev = mixer->chip->dev;
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
704
705
706
  	unsigned int pval = kctl->private_value;
  	u8 value;
  	int err;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
707

da6d27695   Takashi Iwai   ALSA: usb-audio: ...
708
709
710
711
712
  	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  			      (pval >> 16) & 0xff,
  			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  			      0, pval & 0xffff, &value, 1);
  	if (err < 0) {
0ba41d917   Takashi Iwai   ALSA: usb-audio: ...
713
  		dev_err(&dev->dev,
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
714
715
  			"unable to issue vendor read request (ret = %d)", err);
  		return err;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
716
  	}
2acf5a3e6   Colin Ian King   ALSA: usb-audio: ...
717
  	kctl->private_value |= ((unsigned int)value << 24);
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
718
719
  	return 0;
  }
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
720

da6d27695   Takashi Iwai   ALSA: usb-audio: ...
721
722
723
724
  static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
725
726
  	return 0;
  }
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
727
728
729
730
731
  static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
  {
  	struct snd_usb_audio *chip = list->mixer->chip;
  	unsigned int pval = list->kctl->private_value;
  	int err;
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
732
733
734
735
736
737
738
739
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
  			      (pval >> 16) & 0xff,
  			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  			      pval >> 24, pval & 0xffff, NULL, 0, 1000);
  	snd_usb_unlock_shutdown(chip);
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
740
741
  	return err;
  }
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
742
743
744
  static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_value *ucontrol)
  {
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
745
746
747
748
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	u8 oldval = (kcontrol->private_value >> 24) & 0xff;
  	u8 newval = ucontrol->value.integer.value[0];
  	int err;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
749

da6d27695   Takashi Iwai   ALSA: usb-audio: ...
750
751
  	if (oldval == newval)
  		return 0;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
752

da6d27695   Takashi Iwai   ALSA: usb-audio: ...
753
  	kcontrol->private_value &= ~(0xff << 24);
c4a359a00   Takashi Iwai   ALSA: usb-audio: ...
754
  	kcontrol->private_value |= (unsigned int)newval << 24;
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
755
756
  	err = snd_ni_update_cur_val(list);
  	return err < 0 ? err : 1;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
  }
  
  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++) {
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
827
  		struct usb_mixer_elem_list *list;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
828
829
830
  
  		template.name = kc[i].name;
  		template.private_value = kc[i].private_value;
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
831
832
833
  		err = add_single_ctl_with_resume(mixer, 0,
  						 snd_ni_update_cur_val,
  						 &template, &list);
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
834
835
  		if (err < 0)
  			break;
da6d27695   Takashi Iwai   ALSA: usb-audio: ...
836
  		snd_ni_control_init_val(mixer, list->kctl);
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
837
838
839
840
  	}
  
  	return err;
  }
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
841
  /* M-Audio FastTrack Ultra quirks */
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
842
  /* FTU Effect switch (also used by C400/C600) */
d34bf1485   Felix Homann   ALSA: usb-audio: ...
843
844
845
  static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_info *uinfo)
  {
7bbd03e01   Takashi Iwai   ALSA: usb-audio: ...
846
847
848
  	static const char *const texts[8] = {
  		"Room 1", "Room 2", "Room 3", "Hall 1",
  		"Hall 2", "Plate", "Delay", "Echo"
d34bf1485   Felix Homann   ALSA: usb-audio: ...
849
  	};
7bbd03e01   Takashi Iwai   ALSA: usb-audio: ...
850
  	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
851
  }
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
852
853
  static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
  				   struct snd_kcontrol *kctl)
d34bf1485   Felix Homann   ALSA: usb-audio: ...
854
  {
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
855
856
  	struct usb_device *dev = mixer->chip->dev;
  	unsigned int pval = kctl->private_value;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
857
858
  	int err;
  	unsigned char value[2];
d34bf1485   Felix Homann   ALSA: usb-audio: ...
859
860
861
  
  	value[0] = 0x00;
  	value[1] = 0x00;
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
862
863
864
865
866
867
868
  	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
  			      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
  			      pval & 0xff00,
  			      snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
  			      value, 2);
  	if (err < 0)
  		return err;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
869

2acf5a3e6   Colin Ian King   ALSA: usb-audio: ...
870
  	kctl->private_value |= (unsigned int)value[0] << 24;
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
871
872
  	return 0;
  }
d34bf1485   Felix Homann   ALSA: usb-audio: ...
873

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
874
875
876
877
878
879
  static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
  					struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
  	return 0;
  }
d34bf1485   Felix Homann   ALSA: usb-audio: ...
880

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
881
882
883
884
885
886
  static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
  {
  	struct snd_usb_audio *chip = list->mixer->chip;
  	unsigned int pval = list->kctl->private_value;
  	unsigned char value[2];
  	int err;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
887

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
888
889
  	value[0] = pval >> 24;
  	value[1] = 0;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
890

47ab15459   Takashi Iwai   ALSA: usb-audio: ...
891
892
893
894
895
896
897
898
899
900
901
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = snd_usb_ctl_msg(chip->dev,
  			      usb_sndctrlpipe(chip->dev, 0),
  			      UAC_SET_CUR,
  			      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  			      pval & 0xff00,
  			      snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
  			      value, 2);
  	snd_usb_unlock_shutdown(chip);
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
902
  	return err;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
903
904
905
906
907
  }
  
  static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
  					struct snd_ctl_elem_value *ucontrol)
  {
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
908
909
910
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
  	unsigned int pval = list->kctl->private_value;
  	int cur_val, err, new_val;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
911

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
912
  	cur_val = pval >> 24;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
913
  	new_val = ucontrol->value.enumerated.item[0];
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
914
915
  	if (cur_val == new_val)
  		return 0;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
916

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
917
918
919
920
  	kctl->private_value &= ~(0xff << 24);
  	kctl->private_value |= new_val << 24;
  	err = snd_ftu_eff_switch_update(list);
  	return err < 0 ? err : 1;
1a290581d   Takashi Iwai   ALSA: usb-audio: ...
921
  }
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
922
923
  static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
  	int validx, int bUnitID)
d34bf1485   Felix Homann   ALSA: usb-audio: ...
924
925
926
927
928
929
930
931
932
933
  {
  	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
  	};
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
934
  	struct usb_mixer_elem_list *list;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
935
  	int err;
d34bf1485   Felix Homann   ALSA: usb-audio: ...
936

0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
937
938
939
  	err = add_single_ctl_with_resume(mixer, bUnitID,
  					 snd_ftu_eff_switch_update,
  					 &template, &list);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
940
941
  	if (err < 0)
  		return err;
0b4e9cfce   Takashi Iwai   ALSA: usb-audio: ...
942
943
  	list->kctl->private_value = (validx << 8) | bUnitID;
  	snd_ftu_eff_switch_init(mixer, list->kctl);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
944
945
  	return 0;
  }
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
946

cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
947
948
  /* Create volume controls for FTU devices*/
  static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
949
950
  {
  	char name[64];
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
951
  	unsigned int control, cmask;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
952
  	int in, out, err;
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
953
954
  	const unsigned int id = 5;
  	const int val_type = USB_MIXER_S16;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
955
  	for (out = 0; out < 8; out++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
956
  		control = out + 1;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
957
  		for (in = 0; in < 8; in++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
958
  			cmask = 1 << in;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
959
  			snprintf(name, sizeof(name),
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
960
961
962
963
  				"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: ...
964
  							&snd_usb_mixer_vol_tlv);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
965
966
967
  			if (err < 0)
  				return err;
  		}
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
968
  		for (in = 8; in < 16; in++) {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
969
  			cmask = 1 << in;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
970
  			snprintf(name, sizeof(name),
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
971
972
973
974
  				"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: ...
975
  							&snd_usb_mixer_vol_tlv);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
976
977
978
979
980
981
982
  			if (err < 0)
  				return err;
  		}
  	}
  
  	return 0;
  }
d34bf1485   Felix Homann   ALSA: usb-audio: ...
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
  /* 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: ...
1078
  static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1079
  {
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
1080
  	int err;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1081

cfe8f97c8   Felix Homann   ALSA: usb-audio: ...
1082
  	err = snd_ftu_create_volume_ctls(mixer);
8a4d1d397   Felix Homann   ALSA: usb-audio: ...
1083
1084
  	if (err < 0)
  		return err;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1085

d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
1086
  	err = snd_ftu_create_effect_switch(mixer, 1, 6);
d34bf1485   Felix Homann   ALSA: usb-audio: ...
1087
1088
  	if (err < 0)
  		return err;
d847ce0e9   Eldad Zack   ALSA: usb-audio: ...
1089

d34bf1485   Felix Homann   ALSA: usb-audio: ...
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
  	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: ...
1109
  	return 0;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
1110
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1111
1112
1113
1114
1115
  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;
6de3c9e3f   Takashi Iwai   ALSA: usb-audio: ...
1116
  	int unitid = 12; /* SampleRate ExtensionUnit ID */
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1117
1118
  
  	list_for_each_entry(mixer, &chip->mixer_list, list) {
6de3c9e3f   Takashi Iwai   ALSA: usb-audio: ...
1119
1120
  		if (mixer->id_elems[unitid]) {
  			cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1121
1122
1123
1124
  			snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
  						    cval->control << 8,
  						    samplerate_id);
  			snd_usb_mixer_notify_id(mixer, unitid);
6de3c9e3f   Takashi Iwai   ALSA: usb-audio: ...
1125
  			break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1126
  		}
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
1127
1128
  	}
  }
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1129
1130
  /* 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: ...
1131
1132
1133
1134
1135
  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: ...
1136
1137
  	int num_outs = 0;
  	int num_ins = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1138
1139
1140
1141
  
  	const unsigned int id = 0x40;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
  	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: ...
1156
1157
1158
1159
1160
1161
  				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: ...
1162
  					chan - num_outs + 1, out + 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1163
1164
1165
  			}
  
  			cmask = (out == 0) ? 0 : 1 << (out - 1);
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1166
  			offset = chan * num_outs;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
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
  			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: ...
1222
1223
  	int num_outs = 0;
  	int num_ins = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1224
1225
1226
1227
  
  	const unsigned int id = 0x42;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
  	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: ...
1241
1242
1243
1244
1245
1246
  			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: ...
1247
  				chan - num_outs + 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
  		}
  
  		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: ...
1266
1267
  	int num_outs = 0;
  	int offset = 0;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1268
1269
1270
1271
  
  	const unsigned int id = 0x40;
  	const int val_type = USB_MIXER_S16;
  	const int control = 1;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1272

e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
  	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: ...
1287
1288
1289
  		snprintf(name, sizeof(name),
  			"Effect Return %d",
  			chan + 1);
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
1290
1291
  		cmask = (chan == 0) ? 0 :
  			1 << (chan + (chan % 2) * num_outs - 1);
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
1292
1293
1294
1295
1296
1297
1298
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
  		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: ...
1336
1337
1338
1339
1340
  /*
   * 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: ...
1341
  static struct std_mono_table ebox44_table[] = {
989b01385   Mark Hills   ALSA: usb-audio: ...
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
  	{
  		.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: ...
1363

989b01385   Mark Hills   ALSA: usb-audio: ...
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
  	{
  		.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: ...
1385

989b01385   Mark Hills   ALSA: usb-audio: ...
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
  	{
  		.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: ...
1407

989b01385   Mark Hills   ALSA: usb-audio: ...
1408
  	{}
b71dad181   Mark Hills   ALSA: usb-audio: ...
1409
  };
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
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
  /* 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)
  {
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1443
1444
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	struct snd_usb_audio *chip = list->mixer->chip;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1445
1446
1447
1448
1449
1450
  	int err;
  	struct usb_interface *iface;
  	struct usb_host_interface *alts;
  	unsigned int ep;
  	unsigned char data[3];
  	int rate;
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1451
1452
1453
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1454

066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1455
1456
1457
1458
1459
  	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 */
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1460
  	iface = usb_ifnum_to_if(chip->dev, 1);
447d6275f   Takashi Iwai   ALSA: usb-audio: ...
1461
1462
  	if (!iface || iface->num_altsetting < 2)
  		return -EINVAL;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1463
  	alts = &iface->altsetting[1];
447d6275f   Takashi Iwai   ALSA: usb-audio: ...
1464
1465
  	if (get_iface_desc(alts)->bNumEndpoints < 1)
  		return -EINVAL;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1466
  	ep = get_endpoint(alts, 0)->bEndpointAddress;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1467
1468
  	err = snd_usb_ctl_msg(chip->dev,
  			usb_rcvctrlpipe(chip->dev, 0),
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
  			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;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1483
   end:
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1484
  	snd_usb_unlock_shutdown(chip);
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1485
1486
  	return err;
  }
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1487
  static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1488
  {
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1489
1490
  	struct snd_usb_audio *chip = list->mixer->chip;
  	unsigned int pval = list->kctl->private_value;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1491
  	u8 reg;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1492
  	int err;
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1493
1494
1495
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1496

288673bea   Takashi Iwai   ALSA: usb-audio: ...
1497
1498
1499
  	reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
  	err = snd_usb_ctl_msg(chip->dev,
  			usb_sndctrlpipe(chip->dev, 0),
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1500
1501
1502
1503
1504
1505
1506
1507
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			2,
  			NULL,
  			0);
  	if (err < 0)
  		goto end;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1508
1509
1510
1511
  	reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
  	reg |= (pval >> 12) & 0x0f;
  	err = snd_usb_ctl_msg(chip->dev,
  			usb_sndctrlpipe(chip->dev, 0),
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1512
1513
1514
1515
1516
1517
1518
1519
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			3,
  			NULL,
  			0);
  	if (err < 0)
  		goto end;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1520
   end:
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1521
  	snd_usb_unlock_shutdown(chip);
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
  	return err;
  }
  
  static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	unsigned int pval, pval_old;
  	int err;
  
  	pval = pval_old = kcontrol->private_value;
  	pval &= 0xfffff0f0;
  	pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
  	pval |= (ucontrol->value.iec958.status[0] & 0x0f);
  
  	pval &= 0xffff0fff;
  	pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1539
1540
1541
1542
  
  	/* The frequency bits in AES3 cannot be set via register access. */
  
  	/* Silently ignore any bits from the request that cannot be set. */
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1543
1544
1545
1546
1547
1548
  	if (pval == pval_old)
  		return 0;
  
  	kcontrol->private_value = pval;
  	err = snd_microii_spdif_default_update(list);
  	return err < 0 ? err : 1;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
  }
  
  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;
  }
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1569
  static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1570
  {
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1571
1572
  	struct snd_usb_audio *chip = list->mixer->chip;
  	u8 reg = list->kctl->private_value;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1573
  	int err;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1574

47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1575
1576
1577
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1578
1579
1580
  
  	err = snd_usb_ctl_msg(chip->dev,
  			usb_sndctrlpipe(chip->dev, 0),
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1581
1582
1583
1584
1585
1586
  			UAC_SET_CUR,
  			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  			reg,
  			9,
  			NULL,
  			0);
47ab15459   Takashi Iwai   ALSA: usb-audio: ...
1587
  	snd_usb_unlock_shutdown(chip);
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1588
1589
  	return err;
  }
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
  static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	u8 reg;
  	int err;
  
  	reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
  	if (reg != list->kctl->private_value)
  		return 0;
  
  	kcontrol->private_value = reg;
  	err = snd_microii_spdif_switch_update(list);
  	return err < 0 ? err : 1;
  }
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
  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;
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1634
1635
1636
1637
1638
  	static usb_mixer_elem_resume_func_t resume_funcs[] = {
  		snd_microii_spdif_default_update,
  		NULL,
  		snd_microii_spdif_switch_update
  	};
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1639
1640
  
  	for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
288673bea   Takashi Iwai   ALSA: usb-audio: ...
1641
1642
1643
1644
  		err = add_single_ctl_with_resume(mixer, 0,
  						 resume_funcs[i],
  						 &snd_microii_mixer_spdif[i],
  						 NULL);
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1645
1646
1647
  		if (err < 0)
  			return err;
  	}
18e4753ff   Mikulas Patocka   ALSA: usb-audio: ...
1648
  	return 0;
066624c6a   Przemek Rudy   ALSA: usb-audio: ...
1649
  }
388fdb8f8   Ian Douglas Scott   ALSA: usb-audio: ...
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
  /* Creative Sound Blaster E1 */
  
  static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
  {
  	ucontrol->value.integer.value[0] = kcontrol->private_value;
  	return 0;
  }
  
  static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
  					     unsigned char state)
  {
  	struct snd_usb_audio *chip = mixer->chip;
  	int err;
  	unsigned char buff[2];
  
  	buff[0] = 0x02;
  	buff[1] = state ? 0x02 : 0x00;
  
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = snd_usb_ctl_msg(chip->dev,
  			usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
  			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
  			0x0202, 3, buff, 2);
  	snd_usb_unlock_shutdown(chip);
  	return err;
  }
  
  static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	unsigned char value = !!ucontrol->value.integer.value[0];
  	int err;
  
  	if (kcontrol->private_value == value)
  		return 0;
  	kcontrol->private_value = value;
  	err = snd_soundblaster_e1_switch_update(list->mixer, value);
  	return err < 0 ? err : 1;
  }
  
  static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
  {
  	return snd_soundblaster_e1_switch_update(list->mixer,
  						 list->kctl->private_value);
  }
  
  static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
  					   struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const texts[2] = {
  		"Mic", "Aux"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
  }
  
  static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Input Source",
  	.info = snd_soundblaster_e1_switch_info,
  	.get = snd_soundblaster_e1_switch_get,
  	.put = snd_soundblaster_e1_switch_put,
  	.private_value = 0,
  };
  
  static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
  {
  	return add_single_ctl_with_resume(mixer, 0,
  					  snd_soundblaster_e1_switch_resume,
  					  &snd_soundblaster_e1_input_switch,
  					  NULL);
  }
964af639a   Takashi Iwai   ALSA: usb-audio: ...
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
  static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
  {
  	u16 buf = 0;
  
  	snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
  			USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  			ch, snd_usb_ctrl_intf(chip) | (id << 8),
  			&buf, 2);
  }
  
  static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
  {
  	/* fix to 0dB playback volumes */
  	dell_dock_init_vol(mixer->chip, 1, 16);
  	dell_dock_init_vol(mixer->chip, 2, 16);
  	dell_dock_init_vol(mixer->chip, 1, 19);
  	dell_dock_init_vol(mixer->chip, 2, 19);
  	return 0;
  }
d39f1d68f   Jussi Laako   ALSA: usb-audio: ...
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
  /* RME Class Compliant device quirks */
  
  #define SND_RME_GET_STATUS1			23
  #define SND_RME_GET_CURRENT_FREQ		17
  #define SND_RME_CLK_SYSTEM_SHIFT		16
  #define SND_RME_CLK_SYSTEM_MASK			0x1f
  #define SND_RME_CLK_AES_SHIFT			8
  #define SND_RME_CLK_SPDIF_SHIFT			12
  #define SND_RME_CLK_AES_SPDIF_MASK		0xf
  #define SND_RME_CLK_SYNC_SHIFT			6
  #define SND_RME_CLK_SYNC_MASK			0x3
  #define SND_RME_CLK_FREQMUL_SHIFT		18
  #define SND_RME_CLK_FREQMUL_MASK		0x7
  #define SND_RME_CLK_SYSTEM(x) \
  	((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
  #define SND_RME_CLK_AES(x) \
  	((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
  #define SND_RME_CLK_SPDIF(x) \
  	((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
  #define SND_RME_CLK_SYNC(x) \
  	((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
  #define SND_RME_CLK_FREQMUL(x) \
  	((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
  #define SND_RME_CLK_AES_LOCK			0x1
  #define SND_RME_CLK_AES_SYNC			0x4
  #define SND_RME_CLK_SPDIF_LOCK			0x2
  #define SND_RME_CLK_SPDIF_SYNC			0x8
  #define SND_RME_SPDIF_IF_SHIFT			4
  #define SND_RME_SPDIF_FORMAT_SHIFT		5
  #define SND_RME_BINARY_MASK			0x1
  #define SND_RME_SPDIF_IF(x) \
  	((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
  #define SND_RME_SPDIF_FORMAT(x) \
  	((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
  
  static const u32 snd_rme_rate_table[] = {
  	32000, 44100, 48000, 50000,
  	64000, 88200, 96000, 100000,
  	128000, 176400, 192000, 200000,
  	256000,	352800, 384000, 400000,
  	512000, 705600, 768000, 800000
  };
  /* maximum number of items for AES and S/PDIF rates for above table */
  #define SND_RME_RATE_IDX_AES_SPDIF_NUM		12
  
  enum snd_rme_domain {
  	SND_RME_DOMAIN_SYSTEM,
  	SND_RME_DOMAIN_AES,
  	SND_RME_DOMAIN_SPDIF
  };
  
  enum snd_rme_clock_status {
  	SND_RME_CLOCK_NOLOCK,
  	SND_RME_CLOCK_LOCK,
  	SND_RME_CLOCK_SYNC
  };
  
  static int snd_rme_read_value(struct snd_usb_audio *chip,
  			      unsigned int item,
  			      u32 *value)
  {
  	struct usb_device *dev = chip->dev;
  	int err;
  
  	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  			      item,
  			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  			      0, 0,
  			      value, sizeof(*value));
  	if (err < 0)
  		dev_err(&dev->dev,
  			"unable to issue vendor read request %d (ret = %d)",
  			item, err);
  	return err;
  }
  
  static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
  			       u32 *status1)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	struct snd_usb_audio *chip = list->mixer->chip;
  	int err;
  
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
  	snd_usb_unlock_shutdown(chip);
  	return err;
  }
  
  static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
  			    struct snd_ctl_elem_value *ucontrol)
  {
  	u32 status1;
  	u32 rate = 0;
  	int idx;
  	int err;
  
  	err = snd_rme_get_status1(kcontrol, &status1);
  	if (err < 0)
  		return err;
  	switch (kcontrol->private_value) {
  	case SND_RME_DOMAIN_SYSTEM:
  		idx = SND_RME_CLK_SYSTEM(status1);
  		if (idx < ARRAY_SIZE(snd_rme_rate_table))
  			rate = snd_rme_rate_table[idx];
  		break;
  	case SND_RME_DOMAIN_AES:
  		idx = SND_RME_CLK_AES(status1);
  		if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
  			rate = snd_rme_rate_table[idx];
  		break;
  	case SND_RME_DOMAIN_SPDIF:
  		idx = SND_RME_CLK_SPDIF(status1);
  		if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
  			rate = snd_rme_rate_table[idx];
  		break;
  	default:
  		return -EINVAL;
  	}
  	ucontrol->value.integer.value[0] = rate;
  	return 0;
  }
  
  static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
  				  struct snd_ctl_elem_value *ucontrol)
  {
  	u32 status1;
  	int idx = SND_RME_CLOCK_NOLOCK;
  	int err;
  
  	err = snd_rme_get_status1(kcontrol, &status1);
  	if (err < 0)
  		return err;
  	switch (kcontrol->private_value) {
  	case SND_RME_DOMAIN_AES:  /* AES */
  		if (status1 & SND_RME_CLK_AES_SYNC)
  			idx = SND_RME_CLOCK_SYNC;
  		else if (status1 & SND_RME_CLK_AES_LOCK)
  			idx = SND_RME_CLOCK_LOCK;
  		break;
  	case SND_RME_DOMAIN_SPDIF:  /* SPDIF */
  		if (status1 & SND_RME_CLK_SPDIF_SYNC)
  			idx = SND_RME_CLOCK_SYNC;
  		else if (status1 & SND_RME_CLK_SPDIF_LOCK)
  			idx = SND_RME_CLOCK_LOCK;
  		break;
  	default:
  		return -EINVAL;
  	}
  	ucontrol->value.enumerated.item[0] = idx;
  	return 0;
  }
  
  static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
  {
  	u32 status1;
  	int err;
  
  	err = snd_rme_get_status1(kcontrol, &status1);
  	if (err < 0)
  		return err;
  	ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
  	return 0;
  }
  
  static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
  				    struct snd_ctl_elem_value *ucontrol)
  {
  	u32 status1;
  	int err;
  
  	err = snd_rme_get_status1(kcontrol, &status1);
  	if (err < 0)
  		return err;
  	ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
  	return 0;
  }
  
  static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
  	u32 status1;
  	int err;
  
  	err = snd_rme_get_status1(kcontrol, &status1);
  	if (err < 0)
  		return err;
  	ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
  	return 0;
  }
  
  static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
  				    struct snd_ctl_elem_value *ucontrol)
  {
  	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
  	struct snd_usb_audio *chip = list->mixer->chip;
  	u32 status1;
  	const u64 num = 104857600000000ULL;
  	u32 den;
  	unsigned int freq;
  	int err;
  
  	err = snd_usb_lock_shutdown(chip);
  	if (err < 0)
  		return err;
  	err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
  	if (err < 0)
  		goto end;
  	err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
  	if (err < 0)
  		goto end;
  	freq = (den == 0) ? 0 : div64_u64(num, den);
  	freq <<= SND_RME_CLK_FREQMUL(status1);
  	ucontrol->value.integer.value[0] = freq;
  
  end:
  	snd_usb_unlock_shutdown(chip);
  	return err;
  }
  
  static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
  			     struct snd_ctl_elem_info *uinfo)
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 1;
  	switch (kcontrol->private_value) {
  	case SND_RME_DOMAIN_SYSTEM:
  		uinfo->value.integer.min = 32000;
  		uinfo->value.integer.max = 800000;
  		break;
  	case SND_RME_DOMAIN_AES:
  	case SND_RME_DOMAIN_SPDIF:
  	default:
  		uinfo->value.integer.min = 0;
  		uinfo->value.integer.max = 200000;
  	}
  	uinfo->value.integer.step = 0;
  	return 0;
  }
  
  static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const sync_states[] = {
  		"No Lock", "Lock", "Sync"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1,
  				 ARRAY_SIZE(sync_states), sync_states);
  }
  
  static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const spdif_if[] = {
  		"Coaxial", "Optical"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1,
  				 ARRAY_SIZE(spdif_if), spdif_if);
  }
  
  static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
  				     struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const optical_type[] = {
  		"Consumer", "Professional"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1,
  				 ARRAY_SIZE(optical_type), optical_type);
  }
  
  static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
  				    struct snd_ctl_elem_info *uinfo)
  {
  	static const char *const sync_sources[] = {
  		"Internal", "AES", "SPDIF", "Internal"
  	};
  
  	return snd_ctl_enum_info(uinfo, 1,
  				 ARRAY_SIZE(sync_sources), sync_sources);
  }
  
  static struct snd_kcontrol_new snd_rme_controls[] = {
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "AES Rate",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_rate_info,
  		.get = snd_rme_rate_get,
  		.private_value = SND_RME_DOMAIN_AES
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "AES Sync",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_sync_state_info,
  		.get = snd_rme_sync_state_get,
  		.private_value = SND_RME_DOMAIN_AES
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "SPDIF Rate",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_rate_info,
  		.get = snd_rme_rate_get,
  		.private_value = SND_RME_DOMAIN_SPDIF
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "SPDIF Sync",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_sync_state_info,
  		.get = snd_rme_sync_state_get,
  		.private_value = SND_RME_DOMAIN_SPDIF
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "SPDIF Interface",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_spdif_if_info,
  		.get = snd_rme_spdif_if_get,
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "SPDIF Format",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_spdif_format_info,
  		.get = snd_rme_spdif_format_get,
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Sync Source",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_sync_source_info,
  		.get = snd_rme_sync_source_get
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "System Rate",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_rate_info,
  		.get = snd_rme_rate_get,
  		.private_value = SND_RME_DOMAIN_SYSTEM
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Current Frequency",
  		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  		.info = snd_rme_rate_info,
  		.get = snd_rme_current_freq_get
  	}
  };
  
  static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
  {
  	int err, i;
  
  	for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
  		err = add_single_ctl_with_resume(mixer, 0,
  						 NULL,
  						 &snd_rme_controls[i],
  						 NULL);
  		if (err < 0)
  			return err;
  	}
  
  	return 0;
  }
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2118
2119
  int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
  {
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2120
  	int err = 0;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2121

f25ecf8f9   Takashi Iwai   ALSA: usb-audio: ...
2122
2123
  	err = snd_usb_soundblaster_remote_init(mixer);
  	if (err < 0)
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2124
  		return err;
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2125
  	switch (mixer->chip->usb_id) {
d2bb390a2   Detlef Urban   ALSA: usb-audio: ...
2126
2127
2128
2129
  	/* Tascam US-16x08 */
  	case USB_ID(0x0644, 0x8047):
  		err = snd_us16x08_controls_create(mixer);
  		break;
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2130
2131
2132
  	case USB_ID(0x041e, 0x3020):
  	case USB_ID(0x041e, 0x3040):
  	case USB_ID(0x041e, 0x3042):
7cdd8d731   Mathieu Bouffard   ALSA: usb-audio -...
2133
  	case USB_ID(0x041e, 0x30df):
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2134
2135
2136
2137
  	case USB_ID(0x041e, 0x3048):
  		err = snd_audigy2nx_controls_create(mixer);
  		if (err < 0)
  			break;
7449054af   Takashi Iwai   ALSA: usb: Clean ...
2138
2139
  		snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
  				     mixer, snd_audigy2nx_proc_read);
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2140
  		break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2141

44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
2142
2143
2144
  	/* EMU0204 */
  	case USB_ID(0x041e, 0x3f19):
  		err = snd_emu0204_controls_create(mixer);
44832a71f   Vasily Khoruzhick   ALSA: usb-audio: ...
2145
  		break;
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
2146
  	case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
e9a25e04b   Matt Gruskin   ALSA: usb-audio: ...
2147
  	case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
09d8e3a71   Eldad Zack   ALSA: usb-audio: ...
2148
2149
  		err = snd_c400_create_mixer(mixer);
  		break;
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
2150
2151
  	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: ...
2152
  		err = snd_ftu_create_mixer(mixer);
d5a0bf6cc   Daniel Mack   ALSA: usb-audio: ...
2153
  		break;
1d31affbe   Denis Washington   ALSA: usb-audio: ...
2154
2155
2156
  	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: ...
2157
  		err = snd_xonar_u1_controls_create(mixer);
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2158
  		break;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2159

066624c6a   Przemek Rudy   ALSA: usb-audio: ...
2160
2161
2162
  	case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
  		err = snd_microii_controls_create(mixer);
  		break;
d497a82fb   Damien Zammit   ALSA: usb-audio: ...
2163
2164
2165
  	case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
  		err = snd_mbox1_create_sync_switch(mixer);
  		break;
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2166
  	case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
2167
2168
2169
  		err = snd_nativeinstruments_create_mixer(mixer,
  				snd_nativeinstruments_ta6_mixers,
  				ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2170
  		break;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
2171

3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2172
  	case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
2173
2174
2175
  		err = snd_nativeinstruments_create_mixer(mixer,
  				snd_nativeinstruments_ta10_mixers,
  				ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2176
  		break;
7536c301f   Mark Hills   ALSA: snd-usb-aud...
2177
2178
  
  	case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
b71dad181   Mark Hills   ALSA: usb-audio: ...
2179
2180
  		/* detection is disabled in mixer_maps.c */
  		err = snd_create_std_mono_table(mixer, ebox44_table);
7536c301f   Mark Hills   ALSA: snd-usb-aud...
2181
  		break;
76b188c4b   Chris J Arges   ALSA: usb-audio: ...
2182
2183
2184
2185
2186
2187
2188
2189
  
  	case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
  	case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
  	case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
  	case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
  	case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
  		err = snd_scarlett_controls_create(mixer);
  		break;
388fdb8f8   Ian Douglas Scott   ALSA: usb-audio: ...
2190

9e4d5c1be   Geoffrey D. Bennett   ALSA: usb-audio: ...
2191
2192
2193
2194
2195
  	case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
  	case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
  	case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
  		err = snd_scarlett_gen2_controls_create(mixer);
  		break;
388fdb8f8   Ian Douglas Scott   ALSA: usb-audio: ...
2196
2197
2198
  	case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
  		err = snd_soundblaster_e1_switch_create(mixer);
  		break;
964af639a   Takashi Iwai   ALSA: usb-audio: ...
2199
2200
2201
  	case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
  		err = dell_dock_mixer_init(mixer);
  		break;
d39f1d68f   Jussi Laako   ALSA: usb-audio: ...
2202
2203
2204
2205
2206
2207
  
  	case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
  	case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
  	case USB_ID(0x2a39, 0x3fd4): /* RME */
  		err = snd_rme_controls_create(mixer);
  		break;
54a8c500d   Daniel Mack   ALSA: usb-audio: ...
2208
  	}
3347b26ca   Daniel Mack   ALSA: usb-audio: ...
2209
  	return err;
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2210
  }
964af639a   Takashi Iwai   ALSA: usb-audio: ...
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
  #ifdef CONFIG_PM
  void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
  {
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
  		dell_dock_mixer_init(mixer);
  		break;
  	}
  }
  #endif
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
  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:
0ba41d917   Takashi Iwai   ALSA: usb-audio: ...
2244
2245
  		usb_audio_dbg(mixer->chip, "memory change in unknown unit %d
  ", unitid);
7b1eda223   Daniel Mack   ALSA: usb-mixer: ...
2246
2247
2248
  		break;
  	}
  }
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
2249
  static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
eb1a74b7b   Anssi Hannula   ALSA: usb-audio: ...
2250
  					 struct usb_mixer_elem_info *cval,
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
  					 struct snd_kcontrol *kctl)
  {
  	/* Approximation using 10 ranges based on output measurement on hw v1.2.
  	 * This seems close to the cubic mapping e.g. alsamixer uses. */
  	static const DECLARE_TLV_DB_RANGE(scale,
  		 0,  1, TLV_DB_MINMAX_ITEM(-5300, -4970),
  		 2,  5, TLV_DB_MINMAX_ITEM(-4710, -4160),
  		 6,  7, TLV_DB_MINMAX_ITEM(-3884, -3710),
  		 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
  		15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
  		17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
  		20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
  		27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
  		32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
  		41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
  	);
eb1a74b7b   Anssi Hannula   ALSA: usb-audio: ...
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
  	if (cval->min == 0 && cval->max == 50) {
  		usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)
  ");
  		kctl->tlv.p = scale;
  		kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
  		kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  
  	} else if (cval->min == 0 && cval->max <= 1000) {
  		/* Some other clearly broken DragonFly variant.
  		 * At least a 0..53 variant (hw v1.0) exists.
  		 */
  		usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
  		kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
  	}
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
2281
2282
2283
2284
2285
2286
2287
2288
  }
  
  void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
  				  struct usb_mixer_elem_info *cval, int unitid,
  				  struct snd_kcontrol *kctl)
  {
  	switch (mixer->chip->usb_id) {
  	case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
eb1a74b7b   Anssi Hannula   ALSA: usb-audio: ...
2289
2290
  		if (unitid == 7 && cval->control == UAC_FU_VOLUME)
  			snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
2291
  		break;
0f174b352   Takashi Iwai   ALSA: usb-audio: ...
2292
2293
2294
2295
2296
2297
  	/* lowest playback value is muted on C-Media devices */
  	case USB_ID(0x0d8c, 0x000c):
  	case USB_ID(0x0d8c, 0x0014):
  		if (strstr(kctl->id.name, "Playback"))
  			cval->min_mute = 1;
  		break;
42e3121d9   Anssi Hannula   ALSA: usb-audio: ...
2298
2299
  	}
  }