This source file includes following definitions.
- snd_create_std_mono_ctl_offset
- snd_create_std_mono_ctl
- snd_create_std_mono_table
- add_single_ctl_with_resume
- snd_usb_soundblaster_remote_complete
- snd_usb_sbrc_hwdep_read
- snd_usb_sbrc_hwdep_poll
- snd_usb_soundblaster_remote_init
- snd_audigy2nx_led_get
- snd_audigy2nx_led_update
- snd_audigy2nx_led_put
- snd_audigy2nx_led_resume
- snd_audigy2nx_controls_create
- snd_audigy2nx_proc_read
- snd_emu0204_ch_switch_info
- snd_emu0204_ch_switch_get
- snd_emu0204_ch_switch_update
- snd_emu0204_ch_switch_put
- snd_emu0204_ch_switch_resume
- snd_emu0204_controls_create
- snd_xonar_u1_switch_get
- snd_xonar_u1_switch_update
- snd_xonar_u1_switch_put
- snd_xonar_u1_switch_resume
- snd_xonar_u1_controls_create
- snd_mbox1_switch_get
- snd_mbox1_switch_update
- snd_mbox1_switch_put
- snd_mbox1_switch_info
- snd_mbox1_switch_resume
- snd_mbox1_create_sync_switch
- snd_ni_control_init_val
- snd_nativeinstruments_control_get
- snd_ni_update_cur_val
- snd_nativeinstruments_control_put
- snd_nativeinstruments_create_mixer
- snd_ftu_eff_switch_info
- snd_ftu_eff_switch_init
- snd_ftu_eff_switch_get
- snd_ftu_eff_switch_update
- snd_ftu_eff_switch_put
- snd_ftu_create_effect_switch
- snd_ftu_create_volume_ctls
- snd_ftu_create_effect_volume_ctl
- snd_ftu_create_effect_duration_ctl
- snd_ftu_create_effect_feedback_ctl
- snd_ftu_create_effect_return_ctls
- snd_ftu_create_effect_send_ctls
- snd_ftu_create_mixer
- snd_emuusb_set_samplerate
- snd_c400_create_vol_ctls
- snd_c400_create_effect_volume_ctl
- snd_c400_create_effect_duration_ctl
- snd_c400_create_effect_feedback_ctl
- snd_c400_create_effect_vol_ctls
- snd_c400_create_effect_ret_vol_ctls
- snd_c400_create_mixer
- snd_microii_spdif_info
- snd_microii_spdif_default_get
- snd_microii_spdif_default_update
- snd_microii_spdif_default_put
- snd_microii_spdif_mask_get
- snd_microii_spdif_switch_get
- snd_microii_spdif_switch_update
- snd_microii_spdif_switch_put
- snd_microii_controls_create
- snd_soundblaster_e1_switch_get
- snd_soundblaster_e1_switch_update
- snd_soundblaster_e1_switch_put
- snd_soundblaster_e1_switch_resume
- snd_soundblaster_e1_switch_info
- snd_soundblaster_e1_switch_create
- dell_dock_init_vol
- dell_dock_mixer_init
- snd_rme_read_value
- snd_rme_get_status1
- snd_rme_rate_get
- snd_rme_sync_state_get
- snd_rme_spdif_if_get
- snd_rme_spdif_format_get
- snd_rme_sync_source_get
- snd_rme_current_freq_get
- snd_rme_rate_info
- snd_rme_sync_state_info
- snd_rme_spdif_if_info
- snd_rme_spdif_format_info
- snd_rme_sync_source_info
- snd_rme_controls_create
- snd_usb_mixer_apply_create_quirk
- snd_usb_mixer_resume_quirk
- snd_usb_mixer_rc_memory_change
- snd_dragonfly_quirk_db_scale
- snd_usb_mixer_fu_apply_quirk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <linux/hid.h>
18 #include <linux/init.h>
19 #include <linux/math64.h>
20 #include <linux/slab.h>
21 #include <linux/usb.h>
22 #include <linux/usb/audio.h>
23
24 #include <sound/asoundef.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/hwdep.h>
28 #include <sound/info.h>
29 #include <sound/tlv.h>
30
31 #include "usbaudio.h"
32 #include "mixer.h"
33 #include "mixer_quirks.h"
34 #include "mixer_scarlett.h"
35 #include "mixer_scarlett_gen2.h"
36 #include "mixer_us16x08.h"
37 #include "helper.h"
38
39 struct std_mono_table {
40 unsigned int unitid, control, cmask;
41 int val_type;
42 const char *name;
43 snd_kcontrol_tlv_rw_t *tlv_callback;
44 };
45
46
47
48
49
50
51
52
53 static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer,
54 unsigned int unitid,
55 unsigned int control,
56 unsigned int cmask,
57 int val_type,
58 unsigned int idx_off,
59 const char *name,
60 snd_kcontrol_tlv_rw_t *tlv_callback)
61 {
62 struct usb_mixer_elem_info *cval;
63 struct snd_kcontrol *kctl;
64
65 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
66 if (!cval)
67 return -ENOMEM;
68
69 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid);
70 cval->val_type = val_type;
71 cval->channels = 1;
72 cval->control = control;
73 cval->cmask = cmask;
74 cval->idx_off = idx_off;
75
76
77
78 cval->min = 0;
79 cval->max = 1;
80 cval->res = 0;
81 cval->dBmin = 0;
82 cval->dBmax = 0;
83
84
85 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval);
86 if (!kctl) {
87 kfree(cval);
88 return -ENOMEM;
89 }
90
91
92 snprintf(kctl->id.name, sizeof(kctl->id.name), name);
93 kctl->private_free = snd_usb_mixer_elem_free;
94
95
96 if (tlv_callback) {
97 kctl->tlv.c = tlv_callback;
98 kctl->vd[0].access |=
99 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
100 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
101 }
102
103 return snd_usb_mixer_add_control(&cval->head, kctl);
104 }
105
106 static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer,
107 unsigned int unitid,
108 unsigned int control,
109 unsigned int cmask,
110 int val_type,
111 const char *name,
112 snd_kcontrol_tlv_rw_t *tlv_callback)
113 {
114 return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask,
115 val_type, 0 , name, tlv_callback);
116 }
117
118
119
120
121 static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
122 struct std_mono_table *t)
123 {
124 int err;
125
126 while (t->name != NULL) {
127 err = snd_create_std_mono_ctl(mixer, t->unitid, t->control,
128 t->cmask, t->val_type, t->name, t->tlv_callback);
129 if (err < 0)
130 return err;
131 t++;
132 }
133
134 return 0;
135 }
136
137 static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
138 int id,
139 usb_mixer_elem_resume_func_t resume,
140 const struct snd_kcontrol_new *knew,
141 struct usb_mixer_elem_list **listp)
142 {
143 struct usb_mixer_elem_list *list;
144 struct snd_kcontrol *kctl;
145
146 list = kzalloc(sizeof(*list), GFP_KERNEL);
147 if (!list)
148 return -ENOMEM;
149 if (listp)
150 *listp = list;
151 list->mixer = mixer;
152 list->id = id;
153 list->resume = resume;
154 kctl = snd_ctl_new1(knew, list);
155 if (!kctl) {
156 kfree(list);
157 return -ENOMEM;
158 }
159 kctl->private_free = snd_usb_mixer_elem_free;
160 return snd_usb_mixer_add_control(list, kctl);
161 }
162
163
164
165
166
167
168
169
170
171 static const struct rc_config {
172 u32 usb_id;
173 u8 offset;
174 u8 length;
175 u8 packet_length;
176 u8 min_packet_length;
177 u8 mute_mixer_id;
178 u32 mute_code;
179 } rc_configs[] = {
180 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 },
181 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 },
182 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 },
183 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d },
184 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d },
185 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d },
186 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 },
187 };
188
189 static void snd_usb_soundblaster_remote_complete(struct urb *urb)
190 {
191 struct usb_mixer_interface *mixer = urb->context;
192 const struct rc_config *rc = mixer->rc_cfg;
193 u32 code;
194
195 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
196 return;
197
198 code = mixer->rc_buffer[rc->offset];
199 if (rc->length == 2)
200 code |= mixer->rc_buffer[rc->offset + 1] << 8;
201
202
203 if (code == rc->mute_code)
204 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
205 mixer->rc_code = code;
206 wmb();
207 wake_up(&mixer->rc_waitq);
208 }
209
210 static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
211 long count, loff_t *offset)
212 {
213 struct usb_mixer_interface *mixer = hw->private_data;
214 int err;
215 u32 rc_code;
216
217 if (count != 1 && count != 4)
218 return -EINVAL;
219 err = wait_event_interruptible(mixer->rc_waitq,
220 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
221 if (err == 0) {
222 if (count == 1)
223 err = put_user(rc_code, buf);
224 else
225 err = put_user(rc_code, (u32 __user *)buf);
226 }
227 return err < 0 ? err : count;
228 }
229
230 static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
231 poll_table *wait)
232 {
233 struct usb_mixer_interface *mixer = hw->private_data;
234
235 poll_wait(file, &mixer->rc_waitq, wait);
236 return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0;
237 }
238
239 static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
240 {
241 struct snd_hwdep *hwdep;
242 int err, len, i;
243
244 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
245 if (rc_configs[i].usb_id == mixer->chip->usb_id)
246 break;
247 if (i >= ARRAY_SIZE(rc_configs))
248 return 0;
249 mixer->rc_cfg = &rc_configs[i];
250
251 len = mixer->rc_cfg->packet_length;
252
253 init_waitqueue_head(&mixer->rc_waitq);
254 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
255 if (err < 0)
256 return err;
257 snprintf(hwdep->name, sizeof(hwdep->name),
258 "%s remote control", mixer->chip->card->shortname);
259 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
260 hwdep->private_data = mixer;
261 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
262 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
263 hwdep->exclusive = 1;
264
265 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
266 if (!mixer->rc_urb)
267 return -ENOMEM;
268 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
269 if (!mixer->rc_setup_packet) {
270 usb_free_urb(mixer->rc_urb);
271 mixer->rc_urb = NULL;
272 return -ENOMEM;
273 }
274 mixer->rc_setup_packet->bRequestType =
275 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
276 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
277 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
278 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
279 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
280 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
281 usb_rcvctrlpipe(mixer->chip->dev, 0),
282 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
283 snd_usb_soundblaster_remote_complete, mixer);
284 return 0;
285 }
286
287 #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
288
289 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
290 {
291 ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
292 return 0;
293 }
294
295 static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
296 int value, int index)
297 {
298 struct snd_usb_audio *chip = mixer->chip;
299 int err;
300
301 err = snd_usb_lock_shutdown(chip);
302 if (err < 0)
303 return err;
304
305 if (chip->usb_id == USB_ID(0x041e, 0x3042))
306 err = snd_usb_ctl_msg(chip->dev,
307 usb_sndctrlpipe(chip->dev, 0), 0x24,
308 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
309 !value, 0, NULL, 0);
310
311 if (chip->usb_id == USB_ID(0x041e, 0x30df))
312 err = snd_usb_ctl_msg(chip->dev,
313 usb_sndctrlpipe(chip->dev, 0), 0x24,
314 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
315 !value, 0, NULL, 0);
316 else
317 err = snd_usb_ctl_msg(chip->dev,
318 usb_sndctrlpipe(chip->dev, 0), 0x24,
319 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
320 value, index + 2, NULL, 0);
321 snd_usb_unlock_shutdown(chip);
322 return err;
323 }
324
325 static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327 {
328 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
329 struct usb_mixer_interface *mixer = list->mixer;
330 int index = kcontrol->private_value & 0xff;
331 unsigned int value = ucontrol->value.integer.value[0];
332 int old_value = kcontrol->private_value >> 8;
333 int err;
334
335 if (value > 1)
336 return -EINVAL;
337 if (value == old_value)
338 return 0;
339 kcontrol->private_value = (value << 8) | index;
340 err = snd_audigy2nx_led_update(mixer, value, index);
341 return err < 0 ? err : 1;
342 }
343
344 static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
345 {
346 int priv_value = list->kctl->private_value;
347
348 return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
349 priv_value & 0xff);
350 }
351
352
353 static const struct snd_kcontrol_new snd_audigy2nx_control = {
354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
355 .info = snd_audigy2nx_led_info,
356 .get = snd_audigy2nx_led_get,
357 .put = snd_audigy2nx_led_put,
358 };
359
360 static const char * const snd_audigy2nx_led_names[] = {
361 "CMSS LED Switch",
362 "Power LED Switch",
363 "Dolby Digital LED Switch",
364 };
365
366 static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
367 {
368 int i, err;
369
370 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
371 struct snd_kcontrol_new knew;
372
373
374 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
375 continue;
376
377 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0)
378 continue;
379 if (i > 1 &&
380 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
381 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
382 mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
383 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
384 break;
385
386 knew = snd_audigy2nx_control;
387 knew.name = snd_audigy2nx_led_names[i];
388 knew.private_value = (1 << 8) | i;
389 err = add_single_ctl_with_resume(mixer, 0,
390 snd_audigy2nx_led_resume,
391 &knew, NULL);
392 if (err < 0)
393 return err;
394 }
395 return 0;
396 }
397
398 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
399 struct snd_info_buffer *buffer)
400 {
401 static const struct sb_jack {
402 int unitid;
403 const char *name;
404 } jacks_audigy2nx[] = {
405 {4, "dig in "},
406 {7, "line in"},
407 {19, "spk out"},
408 {20, "hph out"},
409 {-1, NULL}
410 }, jacks_live24ext[] = {
411 {4, "line in"},
412 {3, "hph out"},
413 {0, "RC "},
414 {-1, NULL}
415 };
416 const struct sb_jack *jacks;
417 struct usb_mixer_interface *mixer = entry->private_data;
418 int i, err;
419 u8 buf[3];
420
421 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
422 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
423 jacks = jacks_audigy2nx;
424 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
425 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
426 jacks = jacks_live24ext;
427 else
428 return;
429
430 for (i = 0; jacks[i].name; ++i) {
431 snd_iprintf(buffer, "%s: ", jacks[i].name);
432 err = snd_usb_lock_shutdown(mixer->chip);
433 if (err < 0)
434 return;
435 err = snd_usb_ctl_msg(mixer->chip->dev,
436 usb_rcvctrlpipe(mixer->chip->dev, 0),
437 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
438 USB_RECIP_INTERFACE, 0,
439 jacks[i].unitid << 8, buf, 3);
440 snd_usb_unlock_shutdown(mixer->chip);
441 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
442 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
443 else
444 snd_iprintf(buffer, "?\n");
445 }
446 }
447
448
449 static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_info *uinfo)
451 {
452 static const char * const texts[2] = {"1/2", "3/4"};
453
454 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
455 }
456
457 static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
458 struct snd_ctl_elem_value *ucontrol)
459 {
460 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
461 return 0;
462 }
463
464 static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer,
465 int value)
466 {
467 struct snd_usb_audio *chip = mixer->chip;
468 int err;
469 unsigned char buf[2];
470
471 err = snd_usb_lock_shutdown(chip);
472 if (err < 0)
473 return err;
474
475 buf[0] = 0x01;
476 buf[1] = value ? 0x02 : 0x01;
477 err = snd_usb_ctl_msg(chip->dev,
478 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
479 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
480 0x0400, 0x0e00, buf, 2);
481 snd_usb_unlock_shutdown(chip);
482 return err;
483 }
484
485 static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
486 struct snd_ctl_elem_value *ucontrol)
487 {
488 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
489 struct usb_mixer_interface *mixer = list->mixer;
490 unsigned int value = ucontrol->value.enumerated.item[0];
491 int err;
492
493 if (value > 1)
494 return -EINVAL;
495
496 if (value == kcontrol->private_value)
497 return 0;
498
499 kcontrol->private_value = value;
500 err = snd_emu0204_ch_switch_update(mixer, value);
501 return err < 0 ? err : 1;
502 }
503
504 static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list)
505 {
506 return snd_emu0204_ch_switch_update(list->mixer,
507 list->kctl->private_value);
508 }
509
510 static struct snd_kcontrol_new snd_emu0204_control = {
511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
512 .name = "Front Jack Channels",
513 .info = snd_emu0204_ch_switch_info,
514 .get = snd_emu0204_ch_switch_get,
515 .put = snd_emu0204_ch_switch_put,
516 .private_value = 0,
517 };
518
519 static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
520 {
521 return add_single_ctl_with_resume(mixer, 0,
522 snd_emu0204_ch_switch_resume,
523 &snd_emu0204_control, NULL);
524 }
525
526
527
528 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
529 struct snd_ctl_elem_value *ucontrol)
530 {
531 ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02);
532 return 0;
533 }
534
535 static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer,
536 unsigned char status)
537 {
538 struct snd_usb_audio *chip = mixer->chip;
539 int err;
540
541 err = snd_usb_lock_shutdown(chip);
542 if (err < 0)
543 return err;
544 err = snd_usb_ctl_msg(chip->dev,
545 usb_sndctrlpipe(chip->dev, 0), 0x08,
546 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
547 50, 0, &status, 1);
548 snd_usb_unlock_shutdown(chip);
549 return err;
550 }
551
552 static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
553 struct snd_ctl_elem_value *ucontrol)
554 {
555 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
556 u8 old_status, new_status;
557 int err;
558
559 old_status = kcontrol->private_value;
560 if (ucontrol->value.integer.value[0])
561 new_status = old_status | 0x02;
562 else
563 new_status = old_status & ~0x02;
564 if (new_status == old_status)
565 return 0;
566
567 kcontrol->private_value = new_status;
568 err = snd_xonar_u1_switch_update(list->mixer, new_status);
569 return err < 0 ? err : 1;
570 }
571
572 static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list)
573 {
574 return snd_xonar_u1_switch_update(list->mixer,
575 list->kctl->private_value);
576 }
577
578 static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
580 .name = "Digital Playback Switch",
581 .info = snd_ctl_boolean_mono_info,
582 .get = snd_xonar_u1_switch_get,
583 .put = snd_xonar_u1_switch_put,
584 .private_value = 0x05,
585 };
586
587 static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
588 {
589 return add_single_ctl_with_resume(mixer, 0,
590 snd_xonar_u1_switch_resume,
591 &snd_xonar_u1_output_switch, NULL);
592 }
593
594
595
596 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
597 struct snd_ctl_elem_value *ucontrol)
598 {
599 ucontrol->value.enumerated.item[0] = kctl->private_value;
600 return 0;
601 }
602
603 static int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val)
604 {
605 struct snd_usb_audio *chip = mixer->chip;
606 int err;
607 unsigned char buff[3];
608
609 err = snd_usb_lock_shutdown(chip);
610 if (err < 0)
611 return err;
612
613
614 err = snd_usb_ctl_msg(chip->dev,
615 usb_rcvctrlpipe(chip->dev, 0), 0x81,
616 USB_DIR_IN |
617 USB_TYPE_CLASS |
618 USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
619 if (err < 0)
620 goto err;
621 err = snd_usb_ctl_msg(chip->dev,
622 usb_rcvctrlpipe(chip->dev, 0), 0x81,
623 USB_DIR_IN |
624 USB_TYPE_CLASS |
625 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
626 if (err < 0)
627 goto err;
628
629
630
631
632
633
634
635
636 if (val == 0) {
637 buff[0] = 0x80;
638 buff[1] = 0xbb;
639 buff[2] = 0x00;
640 } else {
641 buff[0] = buff[1] = buff[2] = 0x00;
642 }
643
644
645 err = snd_usb_ctl_msg(chip->dev,
646 usb_sndctrlpipe(chip->dev, 0), 0x1,
647 USB_TYPE_CLASS |
648 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
649 if (err < 0)
650 goto err;
651 err = snd_usb_ctl_msg(chip->dev,
652 usb_rcvctrlpipe(chip->dev, 0), 0x81,
653 USB_DIR_IN |
654 USB_TYPE_CLASS |
655 USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
656 if (err < 0)
657 goto err;
658 err = snd_usb_ctl_msg(chip->dev,
659 usb_rcvctrlpipe(chip->dev, 0), 0x81,
660 USB_DIR_IN |
661 USB_TYPE_CLASS |
662 USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
663 if (err < 0)
664 goto err;
665
666 err:
667 snd_usb_unlock_shutdown(chip);
668 return err;
669 }
670
671 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
672 struct snd_ctl_elem_value *ucontrol)
673 {
674 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
675 struct usb_mixer_interface *mixer = list->mixer;
676 int err;
677 bool cur_val, new_val;
678
679 cur_val = kctl->private_value;
680 new_val = ucontrol->value.enumerated.item[0];
681 if (cur_val == new_val)
682 return 0;
683
684 kctl->private_value = new_val;
685 err = snd_mbox1_switch_update(mixer, new_val);
686 return err < 0 ? err : 1;
687 }
688
689 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
690 struct snd_ctl_elem_info *uinfo)
691 {
692 static const char *const texts[2] = {
693 "Internal",
694 "S/PDIF"
695 };
696
697 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
698 }
699
700 static int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list)
701 {
702 return snd_mbox1_switch_update(list->mixer, list->kctl->private_value);
703 }
704
705 static struct snd_kcontrol_new snd_mbox1_switch = {
706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
707 .name = "Clock Source",
708 .index = 0,
709 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
710 .info = snd_mbox1_switch_info,
711 .get = snd_mbox1_switch_get,
712 .put = snd_mbox1_switch_put,
713 .private_value = 0
714 };
715
716 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
717 {
718 return add_single_ctl_with_resume(mixer, 0,
719 snd_mbox1_switch_resume,
720 &snd_mbox1_switch, NULL);
721 }
722
723
724
725 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
726
727 static int snd_ni_control_init_val(struct usb_mixer_interface *mixer,
728 struct snd_kcontrol *kctl)
729 {
730 struct usb_device *dev = mixer->chip->dev;
731 unsigned int pval = kctl->private_value;
732 u8 value;
733 int err;
734
735 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
736 (pval >> 16) & 0xff,
737 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
738 0, pval & 0xffff, &value, 1);
739 if (err < 0) {
740 dev_err(&dev->dev,
741 "unable to issue vendor read request (ret = %d)", err);
742 return err;
743 }
744
745 kctl->private_value |= ((unsigned int)value << 24);
746 return 0;
747 }
748
749 static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
751 {
752 ucontrol->value.integer.value[0] = kcontrol->private_value >> 24;
753 return 0;
754 }
755
756 static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list)
757 {
758 struct snd_usb_audio *chip = list->mixer->chip;
759 unsigned int pval = list->kctl->private_value;
760 int err;
761
762 err = snd_usb_lock_shutdown(chip);
763 if (err < 0)
764 return err;
765 err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
766 (pval >> 16) & 0xff,
767 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
768 pval >> 24, pval & 0xffff, NULL, 0, 1000);
769 snd_usb_unlock_shutdown(chip);
770 return err;
771 }
772
773 static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
775 {
776 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
777 u8 oldval = (kcontrol->private_value >> 24) & 0xff;
778 u8 newval = ucontrol->value.integer.value[0];
779 int err;
780
781 if (oldval == newval)
782 return 0;
783
784 kcontrol->private_value &= ~(0xff << 24);
785 kcontrol->private_value |= (unsigned int)newval << 24;
786 err = snd_ni_update_cur_val(list);
787 return err < 0 ? err : 1;
788 }
789
790 static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = {
791 {
792 .name = "Direct Thru Channel A",
793 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
794 },
795 {
796 .name = "Direct Thru Channel B",
797 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
798 },
799 {
800 .name = "Phono Input Channel A",
801 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
802 },
803 {
804 .name = "Phono Input Channel B",
805 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
806 },
807 };
808
809 static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = {
810 {
811 .name = "Direct Thru Channel A",
812 .private_value = _MAKE_NI_CONTROL(0x01, 0x03),
813 },
814 {
815 .name = "Direct Thru Channel B",
816 .private_value = _MAKE_NI_CONTROL(0x01, 0x05),
817 },
818 {
819 .name = "Direct Thru Channel C",
820 .private_value = _MAKE_NI_CONTROL(0x01, 0x07),
821 },
822 {
823 .name = "Direct Thru Channel D",
824 .private_value = _MAKE_NI_CONTROL(0x01, 0x09),
825 },
826 {
827 .name = "Phono Input Channel A",
828 .private_value = _MAKE_NI_CONTROL(0x02, 0x03),
829 },
830 {
831 .name = "Phono Input Channel B",
832 .private_value = _MAKE_NI_CONTROL(0x02, 0x05),
833 },
834 {
835 .name = "Phono Input Channel C",
836 .private_value = _MAKE_NI_CONTROL(0x02, 0x07),
837 },
838 {
839 .name = "Phono Input Channel D",
840 .private_value = _MAKE_NI_CONTROL(0x02, 0x09),
841 },
842 };
843
844 static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
845 const struct snd_kcontrol_new *kc,
846 unsigned int count)
847 {
848 int i, err = 0;
849 struct snd_kcontrol_new template = {
850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
851 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
852 .get = snd_nativeinstruments_control_get,
853 .put = snd_nativeinstruments_control_put,
854 .info = snd_ctl_boolean_mono_info,
855 };
856
857 for (i = 0; i < count; i++) {
858 struct usb_mixer_elem_list *list;
859
860 template.name = kc[i].name;
861 template.private_value = kc[i].private_value;
862
863 err = add_single_ctl_with_resume(mixer, 0,
864 snd_ni_update_cur_val,
865 &template, &list);
866 if (err < 0)
867 break;
868 snd_ni_control_init_val(mixer, list->kctl);
869 }
870
871 return err;
872 }
873
874
875
876 static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_info *uinfo)
878 {
879 static const char *const texts[8] = {
880 "Room 1", "Room 2", "Room 3", "Hall 1",
881 "Hall 2", "Plate", "Delay", "Echo"
882 };
883
884 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
885 }
886
887 static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer,
888 struct snd_kcontrol *kctl)
889 {
890 struct usb_device *dev = mixer->chip->dev;
891 unsigned int pval = kctl->private_value;
892 int err;
893 unsigned char value[2];
894
895 value[0] = 0x00;
896 value[1] = 0x00;
897
898 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
899 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
900 pval & 0xff00,
901 snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8),
902 value, 2);
903 if (err < 0)
904 return err;
905
906 kctl->private_value |= (unsigned int)value[0] << 24;
907 return 0;
908 }
909
910 static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
911 struct snd_ctl_elem_value *ucontrol)
912 {
913 ucontrol->value.enumerated.item[0] = kctl->private_value >> 24;
914 return 0;
915 }
916
917 static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list)
918 {
919 struct snd_usb_audio *chip = list->mixer->chip;
920 unsigned int pval = list->kctl->private_value;
921 unsigned char value[2];
922 int err;
923
924 value[0] = pval >> 24;
925 value[1] = 0;
926
927 err = snd_usb_lock_shutdown(chip);
928 if (err < 0)
929 return err;
930 err = snd_usb_ctl_msg(chip->dev,
931 usb_sndctrlpipe(chip->dev, 0),
932 UAC_SET_CUR,
933 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
934 pval & 0xff00,
935 snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8),
936 value, 2);
937 snd_usb_unlock_shutdown(chip);
938 return err;
939 }
940
941 static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
942 struct snd_ctl_elem_value *ucontrol)
943 {
944 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
945 unsigned int pval = list->kctl->private_value;
946 int cur_val, err, new_val;
947
948 cur_val = pval >> 24;
949 new_val = ucontrol->value.enumerated.item[0];
950 if (cur_val == new_val)
951 return 0;
952
953 kctl->private_value &= ~(0xff << 24);
954 kctl->private_value |= new_val << 24;
955 err = snd_ftu_eff_switch_update(list);
956 return err < 0 ? err : 1;
957 }
958
959 static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
960 int validx, int bUnitID)
961 {
962 static struct snd_kcontrol_new template = {
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
964 .name = "Effect Program Switch",
965 .index = 0,
966 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
967 .info = snd_ftu_eff_switch_info,
968 .get = snd_ftu_eff_switch_get,
969 .put = snd_ftu_eff_switch_put
970 };
971 struct usb_mixer_elem_list *list;
972 int err;
973
974 err = add_single_ctl_with_resume(mixer, bUnitID,
975 snd_ftu_eff_switch_update,
976 &template, &list);
977 if (err < 0)
978 return err;
979 list->kctl->private_value = (validx << 8) | bUnitID;
980 snd_ftu_eff_switch_init(mixer, list->kctl);
981 return 0;
982 }
983
984
985 static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
986 {
987 char name[64];
988 unsigned int control, cmask;
989 int in, out, err;
990
991 const unsigned int id = 5;
992 const int val_type = USB_MIXER_S16;
993
994 for (out = 0; out < 8; out++) {
995 control = out + 1;
996 for (in = 0; in < 8; in++) {
997 cmask = 1 << in;
998 snprintf(name, sizeof(name),
999 "AIn%d - Out%d Capture Volume",
1000 in + 1, out + 1);
1001 err = snd_create_std_mono_ctl(mixer, id, control,
1002 cmask, val_type, name,
1003 &snd_usb_mixer_vol_tlv);
1004 if (err < 0)
1005 return err;
1006 }
1007 for (in = 8; in < 16; in++) {
1008 cmask = 1 << in;
1009 snprintf(name, sizeof(name),
1010 "DIn%d - Out%d Playback Volume",
1011 in - 7, out + 1);
1012 err = snd_create_std_mono_ctl(mixer, id, control,
1013 cmask, val_type, name,
1014 &snd_usb_mixer_vol_tlv);
1015 if (err < 0)
1016 return err;
1017 }
1018 }
1019
1020 return 0;
1021 }
1022
1023
1024 static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1025 {
1026 static const char name[] = "Effect Volume";
1027 const unsigned int id = 6;
1028 const int val_type = USB_MIXER_U8;
1029 const unsigned int control = 2;
1030 const unsigned int cmask = 0;
1031
1032 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1033 name, snd_usb_mixer_vol_tlv);
1034 }
1035
1036
1037 static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1038 {
1039 static const char name[] = "Effect Duration";
1040 const unsigned int id = 6;
1041 const int val_type = USB_MIXER_S16;
1042 const unsigned int control = 3;
1043 const unsigned int cmask = 0;
1044
1045 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1046 name, snd_usb_mixer_vol_tlv);
1047 }
1048
1049
1050 static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1051 {
1052 static const char name[] = "Effect Feedback Volume";
1053 const unsigned int id = 6;
1054 const int val_type = USB_MIXER_U8;
1055 const unsigned int control = 4;
1056 const unsigned int cmask = 0;
1057
1058 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1059 name, NULL);
1060 }
1061
1062 static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
1063 {
1064 unsigned int cmask;
1065 int err, ch;
1066 char name[48];
1067
1068 const unsigned int id = 7;
1069 const int val_type = USB_MIXER_S16;
1070 const unsigned int control = 7;
1071
1072 for (ch = 0; ch < 4; ++ch) {
1073 cmask = 1 << ch;
1074 snprintf(name, sizeof(name),
1075 "Effect Return %d Volume", ch + 1);
1076 err = snd_create_std_mono_ctl(mixer, id, control,
1077 cmask, val_type, name,
1078 snd_usb_mixer_vol_tlv);
1079 if (err < 0)
1080 return err;
1081 }
1082
1083 return 0;
1084 }
1085
1086 static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
1087 {
1088 unsigned int cmask;
1089 int err, ch;
1090 char name[48];
1091
1092 const unsigned int id = 5;
1093 const int val_type = USB_MIXER_S16;
1094 const unsigned int control = 9;
1095
1096 for (ch = 0; ch < 8; ++ch) {
1097 cmask = 1 << ch;
1098 snprintf(name, sizeof(name),
1099 "Effect Send AIn%d Volume", ch + 1);
1100 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1101 val_type, name,
1102 snd_usb_mixer_vol_tlv);
1103 if (err < 0)
1104 return err;
1105 }
1106 for (ch = 8; ch < 16; ++ch) {
1107 cmask = 1 << ch;
1108 snprintf(name, sizeof(name),
1109 "Effect Send DIn%d Volume", ch - 7);
1110 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
1111 val_type, name,
1112 snd_usb_mixer_vol_tlv);
1113 if (err < 0)
1114 return err;
1115 }
1116 return 0;
1117 }
1118
1119 static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
1120 {
1121 int err;
1122
1123 err = snd_ftu_create_volume_ctls(mixer);
1124 if (err < 0)
1125 return err;
1126
1127 err = snd_ftu_create_effect_switch(mixer, 1, 6);
1128 if (err < 0)
1129 return err;
1130
1131 err = snd_ftu_create_effect_volume_ctl(mixer);
1132 if (err < 0)
1133 return err;
1134
1135 err = snd_ftu_create_effect_duration_ctl(mixer);
1136 if (err < 0)
1137 return err;
1138
1139 err = snd_ftu_create_effect_feedback_ctl(mixer);
1140 if (err < 0)
1141 return err;
1142
1143 err = snd_ftu_create_effect_return_ctls(mixer);
1144 if (err < 0)
1145 return err;
1146
1147 err = snd_ftu_create_effect_send_ctls(mixer);
1148 if (err < 0)
1149 return err;
1150
1151 return 0;
1152 }
1153
1154 void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1155 unsigned char samplerate_id)
1156 {
1157 struct usb_mixer_interface *mixer;
1158 struct usb_mixer_elem_info *cval;
1159 int unitid = 12;
1160
1161 list_for_each_entry(mixer, &chip->mixer_list, list) {
1162 if (mixer->id_elems[unitid]) {
1163 cval = mixer_elem_list_to_info(mixer->id_elems[unitid]);
1164 snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
1165 cval->control << 8,
1166 samplerate_id);
1167 snd_usb_mixer_notify_id(mixer, unitid);
1168 break;
1169 }
1170 }
1171 }
1172
1173
1174
1175 static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1176 {
1177 char name[64];
1178 unsigned int cmask, offset;
1179 int out, chan, err;
1180 int num_outs = 0;
1181 int num_ins = 0;
1182
1183 const unsigned int id = 0x40;
1184 const int val_type = USB_MIXER_S16;
1185 const int control = 1;
1186
1187 switch (mixer->chip->usb_id) {
1188 case USB_ID(0x0763, 0x2030):
1189 num_outs = 6;
1190 num_ins = 4;
1191 break;
1192 case USB_ID(0x0763, 0x2031):
1193 num_outs = 8;
1194 num_ins = 6;
1195 break;
1196 }
1197
1198 for (chan = 0; chan < num_outs + num_ins; chan++) {
1199 for (out = 0; out < num_outs; out++) {
1200 if (chan < num_outs) {
1201 snprintf(name, sizeof(name),
1202 "PCM%d-Out%d Playback Volume",
1203 chan + 1, out + 1);
1204 } else {
1205 snprintf(name, sizeof(name),
1206 "In%d-Out%d Playback Volume",
1207 chan - num_outs + 1, out + 1);
1208 }
1209
1210 cmask = (out == 0) ? 0 : 1 << (out - 1);
1211 offset = chan * num_outs;
1212 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1213 cmask, val_type, offset, name,
1214 &snd_usb_mixer_vol_tlv);
1215 if (err < 0)
1216 return err;
1217 }
1218 }
1219
1220 return 0;
1221 }
1222
1223
1224 static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
1225 {
1226 static const char name[] = "Effect Volume";
1227 const unsigned int id = 0x43;
1228 const int val_type = USB_MIXER_U8;
1229 const unsigned int control = 3;
1230 const unsigned int cmask = 0;
1231
1232 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1233 name, snd_usb_mixer_vol_tlv);
1234 }
1235
1236
1237 static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
1238 {
1239 static const char name[] = "Effect Duration";
1240 const unsigned int id = 0x43;
1241 const int val_type = USB_MIXER_S16;
1242 const unsigned int control = 4;
1243 const unsigned int cmask = 0;
1244
1245 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1246 name, snd_usb_mixer_vol_tlv);
1247 }
1248
1249
1250 static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
1251 {
1252 static const char name[] = "Effect Feedback Volume";
1253 const unsigned int id = 0x43;
1254 const int val_type = USB_MIXER_U8;
1255 const unsigned int control = 5;
1256 const unsigned int cmask = 0;
1257
1258 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
1259 name, NULL);
1260 }
1261
1262 static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1263 {
1264 char name[64];
1265 unsigned int cmask;
1266 int chan, err;
1267 int num_outs = 0;
1268 int num_ins = 0;
1269
1270 const unsigned int id = 0x42;
1271 const int val_type = USB_MIXER_S16;
1272 const int control = 1;
1273
1274 switch (mixer->chip->usb_id) {
1275 case USB_ID(0x0763, 0x2030):
1276 num_outs = 6;
1277 num_ins = 4;
1278 break;
1279 case USB_ID(0x0763, 0x2031):
1280 num_outs = 8;
1281 num_ins = 6;
1282 break;
1283 }
1284
1285 for (chan = 0; chan < num_outs + num_ins; chan++) {
1286 if (chan < num_outs) {
1287 snprintf(name, sizeof(name),
1288 "Effect Send DOut%d",
1289 chan + 1);
1290 } else {
1291 snprintf(name, sizeof(name),
1292 "Effect Send AIn%d",
1293 chan - num_outs + 1);
1294 }
1295
1296 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1297 err = snd_create_std_mono_ctl(mixer, id, control,
1298 cmask, val_type, name,
1299 &snd_usb_mixer_vol_tlv);
1300 if (err < 0)
1301 return err;
1302 }
1303
1304 return 0;
1305 }
1306
1307 static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer)
1308 {
1309 char name[64];
1310 unsigned int cmask;
1311 int chan, err;
1312 int num_outs = 0;
1313 int offset = 0;
1314
1315 const unsigned int id = 0x40;
1316 const int val_type = USB_MIXER_S16;
1317 const int control = 1;
1318
1319 switch (mixer->chip->usb_id) {
1320 case USB_ID(0x0763, 0x2030):
1321 num_outs = 6;
1322 offset = 0x3c;
1323
1324 break;
1325 case USB_ID(0x0763, 0x2031):
1326 num_outs = 8;
1327 offset = 0x70;
1328
1329 break;
1330 }
1331
1332 for (chan = 0; chan < num_outs; chan++) {
1333 snprintf(name, sizeof(name),
1334 "Effect Return %d",
1335 chan + 1);
1336
1337 cmask = (chan == 0) ? 0 :
1338 1 << (chan + (chan % 2) * num_outs - 1);
1339 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1340 cmask, val_type, offset, name,
1341 &snd_usb_mixer_vol_tlv);
1342 if (err < 0)
1343 return err;
1344 }
1345
1346 return 0;
1347 }
1348
1349 static int snd_c400_create_mixer(struct usb_mixer_interface *mixer)
1350 {
1351 int err;
1352
1353 err = snd_c400_create_vol_ctls(mixer);
1354 if (err < 0)
1355 return err;
1356
1357 err = snd_c400_create_effect_vol_ctls(mixer);
1358 if (err < 0)
1359 return err;
1360
1361 err = snd_c400_create_effect_ret_vol_ctls(mixer);
1362 if (err < 0)
1363 return err;
1364
1365 err = snd_ftu_create_effect_switch(mixer, 2, 0x43);
1366 if (err < 0)
1367 return err;
1368
1369 err = snd_c400_create_effect_volume_ctl(mixer);
1370 if (err < 0)
1371 return err;
1372
1373 err = snd_c400_create_effect_duration_ctl(mixer);
1374 if (err < 0)
1375 return err;
1376
1377 err = snd_c400_create_effect_feedback_ctl(mixer);
1378 if (err < 0)
1379 return err;
1380
1381 return 0;
1382 }
1383
1384
1385
1386
1387
1388
1389 static struct std_mono_table ebox44_table[] = {
1390 {
1391 .unitid = 4,
1392 .control = 1,
1393 .cmask = 0x0,
1394 .val_type = USB_MIXER_INV_BOOLEAN,
1395 .name = "Headphone Playback Switch"
1396 },
1397 {
1398 .unitid = 4,
1399 .control = 2,
1400 .cmask = 0x1,
1401 .val_type = USB_MIXER_S16,
1402 .name = "Headphone A Mix Playback Volume"
1403 },
1404 {
1405 .unitid = 4,
1406 .control = 2,
1407 .cmask = 0x2,
1408 .val_type = USB_MIXER_S16,
1409 .name = "Headphone B Mix Playback Volume"
1410 },
1411
1412 {
1413 .unitid = 7,
1414 .control = 1,
1415 .cmask = 0x0,
1416 .val_type = USB_MIXER_INV_BOOLEAN,
1417 .name = "Output Playback Switch"
1418 },
1419 {
1420 .unitid = 7,
1421 .control = 2,
1422 .cmask = 0x1,
1423 .val_type = USB_MIXER_S16,
1424 .name = "Output A Playback Volume"
1425 },
1426 {
1427 .unitid = 7,
1428 .control = 2,
1429 .cmask = 0x2,
1430 .val_type = USB_MIXER_S16,
1431 .name = "Output B Playback Volume"
1432 },
1433
1434 {
1435 .unitid = 10,
1436 .control = 1,
1437 .cmask = 0x0,
1438 .val_type = USB_MIXER_INV_BOOLEAN,
1439 .name = "Input Capture Switch"
1440 },
1441 {
1442 .unitid = 10,
1443 .control = 2,
1444 .cmask = 0x1,
1445 .val_type = USB_MIXER_S16,
1446 .name = "Input A Capture Volume"
1447 },
1448 {
1449 .unitid = 10,
1450 .control = 2,
1451 .cmask = 0x2,
1452 .val_type = USB_MIXER_S16,
1453 .name = "Input B Capture Volume"
1454 },
1455
1456 {}
1457 };
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481 static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol,
1482 struct snd_ctl_elem_info *uinfo)
1483 {
1484 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1485 uinfo->count = 1;
1486 return 0;
1487 }
1488
1489 static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1491 {
1492 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1493 struct snd_usb_audio *chip = list->mixer->chip;
1494 int err;
1495 struct usb_interface *iface;
1496 struct usb_host_interface *alts;
1497 unsigned int ep;
1498 unsigned char data[3];
1499 int rate;
1500
1501 err = snd_usb_lock_shutdown(chip);
1502 if (err < 0)
1503 return err;
1504
1505 ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff;
1506 ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff;
1507 ucontrol->value.iec958.status[2] = 0x00;
1508
1509
1510 iface = usb_ifnum_to_if(chip->dev, 1);
1511 if (!iface || iface->num_altsetting < 2) {
1512 err = -EINVAL;
1513 goto end;
1514 }
1515 alts = &iface->altsetting[1];
1516 if (get_iface_desc(alts)->bNumEndpoints < 1) {
1517 err = -EINVAL;
1518 goto end;
1519 }
1520 ep = get_endpoint(alts, 0)->bEndpointAddress;
1521
1522 err = snd_usb_ctl_msg(chip->dev,
1523 usb_rcvctrlpipe(chip->dev, 0),
1524 UAC_GET_CUR,
1525 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
1526 UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
1527 ep,
1528 data,
1529 sizeof(data));
1530 if (err < 0)
1531 goto end;
1532
1533 rate = data[0] | (data[1] << 8) | (data[2] << 16);
1534 ucontrol->value.iec958.status[3] = (rate == 48000) ?
1535 IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100;
1536
1537 err = 0;
1538 end:
1539 snd_usb_unlock_shutdown(chip);
1540 return err;
1541 }
1542
1543 static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list)
1544 {
1545 struct snd_usb_audio *chip = list->mixer->chip;
1546 unsigned int pval = list->kctl->private_value;
1547 u8 reg;
1548 int err;
1549
1550 err = snd_usb_lock_shutdown(chip);
1551 if (err < 0)
1552 return err;
1553
1554 reg = ((pval >> 4) & 0xf0) | (pval & 0x0f);
1555 err = snd_usb_ctl_msg(chip->dev,
1556 usb_sndctrlpipe(chip->dev, 0),
1557 UAC_SET_CUR,
1558 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1559 reg,
1560 2,
1561 NULL,
1562 0);
1563 if (err < 0)
1564 goto end;
1565
1566 reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20;
1567 reg |= (pval >> 12) & 0x0f;
1568 err = snd_usb_ctl_msg(chip->dev,
1569 usb_sndctrlpipe(chip->dev, 0),
1570 UAC_SET_CUR,
1571 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1572 reg,
1573 3,
1574 NULL,
1575 0);
1576 if (err < 0)
1577 goto end;
1578
1579 end:
1580 snd_usb_unlock_shutdown(chip);
1581 return err;
1582 }
1583
1584 static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol,
1585 struct snd_ctl_elem_value *ucontrol)
1586 {
1587 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1588 unsigned int pval, pval_old;
1589 int err;
1590
1591 pval = pval_old = kcontrol->private_value;
1592 pval &= 0xfffff0f0;
1593 pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8;
1594 pval |= (ucontrol->value.iec958.status[0] & 0x0f);
1595
1596 pval &= 0xffff0fff;
1597 pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8;
1598
1599
1600
1601
1602
1603 if (pval == pval_old)
1604 return 0;
1605
1606 kcontrol->private_value = pval;
1607 err = snd_microii_spdif_default_update(list);
1608 return err < 0 ? err : 1;
1609 }
1610
1611 static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol,
1612 struct snd_ctl_elem_value *ucontrol)
1613 {
1614 ucontrol->value.iec958.status[0] = 0x0f;
1615 ucontrol->value.iec958.status[1] = 0xff;
1616 ucontrol->value.iec958.status[2] = 0x00;
1617 ucontrol->value.iec958.status[3] = 0x00;
1618
1619 return 0;
1620 }
1621
1622 static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_value *ucontrol)
1624 {
1625 ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02);
1626
1627 return 0;
1628 }
1629
1630 static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list)
1631 {
1632 struct snd_usb_audio *chip = list->mixer->chip;
1633 u8 reg = list->kctl->private_value;
1634 int err;
1635
1636 err = snd_usb_lock_shutdown(chip);
1637 if (err < 0)
1638 return err;
1639
1640 err = snd_usb_ctl_msg(chip->dev,
1641 usb_sndctrlpipe(chip->dev, 0),
1642 UAC_SET_CUR,
1643 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
1644 reg,
1645 9,
1646 NULL,
1647 0);
1648
1649 snd_usb_unlock_shutdown(chip);
1650 return err;
1651 }
1652
1653 static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol,
1654 struct snd_ctl_elem_value *ucontrol)
1655 {
1656 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1657 u8 reg;
1658 int err;
1659
1660 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a;
1661 if (reg != list->kctl->private_value)
1662 return 0;
1663
1664 kcontrol->private_value = reg;
1665 err = snd_microii_spdif_switch_update(list);
1666 return err < 0 ? err : 1;
1667 }
1668
1669 static struct snd_kcontrol_new snd_microii_mixer_spdif[] = {
1670 {
1671 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1672 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1673 .info = snd_microii_spdif_info,
1674 .get = snd_microii_spdif_default_get,
1675 .put = snd_microii_spdif_default_put,
1676 .private_value = 0x00000100UL,
1677 },
1678 {
1679 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1680 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1681 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1682 .info = snd_microii_spdif_info,
1683 .get = snd_microii_spdif_mask_get,
1684 },
1685 {
1686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1687 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
1688 .info = snd_ctl_boolean_mono_info,
1689 .get = snd_microii_spdif_switch_get,
1690 .put = snd_microii_spdif_switch_put,
1691 .private_value = 0x00000028UL,
1692 }
1693 };
1694
1695 static int snd_microii_controls_create(struct usb_mixer_interface *mixer)
1696 {
1697 int err, i;
1698 static usb_mixer_elem_resume_func_t resume_funcs[] = {
1699 snd_microii_spdif_default_update,
1700 NULL,
1701 snd_microii_spdif_switch_update
1702 };
1703
1704 for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) {
1705 err = add_single_ctl_with_resume(mixer, 0,
1706 resume_funcs[i],
1707 &snd_microii_mixer_spdif[i],
1708 NULL);
1709 if (err < 0)
1710 return err;
1711 }
1712
1713 return 0;
1714 }
1715
1716
1717
1718 static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
1720 {
1721 ucontrol->value.integer.value[0] = kcontrol->private_value;
1722 return 0;
1723 }
1724
1725 static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer,
1726 unsigned char state)
1727 {
1728 struct snd_usb_audio *chip = mixer->chip;
1729 int err;
1730 unsigned char buff[2];
1731
1732 buff[0] = 0x02;
1733 buff[1] = state ? 0x02 : 0x00;
1734
1735 err = snd_usb_lock_shutdown(chip);
1736 if (err < 0)
1737 return err;
1738 err = snd_usb_ctl_msg(chip->dev,
1739 usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT,
1740 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1741 0x0202, 3, buff, 2);
1742 snd_usb_unlock_shutdown(chip);
1743 return err;
1744 }
1745
1746 static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1748 {
1749 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1750 unsigned char value = !!ucontrol->value.integer.value[0];
1751 int err;
1752
1753 if (kcontrol->private_value == value)
1754 return 0;
1755 kcontrol->private_value = value;
1756 err = snd_soundblaster_e1_switch_update(list->mixer, value);
1757 return err < 0 ? err : 1;
1758 }
1759
1760 static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list)
1761 {
1762 return snd_soundblaster_e1_switch_update(list->mixer,
1763 list->kctl->private_value);
1764 }
1765
1766 static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_info *uinfo)
1768 {
1769 static const char *const texts[2] = {
1770 "Mic", "Aux"
1771 };
1772
1773 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
1774 }
1775
1776 static struct snd_kcontrol_new snd_soundblaster_e1_input_switch = {
1777 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1778 .name = "Input Source",
1779 .info = snd_soundblaster_e1_switch_info,
1780 .get = snd_soundblaster_e1_switch_get,
1781 .put = snd_soundblaster_e1_switch_put,
1782 .private_value = 0,
1783 };
1784
1785 static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer)
1786 {
1787 return add_single_ctl_with_resume(mixer, 0,
1788 snd_soundblaster_e1_switch_resume,
1789 &snd_soundblaster_e1_input_switch,
1790 NULL);
1791 }
1792
1793 static void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id)
1794 {
1795 u16 buf = 0;
1796
1797 snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
1798 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1799 ch, snd_usb_ctrl_intf(chip) | (id << 8),
1800 &buf, 2);
1801 }
1802
1803 static int dell_dock_mixer_init(struct usb_mixer_interface *mixer)
1804 {
1805
1806 dell_dock_init_vol(mixer->chip, 1, 16);
1807 dell_dock_init_vol(mixer->chip, 2, 16);
1808 dell_dock_init_vol(mixer->chip, 1, 19);
1809 dell_dock_init_vol(mixer->chip, 2, 19);
1810 return 0;
1811 }
1812
1813
1814
1815 #define SND_RME_GET_STATUS1 23
1816 #define SND_RME_GET_CURRENT_FREQ 17
1817 #define SND_RME_CLK_SYSTEM_SHIFT 16
1818 #define SND_RME_CLK_SYSTEM_MASK 0x1f
1819 #define SND_RME_CLK_AES_SHIFT 8
1820 #define SND_RME_CLK_SPDIF_SHIFT 12
1821 #define SND_RME_CLK_AES_SPDIF_MASK 0xf
1822 #define SND_RME_CLK_SYNC_SHIFT 6
1823 #define SND_RME_CLK_SYNC_MASK 0x3
1824 #define SND_RME_CLK_FREQMUL_SHIFT 18
1825 #define SND_RME_CLK_FREQMUL_MASK 0x7
1826 #define SND_RME_CLK_SYSTEM(x) \
1827 ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK)
1828 #define SND_RME_CLK_AES(x) \
1829 ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1830 #define SND_RME_CLK_SPDIF(x) \
1831 ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK)
1832 #define SND_RME_CLK_SYNC(x) \
1833 ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK)
1834 #define SND_RME_CLK_FREQMUL(x) \
1835 ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK)
1836 #define SND_RME_CLK_AES_LOCK 0x1
1837 #define SND_RME_CLK_AES_SYNC 0x4
1838 #define SND_RME_CLK_SPDIF_LOCK 0x2
1839 #define SND_RME_CLK_SPDIF_SYNC 0x8
1840 #define SND_RME_SPDIF_IF_SHIFT 4
1841 #define SND_RME_SPDIF_FORMAT_SHIFT 5
1842 #define SND_RME_BINARY_MASK 0x1
1843 #define SND_RME_SPDIF_IF(x) \
1844 ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK)
1845 #define SND_RME_SPDIF_FORMAT(x) \
1846 ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK)
1847
1848 static const u32 snd_rme_rate_table[] = {
1849 32000, 44100, 48000, 50000,
1850 64000, 88200, 96000, 100000,
1851 128000, 176400, 192000, 200000,
1852 256000, 352800, 384000, 400000,
1853 512000, 705600, 768000, 800000
1854 };
1855
1856 #define SND_RME_RATE_IDX_AES_SPDIF_NUM 12
1857
1858 enum snd_rme_domain {
1859 SND_RME_DOMAIN_SYSTEM,
1860 SND_RME_DOMAIN_AES,
1861 SND_RME_DOMAIN_SPDIF
1862 };
1863
1864 enum snd_rme_clock_status {
1865 SND_RME_CLOCK_NOLOCK,
1866 SND_RME_CLOCK_LOCK,
1867 SND_RME_CLOCK_SYNC
1868 };
1869
1870 static int snd_rme_read_value(struct snd_usb_audio *chip,
1871 unsigned int item,
1872 u32 *value)
1873 {
1874 struct usb_device *dev = chip->dev;
1875 int err;
1876
1877 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1878 item,
1879 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1880 0, 0,
1881 value, sizeof(*value));
1882 if (err < 0)
1883 dev_err(&dev->dev,
1884 "unable to issue vendor read request %d (ret = %d)",
1885 item, err);
1886 return err;
1887 }
1888
1889 static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
1890 u32 *status1)
1891 {
1892 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
1893 struct snd_usb_audio *chip = list->mixer->chip;
1894 int err;
1895
1896 err = snd_usb_lock_shutdown(chip);
1897 if (err < 0)
1898 return err;
1899 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
1900 snd_usb_unlock_shutdown(chip);
1901 return err;
1902 }
1903
1904 static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
1905 struct snd_ctl_elem_value *ucontrol)
1906 {
1907 u32 status1;
1908 u32 rate = 0;
1909 int idx;
1910 int err;
1911
1912 err = snd_rme_get_status1(kcontrol, &status1);
1913 if (err < 0)
1914 return err;
1915 switch (kcontrol->private_value) {
1916 case SND_RME_DOMAIN_SYSTEM:
1917 idx = SND_RME_CLK_SYSTEM(status1);
1918 if (idx < ARRAY_SIZE(snd_rme_rate_table))
1919 rate = snd_rme_rate_table[idx];
1920 break;
1921 case SND_RME_DOMAIN_AES:
1922 idx = SND_RME_CLK_AES(status1);
1923 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1924 rate = snd_rme_rate_table[idx];
1925 break;
1926 case SND_RME_DOMAIN_SPDIF:
1927 idx = SND_RME_CLK_SPDIF(status1);
1928 if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM)
1929 rate = snd_rme_rate_table[idx];
1930 break;
1931 default:
1932 return -EINVAL;
1933 }
1934 ucontrol->value.integer.value[0] = rate;
1935 return 0;
1936 }
1937
1938 static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
1939 struct snd_ctl_elem_value *ucontrol)
1940 {
1941 u32 status1;
1942 int idx = SND_RME_CLOCK_NOLOCK;
1943 int err;
1944
1945 err = snd_rme_get_status1(kcontrol, &status1);
1946 if (err < 0)
1947 return err;
1948 switch (kcontrol->private_value) {
1949 case SND_RME_DOMAIN_AES:
1950 if (status1 & SND_RME_CLK_AES_SYNC)
1951 idx = SND_RME_CLOCK_SYNC;
1952 else if (status1 & SND_RME_CLK_AES_LOCK)
1953 idx = SND_RME_CLOCK_LOCK;
1954 break;
1955 case SND_RME_DOMAIN_SPDIF:
1956 if (status1 & SND_RME_CLK_SPDIF_SYNC)
1957 idx = SND_RME_CLOCK_SYNC;
1958 else if (status1 & SND_RME_CLK_SPDIF_LOCK)
1959 idx = SND_RME_CLOCK_LOCK;
1960 break;
1961 default:
1962 return -EINVAL;
1963 }
1964 ucontrol->value.enumerated.item[0] = idx;
1965 return 0;
1966 }
1967
1968 static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
1969 struct snd_ctl_elem_value *ucontrol)
1970 {
1971 u32 status1;
1972 int err;
1973
1974 err = snd_rme_get_status1(kcontrol, &status1);
1975 if (err < 0)
1976 return err;
1977 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1);
1978 return 0;
1979 }
1980
1981 static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
1982 struct snd_ctl_elem_value *ucontrol)
1983 {
1984 u32 status1;
1985 int err;
1986
1987 err = snd_rme_get_status1(kcontrol, &status1);
1988 if (err < 0)
1989 return err;
1990 ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1);
1991 return 0;
1992 }
1993
1994 static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
1995 struct snd_ctl_elem_value *ucontrol)
1996 {
1997 u32 status1;
1998 int err;
1999
2000 err = snd_rme_get_status1(kcontrol, &status1);
2001 if (err < 0)
2002 return err;
2003 ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1);
2004 return 0;
2005 }
2006
2007 static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol,
2008 struct snd_ctl_elem_value *ucontrol)
2009 {
2010 struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
2011 struct snd_usb_audio *chip = list->mixer->chip;
2012 u32 status1;
2013 const u64 num = 104857600000000ULL;
2014 u32 den;
2015 unsigned int freq;
2016 int err;
2017
2018 err = snd_usb_lock_shutdown(chip);
2019 if (err < 0)
2020 return err;
2021 err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1);
2022 if (err < 0)
2023 goto end;
2024 err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den);
2025 if (err < 0)
2026 goto end;
2027 freq = (den == 0) ? 0 : div64_u64(num, den);
2028 freq <<= SND_RME_CLK_FREQMUL(status1);
2029 ucontrol->value.integer.value[0] = freq;
2030
2031 end:
2032 snd_usb_unlock_shutdown(chip);
2033 return err;
2034 }
2035
2036 static int snd_rme_rate_info(struct snd_kcontrol *kcontrol,
2037 struct snd_ctl_elem_info *uinfo)
2038 {
2039 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2040 uinfo->count = 1;
2041 switch (kcontrol->private_value) {
2042 case SND_RME_DOMAIN_SYSTEM:
2043 uinfo->value.integer.min = 32000;
2044 uinfo->value.integer.max = 800000;
2045 break;
2046 case SND_RME_DOMAIN_AES:
2047 case SND_RME_DOMAIN_SPDIF:
2048 default:
2049 uinfo->value.integer.min = 0;
2050 uinfo->value.integer.max = 200000;
2051 }
2052 uinfo->value.integer.step = 0;
2053 return 0;
2054 }
2055
2056 static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol,
2057 struct snd_ctl_elem_info *uinfo)
2058 {
2059 static const char *const sync_states[] = {
2060 "No Lock", "Lock", "Sync"
2061 };
2062
2063 return snd_ctl_enum_info(uinfo, 1,
2064 ARRAY_SIZE(sync_states), sync_states);
2065 }
2066
2067 static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol,
2068 struct snd_ctl_elem_info *uinfo)
2069 {
2070 static const char *const spdif_if[] = {
2071 "Coaxial", "Optical"
2072 };
2073
2074 return snd_ctl_enum_info(uinfo, 1,
2075 ARRAY_SIZE(spdif_if), spdif_if);
2076 }
2077
2078 static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol,
2079 struct snd_ctl_elem_info *uinfo)
2080 {
2081 static const char *const optical_type[] = {
2082 "Consumer", "Professional"
2083 };
2084
2085 return snd_ctl_enum_info(uinfo, 1,
2086 ARRAY_SIZE(optical_type), optical_type);
2087 }
2088
2089 static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol,
2090 struct snd_ctl_elem_info *uinfo)
2091 {
2092 static const char *const sync_sources[] = {
2093 "Internal", "AES", "SPDIF", "Internal"
2094 };
2095
2096 return snd_ctl_enum_info(uinfo, 1,
2097 ARRAY_SIZE(sync_sources), sync_sources);
2098 }
2099
2100 static struct snd_kcontrol_new snd_rme_controls[] = {
2101 {
2102 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2103 .name = "AES Rate",
2104 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2105 .info = snd_rme_rate_info,
2106 .get = snd_rme_rate_get,
2107 .private_value = SND_RME_DOMAIN_AES
2108 },
2109 {
2110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2111 .name = "AES Sync",
2112 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2113 .info = snd_rme_sync_state_info,
2114 .get = snd_rme_sync_state_get,
2115 .private_value = SND_RME_DOMAIN_AES
2116 },
2117 {
2118 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2119 .name = "SPDIF Rate",
2120 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2121 .info = snd_rme_rate_info,
2122 .get = snd_rme_rate_get,
2123 .private_value = SND_RME_DOMAIN_SPDIF
2124 },
2125 {
2126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2127 .name = "SPDIF Sync",
2128 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2129 .info = snd_rme_sync_state_info,
2130 .get = snd_rme_sync_state_get,
2131 .private_value = SND_RME_DOMAIN_SPDIF
2132 },
2133 {
2134 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2135 .name = "SPDIF Interface",
2136 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2137 .info = snd_rme_spdif_if_info,
2138 .get = snd_rme_spdif_if_get,
2139 },
2140 {
2141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2142 .name = "SPDIF Format",
2143 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2144 .info = snd_rme_spdif_format_info,
2145 .get = snd_rme_spdif_format_get,
2146 },
2147 {
2148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2149 .name = "Sync Source",
2150 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2151 .info = snd_rme_sync_source_info,
2152 .get = snd_rme_sync_source_get
2153 },
2154 {
2155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2156 .name = "System Rate",
2157 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2158 .info = snd_rme_rate_info,
2159 .get = snd_rme_rate_get,
2160 .private_value = SND_RME_DOMAIN_SYSTEM
2161 },
2162 {
2163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2164 .name = "Current Frequency",
2165 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2166 .info = snd_rme_rate_info,
2167 .get = snd_rme_current_freq_get
2168 }
2169 };
2170
2171 static int snd_rme_controls_create(struct usb_mixer_interface *mixer)
2172 {
2173 int err, i;
2174
2175 for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) {
2176 err = add_single_ctl_with_resume(mixer, 0,
2177 NULL,
2178 &snd_rme_controls[i],
2179 NULL);
2180 if (err < 0)
2181 return err;
2182 }
2183
2184 return 0;
2185 }
2186
2187 int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
2188 {
2189 int err = 0;
2190
2191 err = snd_usb_soundblaster_remote_init(mixer);
2192 if (err < 0)
2193 return err;
2194
2195 switch (mixer->chip->usb_id) {
2196
2197 case USB_ID(0x0644, 0x8047):
2198 err = snd_us16x08_controls_create(mixer);
2199 break;
2200 case USB_ID(0x041e, 0x3020):
2201 case USB_ID(0x041e, 0x3040):
2202 case USB_ID(0x041e, 0x3042):
2203 case USB_ID(0x041e, 0x30df):
2204 case USB_ID(0x041e, 0x3048):
2205 err = snd_audigy2nx_controls_create(mixer);
2206 if (err < 0)
2207 break;
2208 snd_card_ro_proc_new(mixer->chip->card, "audigy2nx",
2209 mixer, snd_audigy2nx_proc_read);
2210 break;
2211
2212
2213 case USB_ID(0x041e, 0x3f19):
2214 err = snd_emu0204_controls_create(mixer);
2215 break;
2216
2217 case USB_ID(0x0763, 0x2030):
2218 case USB_ID(0x0763, 0x2031):
2219 err = snd_c400_create_mixer(mixer);
2220 break;
2221
2222 case USB_ID(0x0763, 0x2080):
2223 case USB_ID(0x0763, 0x2081):
2224 err = snd_ftu_create_mixer(mixer);
2225 break;
2226
2227 case USB_ID(0x0b05, 0x1739):
2228 case USB_ID(0x0b05, 0x1743):
2229 case USB_ID(0x0b05, 0x17a0):
2230 err = snd_xonar_u1_controls_create(mixer);
2231 break;
2232
2233 case USB_ID(0x0d8c, 0x0103):
2234 err = snd_microii_controls_create(mixer);
2235 break;
2236
2237 case USB_ID(0x0dba, 0x1000):
2238 err = snd_mbox1_create_sync_switch(mixer);
2239 break;
2240
2241 case USB_ID(0x17cc, 0x1011):
2242 err = snd_nativeinstruments_create_mixer(mixer,
2243 snd_nativeinstruments_ta6_mixers,
2244 ARRAY_SIZE(snd_nativeinstruments_ta6_mixers));
2245 break;
2246
2247 case USB_ID(0x17cc, 0x1021):
2248 err = snd_nativeinstruments_create_mixer(mixer,
2249 snd_nativeinstruments_ta10_mixers,
2250 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
2251 break;
2252
2253 case USB_ID(0x200c, 0x1018):
2254
2255 err = snd_create_std_mono_table(mixer, ebox44_table);
2256 break;
2257
2258 case USB_ID(0x1235, 0x8012):
2259 case USB_ID(0x1235, 0x8002):
2260 case USB_ID(0x1235, 0x8004):
2261 case USB_ID(0x1235, 0x8014):
2262 case USB_ID(0x1235, 0x800c):
2263 err = snd_scarlett_controls_create(mixer);
2264 break;
2265
2266 case USB_ID(0x1235, 0x8203):
2267 case USB_ID(0x1235, 0x8204):
2268 case USB_ID(0x1235, 0x8201):
2269 err = snd_scarlett_gen2_controls_create(mixer);
2270 break;
2271
2272 case USB_ID(0x041e, 0x323b):
2273 err = snd_soundblaster_e1_switch_create(mixer);
2274 break;
2275 case USB_ID(0x0bda, 0x4014):
2276 err = dell_dock_mixer_init(mixer);
2277 break;
2278
2279 case USB_ID(0x2a39, 0x3fd2):
2280 case USB_ID(0x2a39, 0x3fd3):
2281 case USB_ID(0x2a39, 0x3fd4):
2282 err = snd_rme_controls_create(mixer);
2283 break;
2284 }
2285
2286 return err;
2287 }
2288
2289 #ifdef CONFIG_PM
2290 void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer)
2291 {
2292 switch (mixer->chip->usb_id) {
2293 case USB_ID(0x0bda, 0x4014):
2294 dell_dock_mixer_init(mixer);
2295 break;
2296 }
2297 }
2298 #endif
2299
2300 void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
2301 int unitid)
2302 {
2303 if (!mixer->rc_cfg)
2304 return;
2305
2306 switch (unitid) {
2307 case 0:
2308 mixer->rc_urb->dev = mixer->chip->dev;
2309 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
2310 break;
2311 case 4:
2312 case 7:
2313 case 19:
2314 case 20:
2315 break;
2316
2317 case 3:
2318 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2319 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2320 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
2321 break;
2322 default:
2323 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
2324 break;
2325 }
2326 }
2327
2328 static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
2329 struct usb_mixer_elem_info *cval,
2330 struct snd_kcontrol *kctl)
2331 {
2332
2333
2334 static const DECLARE_TLV_DB_RANGE(scale,
2335 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970),
2336 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160),
2337 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710),
2338 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560),
2339 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324),
2340 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031),
2341 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393),
2342 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032),
2343 32, 40, TLV_DB_MINMAX_ITEM(-968, -490),
2344 41, 50, TLV_DB_MINMAX_ITEM(-441, 0),
2345 );
2346
2347 if (cval->min == 0 && cval->max == 50) {
2348 usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n");
2349 kctl->tlv.p = scale;
2350 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
2351 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2352
2353 } else if (cval->min == 0 && cval->max <= 1000) {
2354
2355
2356
2357 usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device");
2358 kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
2359 }
2360 }
2361
2362 void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
2363 struct usb_mixer_elem_info *cval, int unitid,
2364 struct snd_kcontrol *kctl)
2365 {
2366 switch (mixer->chip->usb_id) {
2367 case USB_ID(0x21b4, 0x0081):
2368 if (unitid == 7 && cval->control == UAC_FU_VOLUME)
2369 snd_dragonfly_quirk_db_scale(mixer, cval, kctl);
2370 break;
2371
2372 case USB_ID(0x0d8c, 0x000c):
2373 case USB_ID(0x0d8c, 0x0014):
2374 if (strstr(kctl->id.name, "Playback"))
2375 cval->min_mute = 1;
2376 break;
2377 }
2378 }
2379