Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/sound/usb/mixer_quirks.c
29265 views
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
* USB Audio Driver for ALSA
4
*
5
* Quirks and vendor-specific extensions for mixer interfaces
6
*
7
* Copyright (c) 2002 by Takashi Iwai <[email protected]>
8
*
9
* Many codes borrowed from audio.c by
10
* Alan Cox ([email protected])
11
* Thomas Sailer ([email protected])
12
*
13
* Audio Advantage Micro II support added by:
14
* Przemek Rudy ([email protected])
15
*/
16
17
#include <linux/bitfield.h>
18
#include <linux/hid.h>
19
#include <linux/init.h>
20
#include <linux/input.h>
21
#include <linux/math64.h>
22
#include <linux/slab.h>
23
#include <linux/usb.h>
24
#include <linux/usb/audio.h>
25
26
#include <sound/asoundef.h>
27
#include <sound/core.h>
28
#include <sound/control.h>
29
#include <sound/hda_verbs.h>
30
#include <sound/hwdep.h>
31
#include <sound/info.h>
32
#include <sound/tlv.h>
33
34
#include "usbaudio.h"
35
#include "mixer.h"
36
#include "mixer_quirks.h"
37
#include "mixer_scarlett.h"
38
#include "mixer_scarlett2.h"
39
#include "mixer_us16x08.h"
40
#include "mixer_s1810c.h"
41
#include "helper.h"
42
#include "fcp.h"
43
44
struct std_mono_table {
45
unsigned int unitid, control, cmask;
46
int val_type;
47
const char *name;
48
snd_kcontrol_tlv_rw_t *tlv_callback;
49
};
50
51
/* This function allows for the creation of standard UAC controls.
52
* See the quirks for M-Audio FTUs or Ebox-44.
53
* If you don't want to set a TLV callback pass NULL.
54
*
55
* Since there doesn't seem to be a devices that needs a multichannel
56
* version, we keep it mono for simplicity.
57
*/
58
static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
59
unsigned int unitid,
60
unsigned int control,
61
unsigned int cmask,
62
int val_type,
63
unsigned int idx_off,
64
const char *name,
65
snd_kcontrol_tlv_rw_t *tlv_callback)
66
{
67
struct usb_mixer_elem_info *cval;
68
struct snd_kcontrol *kctl;
69
70
cval = kzalloc(sizeof(*cval), GFP_KERNEL);
71
if (!cval)
72
return -ENOMEM;
73
74
snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
75
cval->val_type = val_type;
76
cval->channels = 1;
77
cval->control = control;
78
cval->cmask = cmask;
79
cval->idx_off = idx_off;
80
81
/* get_min_max() is called only for integer volumes later,
82
* so provide a short-cut for booleans
83
*/
84
cval->min = 0;
85
cval->max = 1;
86
cval->res = 0;
87
cval->dBmin = 0;
88
cval->dBmax = 0;
89
90
/* Create control */
91
kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
92
if (!kctl) {
93
kfree(cval);
94
return -ENOMEM;
95
}
96
97
/* Set name */
98
snprintf(kctl->id.name, sizeof(kctl->id.name), name);
99
kctl->private_free = snd_usb_mixer_elem_free;
100
101
/* set TLV */
102
if (tlv_callback) {
103
kctl->tlv.c = tlv_callback;
104
kctl->vd[0].access |=
105
SNDRV_CTL_ELEM_ACCESS_TLV_READ |
106
SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
107
}
108
/* Add control to mixer */
109
return snd_usb_mixer_add_control(&cval->head, kctl);
110
}
111
112
static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
113
unsigned int unitid,
114
unsigned int control,
115
unsigned int cmask,
116
int val_type,
117
const char *name,
118
snd_kcontrol_tlv_rw_t *tlv_callback)
119
{
120
return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
121
val_type, 0 /* Offset */,
122
name, tlv_callback);
123
}
124
125
/*
126
* Create a set of standard UAC controls from a table
127
*/
128
static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
129
const struct std_mono_table *t)
130
{
131
int err;
132
133
while (t->name) {
134
err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
135
t->cmask, t->val_type, t->name,
136
t->tlv_callback);
137
if (err < 0)
138
return err;
139
t++;
140
}
141
142
return 0;
143
}
144
145
static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
146
int id,
147
usb_mixer_elem_resume_func_t resume,
148
const struct snd_kcontrol_new *knew,
149
struct usb_mixer_elem_list **listp)
150
{
151
struct usb_mixer_elem_list *list;
152
struct snd_kcontrol *kctl;
153
154
list = kzalloc(sizeof(*list), GFP_KERNEL);
155
if (!list)
156
return -ENOMEM;
157
if (listp)
158
*listp = list;
159
list->mixer = mixer;
160
list->id = id;
161
list->resume = resume;
162
kctl = snd_ctl_new1(knew, list);
163
if (!kctl) {
164
kfree(list);
165
return -ENOMEM;
166
}
167
kctl->private_free = snd_usb_mixer_elem_free;
168
/* don't use snd_usb_mixer_add_control() here, this is a special list element */
169
return snd_usb_mixer_add_list(list, kctl, false);
170
}
171
172
/*
173
* Sound Blaster remote control configuration
174
*
175
* format of remote control data:
176
* Extigy: xx 00
177
* Audigy 2 NX: 06 80 xx 00 00 00
178
* Live! 24-bit: 06 80 xx yy 22 83
179
*/
180
static const struct rc_config {
181
u32 usb_id;
182
u8 offset;
183
u8 length;
184
u8 packet_length;
185
u8 min_packet_length; /* minimum accepted length of the URB result */
186
u8 mute_mixer_id;
187
u32 mute_code;
188
} rc_configs[] = {
189
{ USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
190
{ USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
191
{ USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
192
{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
193
{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
194
{ USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
195
{ USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
196
{ USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
197
};
198
199
static void snd_usb_soundblaster_remote_complete(struct urb *urb)
200
{
201
struct usb_mixer_interface *mixer = urb->context;
202
const struct rc_config *rc = mixer->rc_cfg;
203
u32 code;
204
205
if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
206
return;
207
208
code = mixer->rc_buffer[rc->offset];
209
if (rc->length == 2)
210
code |= mixer->rc_buffer[rc->offset + 1] << 8;
211
212
/* the Mute button actually changes the mixer control */
213
if (code == rc->mute_code)
214
snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
215
mixer->rc_code = code;
216
wake_up(&mixer->rc_waitq);
217
}
218
219
static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
220
long count, loff_t *offset)
221
{
222
struct usb_mixer_interface *mixer = hw->private_data;
223
int err;
224
u32 rc_code;
225
226
if (count != 1 && count != 4)
227
return -EINVAL;
228
err = wait_event_interruptible(mixer->rc_waitq,
229
(rc_code = xchg(&mixer->rc_code, 0)) != 0);
230
if (err == 0) {
231
if (count == 1)
232
err = put_user(rc_code, buf);
233
else
234
err = put_user(rc_code, (u32 __user *)buf);
235
}
236
return err < 0 ? err : count;
237
}
238
239
static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
240
poll_table *wait)
241
{
242
struct usb_mixer_interface *mixer = hw->private_data;
243
244
poll_wait(file, &mixer->rc_waitq, wait);
245
return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
246
}
247
248
static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
249
{
250
struct snd_hwdep *hwdep;
251
int err, len, i;
252
253
for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
254
if (rc_configs[i].usb_id == mixer->chip->usb_id)
255
break;
256
if (i >= ARRAY_SIZE(rc_configs))
257
return 0;
258
mixer->rc_cfg = &rc_configs[i];
259
260
len = mixer->rc_cfg->packet_length;
261
262
init_waitqueue_head(&mixer->rc_waitq);
263
err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
264
if (err < 0)
265
return err;
266
snprintf(hwdep->name, sizeof(hwdep->name),
267
"%s remote control", mixer->chip->card->shortname);
268
hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
269
hwdep->private_data = mixer;
270
hwdep->ops.read = snd_usb_sbrc_hwdep_read;
271
hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
272
hwdep->exclusive = 1;
273
274
mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
275
if (!mixer->rc_urb)
276
return -ENOMEM;
277
mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
278
if (!mixer->rc_setup_packet) {
279
usb_free_urb(mixer->rc_urb);
280
mixer->rc_urb = NULL;
281
return -ENOMEM;
282
}
283
mixer->rc_setup_packet->bRequestType =
284
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
285
mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
286
mixer->rc_setup_packet->wValue = cpu_to_le16(0);
287
mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
288
mixer->rc_setup_packet->wLength = cpu_to_le16(len);
289
usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
290
usb_rcvctrlpipe(mixer->chip->dev, 0),
291
(u8 *)mixer->rc_setup_packet, mixer->rc_buffer, len,
292
snd_usb_soundblaster_remote_complete, mixer);
293
return 0;
294
}
295
296
#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
297
298
static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
299
{
300
ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
301
return 0;
302
}
303
304
static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
305
int value, int index)
306
{
307
struct snd_usb_audio *chip = mixer->chip;
308
int err;
309
310
CLASS(snd_usb_lock, pm)(chip);
311
if (pm.err < 0)
312
return pm.err;
313
314
if (chip->usb_id == USB_ID(0x041e, 0x3042))
315
err = snd_usb_ctl_msg(chip->dev,
316
usb_sndctrlpipe(chip->dev, 0), 0x24,
317
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
318
!value, 0, NULL, 0);
319
/* USB X-Fi S51 Pro */
320
if (chip->usb_id == USB_ID(0x041e, 0x30df))
321
err = snd_usb_ctl_msg(chip->dev,
322
usb_sndctrlpipe(chip->dev, 0), 0x24,
323
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
324
!value, 0, NULL, 0);
325
else
326
err = snd_usb_ctl_msg(chip->dev,
327
usb_sndctrlpipe(chip->dev, 0), 0x24,
328
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
329
value, index + 2, NULL, 0);
330
return err;
331
}
332
333
static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
334
struct snd_ctl_elem_value *ucontrol)
335
{
336
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
337
struct usb_mixer_interface *mixer = list->mixer;
338
int index = kcontrol->private_value & 0xff;
339
unsigned int value = ucontrol->value.integer.value[0];
340
int old_value = kcontrol->private_value >> 8;
341
int err;
342
343
if (value > 1)
344
return -EINVAL;
345
if (value == old_value)
346
return 0;
347
kcontrol->private_value = (value << 8) | index;
348
err = snd_audigy2nx_led_update(mixer, value, index);
349
return err < 0 ? err : 1;
350
}
351
352
static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
353
{
354
int priv_value = list->kctl->private_value;
355
356
return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
357
priv_value & 0xff);
358
}
359
360
/* name and private_value are set dynamically */
361
static const struct snd_kcontrol_new snd_audigy2nx_control = {
362
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
363
.info = snd_audigy2nx_led_info,
364
.get = snd_audigy2nx_led_get,
365
.put = snd_audigy2nx_led_put,
366
};
367
368
static const char * const snd_audigy2nx_led_names[] = {
369
"CMSS LED Switch",
370
"Power LED Switch",
371
"Dolby Digital LED Switch",
372
};
373
374
static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
375
{
376
int i, err;
377
378
for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
379
struct snd_kcontrol_new knew;
380
381
/* USB X-Fi S51 doesn't have a CMSS LED */
382
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042) && i == 0)
383
continue;
384
/* USB X-Fi S51 Pro doesn't have one either */
385
if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df) && i == 0)
386
continue;
387
if (i > 1 && /* Live24ext has 2 LEDs only */
388
(mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
389
mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
390
mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
391
mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
392
break;
393
394
knew = snd_audigy2nx_control;
395
knew.name = snd_audigy2nx_led_names[i];
396
knew.private_value = (1 << 8) | i; /* LED on as default */
397
err = add_single_ctl_with_resume(mixer, 0,
398
snd_audigy2nx_led_resume,
399
&knew, NULL);
400
if (err < 0)
401
return err;
402
}
403
return 0;
404
}
405
406
static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
407
struct snd_info_buffer *buffer)
408
{
409
static const struct sb_jack {
410
int unitid;
411
const char *name;
412
} jacks_audigy2nx[] = {
413
{4, "dig in "},
414
{7, "line in"},
415
{19, "spk out"},
416
{20, "hph out"},
417
{-1, NULL}
418
}, jacks_live24ext[] = {
419
{4, "line in"}, /* &1=Line, &2=Mic*/
420
{3, "hph out"}, /* headphones */
421
{0, "RC "}, /* last command, 6 bytes see rc_config above */
422
{-1, NULL}
423
};
424
const struct sb_jack *jacks;
425
struct usb_mixer_interface *mixer = entry->private_data;
426
int i, err;
427
u8 buf[3];
428
429
snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
430
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
431
jacks = jacks_audigy2nx;
432
else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
433
mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
434
jacks = jacks_live24ext;
435
else
436
return;
437
438
for (i = 0; jacks[i].name; ++i) {
439
snd_iprintf(buffer, "%s: ", jacks[i].name);
440
CLASS(snd_usb_lock, pm)(mixer->chip);
441
if (pm.err < 0)
442
return;
443
err = snd_usb_ctl_msg(mixer->chip->dev,
444
usb_rcvctrlpipe(mixer->chip->dev, 0),
445
UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
446
USB_RECIP_INTERFACE, 0,
447
jacks[i].unitid << 8, buf, 3);
448
if (err == 3 && (buf[0] == 3 || buf[0] == 6))
449
snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
450
else
451
snd_iprintf(buffer, "?\n");
452
}
453
}
454
455
/* EMU0204 */
456
static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
457
struct snd_ctl_elem_info *uinfo)
458
{
459
static const char * const texts[2] = {"1/2", "3/4"};
460
461
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
462
}
463
464
static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
465
struct snd_ctl_elem_value *ucontrol)
466
{
467
ucontrol->value.enumerated.item[0] = kcontrol->private_value;
468
return 0;
469
}
470
471
static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
472
int value)
473
{
474
struct snd_usb_audio *chip = mixer->chip;
475
unsigned char buf[2];
476
477
CLASS(snd_usb_lock, pm)(chip);
478
if (pm.err < 0)
479
return pm.err;
480
481
buf[0] = 0x01;
482
buf[1] = value ? 0x02 : 0x01;
483
return snd_usb_ctl_msg(chip->dev,
484
usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
485
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
486
0x0400, 0x0e00, buf, 2);
487
}
488
489
static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
490
struct snd_ctl_elem_value *ucontrol)
491
{
492
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
493
struct usb_mixer_interface *mixer = list->mixer;
494
unsigned int value = ucontrol->value.enumerated.item[0];
495
int err;
496
497
if (value > 1)
498
return -EINVAL;
499
500
if (value == kcontrol->private_value)
501
return 0;
502
503
kcontrol->private_value = value;
504
err = snd_emu0204_ch_switch_update(mixer, value);
505
return err < 0 ? err : 1;
506
}
507
508
static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
509
{
510
return snd_emu0204_ch_switch_update(list->mixer,
511
list->kctl->private_value);
512
}
513
514
static const struct snd_kcontrol_new snd_emu0204_control = {
515
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
516
.name = "Front Jack Channels",
517
.info = snd_emu0204_ch_switch_info,
518
.get = snd_emu0204_ch_switch_get,
519
.put = snd_emu0204_ch_switch_put,
520
.private_value = 0,
521
};
522
523
static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
524
{
525
return add_single_ctl_with_resume(mixer, 0,
526
snd_emu0204_ch_switch_resume,
527
&snd_emu0204_control, NULL);
528
}
529
530
#if IS_REACHABLE(CONFIG_INPUT)
531
/*
532
* Sony DualSense controller (PS5) jack detection
533
*
534
* Since this is an UAC 1 device, it doesn't support jack detection.
535
* However, the controller hid-playstation driver reports HP & MIC
536
* insert events through a dedicated input device.
537
*/
538
539
#define SND_DUALSENSE_JACK_OUT_TERM_ID 3
540
#define SND_DUALSENSE_JACK_IN_TERM_ID 4
541
542
struct dualsense_mixer_elem_info {
543
struct usb_mixer_elem_info info;
544
struct input_handler ih;
545
struct input_device_id id_table[2];
546
bool connected;
547
};
548
549
static void snd_dualsense_ih_event(struct input_handle *handle,
550
unsigned int type, unsigned int code,
551
int value)
552
{
553
struct dualsense_mixer_elem_info *mei;
554
struct usb_mixer_elem_list *me;
555
556
if (type != EV_SW)
557
return;
558
559
mei = container_of(handle->handler, struct dualsense_mixer_elem_info, ih);
560
me = &mei->info.head;
561
562
if ((me->id == SND_DUALSENSE_JACK_OUT_TERM_ID && code == SW_HEADPHONE_INSERT) ||
563
(me->id == SND_DUALSENSE_JACK_IN_TERM_ID && code == SW_MICROPHONE_INSERT)) {
564
mei->connected = !!value;
565
snd_ctl_notify(me->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
566
&me->kctl->id);
567
}
568
}
569
570
static bool snd_dualsense_ih_match(struct input_handler *handler,
571
struct input_dev *dev)
572
{
573
struct dualsense_mixer_elem_info *mei;
574
struct usb_device *snd_dev;
575
char *input_dev_path, *usb_dev_path;
576
size_t usb_dev_path_len;
577
bool match = false;
578
579
mei = container_of(handler, struct dualsense_mixer_elem_info, ih);
580
snd_dev = mei->info.head.mixer->chip->dev;
581
582
input_dev_path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
583
if (!input_dev_path) {
584
dev_warn(&snd_dev->dev, "Failed to get input dev path\n");
585
return false;
586
}
587
588
usb_dev_path = kobject_get_path(&snd_dev->dev.kobj, GFP_KERNEL);
589
if (!usb_dev_path) {
590
dev_warn(&snd_dev->dev, "Failed to get USB dev path\n");
591
goto free_paths;
592
}
593
594
/*
595
* Ensure the VID:PID matched input device supposedly owned by the
596
* hid-playstation driver belongs to the actual hardware handled by
597
* the current USB audio device, which implies input_dev_path being
598
* a subpath of usb_dev_path.
599
*
600
* This verification is necessary when there is more than one identical
601
* controller attached to the host system.
602
*/
603
usb_dev_path_len = strlen(usb_dev_path);
604
if (usb_dev_path_len >= strlen(input_dev_path))
605
goto free_paths;
606
607
usb_dev_path[usb_dev_path_len] = '/';
608
match = !memcmp(input_dev_path, usb_dev_path, usb_dev_path_len + 1);
609
610
free_paths:
611
kfree(input_dev_path);
612
kfree(usb_dev_path);
613
614
return match;
615
}
616
617
static int snd_dualsense_ih_connect(struct input_handler *handler,
618
struct input_dev *dev,
619
const struct input_device_id *id)
620
{
621
struct input_handle *handle;
622
int err;
623
624
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
625
if (!handle)
626
return -ENOMEM;
627
628
handle->dev = dev;
629
handle->handler = handler;
630
handle->name = handler->name;
631
632
err = input_register_handle(handle);
633
if (err)
634
goto err_free;
635
636
err = input_open_device(handle);
637
if (err)
638
goto err_unregister;
639
640
return 0;
641
642
err_unregister:
643
input_unregister_handle(handle);
644
err_free:
645
kfree(handle);
646
return err;
647
}
648
649
static void snd_dualsense_ih_disconnect(struct input_handle *handle)
650
{
651
input_close_device(handle);
652
input_unregister_handle(handle);
653
kfree(handle);
654
}
655
656
static void snd_dualsense_ih_start(struct input_handle *handle)
657
{
658
struct dualsense_mixer_elem_info *mei;
659
struct usb_mixer_elem_list *me;
660
int status = -1;
661
662
mei = container_of(handle->handler, struct dualsense_mixer_elem_info, ih);
663
me = &mei->info.head;
664
665
if (me->id == SND_DUALSENSE_JACK_OUT_TERM_ID &&
666
test_bit(SW_HEADPHONE_INSERT, handle->dev->swbit))
667
status = test_bit(SW_HEADPHONE_INSERT, handle->dev->sw);
668
else if (me->id == SND_DUALSENSE_JACK_IN_TERM_ID &&
669
test_bit(SW_MICROPHONE_INSERT, handle->dev->swbit))
670
status = test_bit(SW_MICROPHONE_INSERT, handle->dev->sw);
671
672
if (status >= 0) {
673
mei->connected = !!status;
674
snd_ctl_notify(me->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
675
&me->kctl->id);
676
}
677
}
678
679
static int snd_dualsense_jack_get(struct snd_kcontrol *kctl,
680
struct snd_ctl_elem_value *ucontrol)
681
{
682
struct dualsense_mixer_elem_info *mei = snd_kcontrol_chip(kctl);
683
684
ucontrol->value.integer.value[0] = mei->connected;
685
686
return 0;
687
}
688
689
static const struct snd_kcontrol_new snd_dualsense_jack_control = {
690
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
691
.access = SNDRV_CTL_ELEM_ACCESS_READ,
692
.info = snd_ctl_boolean_mono_info,
693
.get = snd_dualsense_jack_get,
694
};
695
696
static int snd_dualsense_resume_jack(struct usb_mixer_elem_list *list)
697
{
698
snd_ctl_notify(list->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
699
&list->kctl->id);
700
return 0;
701
}
702
703
static void snd_dualsense_mixer_elem_free(struct snd_kcontrol *kctl)
704
{
705
struct dualsense_mixer_elem_info *mei = snd_kcontrol_chip(kctl);
706
707
if (mei->ih.event)
708
input_unregister_handler(&mei->ih);
709
710
snd_usb_mixer_elem_free(kctl);
711
}
712
713
static int snd_dualsense_jack_create(struct usb_mixer_interface *mixer,
714
const char *name, bool is_output)
715
{
716
struct dualsense_mixer_elem_info *mei;
717
struct input_device_id *idev_id;
718
struct snd_kcontrol *kctl;
719
int err;
720
721
mei = kzalloc(sizeof(*mei), GFP_KERNEL);
722
if (!mei)
723
return -ENOMEM;
724
725
snd_usb_mixer_elem_init_std(&mei->info.head, mixer,
726
is_output ? SND_DUALSENSE_JACK_OUT_TERM_ID :
727
SND_DUALSENSE_JACK_IN_TERM_ID);
728
729
mei->info.head.resume = snd_dualsense_resume_jack;
730
mei->info.val_type = USB_MIXER_BOOLEAN;
731
mei->info.channels = 1;
732
mei->info.min = 0;
733
mei->info.max = 1;
734
735
kctl = snd_ctl_new1(&snd_dualsense_jack_control, mei);
736
if (!kctl) {
737
kfree(mei);
738
return -ENOMEM;
739
}
740
741
strscpy(kctl->id.name, name, sizeof(kctl->id.name));
742
kctl->private_free = snd_dualsense_mixer_elem_free;
743
744
err = snd_usb_mixer_add_control(&mei->info.head, kctl);
745
if (err)
746
return err;
747
748
idev_id = &mei->id_table[0];
749
idev_id->flags = INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT |
750
INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT;
751
idev_id->vendor = USB_ID_VENDOR(mixer->chip->usb_id);
752
idev_id->product = USB_ID_PRODUCT(mixer->chip->usb_id);
753
idev_id->evbit[BIT_WORD(EV_SW)] = BIT_MASK(EV_SW);
754
if (is_output)
755
idev_id->swbit[BIT_WORD(SW_HEADPHONE_INSERT)] = BIT_MASK(SW_HEADPHONE_INSERT);
756
else
757
idev_id->swbit[BIT_WORD(SW_MICROPHONE_INSERT)] = BIT_MASK(SW_MICROPHONE_INSERT);
758
759
mei->ih.event = snd_dualsense_ih_event;
760
mei->ih.match = snd_dualsense_ih_match;
761
mei->ih.connect = snd_dualsense_ih_connect;
762
mei->ih.disconnect = snd_dualsense_ih_disconnect;
763
mei->ih.start = snd_dualsense_ih_start;
764
mei->ih.name = name;
765
mei->ih.id_table = mei->id_table;
766
767
err = input_register_handler(&mei->ih);
768
if (err) {
769
dev_warn(&mixer->chip->dev->dev,
770
"Could not register input handler: %d\n", err);
771
mei->ih.event = NULL;
772
}
773
774
return 0;
775
}
776
777
static int snd_dualsense_controls_create(struct usb_mixer_interface *mixer)
778
{
779
int err;
780
781
err = snd_dualsense_jack_create(mixer, "Headphone Jack", true);
782
if (err < 0)
783
return err;
784
785
return snd_dualsense_jack_create(mixer, "Headset Mic Jack", false);
786
}
787
#endif /* IS_REACHABLE(CONFIG_INPUT) */
788
789
/* ASUS Xonar U1 / U3 controls */
790
791
static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
792
struct snd_ctl_elem_value *ucontrol)
793
{
794
ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
795
return 0;
796
}
797
798
static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
799
unsigned char status)
800
{
801
struct snd_usb_audio *chip = mixer->chip;
802
803
CLASS(snd_usb_lock, pm)(chip);
804
if (pm.err < 0)
805
return pm.err;
806
return snd_usb_ctl_msg(chip->dev,
807
usb_sndctrlpipe(chip->dev, 0), 0x08,
808
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
809
50, 0, &status, 1);
810
}
811
812
static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
813
struct snd_ctl_elem_value *ucontrol)
814
{
815
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
816
u8 old_status, new_status;
817
int err;
818
819
old_status = kcontrol->private_value;
820
if (ucontrol->value.integer.value[0])
821
new_status = old_status | 0x02;
822
else
823
new_status = old_status & ~0x02;
824
if (new_status == old_status)
825
return 0;
826
827
kcontrol->private_value = new_status;
828
err = snd_xonar_u1_switch_update(list->mixer, new_status);
829
return err < 0 ? err : 1;
830
}
831
832
static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
833
{
834
return snd_xonar_u1_switch_update(list->mixer,
835
list->kctl->private_value);
836
}
837
838
static const struct snd_kcontrol_new snd_xonar_u1_output_switch = {
839
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
840
.name = "Digital Playback Switch",
841
.info = snd_ctl_boolean_mono_info,
842
.get = snd_xonar_u1_switch_get,
843
.put = snd_xonar_u1_switch_put,
844
.private_value = 0x05,
845
};
846
847
static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
848
{
849
return add_single_ctl_with_resume(mixer, 0,
850
snd_xonar_u1_switch_resume,
851
&snd_xonar_u1_output_switch, NULL);
852
}
853
854
/* Digidesign Mbox 1 helper functions */
855
856
static int snd_mbox1_is_spdif_synced(struct snd_usb_audio *chip)
857
{
858
unsigned char buff[3];
859
int err;
860
int is_spdif_synced;
861
862
/* Read clock source */
863
err = snd_usb_ctl_msg(chip->dev,
864
usb_rcvctrlpipe(chip->dev, 0), 0x81,
865
USB_DIR_IN |
866
USB_TYPE_CLASS |
867
USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
868
if (err < 0)
869
return err;
870
871
/* spdif sync: buff is all zeroes */
872
is_spdif_synced = !(buff[0] | buff[1] | buff[2]);
873
return is_spdif_synced;
874
}
875
876
static int snd_mbox1_set_clk_source(struct snd_usb_audio *chip, int rate_or_zero)
877
{
878
/* 2 possibilities: Internal -> expects sample rate
879
* S/PDIF sync -> expects rate = 0
880
*/
881
unsigned char buff[3];
882
883
buff[0] = (rate_or_zero >> 0) & 0xff;
884
buff[1] = (rate_or_zero >> 8) & 0xff;
885
buff[2] = (rate_or_zero >> 16) & 0xff;
886
887
/* Set clock source */
888
return snd_usb_ctl_msg(chip->dev,
889
usb_sndctrlpipe(chip->dev, 0), 0x1,
890
USB_TYPE_CLASS |
891
USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
892
}
893
894
static int snd_mbox1_is_spdif_input(struct snd_usb_audio *chip)
895
{
896
/* Hardware gives 2 possibilities: ANALOG Source -> 0x01
897
* S/PDIF Source -> 0x02
898
*/
899
int err;
900
unsigned char source[1];
901
902
/* Read input source */
903
err = snd_usb_ctl_msg(chip->dev,
904
usb_rcvctrlpipe(chip->dev, 0), 0x81,
905
USB_DIR_IN |
906
USB_TYPE_CLASS |
907
USB_RECIP_INTERFACE, 0x00, 0x500, source, 1);
908
if (err < 0)
909
return err;
910
911
return (source[0] == 2);
912
}
913
914
static int snd_mbox1_set_input_source(struct snd_usb_audio *chip, int is_spdif)
915
{
916
/* NB: Setting the input source to S/PDIF resets the clock source to S/PDIF
917
* Hardware expects 2 possibilities: ANALOG Source -> 0x01
918
* S/PDIF Source -> 0x02
919
*/
920
unsigned char buff[1];
921
922
buff[0] = (is_spdif & 1) + 1;
923
924
/* Set input source */
925
return snd_usb_ctl_msg(chip->dev,
926
usb_sndctrlpipe(chip->dev, 0), 0x1,
927
USB_TYPE_CLASS |
928
USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
929
}
930
931
/* Digidesign Mbox 1 clock source switch (internal/spdif) */
932
933
static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl,
934
struct snd_ctl_elem_value *ucontrol)
935
{
936
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
937
struct snd_usb_audio *chip = list->mixer->chip;
938
int err;
939
940
CLASS(snd_usb_lock, pm)(chip);
941
if (pm.err < 0)
942
return pm.err;
943
944
err = snd_mbox1_is_spdif_synced(chip);
945
if (err < 0)
946
return err;
947
948
kctl->private_value = err;
949
ucontrol->value.enumerated.item[0] = kctl->private_value;
950
return 0;
951
}
952
953
static int snd_mbox1_clk_switch_update(struct usb_mixer_interface *mixer, int is_spdif_sync)
954
{
955
struct snd_usb_audio *chip = mixer->chip;
956
int err;
957
958
CLASS(snd_usb_lock, pm)(chip);
959
if (pm.err < 0)
960
return pm.err;
961
962
err = snd_mbox1_is_spdif_input(chip);
963
if (err < 0)
964
return err;
965
966
err = snd_mbox1_is_spdif_synced(chip);
967
if (err < 0)
968
return err;
969
970
/* FIXME: hardcoded sample rate */
971
err = snd_mbox1_set_clk_source(chip, is_spdif_sync ? 0 : 48000);
972
if (err < 0)
973
return err;
974
975
return snd_mbox1_is_spdif_synced(chip);
976
}
977
978
static int snd_mbox1_clk_switch_put(struct snd_kcontrol *kctl,
979
struct snd_ctl_elem_value *ucontrol)
980
{
981
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
982
struct usb_mixer_interface *mixer = list->mixer;
983
int err;
984
bool cur_val, new_val;
985
986
cur_val = kctl->private_value;
987
new_val = ucontrol->value.enumerated.item[0];
988
if (cur_val == new_val)
989
return 0;
990
991
kctl->private_value = new_val;
992
err = snd_mbox1_clk_switch_update(mixer, new_val);
993
return err < 0 ? err : 1;
994
}
995
996
static int snd_mbox1_clk_switch_info(struct snd_kcontrol *kcontrol,
997
struct snd_ctl_elem_info *uinfo)
998
{
999
static const char *const texts[2] = {
1000
"Internal",
1001
"S/PDIF"
1002
};
1003
1004
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1005
}
1006
1007
static int snd_mbox1_clk_switch_resume(struct usb_mixer_elem_list *list)
1008
{
1009
return snd_mbox1_clk_switch_update(list->mixer, list->kctl->private_value);
1010
}
1011
1012
/* Digidesign Mbox 1 input source switch (analog/spdif) */
1013
1014
static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl,
1015
struct snd_ctl_elem_value *ucontrol)
1016
{
1017
ucontrol->value.enumerated.item[0] = kctl->private_value;
1018
return 0;
1019
}
1020
1021
static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int is_spdif_input)
1022
{
1023
struct snd_usb_audio *chip = mixer->chip;
1024
int err;
1025
1026
CLASS(snd_usb_lock, pm)(chip);
1027
if (pm.err < 0)
1028
return pm.err;
1029
1030
err = snd_mbox1_is_spdif_input(chip);
1031
if (err < 0)
1032
return err;
1033
1034
err = snd_mbox1_set_input_source(chip, is_spdif_input);
1035
if (err < 0)
1036
return err;
1037
1038
err = snd_mbox1_is_spdif_input(chip);
1039
if (err < 0)
1040
return err;
1041
1042
return snd_mbox1_is_spdif_synced(chip);
1043
}
1044
1045
static int snd_mbox1_src_switch_put(struct snd_kcontrol *kctl,
1046
struct snd_ctl_elem_value *ucontrol)
1047
{
1048
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
1049
struct usb_mixer_interface *mixer = list->mixer;
1050
int err;
1051
bool cur_val, new_val;
1052
1053
cur_val = kctl->private_value;
1054
new_val = ucontrol->value.enumerated.item[0];
1055
if (cur_val == new_val)
1056
return 0;
1057
1058
kctl->private_value = new_val;
1059
err = snd_mbox1_src_switch_update(mixer, new_val);
1060
return err < 0 ? err : 1;
1061
}
1062
1063
static int snd_mbox1_src_switch_info(struct snd_kcontrol *kcontrol,
1064
struct snd_ctl_elem_info *uinfo)
1065
{
1066
static const char *const texts[2] = {
1067
"Analog",
1068
"S/PDIF"
1069
};
1070
1071
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1072
}
1073
1074
static int snd_mbox1_src_switch_resume(struct usb_mixer_elem_list *list)
1075
{
1076
return snd_mbox1_src_switch_update(list->mixer, list->kctl->private_value);
1077
}
1078
1079
static const struct snd_kcontrol_new snd_mbox1_clk_switch = {
1080
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1081
.name = "Clock Source",
1082
.index = 0,
1083
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1084
.info = snd_mbox1_clk_switch_info,
1085
.get = snd_mbox1_clk_switch_get,
1086
.put = snd_mbox1_clk_switch_put,
1087
.private_value = 0
1088
};
1089
1090
static const struct snd_kcontrol_new snd_mbox1_src_switch = {
1091
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1092
.name = "Input Source",
1093
.index = 1,
1094
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1095
.info = snd_mbox1_src_switch_info,
1096
.get = snd_mbox1_src_switch_get,
1097
.put = snd_mbox1_src_switch_put,
1098
.private_value = 0
1099
};
1100
1101
static int snd_mbox1_controls_create(struct usb_mixer_interface *mixer)
1102
{
1103
int err;
1104
1105
err = add_single_ctl_with_resume(mixer, 0,
1106
snd_mbox1_clk_switch_resume,
1107
&snd_mbox1_clk_switch, NULL);
1108
if (err < 0)
1109
return err;
1110
1111
return add_single_ctl_with_resume(mixer, 1,
1112
snd_mbox1_src_switch_resume,
1113
&snd_mbox1_src_switch, NULL);
1114
}
1115
1116
/* Native Instruments device quirks */
1117
1118
#define _MAKE_NI_CONTROL(bRequest, wIndex) ((bRequest) << 16 | (wIndex))
1119
1120
static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
1121
struct snd_kcontrol *kctl)
1122
{
1123
struct usb_device *dev = mixer->chip->dev;
1124
unsigned int pval = kctl->private_value;
1125
u8 value;
1126
int err;
1127
1128
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1129
(pval >> 16) & 0xff,
1130
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
1131
0, pval & 0xffff, &value, 1);
1132
if (err < 0) {
1133
dev_err(&dev->dev,
1134
"unable to issue vendor read request (ret = %d)", err);
1135
return err;
1136
}
1137
1138
kctl->private_value |= ((unsigned int)value << 24);
1139
return 0;
1140
}
1141
1142
static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
1143
struct snd_ctl_elem_value *ucontrol)
1144
{
1145
ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
1146
return 0;
1147
}
1148
1149
static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
1150
{
1151
struct snd_usb_audio *chip = list->mixer->chip;
1152
unsigned int pval = list->kctl->private_value;
1153
1154
CLASS(snd_usb_lock, pm)(chip);
1155
if (pm.err < 0)
1156
return pm.err;
1157
return usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
1158
(pval >> 16) & 0xff,
1159
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
1160
pval >> 24, pval & 0xffff, NULL, 0, 1000);
1161
}
1162
1163
static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
1164
struct snd_ctl_elem_value *ucontrol)
1165
{
1166
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1167
u8 oldval = (kcontrol->private_value >> 24) & 0xff;
1168
u8 newval = ucontrol->value.integer.value[0];
1169
int err;
1170
1171
if (oldval == newval)
1172
return 0;
1173
1174
kcontrol->private_value &= ~(0xff << 24);
1175
kcontrol->private_value |= (unsigned int)newval << 24;
1176
err = snd_ni_update_cur_val(list);
1177
return err < 0 ? err : 1;
1178
}
1179
1180
static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
1181
{
1182
.name = "Direct Thru Channel A",
1183
.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
1184
},
1185
{
1186
.name = "Direct Thru Channel B",
1187
.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
1188
},
1189
{
1190
.name = "Phono Input Channel A",
1191
.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
1192
},
1193
{
1194
.name = "Phono Input Channel B",
1195
.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
1196
},
1197
};
1198
1199
static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
1200
{
1201
.name = "Direct Thru Channel A",
1202
.private_value = _MAKE_NI_CONTROL(0x01, 0x03),
1203
},
1204
{
1205
.name = "Direct Thru Channel B",
1206
.private_value = _MAKE_NI_CONTROL(0x01, 0x05),
1207
},
1208
{
1209
.name = "Direct Thru Channel C",
1210
.private_value = _MAKE_NI_CONTROL(0x01, 0x07),
1211
},
1212
{
1213
.name = "Direct Thru Channel D",
1214
.private_value = _MAKE_NI_CONTROL(0x01, 0x09),
1215
},
1216
{
1217
.name = "Phono Input Channel A",
1218
.private_value = _MAKE_NI_CONTROL(0x02, 0x03),
1219
},
1220
{
1221
.name = "Phono Input Channel B",
1222
.private_value = _MAKE_NI_CONTROL(0x02, 0x05),
1223
},
1224
{
1225
.name = "Phono Input Channel C",
1226
.private_value = _MAKE_NI_CONTROL(0x02, 0x07),
1227
},
1228
{
1229
.name = "Phono Input Channel D",
1230
.private_value = _MAKE_NI_CONTROL(0x02, 0x09),
1231
},
1232
};
1233
1234
static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
1235
const struct snd_kcontrol_new *kc,
1236
unsigned int count)
1237
{
1238
int i, err = 0;
1239
struct snd_kcontrol_new template = {
1240
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1241
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1242
.get = snd_nativeinstruments_control_get,
1243
.put = snd_nativeinstruments_control_put,
1244
.info = snd_ctl_boolean_mono_info,
1245
};
1246
1247
for (i = 0; i < count; i++) {
1248
struct usb_mixer_elem_list *list;
1249
1250
template.name = kc[i].name;
1251
template.private_value = kc[i].private_value;
1252
1253
err = add_single_ctl_with_resume(mixer, 0,
1254
snd_ni_update_cur_val,
1255
&template, &list);
1256
if (err < 0)
1257
break;
1258
snd_ni_control_init_val(mixer, list->kctl);
1259
}
1260
1261
return err;
1262
}
1263
1264
/* M-Audio FastTrack Ultra quirks */
1265
/* FTU Effect switch (also used by C400/C600) */
1266
static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
1267
struct snd_ctl_elem_info *uinfo)
1268
{
1269
static const char *const texts[8] = {
1270
"Room 1", "Room 2", "Room 3", "Hall 1",
1271
"Hall 2", "Plate", "Delay", "Echo"
1272
};
1273
1274
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1275
}
1276
1277
static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
1278
struct snd_kcontrol *kctl)
1279
{
1280
struct usb_device *dev = mixer->chip->dev;
1281
unsigned int pval = kctl->private_value;
1282
int err;
1283
unsigned char value[2];
1284
1285
value[0] = 0x00;
1286
value[1] = 0x00;
1287
1288
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
1289
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1290
pval & 0xff00,
1291
snd_usb_ctrl_intf(mixer->hostif) | ((pval & 0xff) << 8),
1292
value, 2);
1293
if (err < 0)
1294
return err;
1295
1296
kctl->private_value |= (unsigned int)value[0] << 24;
1297
return 0;
1298
}
1299
1300
static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
1301
struct snd_ctl_elem_value *ucontrol)
1302
{
1303
ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
1304
return 0;
1305
}
1306
1307
static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
1308
{
1309
struct snd_usb_audio *chip = list->mixer->chip;
1310
unsigned int pval = list->kctl->private_value;
1311
unsigned char value[2];
1312
1313
value[0] = pval >> 24;
1314
value[1] = 0;
1315
1316
CLASS(snd_usb_lock, pm)(chip);
1317
if (pm.err < 0)
1318
return pm.err;
1319
return snd_usb_ctl_msg(chip->dev,
1320
usb_sndctrlpipe(chip->dev, 0),
1321
UAC_SET_CUR,
1322
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1323
pval & 0xff00,
1324
snd_usb_ctrl_intf(list->mixer->hostif) | ((pval & 0xff) << 8),
1325
value, 2);
1326
}
1327
1328
static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
1329
struct snd_ctl_elem_value *ucontrol)
1330
{
1331
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
1332
unsigned int pval = list->kctl->private_value;
1333
int cur_val, err, new_val;
1334
1335
cur_val = pval >> 24;
1336
new_val = ucontrol->value.enumerated.item[0];
1337
if (cur_val == new_val)
1338
return 0;
1339
1340
kctl->private_value &= ~(0xff << 24);
1341
kctl->private_value |= new_val << 24;
1342
err = snd_ftu_eff_switch_update(list);
1343
return err < 0 ? err : 1;
1344
}
1345
1346
static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
1347
int validx, int bUnitID)
1348
{
1349
static struct snd_kcontrol_new template = {
1350
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1351
.name = "Effect Program Switch",
1352
.index = 0,
1353
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1354
.info = snd_ftu_eff_switch_info,
1355
.get = snd_ftu_eff_switch_get,
1356
.put = snd_ftu_eff_switch_put
1357
};
1358
struct usb_mixer_elem_list *list;
1359
int err;
1360
1361
err = add_single_ctl_with_resume(mixer, bUnitID,
1362
snd_ftu_eff_switch_update,
1363
&template, &list);
1364
if (err < 0)
1365
return err;
1366
list->kctl->private_value = (validx << 8) | bUnitID;
1367
snd_ftu_eff_switch_init(mixer, list->kctl);
1368
return 0;
1369
}
1370
1371
/* Create volume controls for FTU devices*/
1372
static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
1373
{
1374
char name[64];
1375
unsigned int control, cmask;
1376
int in, out, err;
1377
1378
const unsigned int id = 5;
1379
const int val_type = USB_MIXER_S16;
1380
1381
for (out = 0; out < 8; out++) {
1382
control = out + 1;
1383
for (in = 0; in < 8; in++) {
1384
cmask = BIT(in);
1385
snprintf(name, sizeof(name),
1386
"AIn%d - Out%d Capture Volume",
1387
in + 1, out + 1);
1388
err = snd_create_std_mono_ctl(mixer, id, control,
1389
cmask, val_type, name,
1390
&snd_usb_mixer_vol_tlv);
1391
if (err < 0)
1392
return err;
1393
}
1394
for (in = 8; in < 16; in++) {
1395
cmask = BIT(in);
1396
snprintf(name, sizeof(name),
1397
"DIn%d - Out%d Playback Volume",
1398
in - 7, out + 1);
1399
err = snd_create_std_mono_ctl(mixer, id, control,
1400
cmask, val_type, name,
1401
&snd_usb_mixer_vol_tlv);
1402
if (err < 0)
1403
return err;
1404
}
1405
}
1406
1407
return 0;
1408
}
1409
1410
/* This control needs a volume quirk, see mixer.c */
1411
static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1412
{
1413
static const char name[] = "Effect Volume";
1414
const unsigned int id = 6;
1415
const int val_type = USB_MIXER_U8;
1416
const unsigned int control = 2;
1417
const unsigned int cmask = 0;
1418
1419
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1420
name, snd_usb_mixer_vol_tlv);
1421
}
1422
1423
/* This control needs a volume quirk, see mixer.c */
1424
static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1425
{
1426
static const char name[] = "Effect Duration";
1427
const unsigned int id = 6;
1428
const int val_type = USB_MIXER_S16;
1429
const unsigned int control = 3;
1430
const unsigned int cmask = 0;
1431
1432
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1433
name, snd_usb_mixer_vol_tlv);
1434
}
1435
1436
/* This control needs a volume quirk, see mixer.c */
1437
static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1438
{
1439
static const char name[] = "Effect Feedback Volume";
1440
const unsigned int id = 6;
1441
const int val_type = USB_MIXER_U8;
1442
const unsigned int control = 4;
1443
const unsigned int cmask = 0;
1444
1445
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1446
name, NULL);
1447
}
1448
1449
static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1450
{
1451
unsigned int cmask;
1452
int err, ch;
1453
char name[48];
1454
1455
const unsigned int id = 7;
1456
const int val_type = USB_MIXER_S16;
1457
const unsigned int control = 7;
1458
1459
for (ch = 0; ch < 4; ++ch) {
1460
cmask = BIT(ch);
1461
snprintf(name, sizeof(name),
1462
"Effect Return %d Volume", ch + 1);
1463
err = snd_create_std_mono_ctl(mixer, id, control,
1464
cmask, val_type, name,
1465
snd_usb_mixer_vol_tlv);
1466
if (err < 0)
1467
return err;
1468
}
1469
1470
return 0;
1471
}
1472
1473
static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1474
{
1475
unsigned int cmask;
1476
int err, ch;
1477
char name[48];
1478
1479
const unsigned int id = 5;
1480
const int val_type = USB_MIXER_S16;
1481
const unsigned int control = 9;
1482
1483
for (ch = 0; ch < 8; ++ch) {
1484
cmask = BIT(ch);
1485
snprintf(name, sizeof(name),
1486
"Effect Send AIn%d Volume", ch + 1);
1487
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1488
val_type, name,
1489
snd_usb_mixer_vol_tlv);
1490
if (err < 0)
1491
return err;
1492
}
1493
for (ch = 8; ch < 16; ++ch) {
1494
cmask = BIT(ch);
1495
snprintf(name, sizeof(name),
1496
"Effect Send DIn%d Volume", ch - 7);
1497
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1498
val_type, name,
1499
snd_usb_mixer_vol_tlv);
1500
if (err < 0)
1501
return err;
1502
}
1503
return 0;
1504
}
1505
1506
static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1507
{
1508
int err;
1509
1510
err = snd_ftu_create_volume_ctls(mixer);
1511
if (err < 0)
1512
return err;
1513
1514
err = snd_ftu_create_effect_switch(mixer, 1, 6);
1515
if (err < 0)
1516
return err;
1517
1518
err = snd_ftu_create_effect_volume_ctl(mixer);
1519
if (err < 0)
1520
return err;
1521
1522
err = snd_ftu_create_effect_duration_ctl(mixer);
1523
if (err < 0)
1524
return err;
1525
1526
err = snd_ftu_create_effect_feedback_ctl(mixer);
1527
if (err < 0)
1528
return err;
1529
1530
err = snd_ftu_create_effect_return_ctls(mixer);
1531
if (err < 0)
1532
return err;
1533
1534
err = snd_ftu_create_effect_send_ctls(mixer);
1535
if (err < 0)
1536
return err;
1537
1538
return 0;
1539
}
1540
1541
void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1542
unsigned char samplerate_id)
1543
{
1544
struct usb_mixer_interface *mixer;
1545
struct usb_mixer_elem_info *cval;
1546
int unitid = 12; /* SampleRate ExtensionUnit ID */
1547
1548
list_for_each_entry(mixer, &chip->mixer_list, list) {
1549
if (mixer->id_elems[unitid]) {
1550
cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1551
snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1552
cval->control << 8,
1553
samplerate_id);
1554
snd_usb_mixer_notify_id(mixer, unitid);
1555
break;
1556
}
1557
}
1558
}
1559
1560
/* M-Audio Fast Track C400/C600 */
1561
/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1562
static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1563
{
1564
char name[64];
1565
unsigned int cmask, offset;
1566
int out, chan, err;
1567
int num_outs = 0;
1568
int num_ins = 0;
1569
1570
const unsigned int id = 0x40;
1571
const int val_type = USB_MIXER_S16;
1572
const int control = 1;
1573
1574
switch (mixer->chip->usb_id) {
1575
case USB_ID(0x0763, 0x2030):
1576
num_outs = 6;
1577
num_ins = 4;
1578
break;
1579
case USB_ID(0x0763, 0x2031):
1580
num_outs = 8;
1581
num_ins = 6;
1582
break;
1583
}
1584
1585
for (chan = 0; chan < num_outs + num_ins; chan++) {
1586
for (out = 0; out < num_outs; out++) {
1587
if (chan < num_outs) {
1588
snprintf(name, sizeof(name),
1589
"PCM%d-Out%d Playback Volume",
1590
chan + 1, out + 1);
1591
} else {
1592
snprintf(name, sizeof(name),
1593
"In%d-Out%d Playback Volume",
1594
chan - num_outs + 1, out + 1);
1595
}
1596
1597
cmask = (out == 0) ? 0 : BIT(out - 1);
1598
offset = chan * num_outs;
1599
err = snd_create_std_mono_ctl_offset(mixer, id, control,
1600
cmask, val_type, offset, name,
1601
&snd_usb_mixer_vol_tlv);
1602
if (err < 0)
1603
return err;
1604
}
1605
}
1606
1607
return 0;
1608
}
1609
1610
/* This control needs a volume quirk, see mixer.c */
1611
static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1612
{
1613
static const char name[] = "Effect Volume";
1614
const unsigned int id = 0x43;
1615
const int val_type = USB_MIXER_U8;
1616
const unsigned int control = 3;
1617
const unsigned int cmask = 0;
1618
1619
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1620
name, snd_usb_mixer_vol_tlv);
1621
}
1622
1623
/* This control needs a volume quirk, see mixer.c */
1624
static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1625
{
1626
static const char name[] = "Effect Duration";
1627
const unsigned int id = 0x43;
1628
const int val_type = USB_MIXER_S16;
1629
const unsigned int control = 4;
1630
const unsigned int cmask = 0;
1631
1632
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1633
name, snd_usb_mixer_vol_tlv);
1634
}
1635
1636
/* This control needs a volume quirk, see mixer.c */
1637
static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1638
{
1639
static const char name[] = "Effect Feedback Volume";
1640
const unsigned int id = 0x43;
1641
const int val_type = USB_MIXER_U8;
1642
const unsigned int control = 5;
1643
const unsigned int cmask = 0;
1644
1645
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1646
name, NULL);
1647
}
1648
1649
static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1650
{
1651
char name[64];
1652
unsigned int cmask;
1653
int chan, err;
1654
int num_outs = 0;
1655
int num_ins = 0;
1656
1657
const unsigned int id = 0x42;
1658
const int val_type = USB_MIXER_S16;
1659
const int control = 1;
1660
1661
switch (mixer->chip->usb_id) {
1662
case USB_ID(0x0763, 0x2030):
1663
num_outs = 6;
1664
num_ins = 4;
1665
break;
1666
case USB_ID(0x0763, 0x2031):
1667
num_outs = 8;
1668
num_ins = 6;
1669
break;
1670
}
1671
1672
for (chan = 0; chan < num_outs + num_ins; chan++) {
1673
if (chan < num_outs) {
1674
snprintf(name, sizeof(name),
1675
"Effect Send DOut%d",
1676
chan + 1);
1677
} else {
1678
snprintf(name, sizeof(name),
1679
"Effect Send AIn%d",
1680
chan - num_outs + 1);
1681
}
1682
1683
cmask = (chan == 0) ? 0 : BIT(chan - 1);
1684
err = snd_create_std_mono_ctl(mixer, id, control,
1685
cmask, val_type, name,
1686
&snd_usb_mixer_vol_tlv);
1687
if (err < 0)
1688
return err;
1689
}
1690
1691
return 0;
1692
}
1693
1694
static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1695
{
1696
char name[64];
1697
unsigned int cmask;
1698
int chan, err;
1699
int num_outs = 0;
1700
int offset = 0;
1701
1702
const unsigned int id = 0x40;
1703
const int val_type = USB_MIXER_S16;
1704
const int control = 1;
1705
1706
switch (mixer->chip->usb_id) {
1707
case USB_ID(0x0763, 0x2030):
1708
num_outs = 6;
1709
offset = 0x3c;
1710
/* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1711
break;
1712
case USB_ID(0x0763, 0x2031):
1713
num_outs = 8;
1714
offset = 0x70;
1715
/* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1716
break;
1717
}
1718
1719
for (chan = 0; chan < num_outs; chan++) {
1720
snprintf(name, sizeof(name),
1721
"Effect Return %d",
1722
chan + 1);
1723
1724
cmask = (chan == 0) ? 0 :
1725
BIT(chan + (chan % 2) * num_outs - 1);
1726
err = snd_create_std_mono_ctl_offset(mixer, id, control,
1727
cmask, val_type, offset, name,
1728
&snd_usb_mixer_vol_tlv);
1729
if (err < 0)
1730
return err;
1731
}
1732
1733
return 0;
1734
}
1735
1736
static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1737
{
1738
int err;
1739
1740
err = snd_c400_create_vol_ctls(mixer);
1741
if (err < 0)
1742
return err;
1743
1744
err = snd_c400_create_effect_vol_ctls(mixer);
1745
if (err < 0)
1746
return err;
1747
1748
err = snd_c400_create_effect_ret_vol_ctls(mixer);
1749
if (err < 0)
1750
return err;
1751
1752
err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1753
if (err < 0)
1754
return err;
1755
1756
err = snd_c400_create_effect_volume_ctl(mixer);
1757
if (err < 0)
1758
return err;
1759
1760
err = snd_c400_create_effect_duration_ctl(mixer);
1761
if (err < 0)
1762
return err;
1763
1764
err = snd_c400_create_effect_feedback_ctl(mixer);
1765
if (err < 0)
1766
return err;
1767
1768
return 0;
1769
}
1770
1771
/*
1772
* The mixer units for Ebox-44 are corrupt, and even where they
1773
* are valid they presents mono controls as L and R channels of
1774
* stereo. So we provide a good mixer here.
1775
*/
1776
static const struct std_mono_table ebox44_table[] = {
1777
{
1778
.unitid = 4,
1779
.control = 1,
1780
.cmask = 0x0,
1781
.val_type = USB_MIXER_INV_BOOLEAN,
1782
.name = "Headphone Playback Switch"
1783
},
1784
{
1785
.unitid = 4,
1786
.control = 2,
1787
.cmask = 0x1,
1788
.val_type = USB_MIXER_S16,
1789
.name = "Headphone A Mix Playback Volume"
1790
},
1791
{
1792
.unitid = 4,
1793
.control = 2,
1794
.cmask = 0x2,
1795
.val_type = USB_MIXER_S16,
1796
.name = "Headphone B Mix Playback Volume"
1797
},
1798
1799
{
1800
.unitid = 7,
1801
.control = 1,
1802
.cmask = 0x0,
1803
.val_type = USB_MIXER_INV_BOOLEAN,
1804
.name = "Output Playback Switch"
1805
},
1806
{
1807
.unitid = 7,
1808
.control = 2,
1809
.cmask = 0x1,
1810
.val_type = USB_MIXER_S16,
1811
.name = "Output A Playback Volume"
1812
},
1813
{
1814
.unitid = 7,
1815
.control = 2,
1816
.cmask = 0x2,
1817
.val_type = USB_MIXER_S16,
1818
.name = "Output B Playback Volume"
1819
},
1820
1821
{
1822
.unitid = 10,
1823
.control = 1,
1824
.cmask = 0x0,
1825
.val_type = USB_MIXER_INV_BOOLEAN,
1826
.name = "Input Capture Switch"
1827
},
1828
{
1829
.unitid = 10,
1830
.control = 2,
1831
.cmask = 0x1,
1832
.val_type = USB_MIXER_S16,
1833
.name = "Input A Capture Volume"
1834
},
1835
{
1836
.unitid = 10,
1837
.control = 2,
1838
.cmask = 0x2,
1839
.val_type = USB_MIXER_S16,
1840
.name = "Input B Capture Volume"
1841
},
1842
1843
{}
1844
};
1845
1846
/* Audio Advantage Micro II findings:
1847
*
1848
* Mapping spdif AES bits to vendor register.bit:
1849
* AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00
1850
* AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01
1851
* AES2: [0 0 0 0 0 0 0 0]
1852
* AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request
1853
* (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices
1854
*
1855
* power on values:
1856
* r2: 0x10
1857
* r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set
1858
* just after it to 0xa0, presumably it disables/mutes some analog
1859
* parts when there is no audio.)
1860
* r9: 0x28
1861
*
1862
* Optical transmitter on/off:
1863
* vendor register.bit: 9.1
1864
* 0 - on (0x28 register value)
1865
* 1 - off (0x2a register value)
1866
*
1867
*/
1868
static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1869
struct snd_ctl_elem_info *uinfo)
1870
{
1871
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1872
uinfo->count = 1;
1873
return 0;
1874
}
1875
1876
static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1877
struct snd_ctl_elem_value *ucontrol)
1878
{
1879
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1880
struct snd_usb_audio *chip = list->mixer->chip;
1881
int err;
1882
struct usb_interface *iface;
1883
struct usb_host_interface *alts;
1884
unsigned int ep;
1885
unsigned char data[3];
1886
int rate;
1887
1888
CLASS(snd_usb_lock, pm)(chip);
1889
if (pm.err < 0)
1890
return pm.err;
1891
1892
ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1893
ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1894
ucontrol->value.iec958.status[2] = 0x00;
1895
1896
/* use known values for that card: interface#1 altsetting#1 */
1897
iface = usb_ifnum_to_if(chip->dev, 1);
1898
if (!iface || iface->num_altsetting < 2)
1899
return -EINVAL;
1900
alts = &iface->altsetting[1];
1901
if (get_iface_desc(alts)->bNumEndpoints < 1)
1902
return -EINVAL;
1903
ep = get_endpoint(alts, 0)->bEndpointAddress;
1904
1905
err = snd_usb_ctl_msg(chip->dev,
1906
usb_rcvctrlpipe(chip->dev, 0),
1907
UAC_GET_CUR,
1908
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1909
UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1910
ep,
1911
data,
1912
sizeof(data));
1913
if (err < 0)
1914
return err;
1915
1916
rate = data[0] | (data[1] << 8) | (data[2] << 16);
1917
ucontrol->value.iec958.status[3] = (rate == 48000) ?
1918
IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1919
1920
return 0;
1921
}
1922
1923
static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1924
{
1925
struct snd_usb_audio *chip = list->mixer->chip;
1926
unsigned int pval = list->kctl->private_value;
1927
u8 reg;
1928
int err;
1929
1930
CLASS(snd_usb_lock, pm)(chip);
1931
if (pm.err < 0)
1932
return pm.err;
1933
1934
reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1935
err = snd_usb_ctl_msg(chip->dev,
1936
usb_sndctrlpipe(chip->dev, 0),
1937
UAC_SET_CUR,
1938
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1939
reg,
1940
2,
1941
NULL,
1942
0);
1943
if (err < 0)
1944
return err;
1945
1946
reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1947
reg |= (pval >> 12) & 0x0f;
1948
err = snd_usb_ctl_msg(chip->dev,
1949
usb_sndctrlpipe(chip->dev, 0),
1950
UAC_SET_CUR,
1951
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1952
reg,
1953
3,
1954
NULL,
1955
0);
1956
return err;
1957
}
1958
1959
static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1960
struct snd_ctl_elem_value *ucontrol)
1961
{
1962
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1963
unsigned int pval, pval_old;
1964
int err;
1965
1966
pval = kcontrol->private_value;
1967
pval_old = pval;
1968
pval &= 0xfffff0f0;
1969
pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1970
pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1971
1972
pval &= 0xffff0fff;
1973
pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1974
1975
/* The frequency bits in AES3 cannot be set via register access. */
1976
1977
/* Silently ignore any bits from the request that cannot be set. */
1978
1979
if (pval == pval_old)
1980
return 0;
1981
1982
kcontrol->private_value = pval;
1983
err = snd_microii_spdif_default_update(list);
1984
return err < 0 ? err : 1;
1985
}
1986
1987
static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1988
struct snd_ctl_elem_value *ucontrol)
1989
{
1990
ucontrol->value.iec958.status[0] = 0x0f;
1991
ucontrol->value.iec958.status[1] = 0xff;
1992
ucontrol->value.iec958.status[2] = 0x00;
1993
ucontrol->value.iec958.status[3] = 0x00;
1994
1995
return 0;
1996
}
1997
1998
static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1999
struct snd_ctl_elem_value *ucontrol)
2000
{
2001
ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
2002
2003
return 0;
2004
}
2005
2006
static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
2007
{
2008
struct snd_usb_audio *chip = list->mixer->chip;
2009
u8 reg = list->kctl->private_value;
2010
2011
CLASS(snd_usb_lock, pm)(chip);
2012
if (pm.err < 0)
2013
return pm.err;
2014
2015
return snd_usb_ctl_msg(chip->dev,
2016
usb_sndctrlpipe(chip->dev, 0),
2017
UAC_SET_CUR,
2018
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2019
reg,
2020
9,
2021
NULL,
2022
0);
2023
}
2024
2025
static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
2026
struct snd_ctl_elem_value *ucontrol)
2027
{
2028
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2029
u8 reg;
2030
int err;
2031
2032
reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
2033
if (reg != list->kctl->private_value)
2034
return 0;
2035
2036
kcontrol->private_value = reg;
2037
err = snd_microii_spdif_switch_update(list);
2038
return err < 0 ? err : 1;
2039
}
2040
2041
static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
2042
{
2043
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
2044
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2045
.info = snd_microii_spdif_info,
2046
.get = snd_microii_spdif_default_get,
2047
.put = snd_microii_spdif_default_put,
2048
.private_value = 0x00000100UL,/* reset value */
2049
},
2050
{
2051
.access = SNDRV_CTL_ELEM_ACCESS_READ,
2052
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
2053
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
2054
.info = snd_microii_spdif_info,
2055
.get = snd_microii_spdif_mask_get,
2056
},
2057
{
2058
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2059
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2060
.info = snd_ctl_boolean_mono_info,
2061
.get = snd_microii_spdif_switch_get,
2062
.put = snd_microii_spdif_switch_put,
2063
.private_value = 0x00000028UL,/* reset value */
2064
}
2065
};
2066
2067
static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
2068
{
2069
int err, i;
2070
static const usb_mixer_elem_resume_func_t resume_funcs[] = {
2071
snd_microii_spdif_default_update,
2072
NULL,
2073
snd_microii_spdif_switch_update
2074
};
2075
2076
for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
2077
err = add_single_ctl_with_resume(mixer, 0,
2078
resume_funcs[i],
2079
&snd_microii_mixer_spdif[i],
2080
NULL);
2081
if (err < 0)
2082
return err;
2083
}
2084
2085
return 0;
2086
}
2087
2088
/* Creative Sound Blaster E1 */
2089
2090
static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
2091
struct snd_ctl_elem_value *ucontrol)
2092
{
2093
ucontrol->value.integer.value[0] = kcontrol->private_value;
2094
return 0;
2095
}
2096
2097
static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
2098
unsigned char state)
2099
{
2100
struct snd_usb_audio *chip = mixer->chip;
2101
unsigned char buff[2];
2102
2103
buff[0] = 0x02;
2104
buff[1] = state ? 0x02 : 0x00;
2105
2106
CLASS(snd_usb_lock, pm)(chip);
2107
if (pm.err < 0)
2108
return pm.err;
2109
return snd_usb_ctl_msg(chip->dev,
2110
usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
2111
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
2112
0x0202, 3, buff, 2);
2113
}
2114
2115
static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
2116
struct snd_ctl_elem_value *ucontrol)
2117
{
2118
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2119
unsigned char value = !!ucontrol->value.integer.value[0];
2120
int err;
2121
2122
if (kcontrol->private_value == value)
2123
return 0;
2124
kcontrol->private_value = value;
2125
err = snd_soundblaster_e1_switch_update(list->mixer, value);
2126
return err < 0 ? err : 1;
2127
}
2128
2129
static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
2130
{
2131
return snd_soundblaster_e1_switch_update(list->mixer,
2132
list->kctl->private_value);
2133
}
2134
2135
static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
2136
struct snd_ctl_elem_info *uinfo)
2137
{
2138
static const char *const texts[2] = {
2139
"Mic", "Aux"
2140
};
2141
2142
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
2143
}
2144
2145
static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
2146
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2147
.name = "Input Source",
2148
.info = snd_soundblaster_e1_switch_info,
2149
.get = snd_soundblaster_e1_switch_get,
2150
.put = snd_soundblaster_e1_switch_put,
2151
.private_value = 0,
2152
};
2153
2154
static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
2155
{
2156
return add_single_ctl_with_resume(mixer, 0,
2157
snd_soundblaster_e1_switch_resume,
2158
&snd_soundblaster_e1_input_switch,
2159
NULL);
2160
}
2161
2162
/*
2163
* Dell WD15 dock jack detection
2164
*
2165
* The WD15 contains an ALC4020 USB audio controller and ALC3263 audio codec
2166
* from Realtek. It is a UAC 1 device, and UAC 1 does not support jack
2167
* detection. Instead, jack detection works by sending HD Audio commands over
2168
* vendor-type USB messages.
2169
*/
2170
2171
#define HDA_VERB_CMD(V, N, D) (((N) << 20) | ((V) << 8) | (D))
2172
2173
#define REALTEK_HDA_VALUE 0x0038
2174
2175
#define REALTEK_HDA_SET 62
2176
#define REALTEK_MANUAL_MODE 72
2177
#define REALTEK_HDA_GET_OUT 88
2178
#define REALTEK_HDA_GET_IN 89
2179
2180
#define REALTEK_AUDIO_FUNCTION_GROUP 0x01
2181
#define REALTEK_LINE1 0x1a
2182
#define REALTEK_VENDOR_REGISTERS 0x20
2183
#define REALTEK_HP_OUT 0x21
2184
2185
#define REALTEK_CBJ_CTRL2 0x50
2186
2187
#define REALTEK_JACK_INTERRUPT_NODE 5
2188
2189
#define REALTEK_MIC_FLAG 0x100
2190
2191
static int realtek_hda_set(struct snd_usb_audio *chip, u32 cmd)
2192
{
2193
struct usb_device *dev = chip->dev;
2194
__be32 buf = cpu_to_be32(cmd);
2195
2196
return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_SET,
2197
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT,
2198
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf));
2199
}
2200
2201
static int realtek_hda_get(struct snd_usb_audio *chip, u32 cmd, u32 *value)
2202
{
2203
struct usb_device *dev = chip->dev;
2204
int err;
2205
__be32 buf = cpu_to_be32(cmd);
2206
2207
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_GET_OUT,
2208
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT,
2209
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf));
2210
if (err < 0)
2211
return err;
2212
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), REALTEK_HDA_GET_IN,
2213
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_IN,
2214
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf));
2215
if (err < 0)
2216
return err;
2217
2218
*value = be32_to_cpu(buf);
2219
return 0;
2220
}
2221
2222
static int realtek_ctl_connector_get(struct snd_kcontrol *kcontrol,
2223
struct snd_ctl_elem_value *ucontrol)
2224
{
2225
struct usb_mixer_elem_info *cval = snd_kcontrol_chip(kcontrol);
2226
struct snd_usb_audio *chip = cval->head.mixer->chip;
2227
u32 pv = kcontrol->private_value;
2228
u32 node_id = pv & 0xff;
2229
u32 sense;
2230
u32 cbj_ctrl2;
2231
bool presence;
2232
int err;
2233
2234
CLASS(snd_usb_lock, pm)(chip);
2235
if (pm.err < 0)
2236
return pm.err;
2237
err = realtek_hda_get(chip,
2238
HDA_VERB_CMD(AC_VERB_GET_PIN_SENSE, node_id, 0),
2239
&sense);
2240
if (err < 0)
2241
return err;
2242
if (pv & REALTEK_MIC_FLAG) {
2243
err = realtek_hda_set(chip,
2244
HDA_VERB_CMD(AC_VERB_SET_COEF_INDEX,
2245
REALTEK_VENDOR_REGISTERS,
2246
REALTEK_CBJ_CTRL2));
2247
if (err < 0)
2248
return err;
2249
err = realtek_hda_get(chip,
2250
HDA_VERB_CMD(AC_VERB_GET_PROC_COEF,
2251
REALTEK_VENDOR_REGISTERS, 0),
2252
&cbj_ctrl2);
2253
if (err < 0)
2254
return err;
2255
}
2256
2257
presence = sense & AC_PINSENSE_PRESENCE;
2258
if (pv & REALTEK_MIC_FLAG)
2259
presence = presence && (cbj_ctrl2 & 0x0070) == 0x0070;
2260
ucontrol->value.integer.value[0] = presence;
2261
return 0;
2262
}
2263
2264
static const struct snd_kcontrol_new realtek_connector_ctl_ro = {
2265
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
2266
.name = "", /* will be filled later manually */
2267
.access = SNDRV_CTL_ELEM_ACCESS_READ,
2268
.info = snd_ctl_boolean_mono_info,
2269
.get = realtek_ctl_connector_get,
2270
};
2271
2272
static int realtek_resume_jack(struct usb_mixer_elem_list *list)
2273
{
2274
snd_ctl_notify(list->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
2275
&list->kctl->id);
2276
return 0;
2277
}
2278
2279
static int realtek_add_jack(struct usb_mixer_interface *mixer,
2280
char *name, u32 val)
2281
{
2282
struct usb_mixer_elem_info *cval;
2283
struct snd_kcontrol *kctl;
2284
2285
cval = kzalloc(sizeof(*cval), GFP_KERNEL);
2286
if (!cval)
2287
return -ENOMEM;
2288
snd_usb_mixer_elem_init_std(&cval->head, mixer,
2289
REALTEK_JACK_INTERRUPT_NODE);
2290
cval->head.resume = realtek_resume_jack;
2291
cval->val_type = USB_MIXER_BOOLEAN;
2292
cval->channels = 1;
2293
cval->min = 0;
2294
cval->max = 1;
2295
kctl = snd_ctl_new1(&realtek_connector_ctl_ro, cval);
2296
if (!kctl) {
2297
kfree(cval);
2298
return -ENOMEM;
2299
}
2300
kctl->private_value = val;
2301
strscpy(kctl->id.name, name, sizeof(kctl->id.name));
2302
kctl->private_free = snd_usb_mixer_elem_free;
2303
return snd_usb_mixer_add_control(&cval->head, kctl);
2304
}
2305
2306
static int dell_dock_mixer_create(struct usb_mixer_interface *mixer)
2307
{
2308
int err;
2309
struct usb_device *dev = mixer->chip->dev;
2310
2311
/* Power down the audio codec to avoid loud pops in the next step. */
2312
realtek_hda_set(mixer->chip,
2313
HDA_VERB_CMD(AC_VERB_SET_POWER_STATE,
2314
REALTEK_AUDIO_FUNCTION_GROUP,
2315
AC_PWRST_D3));
2316
2317
/*
2318
* Turn off 'manual mode' in case it was enabled. This removes the need
2319
* to power cycle the dock after it was attached to a Windows machine.
2320
*/
2321
snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_MANUAL_MODE,
2322
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT,
2323
0, 0, NULL, 0);
2324
2325
err = realtek_add_jack(mixer, "Line Out Jack", REALTEK_LINE1);
2326
if (err < 0)
2327
return err;
2328
err = realtek_add_jack(mixer, "Headphone Jack", REALTEK_HP_OUT);
2329
if (err < 0)
2330
return err;
2331
err = realtek_add_jack(mixer, "Headset Mic Jack",
2332
REALTEK_HP_OUT | REALTEK_MIC_FLAG);
2333
if (err < 0)
2334
return err;
2335
return 0;
2336
}
2337
2338
static void dell_dock_init_vol(struct usb_mixer_interface *mixer, int ch, int id)
2339
{
2340
struct snd_usb_audio *chip = mixer->chip;
2341
u16 buf = 0;
2342
2343
snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
2344
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
2345
(UAC_FU_VOLUME << 8) | ch,
2346
snd_usb_ctrl_intf(mixer->hostif) | (id << 8),
2347
&buf, 2);
2348
}
2349
2350
static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
2351
{
2352
/* fix to 0dB playback volumes */
2353
dell_dock_init_vol(mixer, 1, 16);
2354
dell_dock_init_vol(mixer, 2, 16);
2355
dell_dock_init_vol(mixer, 1, 19);
2356
dell_dock_init_vol(mixer, 2, 19);
2357
return 0;
2358
}
2359
2360
/* RME Class Compliant device quirks */
2361
2362
#define SND_RME_GET_STATUS1 23
2363
#define SND_RME_GET_CURRENT_FREQ 17
2364
#define SND_RME_CLK_SYSTEM_SHIFT 16
2365
#define SND_RME_CLK_SYSTEM_MASK 0x1f
2366
#define SND_RME_CLK_AES_SHIFT 8
2367
#define SND_RME_CLK_SPDIF_SHIFT 12
2368
#define SND_RME_CLK_AES_SPDIF_MASK 0xf
2369
#define SND_RME_CLK_SYNC_SHIFT 6
2370
#define SND_RME_CLK_SYNC_MASK 0x3
2371
#define SND_RME_CLK_FREQMUL_SHIFT 18
2372
#define SND_RME_CLK_FREQMUL_MASK 0x7
2373
#define SND_RME_CLK_SYSTEM(x) \
2374
(((x) >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
2375
#define SND_RME_CLK_AES(x) \
2376
(((x) >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
2377
#define SND_RME_CLK_SPDIF(x) \
2378
(((x) >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
2379
#define SND_RME_CLK_SYNC(x) \
2380
(((x) >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
2381
#define SND_RME_CLK_FREQMUL(x) \
2382
(((x) >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
2383
#define SND_RME_CLK_AES_LOCK 0x1
2384
#define SND_RME_CLK_AES_SYNC 0x4
2385
#define SND_RME_CLK_SPDIF_LOCK 0x2
2386
#define SND_RME_CLK_SPDIF_SYNC 0x8
2387
#define SND_RME_SPDIF_IF_SHIFT 4
2388
#define SND_RME_SPDIF_FORMAT_SHIFT 5
2389
#define SND_RME_BINARY_MASK 0x1
2390
#define SND_RME_SPDIF_IF(x) \
2391
(((x) >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
2392
#define SND_RME_SPDIF_FORMAT(x) \
2393
(((x) >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
2394
2395
static const u32 snd_rme_rate_table[] = {
2396
32000, 44100, 48000, 50000,
2397
64000, 88200, 96000, 100000,
2398
128000, 176400, 192000, 200000,
2399
256000, 352800, 384000, 400000,
2400
512000, 705600, 768000, 800000
2401
};
2402
2403
/* maximum number of items for AES and S/PDIF rates for above table */
2404
#define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
2405
2406
enum snd_rme_domain {
2407
SND_RME_DOMAIN_SYSTEM,
2408
SND_RME_DOMAIN_AES,
2409
SND_RME_DOMAIN_SPDIF
2410
};
2411
2412
enum snd_rme_clock_status {
2413
SND_RME_CLOCK_NOLOCK,
2414
SND_RME_CLOCK_LOCK,
2415
SND_RME_CLOCK_SYNC
2416
};
2417
2418
static int snd_rme_read_value(struct snd_usb_audio *chip,
2419
unsigned int item,
2420
u32 *value)
2421
{
2422
struct usb_device *dev = chip->dev;
2423
int err;
2424
2425
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
2426
item,
2427
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2428
0, 0,
2429
value, sizeof(*value));
2430
if (err < 0)
2431
dev_err(&dev->dev,
2432
"unable to issue vendor read request %d (ret = %d)",
2433
item, err);
2434
return err;
2435
}
2436
2437
static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
2438
u32 *status1)
2439
{
2440
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2441
struct snd_usb_audio *chip = list->mixer->chip;
2442
2443
CLASS(snd_usb_lock, pm)(chip);
2444
if (pm.err < 0)
2445
return pm.err;
2446
return snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
2447
}
2448
2449
static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
2450
struct snd_ctl_elem_value *ucontrol)
2451
{
2452
u32 status1;
2453
u32 rate = 0;
2454
int idx;
2455
int err;
2456
2457
err = snd_rme_get_status1(kcontrol, &status1);
2458
if (err < 0)
2459
return err;
2460
switch (kcontrol->private_value) {
2461
case SND_RME_DOMAIN_SYSTEM:
2462
idx = SND_RME_CLK_SYSTEM(status1);
2463
if (idx < ARRAY_SIZE(snd_rme_rate_table))
2464
rate = snd_rme_rate_table[idx];
2465
break;
2466
case SND_RME_DOMAIN_AES:
2467
idx = SND_RME_CLK_AES(status1);
2468
if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2469
rate = snd_rme_rate_table[idx];
2470
break;
2471
case SND_RME_DOMAIN_SPDIF:
2472
idx = SND_RME_CLK_SPDIF(status1);
2473
if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
2474
rate = snd_rme_rate_table[idx];
2475
break;
2476
default:
2477
return -EINVAL;
2478
}
2479
ucontrol->value.integer.value[0] = rate;
2480
return 0;
2481
}
2482
2483
static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
2484
struct snd_ctl_elem_value *ucontrol)
2485
{
2486
u32 status1;
2487
int idx = SND_RME_CLOCK_NOLOCK;
2488
int err;
2489
2490
err = snd_rme_get_status1(kcontrol, &status1);
2491
if (err < 0)
2492
return err;
2493
switch (kcontrol->private_value) {
2494
case SND_RME_DOMAIN_AES: /* AES */
2495
if (status1 & SND_RME_CLK_AES_SYNC)
2496
idx = SND_RME_CLOCK_SYNC;
2497
else if (status1 & SND_RME_CLK_AES_LOCK)
2498
idx = SND_RME_CLOCK_LOCK;
2499
break;
2500
case SND_RME_DOMAIN_SPDIF: /* SPDIF */
2501
if (status1 & SND_RME_CLK_SPDIF_SYNC)
2502
idx = SND_RME_CLOCK_SYNC;
2503
else if (status1 & SND_RME_CLK_SPDIF_LOCK)
2504
idx = SND_RME_CLOCK_LOCK;
2505
break;
2506
default:
2507
return -EINVAL;
2508
}
2509
ucontrol->value.enumerated.item[0] = idx;
2510
return 0;
2511
}
2512
2513
static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
2514
struct snd_ctl_elem_value *ucontrol)
2515
{
2516
u32 status1;
2517
int err;
2518
2519
err = snd_rme_get_status1(kcontrol, &status1);
2520
if (err < 0)
2521
return err;
2522
ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
2523
return 0;
2524
}
2525
2526
static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
2527
struct snd_ctl_elem_value *ucontrol)
2528
{
2529
u32 status1;
2530
int err;
2531
2532
err = snd_rme_get_status1(kcontrol, &status1);
2533
if (err < 0)
2534
return err;
2535
ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
2536
return 0;
2537
}
2538
2539
static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
2540
struct snd_ctl_elem_value *ucontrol)
2541
{
2542
u32 status1;
2543
int err;
2544
2545
err = snd_rme_get_status1(kcontrol, &status1);
2546
if (err < 0)
2547
return err;
2548
ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2549
return 0;
2550
}
2551
2552
static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2553
struct snd_ctl_elem_value *ucontrol)
2554
{
2555
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2556
struct snd_usb_audio *chip = list->mixer->chip;
2557
u32 status1;
2558
const u64 num = 104857600000000ULL;
2559
u32 den;
2560
unsigned int freq;
2561
int err;
2562
2563
CLASS(snd_usb_lock, pm)(chip);
2564
if (pm.err < 0)
2565
return pm.err;
2566
err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2567
if (err < 0)
2568
return err;
2569
err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2570
if (err < 0)
2571
return err;
2572
freq = (den == 0) ? 0 : div64_u64(num, den);
2573
freq <<= SND_RME_CLK_FREQMUL(status1);
2574
ucontrol->value.integer.value[0] = freq;
2575
return 0;
2576
}
2577
2578
static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2579
struct snd_ctl_elem_info *uinfo)
2580
{
2581
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2582
uinfo->count = 1;
2583
switch (kcontrol->private_value) {
2584
case SND_RME_DOMAIN_SYSTEM:
2585
uinfo->value.integer.min = 32000;
2586
uinfo->value.integer.max = 800000;
2587
break;
2588
case SND_RME_DOMAIN_AES:
2589
case SND_RME_DOMAIN_SPDIF:
2590
default:
2591
uinfo->value.integer.min = 0;
2592
uinfo->value.integer.max = 200000;
2593
}
2594
uinfo->value.integer.step = 0;
2595
return 0;
2596
}
2597
2598
static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2599
struct snd_ctl_elem_info *uinfo)
2600
{
2601
static const char *const sync_states[] = {
2602
"No Lock", "Lock", "Sync"
2603
};
2604
2605
return snd_ctl_enum_info(uinfo, 1,
2606
ARRAY_SIZE(sync_states), sync_states);
2607
}
2608
2609
static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2610
struct snd_ctl_elem_info *uinfo)
2611
{
2612
static const char *const spdif_if[] = {
2613
"Coaxial", "Optical"
2614
};
2615
2616
return snd_ctl_enum_info(uinfo, 1,
2617
ARRAY_SIZE(spdif_if), spdif_if);
2618
}
2619
2620
static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2621
struct snd_ctl_elem_info *uinfo)
2622
{
2623
static const char *const optical_type[] = {
2624
"Consumer", "Professional"
2625
};
2626
2627
return snd_ctl_enum_info(uinfo, 1,
2628
ARRAY_SIZE(optical_type), optical_type);
2629
}
2630
2631
static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2632
struct snd_ctl_elem_info *uinfo)
2633
{
2634
static const char *const sync_sources[] = {
2635
"Internal", "AES", "SPDIF", "Internal"
2636
};
2637
2638
return snd_ctl_enum_info(uinfo, 1,
2639
ARRAY_SIZE(sync_sources), sync_sources);
2640
}
2641
2642
static const struct snd_kcontrol_new snd_rme_controls[] = {
2643
{
2644
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2645
.name = "AES Rate",
2646
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2647
.info = snd_rme_rate_info,
2648
.get = snd_rme_rate_get,
2649
.private_value = SND_RME_DOMAIN_AES
2650
},
2651
{
2652
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2653
.name = "AES Sync",
2654
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2655
.info = snd_rme_sync_state_info,
2656
.get = snd_rme_sync_state_get,
2657
.private_value = SND_RME_DOMAIN_AES
2658
},
2659
{
2660
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2661
.name = "SPDIF Rate",
2662
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2663
.info = snd_rme_rate_info,
2664
.get = snd_rme_rate_get,
2665
.private_value = SND_RME_DOMAIN_SPDIF
2666
},
2667
{
2668
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2669
.name = "SPDIF Sync",
2670
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2671
.info = snd_rme_sync_state_info,
2672
.get = snd_rme_sync_state_get,
2673
.private_value = SND_RME_DOMAIN_SPDIF
2674
},
2675
{
2676
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2677
.name = "SPDIF Interface",
2678
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2679
.info = snd_rme_spdif_if_info,
2680
.get = snd_rme_spdif_if_get,
2681
},
2682
{
2683
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2684
.name = "SPDIF Format",
2685
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2686
.info = snd_rme_spdif_format_info,
2687
.get = snd_rme_spdif_format_get,
2688
},
2689
{
2690
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2691
.name = "Sync Source",
2692
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2693
.info = snd_rme_sync_source_info,
2694
.get = snd_rme_sync_source_get
2695
},
2696
{
2697
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2698
.name = "System Rate",
2699
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2700
.info = snd_rme_rate_info,
2701
.get = snd_rme_rate_get,
2702
.private_value = SND_RME_DOMAIN_SYSTEM
2703
},
2704
{
2705
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2706
.name = "Current Frequency",
2707
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2708
.info = snd_rme_rate_info,
2709
.get = snd_rme_current_freq_get
2710
}
2711
};
2712
2713
static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2714
{
2715
int err, i;
2716
2717
for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2718
err = add_single_ctl_with_resume(mixer, 0,
2719
NULL,
2720
&snd_rme_controls[i],
2721
NULL);
2722
if (err < 0)
2723
return err;
2724
}
2725
2726
return 0;
2727
}
2728
2729
/*
2730
* RME Babyface Pro (FS)
2731
*
2732
* These devices exposes a couple of DSP functions via request to EP0.
2733
* Switches are available via control registers, while routing is controlled
2734
* by controlling the volume on each possible crossing point.
2735
* Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with
2736
* 0dB being at dec. 32768.
2737
*/
2738
enum {
2739
SND_BBFPRO_CTL_REG1 = 0,
2740
SND_BBFPRO_CTL_REG2
2741
};
2742
2743
#define SND_BBFPRO_CTL_REG_MASK 1
2744
#define SND_BBFPRO_CTL_IDX_MASK 0xff
2745
#define SND_BBFPRO_CTL_IDX_SHIFT 1
2746
#define SND_BBFPRO_CTL_VAL_MASK 1
2747
#define SND_BBFPRO_CTL_VAL_SHIFT 9
2748
#define SND_BBFPRO_CTL_REG1_CLK_MASTER 0
2749
#define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1
2750
#define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7
2751
#define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8
2752
#define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10
2753
#define SND_BBFPRO_CTL_REG2_48V_AN1 0
2754
#define SND_BBFPRO_CTL_REG2_48V_AN2 1
2755
#define SND_BBFPRO_CTL_REG2_SENS_IN3 2
2756
#define SND_BBFPRO_CTL_REG2_SENS_IN4 3
2757
#define SND_BBFPRO_CTL_REG2_PAD_AN1 4
2758
#define SND_BBFPRO_CTL_REG2_PAD_AN2 5
2759
2760
#define SND_BBFPRO_MIXER_MAIN_OUT_CH_OFFSET 992
2761
#define SND_BBFPRO_MIXER_IDX_MASK 0x3ff
2762
#define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff
2763
#define SND_BBFPRO_MIXER_VAL_SHIFT 9
2764
#define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf
2765
#define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB
2766
2767
#define SND_BBFPRO_GAIN_CHANNEL_MASK 0x03
2768
#define SND_BBFPRO_GAIN_CHANNEL_SHIFT 7
2769
#define SND_BBFPRO_GAIN_VAL_MASK 0x7f
2770
#define SND_BBFPRO_GAIN_VAL_MIN 0
2771
#define SND_BBFPRO_GAIN_VAL_MIC_MAX 65
2772
#define SND_BBFPRO_GAIN_VAL_LINE_MAX 18 // 9db in 0.5db incraments
2773
2774
#define SND_BBFPRO_USBREQ_CTL_REG1 0x10
2775
#define SND_BBFPRO_USBREQ_CTL_REG2 0x17
2776
#define SND_BBFPRO_USBREQ_GAIN 0x1a
2777
#define SND_BBFPRO_USBREQ_MIXER 0x12
2778
2779
static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
2780
u8 index, u8 value)
2781
{
2782
u16 usb_req, usb_idx, usb_val;
2783
struct snd_usb_audio *chip = mixer->chip;
2784
2785
CLASS(snd_usb_lock, pm)(chip);
2786
if (pm.err < 0)
2787
return pm.err;
2788
2789
if (reg == SND_BBFPRO_CTL_REG1) {
2790
usb_req = SND_BBFPRO_USBREQ_CTL_REG1;
2791
if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2792
usb_idx = 3;
2793
usb_val = value ? 3 : 0;
2794
} else {
2795
usb_idx = BIT(index);
2796
usb_val = value ? usb_idx : 0;
2797
}
2798
} else {
2799
usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
2800
usb_idx = BIT(index);
2801
usb_val = value ? usb_idx : 0;
2802
}
2803
2804
return snd_usb_ctl_msg(chip->dev,
2805
usb_sndctrlpipe(chip->dev, 0), usb_req,
2806
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2807
usb_val, usb_idx, NULL, 0);
2808
}
2809
2810
static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol,
2811
struct snd_ctl_elem_value *ucontrol)
2812
{
2813
u8 reg, idx, val;
2814
int pv;
2815
2816
pv = kcontrol->private_value;
2817
reg = pv & SND_BBFPRO_CTL_REG_MASK;
2818
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2819
val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT;
2820
2821
if ((reg == SND_BBFPRO_CTL_REG1 &&
2822
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2823
(reg == SND_BBFPRO_CTL_REG2 &&
2824
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2825
idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2826
ucontrol->value.enumerated.item[0] = val;
2827
} else {
2828
ucontrol->value.integer.value[0] = val;
2829
}
2830
return 0;
2831
}
2832
2833
static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol,
2834
struct snd_ctl_elem_info *uinfo)
2835
{
2836
u8 reg, idx;
2837
int pv;
2838
2839
pv = kcontrol->private_value;
2840
reg = pv & SND_BBFPRO_CTL_REG_MASK;
2841
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2842
2843
if (reg == SND_BBFPRO_CTL_REG1 &&
2844
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) {
2845
static const char * const texts[2] = {
2846
"AutoSync",
2847
"Internal"
2848
};
2849
return snd_ctl_enum_info(uinfo, 1, 2, texts);
2850
} else if (reg == SND_BBFPRO_CTL_REG2 &&
2851
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2852
idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) {
2853
static const char * const texts[2] = {
2854
"-10dBV",
2855
"+4dBu"
2856
};
2857
return snd_ctl_enum_info(uinfo, 1, 2, texts);
2858
}
2859
2860
uinfo->count = 1;
2861
uinfo->value.integer.min = 0;
2862
uinfo->value.integer.max = 1;
2863
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2864
return 0;
2865
}
2866
2867
static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol,
2868
struct snd_ctl_elem_value *ucontrol)
2869
{
2870
int err;
2871
u8 reg, idx;
2872
int old_value, pv, val;
2873
2874
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2875
struct usb_mixer_interface *mixer = list->mixer;
2876
2877
pv = kcontrol->private_value;
2878
reg = pv & SND_BBFPRO_CTL_REG_MASK;
2879
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2880
old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2881
2882
if ((reg == SND_BBFPRO_CTL_REG1 &&
2883
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) ||
2884
(reg == SND_BBFPRO_CTL_REG2 &&
2885
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 ||
2886
idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) {
2887
val = ucontrol->value.enumerated.item[0];
2888
} else {
2889
val = ucontrol->value.integer.value[0];
2890
}
2891
2892
if (val > 1)
2893
return -EINVAL;
2894
2895
if (val == old_value)
2896
return 0;
2897
2898
kcontrol->private_value = reg
2899
| ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT)
2900
| ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT);
2901
2902
err = snd_bbfpro_ctl_update(mixer, reg, idx, val);
2903
return err < 0 ? err : 1;
2904
}
2905
2906
static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list)
2907
{
2908
u8 reg, idx;
2909
int value, pv;
2910
2911
pv = list->kctl->private_value;
2912
reg = pv & SND_BBFPRO_CTL_REG_MASK;
2913
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK;
2914
value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK;
2915
2916
return snd_bbfpro_ctl_update(list->mixer, reg, idx, value);
2917
}
2918
2919
static int snd_bbfpro_gain_update(struct usb_mixer_interface *mixer,
2920
u8 channel, u8 gain)
2921
{
2922
struct snd_usb_audio *chip = mixer->chip;
2923
2924
if (channel < 2) {
2925
// XLR preamp: 3-bit fine, 5-bit coarse; special case >60
2926
if (gain < 60)
2927
gain = ((gain % 3) << 5) | (gain / 3);
2928
else
2929
gain = ((gain % 6) << 5) | (60 / 3);
2930
}
2931
2932
CLASS(snd_usb_lock, pm)(chip);
2933
if (pm.err < 0)
2934
return pm.err;
2935
2936
return snd_usb_ctl_msg(chip->dev,
2937
usb_sndctrlpipe(chip->dev, 0),
2938
SND_BBFPRO_USBREQ_GAIN,
2939
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2940
gain, channel, NULL, 0);
2941
}
2942
2943
static int snd_bbfpro_gain_get(struct snd_kcontrol *kcontrol,
2944
struct snd_ctl_elem_value *ucontrol)
2945
{
2946
int value = kcontrol->private_value & SND_BBFPRO_GAIN_VAL_MASK;
2947
2948
ucontrol->value.integer.value[0] = value;
2949
return 0;
2950
}
2951
2952
static int snd_bbfpro_gain_info(struct snd_kcontrol *kcontrol,
2953
struct snd_ctl_elem_info *uinfo)
2954
{
2955
int pv, channel;
2956
2957
pv = kcontrol->private_value;
2958
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) &
2959
SND_BBFPRO_GAIN_CHANNEL_MASK;
2960
2961
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2962
uinfo->count = 1;
2963
uinfo->value.integer.min = SND_BBFPRO_GAIN_VAL_MIN;
2964
2965
if (channel < 2)
2966
uinfo->value.integer.max = SND_BBFPRO_GAIN_VAL_MIC_MAX;
2967
else
2968
uinfo->value.integer.max = SND_BBFPRO_GAIN_VAL_LINE_MAX;
2969
2970
return 0;
2971
}
2972
2973
static int snd_bbfpro_gain_put(struct snd_kcontrol *kcontrol,
2974
struct snd_ctl_elem_value *ucontrol)
2975
{
2976
int pv, channel, old_value, value, err;
2977
2978
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2979
struct usb_mixer_interface *mixer = list->mixer;
2980
2981
pv = kcontrol->private_value;
2982
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) &
2983
SND_BBFPRO_GAIN_CHANNEL_MASK;
2984
old_value = pv & SND_BBFPRO_GAIN_VAL_MASK;
2985
value = ucontrol->value.integer.value[0];
2986
2987
if (value < SND_BBFPRO_GAIN_VAL_MIN)
2988
return -EINVAL;
2989
2990
if (channel < 2) {
2991
if (value > SND_BBFPRO_GAIN_VAL_MIC_MAX)
2992
return -EINVAL;
2993
} else {
2994
if (value > SND_BBFPRO_GAIN_VAL_LINE_MAX)
2995
return -EINVAL;
2996
}
2997
2998
if (value == old_value)
2999
return 0;
3000
3001
err = snd_bbfpro_gain_update(mixer, channel, value);
3002
if (err < 0)
3003
return err;
3004
3005
kcontrol->private_value =
3006
(channel << SND_BBFPRO_GAIN_CHANNEL_SHIFT) | value;
3007
return 1;
3008
}
3009
3010
static int snd_bbfpro_gain_resume(struct usb_mixer_elem_list *list)
3011
{
3012
int pv, channel, value;
3013
struct snd_kcontrol *kctl = list->kctl;
3014
3015
pv = kctl->private_value;
3016
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) &
3017
SND_BBFPRO_GAIN_CHANNEL_MASK;
3018
value = pv & SND_BBFPRO_GAIN_VAL_MASK;
3019
3020
return snd_bbfpro_gain_update(list->mixer, channel, value);
3021
}
3022
3023
static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index,
3024
u32 value)
3025
{
3026
struct snd_usb_audio *chip = mixer->chip;
3027
u16 idx;
3028
u16 usb_idx, usb_val;
3029
u32 v;
3030
3031
CLASS(snd_usb_lock, pm)(chip);
3032
if (pm.err < 0)
3033
return pm.err;
3034
3035
idx = index & SND_BBFPRO_MIXER_IDX_MASK;
3036
// 18 bit linear volume, split so 2 bits end up in index.
3037
v = value & SND_BBFPRO_MIXER_VAL_MASK;
3038
usb_idx = idx | (v & 0x3) << 14;
3039
usb_val = (v >> 2) & 0xffff;
3040
3041
return snd_usb_ctl_msg(chip->dev,
3042
usb_sndctrlpipe(chip->dev, 0),
3043
SND_BBFPRO_USBREQ_MIXER,
3044
USB_DIR_OUT | USB_TYPE_VENDOR |
3045
USB_RECIP_DEVICE,
3046
usb_val, usb_idx, NULL, 0);
3047
}
3048
3049
static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol,
3050
struct snd_ctl_elem_value *ucontrol)
3051
{
3052
ucontrol->value.integer.value[0] =
3053
kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
3054
return 0;
3055
}
3056
3057
static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol,
3058
struct snd_ctl_elem_info *uinfo)
3059
{
3060
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3061
uinfo->count = 1;
3062
uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN;
3063
uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX;
3064
return 0;
3065
}
3066
3067
static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol,
3068
struct snd_ctl_elem_value *ucontrol)
3069
{
3070
int err;
3071
u16 idx;
3072
u32 new_val, old_value, uvalue;
3073
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
3074
struct usb_mixer_interface *mixer = list->mixer;
3075
3076
uvalue = ucontrol->value.integer.value[0];
3077
idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK;
3078
old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT;
3079
3080
if (uvalue > SND_BBFPRO_MIXER_VAL_MAX)
3081
return -EINVAL;
3082
3083
if (uvalue == old_value)
3084
return 0;
3085
3086
new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK;
3087
3088
kcontrol->private_value = idx
3089
| (new_val << SND_BBFPRO_MIXER_VAL_SHIFT);
3090
3091
err = snd_bbfpro_vol_update(mixer, idx, new_val);
3092
return err < 0 ? err : 1;
3093
}
3094
3095
static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list)
3096
{
3097
int pv = list->kctl->private_value;
3098
u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK;
3099
u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT)
3100
& SND_BBFPRO_MIXER_VAL_MASK;
3101
return snd_bbfpro_vol_update(list->mixer, idx, val);
3102
}
3103
3104
// Predfine elements
3105
static const struct snd_kcontrol_new snd_bbfpro_ctl_control = {
3106
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3107
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3108
.index = 0,
3109
.info = snd_bbfpro_ctl_info,
3110
.get = snd_bbfpro_ctl_get,
3111
.put = snd_bbfpro_ctl_put
3112
};
3113
3114
static const struct snd_kcontrol_new snd_bbfpro_gain_control = {
3115
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3116
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3117
.index = 0,
3118
.info = snd_bbfpro_gain_info,
3119
.get = snd_bbfpro_gain_get,
3120
.put = snd_bbfpro_gain_put
3121
};
3122
3123
static const struct snd_kcontrol_new snd_bbfpro_vol_control = {
3124
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3125
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3126
.index = 0,
3127
.info = snd_bbfpro_vol_info,
3128
.get = snd_bbfpro_vol_get,
3129
.put = snd_bbfpro_vol_put
3130
};
3131
3132
static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg,
3133
u8 index, char *name)
3134
{
3135
struct snd_kcontrol_new knew = snd_bbfpro_ctl_control;
3136
3137
knew.name = name;
3138
knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK)
3139
| ((index & SND_BBFPRO_CTL_IDX_MASK)
3140
<< SND_BBFPRO_CTL_IDX_SHIFT);
3141
3142
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume,
3143
&knew, NULL);
3144
}
3145
3146
static int snd_bbfpro_gain_add(struct usb_mixer_interface *mixer, u8 channel,
3147
char *name)
3148
{
3149
struct snd_kcontrol_new knew = snd_bbfpro_gain_control;
3150
3151
knew.name = name;
3152
knew.private_value = channel << SND_BBFPRO_GAIN_CHANNEL_SHIFT;
3153
3154
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_gain_resume,
3155
&knew, NULL);
3156
}
3157
3158
static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index,
3159
char *name)
3160
{
3161
struct snd_kcontrol_new knew = snd_bbfpro_vol_control;
3162
3163
knew.name = name;
3164
knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK;
3165
3166
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume,
3167
&knew, NULL);
3168
}
3169
3170
static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)
3171
{
3172
int err, i, o;
3173
char name[48];
3174
3175
static const char * const input[] = {
3176
"AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3",
3177
"ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"};
3178
3179
static const char * const output[] = {
3180
"AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4",
3181
"ADAT5", "ADAT6", "ADAT7", "ADAT8"};
3182
3183
for (o = 0 ; o < 12 ; ++o) {
3184
for (i = 0 ; i < 12 ; ++i) {
3185
// Line routing
3186
snprintf(name, sizeof(name),
3187
"%s-%s-%s Playback Volume",
3188
(i < 2 ? "Mic" : "Line"),
3189
input[i], output[o]);
3190
err = snd_bbfpro_vol_add(mixer, (26 * o + i), name);
3191
if (err < 0)
3192
return err;
3193
3194
// PCM routing... yes, it is output remapping
3195
snprintf(name, sizeof(name),
3196
"PCM-%s-%s Playback Volume",
3197
output[i], output[o]);
3198
err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i),
3199
name);
3200
if (err < 0)
3201
return err;
3202
}
3203
}
3204
3205
// Main out volume
3206
for (i = 0 ; i < 12 ; ++i) {
3207
snprintf(name, sizeof(name), "Main-Out %s", output[i]);
3208
// Main outs are offset to 992
3209
err = snd_bbfpro_vol_add(mixer,
3210
i + SND_BBFPRO_MIXER_MAIN_OUT_CH_OFFSET,
3211
name);
3212
if (err < 0)
3213
return err;
3214
}
3215
3216
// Input gain
3217
for (i = 0 ; i < 4 ; ++i) {
3218
if (i < 2)
3219
snprintf(name, sizeof(name), "Mic-%s Gain", input[i]);
3220
else
3221
snprintf(name, sizeof(name), "Line-%s Gain", input[i]);
3222
3223
err = snd_bbfpro_gain_add(mixer, i, name);
3224
if (err < 0)
3225
return err;
3226
}
3227
3228
// Control Reg 1
3229
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
3230
SND_BBFPRO_CTL_REG1_CLK_OPTICAL,
3231
"Sample Clock Source");
3232
if (err < 0)
3233
return err;
3234
3235
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
3236
SND_BBFPRO_CTL_REG1_SPDIF_PRO,
3237
"IEC958 Pro Mask");
3238
if (err < 0)
3239
return err;
3240
3241
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
3242
SND_BBFPRO_CTL_REG1_SPDIF_EMPH,
3243
"IEC958 Emphasis");
3244
if (err < 0)
3245
return err;
3246
3247
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1,
3248
SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL,
3249
"IEC958 Switch");
3250
if (err < 0)
3251
return err;
3252
3253
// Control Reg 2
3254
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3255
SND_BBFPRO_CTL_REG2_48V_AN1,
3256
"Mic-AN1 48V");
3257
if (err < 0)
3258
return err;
3259
3260
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3261
SND_BBFPRO_CTL_REG2_48V_AN2,
3262
"Mic-AN2 48V");
3263
if (err < 0)
3264
return err;
3265
3266
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3267
SND_BBFPRO_CTL_REG2_SENS_IN3,
3268
"Line-IN3 Sens.");
3269
if (err < 0)
3270
return err;
3271
3272
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3273
SND_BBFPRO_CTL_REG2_SENS_IN4,
3274
"Line-IN4 Sens.");
3275
if (err < 0)
3276
return err;
3277
3278
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3279
SND_BBFPRO_CTL_REG2_PAD_AN1,
3280
"Mic-AN1 PAD");
3281
if (err < 0)
3282
return err;
3283
3284
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2,
3285
SND_BBFPRO_CTL_REG2_PAD_AN2,
3286
"Mic-AN2 PAD");
3287
if (err < 0)
3288
return err;
3289
3290
return 0;
3291
}
3292
3293
/*
3294
* RME Digiface USB
3295
*/
3296
3297
#define RME_DIGIFACE_READ_STATUS 17
3298
#define RME_DIGIFACE_STATUS_REG0L 0
3299
#define RME_DIGIFACE_STATUS_REG0H 1
3300
#define RME_DIGIFACE_STATUS_REG1L 2
3301
#define RME_DIGIFACE_STATUS_REG1H 3
3302
#define RME_DIGIFACE_STATUS_REG2L 4
3303
#define RME_DIGIFACE_STATUS_REG2H 5
3304
#define RME_DIGIFACE_STATUS_REG3L 6
3305
#define RME_DIGIFACE_STATUS_REG3H 7
3306
3307
#define RME_DIGIFACE_CTL_REG1 16
3308
#define RME_DIGIFACE_CTL_REG2 18
3309
3310
/* Reg is overloaded, 0-7 for status halfwords or 16 or 18 for control registers */
3311
#define RME_DIGIFACE_REGISTER(reg, mask) (((reg) << 16) | (mask))
3312
#define RME_DIGIFACE_INVERT BIT(31)
3313
3314
/* Nonconst helpers */
3315
#define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
3316
#define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
3317
3318
static int snd_rme_digiface_write_reg(struct snd_kcontrol *kcontrol, int item, u16 mask, u16 val)
3319
{
3320
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
3321
struct snd_usb_audio *chip = list->mixer->chip;
3322
struct usb_device *dev = chip->dev;
3323
int err;
3324
3325
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
3326
item,
3327
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
3328
val, mask, NULL, 0);
3329
if (err < 0)
3330
dev_err(&dev->dev,
3331
"unable to issue control set request %d (ret = %d)",
3332
item, err);
3333
return err;
3334
}
3335
3336
static int snd_rme_digiface_read_status(struct snd_kcontrol *kcontrol, u32 status[4])
3337
{
3338
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
3339
struct snd_usb_audio *chip = list->mixer->chip;
3340
struct usb_device *dev = chip->dev;
3341
__le32 buf[4];
3342
int err;
3343
3344
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
3345
RME_DIGIFACE_READ_STATUS,
3346
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
3347
0, 0,
3348
buf, sizeof(buf));
3349
if (err < 0) {
3350
dev_err(&dev->dev,
3351
"unable to issue status read request (ret = %d)",
3352
err);
3353
} else {
3354
for (int i = 0; i < ARRAY_SIZE(buf); i++)
3355
status[i] = le32_to_cpu(buf[i]);
3356
}
3357
return err;
3358
}
3359
3360
static int snd_rme_digiface_get_status_val(struct snd_kcontrol *kcontrol)
3361
{
3362
int err;
3363
u32 status[4];
3364
bool invert = kcontrol->private_value & RME_DIGIFACE_INVERT;
3365
u8 reg = (kcontrol->private_value >> 16) & 0xff;
3366
u16 mask = kcontrol->private_value & 0xffff;
3367
u16 val;
3368
3369
err = snd_rme_digiface_read_status(kcontrol, status);
3370
if (err < 0)
3371
return err;
3372
3373
switch (reg) {
3374
/* Status register halfwords */
3375
case RME_DIGIFACE_STATUS_REG0L ... RME_DIGIFACE_STATUS_REG3H:
3376
break;
3377
case RME_DIGIFACE_CTL_REG1: /* Control register 1, present in halfword 3L */
3378
reg = RME_DIGIFACE_STATUS_REG3L;
3379
break;
3380
case RME_DIGIFACE_CTL_REG2: /* Control register 2, present in halfword 3H */
3381
reg = RME_DIGIFACE_STATUS_REG3H;
3382
break;
3383
default:
3384
return -EINVAL;
3385
}
3386
3387
if (reg & 1)
3388
val = status[reg >> 1] >> 16;
3389
else
3390
val = status[reg >> 1] & 0xffff;
3391
3392
if (invert)
3393
val ^= mask;
3394
3395
return field_get(mask, val);
3396
}
3397
3398
static int snd_rme_digiface_rate_get(struct snd_kcontrol *kcontrol,
3399
struct snd_ctl_elem_value *ucontrol)
3400
{
3401
int freq = snd_rme_digiface_get_status_val(kcontrol);
3402
3403
if (freq < 0)
3404
return freq;
3405
if (freq >= ARRAY_SIZE(snd_rme_rate_table))
3406
return -EIO;
3407
3408
ucontrol->value.integer.value[0] = snd_rme_rate_table[freq];
3409
return 0;
3410
}
3411
3412
static int snd_rme_digiface_enum_get(struct snd_kcontrol *kcontrol,
3413
struct snd_ctl_elem_value *ucontrol)
3414
{
3415
int val = snd_rme_digiface_get_status_val(kcontrol);
3416
3417
if (val < 0)
3418
return val;
3419
3420
ucontrol->value.enumerated.item[0] = val;
3421
return 0;
3422
}
3423
3424
static int snd_rme_digiface_enum_put(struct snd_kcontrol *kcontrol,
3425
struct snd_ctl_elem_value *ucontrol)
3426
{
3427
bool invert = kcontrol->private_value & RME_DIGIFACE_INVERT;
3428
u8 reg = (kcontrol->private_value >> 16) & 0xff;
3429
u16 mask = kcontrol->private_value & 0xffff;
3430
u16 val = field_prep(mask, ucontrol->value.enumerated.item[0]);
3431
3432
if (invert)
3433
val ^= mask;
3434
3435
return snd_rme_digiface_write_reg(kcontrol, reg, mask, val);
3436
}
3437
3438
static int snd_rme_digiface_current_sync_get(struct snd_kcontrol *kcontrol,
3439
struct snd_ctl_elem_value *ucontrol)
3440
{
3441
int ret = snd_rme_digiface_enum_get(kcontrol, ucontrol);
3442
3443
/* 7 means internal for current sync */
3444
if (ucontrol->value.enumerated.item[0] == 7)
3445
ucontrol->value.enumerated.item[0] = 0;
3446
3447
return ret;
3448
}
3449
3450
static int snd_rme_digiface_sync_state_get(struct snd_kcontrol *kcontrol,
3451
struct snd_ctl_elem_value *ucontrol)
3452
{
3453
u32 status[4];
3454
int err;
3455
bool valid, sync;
3456
3457
err = snd_rme_digiface_read_status(kcontrol, status);
3458
if (err < 0)
3459
return err;
3460
3461
valid = status[0] & BIT(kcontrol->private_value);
3462
sync = status[0] & BIT(5 + kcontrol->private_value);
3463
3464
if (!valid)
3465
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_NOLOCK;
3466
else if (!sync)
3467
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_LOCK;
3468
else
3469
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_SYNC;
3470
return 0;
3471
}
3472
3473
static int snd_rme_digiface_format_info(struct snd_kcontrol *kcontrol,
3474
struct snd_ctl_elem_info *uinfo)
3475
{
3476
static const char *const format[] = {
3477
"ADAT", "S/PDIF"
3478
};
3479
3480
return snd_ctl_enum_info(uinfo, 1,
3481
ARRAY_SIZE(format), format);
3482
}
3483
3484
static int snd_rme_digiface_sync_source_info(struct snd_kcontrol *kcontrol,
3485
struct snd_ctl_elem_info *uinfo)
3486
{
3487
static const char *const sync_sources[] = {
3488
"Internal", "Input 1", "Input 2", "Input 3", "Input 4"
3489
};
3490
3491
return snd_ctl_enum_info(uinfo, 1,
3492
ARRAY_SIZE(sync_sources), sync_sources);
3493
}
3494
3495
static int snd_rme_digiface_rate_info(struct snd_kcontrol *kcontrol,
3496
struct snd_ctl_elem_info *uinfo)
3497
{
3498
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3499
uinfo->count = 1;
3500
uinfo->value.integer.min = 0;
3501
uinfo->value.integer.max = 200000;
3502
uinfo->value.integer.step = 0;
3503
return 0;
3504
}
3505
3506
static const struct snd_kcontrol_new snd_rme_digiface_controls[] = {
3507
{
3508
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3509
.name = "Input 1 Sync",
3510
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3511
.info = snd_rme_sync_state_info,
3512
.get = snd_rme_digiface_sync_state_get,
3513
.private_value = 0,
3514
},
3515
{
3516
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3517
.name = "Input 1 Format",
3518
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3519
.info = snd_rme_digiface_format_info,
3520
.get = snd_rme_digiface_enum_get,
3521
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0H, BIT(0)) |
3522
RME_DIGIFACE_INVERT,
3523
},
3524
{
3525
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3526
.name = "Input 1 Rate",
3527
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3528
.info = snd_rme_digiface_rate_info,
3529
.get = snd_rme_digiface_rate_get,
3530
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(3, 0)),
3531
},
3532
{
3533
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3534
.name = "Input 2 Sync",
3535
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3536
.info = snd_rme_sync_state_info,
3537
.get = snd_rme_digiface_sync_state_get,
3538
.private_value = 1,
3539
},
3540
{
3541
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3542
.name = "Input 2 Format",
3543
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3544
.info = snd_rme_digiface_format_info,
3545
.get = snd_rme_digiface_enum_get,
3546
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, BIT(13)) |
3547
RME_DIGIFACE_INVERT,
3548
},
3549
{
3550
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3551
.name = "Input 2 Rate",
3552
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3553
.info = snd_rme_digiface_rate_info,
3554
.get = snd_rme_digiface_rate_get,
3555
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(7, 4)),
3556
},
3557
{
3558
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3559
.name = "Input 3 Sync",
3560
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3561
.info = snd_rme_sync_state_info,
3562
.get = snd_rme_digiface_sync_state_get,
3563
.private_value = 2,
3564
},
3565
{
3566
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3567
.name = "Input 3 Format",
3568
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3569
.info = snd_rme_digiface_format_info,
3570
.get = snd_rme_digiface_enum_get,
3571
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, BIT(14)) |
3572
RME_DIGIFACE_INVERT,
3573
},
3574
{
3575
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3576
.name = "Input 3 Rate",
3577
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3578
.info = snd_rme_digiface_rate_info,
3579
.get = snd_rme_digiface_rate_get,
3580
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(11, 8)),
3581
},
3582
{
3583
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3584
.name = "Input 4 Sync",
3585
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3586
.info = snd_rme_sync_state_info,
3587
.get = snd_rme_digiface_sync_state_get,
3588
.private_value = 3,
3589
},
3590
{
3591
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3592
.name = "Input 4 Format",
3593
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3594
.info = snd_rme_digiface_format_info,
3595
.get = snd_rme_digiface_enum_get,
3596
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, GENMASK(15, 12)) |
3597
RME_DIGIFACE_INVERT,
3598
},
3599
{
3600
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3601
.name = "Input 4 Rate",
3602
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3603
.info = snd_rme_digiface_rate_info,
3604
.get = snd_rme_digiface_rate_get,
3605
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(3, 0)),
3606
},
3607
{
3608
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3609
.name = "Output 1 Format",
3610
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3611
.info = snd_rme_digiface_format_info,
3612
.get = snd_rme_digiface_enum_get,
3613
.put = snd_rme_digiface_enum_put,
3614
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(0)),
3615
},
3616
{
3617
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3618
.name = "Output 2 Format",
3619
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3620
.info = snd_rme_digiface_format_info,
3621
.get = snd_rme_digiface_enum_get,
3622
.put = snd_rme_digiface_enum_put,
3623
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(1)),
3624
},
3625
{
3626
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3627
.name = "Output 3 Format",
3628
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3629
.info = snd_rme_digiface_format_info,
3630
.get = snd_rme_digiface_enum_get,
3631
.put = snd_rme_digiface_enum_put,
3632
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(3)),
3633
},
3634
{
3635
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3636
.name = "Output 4 Format",
3637
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3638
.info = snd_rme_digiface_format_info,
3639
.get = snd_rme_digiface_enum_get,
3640
.put = snd_rme_digiface_enum_put,
3641
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(4)),
3642
},
3643
{
3644
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3645
.name = "Sync Source",
3646
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3647
.info = snd_rme_digiface_sync_source_info,
3648
.get = snd_rme_digiface_enum_get,
3649
.put = snd_rme_digiface_enum_put,
3650
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG1, GENMASK(2, 0)),
3651
},
3652
{
3653
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3654
.name = "Current Sync Source",
3655
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3656
.info = snd_rme_digiface_sync_source_info,
3657
.get = snd_rme_digiface_current_sync_get,
3658
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, GENMASK(12, 10)),
3659
},
3660
{
3661
/*
3662
* This is writeable, but it is only set by the PCM rate.
3663
* Mixer apps currently need to drive the mixer using raw USB requests,
3664
* so they can also change this that way to configure the rate for
3665
* stand-alone operation when the PCM is closed.
3666
*/
3667
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3668
.name = "System Rate",
3669
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3670
.info = snd_rme_rate_info,
3671
.get = snd_rme_digiface_rate_get,
3672
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG1, GENMASK(6, 3)),
3673
},
3674
{
3675
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3676
.name = "Current Rate",
3677
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3678
.info = snd_rme_rate_info,
3679
.get = snd_rme_digiface_rate_get,
3680
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1H, GENMASK(7, 4)),
3681
}
3682
};
3683
3684
static int snd_rme_digiface_controls_create(struct usb_mixer_interface *mixer)
3685
{
3686
int err, i;
3687
3688
for (i = 0; i < ARRAY_SIZE(snd_rme_digiface_controls); ++i) {
3689
err = add_single_ctl_with_resume(mixer, 0,
3690
NULL,
3691
&snd_rme_digiface_controls[i],
3692
NULL);
3693
if (err < 0)
3694
return err;
3695
}
3696
3697
return 0;
3698
}
3699
3700
/*
3701
* Pioneer DJ / AlphaTheta DJM Mixers
3702
*
3703
* These devices generally have options for soft-switching the playback and
3704
* capture sources in addition to the recording level. Although different
3705
* devices have different configurations, there seems to be canonical values
3706
* for specific capture/playback types: See the definitions of these below.
3707
*
3708
* The wValue is masked with the stereo channel number. e.g. Setting Ch2 to
3709
* capture phono would be 0x0203. Capture, playback and capture level have
3710
* different wIndexes.
3711
*/
3712
3713
// Capture types
3714
#define SND_DJM_CAP_LINE 0x00
3715
#define SND_DJM_CAP_CDLINE 0x01
3716
#define SND_DJM_CAP_DIGITAL 0x02
3717
#define SND_DJM_CAP_PHONO 0x03
3718
#define SND_DJM_CAP_PREFADER 0x05
3719
#define SND_DJM_CAP_PFADER 0x06
3720
#define SND_DJM_CAP_XFADERA 0x07
3721
#define SND_DJM_CAP_XFADERB 0x08
3722
#define SND_DJM_CAP_MIC 0x09
3723
#define SND_DJM_CAP_AUX 0x0d
3724
#define SND_DJM_CAP_RECOUT 0x0a
3725
#define SND_DJM_CAP_RECOUT_NOMIC 0x0e
3726
#define SND_DJM_CAP_NONE 0x0f
3727
#define SND_DJM_CAP_FXSEND 0x10
3728
#define SND_DJM_CAP_CH1PFADER 0x11
3729
#define SND_DJM_CAP_CH2PFADER 0x12
3730
#define SND_DJM_CAP_CH3PFADER 0x13
3731
#define SND_DJM_CAP_CH4PFADER 0x14
3732
#define SND_DJM_CAP_EXT1SEND 0x21
3733
#define SND_DJM_CAP_EXT2SEND 0x22
3734
#define SND_DJM_CAP_CH1PREFADER 0x31
3735
#define SND_DJM_CAP_CH2PREFADER 0x32
3736
#define SND_DJM_CAP_CH3PREFADER 0x33
3737
#define SND_DJM_CAP_CH4PREFADER 0x34
3738
3739
// Playback types
3740
#define SND_DJM_PB_CH1 0x00
3741
#define SND_DJM_PB_CH2 0x01
3742
#define SND_DJM_PB_AUX 0x04
3743
3744
#define SND_DJM_WINDEX_CAP 0x8002
3745
#define SND_DJM_WINDEX_CAPLVL 0x8003
3746
#define SND_DJM_WINDEX_PB 0x8016
3747
3748
// kcontrol->private_value layout
3749
#define SND_DJM_VALUE_MASK 0x0000ffff
3750
#define SND_DJM_GROUP_MASK 0x00ff0000
3751
#define SND_DJM_DEVICE_MASK 0xff000000
3752
#define SND_DJM_GROUP_SHIFT 16
3753
#define SND_DJM_DEVICE_SHIFT 24
3754
3755
// device table index
3756
// used for the snd_djm_devices table, so please update accordingly
3757
#define SND_DJM_250MK2_IDX 0x0
3758
#define SND_DJM_750_IDX 0x1
3759
#define SND_DJM_850_IDX 0x2
3760
#define SND_DJM_900NXS2_IDX 0x3
3761
#define SND_DJM_750MK2_IDX 0x4
3762
#define SND_DJM_450_IDX 0x5
3763
#define SND_DJM_A9_IDX 0x6
3764
#define SND_DJM_V10_IDX 0x7
3765
3766
#define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \
3767
.name = _name, \
3768
.options = snd_djm_opts_##suffix, \
3769
.noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \
3770
.default_value = _default_value, \
3771
.wIndex = _windex }
3772
3773
#define SND_DJM_DEVICE(suffix) { \
3774
.controls = snd_djm_ctls_##suffix, \
3775
.ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) }
3776
3777
struct snd_djm_device {
3778
const char *name;
3779
const struct snd_djm_ctl *controls;
3780
size_t ncontrols;
3781
};
3782
3783
struct snd_djm_ctl {
3784
const char *name;
3785
const u16 *options;
3786
size_t noptions;
3787
u16 default_value;
3788
u16 wIndex;
3789
};
3790
3791
static const char *snd_djm_get_label_caplevel_common(u16 wvalue)
3792
{
3793
switch (wvalue) {
3794
case 0x0000: return "-19dB";
3795
case 0x0100: return "-15dB";
3796
case 0x0200: return "-10dB";
3797
case 0x0300: return "-5dB";
3798
default: return NULL;
3799
}
3800
};
3801
3802
// Models like DJM-A9 or DJM-V10 have different capture levels than others
3803
static const char *snd_djm_get_label_caplevel_high(u16 wvalue)
3804
{
3805
switch (wvalue) {
3806
case 0x0000: return "+15dB";
3807
case 0x0100: return "+12dB";
3808
case 0x0200: return "+9dB";
3809
case 0x0300: return "+6dB";
3810
case 0x0400: return "+3dB";
3811
case 0x0500: return "0dB";
3812
default: return NULL;
3813
}
3814
};
3815
3816
static const char *snd_djm_get_label_cap_common(u16 wvalue)
3817
{
3818
switch (wvalue & 0x00ff) {
3819
case SND_DJM_CAP_LINE: return "Control Tone LINE";
3820
case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE";
3821
case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL";
3822
case SND_DJM_CAP_PHONO: return "Control Tone PHONO";
3823
case SND_DJM_CAP_PFADER: return "Post Fader";
3824
case SND_DJM_CAP_XFADERA: return "Cross Fader A";
3825
case SND_DJM_CAP_XFADERB: return "Cross Fader B";
3826
case SND_DJM_CAP_MIC: return "Mic";
3827
case SND_DJM_CAP_RECOUT: return "Rec Out";
3828
case SND_DJM_CAP_RECOUT_NOMIC: return "Rec Out without Mic";
3829
case SND_DJM_CAP_AUX: return "Aux";
3830
case SND_DJM_CAP_NONE: return "None";
3831
case SND_DJM_CAP_FXSEND: return "FX SEND";
3832
case SND_DJM_CAP_CH1PREFADER: return "Pre Fader Ch1";
3833
case SND_DJM_CAP_CH2PREFADER: return "Pre Fader Ch2";
3834
case SND_DJM_CAP_CH3PREFADER: return "Pre Fader Ch3";
3835
case SND_DJM_CAP_CH4PREFADER: return "Pre Fader Ch4";
3836
case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1";
3837
case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2";
3838
case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3";
3839
case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4";
3840
case SND_DJM_CAP_EXT1SEND: return "EXT1 SEND";
3841
case SND_DJM_CAP_EXT2SEND: return "EXT2 SEND";
3842
default: return NULL;
3843
}
3844
};
3845
3846
// The DJM-850 has different values for CD/LINE and LINE capture
3847
// control options than the other DJM declared in this file.
3848
static const char *snd_djm_get_label_cap_850(u16 wvalue)
3849
{
3850
switch (wvalue & 0x00ff) {
3851
case 0x00: return "Control Tone CD/LINE";
3852
case 0x01: return "Control Tone LINE";
3853
default: return snd_djm_get_label_cap_common(wvalue);
3854
}
3855
};
3856
3857
static const char *snd_djm_get_label_caplevel(u8 device_idx, u16 wvalue)
3858
{
3859
switch (device_idx) {
3860
case SND_DJM_A9_IDX: return snd_djm_get_label_caplevel_high(wvalue);
3861
case SND_DJM_V10_IDX: return snd_djm_get_label_caplevel_high(wvalue);
3862
default: return snd_djm_get_label_caplevel_common(wvalue);
3863
}
3864
};
3865
3866
static const char *snd_djm_get_label_cap(u8 device_idx, u16 wvalue)
3867
{
3868
switch (device_idx) {
3869
case SND_DJM_850_IDX: return snd_djm_get_label_cap_850(wvalue);
3870
default: return snd_djm_get_label_cap_common(wvalue);
3871
}
3872
};
3873
3874
static const char *snd_djm_get_label_pb(u16 wvalue)
3875
{
3876
switch (wvalue & 0x00ff) {
3877
case SND_DJM_PB_CH1: return "Ch1";
3878
case SND_DJM_PB_CH2: return "Ch2";
3879
case SND_DJM_PB_AUX: return "Aux";
3880
default: return NULL;
3881
}
3882
};
3883
3884
static const char *snd_djm_get_label(u8 device_idx, u16 wvalue, u16 windex)
3885
{
3886
switch (windex) {
3887
case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(device_idx, wvalue);
3888
case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(device_idx, wvalue);
3889
case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue);
3890
default: return NULL;
3891
}
3892
};
3893
3894
// common DJM capture level option values
3895
static const u16 snd_djm_opts_cap_level[] = {
3896
0x0000, 0x0100, 0x0200, 0x0300 };
3897
3898
// DJM-250MK2
3899
static const u16 snd_djm_opts_250mk2_cap1[] = {
3900
0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a };
3901
3902
static const u16 snd_djm_opts_250mk2_cap2[] = {
3903
0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a };
3904
3905
static const u16 snd_djm_opts_250mk2_cap3[] = {
3906
0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d };
3907
3908
static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 };
3909
static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 };
3910
static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 };
3911
3912
static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = {
3913
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3914
SND_DJM_CTL("Input 1 Capture Switch", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP),
3915
SND_DJM_CTL("Input 2 Capture Switch", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP),
3916
SND_DJM_CTL("Input 3 Capture Switch", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP),
3917
SND_DJM_CTL("Output 1 Playback Switch", 250mk2_pb1, 0, SND_DJM_WINDEX_PB),
3918
SND_DJM_CTL("Output 2 Playback Switch", 250mk2_pb2, 1, SND_DJM_WINDEX_PB),
3919
SND_DJM_CTL("Output 3 Playback Switch", 250mk2_pb3, 2, SND_DJM_WINDEX_PB)
3920
};
3921
3922
// DJM-450
3923
static const u16 snd_djm_opts_450_cap1[] = {
3924
0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a };
3925
3926
static const u16 snd_djm_opts_450_cap2[] = {
3927
0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a };
3928
3929
static const u16 snd_djm_opts_450_cap3[] = {
3930
0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d };
3931
3932
static const u16 snd_djm_opts_450_pb1[] = { 0x0100, 0x0101, 0x0104 };
3933
static const u16 snd_djm_opts_450_pb2[] = { 0x0200, 0x0201, 0x0204 };
3934
static const u16 snd_djm_opts_450_pb3[] = { 0x0300, 0x0301, 0x0304 };
3935
3936
static const struct snd_djm_ctl snd_djm_ctls_450[] = {
3937
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3938
SND_DJM_CTL("Input 1 Capture Switch", 450_cap1, 2, SND_DJM_WINDEX_CAP),
3939
SND_DJM_CTL("Input 2 Capture Switch", 450_cap2, 2, SND_DJM_WINDEX_CAP),
3940
SND_DJM_CTL("Input 3 Capture Switch", 450_cap3, 0, SND_DJM_WINDEX_CAP),
3941
SND_DJM_CTL("Output 1 Playback Switch", 450_pb1, 0, SND_DJM_WINDEX_PB),
3942
SND_DJM_CTL("Output 2 Playback Switch", 450_pb2, 1, SND_DJM_WINDEX_PB),
3943
SND_DJM_CTL("Output 3 Playback Switch", 450_pb3, 2, SND_DJM_WINDEX_PB)
3944
};
3945
3946
// DJM-750
3947
static const u16 snd_djm_opts_750_cap1[] = {
3948
0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
3949
static const u16 snd_djm_opts_750_cap2[] = {
3950
0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
3951
static const u16 snd_djm_opts_750_cap3[] = {
3952
0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
3953
static const u16 snd_djm_opts_750_cap4[] = {
3954
0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
3955
3956
static const struct snd_djm_ctl snd_djm_ctls_750[] = {
3957
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3958
SND_DJM_CTL("Input 1 Capture Switch", 750_cap1, 2, SND_DJM_WINDEX_CAP),
3959
SND_DJM_CTL("Input 2 Capture Switch", 750_cap2, 2, SND_DJM_WINDEX_CAP),
3960
SND_DJM_CTL("Input 3 Capture Switch", 750_cap3, 0, SND_DJM_WINDEX_CAP),
3961
SND_DJM_CTL("Input 4 Capture Switch", 750_cap4, 0, SND_DJM_WINDEX_CAP)
3962
};
3963
3964
// DJM-850
3965
static const u16 snd_djm_opts_850_cap1[] = {
3966
0x0100, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f };
3967
static const u16 snd_djm_opts_850_cap2[] = {
3968
0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f };
3969
static const u16 snd_djm_opts_850_cap3[] = {
3970
0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f };
3971
static const u16 snd_djm_opts_850_cap4[] = {
3972
0x0400, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f };
3973
3974
static const struct snd_djm_ctl snd_djm_ctls_850[] = {
3975
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3976
SND_DJM_CTL("Input 1 Capture Switch", 850_cap1, 1, SND_DJM_WINDEX_CAP),
3977
SND_DJM_CTL("Input 2 Capture Switch", 850_cap2, 0, SND_DJM_WINDEX_CAP),
3978
SND_DJM_CTL("Input 3 Capture Switch", 850_cap3, 0, SND_DJM_WINDEX_CAP),
3979
SND_DJM_CTL("Input 4 Capture Switch", 850_cap4, 1, SND_DJM_WINDEX_CAP)
3980
};
3981
3982
// DJM-900NXS2
3983
static const u16 snd_djm_opts_900nxs2_cap1[] = {
3984
0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a };
3985
static const u16 snd_djm_opts_900nxs2_cap2[] = {
3986
0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a };
3987
static const u16 snd_djm_opts_900nxs2_cap3[] = {
3988
0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a };
3989
static const u16 snd_djm_opts_900nxs2_cap4[] = {
3990
0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a };
3991
static const u16 snd_djm_opts_900nxs2_cap5[] = {
3992
0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 };
3993
3994
static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = {
3995
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
3996
SND_DJM_CTL("Input 1 Capture Switch", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP),
3997
SND_DJM_CTL("Input 2 Capture Switch", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP),
3998
SND_DJM_CTL("Input 3 Capture Switch", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP),
3999
SND_DJM_CTL("Input 4 Capture Switch", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP),
4000
SND_DJM_CTL("Input 5 Capture Switch", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP)
4001
};
4002
4003
// DJM-750MK2
4004
static const u16 snd_djm_opts_750mk2_cap1[] = {
4005
0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a };
4006
static const u16 snd_djm_opts_750mk2_cap2[] = {
4007
0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a };
4008
static const u16 snd_djm_opts_750mk2_cap3[] = {
4009
0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a };
4010
static const u16 snd_djm_opts_750mk2_cap4[] = {
4011
0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a };
4012
static const u16 snd_djm_opts_750mk2_cap5[] = {
4013
0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 };
4014
4015
static const u16 snd_djm_opts_750mk2_pb1[] = { 0x0100, 0x0101, 0x0104 };
4016
static const u16 snd_djm_opts_750mk2_pb2[] = { 0x0200, 0x0201, 0x0204 };
4017
static const u16 snd_djm_opts_750mk2_pb3[] = { 0x0300, 0x0301, 0x0304 };
4018
4019
static const struct snd_djm_ctl snd_djm_ctls_750mk2[] = {
4020
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL),
4021
SND_DJM_CTL("Input 1 Capture Switch", 750mk2_cap1, 2, SND_DJM_WINDEX_CAP),
4022
SND_DJM_CTL("Input 2 Capture Switch", 750mk2_cap2, 2, SND_DJM_WINDEX_CAP),
4023
SND_DJM_CTL("Input 3 Capture Switch", 750mk2_cap3, 2, SND_DJM_WINDEX_CAP),
4024
SND_DJM_CTL("Input 4 Capture Switch", 750mk2_cap4, 2, SND_DJM_WINDEX_CAP),
4025
SND_DJM_CTL("Input 5 Capture Switch", 750mk2_cap5, 3, SND_DJM_WINDEX_CAP),
4026
SND_DJM_CTL("Output 1 Playback Switch", 750mk2_pb1, 0, SND_DJM_WINDEX_PB),
4027
SND_DJM_CTL("Output 2 Playback Switch", 750mk2_pb2, 1, SND_DJM_WINDEX_PB),
4028
SND_DJM_CTL("Output 3 Playback Switch", 750mk2_pb3, 2, SND_DJM_WINDEX_PB)
4029
};
4030
4031
// DJM-A9
4032
static const u16 snd_djm_opts_a9_cap_level[] = {
4033
0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500 };
4034
static const u16 snd_djm_opts_a9_cap1[] = {
4035
0x0107, 0x0108, 0x0109, 0x010a, 0x010e,
4036
0x111, 0x112, 0x113, 0x114, 0x0131, 0x132, 0x133, 0x134 };
4037
static const u16 snd_djm_opts_a9_cap2[] = {
4038
0x0201, 0x0202, 0x0203, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020e };
4039
static const u16 snd_djm_opts_a9_cap3[] = {
4040
0x0301, 0x0302, 0x0303, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030e };
4041
static const u16 snd_djm_opts_a9_cap4[] = {
4042
0x0401, 0x0402, 0x0403, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040e };
4043
static const u16 snd_djm_opts_a9_cap5[] = {
4044
0x0501, 0x0502, 0x0503, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, 0x050a, 0x050e };
4045
4046
static const struct snd_djm_ctl snd_djm_ctls_a9[] = {
4047
SND_DJM_CTL("Master Input Level Capture Switch", a9_cap_level, 0, SND_DJM_WINDEX_CAPLVL),
4048
SND_DJM_CTL("Master Input Capture Switch", a9_cap1, 3, SND_DJM_WINDEX_CAP),
4049
SND_DJM_CTL("Input 1 Capture Switch", a9_cap2, 2, SND_DJM_WINDEX_CAP),
4050
SND_DJM_CTL("Input 2 Capture Switch", a9_cap3, 2, SND_DJM_WINDEX_CAP),
4051
SND_DJM_CTL("Input 3 Capture Switch", a9_cap4, 2, SND_DJM_WINDEX_CAP),
4052
SND_DJM_CTL("Input 4 Capture Switch", a9_cap5, 2, SND_DJM_WINDEX_CAP)
4053
};
4054
4055
// DJM-V10
4056
static const u16 snd_djm_opts_v10_cap_level[] = {
4057
0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500
4058
};
4059
4060
static const u16 snd_djm_opts_v10_cap1[] = {
4061
0x0103,
4062
0x0100, 0x0102, 0x0106, 0x0110, 0x0107,
4063
0x0108, 0x0109, 0x010a, 0x0121, 0x0122
4064
};
4065
4066
static const u16 snd_djm_opts_v10_cap2[] = {
4067
0x0200, 0x0202, 0x0206, 0x0210, 0x0207,
4068
0x0208, 0x0209, 0x020a, 0x0221, 0x0222
4069
};
4070
4071
static const u16 snd_djm_opts_v10_cap3[] = {
4072
0x0303,
4073
0x0300, 0x0302, 0x0306, 0x0310, 0x0307,
4074
0x0308, 0x0309, 0x030a, 0x0321, 0x0322
4075
};
4076
4077
static const u16 snd_djm_opts_v10_cap4[] = {
4078
0x0403,
4079
0x0400, 0x0402, 0x0406, 0x0410, 0x0407,
4080
0x0408, 0x0409, 0x040a, 0x0421, 0x0422
4081
};
4082
4083
static const u16 snd_djm_opts_v10_cap5[] = {
4084
0x0500, 0x0502, 0x0506, 0x0510, 0x0507,
4085
0x0508, 0x0509, 0x050a, 0x0521, 0x0522
4086
};
4087
4088
static const u16 snd_djm_opts_v10_cap6[] = {
4089
0x0603,
4090
0x0600, 0x0602, 0x0606, 0x0610, 0x0607,
4091
0x0608, 0x0609, 0x060a, 0x0621, 0x0622
4092
};
4093
4094
static const struct snd_djm_ctl snd_djm_ctls_v10[] = {
4095
SND_DJM_CTL("Master Input Level Capture Switch", v10_cap_level, 0, SND_DJM_WINDEX_CAPLVL),
4096
SND_DJM_CTL("Input 1 Capture Switch", v10_cap1, 2, SND_DJM_WINDEX_CAP),
4097
SND_DJM_CTL("Input 2 Capture Switch", v10_cap2, 2, SND_DJM_WINDEX_CAP),
4098
SND_DJM_CTL("Input 3 Capture Switch", v10_cap3, 0, SND_DJM_WINDEX_CAP),
4099
SND_DJM_CTL("Input 4 Capture Switch", v10_cap4, 0, SND_DJM_WINDEX_CAP),
4100
SND_DJM_CTL("Input 5 Capture Switch", v10_cap5, 0, SND_DJM_WINDEX_CAP),
4101
SND_DJM_CTL("Input 6 Capture Switch", v10_cap6, 0, SND_DJM_WINDEX_CAP)
4102
// playback channels are fixed and controlled by hardware knobs on the mixer
4103
};
4104
4105
static const struct snd_djm_device snd_djm_devices[] = {
4106
[SND_DJM_250MK2_IDX] = SND_DJM_DEVICE(250mk2),
4107
[SND_DJM_750_IDX] = SND_DJM_DEVICE(750),
4108
[SND_DJM_850_IDX] = SND_DJM_DEVICE(850),
4109
[SND_DJM_900NXS2_IDX] = SND_DJM_DEVICE(900nxs2),
4110
[SND_DJM_750MK2_IDX] = SND_DJM_DEVICE(750mk2),
4111
[SND_DJM_450_IDX] = SND_DJM_DEVICE(450),
4112
[SND_DJM_A9_IDX] = SND_DJM_DEVICE(a9),
4113
[SND_DJM_V10_IDX] = SND_DJM_DEVICE(v10),
4114
};
4115
4116
static int snd_djm_controls_info(struct snd_kcontrol *kctl,
4117
struct snd_ctl_elem_info *info)
4118
{
4119
unsigned long private_value = kctl->private_value;
4120
u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
4121
u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
4122
const struct snd_djm_device *device = &snd_djm_devices[device_idx];
4123
const char *name;
4124
const struct snd_djm_ctl *ctl;
4125
size_t noptions;
4126
4127
if (ctl_idx >= device->ncontrols)
4128
return -EINVAL;
4129
4130
ctl = &device->controls[ctl_idx];
4131
noptions = ctl->noptions;
4132
if (info->value.enumerated.item >= noptions)
4133
info->value.enumerated.item = noptions - 1;
4134
4135
name = snd_djm_get_label(device_idx,
4136
ctl->options[info->value.enumerated.item],
4137
ctl->wIndex);
4138
if (!name)
4139
return -EINVAL;
4140
4141
strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name));
4142
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4143
info->count = 1;
4144
info->value.enumerated.items = noptions;
4145
return 0;
4146
}
4147
4148
static int snd_djm_controls_update(struct usb_mixer_interface *mixer,
4149
u8 device_idx, u8 group, u16 value)
4150
{
4151
const struct snd_djm_device *device = &snd_djm_devices[device_idx];
4152
4153
if (group >= device->ncontrols || value >= device->controls[group].noptions)
4154
return -EINVAL;
4155
4156
CLASS(snd_usb_lock, pm)(mixer->chip);
4157
if (pm.err)
4158
return pm.err;
4159
4160
return snd_usb_ctl_msg(mixer->chip->dev,
4161
usb_sndctrlpipe(mixer->chip->dev, 0),
4162
USB_REQ_SET_FEATURE,
4163
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
4164
device->controls[group].options[value],
4165
device->controls[group].wIndex,
4166
NULL, 0);
4167
}
4168
4169
static int snd_djm_controls_get(struct snd_kcontrol *kctl,
4170
struct snd_ctl_elem_value *elem)
4171
{
4172
elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK;
4173
return 0;
4174
}
4175
4176
static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem)
4177
{
4178
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
4179
struct usb_mixer_interface *mixer = list->mixer;
4180
unsigned long private_value = kctl->private_value;
4181
4182
u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
4183
u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
4184
u16 value = elem->value.enumerated.item[0];
4185
4186
kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) |
4187
(group << SND_DJM_GROUP_SHIFT) |
4188
value);
4189
4190
return snd_djm_controls_update(mixer, device, group, value);
4191
}
4192
4193
static int snd_djm_controls_resume(struct usb_mixer_elem_list *list)
4194
{
4195
unsigned long private_value = list->kctl->private_value;
4196
u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT;
4197
u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT;
4198
u16 value = (private_value & SND_DJM_VALUE_MASK);
4199
4200
return snd_djm_controls_update(list->mixer, device, group, value);
4201
}
4202
4203
static int snd_djm_controls_create(struct usb_mixer_interface *mixer,
4204
const u8 device_idx)
4205
{
4206
int err, i;
4207
u16 value;
4208
4209
const struct snd_djm_device *device = &snd_djm_devices[device_idx];
4210
4211
struct snd_kcontrol_new knew = {
4212
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4213
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
4214
.index = 0,
4215
.info = snd_djm_controls_info,
4216
.get = snd_djm_controls_get,
4217
.put = snd_djm_controls_put
4218
};
4219
4220
for (i = 0; i < device->ncontrols; i++) {
4221
value = device->controls[i].default_value;
4222
knew.name = device->controls[i].name;
4223
knew.private_value =
4224
((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) |
4225
(i << SND_DJM_GROUP_SHIFT) |
4226
value;
4227
err = snd_djm_controls_update(mixer, device_idx, i, value);
4228
if (err)
4229
return err;
4230
err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume,
4231
&knew, NULL);
4232
if (err)
4233
return err;
4234
}
4235
return 0;
4236
}
4237
4238
int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
4239
{
4240
int err = 0;
4241
4242
err = snd_usb_soundblaster_remote_init(mixer);
4243
if (err < 0)
4244
return err;
4245
4246
switch (mixer->chip->usb_id) {
4247
/* Tascam US-16x08 */
4248
case USB_ID(0x0644, 0x8047):
4249
err = snd_us16x08_controls_create(mixer);
4250
break;
4251
case USB_ID(0x041e, 0x3020):
4252
case USB_ID(0x041e, 0x3040):
4253
case USB_ID(0x041e, 0x3042):
4254
case USB_ID(0x041e, 0x30df):
4255
case USB_ID(0x041e, 0x3048):
4256
err = snd_audigy2nx_controls_create(mixer);
4257
if (err < 0)
4258
break;
4259
snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
4260
mixer, snd_audigy2nx_proc_read);
4261
break;
4262
4263
/* EMU0204 */
4264
case USB_ID(0x041e, 0x3f19):
4265
err = snd_emu0204_controls_create(mixer);
4266
break;
4267
4268
#if IS_REACHABLE(CONFIG_INPUT)
4269
case USB_ID(0x054c, 0x0ce6): /* Sony DualSense controller (PS5) */
4270
case USB_ID(0x054c, 0x0df2): /* Sony DualSense Edge controller (PS5) */
4271
err = snd_dualsense_controls_create(mixer);
4272
break;
4273
#endif /* IS_REACHABLE(CONFIG_INPUT) */
4274
4275
case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
4276
case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
4277
err = snd_c400_create_mixer(mixer);
4278
break;
4279
4280
case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
4281
case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
4282
err = snd_ftu_create_mixer(mixer);
4283
break;
4284
4285
case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */
4286
case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */
4287
case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */
4288
err = snd_xonar_u1_controls_create(mixer);
4289
break;
4290
4291
case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */
4292
err = snd_microii_controls_create(mixer);
4293
break;
4294
4295
case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */
4296
err = snd_mbox1_controls_create(mixer);
4297
break;
4298
4299
case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */
4300
err = snd_nativeinstruments_create_mixer(/* checkpatch hack */
4301
mixer,
4302
snd_nativeinstruments_ta6_mixers,
4303
ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
4304
break;
4305
4306
case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */
4307
err = snd_nativeinstruments_create_mixer(/* checkpatch hack */
4308
mixer,
4309
snd_nativeinstruments_ta10_mixers,
4310
ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
4311
break;
4312
4313
case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
4314
/* detection is disabled in mixer_maps.c */
4315
err = snd_create_std_mono_table(mixer, ebox44_table);
4316
break;
4317
4318
case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */
4319
case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */
4320
case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */
4321
case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */
4322
case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */
4323
err = snd_scarlett_controls_create(mixer);
4324
break;
4325
4326
case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
4327
case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
4328
case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
4329
case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */
4330
case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */
4331
case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */
4332
case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */
4333
case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */
4334
case USB_ID(0x1235, 0x8215): /* Focusrite Scarlett 18i20 3rd Gen */
4335
case USB_ID(0x1235, 0x8216): /* Focusrite Vocaster One */
4336
case USB_ID(0x1235, 0x8217): /* Focusrite Vocaster Two */
4337
case USB_ID(0x1235, 0x8218): /* Focusrite Scarlett Solo 4th Gen */
4338
case USB_ID(0x1235, 0x8219): /* Focusrite Scarlett 2i2 4th Gen */
4339
case USB_ID(0x1235, 0x821a): /* Focusrite Scarlett 4i4 4th Gen */
4340
case USB_ID(0x1235, 0x8206): /* Focusrite Clarett 2Pre USB */
4341
case USB_ID(0x1235, 0x8207): /* Focusrite Clarett 4Pre USB */
4342
case USB_ID(0x1235, 0x8208): /* Focusrite Clarett 8Pre USB */
4343
case USB_ID(0x1235, 0x820a): /* Focusrite Clarett+ 2Pre */
4344
case USB_ID(0x1235, 0x820b): /* Focusrite Clarett+ 4Pre */
4345
case USB_ID(0x1235, 0x820c): /* Focusrite Clarett+ 8Pre */
4346
err = snd_scarlett2_init(mixer);
4347
break;
4348
4349
case USB_ID(0x1235, 0x821b): /* Focusrite Scarlett 16i16 4th Gen */
4350
case USB_ID(0x1235, 0x821c): /* Focusrite Scarlett 18i16 4th Gen */
4351
case USB_ID(0x1235, 0x821d): /* Focusrite Scarlett 18i20 4th Gen */
4352
err = snd_fcp_init(mixer);
4353
break;
4354
4355
case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */
4356
err = snd_soundblaster_e1_switch_create(mixer);
4357
break;
4358
case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
4359
err = dell_dock_mixer_create(mixer);
4360
if (err < 0)
4361
break;
4362
err = dell_dock_mixer_init(mixer);
4363
break;
4364
case USB_ID(0x0bda, 0x402e): /* Dell WD19 dock */
4365
err = dell_dock_mixer_create(mixer);
4366
break;
4367
4368
case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */
4369
case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */
4370
case USB_ID(0x2a39, 0x3fd4): /* RME */
4371
err = snd_rme_controls_create(mixer);
4372
break;
4373
4374
case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */
4375
err = snd_sc1810_init_mixer(mixer);
4376
break;
4377
case USB_ID(0x194f, 0x010d): /* Presonus Studio 1824c */
4378
err = snd_sc1810_init_mixer(mixer);
4379
break;
4380
case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */
4381
err = snd_bbfpro_controls_create(mixer);
4382
break;
4383
case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */
4384
case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */
4385
err = snd_rme_digiface_controls_create(mixer);
4386
break;
4387
case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */
4388
err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX);
4389
break;
4390
case USB_ID(0x2b73, 0x0013): /* Pioneer DJ DJM-450 */
4391
err = snd_djm_controls_create(mixer, SND_DJM_450_IDX);
4392
break;
4393
case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */
4394
err = snd_djm_controls_create(mixer, SND_DJM_750_IDX);
4395
break;
4396
case USB_ID(0x2b73, 0x001b): /* Pioneer DJ DJM-750MK2 */
4397
err = snd_djm_controls_create(mixer, SND_DJM_750MK2_IDX);
4398
break;
4399
case USB_ID(0x08e4, 0x0163): /* Pioneer DJ DJM-850 */
4400
err = snd_djm_controls_create(mixer, SND_DJM_850_IDX);
4401
break;
4402
case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */
4403
err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX);
4404
break;
4405
case USB_ID(0x2b73, 0x003c): /* Pioneer DJ / AlphaTheta DJM-A9 */
4406
err = snd_djm_controls_create(mixer, SND_DJM_A9_IDX);
4407
break;
4408
case USB_ID(0x2b73, 0x0034): /* Pioneer DJ DJM-V10 */
4409
err = snd_djm_controls_create(mixer, SND_DJM_V10_IDX);
4410
break;
4411
}
4412
4413
return err;
4414
}
4415
4416
void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
4417
{
4418
switch (mixer->chip->usb_id) {
4419
case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */
4420
dell_dock_mixer_init(mixer);
4421
break;
4422
}
4423
}
4424
4425
void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
4426
int unitid)
4427
{
4428
if (!mixer->rc_cfg)
4429
return;
4430
/* unit ids specific to Extigy/Audigy 2 NX: */
4431
switch (unitid) {
4432
case 0: /* remote control */
4433
mixer->rc_urb->dev = mixer->chip->dev;
4434
usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
4435
break;
4436
case 4: /* digital in jack */
4437
case 7: /* line in jacks */
4438
case 19: /* speaker out jacks */
4439
case 20: /* headphones out jack */
4440
break;
4441
/* live24ext: 4 = line-in jack */
4442
case 3: /* hp-out jack (may actuate Mute) */
4443
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
4444
mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
4445
snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
4446
break;
4447
default:
4448
usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
4449
break;
4450
}
4451
}
4452
4453
static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
4454
struct usb_mixer_elem_info *cval,
4455
struct snd_kcontrol *kctl)
4456
{
4457
/* Approximation using 10 ranges based on output measurement on hw v1.2.
4458
* This seems close to the cubic mapping e.g. alsamixer uses.
4459
*/
4460
static const DECLARE_TLV_DB_RANGE(scale,
4461
0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
4462
2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
4463
6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
4464
8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
4465
15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
4466
17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
4467
20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
4468
27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
4469
32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
4470
41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
4471
);
4472
4473
if (cval->min == 0 && cval->max == 50) {
4474
usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
4475
kctl->tlv.p = scale;
4476
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
4477
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
4478
4479
} else if (cval->min == 0 && cval->max <= 1000) {
4480
/* Some other clearly broken DragonFly variant.
4481
* At least a 0..53 variant (hw v1.0) exists.
4482
*/
4483
usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
4484
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
4485
}
4486
}
4487
4488
/*
4489
* Some Plantronics headsets have control names that don't meet ALSA naming
4490
* standards. This function fixes nonstandard source names. By the time
4491
* this function is called the control name should look like one of these:
4492
* "source names Playback Volume"
4493
* "source names Playback Switch"
4494
* "source names Capture Volume"
4495
* "source names Capture Switch"
4496
* If any of the trigger words are found in the name then the name will
4497
* be changed to:
4498
* "Headset Playback Volume"
4499
* "Headset Playback Switch"
4500
* "Headset Capture Volume"
4501
* "Headset Capture Switch"
4502
* depending on the current suffix.
4503
*/
4504
static void snd_fix_plt_name(struct snd_usb_audio *chip,
4505
struct snd_ctl_elem_id *id)
4506
{
4507
/* no variant of "Sidetone" should be added to this list */
4508
static const char * const trigger[] = {
4509
"Earphone", "Microphone", "Receive", "Transmit"
4510
};
4511
static const char * const suffix[] = {
4512
" Playback Volume", " Playback Switch",
4513
" Capture Volume", " Capture Switch"
4514
};
4515
int i;
4516
4517
for (i = 0; i < ARRAY_SIZE(trigger); i++)
4518
if (strstr(id->name, trigger[i]))
4519
goto triggered;
4520
usb_audio_dbg(chip, "no change in %s\n", id->name);
4521
return;
4522
4523
triggered:
4524
for (i = 0; i < ARRAY_SIZE(suffix); i++)
4525
if (strstr(id->name, suffix[i])) {
4526
usb_audio_dbg(chip, "fixing kctl name %s\n", id->name);
4527
snprintf(id->name, sizeof(id->name), "Headset%s",
4528
suffix[i]);
4529
return;
4530
}
4531
usb_audio_dbg(chip, "something wrong in kctl name %s\n", id->name);
4532
}
4533
4534
void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
4535
struct usb_mixer_elem_info *cval, int unitid,
4536
struct snd_kcontrol *kctl)
4537
{
4538
switch (mixer->chip->usb_id) {
4539
case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
4540
if (unitid == 7 && cval->control == UAC_FU_VOLUME)
4541
snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
4542
break;
4543
}
4544
4545
/* lowest playback value is muted on some devices */
4546
if (mixer->chip->quirk_flags & QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE)
4547
if (strstr(kctl->id.name, "Playback")) {
4548
usb_audio_info(mixer->chip,
4549
"applying playback min mute quirk\n");
4550
cval->min_mute = 1;
4551
}
4552
4553
/* lowest capture value is muted on some devices */
4554
if (mixer->chip->quirk_flags & QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE)
4555
if (strstr(kctl->id.name, "Capture")) {
4556
usb_audio_info(mixer->chip,
4557
"applying capture min mute quirk\n");
4558
cval->min_mute = 1;
4559
}
4560
/* ALSA-ify some Plantronics headset control names */
4561
if (USB_ID_VENDOR(mixer->chip->usb_id) == 0x047f &&
4562
(cval->control == UAC_FU_MUTE || cval->control == UAC_FU_VOLUME))
4563
snd_fix_plt_name(mixer->chip, &kctl->id);
4564
}
4565
4566