blob: e1e7ce9ab217f6f716fc95da5d1544279c0d1b75 [file] [log] [blame]
Daniel Mack7b1eda22010-03-11 21:13:22 +01001/*
2 * USB Audio Driver for ALSA
3 *
4 * Quirks and vendor-specific extensions for mixer interfaces
5 *
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7 *
8 * Many codes borrowed from audio.c by
9 * Alan Cox (alan@lxorguk.ukuu.org.uk)
10 * Thomas Sailer (sailer@ife.ee.ethz.ch)
11 *
Przemek Rudy066624c2013-06-27 23:52:33 +020012 * Audio Advantage Micro II support added by:
13 * Przemek Rudy (prudy1@o2.pl)
Daniel Mack7b1eda22010-03-11 21:13:22 +010014 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30#include <linux/init.h>
Stephen Rothwell36db0452010-03-29 16:02:50 +110031#include <linux/slab.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010032#include <linux/usb.h>
33#include <linux/usb/audio.h>
34
Przemek Rudy066624c2013-06-27 23:52:33 +020035#include <sound/asoundef.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010036#include <sound/core.h>
37#include <sound/control.h>
38#include <sound/hwdep.h>
39#include <sound/info.h>
Anssi Hannula42e31212015-12-13 20:49:58 +020040#include <sound/tlv.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010041
42#include "usbaudio.h"
Daniel Mackf0b5e632010-03-11 21:13:23 +010043#include "mixer.h"
Daniel Mack7b1eda22010-03-11 21:13:22 +010044#include "mixer_quirks.h"
Chris J Arges76b188c2014-11-12 12:07:02 -060045#include "mixer_scarlett.h"
Detlef Urband2bb390a2017-02-20 09:47:59 +010046#include "mixer_us16x08.h"
Daniel Mack7b1eda22010-03-11 21:13:22 +010047#include "helper.h"
48
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +020049extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
50
Mark Hillsb71dad182012-06-09 13:16:38 +010051struct std_mono_table {
52 unsigned int unitid, control, cmask;
53 int val_type;
54 const char *name;
55 snd_kcontrol_tlv_rw_t *tlv_callback;
56};
57
Felix Homann8a4d1d32012-04-23 20:24:23 +020058/* This function allows for the creation of standard UAC controls.
59 * See the quirks for M-Audio FTUs or Ebox-44.
60 * If you don't want to set a TLV callback pass NULL.
61 *
62 * Since there doesn't seem to be a devices that needs a multichannel
63 * version, we keep it mono for simplicity.
64 */
Eldad Zack9f814102012-11-28 23:55:35 +010065static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
Felix Homann8a4d1d32012-04-23 20:24:23 +020066 unsigned int unitid,
67 unsigned int control,
68 unsigned int cmask,
69 int val_type,
Eldad Zack9f814102012-11-28 23:55:35 +010070 unsigned int idx_off,
Felix Homann8a4d1d32012-04-23 20:24:23 +020071 const char *name,
72 snd_kcontrol_tlv_rw_t *tlv_callback)
73{
Felix Homann8a4d1d32012-04-23 20:24:23 +020074 struct usb_mixer_elem_info *cval;
75 struct snd_kcontrol *kctl;
76
77 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
78 if (!cval)
79 return -ENOMEM;
80
Takashi Iwai3360b842014-11-18 11:47:04 +010081 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
Felix Homann8a4d1d32012-04-23 20:24:23 +020082 cval->val_type = val_type;
83 cval->channels = 1;
84 cval->control = control;
85 cval->cmask = cmask;
Eldad Zack9f814102012-11-28 23:55:35 +010086 cval->idx_off = idx_off;
Felix Homann8a4d1d32012-04-23 20:24:23 +020087
Mark Hills7df4a692012-05-11 18:31:55 +010088 /* get_min_max() is called only for integer volumes later,
89 * so provide a short-cut for booleans */
Felix Homann8a4d1d32012-04-23 20:24:23 +020090 cval->min = 0;
91 cval->max = 1;
92 cval->res = 0;
93 cval->dBmin = 0;
94 cval->dBmax = 0;
95
96 /* Create control */
97 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
98 if (!kctl) {
99 kfree(cval);
100 return -ENOMEM;
101 }
102
103 /* Set name */
104 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
Chris J Argeseef90452014-11-12 12:07:01 -0600105 kctl->private_free = snd_usb_mixer_elem_free;
Felix Homann8a4d1d32012-04-23 20:24:23 +0200106
107 /* set TLV */
108 if (tlv_callback) {
109 kctl->tlv.c = tlv_callback;
110 kctl->vd[0].access |=
111 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
112 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
113 }
114 /* Add control to mixer */
Takashi Iwai3360b842014-11-18 11:47:04 +0100115 return snd_usb_mixer_add_control(&cval->head, kctl);
Felix Homann8a4d1d32012-04-23 20:24:23 +0200116}
117
Eldad Zack9f814102012-11-28 23:55:35 +0100118static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
119 unsigned int unitid,
120 unsigned int control,
121 unsigned int cmask,
122 int val_type,
123 const char *name,
124 snd_kcontrol_tlv_rw_t *tlv_callback)
125{
126 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
127 val_type, 0 /* Offset */, name, tlv_callback);
128}
129
Daniel Mack7b1eda22010-03-11 21:13:22 +0100130/*
Mark Hillsb71dad182012-06-09 13:16:38 +0100131 * Create a set of standard UAC controls from a table
132 */
133static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
134 struct std_mono_table *t)
135{
136 int err;
137
138 while (t->name != NULL) {
139 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
140 t->cmask, t->val_type, t->name, t->tlv_callback);
141 if (err < 0)
142 return err;
143 t++;
144 }
145
146 return 0;
147}
148
Takashi Iwai9cf36892014-11-18 12:58:51 +0100149static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
150 int id,
151 usb_mixer_elem_resume_func_t resume,
152 const struct snd_kcontrol_new *knew,
153 struct usb_mixer_elem_list **listp)
154{
155 struct usb_mixer_elem_list *list;
156 struct snd_kcontrol *kctl;
157
158 list = kzalloc(sizeof(*list), GFP_KERNEL);
159 if (!list)
160 return -ENOMEM;
161 if (listp)
162 *listp = list;
163 list->mixer = mixer;
164 list->id = id;
165 list->resume = resume;
166 kctl = snd_ctl_new1(knew, list);
167 if (!kctl) {
168 kfree(list);
169 return -ENOMEM;
170 }
171 kctl->private_free = snd_usb_mixer_elem_free;
172 return snd_usb_mixer_add_control(list, kctl);
173}
174
Mark Hillsb71dad182012-06-09 13:16:38 +0100175/*
Daniel Mack7b1eda22010-03-11 21:13:22 +0100176 * Sound Blaster remote control configuration
177 *
178 * format of remote control data:
179 * Extigy: xx 00
180 * Audigy 2 NX: 06 80 xx 00 00 00
181 * Live! 24-bit: 06 80 xx yy 22 83
182 */
183static const struct rc_config {
184 u32 usb_id;
185 u8 offset;
186 u8 length;
187 u8 packet_length;
188 u8 min_packet_length; /* minimum accepted length of the URB result */
189 u8 mute_mixer_id;
190 u32 mute_code;
191} rc_configs[] = {
192 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
193 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
194 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
Mandar Joshica8dc342010-11-02 14:43:19 +0000195 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200196 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Dmitry M. Fedin3dc85232015-04-09 17:37:03 +0300197 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Daniel Mack7b1eda22010-03-11 21:13:22 +0100198 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
199};
200
201static void snd_usb_soundblaster_remote_complete(struct urb *urb)
202{
203 struct usb_mixer_interface *mixer = urb->context;
204 const struct rc_config *rc = mixer->rc_cfg;
205 u32 code;
206
207 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
208 return;
209
210 code = mixer->rc_buffer[rc->offset];
211 if (rc->length == 2)
212 code |= mixer->rc_buffer[rc->offset + 1] << 8;
213
214 /* the Mute button actually changes the mixer control */
215 if (code == rc->mute_code)
216 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
217 mixer->rc_code = code;
218 wmb();
219 wake_up(&mixer->rc_waitq);
220}
221
222static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
223 long count, loff_t *offset)
224{
225 struct usb_mixer_interface *mixer = hw->private_data;
226 int err;
227 u32 rc_code;
228
229 if (count != 1 && count != 4)
230 return -EINVAL;
231 err = wait_event_interruptible(mixer->rc_waitq,
232 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
233 if (err == 0) {
234 if (count == 1)
235 err = put_user(rc_code, buf);
236 else
237 err = put_user(rc_code, (u32 __user *)buf);
238 }
239 return err < 0 ? err : count;
240}
241
242static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
243 poll_table *wait)
244{
245 struct usb_mixer_interface *mixer = hw->private_data;
246
247 poll_wait(file, &mixer->rc_waitq, wait);
248 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
249}
250
251static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
252{
253 struct snd_hwdep *hwdep;
254 int err, len, i;
255
256 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
257 if (rc_configs[i].usb_id == mixer->chip->usb_id)
258 break;
259 if (i >= ARRAY_SIZE(rc_configs))
260 return 0;
261 mixer->rc_cfg = &rc_configs[i];
262
263 len = mixer->rc_cfg->packet_length;
264
265 init_waitqueue_head(&mixer->rc_waitq);
266 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
267 if (err < 0)
268 return err;
269 snprintf(hwdep->name, sizeof(hwdep->name),
270 "%s remote control", mixer->chip->card->shortname);
271 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
272 hwdep->private_data = mixer;
273 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
274 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
275 hwdep->exclusive = 1;
276
277 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
278 if (!mixer->rc_urb)
279 return -ENOMEM;
280 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
281 if (!mixer->rc_setup_packet) {
282 usb_free_urb(mixer->rc_urb);
283 mixer->rc_urb = NULL;
284 return -ENOMEM;
285 }
286 mixer->rc_setup_packet->bRequestType =
287 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
288 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
289 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
290 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
291 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
292 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
293 usb_rcvctrlpipe(mixer->chip->dev, 0),
294 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
295 snd_usb_soundblaster_remote_complete, mixer);
296 return 0;
297}
298
299#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
300
301static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
302{
Takashi Iwai9cf36892014-11-18 12:58:51 +0100303 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100304 return 0;
305}
306
Takashi Iwai9cf36892014-11-18 12:58:51 +0100307static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
308 int value, int index)
Daniel Mack7b1eda22010-03-11 21:13:22 +0100309{
Takashi Iwai9cf36892014-11-18 12:58:51 +0100310 struct snd_usb_audio *chip = mixer->chip;
311 int err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100312
Takashi Iwai47ab1542015-08-25 16:09:00 +0200313 err = snd_usb_lock_shutdown(chip);
314 if (err < 0)
315 return err;
316
Takashi Iwai9cf36892014-11-18 12:58:51 +0100317 if (chip->usb_id == USB_ID(0x041e, 0x3042))
318 err = snd_usb_ctl_msg(chip->dev,
319 usb_sndctrlpipe(chip->dev, 0), 0x24,
Mandar Joshica8dc342010-11-02 14:43:19 +0000320 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200321 !value, 0, NULL, 0);
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200322 /* USB X-Fi S51 Pro */
Takashi Iwai9cf36892014-11-18 12:58:51 +0100323 if (chip->usb_id == USB_ID(0x041e, 0x30df))
324 err = snd_usb_ctl_msg(chip->dev,
325 usb_sndctrlpipe(chip->dev, 0), 0x24,
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200326 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200327 !value, 0, NULL, 0);
Mandar Joshica8dc342010-11-02 14:43:19 +0000328 else
Takashi Iwai9cf36892014-11-18 12:58:51 +0100329 err = snd_usb_ctl_msg(chip->dev,
330 usb_sndctrlpipe(chip->dev, 0), 0x24,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100331 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200332 value, index + 2, NULL, 0);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200333 snd_usb_unlock_shutdown(chip);
Takashi Iwai9cf36892014-11-18 12:58:51 +0100334 return err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100335}
336
Takashi Iwai9cf36892014-11-18 12:58:51 +0100337static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
339{
340 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
341 struct usb_mixer_interface *mixer = list->mixer;
342 int index = kcontrol->private_value & 0xff;
Dan Carpentere87359e2015-09-28 13:06:20 +0300343 unsigned int value = ucontrol->value.integer.value[0];
Takashi Iwai9cf36892014-11-18 12:58:51 +0100344 int old_value = kcontrol->private_value >> 8;
345 int err;
346
347 if (value > 1)
348 return -EINVAL;
349 if (value == old_value)
350 return 0;
351 kcontrol->private_value = (value << 8) | index;
352 err = snd_audigy2nx_led_update(mixer, value, index);
353 return err < 0 ? err : 1;
354}
355
356static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
357{
358 int priv_value = list->kctl->private_value;
359
360 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
361 priv_value & 0xff);
362}
363
364/* name and private_value are set dynamically */
Bhumika Goyal905e46a2017-05-27 20:16:15 +0530365static const struct snd_kcontrol_new snd_audigy2nx_control = {
Takashi Iwai9cf36892014-11-18 12:58:51 +0100366 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
367 .info = snd_audigy2nx_led_info,
368 .get = snd_audigy2nx_led_get,
369 .put = snd_audigy2nx_led_put,
370};
371
372static const char * const snd_audigy2nx_led_names[] = {
373 "CMSS LED Switch",
374 "Power LED Switch",
375 "Dolby Digital LED Switch",
Daniel Mack7b1eda22010-03-11 21:13:22 +0100376};
377
378static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
379{
380 int i, err;
381
Takashi Iwai9cf36892014-11-18 12:58:51 +0100382 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
383 struct snd_kcontrol_new knew;
384
Mandar Joshica8dc342010-11-02 14:43:19 +0000385 /* USB X-Fi S51 doesn't have a CMSS LED */
386 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
387 continue;
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200388 /* USB X-Fi S51 Pro doesn't have one either */
389 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
390 continue;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100391 if (i > 1 && /* Live24ext has 2 LEDs only */
392 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
Mandar Joshica8dc342010-11-02 14:43:19 +0000393 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200394 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
Daniel Mack7b1eda22010-03-11 21:13:22 +0100395 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
396 break;
Takashi Iwai9cf36892014-11-18 12:58:51 +0100397
398 knew = snd_audigy2nx_control;
399 knew.name = snd_audigy2nx_led_names[i];
400 knew.private_value = (1 << 8) | i; /* LED on as default */
401 err = add_single_ctl_with_resume(mixer, 0,
402 snd_audigy2nx_led_resume,
403 &knew, NULL);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100404 if (err < 0)
405 return err;
406 }
Daniel Mack7b1eda22010-03-11 21:13:22 +0100407 return 0;
408}
409
410static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
411 struct snd_info_buffer *buffer)
412{
413 static const struct sb_jack {
414 int unitid;
415 const char *name;
416 } jacks_audigy2nx[] = {
417 {4, "dig in "},
418 {7, "line in"},
419 {19, "spk out"},
420 {20, "hph out"},
421 {-1, NULL}
422 }, jacks_live24ext[] = {
423 {4, "line in"}, /* &1=Line, &2=Mic*/
424 {3, "hph out"}, /* headphones */
425 {0, "RC "}, /* last command, 6 bytes see rc_config above */
426 {-1, NULL}
427 };
428 const struct sb_jack *jacks;
429 struct usb_mixer_interface *mixer = entry->private_data;
430 int i, err;
431 u8 buf[3];
432
433 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
434 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
435 jacks = jacks_audigy2nx;
436 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
437 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
438 jacks = jacks_live24ext;
439 else
440 return;
441
442 for (i = 0; jacks[i].name; ++i) {
443 snd_iprintf(buffer, "%s: ", jacks[i].name);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200444 err = snd_usb_lock_shutdown(mixer->chip);
445 if (err < 0)
446 return;
447 err = snd_usb_ctl_msg(mixer->chip->dev,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100448 usb_rcvctrlpipe(mixer->chip->dev, 0),
449 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
450 USB_RECIP_INTERFACE, 0,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200451 jacks[i].unitid << 8, buf, 3);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200452 snd_usb_unlock_shutdown(mixer->chip);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100453 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
454 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
455 else
456 snd_iprintf(buffer, "?\n");
457 }
458}
459
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300460/* EMU0204 */
461static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_info *uinfo)
463{
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200464 static const char * const texts[2] = {"1/2", "3/4"};
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300465
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200466 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300467}
468
469static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
470 struct snd_ctl_elem_value *ucontrol)
471{
472 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
473 return 0;
474}
475
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100476static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
477 int value)
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300478{
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100479 struct snd_usb_audio *chip = mixer->chip;
480 int err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300481 unsigned char buf[2];
482
Takashi Iwai47ab1542015-08-25 16:09:00 +0200483 err = snd_usb_lock_shutdown(chip);
484 if (err < 0)
485 return err;
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100486
487 buf[0] = 0x01;
488 buf[1] = value ? 0x02 : 0x01;
489 err = snd_usb_ctl_msg(chip->dev,
490 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300491 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
492 0x0400, 0x0e00, buf, 2);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200493 snd_usb_unlock_shutdown(chip);
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100494 return err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300495}
496
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100497static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
499{
500 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
501 struct usb_mixer_interface *mixer = list->mixer;
502 unsigned int value = ucontrol->value.enumerated.item[0];
503 int err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300504
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100505 if (value > 1)
506 return -EINVAL;
507
508 if (value == kcontrol->private_value)
509 return 0;
510
511 kcontrol->private_value = value;
512 err = snd_emu0204_ch_switch_update(mixer, value);
513 return err < 0 ? err : 1;
514}
515
516static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
517{
518 return snd_emu0204_ch_switch_update(list->mixer,
519 list->kctl->private_value);
520}
521
522static struct snd_kcontrol_new snd_emu0204_control = {
523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524 .name = "Front Jack Channels",
525 .info = snd_emu0204_ch_switch_info,
526 .get = snd_emu0204_ch_switch_get,
527 .put = snd_emu0204_ch_switch_put,
528 .private_value = 0,
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300529};
530
531static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
532{
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100533 return add_single_ctl_with_resume(mixer, 0,
534 snd_emu0204_ch_switch_resume,
535 &snd_emu0204_control, NULL);
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300536}
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100537
Denis Washington1d31aff2012-12-11 11:38:32 +0100538/* ASUS Xonar U1 / U3 controls */
539
Daniel Mack7b1eda22010-03-11 21:13:22 +0100540static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
542{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100543 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100544 return 0;
545}
546
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100547static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
548 unsigned char status)
549{
550 struct snd_usb_audio *chip = mixer->chip;
551 int err;
552
Takashi Iwai47ab1542015-08-25 16:09:00 +0200553 err = snd_usb_lock_shutdown(chip);
554 if (err < 0)
555 return err;
556 err = snd_usb_ctl_msg(chip->dev,
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100557 usb_sndctrlpipe(chip->dev, 0), 0x08,
558 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
559 50, 0, &status, 1);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200560 snd_usb_unlock_shutdown(chip);
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100561 return err;
562}
563
Daniel Mack7b1eda22010-03-11 21:13:22 +0100564static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
565 struct snd_ctl_elem_value *ucontrol)
566{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100567 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100568 u8 old_status, new_status;
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100569 int err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100570
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100571 old_status = kcontrol->private_value;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100572 if (ucontrol->value.integer.value[0])
573 new_status = old_status | 0x02;
574 else
575 new_status = old_status & ~0x02;
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100576 if (new_status == old_status)
577 return 0;
578
579 kcontrol->private_value = new_status;
580 err = snd_xonar_u1_switch_update(list->mixer, new_status);
581 return err < 0 ? err : 1;
582}
583
584static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
585{
586 return snd_xonar_u1_switch_update(list->mixer,
587 list->kctl->private_value);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100588}
589
590static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
592 .name = "Digital Playback Switch",
593 .info = snd_ctl_boolean_mono_info,
594 .get = snd_xonar_u1_switch_get,
595 .put = snd_xonar_u1_switch_put,
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100596 .private_value = 0x05,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100597};
598
599static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
600{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100601 return add_single_ctl_with_resume(mixer, 0,
602 snd_xonar_u1_switch_resume,
603 &snd_xonar_u1_output_switch, NULL);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100604}
605
Damien Zammitd497a822014-11-12 01:09:54 +1100606/* Digidesign Mbox 1 clock source switch (internal/spdif) */
607
608static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
609 struct snd_ctl_elem_value *ucontrol)
610{
611 ucontrol->value.enumerated.item[0] = kctl->private_value;
612 return 0;
613}
614
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100615static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
Damien Zammitd497a822014-11-12 01:09:54 +1100616{
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100617 struct snd_usb_audio *chip = mixer->chip;
Damien Zammitd497a822014-11-12 01:09:54 +1100618 int err;
Damien Zammitd497a822014-11-12 01:09:54 +1100619 unsigned char buff[3];
620
Takashi Iwai47ab1542015-08-25 16:09:00 +0200621 err = snd_usb_lock_shutdown(chip);
622 if (err < 0)
623 return err;
Damien Zammitd497a822014-11-12 01:09:54 +1100624
625 /* Prepare for magic command to toggle clock source */
626 err = snd_usb_ctl_msg(chip->dev,
627 usb_rcvctrlpipe(chip->dev, 0), 0x81,
628 USB_DIR_IN |
629 USB_TYPE_CLASS |
630 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
631 if (err < 0)
632 goto err;
633 err = snd_usb_ctl_msg(chip->dev,
634 usb_rcvctrlpipe(chip->dev, 0), 0x81,
635 USB_DIR_IN |
636 USB_TYPE_CLASS |
637 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
638 if (err < 0)
639 goto err;
640
641 /* 2 possibilities: Internal -> send sample rate
642 * S/PDIF sync -> send zeroes
643 * NB: Sample rate locked to 48kHz on purpose to
644 * prevent user from resetting the sample rate
645 * while S/PDIF sync is enabled and confusing
646 * this configuration.
647 */
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100648 if (val == 0) {
Damien Zammitd497a822014-11-12 01:09:54 +1100649 buff[0] = 0x80;
650 buff[1] = 0xbb;
651 buff[2] = 0x00;
652 } else {
653 buff[0] = buff[1] = buff[2] = 0x00;
654 }
655
656 /* Send the magic command to toggle the clock source */
657 err = snd_usb_ctl_msg(chip->dev,
658 usb_sndctrlpipe(chip->dev, 0), 0x1,
659 USB_TYPE_CLASS |
660 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
661 if (err < 0)
662 goto err;
663 err = snd_usb_ctl_msg(chip->dev,
664 usb_rcvctrlpipe(chip->dev, 0), 0x81,
665 USB_DIR_IN |
666 USB_TYPE_CLASS |
667 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
668 if (err < 0)
669 goto err;
670 err = snd_usb_ctl_msg(chip->dev,
671 usb_rcvctrlpipe(chip->dev, 0), 0x81,
672 USB_DIR_IN |
673 USB_TYPE_CLASS |
674 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
675 if (err < 0)
676 goto err;
Damien Zammitd497a822014-11-12 01:09:54 +1100677
678err:
Takashi Iwai47ab1542015-08-25 16:09:00 +0200679 snd_usb_unlock_shutdown(chip);
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100680 return err;
681}
682
683static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
684 struct snd_ctl_elem_value *ucontrol)
685{
686 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
687 struct usb_mixer_interface *mixer = list->mixer;
688 int err;
689 bool cur_val, new_val;
690
691 cur_val = kctl->private_value;
692 new_val = ucontrol->value.enumerated.item[0];
693 if (cur_val == new_val)
694 return 0;
695
696 kctl->private_value = new_val;
697 err = snd_mbox1_switch_update(mixer, new_val);
Damien Zammitd497a822014-11-12 01:09:54 +1100698 return err < 0 ? err : 1;
699}
700
701static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_info *uinfo)
703{
704 static const char *const texts[2] = {
705 "Internal",
706 "S/PDIF"
707 };
708
709 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
710}
711
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100712static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
713{
714 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
715}
716
Damien Zammitd497a822014-11-12 01:09:54 +1100717static struct snd_kcontrol_new snd_mbox1_switch = {
718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
719 .name = "Clock Source",
720 .index = 0,
721 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
722 .info = snd_mbox1_switch_info,
723 .get = snd_mbox1_switch_get,
724 .put = snd_mbox1_switch_put,
725 .private_value = 0
726};
727
728static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
729{
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100730 return add_single_ctl_with_resume(mixer, 0,
731 snd_mbox1_switch_resume,
732 &snd_mbox1_switch, NULL);
Damien Zammitd497a822014-11-12 01:09:54 +1100733}
734
Daniel Mack54a8c502011-02-11 11:08:06 +0000735/* Native Instruments device quirks */
736
737#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
738
Takashi Iwaida6d2762014-11-18 16:59:47 +0100739static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
740 struct snd_kcontrol *kctl)
741{
742 struct usb_device *dev = mixer->chip->dev;
743 unsigned int pval = kctl->private_value;
744 u8 value;
745 int err;
746
747 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
748 (pval >> 16) & 0xff,
749 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
750 0, pval & 0xffff, &value, 1);
751 if (err < 0) {
752 dev_err(&dev->dev,
753 "unable to issue vendor read request (ret = %d)", err);
754 return err;
755 }
756
757 kctl->private_value |= (value << 24);
758 return 0;
759}
760
Daniel Mack54a8c502011-02-11 11:08:06 +0000761static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
762 struct snd_ctl_elem_value *ucontrol)
763{
Takashi Iwaida6d2762014-11-18 16:59:47 +0100764 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
Daniel Mack54a8c502011-02-11 11:08:06 +0000765 return 0;
766}
767
Takashi Iwaida6d2762014-11-18 16:59:47 +0100768static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
769{
770 struct snd_usb_audio *chip = list->mixer->chip;
771 unsigned int pval = list->kctl->private_value;
772 int err;
773
Takashi Iwai47ab1542015-08-25 16:09:00 +0200774 err = snd_usb_lock_shutdown(chip);
775 if (err < 0)
776 return err;
777 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
778 (pval >> 16) & 0xff,
779 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
780 pval >> 24, pval & 0xffff, NULL, 0, 1000);
781 snd_usb_unlock_shutdown(chip);
Takashi Iwaida6d2762014-11-18 16:59:47 +0100782 return err;
783}
784
Daniel Mack54a8c502011-02-11 11:08:06 +0000785static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
786 struct snd_ctl_elem_value *ucontrol)
787{
Takashi Iwaida6d2762014-11-18 16:59:47 +0100788 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
789 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
790 u8 newval = ucontrol->value.integer.value[0];
791 int err;
Daniel Mack54a8c502011-02-11 11:08:06 +0000792
Takashi Iwaida6d2762014-11-18 16:59:47 +0100793 if (oldval == newval)
794 return 0;
Daniel Mack54a8c502011-02-11 11:08:06 +0000795
Takashi Iwaida6d2762014-11-18 16:59:47 +0100796 kcontrol->private_value &= ~(0xff << 24);
Takashi Iwaic4a359a2016-01-13 07:20:13 +0100797 kcontrol->private_value |= (unsigned int)newval << 24;
Takashi Iwaida6d2762014-11-18 16:59:47 +0100798 err = snd_ni_update_cur_val(list);
799 return err < 0 ? err : 1;
Daniel Mack54a8c502011-02-11 11:08:06 +0000800}
801
802static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
803 {
804 .name = "Direct Thru Channel A",
805 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
806 },
807 {
808 .name = "Direct Thru Channel B",
809 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
810 },
811 {
812 .name = "Phono Input Channel A",
813 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
814 },
815 {
816 .name = "Phono Input Channel B",
817 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
818 },
819};
820
821static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
822 {
823 .name = "Direct Thru Channel A",
824 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
825 },
826 {
827 .name = "Direct Thru Channel B",
828 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
829 },
830 {
831 .name = "Direct Thru Channel C",
832 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
833 },
834 {
835 .name = "Direct Thru Channel D",
836 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
837 },
838 {
839 .name = "Phono Input Channel A",
840 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
841 },
842 {
843 .name = "Phono Input Channel B",
844 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
845 },
846 {
847 .name = "Phono Input Channel C",
848 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
849 },
850 {
851 .name = "Phono Input Channel D",
852 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
853 },
854};
855
856static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
857 const struct snd_kcontrol_new *kc,
858 unsigned int count)
859{
860 int i, err = 0;
861 struct snd_kcontrol_new template = {
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
864 .get = snd_nativeinstruments_control_get,
865 .put = snd_nativeinstruments_control_put,
866 .info = snd_ctl_boolean_mono_info,
867 };
868
869 for (i = 0; i < count; i++) {
Takashi Iwaida6d2762014-11-18 16:59:47 +0100870 struct usb_mixer_elem_list *list;
Daniel Mack54a8c502011-02-11 11:08:06 +0000871
872 template.name = kc[i].name;
873 template.private_value = kc[i].private_value;
874
Takashi Iwaida6d2762014-11-18 16:59:47 +0100875 err = add_single_ctl_with_resume(mixer, 0,
876 snd_ni_update_cur_val,
877 &template, &list);
Daniel Mack54a8c502011-02-11 11:08:06 +0000878 if (err < 0)
879 break;
Takashi Iwaida6d2762014-11-18 16:59:47 +0100880 snd_ni_control_init_val(mixer, list->kctl);
Daniel Mack54a8c502011-02-11 11:08:06 +0000881 }
882
883 return err;
884}
885
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +0200886/* M-Audio FastTrack Ultra quirks */
Matt Gruskine9a25e02013-02-09 12:56:35 -0500887/* FTU Effect switch (also used by C400/C600) */
Felix Homannd34bf142012-04-23 20:24:27 +0200888static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
889 struct snd_ctl_elem_info *uinfo)
890{
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200891 static const char *const texts[8] = {
892 "Room 1", "Room 2", "Room 3", "Hall 1",
893 "Hall 2", "Plate", "Delay", "Echo"
Felix Homannd34bf142012-04-23 20:24:27 +0200894 };
895
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200896 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
Felix Homannd34bf142012-04-23 20:24:27 +0200897}
898
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100899static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
900 struct snd_kcontrol *kctl)
Felix Homannd34bf142012-04-23 20:24:27 +0200901{
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100902 struct usb_device *dev = mixer->chip->dev;
903 unsigned int pval = kctl->private_value;
Felix Homannd34bf142012-04-23 20:24:27 +0200904 int err;
905 unsigned char value[2];
Felix Homannd34bf142012-04-23 20:24:27 +0200906
907 value[0] = 0x00;
908 value[1] = 0x00;
909
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100910 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
911 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
912 pval & 0xff00,
913 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
914 value, 2);
Felix Homannd34bf142012-04-23 20:24:27 +0200915 if (err < 0)
916 return err;
917
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100918 kctl->private_value |= value[0] << 24;
Felix Homannd34bf142012-04-23 20:24:27 +0200919 return 0;
920}
921
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100922static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
923 struct snd_ctl_elem_value *ucontrol)
924{
925 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
926 return 0;
927}
928
929static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
930{
931 struct snd_usb_audio *chip = list->mixer->chip;
932 unsigned int pval = list->kctl->private_value;
933 unsigned char value[2];
934 int err;
935
936 value[0] = pval >> 24;
937 value[1] = 0;
938
Takashi Iwai47ab1542015-08-25 16:09:00 +0200939 err = snd_usb_lock_shutdown(chip);
940 if (err < 0)
941 return err;
942 err = snd_usb_ctl_msg(chip->dev,
943 usb_sndctrlpipe(chip->dev, 0),
944 UAC_SET_CUR,
945 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
946 pval & 0xff00,
947 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
948 value, 2);
949 snd_usb_unlock_shutdown(chip);
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100950 return err;
951}
952
Felix Homannd34bf142012-04-23 20:24:27 +0200953static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
954 struct snd_ctl_elem_value *ucontrol)
955{
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100956 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
957 unsigned int pval = list->kctl->private_value;
958 int cur_val, err, new_val;
Felix Homannd34bf142012-04-23 20:24:27 +0200959
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100960 cur_val = pval >> 24;
Felix Homannd34bf142012-04-23 20:24:27 +0200961 new_val = ucontrol->value.enumerated.item[0];
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100962 if (cur_val == new_val)
963 return 0;
Felix Homannd34bf142012-04-23 20:24:27 +0200964
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100965 kctl->private_value &= ~(0xff << 24);
966 kctl->private_value |= new_val << 24;
967 err = snd_ftu_eff_switch_update(list);
968 return err < 0 ? err : 1;
Takashi Iwai1a290582014-11-11 15:45:57 +0100969}
970
Eldad Zackd847ce02012-11-28 23:55:37 +0100971static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
972 int validx, int bUnitID)
Felix Homannd34bf142012-04-23 20:24:27 +0200973{
974 static struct snd_kcontrol_new template = {
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
976 .name = "Effect Program Switch",
977 .index = 0,
978 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
979 .info = snd_ftu_eff_switch_info,
980 .get = snd_ftu_eff_switch_get,
981 .put = snd_ftu_eff_switch_put
982 };
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100983 struct usb_mixer_elem_list *list;
Felix Homannd34bf142012-04-23 20:24:27 +0200984 int err;
Felix Homannd34bf142012-04-23 20:24:27 +0200985
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100986 err = add_single_ctl_with_resume(mixer, bUnitID,
987 snd_ftu_eff_switch_update,
988 &template, &list);
Felix Homannd34bf142012-04-23 20:24:27 +0200989 if (err < 0)
990 return err;
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +0100991 list->kctl->private_value = (validx << 8) | bUnitID;
992 snd_ftu_eff_switch_init(mixer, list->kctl);
Felix Homannd34bf142012-04-23 20:24:27 +0200993 return 0;
994}
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +0200995
Felix Homanncfe8f972012-04-23 20:24:26 +0200996/* Create volume controls for FTU devices*/
997static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +0200998{
999 char name[64];
Felix Homann8a4d1d32012-04-23 20:24:23 +02001000 unsigned int control, cmask;
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001001 int in, out, err;
1002
Felix Homann8a4d1d32012-04-23 20:24:23 +02001003 const unsigned int id = 5;
1004 const int val_type = USB_MIXER_S16;
1005
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001006 for (out = 0; out < 8; out++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001007 control = out + 1;
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001008 for (in = 0; in < 8; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001009 cmask = 1 << in;
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001010 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +02001011 "AIn%d - Out%d Capture Volume",
1012 in + 1, out + 1);
1013 err = snd_create_std_mono_ctl(mixer, id, control,
1014 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +02001015 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001016 if (err < 0)
1017 return err;
1018 }
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001019 for (in = 8; in < 16; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001020 cmask = 1 << in;
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001021 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +02001022 "DIn%d - Out%d Playback Volume",
1023 in - 7, out + 1);
1024 err = snd_create_std_mono_ctl(mixer, id, control,
1025 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +02001026 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001027 if (err < 0)
1028 return err;
1029 }
1030 }
1031
1032 return 0;
1033}
1034
Felix Homannd34bf142012-04-23 20:24:27 +02001035/* This control needs a volume quirk, see mixer.c */
1036static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1037{
1038 static const char name[] = "Effect Volume";
1039 const unsigned int id = 6;
1040 const int val_type = USB_MIXER_U8;
1041 const unsigned int control = 2;
1042 const unsigned int cmask = 0;
1043
1044 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1045 name, snd_usb_mixer_vol_tlv);
1046}
1047
1048/* This control needs a volume quirk, see mixer.c */
1049static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1050{
1051 static const char name[] = "Effect Duration";
1052 const unsigned int id = 6;
1053 const int val_type = USB_MIXER_S16;
1054 const unsigned int control = 3;
1055 const unsigned int cmask = 0;
1056
1057 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1058 name, snd_usb_mixer_vol_tlv);
1059}
1060
1061/* This control needs a volume quirk, see mixer.c */
1062static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1063{
1064 static const char name[] = "Effect Feedback Volume";
1065 const unsigned int id = 6;
1066 const int val_type = USB_MIXER_U8;
1067 const unsigned int control = 4;
1068 const unsigned int cmask = 0;
1069
1070 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1071 name, NULL);
1072}
1073
1074static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1075{
1076 unsigned int cmask;
1077 int err, ch;
1078 char name[48];
1079
1080 const unsigned int id = 7;
1081 const int val_type = USB_MIXER_S16;
1082 const unsigned int control = 7;
1083
1084 for (ch = 0; ch < 4; ++ch) {
1085 cmask = 1 << ch;
1086 snprintf(name, sizeof(name),
1087 "Effect Return %d Volume", ch + 1);
1088 err = snd_create_std_mono_ctl(mixer, id, control,
1089 cmask, val_type, name,
1090 snd_usb_mixer_vol_tlv);
1091 if (err < 0)
1092 return err;
1093 }
1094
1095 return 0;
1096}
1097
1098static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1099{
1100 unsigned int cmask;
1101 int err, ch;
1102 char name[48];
1103
1104 const unsigned int id = 5;
1105 const int val_type = USB_MIXER_S16;
1106 const unsigned int control = 9;
1107
1108 for (ch = 0; ch < 8; ++ch) {
1109 cmask = 1 << ch;
1110 snprintf(name, sizeof(name),
1111 "Effect Send AIn%d Volume", ch + 1);
1112 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1113 val_type, name,
1114 snd_usb_mixer_vol_tlv);
1115 if (err < 0)
1116 return err;
1117 }
1118 for (ch = 8; ch < 16; ++ch) {
1119 cmask = 1 << ch;
1120 snprintf(name, sizeof(name),
1121 "Effect Send DIn%d Volume", ch - 7);
1122 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1123 val_type, name,
1124 snd_usb_mixer_vol_tlv);
1125 if (err < 0)
1126 return err;
1127 }
1128 return 0;
1129}
1130
Felix Homanncfe8f972012-04-23 20:24:26 +02001131static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
Mark Hills7536c302012-04-14 17:19:24 +01001132{
Felix Homann8a4d1d32012-04-23 20:24:23 +02001133 int err;
Mark Hills7536c302012-04-14 17:19:24 +01001134
Felix Homanncfe8f972012-04-23 20:24:26 +02001135 err = snd_ftu_create_volume_ctls(mixer);
Felix Homann8a4d1d32012-04-23 20:24:23 +02001136 if (err < 0)
1137 return err;
Mark Hills7536c302012-04-14 17:19:24 +01001138
Eldad Zackd847ce02012-11-28 23:55:37 +01001139 err = snd_ftu_create_effect_switch(mixer, 1, 6);
Felix Homannd34bf142012-04-23 20:24:27 +02001140 if (err < 0)
1141 return err;
Eldad Zackd847ce02012-11-28 23:55:37 +01001142
Felix Homannd34bf142012-04-23 20:24:27 +02001143 err = snd_ftu_create_effect_volume_ctl(mixer);
1144 if (err < 0)
1145 return err;
1146
1147 err = snd_ftu_create_effect_duration_ctl(mixer);
1148 if (err < 0)
1149 return err;
1150
1151 err = snd_ftu_create_effect_feedback_ctl(mixer);
1152 if (err < 0)
1153 return err;
1154
1155 err = snd_ftu_create_effect_return_ctls(mixer);
1156 if (err < 0)
1157 return err;
1158
1159 err = snd_ftu_create_effect_send_ctls(mixer);
1160 if (err < 0)
1161 return err;
1162
Felix Homann8a4d1d32012-04-23 20:24:23 +02001163 return 0;
Mark Hills7536c302012-04-14 17:19:24 +01001164}
1165
Daniel Mack7b1eda22010-03-11 21:13:22 +01001166void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1167 unsigned char samplerate_id)
1168{
1169 struct usb_mixer_interface *mixer;
1170 struct usb_mixer_elem_info *cval;
1171 int unitid = 12; /* SamleRate ExtensionUnit ID */
1172
1173 list_for_each_entry(mixer, &chip->mixer_list, list) {
Takashi Iwai3360b842014-11-18 11:47:04 +01001174 cval = (struct usb_mixer_elem_info *)mixer->id_elems[unitid];
Daniel Mack7b1eda22010-03-11 21:13:22 +01001175 if (cval) {
1176 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1177 cval->control << 8,
1178 samplerate_id);
1179 snd_usb_mixer_notify_id(mixer, unitid);
1180 }
1181 break;
1182 }
1183}
1184
Matt Gruskine9a25e02013-02-09 12:56:35 -05001185/* M-Audio Fast Track C400/C600 */
1186/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001187static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1188{
1189 char name[64];
1190 unsigned int cmask, offset;
1191 int out, chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001192 int num_outs = 0;
1193 int num_ins = 0;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001194
1195 const unsigned int id = 0x40;
1196 const int val_type = USB_MIXER_S16;
1197 const int control = 1;
1198
Matt Gruskine9a25e02013-02-09 12:56:35 -05001199 switch (mixer->chip->usb_id) {
1200 case USB_ID(0x0763, 0x2030):
1201 num_outs = 6;
1202 num_ins = 4;
1203 break;
1204 case USB_ID(0x0763, 0x2031):
1205 num_outs = 8;
1206 num_ins = 6;
1207 break;
1208 }
1209
1210 for (chan = 0; chan < num_outs + num_ins; chan++) {
1211 for (out = 0; out < num_outs; out++) {
1212 if (chan < num_outs) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001213 snprintf(name, sizeof(name),
1214 "PCM%d-Out%d Playback Volume",
1215 chan + 1, out + 1);
1216 } else {
1217 snprintf(name, sizeof(name),
1218 "In%d-Out%d Playback Volume",
Matt Gruskine9a25e02013-02-09 12:56:35 -05001219 chan - num_outs + 1, out + 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001220 }
1221
1222 cmask = (out == 0) ? 0 : 1 << (out - 1);
Matt Gruskine9a25e02013-02-09 12:56:35 -05001223 offset = chan * num_outs;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001224 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1225 cmask, val_type, offset, name,
1226 &snd_usb_mixer_vol_tlv);
1227 if (err < 0)
1228 return err;
1229 }
1230 }
1231
1232 return 0;
1233}
1234
1235/* This control needs a volume quirk, see mixer.c */
1236static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1237{
1238 static const char name[] = "Effect Volume";
1239 const unsigned int id = 0x43;
1240 const int val_type = USB_MIXER_U8;
1241 const unsigned int control = 3;
1242 const unsigned int cmask = 0;
1243
1244 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1245 name, snd_usb_mixer_vol_tlv);
1246}
1247
1248/* This control needs a volume quirk, see mixer.c */
1249static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1250{
1251 static const char name[] = "Effect Duration";
1252 const unsigned int id = 0x43;
1253 const int val_type = USB_MIXER_S16;
1254 const unsigned int control = 4;
1255 const unsigned int cmask = 0;
1256
1257 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1258 name, snd_usb_mixer_vol_tlv);
1259}
1260
1261/* This control needs a volume quirk, see mixer.c */
1262static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1263{
1264 static const char name[] = "Effect Feedback Volume";
1265 const unsigned int id = 0x43;
1266 const int val_type = USB_MIXER_U8;
1267 const unsigned int control = 5;
1268 const unsigned int cmask = 0;
1269
1270 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1271 name, NULL);
1272}
1273
1274static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1275{
1276 char name[64];
1277 unsigned int cmask;
1278 int chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001279 int num_outs = 0;
1280 int num_ins = 0;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001281
1282 const unsigned int id = 0x42;
1283 const int val_type = USB_MIXER_S16;
1284 const int control = 1;
1285
Matt Gruskine9a25e02013-02-09 12:56:35 -05001286 switch (mixer->chip->usb_id) {
1287 case USB_ID(0x0763, 0x2030):
1288 num_outs = 6;
1289 num_ins = 4;
1290 break;
1291 case USB_ID(0x0763, 0x2031):
1292 num_outs = 8;
1293 num_ins = 6;
1294 break;
1295 }
1296
1297 for (chan = 0; chan < num_outs + num_ins; chan++) {
1298 if (chan < num_outs) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001299 snprintf(name, sizeof(name),
1300 "Effect Send DOut%d",
1301 chan + 1);
1302 } else {
1303 snprintf(name, sizeof(name),
1304 "Effect Send AIn%d",
Matt Gruskine9a25e02013-02-09 12:56:35 -05001305 chan - num_outs + 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001306 }
1307
1308 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1309 err = snd_create_std_mono_ctl(mixer, id, control,
1310 cmask, val_type, name,
1311 &snd_usb_mixer_vol_tlv);
1312 if (err < 0)
1313 return err;
1314 }
1315
1316 return 0;
1317}
1318
1319static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1320{
1321 char name[64];
1322 unsigned int cmask;
1323 int chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001324 int num_outs = 0;
1325 int offset = 0;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001326
1327 const unsigned int id = 0x40;
1328 const int val_type = USB_MIXER_S16;
1329 const int control = 1;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001330
Matt Gruskine9a25e02013-02-09 12:56:35 -05001331 switch (mixer->chip->usb_id) {
1332 case USB_ID(0x0763, 0x2030):
1333 num_outs = 6;
1334 offset = 0x3c;
1335 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1336 break;
1337 case USB_ID(0x0763, 0x2031):
1338 num_outs = 8;
1339 offset = 0x70;
1340 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1341 break;
1342 }
1343
1344 for (chan = 0; chan < num_outs; chan++) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001345 snprintf(name, sizeof(name),
1346 "Effect Return %d",
1347 chan + 1);
1348
Matt Gruskine9a25e02013-02-09 12:56:35 -05001349 cmask = (chan == 0) ? 0 :
1350 1 << (chan + (chan % 2) * num_outs - 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001351 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1352 cmask, val_type, offset, name,
1353 &snd_usb_mixer_vol_tlv);
1354 if (err < 0)
1355 return err;
1356 }
1357
1358 return 0;
1359}
1360
1361static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1362{
1363 int err;
1364
1365 err = snd_c400_create_vol_ctls(mixer);
1366 if (err < 0)
1367 return err;
1368
1369 err = snd_c400_create_effect_vol_ctls(mixer);
1370 if (err < 0)
1371 return err;
1372
1373 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1374 if (err < 0)
1375 return err;
1376
1377 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1378 if (err < 0)
1379 return err;
1380
1381 err = snd_c400_create_effect_volume_ctl(mixer);
1382 if (err < 0)
1383 return err;
1384
1385 err = snd_c400_create_effect_duration_ctl(mixer);
1386 if (err < 0)
1387 return err;
1388
1389 err = snd_c400_create_effect_feedback_ctl(mixer);
1390 if (err < 0)
1391 return err;
1392
1393 return 0;
1394}
1395
Mark Hillsb71dad182012-06-09 13:16:38 +01001396/*
1397 * The mixer units for Ebox-44 are corrupt, and even where they
1398 * are valid they presents mono controls as L and R channels of
1399 * stereo. So we provide a good mixer here.
1400 */
Sachin Kamate8e7da22013-01-10 11:19:14 +05301401static struct std_mono_table ebox44_table[] = {
Mark Hills989b0132012-06-09 13:16:39 +01001402 {
1403 .unitid = 4,
1404 .control = 1,
1405 .cmask = 0x0,
1406 .val_type = USB_MIXER_INV_BOOLEAN,
1407 .name = "Headphone Playback Switch"
1408 },
1409 {
1410 .unitid = 4,
1411 .control = 2,
1412 .cmask = 0x1,
1413 .val_type = USB_MIXER_S16,
1414 .name = "Headphone A Mix Playback Volume"
1415 },
1416 {
1417 .unitid = 4,
1418 .control = 2,
1419 .cmask = 0x2,
1420 .val_type = USB_MIXER_S16,
1421 .name = "Headphone B Mix Playback Volume"
1422 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001423
Mark Hills989b0132012-06-09 13:16:39 +01001424 {
1425 .unitid = 7,
1426 .control = 1,
1427 .cmask = 0x0,
1428 .val_type = USB_MIXER_INV_BOOLEAN,
1429 .name = "Output Playback Switch"
1430 },
1431 {
1432 .unitid = 7,
1433 .control = 2,
1434 .cmask = 0x1,
1435 .val_type = USB_MIXER_S16,
1436 .name = "Output A Playback Volume"
1437 },
1438 {
1439 .unitid = 7,
1440 .control = 2,
1441 .cmask = 0x2,
1442 .val_type = USB_MIXER_S16,
1443 .name = "Output B Playback Volume"
1444 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001445
Mark Hills989b0132012-06-09 13:16:39 +01001446 {
1447 .unitid = 10,
1448 .control = 1,
1449 .cmask = 0x0,
1450 .val_type = USB_MIXER_INV_BOOLEAN,
1451 .name = "Input Capture Switch"
1452 },
1453 {
1454 .unitid = 10,
1455 .control = 2,
1456 .cmask = 0x1,
1457 .val_type = USB_MIXER_S16,
1458 .name = "Input A Capture Volume"
1459 },
1460 {
1461 .unitid = 10,
1462 .control = 2,
1463 .cmask = 0x2,
1464 .val_type = USB_MIXER_S16,
1465 .name = "Input B Capture Volume"
1466 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001467
Mark Hills989b0132012-06-09 13:16:39 +01001468 {}
Mark Hillsb71dad182012-06-09 13:16:38 +01001469};
1470
Przemek Rudy066624c2013-06-27 23:52:33 +02001471/* Audio Advantage Micro II findings:
1472 *
1473 * Mapping spdif AES bits to vendor register.bit:
1474 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1475 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1476 * AES2: [0 0 0 0 0 0 0 0]
1477 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1478 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1479 *
1480 * power on values:
1481 * r2: 0x10
1482 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1483 * just after it to 0xa0, presumably it disables/mutes some analog
1484 * parts when there is no audio.)
1485 * r9: 0x28
1486 *
1487 * Optical transmitter on/off:
1488 * vendor register.bit: 9.1
1489 * 0 - on (0x28 register value)
1490 * 1 - off (0x2a register value)
1491 *
1492 */
1493static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1494 struct snd_ctl_elem_info *uinfo)
1495{
1496 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1497 uinfo->count = 1;
1498 return 0;
1499}
1500
1501static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1502 struct snd_ctl_elem_value *ucontrol)
1503{
Takashi Iwai288673b2014-11-18 18:06:17 +01001504 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1505 struct snd_usb_audio *chip = list->mixer->chip;
Przemek Rudy066624c2013-06-27 23:52:33 +02001506 int err;
1507 struct usb_interface *iface;
1508 struct usb_host_interface *alts;
1509 unsigned int ep;
1510 unsigned char data[3];
1511 int rate;
1512
Takashi Iwai47ab1542015-08-25 16:09:00 +02001513 err = snd_usb_lock_shutdown(chip);
1514 if (err < 0)
1515 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001516
Przemek Rudy066624c2013-06-27 23:52:33 +02001517 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1518 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1519 ucontrol->value.iec958.status[2] = 0x00;
1520
1521 /* use known values for that card: interface#1 altsetting#1 */
Takashi Iwai288673b2014-11-18 18:06:17 +01001522 iface = usb_ifnum_to_if(chip->dev, 1);
Takashi Iwai447d6272016-03-15 15:20:58 +01001523 if (!iface || iface->num_altsetting < 2)
1524 return -EINVAL;
Przemek Rudy066624c2013-06-27 23:52:33 +02001525 alts = &iface->altsetting[1];
Takashi Iwai447d6272016-03-15 15:20:58 +01001526 if (get_iface_desc(alts)->bNumEndpoints < 1)
1527 return -EINVAL;
Przemek Rudy066624c2013-06-27 23:52:33 +02001528 ep = get_endpoint(alts, 0)->bEndpointAddress;
1529
Takashi Iwai288673b2014-11-18 18:06:17 +01001530 err = snd_usb_ctl_msg(chip->dev,
1531 usb_rcvctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001532 UAC_GET_CUR,
1533 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1534 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1535 ep,
1536 data,
1537 sizeof(data));
1538 if (err < 0)
1539 goto end;
1540
1541 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1542 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1543 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1544
1545 err = 0;
Takashi Iwai288673b2014-11-18 18:06:17 +01001546 end:
Takashi Iwai47ab1542015-08-25 16:09:00 +02001547 snd_usb_unlock_shutdown(chip);
Przemek Rudy066624c2013-06-27 23:52:33 +02001548 return err;
1549}
1550
Takashi Iwai288673b2014-11-18 18:06:17 +01001551static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
Przemek Rudy066624c2013-06-27 23:52:33 +02001552{
Takashi Iwai288673b2014-11-18 18:06:17 +01001553 struct snd_usb_audio *chip = list->mixer->chip;
1554 unsigned int pval = list->kctl->private_value;
Przemek Rudy066624c2013-06-27 23:52:33 +02001555 u8 reg;
Takashi Iwai288673b2014-11-18 18:06:17 +01001556 int err;
Przemek Rudy066624c2013-06-27 23:52:33 +02001557
Takashi Iwai47ab1542015-08-25 16:09:00 +02001558 err = snd_usb_lock_shutdown(chip);
1559 if (err < 0)
1560 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001561
1562 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1563 err = snd_usb_ctl_msg(chip->dev,
1564 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001565 UAC_SET_CUR,
1566 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1567 reg,
1568 2,
1569 NULL,
1570 0);
1571 if (err < 0)
1572 goto end;
1573
Takashi Iwai288673b2014-11-18 18:06:17 +01001574 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1575 reg |= (pval >> 12) & 0x0f;
1576 err = snd_usb_ctl_msg(chip->dev,
1577 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001578 UAC_SET_CUR,
1579 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1580 reg,
1581 3,
1582 NULL,
1583 0);
1584 if (err < 0)
1585 goto end;
1586
Takashi Iwai288673b2014-11-18 18:06:17 +01001587 end:
Takashi Iwai47ab1542015-08-25 16:09:00 +02001588 snd_usb_unlock_shutdown(chip);
Takashi Iwai288673b2014-11-18 18:06:17 +01001589 return err;
1590}
1591
1592static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1596 unsigned int pval, pval_old;
1597 int err;
1598
1599 pval = pval_old = kcontrol->private_value;
1600 pval &= 0xfffff0f0;
1601 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1602 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1603
1604 pval &= 0xffff0fff;
1605 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
Przemek Rudy066624c2013-06-27 23:52:33 +02001606
1607 /* The frequency bits in AES3 cannot be set via register access. */
1608
1609 /* Silently ignore any bits from the request that cannot be set. */
1610
Takashi Iwai288673b2014-11-18 18:06:17 +01001611 if (pval == pval_old)
1612 return 0;
1613
1614 kcontrol->private_value = pval;
1615 err = snd_microii_spdif_default_update(list);
1616 return err < 0 ? err : 1;
Przemek Rudy066624c2013-06-27 23:52:33 +02001617}
1618
1619static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1621{
1622 ucontrol->value.iec958.status[0] = 0x0f;
1623 ucontrol->value.iec958.status[1] = 0xff;
1624 ucontrol->value.iec958.status[2] = 0x00;
1625 ucontrol->value.iec958.status[3] = 0x00;
1626
1627 return 0;
1628}
1629
1630static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1631 struct snd_ctl_elem_value *ucontrol)
1632{
1633 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1634
1635 return 0;
1636}
1637
Takashi Iwai288673b2014-11-18 18:06:17 +01001638static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
Przemek Rudy066624c2013-06-27 23:52:33 +02001639{
Takashi Iwai288673b2014-11-18 18:06:17 +01001640 struct snd_usb_audio *chip = list->mixer->chip;
1641 u8 reg = list->kctl->private_value;
Przemek Rudy066624c2013-06-27 23:52:33 +02001642 int err;
Przemek Rudy066624c2013-06-27 23:52:33 +02001643
Takashi Iwai47ab1542015-08-25 16:09:00 +02001644 err = snd_usb_lock_shutdown(chip);
1645 if (err < 0)
1646 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001647
1648 err = snd_usb_ctl_msg(chip->dev,
1649 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001650 UAC_SET_CUR,
1651 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1652 reg,
1653 9,
1654 NULL,
1655 0);
1656
Takashi Iwai47ab1542015-08-25 16:09:00 +02001657 snd_usb_unlock_shutdown(chip);
Przemek Rudy066624c2013-06-27 23:52:33 +02001658 return err;
1659}
1660
Takashi Iwai288673b2014-11-18 18:06:17 +01001661static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1662 struct snd_ctl_elem_value *ucontrol)
1663{
1664 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1665 u8 reg;
1666 int err;
1667
1668 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1669 if (reg != list->kctl->private_value)
1670 return 0;
1671
1672 kcontrol->private_value = reg;
1673 err = snd_microii_spdif_switch_update(list);
1674 return err < 0 ? err : 1;
1675}
1676
Przemek Rudy066624c2013-06-27 23:52:33 +02001677static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1678 {
1679 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1680 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1681 .info = snd_microii_spdif_info,
1682 .get = snd_microii_spdif_default_get,
1683 .put = snd_microii_spdif_default_put,
1684 .private_value = 0x00000100UL,/* reset value */
1685 },
1686 {
1687 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1688 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1689 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1690 .info = snd_microii_spdif_info,
1691 .get = snd_microii_spdif_mask_get,
1692 },
1693 {
1694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1695 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1696 .info = snd_ctl_boolean_mono_info,
1697 .get = snd_microii_spdif_switch_get,
1698 .put = snd_microii_spdif_switch_put,
1699 .private_value = 0x00000028UL,/* reset value */
1700 }
1701};
1702
1703static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1704{
1705 int err, i;
Takashi Iwai288673b2014-11-18 18:06:17 +01001706 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1707 snd_microii_spdif_default_update,
1708 NULL,
1709 snd_microii_spdif_switch_update
1710 };
Przemek Rudy066624c2013-06-27 23:52:33 +02001711
1712 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
Takashi Iwai288673b2014-11-18 18:06:17 +01001713 err = add_single_ctl_with_resume(mixer, 0,
1714 resume_funcs[i],
1715 &snd_microii_mixer_spdif[i],
1716 NULL);
Przemek Rudy066624c2013-06-27 23:52:33 +02001717 if (err < 0)
1718 return err;
1719 }
1720
Mikulas Patocka18e47532013-12-05 14:32:43 -05001721 return 0;
Przemek Rudy066624c2013-06-27 23:52:33 +02001722}
1723
Daniel Mack7b1eda22010-03-11 21:13:22 +01001724int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1725{
Daniel Mack3347b262011-02-11 11:34:12 +00001726 int err = 0;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001727 struct snd_info_entry *entry;
1728
1729 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
1730 return err;
1731
Daniel Mack3347b262011-02-11 11:34:12 +00001732 switch (mixer->chip->usb_id) {
Detlef Urband2bb390a2017-02-20 09:47:59 +01001733 /* Tascam US-16x08 */
1734 case USB_ID(0x0644, 0x8047):
1735 err = snd_us16x08_controls_create(mixer);
1736 break;
Daniel Mack3347b262011-02-11 11:34:12 +00001737 case USB_ID(0x041e, 0x3020):
1738 case USB_ID(0x041e, 0x3040):
1739 case USB_ID(0x041e, 0x3042):
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +02001740 case USB_ID(0x041e, 0x30df):
Daniel Mack3347b262011-02-11 11:34:12 +00001741 case USB_ID(0x041e, 0x3048):
1742 err = snd_audigy2nx_controls_create(mixer);
1743 if (err < 0)
1744 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001745 if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
1746 snd_info_set_text_ops(entry, mixer,
1747 snd_audigy2nx_proc_read);
Daniel Mack3347b262011-02-11 11:34:12 +00001748 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001749
Vasily Khoruzhick44832a72013-11-13 13:13:35 +03001750 /* EMU0204 */
1751 case USB_ID(0x041e, 0x3f19):
1752 err = snd_emu0204_controls_create(mixer);
1753 if (err < 0)
1754 break;
1755 break;
1756
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001757 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
Matt Gruskine9a25e02013-02-09 12:56:35 -05001758 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001759 err = snd_c400_create_mixer(mixer);
1760 break;
1761
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001762 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
1763 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
Felix Homanncfe8f972012-04-23 20:24:26 +02001764 err = snd_ftu_create_mixer(mixer);
Daniel Mackd5a0bf6cc2011-05-25 09:09:03 +02001765 break;
1766
Denis Washington1d31aff2012-12-11 11:38:32 +01001767 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
1768 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
1769 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
Daniel Mack7b1eda22010-03-11 21:13:22 +01001770 err = snd_xonar_u1_controls_create(mixer);
Daniel Mack3347b262011-02-11 11:34:12 +00001771 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001772
Przemek Rudy066624c2013-06-27 23:52:33 +02001773 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
1774 err = snd_microii_controls_create(mixer);
1775 break;
1776
Damien Zammitd497a822014-11-12 01:09:54 +11001777 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
1778 err = snd_mbox1_create_sync_switch(mixer);
1779 break;
1780
Daniel Mack3347b262011-02-11 11:34:12 +00001781 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
Daniel Mack54a8c502011-02-11 11:08:06 +00001782 err = snd_nativeinstruments_create_mixer(mixer,
1783 snd_nativeinstruments_ta6_mixers,
1784 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00001785 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00001786
Daniel Mack3347b262011-02-11 11:34:12 +00001787 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
Daniel Mack54a8c502011-02-11 11:08:06 +00001788 err = snd_nativeinstruments_create_mixer(mixer,
1789 snd_nativeinstruments_ta10_mixers,
1790 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00001791 break;
Mark Hills7536c302012-04-14 17:19:24 +01001792
1793 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
Mark Hillsb71dad182012-06-09 13:16:38 +01001794 /* detection is disabled in mixer_maps.c */
1795 err = snd_create_std_mono_table(mixer, ebox44_table);
Mark Hills7536c302012-04-14 17:19:24 +01001796 break;
Chris J Arges76b188c2014-11-12 12:07:02 -06001797
1798 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
1799 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
1800 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
1801 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
1802 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
1803 err = snd_scarlett_controls_create(mixer);
1804 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00001805 }
1806
Daniel Mack3347b262011-02-11 11:34:12 +00001807 return err;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001808}
1809
1810void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1811 int unitid)
1812{
1813 if (!mixer->rc_cfg)
1814 return;
1815 /* unit ids specific to Extigy/Audigy 2 NX: */
1816 switch (unitid) {
1817 case 0: /* remote control */
1818 mixer->rc_urb->dev = mixer->chip->dev;
1819 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1820 break;
1821 case 4: /* digital in jack */
1822 case 7: /* line in jacks */
1823 case 19: /* speaker out jacks */
1824 case 20: /* headphones out jack */
1825 break;
1826 /* live24ext: 4 = line-in jack */
1827 case 3: /* hp-out jack (may actuate Mute) */
1828 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1829 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1830 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1831 break;
1832 default:
Takashi Iwai0ba41d92014-02-26 13:02:17 +01001833 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
Daniel Mack7b1eda22010-03-11 21:13:22 +01001834 break;
1835 }
1836}
1837
Anssi Hannula42e31212015-12-13 20:49:58 +02001838static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03001839 struct usb_mixer_elem_info *cval,
Anssi Hannula42e31212015-12-13 20:49:58 +02001840 struct snd_kcontrol *kctl)
1841{
1842 /* Approximation using 10 ranges based on output measurement on hw v1.2.
1843 * This seems close to the cubic mapping e.g. alsamixer uses. */
1844 static const DECLARE_TLV_DB_RANGE(scale,
1845 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
1846 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
1847 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
1848 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
1849 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
1850 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
1851 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
1852 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
1853 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
1854 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
1855 );
1856
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03001857 if (cval->min == 0 && cval->max == 50) {
1858 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
1859 kctl->tlv.p = scale;
1860 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1861 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1862
1863 } else if (cval->min == 0 && cval->max <= 1000) {
1864 /* Some other clearly broken DragonFly variant.
1865 * At least a 0..53 variant (hw v1.0) exists.
1866 */
1867 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
1868 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1869 }
Anssi Hannula42e31212015-12-13 20:49:58 +02001870}
1871
1872void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
1873 struct usb_mixer_elem_info *cval, int unitid,
1874 struct snd_kcontrol *kctl)
1875{
1876 switch (mixer->chip->usb_id) {
1877 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03001878 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
1879 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
Anssi Hannula42e31212015-12-13 20:49:58 +02001880 break;
Takashi Iwai0f174b32017-08-16 14:18:37 +02001881 /* lowest playback value is muted on C-Media devices */
1882 case USB_ID(0x0d8c, 0x000c):
1883 case USB_ID(0x0d8c, 0x0014):
1884 if (strstr(kctl->id.name, "Playback"))
1885 cval->min_mute = 1;
1886 break;
Anssi Hannula42e31212015-12-13 20:49:58 +02001887 }
1888}
1889