blob: e447ddd6854cdb304236d8c8369c624a320f4a21 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Daniel Mack7b1eda22010-03-11 21:13:22 +01002/*
3 * USB Audio Driver for ALSA
4 *
5 * Quirks and vendor-specific extensions for mixer interfaces
6 *
7 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 *
9 * Many codes borrowed from audio.c by
10 * Alan Cox (alan@lxorguk.ukuu.org.uk)
11 * Thomas Sailer (sailer@ife.ee.ethz.ch)
12 *
Przemek Rudy066624c2013-06-27 23:52:33 +020013 * Audio Advantage Micro II support added by:
14 * Przemek Rudy (prudy1@o2.pl)
Daniel Mack7b1eda22010-03-11 21:13:22 +010015 */
16
Ian Douglas Scott388fdb82018-01-16 15:34:50 -080017#include <linux/hid.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010018#include <linux/init.h>
Jussi Laakod39f1d62018-10-05 11:00:04 +030019#include <linux/math64.h>
Stephen Rothwell36db0452010-03-29 16:02:50 +110020#include <linux/slab.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010021#include <linux/usb.h>
22#include <linux/usb/audio.h>
23
Przemek Rudy066624c2013-06-27 23:52:33 +020024#include <sound/asoundef.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010025#include <sound/core.h>
26#include <sound/control.h>
27#include <sound/hwdep.h>
28#include <sound/info.h>
Anssi Hannula42e31212015-12-13 20:49:58 +020029#include <sound/tlv.h>
Daniel Mack7b1eda22010-03-11 21:13:22 +010030
31#include "usbaudio.h"
Daniel Mackf0b5e632010-03-11 21:13:23 +010032#include "mixer.h"
Daniel Mack7b1eda22010-03-11 21:13:22 +010033#include "mixer_quirks.h"
Chris J Arges76b188c2014-11-12 12:07:02 -060034#include "mixer_scarlett.h"
Geoffrey D. Bennett9e4d5c12019-07-29 00:42:45 +093035#include "mixer_scarlett_gen2.h"
Detlef Urband2bb390a2017-02-20 09:47:59 +010036#include "mixer_us16x08.h"
Nick Kossifidis8dc5efe2020-02-15 03:23:35 +020037#include "mixer_s1810c.h"
Daniel Mack7b1eda22010-03-11 21:13:22 +010038#include "helper.h"
39
Mark Hillsb71dad182012-06-09 13:16:38 +010040struct std_mono_table {
41 unsigned int unitid, control, cmask;
42 int val_type;
43 const char *name;
44 snd_kcontrol_tlv_rw_t *tlv_callback;
45};
46
Felix Homann8a4d1d32012-04-23 20:24:23 +020047/* This function allows for the creation of standard UAC controls.
48 * See the quirks for M-Audio FTUs or Ebox-44.
49 * If you don't want to set a TLV callback pass NULL.
50 *
51 * Since there doesn't seem to be a devices that needs a multichannel
52 * version, we keep it mono for simplicity.
53 */
Eldad Zack9f814102012-11-28 23:55:35 +010054static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
Felix Homann8a4d1d32012-04-23 20:24:23 +020055 unsigned int unitid,
56 unsigned int control,
57 unsigned int cmask,
58 int val_type,
Eldad Zack9f814102012-11-28 23:55:35 +010059 unsigned int idx_off,
Felix Homann8a4d1d32012-04-23 20:24:23 +020060 const char *name,
61 snd_kcontrol_tlv_rw_t *tlv_callback)
62{
Felix Homann8a4d1d32012-04-23 20:24:23 +020063 struct usb_mixer_elem_info *cval;
64 struct snd_kcontrol *kctl;
65
66 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
67 if (!cval)
68 return -ENOMEM;
69
Takashi Iwai3360b842014-11-18 11:47:04 +010070 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
Felix Homann8a4d1d32012-04-23 20:24:23 +020071 cval->val_type = val_type;
72 cval->channels = 1;
73 cval->control = control;
74 cval->cmask = cmask;
Eldad Zack9f814102012-11-28 23:55:35 +010075 cval->idx_off = idx_off;
Felix Homann8a4d1d32012-04-23 20:24:23 +020076
Mark Hills7df4a692012-05-11 18:31:55 +010077 /* get_min_max() is called only for integer volumes later,
78 * so provide a short-cut for booleans */
Felix Homann8a4d1d32012-04-23 20:24:23 +020079 cval->min = 0;
80 cval->max = 1;
81 cval->res = 0;
82 cval->dBmin = 0;
83 cval->dBmax = 0;
84
85 /* Create control */
86 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
87 if (!kctl) {
88 kfree(cval);
89 return -ENOMEM;
90 }
91
92 /* Set name */
93 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
Chris J Argeseef90452014-11-12 12:07:01 -060094 kctl->private_free = snd_usb_mixer_elem_free;
Felix Homann8a4d1d32012-04-23 20:24:23 +020095
96 /* set TLV */
97 if (tlv_callback) {
98 kctl->tlv.c = tlv_callback;
99 kctl->vd[0].access |=
100 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
101 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
102 }
103 /* Add control to mixer */
Takashi Iwai3360b842014-11-18 11:47:04 +0100104 return snd_usb_mixer_add_control(&cval->head, kctl);
Felix Homann8a4d1d32012-04-23 20:24:23 +0200105}
106
Eldad Zack9f814102012-11-28 23:55:35 +0100107static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
108 unsigned int unitid,
109 unsigned int control,
110 unsigned int cmask,
111 int val_type,
112 const char *name,
113 snd_kcontrol_tlv_rw_t *tlv_callback)
114{
115 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
116 val_type, 0 /* Offset */, name, tlv_callback);
117}
118
Daniel Mack7b1eda22010-03-11 21:13:22 +0100119/*
Mark Hillsb71dad182012-06-09 13:16:38 +0100120 * Create a set of standard UAC controls from a table
121 */
122static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
Takashi Iwaia01df922020-01-05 15:47:26 +0100123 const struct std_mono_table *t)
Mark Hillsb71dad182012-06-09 13:16:38 +0100124{
125 int err;
126
127 while (t->name != NULL) {
128 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
129 t->cmask, t->val_type, t->name, t->tlv_callback);
130 if (err < 0)
131 return err;
132 t++;
133 }
134
135 return 0;
136}
137
Takashi Iwai9cf36892014-11-18 12:58:51 +0100138static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
139 int id,
140 usb_mixer_elem_resume_func_t resume,
141 const struct snd_kcontrol_new *knew,
142 struct usb_mixer_elem_list **listp)
143{
144 struct usb_mixer_elem_list *list;
145 struct snd_kcontrol *kctl;
146
147 list = kzalloc(sizeof(*list), GFP_KERNEL);
148 if (!list)
149 return -ENOMEM;
150 if (listp)
151 *listp = list;
152 list->mixer = mixer;
153 list->id = id;
Takashi Iwai7b9cf902021-09-10 12:51:55 +0200154 list->resume = resume;
Takashi Iwai9cf36892014-11-18 12:58:51 +0100155 kctl = snd_ctl_new1(knew, list);
156 if (!kctl) {
157 kfree(list);
158 return -ENOMEM;
159 }
160 kctl->private_free = snd_usb_mixer_elem_free;
Takashi Iwai220345e2020-06-24 14:23:40 +0200161 /* don't use snd_usb_mixer_add_control() here, this is a special list element */
162 return snd_usb_mixer_add_list(list, kctl, false);
Takashi Iwai9cf36892014-11-18 12:58:51 +0100163}
164
Mark Hillsb71dad182012-06-09 13:16:38 +0100165/*
Daniel Mack7b1eda22010-03-11 21:13:22 +0100166 * Sound Blaster remote control configuration
167 *
168 * format of remote control data:
169 * Extigy: xx 00
170 * Audigy 2 NX: 06 80 xx 00 00 00
171 * Live! 24-bit: 06 80 xx yy 22 83
172 */
173static const struct rc_config {
174 u32 usb_id;
175 u8 offset;
176 u8 length;
177 u8 packet_length;
178 u8 min_packet_length; /* minimum accepted length of the URB result */
179 u8 mute_mixer_id;
180 u32 mute_code;
181} rc_configs[] = {
182 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
183 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
184 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
Mandar Joshica8dc342010-11-02 14:43:19 +0000185 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200186 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Dmitry M. Fedin3dc85232015-04-09 17:37:03 +0300187 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Mirko Dietrichfec90082020-08-06 14:48:50 +0200188 { USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
Daniel Mack7b1eda22010-03-11 21:13:22 +0100189 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
190};
191
192static void snd_usb_soundblaster_remote_complete(struct urb *urb)
193{
194 struct usb_mixer_interface *mixer = urb->context;
195 const struct rc_config *rc = mixer->rc_cfg;
196 u32 code;
197
198 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
199 return;
200
201 code = mixer->rc_buffer[rc->offset];
202 if (rc->length == 2)
203 code |= mixer->rc_buffer[rc->offset + 1] << 8;
204
205 /* the Mute button actually changes the mixer control */
206 if (code == rc->mute_code)
207 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
208 mixer->rc_code = code;
209 wmb();
210 wake_up(&mixer->rc_waitq);
211}
212
213static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
214 long count, loff_t *offset)
215{
216 struct usb_mixer_interface *mixer = hw->private_data;
217 int err;
218 u32 rc_code;
219
220 if (count != 1 && count != 4)
221 return -EINVAL;
222 err = wait_event_interruptible(mixer->rc_waitq,
223 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
224 if (err == 0) {
225 if (count == 1)
226 err = put_user(rc_code, buf);
227 else
228 err = put_user(rc_code, (u32 __user *)buf);
229 }
230 return err < 0 ? err : count;
231}
232
Al Viro680ef722017-07-02 23:27:36 -0400233static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100234 poll_table *wait)
235{
236 struct usb_mixer_interface *mixer = hw->private_data;
237
238 poll_wait(file, &mixer->rc_waitq, wait);
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800239 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100240}
241
242static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
243{
244 struct snd_hwdep *hwdep;
245 int err, len, i;
246
247 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
248 if (rc_configs[i].usb_id == mixer->chip->usb_id)
249 break;
250 if (i >= ARRAY_SIZE(rc_configs))
251 return 0;
252 mixer->rc_cfg = &rc_configs[i];
253
254 len = mixer->rc_cfg->packet_length;
255
256 init_waitqueue_head(&mixer->rc_waitq);
257 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
258 if (err < 0)
259 return err;
260 snprintf(hwdep->name, sizeof(hwdep->name),
261 "%s remote control", mixer->chip->card->shortname);
262 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
263 hwdep->private_data = mixer;
264 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
265 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
266 hwdep->exclusive = 1;
267
268 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
269 if (!mixer->rc_urb)
270 return -ENOMEM;
271 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
272 if (!mixer->rc_setup_packet) {
273 usb_free_urb(mixer->rc_urb);
274 mixer->rc_urb = NULL;
275 return -ENOMEM;
276 }
277 mixer->rc_setup_packet->bRequestType =
278 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
279 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
280 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
281 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
282 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
283 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
284 usb_rcvctrlpipe(mixer->chip->dev, 0),
285 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
286 snd_usb_soundblaster_remote_complete, mixer);
287 return 0;
288}
289
290#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
291
292static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
293{
Takashi Iwai9cf36892014-11-18 12:58:51 +0100294 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100295 return 0;
296}
297
Takashi Iwai9cf36892014-11-18 12:58:51 +0100298static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
299 int value, int index)
Daniel Mack7b1eda22010-03-11 21:13:22 +0100300{
Takashi Iwai9cf36892014-11-18 12:58:51 +0100301 struct snd_usb_audio *chip = mixer->chip;
302 int err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100303
Takashi Iwai47ab1542015-08-25 16:09:00 +0200304 err = snd_usb_lock_shutdown(chip);
305 if (err < 0)
306 return err;
307
Takashi Iwai9cf36892014-11-18 12:58:51 +0100308 if (chip->usb_id == USB_ID(0x041e, 0x3042))
309 err = snd_usb_ctl_msg(chip->dev,
310 usb_sndctrlpipe(chip->dev, 0), 0x24,
Mandar Joshica8dc342010-11-02 14:43:19 +0000311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200312 !value, 0, NULL, 0);
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200313 /* USB X-Fi S51 Pro */
Takashi Iwai9cf36892014-11-18 12:58:51 +0100314 if (chip->usb_id == USB_ID(0x041e, 0x30df))
315 err = snd_usb_ctl_msg(chip->dev,
316 usb_sndctrlpipe(chip->dev, 0), 0x24,
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200317 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200318 !value, 0, NULL, 0);
Mandar Joshica8dc342010-11-02 14:43:19 +0000319 else
Takashi Iwai9cf36892014-11-18 12:58:51 +0100320 err = snd_usb_ctl_msg(chip->dev,
321 usb_sndctrlpipe(chip->dev, 0), 0x24,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100322 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200323 value, index + 2, NULL, 0);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200324 snd_usb_unlock_shutdown(chip);
Takashi Iwai9cf36892014-11-18 12:58:51 +0100325 return err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100326}
327
Takashi Iwai9cf36892014-11-18 12:58:51 +0100328static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
330{
331 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
332 struct usb_mixer_interface *mixer = list->mixer;
333 int index = kcontrol->private_value & 0xff;
Dan Carpentere87359e2015-09-28 13:06:20 +0300334 unsigned int value = ucontrol->value.integer.value[0];
Takashi Iwai9cf36892014-11-18 12:58:51 +0100335 int old_value = kcontrol->private_value >> 8;
336 int err;
337
338 if (value > 1)
339 return -EINVAL;
340 if (value == old_value)
341 return 0;
342 kcontrol->private_value = (value << 8) | index;
343 err = snd_audigy2nx_led_update(mixer, value, index);
344 return err < 0 ? err : 1;
345}
346
347static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
348{
349 int priv_value = list->kctl->private_value;
350
351 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
352 priv_value & 0xff);
353}
354
355/* name and private_value are set dynamically */
Bhumika Goyal905e46a2017-05-27 20:16:15 +0530356static const struct snd_kcontrol_new snd_audigy2nx_control = {
Takashi Iwai9cf36892014-11-18 12:58:51 +0100357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .info = snd_audigy2nx_led_info,
359 .get = snd_audigy2nx_led_get,
360 .put = snd_audigy2nx_led_put,
361};
362
363static const char * const snd_audigy2nx_led_names[] = {
364 "CMSS LED Switch",
365 "Power LED Switch",
366 "Dolby Digital LED Switch",
Daniel Mack7b1eda22010-03-11 21:13:22 +0100367};
368
369static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
370{
371 int i, err;
372
Takashi Iwai9cf36892014-11-18 12:58:51 +0100373 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
374 struct snd_kcontrol_new knew;
375
Mandar Joshica8dc342010-11-02 14:43:19 +0000376 /* USB X-Fi S51 doesn't have a CMSS LED */
377 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
378 continue;
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200379 /* USB X-Fi S51 Pro doesn't have one either */
380 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
381 continue;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100382 if (i > 1 && /* Live24ext has 2 LEDs only */
383 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
Mandar Joshica8dc342010-11-02 14:43:19 +0000384 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +0200385 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
Daniel Mack7b1eda22010-03-11 21:13:22 +0100386 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
387 break;
Takashi Iwai9cf36892014-11-18 12:58:51 +0100388
389 knew = snd_audigy2nx_control;
390 knew.name = snd_audigy2nx_led_names[i];
391 knew.private_value = (1 << 8) | i; /* LED on as default */
392 err = add_single_ctl_with_resume(mixer, 0,
393 snd_audigy2nx_led_resume,
394 &knew, NULL);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100395 if (err < 0)
396 return err;
397 }
Daniel Mack7b1eda22010-03-11 21:13:22 +0100398 return 0;
399}
400
401static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
402 struct snd_info_buffer *buffer)
403{
404 static const struct sb_jack {
405 int unitid;
406 const char *name;
407 } jacks_audigy2nx[] = {
408 {4, "dig in "},
409 {7, "line in"},
410 {19, "spk out"},
411 {20, "hph out"},
412 {-1, NULL}
413 }, jacks_live24ext[] = {
414 {4, "line in"}, /* &1=Line, &2=Mic*/
415 {3, "hph out"}, /* headphones */
416 {0, "RC "}, /* last command, 6 bytes see rc_config above */
417 {-1, NULL}
418 };
419 const struct sb_jack *jacks;
420 struct usb_mixer_interface *mixer = entry->private_data;
421 int i, err;
422 u8 buf[3];
423
424 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
425 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
426 jacks = jacks_audigy2nx;
427 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
428 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
429 jacks = jacks_live24ext;
430 else
431 return;
432
433 for (i = 0; jacks[i].name; ++i) {
434 snd_iprintf(buffer, "%s: ", jacks[i].name);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200435 err = snd_usb_lock_shutdown(mixer->chip);
436 if (err < 0)
437 return;
438 err = snd_usb_ctl_msg(mixer->chip->dev,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100439 usb_rcvctrlpipe(mixer->chip->dev, 0),
440 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
441 USB_RECIP_INTERFACE, 0,
Clemens Ladisch17d900c2011-09-26 21:15:27 +0200442 jacks[i].unitid << 8, buf, 3);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200443 snd_usb_unlock_shutdown(mixer->chip);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100444 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
445 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
446 else
447 snd_iprintf(buffer, "?\n");
448 }
449}
450
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300451/* EMU0204 */
452static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
453 struct snd_ctl_elem_info *uinfo)
454{
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200455 static const char * const texts[2] = {"1/2", "3/4"};
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300456
Takashi Iwai7bbd03e2014-10-20 18:21:42 +0200457 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300458}
459
460static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
462{
463 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
464 return 0;
465}
466
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100467static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
468 int value)
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300469{
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100470 struct snd_usb_audio *chip = mixer->chip;
471 int err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300472 unsigned char buf[2];
473
Takashi Iwai47ab1542015-08-25 16:09:00 +0200474 err = snd_usb_lock_shutdown(chip);
475 if (err < 0)
476 return err;
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100477
478 buf[0] = 0x01;
479 buf[1] = value ? 0x02 : 0x01;
480 err = snd_usb_ctl_msg(chip->dev,
481 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300482 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
483 0x0400, 0x0e00, buf, 2);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200484 snd_usb_unlock_shutdown(chip);
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100485 return err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300486}
487
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100488static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
489 struct snd_ctl_elem_value *ucontrol)
490{
491 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
492 struct usb_mixer_interface *mixer = list->mixer;
493 unsigned int value = ucontrol->value.enumerated.item[0];
494 int err;
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300495
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100496 if (value > 1)
497 return -EINVAL;
498
499 if (value == kcontrol->private_value)
500 return 0;
501
502 kcontrol->private_value = value;
503 err = snd_emu0204_ch_switch_update(mixer, value);
504 return err < 0 ? err : 1;
505}
506
507static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
508{
509 return snd_emu0204_ch_switch_update(list->mixer,
510 list->kctl->private_value);
511}
512
Takashi Iwai195727e2020-01-03 09:16:57 +0100513static const struct snd_kcontrol_new snd_emu0204_control = {
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
515 .name = "Front Jack Channels",
516 .info = snd_emu0204_ch_switch_info,
517 .get = snd_emu0204_ch_switch_get,
518 .put = snd_emu0204_ch_switch_put,
519 .private_value = 0,
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300520};
521
522static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
523{
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100524 return add_single_ctl_with_resume(mixer, 0,
525 snd_emu0204_ch_switch_resume,
526 &snd_emu0204_control, NULL);
Vasily Khoruzhick44832a72013-11-13 13:13:35 +0300527}
Takashi Iwai5f503ee2014-11-18 16:11:37 +0100528
Denis Washington1d31aff2012-12-11 11:38:32 +0100529/* ASUS Xonar U1 / U3 controls */
530
Daniel Mack7b1eda22010-03-11 21:13:22 +0100531static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
533{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100534 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100535 return 0;
536}
537
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100538static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
539 unsigned char status)
540{
541 struct snd_usb_audio *chip = mixer->chip;
542 int err;
543
Takashi Iwai47ab1542015-08-25 16:09:00 +0200544 err = snd_usb_lock_shutdown(chip);
545 if (err < 0)
546 return err;
547 err = snd_usb_ctl_msg(chip->dev,
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100548 usb_sndctrlpipe(chip->dev, 0), 0x08,
549 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
550 50, 0, &status, 1);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200551 snd_usb_unlock_shutdown(chip);
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100552 return err;
553}
554
Daniel Mack7b1eda22010-03-11 21:13:22 +0100555static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
556 struct snd_ctl_elem_value *ucontrol)
557{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100558 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100559 u8 old_status, new_status;
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100560 int err;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100561
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100562 old_status = kcontrol->private_value;
Daniel Mack7b1eda22010-03-11 21:13:22 +0100563 if (ucontrol->value.integer.value[0])
564 new_status = old_status | 0x02;
565 else
566 new_status = old_status & ~0x02;
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100567 if (new_status == old_status)
568 return 0;
569
570 kcontrol->private_value = new_status;
571 err = snd_xonar_u1_switch_update(list->mixer, new_status);
572 return err < 0 ? err : 1;
573}
574
575static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
576{
577 return snd_xonar_u1_switch_update(list->mixer,
578 list->kctl->private_value);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100579}
580
Takashi Iwai195727e2020-01-03 09:16:57 +0100581static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
Daniel Mack7b1eda22010-03-11 21:13:22 +0100582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
583 .name = "Digital Playback Switch",
584 .info = snd_ctl_boolean_mono_info,
585 .get = snd_xonar_u1_switch_get,
586 .put = snd_xonar_u1_switch_put,
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100587 .private_value = 0x05,
Daniel Mack7b1eda22010-03-11 21:13:22 +0100588};
589
590static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
591{
Takashi Iwai2bfb14c2014-11-18 16:18:15 +0100592 return add_single_ctl_with_resume(mixer, 0,
593 snd_xonar_u1_switch_resume,
594 &snd_xonar_u1_output_switch, NULL);
Daniel Mack7b1eda22010-03-11 21:13:22 +0100595}
596
Damien Zammit7ac22462021-08-13 21:34:02 +1000597/* Digidesign Mbox 1 helper functions */
Damien Zammitd497a822014-11-12 01:09:54 +1100598
Damien Zammit7ac22462021-08-13 21:34:02 +1000599static int snd_mbox1_is_spdif_synced(struct snd_usb_audio *chip)
Damien Zammitd497a822014-11-12 01:09:54 +1100600{
Damien Zammitd497a822014-11-12 01:09:54 +1100601 unsigned char buff[3];
Damien Zammit7ac22462021-08-13 21:34:02 +1000602 int err;
603 int is_spdif_synced;
Damien Zammitd497a822014-11-12 01:09:54 +1100604
Damien Zammit7ac22462021-08-13 21:34:02 +1000605 /* Read clock source */
606 err = snd_usb_ctl_msg(chip->dev,
607 usb_rcvctrlpipe(chip->dev, 0), 0x81,
608 USB_DIR_IN |
609 USB_TYPE_CLASS |
610 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
Takashi Iwai47ab1542015-08-25 16:09:00 +0200611 if (err < 0)
612 return err;
Damien Zammitd497a822014-11-12 01:09:54 +1100613
Damien Zammit7ac22462021-08-13 21:34:02 +1000614 /* spdif sync: buff is all zeroes */
615 is_spdif_synced = !(buff[0] | buff[1] | buff[2]);
616 return is_spdif_synced;
617}
Damien Zammitd497a822014-11-12 01:09:54 +1100618
Damien Zammit7ac22462021-08-13 21:34:02 +1000619static int snd_mbox1_set_clk_source(struct snd_usb_audio *chip, int rate_or_zero)
620{
621 /* 2 possibilities: Internal -> expects sample rate
622 * S/PDIF sync -> expects rate = 0
Damien Zammitd497a822014-11-12 01:09:54 +1100623 */
Damien Zammit7ac22462021-08-13 21:34:02 +1000624 unsigned char buff[3];
Damien Zammitd497a822014-11-12 01:09:54 +1100625
Damien Zammit7ac22462021-08-13 21:34:02 +1000626 buff[0] = (rate_or_zero >> 0) & 0xff;
627 buff[1] = (rate_or_zero >> 8) & 0xff;
628 buff[2] = (rate_or_zero >> 16) & 0xff;
629
630 /* Set clock source */
631 return snd_usb_ctl_msg(chip->dev,
632 usb_sndctrlpipe(chip->dev, 0), 0x1,
633 USB_TYPE_CLASS |
634 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
635}
636
637static int snd_mbox1_is_spdif_input(struct snd_usb_audio *chip)
638{
639 /* Hardware gives 2 possibilities: ANALOG Source -> 0x01
640 * S/PDIF Source -> 0x02
641 */
642 int err;
643 unsigned char source[1];
644
645 /* Read input source */
Damien Zammitd497a822014-11-12 01:09:54 +1100646 err = snd_usb_ctl_msg(chip->dev,
Damien Zammit7ac22462021-08-13 21:34:02 +1000647 usb_rcvctrlpipe(chip->dev, 0), 0x81,
648 USB_DIR_IN |
649 USB_TYPE_CLASS |
650 USB_RECIP_INTERFACE, 0x00, 0x500, source, 1);
Damien Zammitd497a822014-11-12 01:09:54 +1100651 if (err < 0)
Damien Zammit7ac22462021-08-13 21:34:02 +1000652 return err;
653
654 return (source[0] == 2);
655}
656
657static int snd_mbox1_set_input_source(struct snd_usb_audio *chip, int is_spdif)
658{
659 /* NB: Setting the input source to S/PDIF resets the clock source to S/PDIF
660 * Hardware expects 2 possibilities: ANALOG Source -> 0x01
661 * S/PDIF Source -> 0x02
662 */
663 unsigned char buff[1];
664
665 buff[0] = (is_spdif & 1) + 1;
666
667 /* Set input source */
668 return snd_usb_ctl_msg(chip->dev,
669 usb_sndctrlpipe(chip->dev, 0), 0x1,
670 USB_TYPE_CLASS |
671 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
672}
673
674/* Digidesign Mbox 1 clock source switch (internal/spdif) */
675
676static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl,
677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
680 struct snd_usb_audio *chip = list->mixer->chip;
681 int err;
682
683 err = snd_usb_lock_shutdown(chip);
Damien Zammitd497a822014-11-12 01:09:54 +1100684 if (err < 0)
685 goto err;
Damien Zammitd497a822014-11-12 01:09:54 +1100686
Damien Zammit7ac22462021-08-13 21:34:02 +1000687 err = snd_mbox1_is_spdif_synced(chip);
688 if (err < 0)
689 goto err;
690
691 kctl->private_value = err;
692 err = 0;
693 ucontrol->value.enumerated.item[0] = kctl->private_value;
Damien Zammitd497a822014-11-12 01:09:54 +1100694err:
Takashi Iwai47ab1542015-08-25 16:09:00 +0200695 snd_usb_unlock_shutdown(chip);
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100696 return err;
697}
698
Damien Zammit7ac22462021-08-13 21:34:02 +1000699static int snd_mbox1_clk_switch_update(struct usb_mixer_interface *mixer, int is_spdif_sync)
700{
701 struct snd_usb_audio *chip = mixer->chip;
702 int err;
703
704 err = snd_usb_lock_shutdown(chip);
705 if (err < 0)
706 return err;
707
708 err = snd_mbox1_is_spdif_input(chip);
709 if (err < 0)
710 goto err;
711
712 err = snd_mbox1_is_spdif_synced(chip);
713 if (err < 0)
714 goto err;
715
716 /* FIXME: hardcoded sample rate */
717 err = snd_mbox1_set_clk_source(chip, is_spdif_sync ? 0 : 48000);
718 if (err < 0)
719 goto err;
720
721 err = snd_mbox1_is_spdif_synced(chip);
722err:
723 snd_usb_unlock_shutdown(chip);
724 return err;
725}
726
727static int snd_mbox1_clk_switch_put(struct snd_kcontrol *kctl,
728 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100729{
730 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
731 struct usb_mixer_interface *mixer = list->mixer;
732 int err;
733 bool cur_val, new_val;
734
735 cur_val = kctl->private_value;
736 new_val = ucontrol->value.enumerated.item[0];
737 if (cur_val == new_val)
738 return 0;
739
740 kctl->private_value = new_val;
Damien Zammit7ac22462021-08-13 21:34:02 +1000741 err = snd_mbox1_clk_switch_update(mixer, new_val);
Damien Zammitd497a822014-11-12 01:09:54 +1100742 return err < 0 ? err : 1;
743}
744
Damien Zammit7ac22462021-08-13 21:34:02 +1000745static int snd_mbox1_clk_switch_info(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_info *uinfo)
Damien Zammitd497a822014-11-12 01:09:54 +1100747{
748 static const char *const texts[2] = {
749 "Internal",
750 "S/PDIF"
751 };
752
753 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
754}
755
Damien Zammit7ac22462021-08-13 21:34:02 +1000756static int snd_mbox1_clk_switch_resume(struct usb_mixer_elem_list *list)
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100757{
Damien Zammit7ac22462021-08-13 21:34:02 +1000758 return snd_mbox1_clk_switch_update(list->mixer, list->kctl->private_value);
Takashi Iwai25a9a4f2014-11-18 16:31:35 +0100759}
760
Damien Zammit7ac22462021-08-13 21:34:02 +1000761/* Digidesign Mbox 1 input source switch (analog/spdif) */
762
763static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl,
764 struct snd_ctl_elem_value *ucontrol)
765{
766 ucontrol->value.enumerated.item[0] = kctl->private_value;
767 return 0;
768}
769
770static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int is_spdif_input)
771{
772 struct snd_usb_audio *chip = mixer->chip;
773 int err;
774
775 err = snd_usb_lock_shutdown(chip);
776 if (err < 0)
777 return err;
778
779 err = snd_mbox1_is_spdif_input(chip);
780 if (err < 0)
781 goto err;
782
783 err = snd_mbox1_set_input_source(chip, is_spdif_input);
784 if (err < 0)
785 goto err;
786
787 err = snd_mbox1_is_spdif_input(chip);
788 if (err < 0)
789 goto err;
790
791 err = snd_mbox1_is_spdif_synced(chip);
792err:
793 snd_usb_unlock_shutdown(chip);
794 return err;
795}
796
797static int snd_mbox1_src_switch_put(struct snd_kcontrol *kctl,
798 struct snd_ctl_elem_value *ucontrol)
799{
800 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
801 struct usb_mixer_interface *mixer = list->mixer;
802 int err;
803 bool cur_val, new_val;
804
805 cur_val = kctl->private_value;
806 new_val = ucontrol->value.enumerated.item[0];
807 if (cur_val == new_val)
808 return 0;
809
810 kctl->private_value = new_val;
811 err = snd_mbox1_src_switch_update(mixer, new_val);
812 return err < 0 ? err : 1;
813}
814
815static int snd_mbox1_src_switch_info(struct snd_kcontrol *kcontrol,
816 struct snd_ctl_elem_info *uinfo)
817{
818 static const char *const texts[2] = {
819 "Analog",
820 "S/PDIF"
821 };
822
823 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
824}
825
826static int snd_mbox1_src_switch_resume(struct usb_mixer_elem_list *list)
827{
828 return snd_mbox1_src_switch_update(list->mixer, list->kctl->private_value);
829}
830
831static const struct snd_kcontrol_new snd_mbox1_clk_switch = {
Damien Zammitd497a822014-11-12 01:09:54 +1100832 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
833 .name = "Clock Source",
834 .index = 0,
835 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
Damien Zammit7ac22462021-08-13 21:34:02 +1000836 .info = snd_mbox1_clk_switch_info,
837 .get = snd_mbox1_clk_switch_get,
838 .put = snd_mbox1_clk_switch_put,
Damien Zammitd497a822014-11-12 01:09:54 +1100839 .private_value = 0
840};
841
Damien Zammit7ac22462021-08-13 21:34:02 +1000842static const struct snd_kcontrol_new snd_mbox1_src_switch = {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "Input Source",
845 .index = 1,
846 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
847 .info = snd_mbox1_src_switch_info,
848 .get = snd_mbox1_src_switch_get,
849 .put = snd_mbox1_src_switch_put,
850 .private_value = 0
851};
852
853static int snd_mbox1_controls_create(struct usb_mixer_interface *mixer)
Damien Zammitd497a822014-11-12 01:09:54 +1100854{
Damien Zammit7ac22462021-08-13 21:34:02 +1000855 int err;
856 err = add_single_ctl_with_resume(mixer, 0,
857 snd_mbox1_clk_switch_resume,
858 &snd_mbox1_clk_switch, NULL);
859 if (err < 0)
860 return err;
861
862 return add_single_ctl_with_resume(mixer, 1,
863 snd_mbox1_src_switch_resume,
864 &snd_mbox1_src_switch, NULL);
Damien Zammitd497a822014-11-12 01:09:54 +1100865}
866
Daniel Mack54a8c502011-02-11 11:08:06 +0000867/* Native Instruments device quirks */
868
869#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
870
Takashi Iwaida6d2762014-11-18 16:59:47 +0100871static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
872 struct snd_kcontrol *kctl)
873{
874 struct usb_device *dev = mixer->chip->dev;
875 unsigned int pval = kctl->private_value;
876 u8 value;
877 int err;
878
879 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
880 (pval >> 16) & 0xff,
881 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
882 0, pval & 0xffff, &value, 1);
883 if (err < 0) {
884 dev_err(&dev->dev,
885 "unable to issue vendor read request (ret = %d)", err);
886 return err;
887 }
888
Colin Ian King2acf5a32019-06-27 17:43:08 +0100889 kctl->private_value |= ((unsigned int)value << 24);
Takashi Iwaida6d2762014-11-18 16:59:47 +0100890 return 0;
891}
892
Daniel Mack54a8c502011-02-11 11:08:06 +0000893static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
894 struct snd_ctl_elem_value *ucontrol)
895{
Takashi Iwaida6d2762014-11-18 16:59:47 +0100896 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
Daniel Mack54a8c502011-02-11 11:08:06 +0000897 return 0;
898}
899
Takashi Iwaida6d2762014-11-18 16:59:47 +0100900static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
901{
902 struct snd_usb_audio *chip = list->mixer->chip;
903 unsigned int pval = list->kctl->private_value;
904 int err;
905
Takashi Iwai47ab1542015-08-25 16:09:00 +0200906 err = snd_usb_lock_shutdown(chip);
907 if (err < 0)
908 return err;
909 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
910 (pval >> 16) & 0xff,
911 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
912 pval >> 24, pval & 0xffff, NULL, 0, 1000);
913 snd_usb_unlock_shutdown(chip);
Takashi Iwaida6d2762014-11-18 16:59:47 +0100914 return err;
915}
916
Daniel Mack54a8c502011-02-11 11:08:06 +0000917static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
918 struct snd_ctl_elem_value *ucontrol)
919{
Takashi Iwaida6d2762014-11-18 16:59:47 +0100920 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
921 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
922 u8 newval = ucontrol->value.integer.value[0];
923 int err;
Daniel Mack54a8c502011-02-11 11:08:06 +0000924
Takashi Iwaida6d2762014-11-18 16:59:47 +0100925 if (oldval == newval)
926 return 0;
Daniel Mack54a8c502011-02-11 11:08:06 +0000927
Takashi Iwaida6d2762014-11-18 16:59:47 +0100928 kcontrol->private_value &= ~(0xff << 24);
Takashi Iwaic4a359a2016-01-13 07:20:13 +0100929 kcontrol->private_value |= (unsigned int)newval << 24;
Takashi Iwaida6d2762014-11-18 16:59:47 +0100930 err = snd_ni_update_cur_val(list);
931 return err < 0 ? err : 1;
Daniel Mack54a8c502011-02-11 11:08:06 +0000932}
933
Takashi Iwai195727e2020-01-03 09:16:57 +0100934static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
Daniel Mack54a8c502011-02-11 11:08:06 +0000935 {
936 .name = "Direct Thru Channel A",
937 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
938 },
939 {
940 .name = "Direct Thru Channel B",
941 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
942 },
943 {
944 .name = "Phono Input Channel A",
945 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
946 },
947 {
948 .name = "Phono Input Channel B",
949 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
950 },
951};
952
Takashi Iwai195727e2020-01-03 09:16:57 +0100953static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
Daniel Mack54a8c502011-02-11 11:08:06 +0000954 {
955 .name = "Direct Thru Channel A",
956 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
957 },
958 {
959 .name = "Direct Thru Channel B",
960 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
961 },
962 {
963 .name = "Direct Thru Channel C",
964 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
965 },
966 {
967 .name = "Direct Thru Channel D",
968 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
969 },
970 {
971 .name = "Phono Input Channel A",
972 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
973 },
974 {
975 .name = "Phono Input Channel B",
976 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
977 },
978 {
979 .name = "Phono Input Channel C",
980 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
981 },
982 {
983 .name = "Phono Input Channel D",
984 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
985 },
986};
987
988static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
989 const struct snd_kcontrol_new *kc,
990 unsigned int count)
991{
992 int i, err = 0;
993 struct snd_kcontrol_new template = {
994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
995 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
996 .get = snd_nativeinstruments_control_get,
997 .put = snd_nativeinstruments_control_put,
998 .info = snd_ctl_boolean_mono_info,
999 };
1000
1001 for (i = 0; i < count; i++) {
Takashi Iwaida6d2762014-11-18 16:59:47 +01001002 struct usb_mixer_elem_list *list;
Daniel Mack54a8c502011-02-11 11:08:06 +00001003
1004 template.name = kc[i].name;
1005 template.private_value = kc[i].private_value;
1006
Takashi Iwaida6d2762014-11-18 16:59:47 +01001007 err = add_single_ctl_with_resume(mixer, 0,
1008 snd_ni_update_cur_val,
1009 &template, &list);
Daniel Mack54a8c502011-02-11 11:08:06 +00001010 if (err < 0)
1011 break;
Takashi Iwaida6d2762014-11-18 16:59:47 +01001012 snd_ni_control_init_val(mixer, list->kctl);
Daniel Mack54a8c502011-02-11 11:08:06 +00001013 }
1014
1015 return err;
1016}
1017
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001018/* M-Audio FastTrack Ultra quirks */
Matt Gruskine9a25e02013-02-09 12:56:35 -05001019/* FTU Effect switch (also used by C400/C600) */
Felix Homannd34bf142012-04-23 20:24:27 +02001020static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
1021 struct snd_ctl_elem_info *uinfo)
1022{
Takashi Iwai7bbd03e2014-10-20 18:21:42 +02001023 static const char *const texts[8] = {
1024 "Room 1", "Room 2", "Room 3", "Hall 1",
1025 "Hall 2", "Plate", "Delay", "Echo"
Felix Homannd34bf142012-04-23 20:24:27 +02001026 };
1027
Takashi Iwai7bbd03e2014-10-20 18:21:42 +02001028 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
Felix Homannd34bf142012-04-23 20:24:27 +02001029}
1030
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001031static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
1032 struct snd_kcontrol *kctl)
Felix Homannd34bf142012-04-23 20:24:27 +02001033{
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001034 struct usb_device *dev = mixer->chip->dev;
1035 unsigned int pval = kctl->private_value;
Felix Homannd34bf142012-04-23 20:24:27 +02001036 int err;
1037 unsigned char value[2];
Felix Homannd34bf142012-04-23 20:24:27 +02001038
1039 value[0] = 0x00;
1040 value[1] = 0x00;
1041
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001042 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
1043 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1044 pval & 0xff00,
1045 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
1046 value, 2);
Felix Homannd34bf142012-04-23 20:24:27 +02001047 if (err < 0)
1048 return err;
1049
Colin Ian King2acf5a32019-06-27 17:43:08 +01001050 kctl->private_value |= (unsigned int)value[0] << 24;
Felix Homannd34bf142012-04-23 20:24:27 +02001051 return 0;
1052}
1053
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001054static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
1055 struct snd_ctl_elem_value *ucontrol)
1056{
1057 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
1058 return 0;
1059}
1060
1061static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
1062{
1063 struct snd_usb_audio *chip = list->mixer->chip;
1064 unsigned int pval = list->kctl->private_value;
1065 unsigned char value[2];
1066 int err;
1067
1068 value[0] = pval >> 24;
1069 value[1] = 0;
1070
Takashi Iwai47ab1542015-08-25 16:09:00 +02001071 err = snd_usb_lock_shutdown(chip);
1072 if (err < 0)
1073 return err;
1074 err = snd_usb_ctl_msg(chip->dev,
1075 usb_sndctrlpipe(chip->dev, 0),
1076 UAC_SET_CUR,
1077 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1078 pval & 0xff00,
1079 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
1080 value, 2);
1081 snd_usb_unlock_shutdown(chip);
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001082 return err;
1083}
1084
Felix Homannd34bf142012-04-23 20:24:27 +02001085static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
1086 struct snd_ctl_elem_value *ucontrol)
1087{
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001088 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
1089 unsigned int pval = list->kctl->private_value;
1090 int cur_val, err, new_val;
Felix Homannd34bf142012-04-23 20:24:27 +02001091
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001092 cur_val = pval >> 24;
Felix Homannd34bf142012-04-23 20:24:27 +02001093 new_val = ucontrol->value.enumerated.item[0];
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001094 if (cur_val == new_val)
1095 return 0;
Felix Homannd34bf142012-04-23 20:24:27 +02001096
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001097 kctl->private_value &= ~(0xff << 24);
1098 kctl->private_value |= new_val << 24;
1099 err = snd_ftu_eff_switch_update(list);
1100 return err < 0 ? err : 1;
Takashi Iwai1a290582014-11-11 15:45:57 +01001101}
1102
Eldad Zackd847ce02012-11-28 23:55:37 +01001103static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
1104 int validx, int bUnitID)
Felix Homannd34bf142012-04-23 20:24:27 +02001105{
1106 static struct snd_kcontrol_new template = {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108 .name = "Effect Program Switch",
1109 .index = 0,
1110 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1111 .info = snd_ftu_eff_switch_info,
1112 .get = snd_ftu_eff_switch_get,
1113 .put = snd_ftu_eff_switch_put
1114 };
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001115 struct usb_mixer_elem_list *list;
Felix Homannd34bf142012-04-23 20:24:27 +02001116 int err;
Felix Homannd34bf142012-04-23 20:24:27 +02001117
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001118 err = add_single_ctl_with_resume(mixer, bUnitID,
1119 snd_ftu_eff_switch_update,
1120 &template, &list);
Felix Homannd34bf142012-04-23 20:24:27 +02001121 if (err < 0)
1122 return err;
Takashi Iwai0b4e9cf2014-11-18 17:37:40 +01001123 list->kctl->private_value = (validx << 8) | bUnitID;
1124 snd_ftu_eff_switch_init(mixer, list->kctl);
Felix Homannd34bf142012-04-23 20:24:27 +02001125 return 0;
1126}
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001127
Felix Homanncfe8f972012-04-23 20:24:26 +02001128/* Create volume controls for FTU devices*/
1129static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001130{
1131 char name[64];
Felix Homann8a4d1d32012-04-23 20:24:23 +02001132 unsigned int control, cmask;
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001133 int in, out, err;
1134
Felix Homann8a4d1d32012-04-23 20:24:23 +02001135 const unsigned int id = 5;
1136 const int val_type = USB_MIXER_S16;
1137
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001138 for (out = 0; out < 8; out++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001139 control = out + 1;
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001140 for (in = 0; in < 8; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001141 cmask = 1 << in;
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001142 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +02001143 "AIn%d - Out%d Capture Volume",
1144 in + 1, out + 1);
1145 err = snd_create_std_mono_ctl(mixer, id, control,
1146 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +02001147 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001148 if (err < 0)
1149 return err;
1150 }
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001151 for (in = 8; in < 16; in++) {
Felix Homann8a4d1d32012-04-23 20:24:23 +02001152 cmask = 1 << in;
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001153 snprintf(name, sizeof(name),
Felix Homann8a4d1d32012-04-23 20:24:23 +02001154 "DIn%d - Out%d Playback Volume",
1155 in - 7, out + 1);
1156 err = snd_create_std_mono_ctl(mixer, id, control,
1157 cmask, val_type, name,
Felix Homann25ee7ef2012-04-23 20:24:25 +02001158 &snd_usb_mixer_vol_tlv);
Daniel Mackd5a0bf62011-05-25 09:09:03 +02001159 if (err < 0)
1160 return err;
1161 }
1162 }
1163
1164 return 0;
1165}
1166
Felix Homannd34bf142012-04-23 20:24:27 +02001167/* This control needs a volume quirk, see mixer.c */
1168static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1169{
1170 static const char name[] = "Effect Volume";
1171 const unsigned int id = 6;
1172 const int val_type = USB_MIXER_U8;
1173 const unsigned int control = 2;
1174 const unsigned int cmask = 0;
1175
1176 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1177 name, snd_usb_mixer_vol_tlv);
1178}
1179
1180/* This control needs a volume quirk, see mixer.c */
1181static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1182{
1183 static const char name[] = "Effect Duration";
1184 const unsigned int id = 6;
1185 const int val_type = USB_MIXER_S16;
1186 const unsigned int control = 3;
1187 const unsigned int cmask = 0;
1188
1189 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1190 name, snd_usb_mixer_vol_tlv);
1191}
1192
1193/* This control needs a volume quirk, see mixer.c */
1194static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1195{
1196 static const char name[] = "Effect Feedback Volume";
1197 const unsigned int id = 6;
1198 const int val_type = USB_MIXER_U8;
1199 const unsigned int control = 4;
1200 const unsigned int cmask = 0;
1201
1202 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1203 name, NULL);
1204}
1205
1206static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1207{
1208 unsigned int cmask;
1209 int err, ch;
1210 char name[48];
1211
1212 const unsigned int id = 7;
1213 const int val_type = USB_MIXER_S16;
1214 const unsigned int control = 7;
1215
1216 for (ch = 0; ch < 4; ++ch) {
1217 cmask = 1 << ch;
1218 snprintf(name, sizeof(name),
1219 "Effect Return %d Volume", ch + 1);
1220 err = snd_create_std_mono_ctl(mixer, id, control,
1221 cmask, val_type, name,
1222 snd_usb_mixer_vol_tlv);
1223 if (err < 0)
1224 return err;
1225 }
1226
1227 return 0;
1228}
1229
1230static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1231{
1232 unsigned int cmask;
1233 int err, ch;
1234 char name[48];
1235
1236 const unsigned int id = 5;
1237 const int val_type = USB_MIXER_S16;
1238 const unsigned int control = 9;
1239
1240 for (ch = 0; ch < 8; ++ch) {
1241 cmask = 1 << ch;
1242 snprintf(name, sizeof(name),
1243 "Effect Send AIn%d Volume", ch + 1);
1244 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1245 val_type, name,
1246 snd_usb_mixer_vol_tlv);
1247 if (err < 0)
1248 return err;
1249 }
1250 for (ch = 8; ch < 16; ++ch) {
1251 cmask = 1 << ch;
1252 snprintf(name, sizeof(name),
1253 "Effect Send DIn%d Volume", ch - 7);
1254 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1255 val_type, name,
1256 snd_usb_mixer_vol_tlv);
1257 if (err < 0)
1258 return err;
1259 }
1260 return 0;
1261}
1262
Felix Homanncfe8f972012-04-23 20:24:26 +02001263static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
Mark Hills7536c302012-04-14 17:19:24 +01001264{
Felix Homann8a4d1d32012-04-23 20:24:23 +02001265 int err;
Mark Hills7536c302012-04-14 17:19:24 +01001266
Felix Homanncfe8f972012-04-23 20:24:26 +02001267 err = snd_ftu_create_volume_ctls(mixer);
Felix Homann8a4d1d32012-04-23 20:24:23 +02001268 if (err < 0)
1269 return err;
Mark Hills7536c302012-04-14 17:19:24 +01001270
Eldad Zackd847ce02012-11-28 23:55:37 +01001271 err = snd_ftu_create_effect_switch(mixer, 1, 6);
Felix Homannd34bf142012-04-23 20:24:27 +02001272 if (err < 0)
1273 return err;
Eldad Zackd847ce02012-11-28 23:55:37 +01001274
Felix Homannd34bf142012-04-23 20:24:27 +02001275 err = snd_ftu_create_effect_volume_ctl(mixer);
1276 if (err < 0)
1277 return err;
1278
1279 err = snd_ftu_create_effect_duration_ctl(mixer);
1280 if (err < 0)
1281 return err;
1282
1283 err = snd_ftu_create_effect_feedback_ctl(mixer);
1284 if (err < 0)
1285 return err;
1286
1287 err = snd_ftu_create_effect_return_ctls(mixer);
1288 if (err < 0)
1289 return err;
1290
1291 err = snd_ftu_create_effect_send_ctls(mixer);
1292 if (err < 0)
1293 return err;
1294
Felix Homann8a4d1d32012-04-23 20:24:23 +02001295 return 0;
Mark Hills7536c302012-04-14 17:19:24 +01001296}
1297
Daniel Mack7b1eda22010-03-11 21:13:22 +01001298void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1299 unsigned char samplerate_id)
1300{
1301 struct usb_mixer_interface *mixer;
1302 struct usb_mixer_elem_info *cval;
Takashi Iwai6de3c9e2019-08-15 11:41:06 +02001303 int unitid = 12; /* SampleRate ExtensionUnit ID */
Daniel Mack7b1eda22010-03-11 21:13:22 +01001304
1305 list_for_each_entry(mixer, &chip->mixer_list, list) {
Takashi Iwai6de3c9e2019-08-15 11:41:06 +02001306 if (mixer->id_elems[unitid]) {
1307 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
Daniel Mack7b1eda22010-03-11 21:13:22 +01001308 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1309 cval->control << 8,
1310 samplerate_id);
1311 snd_usb_mixer_notify_id(mixer, unitid);
Takashi Iwai6de3c9e2019-08-15 11:41:06 +02001312 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01001313 }
Daniel Mack7b1eda22010-03-11 21:13:22 +01001314 }
1315}
1316
Matt Gruskine9a25e02013-02-09 12:56:35 -05001317/* M-Audio Fast Track C400/C600 */
1318/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001319static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1320{
1321 char name[64];
1322 unsigned int cmask, offset;
1323 int out, chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001324 int num_outs = 0;
1325 int num_ins = 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;
1330
Matt Gruskine9a25e02013-02-09 12:56:35 -05001331 switch (mixer->chip->usb_id) {
1332 case USB_ID(0x0763, 0x2030):
1333 num_outs = 6;
1334 num_ins = 4;
1335 break;
1336 case USB_ID(0x0763, 0x2031):
1337 num_outs = 8;
1338 num_ins = 6;
1339 break;
1340 }
1341
1342 for (chan = 0; chan < num_outs + num_ins; chan++) {
1343 for (out = 0; out < num_outs; out++) {
1344 if (chan < num_outs) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001345 snprintf(name, sizeof(name),
1346 "PCM%d-Out%d Playback Volume",
1347 chan + 1, out + 1);
1348 } else {
1349 snprintf(name, sizeof(name),
1350 "In%d-Out%d Playback Volume",
Matt Gruskine9a25e02013-02-09 12:56:35 -05001351 chan - num_outs + 1, out + 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001352 }
1353
1354 cmask = (out == 0) ? 0 : 1 << (out - 1);
Matt Gruskine9a25e02013-02-09 12:56:35 -05001355 offset = chan * num_outs;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001356 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1357 cmask, val_type, offset, name,
1358 &snd_usb_mixer_vol_tlv);
1359 if (err < 0)
1360 return err;
1361 }
1362 }
1363
1364 return 0;
1365}
1366
1367/* This control needs a volume quirk, see mixer.c */
1368static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1369{
1370 static const char name[] = "Effect Volume";
1371 const unsigned int id = 0x43;
1372 const int val_type = USB_MIXER_U8;
1373 const unsigned int control = 3;
1374 const unsigned int cmask = 0;
1375
1376 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1377 name, snd_usb_mixer_vol_tlv);
1378}
1379
1380/* This control needs a volume quirk, see mixer.c */
1381static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1382{
1383 static const char name[] = "Effect Duration";
1384 const unsigned int id = 0x43;
1385 const int val_type = USB_MIXER_S16;
1386 const unsigned int control = 4;
1387 const unsigned int cmask = 0;
1388
1389 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1390 name, snd_usb_mixer_vol_tlv);
1391}
1392
1393/* This control needs a volume quirk, see mixer.c */
1394static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1395{
1396 static const char name[] = "Effect Feedback Volume";
1397 const unsigned int id = 0x43;
1398 const int val_type = USB_MIXER_U8;
1399 const unsigned int control = 5;
1400 const unsigned int cmask = 0;
1401
1402 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1403 name, NULL);
1404}
1405
1406static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1407{
1408 char name[64];
1409 unsigned int cmask;
1410 int chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001411 int num_outs = 0;
1412 int num_ins = 0;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001413
1414 const unsigned int id = 0x42;
1415 const int val_type = USB_MIXER_S16;
1416 const int control = 1;
1417
Matt Gruskine9a25e02013-02-09 12:56:35 -05001418 switch (mixer->chip->usb_id) {
1419 case USB_ID(0x0763, 0x2030):
1420 num_outs = 6;
1421 num_ins = 4;
1422 break;
1423 case USB_ID(0x0763, 0x2031):
1424 num_outs = 8;
1425 num_ins = 6;
1426 break;
1427 }
1428
1429 for (chan = 0; chan < num_outs + num_ins; chan++) {
1430 if (chan < num_outs) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001431 snprintf(name, sizeof(name),
1432 "Effect Send DOut%d",
1433 chan + 1);
1434 } else {
1435 snprintf(name, sizeof(name),
1436 "Effect Send AIn%d",
Matt Gruskine9a25e02013-02-09 12:56:35 -05001437 chan - num_outs + 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001438 }
1439
1440 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1441 err = snd_create_std_mono_ctl(mixer, id, control,
1442 cmask, val_type, name,
1443 &snd_usb_mixer_vol_tlv);
1444 if (err < 0)
1445 return err;
1446 }
1447
1448 return 0;
1449}
1450
1451static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1452{
1453 char name[64];
1454 unsigned int cmask;
1455 int chan, err;
Matt Gruskine9a25e02013-02-09 12:56:35 -05001456 int num_outs = 0;
1457 int offset = 0;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001458
1459 const unsigned int id = 0x40;
1460 const int val_type = USB_MIXER_S16;
1461 const int control = 1;
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001462
Matt Gruskine9a25e02013-02-09 12:56:35 -05001463 switch (mixer->chip->usb_id) {
1464 case USB_ID(0x0763, 0x2030):
1465 num_outs = 6;
1466 offset = 0x3c;
1467 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1468 break;
1469 case USB_ID(0x0763, 0x2031):
1470 num_outs = 8;
1471 offset = 0x70;
1472 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1473 break;
1474 }
1475
1476 for (chan = 0; chan < num_outs; chan++) {
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001477 snprintf(name, sizeof(name),
1478 "Effect Return %d",
1479 chan + 1);
1480
Matt Gruskine9a25e02013-02-09 12:56:35 -05001481 cmask = (chan == 0) ? 0 :
1482 1 << (chan + (chan % 2) * num_outs - 1);
Eldad Zack09d8e3a2012-11-28 23:55:40 +01001483 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1484 cmask, val_type, offset, name,
1485 &snd_usb_mixer_vol_tlv);
1486 if (err < 0)
1487 return err;
1488 }
1489
1490 return 0;
1491}
1492
1493static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1494{
1495 int err;
1496
1497 err = snd_c400_create_vol_ctls(mixer);
1498 if (err < 0)
1499 return err;
1500
1501 err = snd_c400_create_effect_vol_ctls(mixer);
1502 if (err < 0)
1503 return err;
1504
1505 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1506 if (err < 0)
1507 return err;
1508
1509 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1510 if (err < 0)
1511 return err;
1512
1513 err = snd_c400_create_effect_volume_ctl(mixer);
1514 if (err < 0)
1515 return err;
1516
1517 err = snd_c400_create_effect_duration_ctl(mixer);
1518 if (err < 0)
1519 return err;
1520
1521 err = snd_c400_create_effect_feedback_ctl(mixer);
1522 if (err < 0)
1523 return err;
1524
1525 return 0;
1526}
1527
Mark Hillsb71dad182012-06-09 13:16:38 +01001528/*
1529 * The mixer units for Ebox-44 are corrupt, and even where they
1530 * are valid they presents mono controls as L and R channels of
1531 * stereo. So we provide a good mixer here.
1532 */
Takashi Iwaia01df922020-01-05 15:47:26 +01001533static const struct std_mono_table ebox44_table[] = {
Mark Hills989b0132012-06-09 13:16:39 +01001534 {
1535 .unitid = 4,
1536 .control = 1,
1537 .cmask = 0x0,
1538 .val_type = USB_MIXER_INV_BOOLEAN,
1539 .name = "Headphone Playback Switch"
1540 },
1541 {
1542 .unitid = 4,
1543 .control = 2,
1544 .cmask = 0x1,
1545 .val_type = USB_MIXER_S16,
1546 .name = "Headphone A Mix Playback Volume"
1547 },
1548 {
1549 .unitid = 4,
1550 .control = 2,
1551 .cmask = 0x2,
1552 .val_type = USB_MIXER_S16,
1553 .name = "Headphone B Mix Playback Volume"
1554 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001555
Mark Hills989b0132012-06-09 13:16:39 +01001556 {
1557 .unitid = 7,
1558 .control = 1,
1559 .cmask = 0x0,
1560 .val_type = USB_MIXER_INV_BOOLEAN,
1561 .name = "Output Playback Switch"
1562 },
1563 {
1564 .unitid = 7,
1565 .control = 2,
1566 .cmask = 0x1,
1567 .val_type = USB_MIXER_S16,
1568 .name = "Output A Playback Volume"
1569 },
1570 {
1571 .unitid = 7,
1572 .control = 2,
1573 .cmask = 0x2,
1574 .val_type = USB_MIXER_S16,
1575 .name = "Output B Playback Volume"
1576 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001577
Mark Hills989b0132012-06-09 13:16:39 +01001578 {
1579 .unitid = 10,
1580 .control = 1,
1581 .cmask = 0x0,
1582 .val_type = USB_MIXER_INV_BOOLEAN,
1583 .name = "Input Capture Switch"
1584 },
1585 {
1586 .unitid = 10,
1587 .control = 2,
1588 .cmask = 0x1,
1589 .val_type = USB_MIXER_S16,
1590 .name = "Input A Capture Volume"
1591 },
1592 {
1593 .unitid = 10,
1594 .control = 2,
1595 .cmask = 0x2,
1596 .val_type = USB_MIXER_S16,
1597 .name = "Input B Capture Volume"
1598 },
Mark Hillsb71dad182012-06-09 13:16:38 +01001599
Mark Hills989b0132012-06-09 13:16:39 +01001600 {}
Mark Hillsb71dad182012-06-09 13:16:38 +01001601};
1602
Przemek Rudy066624c2013-06-27 23:52:33 +02001603/* Audio Advantage Micro II findings:
1604 *
1605 * Mapping spdif AES bits to vendor register.bit:
1606 * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1607 * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1608 * AES2: [0 0 0 0 0 0 0 0]
1609 * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1610 * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1611 *
1612 * power on values:
1613 * r2: 0x10
1614 * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1615 * just after it to 0xa0, presumably it disables/mutes some analog
1616 * parts when there is no audio.)
1617 * r9: 0x28
1618 *
1619 * Optical transmitter on/off:
1620 * vendor register.bit: 9.1
1621 * 0 - on (0x28 register value)
1622 * 1 - off (0x2a register value)
1623 *
1624 */
1625static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_info *uinfo)
1627{
1628 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1629 uinfo->count = 1;
1630 return 0;
1631}
1632
1633static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1635{
Takashi Iwai288673b2014-11-18 18:06:17 +01001636 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1637 struct snd_usb_audio *chip = list->mixer->chip;
Przemek Rudy066624c2013-06-27 23:52:33 +02001638 int err;
1639 struct usb_interface *iface;
1640 struct usb_host_interface *alts;
1641 unsigned int ep;
1642 unsigned char data[3];
1643 int rate;
1644
Takashi Iwai47ab1542015-08-25 16:09:00 +02001645 err = snd_usb_lock_shutdown(chip);
1646 if (err < 0)
1647 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001648
Przemek Rudy066624c2013-06-27 23:52:33 +02001649 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1650 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1651 ucontrol->value.iec958.status[2] = 0x00;
1652
1653 /* use known values for that card: interface#1 altsetting#1 */
Takashi Iwai288673b2014-11-18 18:06:17 +01001654 iface = usb_ifnum_to_if(chip->dev, 1);
Xiyu Yang59e19472020-04-23 12:54:19 +08001655 if (!iface || iface->num_altsetting < 2) {
1656 err = -EINVAL;
1657 goto end;
1658 }
Przemek Rudy066624c2013-06-27 23:52:33 +02001659 alts = &iface->altsetting[1];
Xiyu Yang59e19472020-04-23 12:54:19 +08001660 if (get_iface_desc(alts)->bNumEndpoints < 1) {
1661 err = -EINVAL;
1662 goto end;
1663 }
Przemek Rudy066624c2013-06-27 23:52:33 +02001664 ep = get_endpoint(alts, 0)->bEndpointAddress;
1665
Takashi Iwai288673b2014-11-18 18:06:17 +01001666 err = snd_usb_ctl_msg(chip->dev,
1667 usb_rcvctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001668 UAC_GET_CUR,
1669 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1670 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1671 ep,
1672 data,
1673 sizeof(data));
1674 if (err < 0)
1675 goto end;
1676
1677 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1678 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1679 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1680
1681 err = 0;
Takashi Iwai288673b2014-11-18 18:06:17 +01001682 end:
Takashi Iwai47ab1542015-08-25 16:09:00 +02001683 snd_usb_unlock_shutdown(chip);
Przemek Rudy066624c2013-06-27 23:52:33 +02001684 return err;
1685}
1686
Takashi Iwai288673b2014-11-18 18:06:17 +01001687static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
Przemek Rudy066624c2013-06-27 23:52:33 +02001688{
Takashi Iwai288673b2014-11-18 18:06:17 +01001689 struct snd_usb_audio *chip = list->mixer->chip;
1690 unsigned int pval = list->kctl->private_value;
Przemek Rudy066624c2013-06-27 23:52:33 +02001691 u8 reg;
Takashi Iwai288673b2014-11-18 18:06:17 +01001692 int err;
Przemek Rudy066624c2013-06-27 23:52:33 +02001693
Takashi Iwai47ab1542015-08-25 16:09:00 +02001694 err = snd_usb_lock_shutdown(chip);
1695 if (err < 0)
1696 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001697
1698 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1699 err = snd_usb_ctl_msg(chip->dev,
1700 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001701 UAC_SET_CUR,
1702 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1703 reg,
1704 2,
1705 NULL,
1706 0);
1707 if (err < 0)
1708 goto end;
1709
Takashi Iwai288673b2014-11-18 18:06:17 +01001710 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1711 reg |= (pval >> 12) & 0x0f;
1712 err = snd_usb_ctl_msg(chip->dev,
1713 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001714 UAC_SET_CUR,
1715 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1716 reg,
1717 3,
1718 NULL,
1719 0);
1720 if (err < 0)
1721 goto end;
1722
Takashi Iwai288673b2014-11-18 18:06:17 +01001723 end:
Takashi Iwai47ab1542015-08-25 16:09:00 +02001724 snd_usb_unlock_shutdown(chip);
Takashi Iwai288673b2014-11-18 18:06:17 +01001725 return err;
1726}
1727
1728static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol)
1730{
1731 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1732 unsigned int pval, pval_old;
1733 int err;
1734
1735 pval = pval_old = kcontrol->private_value;
1736 pval &= 0xfffff0f0;
1737 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1738 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1739
1740 pval &= 0xffff0fff;
1741 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
Przemek Rudy066624c2013-06-27 23:52:33 +02001742
1743 /* The frequency bits in AES3 cannot be set via register access. */
1744
1745 /* Silently ignore any bits from the request that cannot be set. */
1746
Takashi Iwai288673b2014-11-18 18:06:17 +01001747 if (pval == pval_old)
1748 return 0;
1749
1750 kcontrol->private_value = pval;
1751 err = snd_microii_spdif_default_update(list);
1752 return err < 0 ? err : 1;
Przemek Rudy066624c2013-06-27 23:52:33 +02001753}
1754
1755static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1757{
1758 ucontrol->value.iec958.status[0] = 0x0f;
1759 ucontrol->value.iec958.status[1] = 0xff;
1760 ucontrol->value.iec958.status[2] = 0x00;
1761 ucontrol->value.iec958.status[3] = 0x00;
1762
1763 return 0;
1764}
1765
1766static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1768{
1769 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1770
1771 return 0;
1772}
1773
Takashi Iwai288673b2014-11-18 18:06:17 +01001774static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
Przemek Rudy066624c2013-06-27 23:52:33 +02001775{
Takashi Iwai288673b2014-11-18 18:06:17 +01001776 struct snd_usb_audio *chip = list->mixer->chip;
1777 u8 reg = list->kctl->private_value;
Przemek Rudy066624c2013-06-27 23:52:33 +02001778 int err;
Przemek Rudy066624c2013-06-27 23:52:33 +02001779
Takashi Iwai47ab1542015-08-25 16:09:00 +02001780 err = snd_usb_lock_shutdown(chip);
1781 if (err < 0)
1782 return err;
Takashi Iwai288673b2014-11-18 18:06:17 +01001783
1784 err = snd_usb_ctl_msg(chip->dev,
1785 usb_sndctrlpipe(chip->dev, 0),
Przemek Rudy066624c2013-06-27 23:52:33 +02001786 UAC_SET_CUR,
1787 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1788 reg,
1789 9,
1790 NULL,
1791 0);
1792
Takashi Iwai47ab1542015-08-25 16:09:00 +02001793 snd_usb_unlock_shutdown(chip);
Przemek Rudy066624c2013-06-27 23:52:33 +02001794 return err;
1795}
1796
Takashi Iwai288673b2014-11-18 18:06:17 +01001797static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1798 struct snd_ctl_elem_value *ucontrol)
1799{
1800 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1801 u8 reg;
1802 int err;
1803
1804 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1805 if (reg != list->kctl->private_value)
1806 return 0;
1807
1808 kcontrol->private_value = reg;
1809 err = snd_microii_spdif_switch_update(list);
1810 return err < 0 ? err : 1;
1811}
1812
Takashi Iwai195727e2020-01-03 09:16:57 +01001813static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
Przemek Rudy066624c2013-06-27 23:52:33 +02001814 {
1815 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1816 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1817 .info = snd_microii_spdif_info,
1818 .get = snd_microii_spdif_default_get,
1819 .put = snd_microii_spdif_default_put,
1820 .private_value = 0x00000100UL,/* reset value */
1821 },
1822 {
1823 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1824 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1825 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1826 .info = snd_microii_spdif_info,
1827 .get = snd_microii_spdif_mask_get,
1828 },
1829 {
1830 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1831 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1832 .info = snd_ctl_boolean_mono_info,
1833 .get = snd_microii_spdif_switch_get,
1834 .put = snd_microii_spdif_switch_put,
1835 .private_value = 0x00000028UL,/* reset value */
1836 }
1837};
1838
1839static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1840{
1841 int err, i;
Pierre-Louis Bossartff40e0d42020-01-11 15:47:36 -06001842 static const usb_mixer_elem_resume_func_t resume_funcs[] = {
Takashi Iwai288673b2014-11-18 18:06:17 +01001843 snd_microii_spdif_default_update,
1844 NULL,
1845 snd_microii_spdif_switch_update
1846 };
Przemek Rudy066624c2013-06-27 23:52:33 +02001847
1848 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
Takashi Iwai288673b2014-11-18 18:06:17 +01001849 err = add_single_ctl_with_resume(mixer, 0,
1850 resume_funcs[i],
1851 &snd_microii_mixer_spdif[i],
1852 NULL);
Przemek Rudy066624c2013-06-27 23:52:33 +02001853 if (err < 0)
1854 return err;
1855 }
1856
Mikulas Patocka18e47532013-12-05 14:32:43 -05001857 return 0;
Przemek Rudy066624c2013-06-27 23:52:33 +02001858}
1859
Ian Douglas Scott388fdb82018-01-16 15:34:50 -08001860/* Creative Sound Blaster E1 */
1861
1862static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1863 struct snd_ctl_elem_value *ucontrol)
1864{
1865 ucontrol->value.integer.value[0] = kcontrol->private_value;
1866 return 0;
1867}
1868
1869static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1870 unsigned char state)
1871{
1872 struct snd_usb_audio *chip = mixer->chip;
1873 int err;
1874 unsigned char buff[2];
1875
1876 buff[0] = 0x02;
1877 buff[1] = state ? 0x02 : 0x00;
1878
1879 err = snd_usb_lock_shutdown(chip);
1880 if (err < 0)
1881 return err;
1882 err = snd_usb_ctl_msg(chip->dev,
1883 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1884 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1885 0x0202, 3, buff, 2);
1886 snd_usb_unlock_shutdown(chip);
1887 return err;
1888}
1889
1890static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1891 struct snd_ctl_elem_value *ucontrol)
1892{
1893 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1894 unsigned char value = !!ucontrol->value.integer.value[0];
1895 int err;
1896
1897 if (kcontrol->private_value == value)
1898 return 0;
1899 kcontrol->private_value = value;
1900 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1901 return err < 0 ? err : 1;
1902}
1903
1904static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1905{
1906 return snd_soundblaster_e1_switch_update(list->mixer,
1907 list->kctl->private_value);
1908}
1909
1910static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1911 struct snd_ctl_elem_info *uinfo)
1912{
1913 static const char *const texts[2] = {
1914 "Mic", "Aux"
1915 };
1916
1917 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1918}
1919
Takashi Iwai195727e2020-01-03 09:16:57 +01001920static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
Ian Douglas Scott388fdb82018-01-16 15:34:50 -08001921 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1922 .name = "Input Source",
1923 .info = snd_soundblaster_e1_switch_info,
1924 .get = snd_soundblaster_e1_switch_get,
1925 .put = snd_soundblaster_e1_switch_put,
1926 .private_value = 0,
1927};
1928
1929static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1930{
1931 return add_single_ctl_with_resume(mixer, 0,
1932 snd_soundblaster_e1_switch_resume,
1933 &snd_soundblaster_e1_input_switch,
1934 NULL);
1935}
1936
Takashi Iwai964af632018-04-27 14:23:37 +02001937static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1938{
1939 u16 buf = 0;
1940
1941 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1942 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1943 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1944 &buf, 2);
1945}
1946
1947static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1948{
1949 /* fix to 0dB playback volumes */
1950 dell_dock_init_vol(mixer->chip, 1, 16);
1951 dell_dock_init_vol(mixer->chip, 2, 16);
1952 dell_dock_init_vol(mixer->chip, 1, 19);
1953 dell_dock_init_vol(mixer->chip, 2, 19);
1954 return 0;
1955}
1956
Jussi Laakod39f1d62018-10-05 11:00:04 +03001957/* RME Class Compliant device quirks */
1958
1959#define SND_RME_GET_STATUS1 23
1960#define SND_RME_GET_CURRENT_FREQ 17
1961#define SND_RME_CLK_SYSTEM_SHIFT 16
1962#define SND_RME_CLK_SYSTEM_MASK 0x1f
1963#define SND_RME_CLK_AES_SHIFT 8
1964#define SND_RME_CLK_SPDIF_SHIFT 12
1965#define SND_RME_CLK_AES_SPDIF_MASK 0xf
1966#define SND_RME_CLK_SYNC_SHIFT 6
1967#define SND_RME_CLK_SYNC_MASK 0x3
1968#define SND_RME_CLK_FREQMUL_SHIFT 18
1969#define SND_RME_CLK_FREQMUL_MASK 0x7
1970#define SND_RME_CLK_SYSTEM(x) \
1971 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1972#define SND_RME_CLK_AES(x) \
1973 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1974#define SND_RME_CLK_SPDIF(x) \
1975 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1976#define SND_RME_CLK_SYNC(x) \
1977 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1978#define SND_RME_CLK_FREQMUL(x) \
1979 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1980#define SND_RME_CLK_AES_LOCK 0x1
1981#define SND_RME_CLK_AES_SYNC 0x4
1982#define SND_RME_CLK_SPDIF_LOCK 0x2
1983#define SND_RME_CLK_SPDIF_SYNC 0x8
1984#define SND_RME_SPDIF_IF_SHIFT 4
1985#define SND_RME_SPDIF_FORMAT_SHIFT 5
1986#define SND_RME_BINARY_MASK 0x1
1987#define SND_RME_SPDIF_IF(x) \
1988 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1989#define SND_RME_SPDIF_FORMAT(x) \
1990 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1991
1992static const u32 snd_rme_rate_table[] = {
1993 32000, 44100, 48000, 50000,
1994 64000, 88200, 96000, 100000,
1995 128000, 176400, 192000, 200000,
1996 256000, 352800, 384000, 400000,
1997 512000, 705600, 768000, 800000
1998};
1999/* maximum number of items for AES and S/PDIF rates for above table */
2000#define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
2001
2002enum snd_rme_domain {
2003 SND_RME_DOMAIN_SYSTEM,
2004 SND_RME_DOMAIN_AES,
2005 SND_RME_DOMAIN_SPDIF
2006};
2007
2008enum snd_rme_clock_status {
2009 SND_RME_CLOCK_NOLOCK,
2010 SND_RME_CLOCK_LOCK,
2011 SND_RME_CLOCK_SYNC
2012};
2013
2014static int snd_rme_read_value(struct snd_usb_audio *chip,
2015 unsigned int item,
2016 u32 *value)
2017{
2018 struct usb_device *dev = chip->dev;
2019 int err;
2020
2021 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
2022 item,
2023 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2024 0, 0,
2025 value, sizeof(*value));
2026 if (err < 0)
2027 dev_err(&dev->dev,
2028 "unable to issue vendor read request %d (ret = %d)",
2029 item, err);
2030 return err;
2031}
2032
2033static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
2034 u32 *status1)
2035{
2036 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2037 struct snd_usb_audio *chip = list->mixer->chip;
2038 int err;
2039
2040 err = snd_usb_lock_shutdown(chip);
2041 if (err < 0)
2042 return err;
2043 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
2044 snd_usb_unlock_shutdown(chip);
2045 return err;
2046}
2047
2048static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
2049 struct snd_ctl_elem_value *ucontrol)
2050{
2051 u32 status1;
2052 u32 rate = 0;
2053 int idx;
2054 int err;
2055
2056 err = snd_rme_get_status1(kcontrol, &status1);
2057 if (err < 0)
2058 return err;
2059 switch (kcontrol->private_value) {
2060 case SND_RME_DOMAIN_SYSTEM:
2061 idx = SND_RME_CLK_SYSTEM(status1);
2062 if (idx < ARRAY_SIZE(snd_rme_rate_table))
2063 rate = snd_rme_rate_table[idx];
2064 break;
2065 case SND_RME_DOMAIN_AES:
2066 idx = SND_RME_CLK_AES(status1);
2067 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2068 rate = snd_rme_rate_table[idx];
2069 break;
2070 case SND_RME_DOMAIN_SPDIF:
2071 idx = SND_RME_CLK_SPDIF(status1);
2072 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2073 rate = snd_rme_rate_table[idx];
2074 break;
2075 default:
2076 return -EINVAL;
2077 }
2078 ucontrol->value.integer.value[0] = rate;
2079 return 0;
2080}
2081
2082static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
2083 struct snd_ctl_elem_value *ucontrol)
2084{
2085 u32 status1;
2086 int idx = SND_RME_CLOCK_NOLOCK;
2087 int err;
2088
2089 err = snd_rme_get_status1(kcontrol, &status1);
2090 if (err < 0)
2091 return err;
2092 switch (kcontrol->private_value) {
2093 case SND_RME_DOMAIN_AES: /* AES */
2094 if (status1 & SND_RME_CLK_AES_SYNC)
2095 idx = SND_RME_CLOCK_SYNC;
2096 else if (status1 & SND_RME_CLK_AES_LOCK)
2097 idx = SND_RME_CLOCK_LOCK;
2098 break;
2099 case SND_RME_DOMAIN_SPDIF: /* SPDIF */
2100 if (status1 & SND_RME_CLK_SPDIF_SYNC)
2101 idx = SND_RME_CLOCK_SYNC;
2102 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
2103 idx = SND_RME_CLOCK_LOCK;
2104 break;
2105 default:
2106 return -EINVAL;
2107 }
2108 ucontrol->value.enumerated.item[0] = idx;
2109 return 0;
2110}
2111
2112static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
2113 struct snd_ctl_elem_value *ucontrol)
2114{
2115 u32 status1;
2116 int err;
2117
2118 err = snd_rme_get_status1(kcontrol, &status1);
2119 if (err < 0)
2120 return err;
2121 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
2122 return 0;
2123}
2124
2125static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
2126 struct snd_ctl_elem_value *ucontrol)
2127{
2128 u32 status1;
2129 int err;
2130
2131 err = snd_rme_get_status1(kcontrol, &status1);
2132 if (err < 0)
2133 return err;
2134 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
2135 return 0;
2136}
2137
2138static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
2139 struct snd_ctl_elem_value *ucontrol)
2140{
2141 u32 status1;
2142 int err;
2143
2144 err = snd_rme_get_status1(kcontrol, &status1);
2145 if (err < 0)
2146 return err;
2147 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2148 return 0;
2149}
2150
2151static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2152 struct snd_ctl_elem_value *ucontrol)
2153{
2154 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2155 struct snd_usb_audio *chip = list->mixer->chip;
2156 u32 status1;
2157 const u64 num = 104857600000000ULL;
2158 u32 den;
2159 unsigned int freq;
2160 int err;
2161
2162 err = snd_usb_lock_shutdown(chip);
2163 if (err < 0)
2164 return err;
2165 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2166 if (err < 0)
2167 goto end;
2168 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2169 if (err < 0)
2170 goto end;
2171 freq = (den == 0) ? 0 : div64_u64(num, den);
2172 freq <<= SND_RME_CLK_FREQMUL(status1);
2173 ucontrol->value.integer.value[0] = freq;
2174
2175end:
2176 snd_usb_unlock_shutdown(chip);
2177 return err;
2178}
2179
2180static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2181 struct snd_ctl_elem_info *uinfo)
2182{
2183 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2184 uinfo->count = 1;
2185 switch (kcontrol->private_value) {
2186 case SND_RME_DOMAIN_SYSTEM:
2187 uinfo->value.integer.min = 32000;
2188 uinfo->value.integer.max = 800000;
2189 break;
2190 case SND_RME_DOMAIN_AES:
2191 case SND_RME_DOMAIN_SPDIF:
2192 default:
2193 uinfo->value.integer.min = 0;
2194 uinfo->value.integer.max = 200000;
2195 }
2196 uinfo->value.integer.step = 0;
2197 return 0;
2198}
2199
2200static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2201 struct snd_ctl_elem_info *uinfo)
2202{
2203 static const char *const sync_states[] = {
2204 "No Lock", "Lock", "Sync"
2205 };
2206
2207 return snd_ctl_enum_info(uinfo, 1,
2208 ARRAY_SIZE(sync_states), sync_states);
2209}
2210
2211static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2212 struct snd_ctl_elem_info *uinfo)
2213{
2214 static const char *const spdif_if[] = {
2215 "Coaxial", "Optical"
2216 };
2217
2218 return snd_ctl_enum_info(uinfo, 1,
2219 ARRAY_SIZE(spdif_if), spdif_if);
2220}
2221
2222static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2223 struct snd_ctl_elem_info *uinfo)
2224{
2225 static const char *const optical_type[] = {
2226 "Consumer", "Professional"
2227 };
2228
2229 return snd_ctl_enum_info(uinfo, 1,
2230 ARRAY_SIZE(optical_type), optical_type);
2231}
2232
2233static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2234 struct snd_ctl_elem_info *uinfo)
2235{
2236 static const char *const sync_sources[] = {
2237 "Internal", "AES", "SPDIF", "Internal"
2238 };
2239
2240 return snd_ctl_enum_info(uinfo, 1,
2241 ARRAY_SIZE(sync_sources), sync_sources);
2242}
2243
Takashi Iwai195727e2020-01-03 09:16:57 +01002244static const struct snd_kcontrol_new snd_rme_controls[] = {
Jussi Laakod39f1d62018-10-05 11:00:04 +03002245 {
2246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2247 .name = "AES Rate",
2248 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2249 .info = snd_rme_rate_info,
2250 .get = snd_rme_rate_get,
2251 .private_value = SND_RME_DOMAIN_AES
2252 },
2253 {
2254 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2255 .name = "AES Sync",
2256 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2257 .info = snd_rme_sync_state_info,
2258 .get = snd_rme_sync_state_get,
2259 .private_value = SND_RME_DOMAIN_AES
2260 },
2261 {
2262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2263 .name = "SPDIF Rate",
2264 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2265 .info = snd_rme_rate_info,
2266 .get = snd_rme_rate_get,
2267 .private_value = SND_RME_DOMAIN_SPDIF
2268 },
2269 {
2270 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2271 .name = "SPDIF Sync",
2272 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2273 .info = snd_rme_sync_state_info,
2274 .get = snd_rme_sync_state_get,
2275 .private_value = SND_RME_DOMAIN_SPDIF
2276 },
2277 {
2278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2279 .name = "SPDIF Interface",
2280 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2281 .info = snd_rme_spdif_if_info,
2282 .get = snd_rme_spdif_if_get,
2283 },
2284 {
2285 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2286 .name = "SPDIF Format",
2287 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2288 .info = snd_rme_spdif_format_info,
2289 .get = snd_rme_spdif_format_get,
2290 },
2291 {
2292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2293 .name = "Sync Source",
2294 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2295 .info = snd_rme_sync_source_info,
2296 .get = snd_rme_sync_source_get
2297 },
2298 {
2299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2300 .name = "System Rate",
2301 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2302 .info = snd_rme_rate_info,
2303 .get = snd_rme_rate_get,
2304 .private_value = SND_RME_DOMAIN_SYSTEM
2305 },
2306 {
2307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2308 .name = "Current Frequency",
2309 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2310 .info = snd_rme_rate_info,
2311 .get = snd_rme_current_freq_get
2312 }
2313};
2314
2315static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2316{
2317 int err, i;
2318
2319 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2320 err = add_single_ctl_with_resume(mixer, 0,
2321 NULL,
2322 &snd_rme_controls[i],
2323 NULL);
2324 if (err < 0)
2325 return err;
2326 }
2327
2328 return 0;
2329}
2330
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02002331/*
2332 * RME Babyface Pro (FS)
2333 *
2334 * These devices exposes a couple of DSP functions via request to EP0.
2335 * Switches are available via control registers, while routing is controlled
2336 * by controlling the volume on each possible crossing point.
Thomas Ebeling47b4f5f2020-05-15 13:46:05 +02002337 * Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02002338 * 0dB being at dec. 32768.
2339 */
2340enum {
2341 SND_BBFPRO_CTL_REG1 = 0,
2342 SND_BBFPRO_CTL_REG2
2343};
2344
2345#define SND_BBFPRO_CTL_REG_MASK 1
2346#define SND_BBFPRO_CTL_IDX_MASK 0xff
2347#define SND_BBFPRO_CTL_IDX_SHIFT 1
2348#define SND_BBFPRO_CTL_VAL_MASK 1
2349#define SND_BBFPRO_CTL_VAL_SHIFT 9
2350#define SND_BBFPRO_CTL_REG1_CLK_MASTER 0
2351#define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1
2352#define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7
2353#define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8
2354#define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10
2355#define SND_BBFPRO_CTL_REG2_48V_AN1 0
2356#define SND_BBFPRO_CTL_REG2_48V_AN2 1
2357#define SND_BBFPRO_CTL_REG2_SENS_IN3 2
2358#define SND_BBFPRO_CTL_REG2_SENS_IN4 3
2359#define SND_BBFPRO_CTL_REG2_PAD_AN1 4
2360#define SND_BBFPRO_CTL_REG2_PAD_AN2 5
2361
2362#define SND_BBFPRO_MIXER_IDX_MASK 0x1ff
2363#define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff
2364#define SND_BBFPRO_MIXER_VAL_SHIFT 9
2365#define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf
Thomas Ebeling47b4f5f2020-05-15 13:46:05 +02002366#define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02002367
2368#define SND_BBFPRO_USBREQ_CTL_REG1 0x10
2369#define SND_BBFPRO_USBREQ_CTL_REG2 0x17
2370#define SND_BBFPRO_USBREQ_MIXER 0x12
2371
2372static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
2373 u8 index, u8 value)
2374{
2375 int err;
2376 u16 usb_req, usb_idx, usb_val;
2377 struct snd_usb_audio *chip = mixer->chip;
2378
2379 err = snd_usb_lock_shutdown(chip);
2380 if (err < 0)
2381 return err;
2382
2383 if (reg == SND_BBFPRO_CTL_REG1) {
2384 usb_req = SND_BBFPRO_USBREQ_CTL_REG1;
2385 if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2386 usb_idx = 3;
2387 usb_val = value ? 3 : 0;
2388 } else {
2389 usb_idx = 1 << index;
2390 usb_val = value ? usb_idx : 0;
2391 }
2392 } else {
2393 usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
2394 usb_idx = 1 << index;
2395 usb_val = value ? usb_idx : 0;
2396 }
2397
2398 err = snd_usb_ctl_msg(chip->dev,
2399 usb_sndctrlpipe(chip->dev, 0), usb_req,
2400 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Thomas Ebelingf99e24a2020-05-29 19:32:56 +02002401 usb_val, usb_idx, NULL, 0);
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02002402
2403 snd_usb_unlock_shutdown(chip);
2404 return err;
2405}
2406
2407static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol,
2408 struct snd_ctl_elem_value *ucontrol)
2409{
2410 u8 reg, idx, val;
2411 int pv;
2412
2413 pv = kcontrol->private_value;
2414 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2415 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2416 val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT;
2417
2418 if ((reg == SND_BBFPRO_CTL_REG1 &&
2419 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2420 (reg == SND_BBFPRO_CTL_REG2 &&
2421 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2422 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2423 ucontrol->value.enumerated.item[0] = val;
2424 } else {
2425 ucontrol->value.integer.value[0] = val;
2426 }
2427 return 0;
2428}
2429
2430static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol,
2431 struct snd_ctl_elem_info *uinfo)
2432{
2433 u8 reg, idx;
2434 int pv;
2435
2436 pv = kcontrol->private_value;
2437 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2438 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2439
2440 if (reg == SND_BBFPRO_CTL_REG1 &&
2441 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2442 static const char * const texts[2] = {
2443 "AutoSync",
2444 "Internal"
2445 };
2446 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2447 } else if (reg == SND_BBFPRO_CTL_REG2 &&
2448 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2449 idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) {
2450 static const char * const texts[2] = {
2451 "-10dBV",
2452 "+4dBu"
2453 };
2454 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2455 }
2456
2457 uinfo->count = 1;
2458 uinfo->value.integer.min = 0;
2459 uinfo->value.integer.max = 1;
2460 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2461 return 0;
2462}
2463
2464static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol,
2465 struct snd_ctl_elem_value *ucontrol)
2466{
2467 int err;
2468 u8 reg, idx;
2469 int old_value, pv, val;
2470
2471 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2472 struct usb_mixer_interface *mixer = list->mixer;
2473
2474 pv = kcontrol->private_value;
2475 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2476 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2477 old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2478
2479 if ((reg == SND_BBFPRO_CTL_REG1 &&
2480 idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2481 (reg == SND_BBFPRO_CTL_REG2 &&
2482 (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2483 idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2484 val = ucontrol->value.enumerated.item[0];
2485 } else {
2486 val = ucontrol->value.integer.value[0];
2487 }
2488
2489 if (val > 1)
2490 return -EINVAL;
2491
2492 if (val == old_value)
2493 return 0;
2494
2495 kcontrol->private_value = reg
2496 | ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT)
2497 | ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT);
2498
2499 err = snd_bbfpro_ctl_update(mixer, reg, idx, val);
2500 return err < 0 ? err : 1;
2501}
2502
2503static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list)
2504{
2505 u8 reg, idx;
2506 int value, pv;
2507
2508 pv = list->kctl->private_value;
2509 reg = pv & SND_BBFPRO_CTL_REG_MASK;
2510 idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2511 value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2512
2513 return snd_bbfpro_ctl_update(list->mixer, reg, idx, value);
2514}
2515
2516static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index,
2517 u32 value)
2518{
2519 struct snd_usb_audio *chip = mixer->chip;
2520 int err;
2521 u16 idx;
2522 u16 usb_idx, usb_val;
2523 u32 v;
2524
2525 err = snd_usb_lock_shutdown(chip);
2526 if (err < 0)
2527 return err;
2528
2529 idx = index & SND_BBFPRO_MIXER_IDX_MASK;
2530 // 18 bit linear volume, split so 2 bits end up in index.
2531 v = value & SND_BBFPRO_MIXER_VAL_MASK;
2532 usb_idx = idx | (v & 0x3) << 14;
2533 usb_val = (v >> 2) & 0xffff;
2534
2535 err = snd_usb_ctl_msg(chip->dev,
2536 usb_sndctrlpipe(chip->dev, 0),
2537 SND_BBFPRO_USBREQ_MIXER,
2538 USB_DIR_OUT | USB_TYPE_VENDOR |
2539 USB_RECIP_DEVICE,
Thomas Ebelingf99e24a2020-05-29 19:32:56 +02002540 usb_val, usb_idx, NULL, 0);
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02002541
2542 snd_usb_unlock_shutdown(chip);
2543 return err;
2544}
2545
2546static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2548{
2549 ucontrol->value.integer.value[0] =
2550 kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2551 return 0;
2552}
2553
2554static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2556{
2557 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2558 uinfo->count = 1;
2559 uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN;
2560 uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX;
2561 return 0;
2562}
2563
2564static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_value *ucontrol)
2566{
2567 int err;
2568 u16 idx;
2569 u32 new_val, old_value, uvalue;
2570 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2571 struct usb_mixer_interface *mixer = list->mixer;
2572
2573 uvalue = ucontrol->value.integer.value[0];
2574 idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK;
2575 old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
2576
2577 if (uvalue > SND_BBFPRO_MIXER_VAL_MAX)
2578 return -EINVAL;
2579
2580 if (uvalue == old_value)
2581 return 0;
2582
2583 new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK;
2584
2585 kcontrol->private_value = idx
2586 | (new_val << SND_BBFPRO_MIXER_VAL_SHIFT);
2587
2588 err = snd_bbfpro_vol_update(mixer, idx, new_val);
2589 return err < 0 ? err : 1;
2590}
2591
2592static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list)
2593{
2594 int pv = list->kctl->private_value;
2595 u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK;
2596 u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT)
2597 & SND_BBFPRO_MIXER_VAL_MASK;
2598 return snd_bbfpro_vol_update(list->mixer, idx, val);
2599}
2600
2601// Predfine elements
2602static const struct snd_kcontrol_new snd_bbfpro_ctl_control = {
2603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2604 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2605 .index = 0,
2606 .info = snd_bbfpro_ctl_info,
2607 .get = snd_bbfpro_ctl_get,
2608 .put = snd_bbfpro_ctl_put
2609};
2610
2611static const struct snd_kcontrol_new snd_bbfpro_vol_control = {
2612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2613 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
2614 .index = 0,
2615 .info = snd_bbfpro_vol_info,
2616 .get = snd_bbfpro_vol_get,
2617 .put = snd_bbfpro_vol_put
2618};
2619
2620static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg,
2621 u8 index, char *name)
2622{
2623 struct snd_kcontrol_new knew = snd_bbfpro_ctl_control;
2624
2625 knew.name = name;
2626 knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK)
2627 | ((index & SND_BBFPRO_CTL_IDX_MASK)
2628 << SND_BBFPRO_CTL_IDX_SHIFT);
2629
2630 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume,
2631 &knew, NULL);
2632}
2633
2634static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index,
2635 char *name)
2636{
2637 struct snd_kcontrol_new knew = snd_bbfpro_vol_control;
2638
2639 knew.name = name;
2640 knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK;
2641
2642 return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume,
2643 &knew, NULL);
2644}
2645
2646static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)
2647{
2648 int err, i, o;
2649 char name[48];
2650
2651 static const char * const input[] = {
2652 "AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3",
2653 "ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2654
2655 static const char * const output[] = {
2656 "AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4",
2657 "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
2658
2659 for (o = 0 ; o < 12 ; ++o) {
2660 for (i = 0 ; i < 12 ; ++i) {
2661 // Line routing
2662 snprintf(name, sizeof(name),
2663 "%s-%s-%s Playback Volume",
2664 (i < 2 ? "Mic" : "Line"),
2665 input[i], output[o]);
2666 err = snd_bbfpro_vol_add(mixer, (26 * o + i), name);
2667 if (err < 0)
2668 return err;
2669
2670 // PCM routing... yes, it is output remapping
2671 snprintf(name, sizeof(name),
2672 "PCM-%s-%s Playback Volume",
2673 output[i], output[o]);
2674 err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i),
2675 name);
2676 if (err < 0)
2677 return err;
2678 }
2679 }
2680
2681 // Control Reg 1
2682 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2683 SND_BBFPRO_CTL_REG1_CLK_OPTICAL,
2684 "Sample Clock Source");
2685 if (err < 0)
2686 return err;
2687
2688 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2689 SND_BBFPRO_CTL_REG1_SPDIF_PRO,
2690 "IEC958 Pro Mask");
2691 if (err < 0)
2692 return err;
2693
2694 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2695 SND_BBFPRO_CTL_REG1_SPDIF_EMPH,
2696 "IEC958 Emphasis");
2697 if (err < 0)
2698 return err;
2699
2700 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
2701 SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL,
2702 "IEC958 Switch");
2703 if (err < 0)
2704 return err;
2705
2706 // Control Reg 2
2707 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2708 SND_BBFPRO_CTL_REG2_48V_AN1,
2709 "Mic-AN1 48V");
2710 if (err < 0)
2711 return err;
2712
2713 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2714 SND_BBFPRO_CTL_REG2_48V_AN2,
2715 "Mic-AN2 48V");
2716 if (err < 0)
2717 return err;
2718
2719 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2720 SND_BBFPRO_CTL_REG2_SENS_IN3,
2721 "Line-IN3 Sens.");
2722 if (err < 0)
2723 return err;
2724
2725 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2726 SND_BBFPRO_CTL_REG2_SENS_IN4,
2727 "Line-IN4 Sens.");
2728 if (err < 0)
2729 return err;
2730
2731 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2732 SND_BBFPRO_CTL_REG2_PAD_AN1,
2733 "Mic-AN1 PAD");
2734 if (err < 0)
2735 return err;
2736
2737 err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
2738 SND_BBFPRO_CTL_REG2_PAD_AN2,
2739 "Mic-AN2 PAD");
2740 if (err < 0)
2741 return err;
2742
2743 return 0;
2744}
2745
František Kučeracdc01a12020-09-22 16:42:06 +02002746/*
Olivia Mackintosha07df822021-02-05 18:42:56 +00002747 * Pioneer DJ DJM Mixers
František Kučeracdc01a12020-09-22 16:42:06 +02002748 *
Olivia Mackintosha07df822021-02-05 18:42:56 +00002749 * These devices generally have options for soft-switching the playback and
2750 * capture sources in addition to the recording level. Although different
2751 * devices have different configurations, there seems to be canonical values
2752 * for specific capture/playback types: See the definitions of these below.
František Kučeracdc01a12020-09-22 16:42:06 +02002753 *
Olivia Mackintosha07df822021-02-05 18:42:56 +00002754 * The wValue is masked with the stereo channel number. e.g. Setting Ch2 to
2755 * capture phono would be 0x0203. Capture, playback and capture level have
2756 * different wIndexes.
František Kučeracdc01a12020-09-22 16:42:06 +02002757 */
2758
Olivia Mackintosha07df822021-02-05 18:42:56 +00002759// Capture types
2760#define SND_DJM_CAP_LINE 0x00
2761#define SND_DJM_CAP_CDLINE 0x01
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01002762#define SND_DJM_CAP_DIGITAL 0x02
Olivia Mackintosha07df822021-02-05 18:42:56 +00002763#define SND_DJM_CAP_PHONO 0x03
2764#define SND_DJM_CAP_PFADER 0x06
2765#define SND_DJM_CAP_XFADERA 0x07
2766#define SND_DJM_CAP_XFADERB 0x08
2767#define SND_DJM_CAP_MIC 0x09
2768#define SND_DJM_CAP_AUX 0x0d
2769#define SND_DJM_CAP_RECOUT 0x0a
2770#define SND_DJM_CAP_NONE 0x0f
2771#define SND_DJM_CAP_CH1PFADER 0x11
2772#define SND_DJM_CAP_CH2PFADER 0x12
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01002773#define SND_DJM_CAP_CH3PFADER 0x13
2774#define SND_DJM_CAP_CH4PFADER 0x14
František Kučeracdc01a12020-09-22 16:42:06 +02002775
Olivia Mackintosha07df822021-02-05 18:42:56 +00002776// Playback types
2777#define SND_DJM_PB_CH1 0x00
2778#define SND_DJM_PB_CH2 0x01
2779#define SND_DJM_PB_AUX 0x04
František Kučeracdc01a12020-09-22 16:42:06 +02002780
Olivia Mackintosha07df822021-02-05 18:42:56 +00002781#define SND_DJM_WINDEX_CAP 0x8002
2782#define SND_DJM_WINDEX_CAPLVL 0x8003
2783#define SND_DJM_WINDEX_PB 0x8016
František Kučeracdc01a12020-09-22 16:42:06 +02002784
Olivia Mackintosha07df822021-02-05 18:42:56 +00002785// kcontrol->private_value layout
2786#define SND_DJM_VALUE_MASK 0x0000ffff
2787#define SND_DJM_GROUP_MASK 0x00ff0000
2788#define SND_DJM_DEVICE_MASK 0xff000000
2789#define SND_DJM_GROUP_SHIFT 16
2790#define SND_DJM_DEVICE_SHIFT 24
František Kučeracdc01a12020-09-22 16:42:06 +02002791
Olivia Mackintosha07df822021-02-05 18:42:56 +00002792// device table index
Nicolas MURE76878502021-03-01 16:27:27 +01002793// used for the snd_djm_devices table, so please update accordingly
Olivia Mackintosha07df822021-02-05 18:42:56 +00002794#define SND_DJM_250MK2_IDX 0x0
2795#define SND_DJM_750_IDX 0x1
Nicolas MURE76878502021-03-01 16:27:27 +01002796#define SND_DJM_850_IDX 0x2
2797#define SND_DJM_900NXS2_IDX 0x3
William Overton6d277882021-10-10 15:58:41 +01002798#define SND_DJM_750MK2_IDX 0x4
František Kučeracdc01a12020-09-22 16:42:06 +02002799
František Kučeracdc01a12020-09-22 16:42:06 +02002800
Olivia Mackintosha07df822021-02-05 18:42:56 +00002801#define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \
František Kučeracdc01a12020-09-22 16:42:06 +02002802 .name = _name, \
Olivia Mackintosha07df822021-02-05 18:42:56 +00002803 .options = snd_djm_opts_##suffix, \
2804 .noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \
2805 .default_value = _default_value, \
2806 .wIndex = _windex }
František Kučeracdc01a12020-09-22 16:42:06 +02002807
Olivia Mackintosha07df822021-02-05 18:42:56 +00002808#define SND_DJM_DEVICE(suffix) { \
2809 .controls = snd_djm_ctls_##suffix, \
2810 .ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) }
2811
2812
2813struct snd_djm_device {
2814 const char *name;
2815 const struct snd_djm_ctl *controls;
2816 size_t ncontrols;
František Kučeracdc01a12020-09-22 16:42:06 +02002817};
2818
Olivia Mackintosha07df822021-02-05 18:42:56 +00002819struct snd_djm_ctl {
František Kučeracdc01a12020-09-22 16:42:06 +02002820 const char *name;
Olivia Mackintosha07df822021-02-05 18:42:56 +00002821 const u16 *options;
2822 size_t noptions;
2823 u16 default_value;
2824 u16 wIndex;
2825};
František Kučeracdc01a12020-09-22 16:42:06 +02002826
Olivia Mackintosha07df822021-02-05 18:42:56 +00002827static const char *snd_djm_get_label_caplevel(u16 wvalue)
2828{
2829 switch (wvalue) {
2830 case 0x0000: return "-19dB";
2831 case 0x0100: return "-15dB";
2832 case 0x0200: return "-10dB";
2833 case 0x0300: return "-5dB";
2834 default: return NULL;
2835 }
2836};
2837
Nicolas MUREb8db8be2021-03-01 16:27:29 +01002838static const char *snd_djm_get_label_cap_common(u16 wvalue)
Olivia Mackintosha07df822021-02-05 18:42:56 +00002839{
2840 switch (wvalue & 0x00ff) {
2841 case SND_DJM_CAP_LINE: return "Control Tone LINE";
2842 case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE";
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01002843 case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL";
Olivia Mackintosha07df822021-02-05 18:42:56 +00002844 case SND_DJM_CAP_PHONO: return "Control Tone PHONO";
2845 case SND_DJM_CAP_PFADER: return "Post Fader";
2846 case SND_DJM_CAP_XFADERA: return "Cross Fader A";
2847 case SND_DJM_CAP_XFADERB: return "Cross Fader B";
2848 case SND_DJM_CAP_MIC: return "Mic";
2849 case SND_DJM_CAP_RECOUT: return "Rec Out";
2850 case SND_DJM_CAP_AUX: return "Aux";
2851 case SND_DJM_CAP_NONE: return "None";
2852 case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1";
2853 case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2";
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01002854 case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3";
2855 case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4";
Olivia Mackintosha07df822021-02-05 18:42:56 +00002856 default: return NULL;
2857 }
2858};
2859
Nicolas MUREb8db8be2021-03-01 16:27:29 +01002860// The DJM-850 has different values for CD/LINE and LINE capture
2861// control options than the other DJM declared in this file.
2862static const char *snd_djm_get_label_cap_850(u16 wvalue)
2863{
2864 switch (wvalue & 0x00ff) {
2865 case 0x00: return "Control Tone CD/LINE";
2866 case 0x01: return "Control Tone LINE";
2867 default: return snd_djm_get_label_cap_common(wvalue);
2868 }
2869};
2870
2871static const char *snd_djm_get_label_cap(u8 device_idx, u16 wvalue)
2872{
2873 switch (device_idx) {
2874 case SND_DJM_850_IDX: return snd_djm_get_label_cap_850(wvalue);
2875 default: return snd_djm_get_label_cap_common(wvalue);
2876 }
2877};
2878
Olivia Mackintosha07df822021-02-05 18:42:56 +00002879static const char *snd_djm_get_label_pb(u16 wvalue)
2880{
2881 switch (wvalue & 0x00ff) {
2882 case SND_DJM_PB_CH1: return "Ch1";
2883 case SND_DJM_PB_CH2: return "Ch2";
2884 case SND_DJM_PB_AUX: return "Aux";
2885 default: return NULL;
2886 }
2887};
2888
Nicolas MUREb8db8be2021-03-01 16:27:29 +01002889static const char *snd_djm_get_label(u8 device_idx, u16 wvalue, u16 windex)
Olivia Mackintosha07df822021-02-05 18:42:56 +00002890{
2891 switch (windex) {
2892 case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue);
Nicolas MUREb8db8be2021-03-01 16:27:29 +01002893 case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(device_idx, wvalue);
Olivia Mackintosha07df822021-02-05 18:42:56 +00002894 case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue);
2895 default: return NULL;
2896 }
2897};
2898
Nicolas MURE76878502021-03-01 16:27:27 +01002899// common DJM capture level option values
Olivia Mackintosha07df822021-02-05 18:42:56 +00002900static const u16 snd_djm_opts_cap_level[] = {
2901 0x0000, 0x0100, 0x0200, 0x0300 };
2902
Nicolas MURE76878502021-03-01 16:27:27 +01002903
2904// DJM-250MK2
Olivia Mackintosha07df822021-02-05 18:42:56 +00002905static const u16 snd_djm_opts_250mk2_cap1[] = {
2906 0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a };
2907
2908static const u16 snd_djm_opts_250mk2_cap2[] = {
2909 0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a };
2910
2911static const u16 snd_djm_opts_250mk2_cap3[] = {
2912 0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d };
2913
2914static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 };
2915static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 };
2916static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 };
2917
2918static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = {
2919 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2920 SND_DJM_CTL("Ch1 Input", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP),
2921 SND_DJM_CTL("Ch2 Input", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP),
2922 SND_DJM_CTL("Ch3 Input", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP),
2923 SND_DJM_CTL("Ch1 Output", 250mk2_pb1, 0, SND_DJM_WINDEX_PB),
2924 SND_DJM_CTL("Ch2 Output", 250mk2_pb2, 1, SND_DJM_WINDEX_PB),
2925 SND_DJM_CTL("Ch3 Output", 250mk2_pb3, 2, SND_DJM_WINDEX_PB)
2926};
2927
2928
2929// DJM-750
2930static const u16 snd_djm_opts_750_cap1[] = {
2931 0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
2932static const u16 snd_djm_opts_750_cap2[] = {
2933 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
2934static const u16 snd_djm_opts_750_cap3[] = {
2935 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
2936static const u16 snd_djm_opts_750_cap4[] = {
2937 0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
2938
2939static const struct snd_djm_ctl snd_djm_ctls_750[] = {
2940 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2941 SND_DJM_CTL("Ch1 Input", 750_cap1, 2, SND_DJM_WINDEX_CAP),
2942 SND_DJM_CTL("Ch2 Input", 750_cap2, 2, SND_DJM_WINDEX_CAP),
2943 SND_DJM_CTL("Ch3 Input", 750_cap3, 0, SND_DJM_WINDEX_CAP),
2944 SND_DJM_CTL("Ch4 Input", 750_cap4, 0, SND_DJM_WINDEX_CAP)
2945};
2946
2947
Nicolas MURE76878502021-03-01 16:27:27 +01002948// DJM-850
2949static const u16 snd_djm_opts_850_cap1[] = {
2950 0x0100, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
2951static const u16 snd_djm_opts_850_cap2[] = {
2952 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
2953static const u16 snd_djm_opts_850_cap3[] = {
2954 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
2955static const u16 snd_djm_opts_850_cap4[] = {
2956 0x0400, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
2957
2958static const struct snd_djm_ctl snd_djm_ctls_850[] = {
2959 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2960 SND_DJM_CTL("Ch1 Input", 850_cap1, 1, SND_DJM_WINDEX_CAP),
2961 SND_DJM_CTL("Ch2 Input", 850_cap2, 0, SND_DJM_WINDEX_CAP),
2962 SND_DJM_CTL("Ch3 Input", 850_cap3, 0, SND_DJM_WINDEX_CAP),
2963 SND_DJM_CTL("Ch4 Input", 850_cap4, 1, SND_DJM_WINDEX_CAP)
2964};
2965
2966
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01002967// DJM-900NXS2
2968static const u16 snd_djm_opts_900nxs2_cap1[] = {
2969 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a };
2970static const u16 snd_djm_opts_900nxs2_cap2[] = {
2971 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a };
2972static const u16 snd_djm_opts_900nxs2_cap3[] = {
2973 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a };
2974static const u16 snd_djm_opts_900nxs2_cap4[] = {
2975 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a };
2976static const u16 snd_djm_opts_900nxs2_cap5[] = {
2977 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 };
2978
2979static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = {
2980 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
2981 SND_DJM_CTL("Ch1 Input", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP),
2982 SND_DJM_CTL("Ch2 Input", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP),
2983 SND_DJM_CTL("Ch3 Input", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP),
2984 SND_DJM_CTL("Ch4 Input", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP),
2985 SND_DJM_CTL("Ch5 Input", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP)
2986};
2987
William Overton6d277882021-10-10 15:58:41 +01002988// DJM-750MK2
2989static const u16 snd_djm_opts_750mk2_cap1[] = {
2990 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a };
2991static const u16 snd_djm_opts_750mk2_cap2[] = {
2992 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a };
2993static const u16 snd_djm_opts_750mk2_cap3[] = {
2994 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a };
2995static const u16 snd_djm_opts_750mk2_cap4[] = {
2996 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a };
2997static const u16 snd_djm_opts_750mk2_cap5[] = {
2998 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 };
2999
3000static const u16 snd_djm_opts_750mk2_pb1[] = { 0x0100, 0x0101, 0x0104 };
3001static const u16 snd_djm_opts_750mk2_pb2[] = { 0x0200, 0x0201, 0x0204 };
3002static const u16 snd_djm_opts_750mk2_pb3[] = { 0x0300, 0x0301, 0x0304 };
3003
3004
3005static const struct snd_djm_ctl snd_djm_ctls_750mk2[] = {
3006 SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3007 SND_DJM_CTL("Ch1 Input", 750mk2_cap1, 2, SND_DJM_WINDEX_CAP),
3008 SND_DJM_CTL("Ch2 Input", 750mk2_cap2, 2, SND_DJM_WINDEX_CAP),
3009 SND_DJM_CTL("Ch3 Input", 750mk2_cap3, 2, SND_DJM_WINDEX_CAP),
3010 SND_DJM_CTL("Ch4 Input", 750mk2_cap4, 2, SND_DJM_WINDEX_CAP),
3011 SND_DJM_CTL("Ch5 Input", 750mk2_cap5, 3, SND_DJM_WINDEX_CAP),
3012 SND_DJM_CTL("Ch1 Output", 750mk2_pb1, 0, SND_DJM_WINDEX_PB),
3013 SND_DJM_CTL("Ch2 Output", 750mk2_pb2, 1, SND_DJM_WINDEX_PB),
3014 SND_DJM_CTL("Ch3 Output", 750mk2_pb3, 2, SND_DJM_WINDEX_PB)
3015};
3016
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01003017
Olivia Mackintosha07df822021-02-05 18:42:56 +00003018static const struct snd_djm_device snd_djm_devices[] = {
Geraldo Nascimentofb1af5b2021-12-04 15:52:24 -03003019 [SND_DJM_250MK2_IDX] = SND_DJM_DEVICE(250mk2),
3020 [SND_DJM_750_IDX] = SND_DJM_DEVICE(750),
3021 [SND_DJM_850_IDX] = SND_DJM_DEVICE(850),
3022 [SND_DJM_900NXS2_IDX] = SND_DJM_DEVICE(900nxs2),
3023 [SND_DJM_750MK2_IDX] = SND_DJM_DEVICE(750mk2),
Olivia Mackintosha07df822021-02-05 18:42:56 +00003024};
3025
3026
3027static int snd_djm_controls_info(struct snd_kcontrol *kctl,
3028 struct snd_ctl_elem_info *info)
3029{
3030 unsigned long private_value = kctl->private_value;
3031 u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3032 u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
3033 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
3034 const char *name;
3035 const struct snd_djm_ctl *ctl;
3036 size_t noptions;
3037
3038 if (ctl_idx >= device->ncontrols)
František Kučeracdc01a12020-09-22 16:42:06 +02003039 return -EINVAL;
3040
Olivia Mackintosha07df822021-02-05 18:42:56 +00003041 ctl = &device->controls[ctl_idx];
3042 noptions = ctl->noptions;
3043 if (info->value.enumerated.item >= noptions)
3044 info->value.enumerated.item = noptions - 1;
3045
Nicolas MUREb8db8be2021-03-01 16:27:29 +01003046 name = snd_djm_get_label(device_idx,
3047 ctl->options[info->value.enumerated.item],
Olivia Mackintosha07df822021-02-05 18:42:56 +00003048 ctl->wIndex);
3049 if (!name)
3050 return -EINVAL;
3051
Joe Perches75b1a8f2021-01-04 09:17:34 -08003052 strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name));
František Kučeracdc01a12020-09-22 16:42:06 +02003053 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3054 info->count = 1;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003055 info->value.enumerated.items = noptions;
František Kučeracdc01a12020-09-22 16:42:06 +02003056 return 0;
3057}
3058
Olivia Mackintosha07df822021-02-05 18:42:56 +00003059static int snd_djm_controls_update(struct usb_mixer_interface *mixer,
3060 u8 device_idx, u8 group, u16 value)
František Kučeracdc01a12020-09-22 16:42:06 +02003061{
3062 int err;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003063 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
František Kučeracdc01a12020-09-22 16:42:06 +02003064
Olivia Mackintosha07df822021-02-05 18:42:56 +00003065 if ((group >= device->ncontrols) || value >= device->controls[group].noptions)
František Kučeracdc01a12020-09-22 16:42:06 +02003066 return -EINVAL;
3067
3068 err = snd_usb_lock_shutdown(mixer->chip);
3069 if (err)
3070 return err;
3071
3072 err = snd_usb_ctl_msg(
3073 mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0),
3074 USB_REQ_SET_FEATURE,
3075 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Olivia Mackintosha07df822021-02-05 18:42:56 +00003076 device->controls[group].options[value],
3077 device->controls[group].wIndex,
František Kučeracdc01a12020-09-22 16:42:06 +02003078 NULL, 0);
3079
3080 snd_usb_unlock_shutdown(mixer->chip);
3081 return err;
3082}
3083
Olivia Mackintosha07df822021-02-05 18:42:56 +00003084static int snd_djm_controls_get(struct snd_kcontrol *kctl,
3085 struct snd_ctl_elem_value *elem)
František Kučeracdc01a12020-09-22 16:42:06 +02003086{
Olivia Mackintosha07df822021-02-05 18:42:56 +00003087 elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK;
František Kučeracdc01a12020-09-22 16:42:06 +02003088 return 0;
3089}
3090
Olivia Mackintosha07df822021-02-05 18:42:56 +00003091static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem)
František Kučeracdc01a12020-09-22 16:42:06 +02003092{
3093 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
3094 struct usb_mixer_interface *mixer = list->mixer;
3095 unsigned long private_value = kctl->private_value;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003096
3097 u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3098 u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
František Kučeracdc01a12020-09-22 16:42:06 +02003099 u16 value = elem->value.enumerated.item[0];
3100
Colin Ian King50b1aff2021-03-18 13:20:08 +00003101 kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) |
Olivia Mackintosha07df822021-02-05 18:42:56 +00003102 (group << SND_DJM_GROUP_SHIFT) |
3103 value);
František Kučeracdc01a12020-09-22 16:42:06 +02003104
Olivia Mackintosha07df822021-02-05 18:42:56 +00003105 return snd_djm_controls_update(mixer, device, group, value);
František Kučeracdc01a12020-09-22 16:42:06 +02003106}
3107
Olivia Mackintosha07df822021-02-05 18:42:56 +00003108static int snd_djm_controls_resume(struct usb_mixer_elem_list *list)
František Kučeracdc01a12020-09-22 16:42:06 +02003109{
3110 unsigned long private_value = list->kctl->private_value;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003111 u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
3112 u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
3113 u16 value = (private_value & SND_DJM_VALUE_MASK);
František Kučeracdc01a12020-09-22 16:42:06 +02003114
Olivia Mackintosha07df822021-02-05 18:42:56 +00003115 return snd_djm_controls_update(list->mixer, device, group, value);
František Kučeracdc01a12020-09-22 16:42:06 +02003116}
3117
Olivia Mackintosha07df822021-02-05 18:42:56 +00003118static int snd_djm_controls_create(struct usb_mixer_interface *mixer,
3119 const u8 device_idx)
František Kučeracdc01a12020-09-22 16:42:06 +02003120{
3121 int err, i;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003122 u16 value;
3123
3124 const struct snd_djm_device *device = &snd_djm_devices[device_idx];
3125
František Kučeracdc01a12020-09-22 16:42:06 +02003126 struct snd_kcontrol_new knew = {
3127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3128 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3129 .index = 0,
Olivia Mackintosha07df822021-02-05 18:42:56 +00003130 .info = snd_djm_controls_info,
3131 .get = snd_djm_controls_get,
3132 .put = snd_djm_controls_put
František Kučeracdc01a12020-09-22 16:42:06 +02003133 };
3134
Olivia Mackintosha07df822021-02-05 18:42:56 +00003135 for (i = 0; i < device->ncontrols; i++) {
3136 value = device->controls[i].default_value;
3137 knew.name = device->controls[i].name;
3138 knew.private_value = (
Colin Ian King50b1aff2021-03-18 13:20:08 +00003139 ((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) |
Olivia Mackintosha07df822021-02-05 18:42:56 +00003140 (i << SND_DJM_GROUP_SHIFT) |
3141 value);
3142 err = snd_djm_controls_update(mixer, device_idx, i, value);
František Kučeracdc01a12020-09-22 16:42:06 +02003143 if (err)
3144 return err;
Olivia Mackintosha07df822021-02-05 18:42:56 +00003145 err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume,
František Kučeracdc01a12020-09-22 16:42:06 +02003146 &knew, NULL);
3147 if (err)
3148 return err;
3149 }
3150 return 0;
3151}
3152
Daniel Mack7b1eda22010-03-11 21:13:22 +01003153int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
3154{
Daniel Mack3347b262011-02-11 11:34:12 +00003155 int err = 0;
Daniel Mack7b1eda22010-03-11 21:13:22 +01003156
Takashi Iwaif25ecf82018-05-27 15:18:22 +02003157 err = snd_usb_soundblaster_remote_init(mixer);
3158 if (err < 0)
Daniel Mack7b1eda22010-03-11 21:13:22 +01003159 return err;
3160
Daniel Mack3347b262011-02-11 11:34:12 +00003161 switch (mixer->chip->usb_id) {
Detlef Urband2bb390a2017-02-20 09:47:59 +01003162 /* Tascam US-16x08 */
3163 case USB_ID(0x0644, 0x8047):
3164 err = snd_us16x08_controls_create(mixer);
3165 break;
Daniel Mack3347b262011-02-11 11:34:12 +00003166 case USB_ID(0x041e, 0x3020):
3167 case USB_ID(0x041e, 0x3040):
3168 case USB_ID(0x041e, 0x3042):
Mathieu Bouffard7cdd8d72011-05-18 17:09:17 +02003169 case USB_ID(0x041e, 0x30df):
Daniel Mack3347b262011-02-11 11:34:12 +00003170 case USB_ID(0x041e, 0x3048):
3171 err = snd_audigy2nx_controls_create(mixer);
3172 if (err < 0)
3173 break;
Takashi Iwai74490542019-02-04 16:07:35 +01003174 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
3175 mixer, snd_audigy2nx_proc_read);
Daniel Mack3347b262011-02-11 11:34:12 +00003176 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01003177
Vasily Khoruzhick44832a72013-11-13 13:13:35 +03003178 /* EMU0204 */
3179 case USB_ID(0x041e, 0x3f19):
3180 err = snd_emu0204_controls_create(mixer);
Vasily Khoruzhick44832a72013-11-13 13:13:35 +03003181 break;
3182
Eldad Zack09d8e3a2012-11-28 23:55:40 +01003183 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
Matt Gruskine9a25e02013-02-09 12:56:35 -05003184 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
Eldad Zack09d8e3a2012-11-28 23:55:40 +01003185 err = snd_c400_create_mixer(mixer);
3186 break;
3187
Daniel Mackd5a0bf62011-05-25 09:09:03 +02003188 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
3189 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
Felix Homanncfe8f972012-04-23 20:24:26 +02003190 err = snd_ftu_create_mixer(mixer);
Daniel Mackd5a0bf62011-05-25 09:09:03 +02003191 break;
3192
Denis Washington1d31aff2012-12-11 11:38:32 +01003193 case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
3194 case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
3195 case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
Daniel Mack7b1eda22010-03-11 21:13:22 +01003196 err = snd_xonar_u1_controls_create(mixer);
Daniel Mack3347b262011-02-11 11:34:12 +00003197 break;
Daniel Mack7b1eda22010-03-11 21:13:22 +01003198
Przemek Rudy066624c2013-06-27 23:52:33 +02003199 case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
3200 err = snd_microii_controls_create(mixer);
3201 break;
3202
Damien Zammitd497a822014-11-12 01:09:54 +11003203 case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
Damien Zammit7ac22462021-08-13 21:34:02 +10003204 err = snd_mbox1_controls_create(mixer);
Damien Zammitd497a822014-11-12 01:09:54 +11003205 break;
3206
Daniel Mack3347b262011-02-11 11:34:12 +00003207 case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
Daniel Mack54a8c502011-02-11 11:08:06 +00003208 err = snd_nativeinstruments_create_mixer(mixer,
3209 snd_nativeinstruments_ta6_mixers,
3210 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00003211 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00003212
Daniel Mack3347b262011-02-11 11:34:12 +00003213 case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
Daniel Mack54a8c502011-02-11 11:08:06 +00003214 err = snd_nativeinstruments_create_mixer(mixer,
3215 snd_nativeinstruments_ta10_mixers,
3216 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
Daniel Mack3347b262011-02-11 11:34:12 +00003217 break;
Mark Hills7536c302012-04-14 17:19:24 +01003218
3219 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
Mark Hillsb71dad182012-06-09 13:16:38 +01003220 /* detection is disabled in mixer_maps.c */
3221 err = snd_create_std_mono_table(mixer, ebox44_table);
Mark Hills7536c302012-04-14 17:19:24 +01003222 break;
Chris J Arges76b188c2014-11-12 12:07:02 -06003223
3224 case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
3225 case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
3226 case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
3227 case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
3228 case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
3229 err = snd_scarlett_controls_create(mixer);
3230 break;
Ian Douglas Scott388fdb82018-01-16 15:34:50 -08003231
Geoffrey D. Bennett9e4d5c12019-07-29 00:42:45 +09303232 case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
3233 case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
3234 case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
Geoffrey D. Bennett2fa96272021-06-23 02:32:31 +09303235 case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */
3236 case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */
Geoffrey D. Bennett4be47792021-06-23 02:31:37 +09303237 case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */
3238 case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */
3239 case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */
3240 case USB_ID(0x1235, 0x8215): /* Focusrite Scarlett 18i20 3rd Gen */
Geoffrey D. Bennett265d1a92021-05-21 17:50:13 +09303241 err = snd_scarlett_gen2_init(mixer);
Geoffrey D. Bennett9e4d5c12019-07-29 00:42:45 +09303242 break;
3243
Ian Douglas Scott388fdb82018-01-16 15:34:50 -08003244 case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
3245 err = snd_soundblaster_e1_switch_create(mixer);
3246 break;
Takashi Iwai964af632018-04-27 14:23:37 +02003247 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
3248 err = dell_dock_mixer_init(mixer);
3249 break;
Jussi Laakod39f1d62018-10-05 11:00:04 +03003250
3251 case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
3252 case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
3253 case USB_ID(0x2a39, 0x3fd4): /* RME */
3254 err = snd_rme_controls_create(mixer);
3255 break;
Nick Kossifidis8dc5efe2020-02-15 03:23:35 +02003256
Takashi Iwai1e583ae2021-12-02 09:38:33 +01003257 case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */
Nick Kossifidis8dc5efe2020-02-15 03:23:35 +02003258 err = snd_sc1810_init_mixer(mixer);
3259 break;
Thomas Ebeling3e8f3bd2020-04-14 23:10:29 +02003260 case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */
3261 err = snd_bbfpro_controls_create(mixer);
3262 break;
František Kučeracdc01a12020-09-22 16:42:06 +02003263 case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */
Olivia Mackintosha07df822021-02-05 18:42:56 +00003264 err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX);
3265 break;
3266 case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */
3267 err = snd_djm_controls_create(mixer, SND_DJM_750_IDX);
František Kučeracdc01a12020-09-22 16:42:06 +02003268 break;
William Overton6d277882021-10-10 15:58:41 +01003269 case USB_ID(0x2b73, 0x001b): /* Pioneer DJ DJM-750MK2 */
3270 err = snd_djm_controls_create(mixer, SND_DJM_750MK2_IDX);
3271 break;
Nicolas MURE76878502021-03-01 16:27:27 +01003272 case USB_ID(0x08e4, 0x0163): /* Pioneer DJ DJM-850 */
3273 err = snd_djm_controls_create(mixer, SND_DJM_850_IDX);
3274 break;
Fabian Lesniakfee03ef2021-02-05 22:51:16 +01003275 case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */
3276 err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX);
3277 break;
Daniel Mack54a8c502011-02-11 11:08:06 +00003278 }
3279
Daniel Mack3347b262011-02-11 11:34:12 +00003280 return err;
Daniel Mack7b1eda22010-03-11 21:13:22 +01003281}
3282
Takashi Iwai964af632018-04-27 14:23:37 +02003283void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
3284{
3285 switch (mixer->chip->usb_id) {
3286 case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
3287 dell_dock_mixer_init(mixer);
3288 break;
3289 }
3290}
Takashi Iwai964af632018-04-27 14:23:37 +02003291
Daniel Mack7b1eda22010-03-11 21:13:22 +01003292void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
3293 int unitid)
3294{
3295 if (!mixer->rc_cfg)
3296 return;
3297 /* unit ids specific to Extigy/Audigy 2 NX: */
3298 switch (unitid) {
3299 case 0: /* remote control */
3300 mixer->rc_urb->dev = mixer->chip->dev;
3301 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
3302 break;
3303 case 4: /* digital in jack */
3304 case 7: /* line in jacks */
3305 case 19: /* speaker out jacks */
3306 case 20: /* headphones out jack */
3307 break;
3308 /* live24ext: 4 = line-in jack */
3309 case 3: /* hp-out jack (may actuate Mute) */
3310 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
3311 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
3312 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
3313 break;
3314 default:
Takashi Iwai0ba41d92014-02-26 13:02:17 +01003315 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
Daniel Mack7b1eda22010-03-11 21:13:22 +01003316 break;
3317 }
3318}
3319
Anssi Hannula42e31212015-12-13 20:49:58 +02003320static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03003321 struct usb_mixer_elem_info *cval,
Anssi Hannula42e31212015-12-13 20:49:58 +02003322 struct snd_kcontrol *kctl)
3323{
3324 /* Approximation using 10 ranges based on output measurement on hw v1.2.
3325 * This seems close to the cubic mapping e.g. alsamixer uses. */
3326 static const DECLARE_TLV_DB_RANGE(scale,
3327 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
3328 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
3329 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
3330 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
3331 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
3332 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
3333 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
3334 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
3335 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
3336 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
3337 );
3338
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03003339 if (cval->min == 0 && cval->max == 50) {
3340 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
3341 kctl->tlv.p = scale;
3342 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3343 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
3344
3345 } else if (cval->min == 0 && cval->max <= 1000) {
3346 /* Some other clearly broken DragonFly variant.
3347 * At least a 0..53 variant (hw v1.0) exists.
3348 */
3349 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
3350 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
3351 }
Anssi Hannula42e31212015-12-13 20:49:58 +02003352}
3353
3354void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
3355 struct usb_mixer_elem_info *cval, int unitid,
3356 struct snd_kcontrol *kctl)
3357{
3358 switch (mixer->chip->usb_id) {
3359 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
Anssi Hannulaeb1a74b2016-09-23 06:43:47 +03003360 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
3361 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
Anssi Hannula42e31212015-12-13 20:49:58 +02003362 break;
Takashi Iwai0f174b32017-08-16 14:18:37 +02003363 /* lowest playback value is muted on C-Media devices */
3364 case USB_ID(0x0d8c, 0x000c):
3365 case USB_ID(0x0d8c, 0x0014):
3366 if (strstr(kctl->id.name, "Playback"))
3367 cval->min_mute = 1;
3368 break;
Anssi Hannula42e31212015-12-13 20:49:58 +02003369 }
3370}
3371