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