1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 */ 4 5 #include <linux/cleanup.h> 6 #include <linux/err.h> 7 #include <linux/init.h> 8 #include <linux/slab.h> 9 #include <linux/string.h> 10 #include <linux/usb.h> 11 #include <linux/usb/audio.h> 12 #include <linux/usb/midi.h> 13 #include <linux/bits.h> 14 15 #include <sound/control.h> 16 #include <sound/core.h> 17 #include <sound/info.h> 18 #include <sound/pcm.h> 19 20 #include "usbaudio.h" 21 #include "card.h" 22 #include "mixer.h" 23 #include "mixer_quirks.h" 24 #include "midi.h" 25 #include "midi2.h" 26 #include "quirks.h" 27 #include "helper.h" 28 #include "endpoint.h" 29 #include "pcm.h" 30 #include "clock.h" 31 #include "stream.h" 32 33 /* 34 * handle the quirks for the contained interfaces 35 */ 36 static int create_composite_quirk(struct snd_usb_audio *chip, 37 struct usb_interface *iface, 38 struct usb_driver *driver, 39 const struct snd_usb_audio_quirk *quirk_comp) 40 { 41 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber; 42 const struct snd_usb_audio_quirk *quirk; 43 int err; 44 45 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) { 46 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); 47 if (!iface) 48 continue; 49 if (quirk->ifnum != probed_ifnum && 50 usb_interface_claimed(iface)) 51 continue; 52 err = snd_usb_create_quirk(chip, iface, driver, quirk); 53 if (err < 0) 54 return err; 55 } 56 57 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) { 58 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); 59 if (!iface) 60 continue; 61 if (quirk->ifnum != probed_ifnum && 62 !usb_interface_claimed(iface)) { 63 err = usb_driver_claim_interface(driver, iface, 64 USB_AUDIO_IFACE_UNUSED); 65 if (err < 0) 66 return err; 67 } 68 } 69 70 return 0; 71 } 72 73 static int ignore_interface_quirk(struct snd_usb_audio *chip, 74 struct usb_interface *iface, 75 struct usb_driver *driver, 76 const struct snd_usb_audio_quirk *quirk) 77 { 78 return 0; 79 } 80 81 82 static int create_any_midi_quirk(struct snd_usb_audio *chip, 83 struct usb_interface *intf, 84 struct usb_driver *driver, 85 const struct snd_usb_audio_quirk *quirk) 86 { 87 return snd_usb_midi_v2_create(chip, intf, quirk, 0); 88 } 89 90 /* 91 * create a stream for an interface with proper descriptors 92 */ 93 static int create_standard_audio_quirk(struct snd_usb_audio *chip, 94 struct usb_interface *iface, 95 struct usb_driver *driver, 96 const struct snd_usb_audio_quirk *quirk) 97 { 98 struct usb_host_interface *alts; 99 struct usb_interface_descriptor *altsd; 100 int err; 101 102 alts = &iface->altsetting[0]; 103 altsd = get_iface_desc(alts); 104 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber); 105 if (err < 0) { 106 usb_audio_err(chip, "cannot setup if %d: error %d\n", 107 altsd->bInterfaceNumber, err); 108 return err; 109 } 110 /* reset the current interface */ 111 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0); 112 return 0; 113 } 114 115 /* create the audio stream and the corresponding endpoints from the fixed 116 * audioformat object; this is used for quirks with the fixed EPs 117 */ 118 static int add_audio_stream_from_fixed_fmt(struct snd_usb_audio *chip, 119 struct audioformat *fp) 120 { 121 int stream, err; 122 123 stream = (fp->endpoint & USB_DIR_IN) ? 124 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; 125 126 snd_usb_audioformat_set_sync_ep(chip, fp); 127 128 err = snd_usb_add_audio_stream(chip, stream, fp, NULL); 129 if (err < 0) 130 return err; 131 132 err = snd_usb_add_endpoint(chip, fp->endpoint, 133 SND_USB_ENDPOINT_TYPE_DATA); 134 if (err < 0) 135 return err; 136 137 if (fp->sync_ep) { 138 err = snd_usb_add_endpoint(chip, fp->sync_ep, 139 fp->implicit_fb ? 140 SND_USB_ENDPOINT_TYPE_DATA : 141 SND_USB_ENDPOINT_TYPE_SYNC); 142 if (err < 0) 143 return err; 144 } 145 146 return 0; 147 } 148 149 /* 150 * create a stream for an endpoint/altsetting without proper descriptors 151 */ 152 static int create_fixed_stream_quirk(struct snd_usb_audio *chip, 153 struct usb_interface *iface, 154 struct usb_driver *driver, 155 const struct snd_usb_audio_quirk *quirk) 156 { 157 struct audioformat *fp; 158 struct usb_host_interface *alts; 159 struct usb_interface_descriptor *altsd; 160 unsigned *rate_table = NULL; 161 int err; 162 163 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); 164 if (!fp) 165 return -ENOMEM; 166 167 INIT_LIST_HEAD(&fp->list); 168 if (fp->nr_rates > MAX_NR_RATES) { 169 kfree(fp); 170 return -EINVAL; 171 } 172 if (fp->nr_rates > 0) { 173 rate_table = kmemdup_array(fp->rate_table, fp->nr_rates, sizeof(int), 174 GFP_KERNEL); 175 if (!rate_table) { 176 kfree(fp); 177 return -ENOMEM; 178 } 179 fp->rate_table = rate_table; 180 } 181 182 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber || 183 fp->altset_idx >= iface->num_altsetting) { 184 err = -EINVAL; 185 goto error; 186 } 187 alts = &iface->altsetting[fp->altset_idx]; 188 altsd = get_iface_desc(alts); 189 if (altsd->bNumEndpoints <= fp->ep_idx) { 190 err = -EINVAL; 191 goto error; 192 } 193 194 fp->protocol = altsd->bInterfaceProtocol; 195 196 if (fp->datainterval == 0) 197 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 198 if (fp->maxpacksize == 0) 199 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, fp->ep_idx)->wMaxPacketSize); 200 if (!fp->fmt_type) 201 fp->fmt_type = UAC_FORMAT_TYPE_I; 202 203 err = add_audio_stream_from_fixed_fmt(chip, fp); 204 if (err < 0) 205 goto error; 206 207 usb_set_interface(chip->dev, fp->iface, 0); 208 snd_usb_init_pitch(chip, fp); 209 snd_usb_init_sample_rate(chip, fp, fp->rate_max); 210 return 0; 211 212 error: 213 list_del(&fp->list); /* unlink for avoiding double-free */ 214 kfree(fp); 215 kfree(rate_table); 216 return err; 217 } 218 219 static int create_auto_pcm_quirk(struct snd_usb_audio *chip, 220 struct usb_interface *iface, 221 struct usb_driver *driver) 222 { 223 struct usb_host_interface *alts; 224 struct usb_interface_descriptor *altsd; 225 struct usb_endpoint_descriptor *epd; 226 struct uac1_as_header_descriptor *ashd; 227 struct uac_format_type_i_discrete_descriptor *fmtd; 228 229 /* 230 * Most Roland/Yamaha audio streaming interfaces have more or less 231 * standard descriptors, but older devices might lack descriptors, and 232 * future ones might change, so ensure that we fail silently if the 233 * interface doesn't look exactly right. 234 */ 235 236 /* must have a non-zero altsetting for streaming */ 237 if (iface->num_altsetting < 2) 238 return -ENODEV; 239 alts = &iface->altsetting[1]; 240 altsd = get_iface_desc(alts); 241 242 /* must have an isochronous endpoint for streaming */ 243 if (altsd->bNumEndpoints < 1) 244 return -ENODEV; 245 epd = get_endpoint(alts, 0); 246 if (!usb_endpoint_xfer_isoc(epd)) 247 return -ENODEV; 248 249 /* must have format descriptors */ 250 ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, 251 UAC_AS_GENERAL); 252 fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, 253 UAC_FORMAT_TYPE); 254 if (!ashd || ashd->bLength < 7 || 255 !fmtd || fmtd->bLength < 8) 256 return -ENODEV; 257 258 return create_standard_audio_quirk(chip, iface, driver, NULL); 259 } 260 261 static int create_yamaha_midi_quirk(struct snd_usb_audio *chip, 262 struct usb_interface *iface, 263 struct usb_driver *driver, 264 struct usb_host_interface *alts) 265 { 266 static const struct snd_usb_audio_quirk yamaha_midi_quirk = { 267 .type = QUIRK_MIDI_YAMAHA 268 }; 269 struct usb_midi_in_jack_descriptor *injd; 270 struct usb_midi_out_jack_descriptor *outjd; 271 272 /* must have some valid jack descriptors */ 273 injd = snd_usb_find_csint_desc(alts->extra, alts->extralen, 274 NULL, USB_MS_MIDI_IN_JACK); 275 outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen, 276 NULL, USB_MS_MIDI_OUT_JACK); 277 if (!injd && !outjd) 278 return -ENODEV; 279 if ((injd && !snd_usb_validate_midi_desc(injd)) || 280 (outjd && !snd_usb_validate_midi_desc(outjd))) 281 return -ENODEV; 282 if (injd && (injd->bLength < 5 || 283 (injd->bJackType != USB_MS_EMBEDDED && 284 injd->bJackType != USB_MS_EXTERNAL))) 285 return -ENODEV; 286 if (outjd && (outjd->bLength < 6 || 287 (outjd->bJackType != USB_MS_EMBEDDED && 288 outjd->bJackType != USB_MS_EXTERNAL))) 289 return -ENODEV; 290 return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk); 291 } 292 293 static int create_roland_midi_quirk(struct snd_usb_audio *chip, 294 struct usb_interface *iface, 295 struct usb_driver *driver, 296 struct usb_host_interface *alts) 297 { 298 static const struct snd_usb_audio_quirk roland_midi_quirk = { 299 .type = QUIRK_MIDI_ROLAND 300 }; 301 u8 *roland_desc = NULL; 302 303 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */ 304 for (;;) { 305 roland_desc = snd_usb_find_csint_desc(alts->extra, 306 alts->extralen, 307 roland_desc, 0xf1); 308 if (!roland_desc) 309 return -ENODEV; 310 if (roland_desc[0] < 6 || roland_desc[3] != 2) 311 continue; 312 return create_any_midi_quirk(chip, iface, driver, 313 &roland_midi_quirk); 314 } 315 } 316 317 static int create_std_midi_quirk(struct snd_usb_audio *chip, 318 struct usb_interface *iface, 319 struct usb_driver *driver, 320 struct usb_host_interface *alts) 321 { 322 struct usb_ms_header_descriptor *mshd; 323 struct usb_ms_endpoint_descriptor *msepd; 324 325 /* must have the MIDIStreaming interface header descriptor*/ 326 mshd = (struct usb_ms_header_descriptor *)alts->extra; 327 if (alts->extralen < 7 || 328 mshd->bLength < 7 || 329 mshd->bDescriptorType != USB_DT_CS_INTERFACE || 330 mshd->bDescriptorSubtype != USB_MS_HEADER) 331 return -ENODEV; 332 /* must have the MIDIStreaming endpoint descriptor*/ 333 msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra; 334 if (alts->endpoint[0].extralen < 4 || 335 msepd->bLength < 4 || 336 msepd->bDescriptorType != USB_DT_CS_ENDPOINT || 337 msepd->bDescriptorSubtype != UAC_MS_GENERAL || 338 msepd->bNumEmbMIDIJack < 1 || 339 msepd->bNumEmbMIDIJack > 16) 340 return -ENODEV; 341 342 return create_any_midi_quirk(chip, iface, driver, NULL); 343 } 344 345 static int create_auto_midi_quirk(struct snd_usb_audio *chip, 346 struct usb_interface *iface, 347 struct usb_driver *driver) 348 { 349 struct usb_host_interface *alts; 350 struct usb_interface_descriptor *altsd; 351 struct usb_endpoint_descriptor *epd; 352 int err; 353 354 alts = &iface->altsetting[0]; 355 altsd = get_iface_desc(alts); 356 357 /* must have at least one bulk/interrupt endpoint for streaming */ 358 if (altsd->bNumEndpoints < 1) 359 return -ENODEV; 360 epd = get_endpoint(alts, 0); 361 if (!usb_endpoint_xfer_bulk(epd) && 362 !usb_endpoint_xfer_int(epd)) 363 return -ENODEV; 364 365 switch (USB_ID_VENDOR(chip->usb_id)) { 366 case 0x0499: /* Yamaha */ 367 err = create_yamaha_midi_quirk(chip, iface, driver, alts); 368 if (err != -ENODEV) 369 return err; 370 break; 371 case 0x0582: /* Roland */ 372 err = create_roland_midi_quirk(chip, iface, driver, alts); 373 if (err != -ENODEV) 374 return err; 375 break; 376 } 377 378 return create_std_midi_quirk(chip, iface, driver, alts); 379 } 380 381 static int create_autodetect_quirk(struct snd_usb_audio *chip, 382 struct usb_interface *iface, 383 struct usb_driver *driver, 384 const struct snd_usb_audio_quirk *quirk) 385 { 386 int err; 387 388 err = create_auto_pcm_quirk(chip, iface, driver); 389 if (err == -ENODEV) 390 err = create_auto_midi_quirk(chip, iface, driver); 391 return err; 392 } 393 394 /* 395 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface. 396 * The only way to detect the sample rate is by looking at wMaxPacketSize. 397 */ 398 static int create_uaxx_quirk(struct snd_usb_audio *chip, 399 struct usb_interface *iface, 400 struct usb_driver *driver, 401 const struct snd_usb_audio_quirk *quirk) 402 { 403 static const struct audioformat ua_format = { 404 .formats = SNDRV_PCM_FMTBIT_S24_3LE, 405 .channels = 2, 406 .fmt_type = UAC_FORMAT_TYPE_I, 407 .altsetting = 1, 408 .altset_idx = 1, 409 .rates = SNDRV_PCM_RATE_CONTINUOUS, 410 }; 411 struct usb_host_interface *alts; 412 struct usb_interface_descriptor *altsd; 413 struct audioformat *fp; 414 int err; 415 416 /* both PCM and MIDI interfaces have 2 or more altsettings */ 417 if (iface->num_altsetting < 2) 418 return -ENXIO; 419 alts = &iface->altsetting[1]; 420 altsd = get_iface_desc(alts); 421 422 if (altsd->bNumEndpoints == 2) { 423 static const struct snd_usb_midi_endpoint_info ua700_ep = { 424 .out_cables = 0x0003, 425 .in_cables = 0x0003 426 }; 427 static const struct snd_usb_audio_quirk ua700_quirk = { 428 .type = QUIRK_MIDI_FIXED_ENDPOINT, 429 .data = &ua700_ep 430 }; 431 static const struct snd_usb_midi_endpoint_info uaxx_ep = { 432 .out_cables = 0x0001, 433 .in_cables = 0x0001 434 }; 435 static const struct snd_usb_audio_quirk uaxx_quirk = { 436 .type = QUIRK_MIDI_FIXED_ENDPOINT, 437 .data = &uaxx_ep 438 }; 439 const struct snd_usb_audio_quirk *quirk = 440 chip->usb_id == USB_ID(0x0582, 0x002b) 441 ? &ua700_quirk : &uaxx_quirk; 442 return __snd_usbmidi_create(chip->card, iface, 443 &chip->midi_list, quirk, 444 chip->usb_id, 445 &chip->num_rawmidis); 446 } 447 448 if (altsd->bNumEndpoints != 1) 449 return -ENXIO; 450 451 fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL); 452 if (!fp) 453 return -ENOMEM; 454 455 fp->iface = altsd->bInterfaceNumber; 456 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; 457 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 458 fp->datainterval = 0; 459 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 460 INIT_LIST_HEAD(&fp->list); 461 462 switch (fp->maxpacksize) { 463 case 0x120: 464 fp->rate_max = fp->rate_min = 44100; 465 break; 466 case 0x138: 467 case 0x140: 468 fp->rate_max = fp->rate_min = 48000; 469 break; 470 case 0x258: 471 case 0x260: 472 fp->rate_max = fp->rate_min = 96000; 473 break; 474 default: 475 usb_audio_err(chip, "unknown sample rate\n"); 476 kfree(fp); 477 return -ENXIO; 478 } 479 480 err = add_audio_stream_from_fixed_fmt(chip, fp); 481 if (err < 0) { 482 list_del(&fp->list); /* unlink for avoiding double-free */ 483 kfree(fp); 484 return err; 485 } 486 usb_set_interface(chip->dev, fp->iface, 0); 487 return 0; 488 } 489 490 /* 491 * Create a standard mixer for the specified interface. 492 */ 493 static int create_standard_mixer_quirk(struct snd_usb_audio *chip, 494 struct usb_interface *iface, 495 struct usb_driver *driver, 496 const struct snd_usb_audio_quirk *quirk) 497 { 498 if (quirk->ifnum < 0) 499 return 0; 500 501 return snd_usb_create_mixer(chip, quirk->ifnum); 502 } 503 504 /* 505 * audio-interface quirks 506 * 507 * returns zero if no standard audio/MIDI parsing is needed. 508 * returns a positive value if standard audio/midi interfaces are parsed 509 * after this. 510 * returns a negative value at error. 511 */ 512 int snd_usb_create_quirk(struct snd_usb_audio *chip, 513 struct usb_interface *iface, 514 struct usb_driver *driver, 515 const struct snd_usb_audio_quirk *quirk) 516 { 517 typedef int (*quirk_func_t)(struct snd_usb_audio *, 518 struct usb_interface *, 519 struct usb_driver *, 520 const struct snd_usb_audio_quirk *); 521 static const quirk_func_t quirk_funcs[] = { 522 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, 523 [QUIRK_COMPOSITE] = create_composite_quirk, 524 [QUIRK_AUTODETECT] = create_autodetect_quirk, 525 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk, 526 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk, 527 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk, 528 [QUIRK_MIDI_ROLAND] = create_any_midi_quirk, 529 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk, 530 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk, 531 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk, 532 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, 533 [QUIRK_MIDI_CME] = create_any_midi_quirk, 534 [QUIRK_MIDI_AKAI] = create_any_midi_quirk, 535 [QUIRK_MIDI_FTDI] = create_any_midi_quirk, 536 [QUIRK_MIDI_CH345] = create_any_midi_quirk, 537 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 538 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 539 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, 540 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk, 541 }; 542 543 if (quirk->type < QUIRK_TYPE_COUNT) { 544 return quirk_funcs[quirk->type](chip, iface, driver, quirk); 545 } else { 546 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type); 547 return -ENXIO; 548 } 549 } 550 551 /* 552 * boot quirks 553 */ 554 555 #define EXTIGY_FIRMWARE_SIZE_OLD 794 556 #define EXTIGY_FIRMWARE_SIZE_NEW 483 557 558 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf) 559 { 560 struct usb_host_config *config = dev->actconfig; 561 int err; 562 563 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD || 564 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) { 565 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n"); 566 /* Send message to force it to reconnect with full interface. */ 567 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), 568 0x10, 0x43, 0x0001, 0x000a, NULL, 0); 569 if (err < 0) 570 dev_dbg(&dev->dev, "error sending boot message: %d\n", err); 571 struct usb_device_descriptor *new_device_descriptor __free(kfree) = 572 kmalloc_obj(*new_device_descriptor); 573 if (!new_device_descriptor) 574 return -ENOMEM; 575 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 576 new_device_descriptor, sizeof(*new_device_descriptor)); 577 if (err < 0) 578 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err); 579 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations) 580 dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n", 581 new_device_descriptor->bNumConfigurations); 582 else 583 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor)); 584 err = usb_reset_configuration(dev); 585 if (err < 0) 586 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err); 587 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n", 588 le16_to_cpu(get_cfg_desc(config)->wTotalLength)); 589 return -ENODEV; /* quit this anyway */ 590 } 591 return 0; 592 } 593 594 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) 595 { 596 u8 buf = 1; 597 598 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, 599 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, 600 0, 0, &buf, 1); 601 if (buf == 0) { 602 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, 603 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 604 1, 2000, NULL, 0); 605 return -ENODEV; 606 } 607 return 0; 608 } 609 610 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev) 611 { 612 int err; 613 614 if (dev->actconfig->desc.bConfigurationValue == 1) { 615 dev_info(&dev->dev, 616 "Fast Track Pro switching to config #2\n"); 617 /* This function has to be available by the usb core module. 618 * if it is not avialable the boot quirk has to be left out 619 * and the configuration has to be set by udev or hotplug 620 * rules 621 */ 622 err = usb_driver_set_configuration(dev, 2); 623 if (err < 0) 624 dev_dbg(&dev->dev, 625 "error usb_driver_set_configuration: %d\n", 626 err); 627 /* Always return an error, so that we stop creating a device 628 that will just be destroyed and recreated with a new 629 configuration */ 630 return -ENODEV; 631 } else 632 dev_info(&dev->dev, "Fast Track Pro config OK\n"); 633 634 return 0; 635 } 636 637 /* 638 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely 639 * documented in the device's data sheet. 640 */ 641 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value) 642 { 643 u8 buf[4]; 644 buf[0] = 0x20; 645 buf[1] = value & 0xff; 646 buf[2] = (value >> 8) & 0xff; 647 buf[3] = reg; 648 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, 649 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, 650 0, 0, &buf, 4); 651 } 652 653 static int snd_usb_cm106_boot_quirk(struct usb_device *dev) 654 { 655 /* 656 * Enable line-out driver mode, set headphone source to front 657 * channels, enable stereo mic. 658 */ 659 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004); 660 } 661 662 /* 663 * CM6206 registers from the CM6206 datasheet rev 2.1 664 */ 665 #define CM6206_REG0_DMA_MASTER BIT(15) 666 #define CM6206_REG0_SPDIFO_RATE_48K (2 << 12) 667 #define CM6206_REG0_SPDIFO_RATE_96K (7 << 12) 668 /* Bit 4 thru 11 is the S/PDIF category code */ 669 #define CM6206_REG0_SPDIFO_CAT_CODE_GENERAL (0 << 4) 670 #define CM6206_REG0_SPDIFO_EMPHASIS_CD BIT(3) 671 #define CM6206_REG0_SPDIFO_COPYRIGHT_NA BIT(2) 672 #define CM6206_REG0_SPDIFO_NON_AUDIO BIT(1) 673 #define CM6206_REG0_SPDIFO_PRO_FORMAT BIT(0) 674 675 #define CM6206_REG1_TEST_SEL_CLK BIT(14) 676 #define CM6206_REG1_PLLBIN_EN BIT(13) 677 #define CM6206_REG1_SOFT_MUTE_EN BIT(12) 678 #define CM6206_REG1_GPIO4_OUT BIT(11) 679 #define CM6206_REG1_GPIO4_OE BIT(10) 680 #define CM6206_REG1_GPIO3_OUT BIT(9) 681 #define CM6206_REG1_GPIO3_OE BIT(8) 682 #define CM6206_REG1_GPIO2_OUT BIT(7) 683 #define CM6206_REG1_GPIO2_OE BIT(6) 684 #define CM6206_REG1_GPIO1_OUT BIT(5) 685 #define CM6206_REG1_GPIO1_OE BIT(4) 686 #define CM6206_REG1_SPDIFO_INVALID BIT(3) 687 #define CM6206_REG1_SPDIF_LOOP_EN BIT(2) 688 #define CM6206_REG1_SPDIFO_DIS BIT(1) 689 #define CM6206_REG1_SPDIFI_MIX BIT(0) 690 691 #define CM6206_REG2_DRIVER_ON BIT(15) 692 #define CM6206_REG2_HEADP_SEL_SIDE_CHANNELS (0 << 13) 693 #define CM6206_REG2_HEADP_SEL_SURROUND_CHANNELS (1 << 13) 694 #define CM6206_REG2_HEADP_SEL_CENTER_SUBW (2 << 13) 695 #define CM6206_REG2_HEADP_SEL_FRONT_CHANNELS (3 << 13) 696 #define CM6206_REG2_MUTE_HEADPHONE_RIGHT BIT(12) 697 #define CM6206_REG2_MUTE_HEADPHONE_LEFT BIT(11) 698 #define CM6206_REG2_MUTE_REAR_SURROUND_RIGHT BIT(10) 699 #define CM6206_REG2_MUTE_REAR_SURROUND_LEFT BIT(9) 700 #define CM6206_REG2_MUTE_SIDE_SURROUND_RIGHT BIT(8) 701 #define CM6206_REG2_MUTE_SIDE_SURROUND_LEFT BIT(7) 702 #define CM6206_REG2_MUTE_SUBWOOFER BIT(6) 703 #define CM6206_REG2_MUTE_CENTER BIT(5) 704 #define CM6206_REG2_MUTE_RIGHT_FRONT BIT(3) 705 #define CM6206_REG2_MUTE_LEFT_FRONT BIT(3) 706 #define CM6206_REG2_EN_BTL BIT(2) 707 #define CM6206_REG2_MCUCLKSEL_1_5_MHZ (0) 708 #define CM6206_REG2_MCUCLKSEL_3_MHZ (1) 709 #define CM6206_REG2_MCUCLKSEL_6_MHZ (2) 710 #define CM6206_REG2_MCUCLKSEL_12_MHZ (3) 711 712 /* Bit 11..13 sets the sensitivity to FLY tuner volume control VP/VD signal */ 713 #define CM6206_REG3_FLYSPEED_DEFAULT (2 << 11) 714 #define CM6206_REG3_VRAP25EN BIT(10) 715 #define CM6206_REG3_MSEL1 BIT(9) 716 #define CM6206_REG3_SPDIFI_RATE_44_1K BIT(0 << 7) 717 #define CM6206_REG3_SPDIFI_RATE_48K BIT(2 << 7) 718 #define CM6206_REG3_SPDIFI_RATE_32K BIT(3 << 7) 719 #define CM6206_REG3_PINSEL BIT(6) 720 #define CM6206_REG3_FOE BIT(5) 721 #define CM6206_REG3_ROE BIT(4) 722 #define CM6206_REG3_CBOE BIT(3) 723 #define CM6206_REG3_LOSE BIT(2) 724 #define CM6206_REG3_HPOE BIT(1) 725 #define CM6206_REG3_SPDIFI_CANREC BIT(0) 726 727 #define CM6206_REG5_DA_RSTN BIT(13) 728 #define CM6206_REG5_AD_RSTN BIT(12) 729 #define CM6206_REG5_SPDIFO_AD2SPDO BIT(12) 730 #define CM6206_REG5_SPDIFO_SEL_FRONT (0 << 9) 731 #define CM6206_REG5_SPDIFO_SEL_SIDE_SUR (1 << 9) 732 #define CM6206_REG5_SPDIFO_SEL_CEN_LFE (2 << 9) 733 #define CM6206_REG5_SPDIFO_SEL_REAR_SUR (3 << 9) 734 #define CM6206_REG5_CODECM BIT(8) 735 #define CM6206_REG5_EN_HPF BIT(7) 736 #define CM6206_REG5_T_SEL_DSDA4 BIT(6) 737 #define CM6206_REG5_T_SEL_DSDA3 BIT(5) 738 #define CM6206_REG5_T_SEL_DSDA2 BIT(4) 739 #define CM6206_REG5_T_SEL_DSDA1 BIT(3) 740 #define CM6206_REG5_T_SEL_DSDAD_NORMAL 0 741 #define CM6206_REG5_T_SEL_DSDAD_FRONT 4 742 #define CM6206_REG5_T_SEL_DSDAD_S_SURROUND 5 743 #define CM6206_REG5_T_SEL_DSDAD_CEN_LFE 6 744 #define CM6206_REG5_T_SEL_DSDAD_R_SURROUND 7 745 746 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) 747 { 748 int err = 0, reg; 749 int val[] = { 750 /* 751 * Values here are chosen based on sniffing USB traffic 752 * under Windows. 753 * 754 * REG0: DAC is master, sample rate 48kHz, no copyright 755 */ 756 CM6206_REG0_SPDIFO_RATE_48K | 757 CM6206_REG0_SPDIFO_COPYRIGHT_NA, 758 /* 759 * REG1: PLL binary search enable, soft mute enable. 760 */ 761 CM6206_REG1_PLLBIN_EN | 762 CM6206_REG1_SOFT_MUTE_EN, 763 /* 764 * REG2: enable output drivers, 765 * select front channels to the headphone output, 766 * then mute the headphone channels, run the MCU 767 * at 1.5 MHz. 768 */ 769 CM6206_REG2_DRIVER_ON | 770 CM6206_REG2_HEADP_SEL_FRONT_CHANNELS | 771 CM6206_REG2_MUTE_HEADPHONE_RIGHT | 772 CM6206_REG2_MUTE_HEADPHONE_LEFT, 773 /* 774 * REG3: default flyspeed, set 2.5V mic bias 775 * enable all line out ports and enable SPDIF 776 */ 777 CM6206_REG3_FLYSPEED_DEFAULT | 778 CM6206_REG3_VRAP25EN | 779 CM6206_REG3_FOE | 780 CM6206_REG3_ROE | 781 CM6206_REG3_CBOE | 782 CM6206_REG3_LOSE | 783 CM6206_REG3_HPOE | 784 CM6206_REG3_SPDIFI_CANREC, 785 /* REG4 is just a bunch of GPIO lines */ 786 0x0000, 787 /* REG5: de-assert AD/DA reset signals */ 788 CM6206_REG5_DA_RSTN | 789 CM6206_REG5_AD_RSTN }; 790 791 for (reg = 0; reg < ARRAY_SIZE(val); reg++) { 792 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]); 793 if (err < 0) 794 return err; 795 } 796 797 return err; 798 } 799 800 /* quirk for Plantronics GameCom 780 with CM6302 chip */ 801 static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev) 802 { 803 /* set the initial volume and don't change; other values are either 804 * too loud or silent due to firmware bug (bko#65251) 805 */ 806 u8 buf[2] = { 0x74, 0xe3 }; 807 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, 808 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 809 UAC_FU_VOLUME << 8, 9 << 8, buf, 2); 810 } 811 812 /* 813 * Novation Twitch DJ controller 814 * Focusrite Novation Saffire 6 USB audio card 815 */ 816 static int snd_usb_novation_boot_quirk(struct usb_device *dev) 817 { 818 /* preemptively set up the device because otherwise the 819 * raw MIDI endpoints are not active */ 820 usb_set_interface(dev, 0, 1); 821 return 0; 822 } 823 824 /* 825 * This call will put the synth in "USB send" mode, i.e it will send MIDI 826 * messages through USB (this is disabled at startup). The synth will 827 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB 828 * sign on its LCD. Values here are chosen based on sniffing USB traffic 829 * under Windows. 830 */ 831 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) 832 { 833 int err, actual_length; 834 /* "midi send" enable */ 835 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 }; 836 void *buf; 837 838 if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x05))) 839 return -EINVAL; 840 buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); 841 if (!buf) 842 return -ENOMEM; 843 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf, 844 ARRAY_SIZE(seq), &actual_length, 1000); 845 kfree(buf); 846 if (err < 0) 847 return err; 848 849 return 0; 850 } 851 852 /* 853 * A post configuration device descriptor read is needed to make the CM1A 854 * operational after reenumeration. 855 */ 856 static int snd_usb_cm1a_boot_quirk(struct usb_device *dev) 857 { 858 struct usb_device_descriptor *desc __free(kfree) = kmalloc_obj(*desc); 859 int err; 860 861 if (!desc) 862 return -ENOMEM; 863 864 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, sizeof(*desc)); 865 if (err < 0) { 866 dev_err(&dev->dev, "failed to read device descriptor: %d\n", err); 867 return err; 868 } 869 870 return 0; 871 } 872 873 /* 874 * Some sound cards from Native Instruments are in fact compliant to the USB 875 * audio standard of version 2 and other approved USB standards, even though 876 * they come up as vendor-specific device when first connected. 877 * 878 * However, they can be told to come up with a new set of descriptors 879 * upon their next enumeration, and the interfaces announced by the new 880 * descriptors will then be handled by the kernel's class drivers. As the 881 * product ID will also change, no further checks are required. 882 */ 883 884 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev) 885 { 886 int ret; 887 888 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 889 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE, 890 1, 0, NULL, 0, 1000); 891 892 if (ret < 0) 893 return ret; 894 895 usb_reset_device(dev); 896 897 /* return -EAGAIN, so the creation of an audio interface for this 898 * temporary device is aborted. The device will reconnect with a 899 * new product ID */ 900 return -EAGAIN; 901 } 902 903 static void mbox2_setup_48_24_magic(struct usb_device *dev) 904 { 905 u8 srate[3]; 906 u8 temp[12]; 907 908 /* Choose 48000Hz permanently */ 909 srate[0] = 0x80; 910 srate[1] = 0xbb; 911 srate[2] = 0x00; 912 913 /* Send the magic! */ 914 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 915 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003); 916 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 917 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003); 918 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 919 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003); 920 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 921 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003); 922 return; 923 } 924 925 /* Digidesign Mbox 2 needs to load firmware onboard 926 * and driver must wait a few seconds for initialisation. 927 */ 928 929 #define MBOX2_FIRMWARE_SIZE 646 930 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */ 931 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */ 932 933 static int snd_usb_mbox2_boot_quirk(struct usb_device *dev) 934 { 935 struct usb_host_config *config = dev->actconfig; 936 int err; 937 u8 bootresponse[0x12]; 938 int fwsize; 939 int count; 940 941 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength); 942 943 if (fwsize != MBOX2_FIRMWARE_SIZE) { 944 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize); 945 return -ENODEV; 946 } 947 948 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n"); 949 950 count = 0; 951 bootresponse[0] = MBOX2_BOOT_LOADING; 952 while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) { 953 msleep(500); /* 0.5 second delay */ 954 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 955 /* Control magic - load onboard firmware */ 956 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012); 957 if (bootresponse[0] == MBOX2_BOOT_READY) 958 break; 959 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n"); 960 count++; 961 } 962 963 if (bootresponse[0] != MBOX2_BOOT_READY) { 964 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]); 965 return -ENODEV; 966 } 967 968 dev_dbg(&dev->dev, "device initialised!\n"); 969 970 struct usb_device_descriptor *new_device_descriptor __free(kfree) = 971 kmalloc_obj(*new_device_descriptor); 972 if (!new_device_descriptor) 973 return -ENOMEM; 974 975 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 976 new_device_descriptor, sizeof(*new_device_descriptor)); 977 if (err < 0) 978 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err); 979 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations) 980 dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n", 981 new_device_descriptor->bNumConfigurations); 982 else 983 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor)); 984 985 err = usb_reset_configuration(dev); 986 if (err < 0) 987 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err); 988 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n", 989 le16_to_cpu(get_cfg_desc(config)->wTotalLength)); 990 991 mbox2_setup_48_24_magic(dev); 992 993 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz"); 994 995 return 0; /* Successful boot */ 996 } 997 998 static int snd_usb_axefx3_boot_quirk(struct usb_device *dev) 999 { 1000 int err; 1001 1002 dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n"); 1003 1004 /* If the Axe-Fx III has not fully booted, it will timeout when trying 1005 * to enable the audio streaming interface. A more generous timeout is 1006 * used here to detect when the Axe-Fx III has finished booting as the 1007 * set interface message will be acked once it has 1008 */ 1009 err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1010 USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, 1011 1, 1, NULL, 0, 120000); 1012 if (err < 0) { 1013 dev_err(&dev->dev, 1014 "failed waiting for Axe-Fx III to boot: %d\n", err); 1015 return err; 1016 } 1017 1018 dev_dbg(&dev->dev, "Axe-Fx III is now ready\n"); 1019 1020 err = usb_set_interface(dev, 1, 0); 1021 if (err < 0) 1022 dev_dbg(&dev->dev, 1023 "error stopping Axe-Fx III interface: %d\n", err); 1024 1025 return 0; 1026 } 1027 1028 static void mbox3_setup_defaults(struct usb_device *dev) 1029 { 1030 /* The Mbox 3 is "little endian" */ 1031 /* max volume is: 0x0000. */ 1032 /* min volume is: 0x0080 (shown in little endian form) */ 1033 1034 u8 com_buff[2]; 1035 1036 /* Deactivate Tuner */ 1037 /* on = 0x01*/ 1038 /* off = 0x00*/ 1039 com_buff[0] = 0x00; 1040 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1041 0x01, 0x21, 0x0003, 0x2001, &com_buff, 1); 1042 1043 /* Set clock source to Internal (as opposed to S/PDIF) */ 1044 /* Internal = 0x01*/ 1045 /* S/PDIF = 0x02*/ 1046 com_buff[0] = 0x01; 1047 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1048 1, 0x21, 0x0100, 0x8001, &com_buff, 1); 1049 1050 /* Mute the hardware loopbacks to start the device in a known state. */ 1051 com_buff[0] = 0x00; 1052 com_buff[1] = 0x80; 1053 /* Analogue input 1 left channel: */ 1054 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1055 1, 0x21, 0x0110, 0x4001, &com_buff, 2); 1056 /* Analogue input 1 right channel: */ 1057 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1058 1, 0x21, 0x0111, 0x4001, &com_buff, 2); 1059 /* Analogue input 2 left channel: */ 1060 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1061 1, 0x21, 0x0114, 0x4001, &com_buff, 2); 1062 /* Analogue input 2 right channel: */ 1063 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1064 1, 0x21, 0x0115, 0x4001, &com_buff, 2); 1065 /* Analogue input 3 left channel: */ 1066 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1067 1, 0x21, 0x0118, 0x4001, &com_buff, 2); 1068 /* Analogue input 3 right channel: */ 1069 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1070 1, 0x21, 0x0119, 0x4001, &com_buff, 2); 1071 /* Analogue input 4 left channel: */ 1072 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1073 1, 0x21, 0x011c, 0x4001, &com_buff, 2); 1074 /* Analogue input 4 right channel: */ 1075 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1076 1, 0x21, 0x011d, 0x4001, &com_buff, 2); 1077 1078 /* Set software sends to output */ 1079 com_buff[0] = 0x00; 1080 com_buff[1] = 0x00; 1081 /* Analogue software return 1 left channel: */ 1082 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1083 1, 0x21, 0x0100, 0x4001, &com_buff, 2); 1084 com_buff[0] = 0x00; 1085 com_buff[1] = 0x80; 1086 /* Analogue software return 1 right channel: */ 1087 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1088 1, 0x21, 0x0101, 0x4001, &com_buff, 2); 1089 com_buff[0] = 0x00; 1090 com_buff[1] = 0x80; 1091 /* Analogue software return 2 left channel: */ 1092 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1093 1, 0x21, 0x0104, 0x4001, &com_buff, 2); 1094 com_buff[0] = 0x00; 1095 com_buff[1] = 0x00; 1096 /* Analogue software return 2 right channel: */ 1097 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1098 1, 0x21, 0x0105, 0x4001, &com_buff, 2); 1099 1100 com_buff[0] = 0x00; 1101 com_buff[1] = 0x80; 1102 /* Analogue software return 3 left channel: */ 1103 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1104 1, 0x21, 0x0108, 0x4001, &com_buff, 2); 1105 /* Analogue software return 3 right channel: */ 1106 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1107 1, 0x21, 0x0109, 0x4001, &com_buff, 2); 1108 /* Analogue software return 4 left channel: */ 1109 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1110 1, 0x21, 0x010c, 0x4001, &com_buff, 2); 1111 /* Analogue software return 4 right channel: */ 1112 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1113 1, 0x21, 0x010d, 0x4001, &com_buff, 2); 1114 1115 /* Return to muting sends */ 1116 com_buff[0] = 0x00; 1117 com_buff[1] = 0x80; 1118 /* Analogue fx return left channel: */ 1119 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1120 1, 0x21, 0x0120, 0x4001, &com_buff, 2); 1121 /* Analogue fx return right channel: */ 1122 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1123 1, 0x21, 0x0121, 0x4001, &com_buff, 2); 1124 1125 /* Analogue software input 1 fx send: */ 1126 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1127 1, 0x21, 0x0100, 0x4201, &com_buff, 2); 1128 /* Analogue software input 2 fx send: */ 1129 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1130 1, 0x21, 0x0101, 0x4201, &com_buff, 2); 1131 /* Analogue software input 3 fx send: */ 1132 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1133 1, 0x21, 0x0102, 0x4201, &com_buff, 2); 1134 /* Analogue software input 4 fx send: */ 1135 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1136 1, 0x21, 0x0103, 0x4201, &com_buff, 2); 1137 /* Analogue input 1 fx send: */ 1138 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1139 1, 0x21, 0x0104, 0x4201, &com_buff, 2); 1140 /* Analogue input 2 fx send: */ 1141 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1142 1, 0x21, 0x0105, 0x4201, &com_buff, 2); 1143 /* Analogue input 3 fx send: */ 1144 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1145 1, 0x21, 0x0106, 0x4201, &com_buff, 2); 1146 /* Analogue input 4 fx send: */ 1147 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1148 1, 0x21, 0x0107, 0x4201, &com_buff, 2); 1149 1150 /* Toggle allowing host control */ 1151 /* Not needed 1152 com_buff[0] = 0x02; 1153 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1154 3, 0x21, 0x0000, 0x2001, &com_buff, 1); 1155 */ 1156 1157 /* Do not dim fx returns */ 1158 com_buff[0] = 0x00; 1159 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1160 3, 0x21, 0x0002, 0x2001, &com_buff, 1); 1161 1162 /* Do not set fx returns to mono */ 1163 com_buff[0] = 0x00; 1164 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1165 3, 0x21, 0x0001, 0x2001, &com_buff, 1); 1166 1167 /* Mute the S/PDIF hardware loopback 1168 * same odd volume logic here as above 1169 */ 1170 com_buff[0] = 0x00; 1171 com_buff[1] = 0x80; 1172 /* S/PDIF hardware input 1 left channel */ 1173 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1174 1, 0x21, 0x0112, 0x4001, &com_buff, 2); 1175 /* S/PDIF hardware input 1 right channel */ 1176 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1177 1, 0x21, 0x0113, 0x4001, &com_buff, 2); 1178 /* S/PDIF hardware input 2 left channel */ 1179 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1180 1, 0x21, 0x0116, 0x4001, &com_buff, 2); 1181 /* S/PDIF hardware input 2 right channel */ 1182 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1183 1, 0x21, 0x0117, 0x4001, &com_buff, 2); 1184 /* S/PDIF hardware input 3 left channel */ 1185 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1186 1, 0x21, 0x011a, 0x4001, &com_buff, 2); 1187 /* S/PDIF hardware input 3 right channel */ 1188 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1189 1, 0x21, 0x011b, 0x4001, &com_buff, 2); 1190 /* S/PDIF hardware input 4 left channel */ 1191 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1192 1, 0x21, 0x011e, 0x4001, &com_buff, 2); 1193 /* S/PDIF hardware input 4 right channel */ 1194 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1195 1, 0x21, 0x011f, 0x4001, &com_buff, 2); 1196 /* S/PDIF software return 1 left channel */ 1197 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1198 1, 0x21, 0x0102, 0x4001, &com_buff, 2); 1199 /* S/PDIF software return 1 right channel */ 1200 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1201 1, 0x21, 0x0103, 0x4001, &com_buff, 2); 1202 /* S/PDIF software return 2 left channel */ 1203 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1204 1, 0x21, 0x0106, 0x4001, &com_buff, 2); 1205 /* S/PDIF software return 2 right channel */ 1206 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1207 1, 0x21, 0x0107, 0x4001, &com_buff, 2); 1208 1209 com_buff[0] = 0x00; 1210 com_buff[1] = 0x00; 1211 /* S/PDIF software return 3 left channel */ 1212 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1213 1, 0x21, 0x010a, 0x4001, &com_buff, 2); 1214 1215 com_buff[0] = 0x00; 1216 com_buff[1] = 0x80; 1217 /* S/PDIF software return 3 right channel */ 1218 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1219 1, 0x21, 0x010b, 0x4001, &com_buff, 2); 1220 /* S/PDIF software return 4 left channel */ 1221 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1222 1, 0x21, 0x010e, 0x4001, &com_buff, 2); 1223 1224 com_buff[0] = 0x00; 1225 com_buff[1] = 0x00; 1226 /* S/PDIF software return 4 right channel */ 1227 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1228 1, 0x21, 0x010f, 0x4001, &com_buff, 2); 1229 1230 com_buff[0] = 0x00; 1231 com_buff[1] = 0x80; 1232 /* S/PDIF fx returns left channel */ 1233 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1234 1, 0x21, 0x0122, 0x4001, &com_buff, 2); 1235 /* S/PDIF fx returns right channel */ 1236 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1237 1, 0x21, 0x0123, 0x4001, &com_buff, 2); 1238 1239 /* Set the dropdown "Effect" to the first option */ 1240 /* Room1 = 0x00 */ 1241 /* Room2 = 0x01 */ 1242 /* Room3 = 0x02 */ 1243 /* Hall 1 = 0x03 */ 1244 /* Hall 2 = 0x04 */ 1245 /* Plate = 0x05 */ 1246 /* Delay = 0x06 */ 1247 /* Echo = 0x07 */ 1248 com_buff[0] = 0x00; 1249 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1250 1, 0x21, 0x0200, 0x4301, &com_buff, 1); /* max is 0xff */ 1251 /* min is 0x00 */ 1252 1253 1254 /* Set the effect duration to 0 */ 1255 /* max is 0xffff */ 1256 /* min is 0x0000 */ 1257 com_buff[0] = 0x00; 1258 com_buff[1] = 0x00; 1259 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1260 1, 0x21, 0x0400, 0x4301, &com_buff, 2); 1261 1262 /* Set the effect volume and feedback to 0 */ 1263 /* max is 0xff */ 1264 /* min is 0x00 */ 1265 com_buff[0] = 0x00; 1266 /* feedback: */ 1267 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1268 1, 0x21, 0x0500, 0x4301, &com_buff, 1); 1269 /* volume: */ 1270 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1271 1, 0x21, 0x0300, 0x4301, &com_buff, 1); 1272 1273 /* Set soft button hold duration */ 1274 /* 0x03 = 250ms */ 1275 /* 0x05 = 500ms DEFAULT */ 1276 /* 0x08 = 750ms */ 1277 /* 0x0a = 1sec */ 1278 com_buff[0] = 0x05; 1279 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1280 3, 0x21, 0x0005, 0x2001, &com_buff, 1); 1281 1282 /* Use dim LEDs for button of state */ 1283 com_buff[0] = 0x00; 1284 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1285 3, 0x21, 0x0004, 0x2001, &com_buff, 1); 1286 } 1287 1288 #define MBOX3_DESCRIPTOR_SIZE 464 1289 1290 static int snd_usb_mbox3_boot_quirk(struct usb_device *dev) 1291 { 1292 struct usb_host_config *config = dev->actconfig; 1293 int err; 1294 int descriptor_size; 1295 1296 descriptor_size = le16_to_cpu(get_cfg_desc(config)->wTotalLength); 1297 1298 if (descriptor_size != MBOX3_DESCRIPTOR_SIZE) { 1299 dev_err(&dev->dev, "MBOX3: Invalid descriptor size=%d.\n", descriptor_size); 1300 return -ENODEV; 1301 } 1302 1303 dev_dbg(&dev->dev, "MBOX3: device initialised!\n"); 1304 1305 struct usb_device_descriptor *new_device_descriptor __free(kfree) = 1306 kmalloc_obj(*new_device_descriptor); 1307 if (!new_device_descriptor) 1308 return -ENOMEM; 1309 1310 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 1311 new_device_descriptor, sizeof(*new_device_descriptor)); 1312 if (err < 0) 1313 dev_dbg(&dev->dev, "MBOX3: error usb_get_descriptor: %d\n", err); 1314 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations) 1315 dev_dbg(&dev->dev, "MBOX3: error too large bNumConfigurations: %d\n", 1316 new_device_descriptor->bNumConfigurations); 1317 else 1318 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor)); 1319 1320 err = usb_reset_configuration(dev); 1321 if (err < 0) 1322 dev_dbg(&dev->dev, "MBOX3: error usb_reset_configuration: %d\n", err); 1323 1324 dev_dbg(&dev->dev, "MBOX3: new boot length = %d\n", 1325 le16_to_cpu(get_cfg_desc(config)->wTotalLength)); 1326 1327 mbox3_setup_defaults(dev); 1328 dev_info(&dev->dev, "MBOX3: Initialized."); 1329 1330 return 0; /* Successful boot */ 1331 } 1332 1333 #define MICROBOOK_BUF_SIZE 128 1334 1335 static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf, 1336 int buf_size, int *length) 1337 { 1338 int err, actual_length; 1339 1340 if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x01))) 1341 return -EINVAL; 1342 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x01), buf, *length, 1343 &actual_length, 1000); 1344 if (err < 0) 1345 return err; 1346 1347 print_hex_dump(KERN_DEBUG, "MicroBookII snd: ", DUMP_PREFIX_NONE, 16, 1, 1348 buf, actual_length, false); 1349 1350 memset(buf, 0, buf_size); 1351 1352 if (usb_pipe_type_check(dev, usb_rcvintpipe(dev, 0x82))) 1353 return -EINVAL; 1354 err = usb_interrupt_msg(dev, usb_rcvintpipe(dev, 0x82), buf, buf_size, 1355 &actual_length, 1000); 1356 if (err < 0) 1357 return err; 1358 1359 print_hex_dump(KERN_DEBUG, "MicroBookII rcv: ", DUMP_PREFIX_NONE, 16, 1, 1360 buf, actual_length, false); 1361 1362 *length = actual_length; 1363 return 0; 1364 } 1365 1366 static int snd_usb_motu_microbookii_boot_quirk(struct usb_device *dev) 1367 { 1368 int err, actual_length, poll_attempts = 0; 1369 static const u8 set_samplerate_seq[] = { 0x00, 0x00, 0x00, 0x00, 1370 0x00, 0x00, 0x0b, 0x14, 1371 0x00, 0x00, 0x00, 0x01 }; 1372 static const u8 poll_ready_seq[] = { 0x00, 0x04, 0x00, 0x00, 1373 0x00, 0x00, 0x0b, 0x18 }; 1374 u8 *buf = kzalloc(MICROBOOK_BUF_SIZE, GFP_KERNEL); 1375 1376 if (!buf) 1377 return -ENOMEM; 1378 1379 dev_info(&dev->dev, "Waiting for MOTU Microbook II to boot up...\n"); 1380 1381 /* First we tell the device which sample rate to use. */ 1382 memcpy(buf, set_samplerate_seq, sizeof(set_samplerate_seq)); 1383 actual_length = sizeof(set_samplerate_seq); 1384 err = snd_usb_motu_microbookii_communicate(dev, buf, MICROBOOK_BUF_SIZE, 1385 &actual_length); 1386 1387 if (err < 0) { 1388 dev_err(&dev->dev, 1389 "failed setting the sample rate for Motu MicroBook II: %d\n", 1390 err); 1391 goto free_buf; 1392 } 1393 1394 /* Then we poll every 100 ms until the device informs of its readiness. */ 1395 while (true) { 1396 if (++poll_attempts > 100) { 1397 dev_err(&dev->dev, 1398 "failed booting Motu MicroBook II: timeout\n"); 1399 err = -ENODEV; 1400 goto free_buf; 1401 } 1402 1403 memset(buf, 0, MICROBOOK_BUF_SIZE); 1404 memcpy(buf, poll_ready_seq, sizeof(poll_ready_seq)); 1405 1406 actual_length = sizeof(poll_ready_seq); 1407 err = snd_usb_motu_microbookii_communicate( 1408 dev, buf, MICROBOOK_BUF_SIZE, &actual_length); 1409 if (err < 0) { 1410 dev_err(&dev->dev, 1411 "failed booting Motu MicroBook II: communication error %d\n", 1412 err); 1413 goto free_buf; 1414 } 1415 1416 /* the device signals its readiness through a message of the 1417 * form 1418 * XX 06 00 00 00 00 0b 18 00 00 00 01 1419 * If the device is not yet ready to accept audio data, the 1420 * last byte of that sequence is 00. 1421 */ 1422 if (actual_length == 12 && buf[actual_length - 1] == 1) 1423 break; 1424 1425 msleep(100); 1426 } 1427 1428 dev_info(&dev->dev, "MOTU MicroBook II ready\n"); 1429 1430 free_buf: 1431 kfree(buf); 1432 return err; 1433 } 1434 1435 static int snd_usb_motu_m_series_boot_quirk(struct usb_device *dev) 1436 { 1437 msleep(4000); 1438 1439 return 0; 1440 } 1441 1442 static int snd_usb_rme_digiface_boot_quirk(struct usb_device *dev) 1443 { 1444 /* Disable mixer, internal clock, all outputs ADAT, 48kHz, TMS off */ 1445 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1446 16, 0x40, 0x2410, 0x7fff, NULL, 0); 1447 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1448 18, 0x40, 0x0104, 0xffff, NULL, 0); 1449 1450 /* Disable loopback for all inputs */ 1451 for (int ch = 0; ch < 32; ch++) 1452 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1453 22, 0x40, 0x400, ch, NULL, 0); 1454 1455 /* Unity gain for all outputs */ 1456 for (int ch = 0; ch < 34; ch++) 1457 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 1458 21, 0x40, 0x9000, 0x100 + ch, NULL, 0); 1459 1460 return 0; 1461 } 1462 1463 /* 1464 * Setup quirks 1465 */ 1466 #define MAUDIO_SET 0x01 /* parse device_setup */ 1467 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */ 1468 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */ 1469 #define MAUDIO_SET_96K 0x04 /* 48-96kHz rate if set, 8-48kHz otherwise */ 1470 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */ 1471 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */ 1472 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */ 1473 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48kHz+Digital Input */ 1474 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48kHz+No Digital Input */ 1475 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48kHz+Digital Input */ 1476 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48kHz+No Digital Input */ 1477 1478 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip, 1479 int iface, int altno) 1480 { 1481 /* Reset ALL ifaces to 0 altsetting. 1482 * Call it for every possible altsetting of every interface. 1483 */ 1484 usb_set_interface(chip->dev, iface, 0); 1485 if (chip->setup & MAUDIO_SET) { 1486 if (chip->setup & MAUDIO_SET_COMPATIBLE) { 1487 if (iface != 1 && iface != 2) 1488 return 1; /* skip all interfaces but 1 and 2 */ 1489 } else { 1490 unsigned int mask; 1491 if (iface == 1 || iface == 2) 1492 return 1; /* skip interfaces 1 and 2 */ 1493 if ((chip->setup & MAUDIO_SET_96K) && altno != 1) 1494 return 1; /* skip this altsetting */ 1495 mask = chip->setup & MAUDIO_SET_MASK; 1496 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2) 1497 return 1; /* skip this altsetting */ 1498 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3) 1499 return 1; /* skip this altsetting */ 1500 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4) 1501 return 1; /* skip this altsetting */ 1502 } 1503 } 1504 usb_audio_dbg(chip, 1505 "using altsetting %d for interface %d config %d\n", 1506 altno, iface, chip->setup); 1507 return 0; /* keep this altsetting */ 1508 } 1509 1510 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip, 1511 int iface, 1512 int altno) 1513 { 1514 /* Reset ALL ifaces to 0 altsetting. 1515 * Call it for every possible altsetting of every interface. 1516 */ 1517 usb_set_interface(chip->dev, iface, 0); 1518 1519 if (chip->setup & MAUDIO_SET) { 1520 unsigned int mask; 1521 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6) 1522 return 1; /* skip this altsetting */ 1523 if ((chip->setup & MAUDIO_SET_96K) && altno != 1) 1524 return 1; /* skip this altsetting */ 1525 mask = chip->setup & MAUDIO_SET_MASK; 1526 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2) 1527 return 1; /* skip this altsetting */ 1528 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3) 1529 return 1; /* skip this altsetting */ 1530 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4) 1531 return 1; /* skip this altsetting */ 1532 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5) 1533 return 1; /* skip this altsetting */ 1534 } 1535 1536 return 0; /* keep this altsetting */ 1537 } 1538 1539 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip, 1540 int iface, int altno) 1541 { 1542 /* Reset ALL ifaces to 0 altsetting. 1543 * Call it for every possible altsetting of every interface. 1544 */ 1545 usb_set_interface(chip->dev, iface, 0); 1546 1547 /* possible configuration where both inputs and only one output is 1548 *used is not supported by the current setup 1549 */ 1550 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) { 1551 if (chip->setup & MAUDIO_SET_96K) { 1552 if (altno != 3 && altno != 6) 1553 return 1; 1554 } else if (chip->setup & MAUDIO_SET_DI) { 1555 if (iface == 4) 1556 return 1; /* no analog input */ 1557 if (altno != 2 && altno != 5) 1558 return 1; /* enable only altsets 2 and 5 */ 1559 } else { 1560 if (iface == 5) 1561 return 1; /* disable digialt input */ 1562 if (altno != 2 && altno != 5) 1563 return 1; /* enalbe only altsets 2 and 5 */ 1564 } 1565 } else { 1566 /* keep only 16-Bit mode */ 1567 if (altno != 1) 1568 return 1; 1569 } 1570 1571 usb_audio_dbg(chip, 1572 "using altsetting %d for interface %d config %d\n", 1573 altno, iface, chip->setup); 1574 return 0; /* keep this altsetting */ 1575 } 1576 1577 static int s1810c_skip_setting_quirk(struct snd_usb_audio *chip, 1578 int iface, int altno) 1579 { 1580 /* 1581 * Altno settings: 1582 * 1583 * Playback (Interface 1): 1584 * 1: 6 Analog + 2 S/PDIF 1585 * 2: 6 Analog + 2 S/PDIF 1586 * 3: 6 Analog 1587 * 1588 * Capture (Interface 2): 1589 * 1: 8 Analog + 2 S/PDIF + 8 ADAT 1590 * 2: 8 Analog + 2 S/PDIF + 4 ADAT 1591 * 3: 8 Analog 1592 */ 1593 1594 /* 1595 * I'll leave 2 as the default one and 1596 * use device_setup to switch to the 1597 * other two. 1598 */ 1599 if ((chip->setup == 0 || chip->setup > 2) && altno != 2) 1600 return 1; 1601 else if (chip->setup == 1 && altno != 1) 1602 return 1; 1603 else if (chip->setup == 2 && altno != 3) 1604 return 1; 1605 1606 return 0; 1607 } 1608 1609 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip, 1610 int iface, 1611 int altno) 1612 { 1613 /* audiophile usb: skip altsets incompatible with device_setup */ 1614 if (chip->usb_id == USB_ID(0x0763, 0x2003)) 1615 return audiophile_skip_setting_quirk(chip, iface, altno); 1616 /* quattro usb: skip altsets incompatible with device_setup */ 1617 if (chip->usb_id == USB_ID(0x0763, 0x2001)) 1618 return quattro_skip_setting_quirk(chip, iface, altno); 1619 /* fasttrackpro usb: skip altsets incompatible with device_setup */ 1620 if (chip->usb_id == USB_ID(0x0763, 0x2012)) 1621 return fasttrackpro_skip_setting_quirk(chip, iface, altno); 1622 /* presonus studio 1810c: skip altsets incompatible with device_setup */ 1623 if (chip->usb_id == USB_ID(0x194f, 0x010c)) 1624 return s1810c_skip_setting_quirk(chip, iface, altno); 1625 1626 return 0; 1627 } 1628 1629 int snd_usb_apply_boot_quirk(struct usb_device *dev, 1630 struct usb_interface *intf, 1631 const struct snd_usb_audio_quirk *quirk, 1632 unsigned int id) 1633 { 1634 switch (id) { 1635 case USB_ID(0x041e, 0x3000): 1636 /* SB Extigy needs special boot-up sequence */ 1637 /* if more models come, this will go to the quirk list. */ 1638 return snd_usb_extigy_boot_quirk(dev, intf); 1639 1640 case USB_ID(0x041e, 0x3020): 1641 /* SB Audigy 2 NX needs its own boot-up magic, too */ 1642 return snd_usb_audigy2nx_boot_quirk(dev); 1643 1644 case USB_ID(0x10f5, 0x0200): 1645 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */ 1646 return snd_usb_cm106_boot_quirk(dev); 1647 1648 case USB_ID(0x0d8c, 0x0102): 1649 /* C-Media CM6206 / CM106-Like Sound Device */ 1650 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */ 1651 return snd_usb_cm6206_boot_quirk(dev); 1652 1653 case USB_ID(0x0dba, 0x3000): 1654 /* Digidesign Mbox 2 */ 1655 return snd_usb_mbox2_boot_quirk(dev); 1656 case USB_ID(0x0dba, 0x5000): 1657 /* Digidesign Mbox 3 */ 1658 return snd_usb_mbox3_boot_quirk(dev); 1659 1660 1661 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */ 1662 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */ 1663 return snd_usb_novation_boot_quirk(dev); 1664 1665 case USB_ID(0x133e, 0x0815): 1666 /* Access Music VirusTI Desktop */ 1667 return snd_usb_accessmusic_boot_quirk(dev); 1668 1669 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */ 1670 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */ 1671 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */ 1672 return snd_usb_nativeinstruments_boot_quirk(dev); 1673 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ 1674 return snd_usb_fasttrackpro_boot_quirk(dev); 1675 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */ 1676 return snd_usb_gamecon780_boot_quirk(dev); 1677 case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */ 1678 return snd_usb_axefx3_boot_quirk(dev); 1679 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook II */ 1680 /* 1681 * For some reason interface 3 with vendor-spec class is 1682 * detected on MicroBook IIc. 1683 */ 1684 if (get_iface_desc(intf->altsetting)->bInterfaceClass == 1685 USB_CLASS_VENDOR_SPEC && 1686 get_iface_desc(intf->altsetting)->bInterfaceNumber < 3) 1687 return snd_usb_motu_microbookii_boot_quirk(dev); 1688 break; 1689 case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */ 1690 case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */ 1691 return snd_usb_rme_digiface_boot_quirk(dev); 1692 } 1693 1694 return 0; 1695 } 1696 1697 int snd_usb_apply_boot_quirk_once(struct usb_device *dev, 1698 struct usb_interface *intf, 1699 const struct snd_usb_audio_quirk *quirk, 1700 unsigned int id) 1701 { 1702 switch (id) { 1703 case USB_ID(0x07fd, 0x0008): /* MOTU M Series, 1st hardware version */ 1704 return snd_usb_motu_m_series_boot_quirk(dev); 1705 } 1706 1707 /* Behringer devices may need explicit device descriptor read at boot */ 1708 if (USB_ID_VENDOR(id) == 0x1397) 1709 return snd_usb_cm1a_boot_quirk(dev); 1710 1711 return 0; 1712 } 1713 1714 /* 1715 * check if the device uses big-endian samples 1716 */ 1717 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, 1718 const struct audioformat *fp) 1719 { 1720 /* it depends on altsetting whether the device is big-endian or not */ 1721 switch (chip->usb_id) { 1722 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */ 1723 if (fp->altsetting == 2 || fp->altsetting == 3 || 1724 fp->altsetting == 5 || fp->altsetting == 6) 1725 return 1; 1726 break; 1727 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 1728 if (chip->setup == 0x00 || 1729 fp->altsetting == 1 || fp->altsetting == 2 || 1730 fp->altsetting == 3) 1731 return 1; 1732 break; 1733 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */ 1734 if (fp->altsetting == 2 || fp->altsetting == 3 || 1735 fp->altsetting == 5 || fp->altsetting == 6) 1736 return 1; 1737 break; 1738 } 1739 return 0; 1740 } 1741 1742 /* 1743 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device, 1744 * not for interface. 1745 */ 1746 1747 enum { 1748 EMU_QUIRK_SR_44100HZ = 0, 1749 EMU_QUIRK_SR_48000HZ, 1750 EMU_QUIRK_SR_88200HZ, 1751 EMU_QUIRK_SR_96000HZ, 1752 EMU_QUIRK_SR_176400HZ, 1753 EMU_QUIRK_SR_192000HZ 1754 }; 1755 1756 static void set_format_emu_quirk(struct snd_usb_substream *subs, 1757 const struct audioformat *fmt) 1758 { 1759 unsigned char emu_samplerate_id = 0; 1760 1761 /* When capture is active 1762 * sample rate shouldn't be changed 1763 * by playback substream 1764 */ 1765 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { 1766 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].cur_audiofmt) 1767 return; 1768 } 1769 1770 switch (fmt->rate_min) { 1771 case 48000: 1772 emu_samplerate_id = EMU_QUIRK_SR_48000HZ; 1773 break; 1774 case 88200: 1775 emu_samplerate_id = EMU_QUIRK_SR_88200HZ; 1776 break; 1777 case 96000: 1778 emu_samplerate_id = EMU_QUIRK_SR_96000HZ; 1779 break; 1780 case 176400: 1781 emu_samplerate_id = EMU_QUIRK_SR_176400HZ; 1782 break; 1783 case 192000: 1784 emu_samplerate_id = EMU_QUIRK_SR_192000HZ; 1785 break; 1786 default: 1787 emu_samplerate_id = EMU_QUIRK_SR_44100HZ; 1788 break; 1789 } 1790 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); 1791 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0; 1792 } 1793 1794 static int pioneer_djm_set_format_quirk(struct snd_usb_substream *subs, 1795 u16 windex) 1796 { 1797 unsigned int cur_rate = subs->data_endpoint->cur_rate; 1798 u8 sr[3]; 1799 // Convert to little endian 1800 sr[0] = cur_rate & 0xff; 1801 sr[1] = (cur_rate >> 8) & 0xff; 1802 sr[2] = (cur_rate >> 16) & 0xff; 1803 usb_set_interface(subs->dev, 0, 1); 1804 // we should derive windex from fmt-sync_ep but it's not set 1805 snd_usb_ctl_msg(subs->stream->chip->dev, 1806 usb_sndctrlpipe(subs->stream->chip->dev, 0), 1807 0x01, 0x22, 0x0100, windex, &sr, 0x0003); 1808 return 0; 1809 } 1810 1811 static void mbox3_set_format_quirk(struct snd_usb_substream *subs, 1812 const struct audioformat *fmt) 1813 { 1814 __le32 buff4 = 0; 1815 u8 buff1 = 0x01; 1816 u32 new_rate = subs->data_endpoint->cur_rate; 1817 u32 current_rate; 1818 1819 // Get current rate from card and check if changing it is needed 1820 snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0), 1821 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4); 1822 current_rate = le32_to_cpu(buff4); 1823 dev_dbg(&subs->dev->dev, 1824 "MBOX3: Current configured sample rate: %d", current_rate); 1825 if (current_rate == new_rate) { 1826 dev_dbg(&subs->dev->dev, 1827 "MBOX3: No change needed (current rate:%d == new rate:%d)", 1828 current_rate, new_rate); 1829 return; 1830 } 1831 1832 // Set new rate 1833 dev_info(&subs->dev->dev, 1834 "MBOX3: Changing sample rate to: %d", new_rate); 1835 buff4 = cpu_to_le32(new_rate); 1836 snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0), 1837 0x01, 0x21, 0x0100, 0x8101, &buff4, 4); 1838 1839 // Set clock source to Internal 1840 snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0), 1841 0x01, 0x21, 0x0100, 0x8001, &buff1, 1); 1842 1843 // Check whether the change was successful 1844 buff4 = 0; 1845 snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0), 1846 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4); 1847 if (new_rate != le32_to_cpu(buff4)) 1848 dev_warn(&subs->dev->dev, "MBOX3: Couldn't set the sample rate"); 1849 } 1850 1851 static const int rme_digiface_rate_table[] = { 1852 32000, 44100, 48000, 0, 1853 64000, 88200, 96000, 0, 1854 128000, 176400, 192000, 0, 1855 }; 1856 1857 static int rme_digiface_set_format_quirk(struct snd_usb_substream *subs) 1858 { 1859 unsigned int cur_rate = subs->data_endpoint->cur_rate; 1860 u16 val; 1861 int speed_mode; 1862 int id; 1863 1864 for (id = 0; id < ARRAY_SIZE(rme_digiface_rate_table); id++) { 1865 if (rme_digiface_rate_table[id] == cur_rate) 1866 break; 1867 } 1868 1869 if (id >= ARRAY_SIZE(rme_digiface_rate_table)) 1870 return -EINVAL; 1871 1872 /* 2, 3, 4 for 1x, 2x, 4x */ 1873 speed_mode = (id >> 2) + 2; 1874 val = (id << 3) | (speed_mode << 12); 1875 1876 /* Set the sample rate */ 1877 snd_usb_ctl_msg(subs->stream->chip->dev, 1878 usb_sndctrlpipe(subs->stream->chip->dev, 0), 1879 16, 0x40, val, 0x7078, NULL, 0); 1880 return 0; 1881 } 1882 1883 void snd_usb_set_format_quirk(struct snd_usb_substream *subs, 1884 const struct audioformat *fmt) 1885 { 1886 switch (subs->stream->chip->usb_id) { 1887 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ 1888 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ 1889 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ 1890 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */ 1891 set_format_emu_quirk(subs, fmt); 1892 break; 1893 case USB_ID(0x534d, 0x0021): /* MacroSilicon MS2100/MS2106 */ 1894 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */ 1895 subs->stream_offset_adj = 2; 1896 break; 1897 case USB_ID(0x2b73, 0x000a): /* Pioneer DJM-900NXS2 */ 1898 case USB_ID(0x2b73, 0x0013): /* Pioneer DJM-450 */ 1899 case USB_ID(0x2b73, 0x0034): /* Pioneer DJM-V10 */ 1900 pioneer_djm_set_format_quirk(subs, 0x0082); 1901 break; 1902 case USB_ID(0x08e4, 0x017f): /* Pioneer DJM-750 */ 1903 case USB_ID(0x08e4, 0x0163): /* Pioneer DJM-850 */ 1904 pioneer_djm_set_format_quirk(subs, 0x0086); 1905 break; 1906 case USB_ID(0x0dba, 0x5000): 1907 mbox3_set_format_quirk(subs, fmt); /* Digidesign Mbox 3 */ 1908 break; 1909 case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */ 1910 case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */ 1911 rme_digiface_set_format_quirk(subs); 1912 break; 1913 } 1914 } 1915 1916 int snd_usb_select_mode_quirk(struct snd_usb_audio *chip, 1917 const struct audioformat *fmt) 1918 { 1919 struct usb_device *dev = chip->dev; 1920 int err; 1921 1922 if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) { 1923 /* First switch to alt set 0, otherwise the mode switch cmd 1924 * will not be accepted by the DAC 1925 */ 1926 err = usb_set_interface(dev, fmt->iface, 0); 1927 if (err < 0) 1928 return err; 1929 1930 msleep(20); /* Delay needed after setting the interface */ 1931 1932 /* Vendor mode switch cmd is required. */ 1933 if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) { 1934 /* DSD mode (DSD_U32) requested */ 1935 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, 1936 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 1937 1, 1, NULL, 0); 1938 if (err < 0) 1939 return err; 1940 1941 } else { 1942 /* PCM or DOP mode (S32) requested */ 1943 /* PCM mode (S16) requested */ 1944 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, 1945 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 1946 0, 1, NULL, 0); 1947 if (err < 0) 1948 return err; 1949 1950 } 1951 msleep(20); 1952 } 1953 return 0; 1954 } 1955 1956 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep) 1957 { 1958 /* 1959 * "Playback Design" products send bogus feedback data at the start 1960 * of the stream. Ignore them. 1961 */ 1962 if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba && 1963 ep->type == SND_USB_ENDPOINT_TYPE_SYNC) 1964 ep->skip_packets = 4; 1965 1966 /* 1967 * M-Audio Fast Track C400/C600 - when packets are not skipped, real 1968 * world latency varies by approx. +/- 50 frames (at 96kHz) each time 1969 * the stream is (re)started. When skipping packets 16 at endpoint 1970 * start up, the real world latency is stable within +/- 1 frame (also 1971 * across power cycles). 1972 */ 1973 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) || 1974 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) && 1975 ep->type == SND_USB_ENDPOINT_TYPE_DATA) 1976 ep->skip_packets = 16; 1977 1978 /* Work around devices that report unreasonable feedback data */ 1979 if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */ 1980 ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */ 1981 ep->syncmaxsize == 4) 1982 ep->tenor_fb_quirk = 1; 1983 } 1984 1985 /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */ 1986 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, 1987 __u8 request, __u8 requesttype, __u16 value, 1988 __u16 index, void *data, __u16 size) 1989 { 1990 struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev); 1991 1992 if (!chip || (requesttype & USB_TYPE_MASK) != USB_TYPE_CLASS) 1993 return; 1994 1995 if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY) 1996 msleep(20); 1997 else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_1M) 1998 usleep_range(1000, 2000); 1999 else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_5M) 2000 usleep_range(5000, 6000); 2001 } 2002 2003 /* 2004 * snd_usb_interface_dsd_format_quirks() is called from format.c to 2005 * augment the PCM format bit-field for DSD types. The UAC standards 2006 * don't have a designated bit field to denote DSD-capable interfaces, 2007 * hence all hardware that is known to support this format has to be 2008 * listed here. 2009 */ 2010 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, 2011 struct audioformat *fp, 2012 unsigned int sample_bytes) 2013 { 2014 struct usb_interface *iface; 2015 2016 /* Playback Designs */ 2017 if (USB_ID_VENDOR(chip->usb_id) == 0x23ba && 2018 USB_ID_PRODUCT(chip->usb_id) < 0x0110) { 2019 switch (fp->altsetting) { 2020 case 1: 2021 fp->dsd_dop = true; 2022 return SNDRV_PCM_FMTBIT_DSD_U16_LE; 2023 case 2: 2024 fp->dsd_bitrev = true; 2025 return SNDRV_PCM_FMTBIT_DSD_U8; 2026 case 3: 2027 fp->dsd_bitrev = true; 2028 return SNDRV_PCM_FMTBIT_DSD_U16_LE; 2029 } 2030 } 2031 2032 /* XMOS based USB DACs */ 2033 switch (chip->usb_id) { 2034 case USB_ID(0x139f, 0x5504): /* Nagra DAC */ 2035 case USB_ID(0x20b1, 0x3089): /* Mola-Mola DAC */ 2036 case USB_ID(0x2522, 0x0007): /* LH Labs Geek Out 1V5 */ 2037 case USB_ID(0x2522, 0x0009): /* LH Labs Geek Pulse X Inifinity 2V0 */ 2038 case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */ 2039 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */ 2040 if (fp->altsetting == 2) 2041 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2042 break; 2043 2044 case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */ 2045 case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */ 2046 case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */ 2047 case USB_ID(0x16d0, 0x06b4): /* NuPrime Audio HD-AVP/AVA */ 2048 case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */ 2049 case USB_ID(0x16d0, 0x09d8): /* NuPrime IDA-8 */ 2050 case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */ 2051 case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */ 2052 case USB_ID(0x16d0, 0x0ab1): /* PureAudio APA DAC */ 2053 case USB_ID(0x16d0, 0xeca1): /* PureAudio Lotus DAC5, DAC5 SE, DAC5 Pro */ 2054 case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */ 2055 case USB_ID(0x20a0, 0x4143): /* WaveIO USB Audio 2.0 */ 2056 case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */ 2057 case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */ 2058 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */ 2059 case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */ 2060 case USB_ID(0x2622, 0x0061): /* LEAK Stereo 230 */ 2061 case USB_ID(0x278b, 0x5100): /* Rotel RC-1590 */ 2062 case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */ 2063 case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */ 2064 case USB_ID(0x6b42, 0x0042): /* MSB Technology */ 2065 if (fp->altsetting == 3) 2066 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2067 break; 2068 2069 /* Amanero Combo384 USB based DACs with native DSD support */ 2070 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */ 2071 if (fp->altsetting == 2) { 2072 switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) { 2073 case 0x199: 2074 return SNDRV_PCM_FMTBIT_DSD_U32_LE; 2075 case 0x19b: 2076 case 0x203: 2077 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2078 default: 2079 break; 2080 } 2081 } 2082 break; 2083 case USB_ID(0x16d0, 0x0a23): 2084 if (fp->altsetting == 2) 2085 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2086 break; 2087 2088 default: 2089 break; 2090 } 2091 2092 /* ITF-USB DSD based DACs */ 2093 if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) { 2094 iface = usb_ifnum_to_if(chip->dev, fp->iface); 2095 2096 /* Altsetting 2 support native DSD if the num of altsets is 2097 * three (0-2), 2098 * Altsetting 3 support native DSD if the num of altsets is 2099 * four (0-3). 2100 */ 2101 if (fp->altsetting == iface->num_altsetting - 1) 2102 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2103 } 2104 2105 /* Mostly generic method to detect many DSD-capable implementations */ 2106 if ((chip->quirk_flags & QUIRK_FLAG_DSD_RAW) && fp->dsd_raw) 2107 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 2108 2109 return 0; 2110 } 2111 2112 void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip, 2113 struct audioformat *fp, 2114 int stream) 2115 { 2116 switch (chip->usb_id) { 2117 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ 2118 /* Optoplay sets the sample rate attribute although 2119 * it seems not supporting it in fact. 2120 */ 2121 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; 2122 break; 2123 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ 2124 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 2125 /* doesn't set the sample rate attribute, but supports it */ 2126 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; 2127 break; 2128 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */ 2129 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ 2130 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ 2131 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is 2132 an older model 77d:223) */ 2133 /* 2134 * plantronics headset and Griffin iMic have set adaptive-in 2135 * although it's really not... 2136 */ 2137 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; 2138 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 2139 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; 2140 else 2141 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; 2142 break; 2143 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook IIc */ 2144 /* 2145 * MaxPacketsOnly attribute is erroneously set in endpoint 2146 * descriptors. As a result this card produces noise with 2147 * all sample rates other than 96 kHz. 2148 */ 2149 fp->attributes &= ~UAC_EP_CS_ATTR_FILL_MAX; 2150 break; 2151 case USB_ID(0x1224, 0x2a25): /* Jieli Technology USB PHY 2.0 */ 2152 /* mic works only when ep packet size is set to wMaxPacketSize */ 2153 fp->attributes |= UAC_EP_CS_ATTR_FILL_MAX; 2154 break; 2155 case USB_ID(0x3511, 0x2b1e): /* Opencomm2 UC USB Bluetooth dongle */ 2156 /* mic works only when ep pitch control is not set */ 2157 if (stream == SNDRV_PCM_STREAM_CAPTURE) 2158 fp->attributes &= ~UAC_EP_CS_ATTR_PITCH_CONTROL; 2159 break; 2160 } 2161 } 2162 2163 /* 2164 * driver behavior quirk flags 2165 */ 2166 struct usb_string_match { 2167 const char *manufacturer; 2168 const char *product; 2169 }; 2170 2171 struct usb_audio_quirk_flags_table { 2172 u32 id; 2173 u64 flags; 2174 const struct usb_string_match *usb_string_match; 2175 }; 2176 2177 #define DEVICE_FLG(vid, pid, _flags) \ 2178 { .id = USB_ID(vid, pid), .flags = (_flags) } 2179 #define VENDOR_FLG(vid, _flags) DEVICE_FLG(vid, 0, _flags) 2180 2181 /* 2182 * Use as a last resort if using DEVICE_FLG() is prone to VID/PID conflicts. 2183 * 2184 * Usage: 2185 * // match vid, pid, "manufacturer", and "product" 2186 * DEVICE_STRING_FLG(vid, pid, "manufacturer", "product", flags) 2187 * 2188 * // match vid, pid, "manufacturer", and any product string 2189 * DEVICE_STRING_FLG(vid, pid, "manufacturer", NULL, flags) 2190 * 2191 * // match vid, pid, "manufacturer", and device must have no product string 2192 * DEVICE_STRING_FLG(vid, pid, "manufacturer", "", flags) 2193 * 2194 * // match vid, pid, any manufacturer string, and "product" 2195 * DEVICE_STRING_FLG(vid, pid, NULL, "product", flags) 2196 * 2197 * // match vid, pid, no manufacturer string, and "product" 2198 * DEVICE_STRING_FLG(vid, pid, "", "product", flags) 2199 * 2200 * // match vid, pid, no manufacturer string, and no product string 2201 * DEVICE_STRING_FLG(vid, pid, "", "", flags) 2202 */ 2203 #define DEVICE_STRING_FLG(vid, pid, _manufacturer, _product, _flags) \ 2204 { \ 2205 .id = USB_ID(vid, pid), \ 2206 .usb_string_match = &(const struct usb_string_match) { \ 2207 .manufacturer = _manufacturer, \ 2208 .product = _product, \ 2209 }, \ 2210 .flags = (_flags), \ 2211 } 2212 2213 /* 2214 * Use as a last resort if using VENDOR_FLG() is prone to VID conflicts. 2215 * 2216 * Usage: 2217 * // match vid, and "manufacturer" 2218 * VENDOR_STRING_FLG(vid, "manufacturer", flags) 2219 * 2220 * // match vid, and device must have no manufacturer string 2221 * VENDOR_STRING_FLG(vid, "", flags) 2222 */ 2223 #define VENDOR_STRING_FLG(vid, _manufacturer, _flags) \ 2224 DEVICE_STRING_FLG(vid, 0, _manufacturer, NULL, _flags) 2225 2226 static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { 2227 /* Device and string descriptor matches */ 2228 DEVICE_STRING_FLG(0x05ac, 0x110b, /* VID conflicts with Apple */ 2229 "JKY Technology", NULL, /* Q2A */ 2230 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2231 2232 /* Device matches */ 2233 DEVICE_FLG(0x001f, 0x0b21, /* AB13X USB Audio */ 2234 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2235 DEVICE_FLG(0x001f, 0x0b23, /* AB17X USB Audio */ 2236 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2237 DEVICE_FLG(0x0020, 0x0b21, /* GHW-123P */ 2238 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2239 DEVICE_FLG(0x0124, 0x0c21, /* Generic USB Headphone */ 2240 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2241 DEVICE_FLG(0x03f0, 0x654a, /* HP 320 FHD Webcam */ 2242 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16), 2243 DEVICE_FLG(0x041e, 0x3000, /* Creative SB Extigy */ 2244 QUIRK_FLAG_IGNORE_CTL_ERROR), 2245 DEVICE_FLG(0x041e, 0x324d, /* Creative Sound Blaster Play! 3 */ 2246 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2247 DEVICE_FLG(0x041e, 0x4080, /* Creative Live Cam VF0610 */ 2248 QUIRK_FLAG_GET_SAMPLE_RATE), 2249 DEVICE_FLG(0x045e, 0x083c, /* MS USB Link headset */ 2250 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY | 2251 QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2252 DEVICE_FLG(0x045e, 0x070f, /* MS LifeChat LX-3000 Headset */ 2253 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2254 DEVICE_FLG(0x046d, 0x0807, /* Logitech Webcam C500 */ 2255 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2256 DEVICE_FLG(0x046d, 0x0808, /* Logitech Webcam C600 */ 2257 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2258 DEVICE_FLG(0x046d, 0x0809, 2259 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2260 DEVICE_FLG(0x046d, 0x0819, /* Logitech Webcam C210 */ 2261 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2262 DEVICE_FLG(0x046d, 0x081b, /* HD Webcam c310 */ 2263 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2264 DEVICE_FLG(0x046d, 0x081d, /* HD Webcam c510 */ 2265 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2266 DEVICE_FLG(0x046d, 0x0825, /* HD Webcam c270 */ 2267 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2268 DEVICE_FLG(0x046d, 0x0826, /* HD Webcam c525 */ 2269 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2270 DEVICE_FLG(0x046d, 0x084c, /* Logitech ConferenceCam Connect */ 2271 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY_1M), 2272 DEVICE_FLG(0x046d, 0x08ca, /* Logitech Quickcam Fusion */ 2273 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2274 DEVICE_FLG(0x046d, 0x0991, /* Logitech QuickCam Pro */ 2275 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR | 2276 QUIRK_FLAG_MIC_RES_384), 2277 DEVICE_FLG(0x046d, 0x09a2, /* QuickCam Communicate Deluxe/S7500 */ 2278 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384), 2279 DEVICE_FLG(0x046d, 0x09a4, /* Logitech QuickCam E 3500 */ 2280 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR), 2281 DEVICE_FLG(0x046d, 0x0a8f, /* Logitech H390 headset */ 2282 QUIRK_FLAG_CTL_MSG_DELAY_1M | 2283 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2284 DEVICE_FLG(0x046d, 0x0aba, /* Logitech PRO X Wireless */ 2285 QUIRK_FLAG_MIXER_GET_CUR_OK | 2286 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2287 DEVICE_FLG(0x0499, 0x1506, /* Yamaha THR5 */ 2288 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2289 DEVICE_FLG(0x0499, 0x1509, /* Steinberg UR22 */ 2290 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2291 DEVICE_FLG(0x0499, 0x3108, /* Yamaha YIT-W12TX */ 2292 QUIRK_FLAG_GET_SAMPLE_RATE), 2293 DEVICE_FLG(0x04d8, 0xfeea, /* Benchmark DAC1 Pre */ 2294 QUIRK_FLAG_GET_SAMPLE_RATE), 2295 DEVICE_FLG(0x04e8, 0xa051, /* Samsung USBC Headset (AKG) */ 2296 QUIRK_FLAG_SKIP_CLOCK_SELECTOR | QUIRK_FLAG_CTL_MSG_DELAY_5M), 2297 DEVICE_FLG(0x0525, 0xa4ad, /* Hamedal C20 usb camero */ 2298 QUIRK_FLAG_IFACE_SKIP_CLOSE), 2299 DEVICE_FLG(0x054c, 0x0b8c, /* Sony WALKMAN NW-A45 DAC */ 2300 QUIRK_FLAG_SET_IFACE_FIRST), 2301 DEVICE_FLG(0x0556, 0x0014, /* Phoenix Audio TMX320VC */ 2302 QUIRK_FLAG_GET_SAMPLE_RATE), 2303 DEVICE_FLG(0x0572, 0x1b08, /* Conexant Systems (Rockwell), Inc. */ 2304 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2305 DEVICE_FLG(0x0572, 0x1b09, /* Conexant Systems (Rockwell), Inc. */ 2306 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2307 DEVICE_FLG(0x05a3, 0x9420, /* ELP HD USB Camera */ 2308 QUIRK_FLAG_GET_SAMPLE_RATE), 2309 DEVICE_FLG(0x05a7, 0x1020, /* Bose Companion 5 */ 2310 QUIRK_FLAG_GET_SAMPLE_RATE), 2311 DEVICE_FLG(0x05e1, 0x0408, /* Syntek STK1160 */ 2312 QUIRK_FLAG_ALIGN_TRANSFER), 2313 DEVICE_FLG(0x05e1, 0x0480, /* Hauppauge Woodbury */ 2314 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2315 DEVICE_FLG(0x05fc, 0x0231, /* JBL Pebbles */ 2316 QUIRK_FLAG_MIXER_PLAYBACK_LINEAR_VOL | QUIRK_FLAG_MIXER_CAPTURE_LINEAR_VOL | 2317 QUIRK_FLAG_GET_SAMPLE_RATE), 2318 DEVICE_FLG(0x0624, 0x3d3f, /* AB13X USB Audio */ 2319 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2320 DEVICE_FLG(0x0644, 0x8043, /* TEAC UD-501/UD-501V2/UD-503/NT-503 */ 2321 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2322 QUIRK_FLAG_IFACE_DELAY), 2323 DEVICE_FLG(0x0644, 0x8044, /* Esoteric D-05X */ 2324 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2325 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET), 2326 DEVICE_FLG(0x0644, 0x804a, /* TEAC UD-301 */ 2327 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2328 QUIRK_FLAG_IFACE_DELAY), 2329 DEVICE_FLG(0x0644, 0x805f, /* TEAC Model 12 */ 2330 QUIRK_FLAG_FORCE_IFACE_RESET), 2331 DEVICE_FLG(0x0644, 0x806b, /* TEAC UD-701 */ 2332 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2333 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET), 2334 DEVICE_FLG(0x0644, 0x807d, /* TEAC UD-507 */ 2335 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2336 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET), 2337 DEVICE_FLG(0x0644, 0x806c, /* Esoteric XD */ 2338 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY | 2339 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET), 2340 DEVICE_FLG(0x0661, 0x0883, /* iBasso DC04 Ultra */ 2341 QUIRK_FLAG_DSD_RAW), 2342 DEVICE_FLG(0x0666, 0x0880, /* SPACETOUCH USB Audio */ 2343 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY | 2344 QUIRK_FLAG_CTL_MSG_DELAY_5M), 2345 DEVICE_FLG(0x06f8, 0xb000, /* Hercules DJ Console (Windows Edition) */ 2346 QUIRK_FLAG_IGNORE_CTL_ERROR), 2347 DEVICE_FLG(0x06f8, 0xd002, /* Hercules DJ Console (Macintosh Edition) */ 2348 QUIRK_FLAG_IGNORE_CTL_ERROR), 2349 DEVICE_FLG(0x0711, 0x5800, /* MCT Trigger 5 USB-to-HDMI */ 2350 QUIRK_FLAG_GET_SAMPLE_RATE), 2351 DEVICE_FLG(0x074d, 0x3553, /* Outlaw RR2150 (Micronas UAC3553B) */ 2352 QUIRK_FLAG_GET_SAMPLE_RATE), 2353 DEVICE_FLG(0x0763, 0x2030, /* M-Audio Fast Track C400 */ 2354 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2355 DEVICE_FLG(0x0763, 0x2031, /* M-Audio Fast Track C600 */ 2356 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2357 DEVICE_FLG(0x0763, 0x2080, /* M-Audio Fast Track Ultra */ 2358 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2359 DEVICE_FLG(0x0763, 0x2081, /* M-Audio Fast Track Ultra */ 2360 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2361 DEVICE_FLG(0x0763, 0x2084, /* M-Audio Venom */ 2362 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2363 DEVICE_FLG(0x07fd, 0x000b, /* MOTU M Series 2nd hardware revision */ 2364 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2365 DEVICE_FLG(0x08bb, 0x2702, /* LineX FM Transmitter */ 2366 QUIRK_FLAG_IGNORE_CTL_ERROR), 2367 DEVICE_FLG(0x0951, 0x16ad, /* Kingston HyperX */ 2368 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2369 DEVICE_FLG(0x0a73, 0x003a, /* Mackie DLZ Creator XS */ 2370 QUIRK_FLAG_ALWAYS_SET_RATE), 2371 DEVICE_FLG(0x0b05, 0x1826, /* ASUS SupremeFX Hi-Fi */ 2372 QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2373 DEVICE_FLG(0x0b05, 0x1827, /* ASUS SupremeFX Hi-Fi */ 2374 QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2375 DEVICE_FLG(0x0b05, 0x18a6, /* ASUSTek Computer, Inc. */ 2376 QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE), 2377 DEVICE_FLG(0x0b0e, 0x0349, /* Jabra 550a */ 2378 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2379 DEVICE_FLG(0x0bda, 0x498a, /* Realtek Semiconductor Corp. */ 2380 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE), 2381 DEVICE_FLG(0x0c45, 0x6340, /* Sonix HD USB Camera */ 2382 QUIRK_FLAG_GET_SAMPLE_RATE), 2383 DEVICE_FLG(0x0c45, 0x636b, /* Microdia JP001 USB Camera */ 2384 QUIRK_FLAG_GET_SAMPLE_RATE), 2385 DEVICE_FLG(0x0d8c, 0x000c, /* C-Media */ 2386 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2387 DEVICE_FLG(0x0d8c, 0x0012, /* C-Media */ 2388 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2389 DEVICE_FLG(0x0d8c, 0x0014, /* C-Media */ 2390 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2391 DEVICE_FLG(0x0d8c, 0x0102, /* C-Media CM6206 */ 2392 QUIRK_FLAG_GET_SAMPLE_RATE), 2393 DEVICE_FLG(0x0e0b, 0xfa01, /* Feaulle Rainbow */ 2394 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2395 DEVICE_FLG(0x0ecb, 0x205c, /* JBL Quantum610 Wireless */ 2396 QUIRK_FLAG_FIXED_RATE), 2397 DEVICE_FLG(0x0ecb, 0x2125, /* JBL Quantum650 Wireless */ 2398 QUIRK_FLAG_FIXED_RATE), 2399 DEVICE_FLG(0x0ecb, 0x2069, /* JBL Quantum810 Wireless */ 2400 QUIRK_FLAG_FIXED_RATE), 2401 DEVICE_FLG(0x0fd9, 0x0008, /* Hauppauge HVR-950Q */ 2402 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2403 DEVICE_FLG(0x1038, 0x1294, /* SteelSeries Arctis Pro Wireless */ 2404 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2405 DEVICE_FLG(0x1101, 0x0003, /* Audioengine D1 */ 2406 QUIRK_FLAG_GET_SAMPLE_RATE), 2407 DEVICE_FLG(0x12d1, 0x3a07, /* HUAWEI USB-C HEADSET */ 2408 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE | 2409 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2410 DEVICE_FLG(0x1224, 0x2a25, /* Jieli Technology USB PHY 2.0 */ 2411 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16), 2412 DEVICE_FLG(0x1395, 0x740a, /* Sennheiser DECT */ 2413 QUIRK_FLAG_GET_SAMPLE_RATE), 2414 DEVICE_FLG(0x1397, 0x0507, /* Behringer UMC202HD */ 2415 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2416 DEVICE_FLG(0x1397, 0x0508, /* Behringer UMC204HD */ 2417 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2418 DEVICE_FLG(0x1397, 0x0509, /* Behringer UMC404HD */ 2419 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2420 DEVICE_FLG(0x1397, 0x050c, /* Behringer Flow 8 */ 2421 QUIRK_FLAG_IFB_SILENCE_ON_EMPTY), 2422 DEVICE_FLG(0x1397, 0x0510, /* Behringer UV1 */ 2423 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2424 DEVICE_FLG(0x13e5, 0x0001, /* Serato Phono */ 2425 QUIRK_FLAG_IGNORE_CTL_ERROR), 2426 DEVICE_FLG(0x152a, 0x85dd, /* SMSL USB DAC */ 2427 QUIRK_FLAG_DSD_RAW | QUIRK_FLAG_DISABLE_AUTOSUSPEND | 2428 QUIRK_FLAG_SKIP_IFACE_SETUP), 2429 DEVICE_FLG(0x152a, 0x880a, /* NeuralDSP Quad Cortex */ 2430 0), /* Doesn't have the vendor quirk which would otherwise apply */ 2431 DEVICE_FLG(0x1532, 0x055e, /* Razer Nommo V2 X */ 2432 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2433 DEVICE_FLG(0x154e, 0x1002, /* Denon DCD-1500RE */ 2434 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2435 DEVICE_FLG(0x154e, 0x1003, /* Denon DA-300USB */ 2436 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2437 DEVICE_FLG(0x154e, 0x3005, /* Marantz HD-DAC1 */ 2438 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2439 DEVICE_FLG(0x154e, 0x3006, /* Marantz SA-14S1 */ 2440 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2441 DEVICE_FLG(0x154e, 0x300b, /* Marantz SA-KI RUBY / SA-12 */ 2442 QUIRK_FLAG_DSD_RAW), 2443 DEVICE_FLG(0x154e, 0x500e, /* Denon DN-X1600 */ 2444 QUIRK_FLAG_IGNORE_CLOCK_SOURCE), 2445 DEVICE_FLG(0x1686, 0x00dd, /* Zoom R16/24 */ 2446 QUIRK_FLAG_TX_LENGTH | QUIRK_FLAG_CTL_MSG_DELAY_1M), 2447 DEVICE_FLG(0x16d0, 0x0ab1, /* PureAudio APA DAC */ 2448 QUIRK_FLAG_DSD_RAW), 2449 DEVICE_FLG(0x16d0, 0xeca1, /* PureAudio Lotus DAC5, DAC5 SE and DAC5 Pro */ 2450 QUIRK_FLAG_DSD_RAW), 2451 DEVICE_FLG(0x17aa, 0x1046, /* Lenovo ThinkStation P620 Rear Line-in, Line-out and Microphone */ 2452 QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2453 DEVICE_FLG(0x17aa, 0x104d, /* Lenovo ThinkStation P620 Internal Speaker + Front Headset */ 2454 QUIRK_FLAG_DISABLE_AUTOSUSPEND), 2455 DEVICE_FLG(0x17ef, 0x3083, /* Lenovo TBT3 dock */ 2456 QUIRK_FLAG_GET_SAMPLE_RATE), 2457 DEVICE_FLG(0x1852, 0x5062, /* Luxman D-08u */ 2458 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2459 DEVICE_FLG(0x1852, 0x5065, /* Luxman DA-06 */ 2460 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2461 DEVICE_FLG(0x1901, 0x0191, /* GE B850V3 CP2114 audio interface */ 2462 QUIRK_FLAG_GET_SAMPLE_RATE), 2463 DEVICE_FLG(0x19f7, 0x0003, /* RODE NT-USB */ 2464 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2465 DEVICE_FLG(0x19f7, 0x0035, /* RODE NT-USB+ */ 2466 QUIRK_FLAG_GET_SAMPLE_RATE), 2467 DEVICE_FLG(0x1bcf, 0x2281, /* HD Webcam */ 2468 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16), 2469 DEVICE_FLG(0x1bcf, 0x2283, /* NexiGo N930AF FHD Webcam */ 2470 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16), 2471 DEVICE_FLG(0x1e0b, 0xd01e, /* Generic USB Audio Device */ 2472 QUIRK_FLAG_PLAYBACK_URB_FIXUP), 2473 DEVICE_FLG(0x1ff7, 0x0f81, /* SC13A Webcam */ 2474 QUIRK_FLAG_GET_SAMPLE_RATE), 2475 DEVICE_FLG(0x2040, 0x7200, /* Hauppauge HVR-950Q */ 2476 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2477 DEVICE_FLG(0x2040, 0x7201, /* Hauppauge HVR-950Q-MXL */ 2478 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2479 DEVICE_FLG(0x2040, 0x7210, /* Hauppauge HVR-950Q */ 2480 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2481 DEVICE_FLG(0x2040, 0x7211, /* Hauppauge HVR-950Q-MXL */ 2482 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2483 DEVICE_FLG(0x2040, 0x7213, /* Hauppauge HVR-950Q */ 2484 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2485 DEVICE_FLG(0x2040, 0x7217, /* Hauppauge HVR-950Q */ 2486 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2487 DEVICE_FLG(0x2040, 0x721b, /* Hauppauge HVR-950Q */ 2488 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2489 DEVICE_FLG(0x2040, 0x721e, /* Hauppauge HVR-950Q */ 2490 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2491 DEVICE_FLG(0x2040, 0x721f, /* Hauppauge HVR-950Q */ 2492 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2493 DEVICE_FLG(0x2040, 0x7240, /* Hauppauge HVR-850 */ 2494 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2495 DEVICE_FLG(0x2040, 0x7260, /* Hauppauge HVR-950Q */ 2496 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2497 DEVICE_FLG(0x2040, 0x7270, /* Hauppauge HVR-950Q */ 2498 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2499 DEVICE_FLG(0x2040, 0x7280, /* Hauppauge HVR-950Q */ 2500 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2501 DEVICE_FLG(0x2040, 0x7281, /* Hauppauge HVR-950Q-MXL */ 2502 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2503 DEVICE_FLG(0x20b1, 0x2009, /* XMOS Ltd DIYINHK USB Audio 2.0 */ 2504 QUIRK_FLAG_SKIP_IMPLICIT_FB | QUIRK_FLAG_DSD_RAW), 2505 DEVICE_FLG(0x2040, 0x8200, /* Hauppauge Woodbury */ 2506 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER), 2507 DEVICE_FLG(0x21b4, 0x0081, /* AudioQuest DragonFly */ 2508 QUIRK_FLAG_GET_SAMPLE_RATE), 2509 DEVICE_FLG(0x21b4, 0x0230, /* Ayre QB-9 Twenty */ 2510 QUIRK_FLAG_DSD_RAW), 2511 DEVICE_FLG(0x21b4, 0x0232, /* Ayre QX-5 Twenty */ 2512 QUIRK_FLAG_DSD_RAW), 2513 DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */ 2514 QUIRK_FLAG_SET_IFACE_FIRST), 2515 DEVICE_FLG(0x25aa, 0x600b, /* TAE1159 */ 2516 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2517 DEVICE_FLG(0x262a, 0x9302, /* ddHiFi TC44C */ 2518 QUIRK_FLAG_DSD_RAW), 2519 DEVICE_FLG(0x2772, 0x0502, /* Musical Fidelity M6s DAC */ 2520 0), /* for avoiding QUIRK_FLAG_DSD_RAW with vendor match */ 2521 DEVICE_FLG(0x2912, 0x30c8, /* Audioengine D1 */ 2522 QUIRK_FLAG_GET_SAMPLE_RATE), 2523 DEVICE_FLG(0x2a70, 0x1881, /* OnePlus Technology (Shenzhen) Co., Ltd. BE02T */ 2524 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE), 2525 DEVICE_FLG(0x2b53, 0x0023, /* Fiero SC-01 (firmware v1.0.0 @ 48 kHz) */ 2526 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2527 DEVICE_FLG(0x2b53, 0x0024, /* Fiero SC-01 (firmware v1.0.0 @ 96 kHz) */ 2528 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2529 DEVICE_FLG(0x2b53, 0x0031, /* Fiero SC-01 (firmware v1.1.0) */ 2530 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2531 DEVICE_FLG(0x2b73, 0x0047, /* AlphaTheta EUPHONIA */ 2532 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2533 DEVICE_FLG(0x2d95, 0x8011, /* VIVO USB-C HEADSET */ 2534 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2535 DEVICE_FLG(0x2d95, 0x8021, /* VIVO USB-C-XE710 HEADSET */ 2536 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2537 DEVICE_FLG(0x2d99, 0x0026, /* HECATE G2 GAMING HEADSET */ 2538 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2539 DEVICE_FLG(0x2fc6, 0xf06b, /* MOONDROP Moonriver2 Ti */ 2540 QUIRK_FLAG_CTL_MSG_DELAY), 2541 DEVICE_FLG(0x2fc6, 0xf0b5, /* iBasso DC-Elite */ 2542 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2543 DEVICE_FLG(0x2fc6, 0xf0b7, /* iBasso DC07 Pro */ 2544 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2545 DEVICE_FLG(0x30be, 0x0101, /* Schiit Hel */ 2546 QUIRK_FLAG_IGNORE_CTL_ERROR), 2547 DEVICE_FLG(0x3255, 0x0000, /* Luxman D-10X */ 2548 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY), 2549 DEVICE_FLG(0x32bb, 0x0004, /* HiBy FC4 */ 2550 QUIRK_FLAG_DSD_RAW), 2551 DEVICE_FLG(0x3302, 0x17c2, /* TTGK Technology USB-C Audio */ 2552 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2553 DEVICE_FLG(0x339b, 0x3a07, /* Synaptics HONOR USB-C HEADSET */ 2554 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), 2555 DEVICE_FLG(0x3443, 0x930d, /* NexiGo N930W 60fps Webcam */ 2556 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16), 2557 DEVICE_FLG(0x36f9, 0xc009, /* XIBERIA K03S */ 2558 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2559 DEVICE_FLG(0x3c20, 0x3d21, /* AB13X USB Audio */ 2560 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), 2561 DEVICE_FLG(0x413c, 0xa506, /* Dell AE515 sound bar */ 2562 QUIRK_FLAG_GET_SAMPLE_RATE), 2563 DEVICE_FLG(0x534d, 0x0021, /* MacroSilicon MS2100/MS2106 */ 2564 QUIRK_FLAG_ALIGN_TRANSFER), 2565 DEVICE_FLG(0x534d, 0x2109, /* MacroSilicon MS2109 */ 2566 QUIRK_FLAG_ALIGN_TRANSFER), 2567 DEVICE_FLG(0x84ef, 0x002a, /* Valeton GP-200 */ 2568 QUIRK_FLAG_GENERIC_IMPLICIT_FB), 2569 DEVICE_FLG(0x84ef, 0x0082, /* Hotone Audio Pulze Mini */ 2570 QUIRK_FLAG_MIXER_PLAYBACK_LINEAR_VOL | QUIRK_FLAG_MIXER_CAPTURE_LINEAR_VOL), 2571 2572 /* Vendor and string descriptor matches */ 2573 VENDOR_STRING_FLG(0x1235, /* Conflict with Focusrite Novation */ 2574 "MV-SILICON", 2575 0), /* Stop matching */ 2576 2577 /* Vendor matches */ 2578 VENDOR_FLG(0x045e, /* MS Lifecam */ 2579 QUIRK_FLAG_GET_SAMPLE_RATE), 2580 VENDOR_FLG(0x046d, /* Logitech */ 2581 QUIRK_FLAG_CTL_MSG_DELAY_1M), 2582 VENDOR_FLG(0x047f, /* Plantronics */ 2583 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY), 2584 VENDOR_FLG(0x0644, /* TEAC Corp. */ 2585 QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY), 2586 VENDOR_FLG(0x07fd, /* MOTU */ 2587 QUIRK_FLAG_VALIDATE_RATES), 2588 DEVICE_FLG(0x1235, 0x8006, 0), /* Focusrite Scarlett 2i2 1st Gen */ 2589 DEVICE_FLG(0x1235, 0x800a, 0), /* Focusrite Scarlett 2i4 1st Gen */ 2590 DEVICE_FLG(0x1235, 0x800c, 0), /* Focusrite Scarlett 18i20 1st Gen */ 2591 DEVICE_FLG(0x1235, 0x8016, 0), /* Focusrite Scarlett 2i2 1st Gen */ 2592 DEVICE_FLG(0x1235, 0x801c, 0), /* Focusrite Scarlett Solo 1st Gen */ 2593 VENDOR_FLG(0x1235, /* Focusrite Novation */ 2594 QUIRK_FLAG_SKIP_CLOCK_SELECTOR | 2595 QUIRK_FLAG_SKIP_IFACE_SETUP), 2596 VENDOR_FLG(0x1511, /* AURALiC */ 2597 QUIRK_FLAG_DSD_RAW), 2598 VENDOR_FLG(0x152a, /* Thesycon devices */ 2599 QUIRK_FLAG_DSD_RAW), 2600 VENDOR_FLG(0x18d1, /* iBasso devices */ 2601 QUIRK_FLAG_DSD_RAW), 2602 VENDOR_FLG(0x1de7, /* Phoenix Audio */ 2603 QUIRK_FLAG_GET_SAMPLE_RATE), 2604 VENDOR_FLG(0x20b1, /* XMOS based devices */ 2605 QUIRK_FLAG_DSD_RAW), 2606 VENDOR_FLG(0x21ed, /* Accuphase Laboratory */ 2607 QUIRK_FLAG_DSD_RAW), 2608 VENDOR_FLG(0x22d9, /* Oppo */ 2609 QUIRK_FLAG_DSD_RAW), 2610 VENDOR_FLG(0x23ba, /* Playback Design */ 2611 QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY | 2612 QUIRK_FLAG_DSD_RAW), 2613 VENDOR_FLG(0x25ce, /* Mytek devices */ 2614 QUIRK_FLAG_DSD_RAW), 2615 VENDOR_FLG(0x2622, /* IAG Limited devices */ 2616 QUIRK_FLAG_DSD_RAW), 2617 VENDOR_FLG(0x2708, /* Audient devices */ 2618 QUIRK_FLAG_IGNORE_CTL_ERROR), 2619 VENDOR_FLG(0x2772, /* Musical Fidelity devices */ 2620 QUIRK_FLAG_DSD_RAW), 2621 VENDOR_FLG(0x278b, /* Rotel? */ 2622 QUIRK_FLAG_DSD_RAW), 2623 VENDOR_FLG(0x292b, /* Gustard/Ess based devices */ 2624 QUIRK_FLAG_DSD_RAW), 2625 VENDOR_FLG(0x2972, /* FiiO devices */ 2626 QUIRK_FLAG_DSD_RAW), 2627 VENDOR_FLG(0x2ab6, /* T+A devices */ 2628 QUIRK_FLAG_DSD_RAW), 2629 VENDOR_FLG(0x2afd, /* McIntosh Laboratory, Inc. */ 2630 QUIRK_FLAG_DSD_RAW), 2631 VENDOR_FLG(0x2d87, /* Cayin device */ 2632 QUIRK_FLAG_DSD_RAW), 2633 VENDOR_FLG(0x2fc6, /* Comture-inc devices */ 2634 QUIRK_FLAG_DSD_RAW), 2635 VENDOR_FLG(0x3336, /* HEM devices */ 2636 QUIRK_FLAG_DSD_RAW), 2637 VENDOR_FLG(0x3353, /* Khadas devices */ 2638 QUIRK_FLAG_DSD_RAW), 2639 VENDOR_FLG(0x35f4, /* MSB Technology */ 2640 QUIRK_FLAG_DSD_RAW), 2641 VENDOR_FLG(0x3842, /* EVGA */ 2642 QUIRK_FLAG_DSD_RAW), 2643 VENDOR_FLG(0xc502, /* HiBy devices */ 2644 QUIRK_FLAG_DSD_RAW), 2645 2646 {} /* terminator */ 2647 }; 2648 2649 #define QUIRK_STRING_ENTRY(x) \ 2650 [QUIRK_TYPE_ ## x] = __stringify(x) 2651 2652 static const char *const snd_usb_audio_quirk_flag_names[] = { 2653 QUIRK_STRING_ENTRY(GET_SAMPLE_RATE), 2654 QUIRK_STRING_ENTRY(SHARE_MEDIA_DEVICE), 2655 QUIRK_STRING_ENTRY(ALIGN_TRANSFER), 2656 QUIRK_STRING_ENTRY(TX_LENGTH), 2657 QUIRK_STRING_ENTRY(PLAYBACK_FIRST), 2658 QUIRK_STRING_ENTRY(SKIP_CLOCK_SELECTOR), 2659 QUIRK_STRING_ENTRY(IGNORE_CLOCK_SOURCE), 2660 QUIRK_STRING_ENTRY(ITF_USB_DSD_DAC), 2661 QUIRK_STRING_ENTRY(CTL_MSG_DELAY), 2662 QUIRK_STRING_ENTRY(CTL_MSG_DELAY_1M), 2663 QUIRK_STRING_ENTRY(CTL_MSG_DELAY_5M), 2664 QUIRK_STRING_ENTRY(IFACE_DELAY), 2665 QUIRK_STRING_ENTRY(VALIDATE_RATES), 2666 QUIRK_STRING_ENTRY(DISABLE_AUTOSUSPEND), 2667 QUIRK_STRING_ENTRY(IGNORE_CTL_ERROR), 2668 QUIRK_STRING_ENTRY(DSD_RAW), 2669 QUIRK_STRING_ENTRY(SET_IFACE_FIRST), 2670 QUIRK_STRING_ENTRY(GENERIC_IMPLICIT_FB), 2671 QUIRK_STRING_ENTRY(SKIP_IMPLICIT_FB), 2672 QUIRK_STRING_ENTRY(IFACE_SKIP_CLOSE), 2673 QUIRK_STRING_ENTRY(FORCE_IFACE_RESET), 2674 QUIRK_STRING_ENTRY(FIXED_RATE), 2675 QUIRK_STRING_ENTRY(MIC_RES_16), 2676 QUIRK_STRING_ENTRY(MIC_RES_384), 2677 QUIRK_STRING_ENTRY(MIXER_PLAYBACK_MIN_MUTE), 2678 QUIRK_STRING_ENTRY(MIXER_CAPTURE_MIN_MUTE), 2679 QUIRK_STRING_ENTRY(SKIP_IFACE_SETUP), 2680 QUIRK_STRING_ENTRY(MIXER_PLAYBACK_LINEAR_VOL), 2681 QUIRK_STRING_ENTRY(MIXER_CAPTURE_LINEAR_VOL), 2682 QUIRK_STRING_ENTRY(IFB_SILENCE_ON_EMPTY), 2683 QUIRK_STRING_ENTRY(MIXER_GET_CUR_OK), 2684 QUIRK_STRING_ENTRY(PLAYBACK_URB_FIXUP), 2685 QUIRK_STRING_ENTRY(ALWAYS_SET_RATE), 2686 NULL 2687 }; 2688 2689 static u64 snd_usb_quirk_flags_from_name(const char *name) 2690 { 2691 int i; 2692 2693 if (!name || !*name) 2694 return 0; 2695 2696 for (i = 0; snd_usb_audio_quirk_flag_names[i]; i++) { 2697 if (strcasecmp(name, snd_usb_audio_quirk_flag_names[i]) == 0) 2698 return BIT_U64(i); 2699 } 2700 2701 return 0; 2702 } 2703 2704 void snd_usb_apply_flag_dbg(const char *reason, 2705 struct snd_usb_audio *chip, 2706 unsigned long flag) 2707 { 2708 unsigned long bit; 2709 2710 for_each_set_bit(bit, &flag, BYTES_TO_BITS(sizeof(flag))) { 2711 const char *name = snd_usb_audio_quirk_flag_names[bit]; 2712 2713 if (name) 2714 usb_audio_dbg(chip, 2715 "From %s apply quirk flag %s for device %04x:%04x\n", 2716 reason, name, USB_ID_VENDOR(chip->usb_id), 2717 USB_ID_PRODUCT(chip->usb_id)); 2718 else 2719 usb_audio_warn(chip, 2720 "From %s apply unknown quirk flag 0x%lx for device %04x:%04x\n", 2721 reason, bit, USB_ID_VENDOR(chip->usb_id), 2722 USB_ID_PRODUCT(chip->usb_id)); 2723 } 2724 } 2725 2726 void snd_usb_init_quirk_flags_table(struct snd_usb_audio *chip) 2727 { 2728 const struct usb_audio_quirk_flags_table *p; 2729 2730 for (p = quirk_flags_table; p->id; p++) { 2731 if (chip->usb_id == p->id || 2732 (!USB_ID_PRODUCT(p->id) && 2733 USB_ID_VENDOR(chip->usb_id) == USB_ID_VENDOR(p->id))) { 2734 /* Handle DEVICE_STRING_FLG/VENDOR_STRING_FLG. */ 2735 if (p->usb_string_match && p->usb_string_match->manufacturer && 2736 strcmp(p->usb_string_match->manufacturer, 2737 chip->dev->manufacturer ? chip->dev->manufacturer : "")) 2738 continue; 2739 if (p->usb_string_match && p->usb_string_match->product && 2740 strcmp(p->usb_string_match->product, 2741 chip->dev->product ? chip->dev->product : "")) 2742 continue; 2743 2744 snd_usb_apply_flag_dbg("builtin table", chip, p->flags); 2745 chip->quirk_flags |= p->flags; 2746 return; 2747 } 2748 } 2749 } 2750 2751 void snd_usb_init_quirk_flags_parse_string(struct snd_usb_audio *chip, 2752 const char *str) 2753 { 2754 u16 chip_vid = USB_ID_VENDOR(chip->usb_id); 2755 u16 chip_pid = USB_ID_PRODUCT(chip->usb_id); 2756 u64 mask_flags, unmask_flags, bit; 2757 char *p, *field, *flag; 2758 bool is_unmask; 2759 u16 vid, pid; 2760 2761 char *val __free(kfree) = kstrdup(str, GFP_KERNEL); 2762 2763 if (!val) 2764 return; 2765 2766 for (p = val; p && *p;) { 2767 /* Each entry consists of VID:PID:flags */ 2768 field = strsep(&p, ":"); 2769 if (!field) 2770 break; 2771 2772 if (strcmp(field, "*") == 0) 2773 vid = 0; 2774 else if (kstrtou16(field, 16, &vid)) 2775 break; 2776 2777 field = strsep(&p, ":"); 2778 if (!field) 2779 break; 2780 2781 if (strcmp(field, "*") == 0) 2782 pid = 0; 2783 else if (kstrtou16(field, 16, &pid)) 2784 break; 2785 2786 field = strsep(&p, ";"); 2787 if (!field || !*field) 2788 break; 2789 2790 if ((vid != 0 && vid != chip_vid) || 2791 (pid != 0 && pid != chip_pid)) 2792 continue; 2793 2794 /* Collect the flags */ 2795 mask_flags = 0; 2796 unmask_flags = 0; 2797 while (field && *field) { 2798 flag = strsep(&field, "|"); 2799 2800 if (!flag) 2801 break; 2802 2803 if (*flag == '!') { 2804 is_unmask = true; 2805 flag++; 2806 } else { 2807 is_unmask = false; 2808 } 2809 2810 if (!kstrtou64(flag, 16, &bit)) { 2811 if (is_unmask) 2812 unmask_flags |= bit; 2813 else 2814 mask_flags |= bit; 2815 2816 break; 2817 } 2818 2819 bit = snd_usb_quirk_flags_from_name(flag); 2820 2821 if (bit) { 2822 if (is_unmask) 2823 unmask_flags |= bit; 2824 else 2825 mask_flags |= bit; 2826 } else { 2827 pr_warn("snd_usb_audio: unknown flag %s while parsing param quirk_flags\n", 2828 flag); 2829 } 2830 } 2831 2832 chip->quirk_flags &= ~unmask_flags; 2833 chip->quirk_flags |= mask_flags; 2834 snd_usb_apply_flag_dbg("module param", chip, 2835 chip->quirk_flags); 2836 } 2837 } 2838