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