| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 3 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 4 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 5 | | - * (at your option) any later version. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 8 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 9 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 10 | | - * GNU General Public License for more details. |
|---|
| 11 | | - * |
|---|
| 12 | | - * You should have received a copy of the GNU General Public License |
|---|
| 13 | | - * along with this program; if not, write to the Free Software |
|---|
| 14 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 15 | | - * |
|---|
| 16 | 3 | */ |
|---|
| 17 | 4 | |
|---|
| 18 | 5 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 53 | 40 | case UAC_VERSION_1: |
|---|
| 54 | 41 | default: { |
|---|
| 55 | 42 | struct uac_format_type_i_discrete_descriptor *fmt = _fmt; |
|---|
| 56 | | - if (format >= 64) |
|---|
| 57 | | - return 0; /* invalid format */ |
|---|
| 43 | + if (format >= 64) { |
|---|
| 44 | + usb_audio_info(chip, |
|---|
| 45 | + "%u:%d: invalid format type 0x%llx is detected, processed as PCM\n", |
|---|
| 46 | + fp->iface, fp->altsetting, format); |
|---|
| 47 | + format = UAC_FORMAT_TYPE_I_PCM; |
|---|
| 48 | + } |
|---|
| 58 | 49 | sample_width = fmt->bBitResolution; |
|---|
| 59 | 50 | sample_bytes = fmt->bSubframeSize; |
|---|
| 60 | 51 | format = 1ULL << format; |
|---|
| .. | .. |
|---|
| 88 | 79 | break; |
|---|
| 89 | 80 | } |
|---|
| 90 | 81 | } |
|---|
| 82 | + |
|---|
| 83 | + fp->fmt_bits = sample_width; |
|---|
| 91 | 84 | |
|---|
| 92 | 85 | if ((pcm_formats == 0) && |
|---|
| 93 | 86 | (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) { |
|---|
| .. | .. |
|---|
| 164 | 157 | return pcm_formats; |
|---|
| 165 | 158 | } |
|---|
| 166 | 159 | |
|---|
| 160 | +static int set_fixed_rate(struct audioformat *fp, int rate, int rate_bits) |
|---|
| 161 | +{ |
|---|
| 162 | + kfree(fp->rate_table); |
|---|
| 163 | + fp->rate_table = kmalloc(sizeof(int), GFP_KERNEL); |
|---|
| 164 | + if (!fp->rate_table) |
|---|
| 165 | + return -ENOMEM; |
|---|
| 166 | + fp->nr_rates = 1; |
|---|
| 167 | + fp->rate_min = rate; |
|---|
| 168 | + fp->rate_max = rate; |
|---|
| 169 | + fp->rates = rate_bits; |
|---|
| 170 | + fp->rate_table[0] = rate; |
|---|
| 171 | + return 0; |
|---|
| 172 | +} |
|---|
| 167 | 173 | |
|---|
| 168 | 174 | /* |
|---|
| 169 | 175 | * parse the format descriptor and stores the possible sample rates |
|---|
| .. | .. |
|---|
| 238 | 244 | fp->rate_min = combine_triple(&fmt[offset + 1]); |
|---|
| 239 | 245 | fp->rate_max = combine_triple(&fmt[offset + 4]); |
|---|
| 240 | 246 | } |
|---|
| 247 | + |
|---|
| 248 | + /* Jabra Evolve 65 headset */ |
|---|
| 249 | + if (chip->usb_id == USB_ID(0x0b0e, 0x030b)) { |
|---|
| 250 | + /* only 48kHz for playback while keeping 16kHz for capture */ |
|---|
| 251 | + if (fp->nr_rates != 1) |
|---|
| 252 | + return set_fixed_rate(fp, 48000, SNDRV_PCM_RATE_48000); |
|---|
| 253 | + } |
|---|
| 254 | + |
|---|
| 241 | 255 | return 0; |
|---|
| 256 | +} |
|---|
| 257 | + |
|---|
| 258 | + |
|---|
| 259 | +/* |
|---|
| 260 | + * Presonus Studio 1810c supports a limited set of sampling |
|---|
| 261 | + * rates per altsetting but reports the full set each time. |
|---|
| 262 | + * If we don't filter out the unsupported rates and attempt |
|---|
| 263 | + * to configure the card, it will hang refusing to do any |
|---|
| 264 | + * further audio I/O until a hard reset is performed. |
|---|
| 265 | + * |
|---|
| 266 | + * The list of supported rates per altsetting (set of available |
|---|
| 267 | + * I/O channels) is described in the owner's manual, section 2.2. |
|---|
| 268 | + */ |
|---|
| 269 | +static bool s1810c_valid_sample_rate(struct audioformat *fp, |
|---|
| 270 | + unsigned int rate) |
|---|
| 271 | +{ |
|---|
| 272 | + switch (fp->altsetting) { |
|---|
| 273 | + case 1: |
|---|
| 274 | + /* All ADAT ports available */ |
|---|
| 275 | + return rate <= 48000; |
|---|
| 276 | + case 2: |
|---|
| 277 | + /* Half of ADAT ports available */ |
|---|
| 278 | + return (rate == 88200 || rate == 96000); |
|---|
| 279 | + case 3: |
|---|
| 280 | + /* Analog I/O only (no S/PDIF nor ADAT) */ |
|---|
| 281 | + return rate >= 176400; |
|---|
| 282 | + default: |
|---|
| 283 | + return false; |
|---|
| 284 | + } |
|---|
| 285 | + return false; |
|---|
| 242 | 286 | } |
|---|
| 243 | 287 | |
|---|
| 244 | 288 | /* |
|---|
| .. | .. |
|---|
| 323 | 367 | } |
|---|
| 324 | 368 | |
|---|
| 325 | 369 | for (rate = min; rate <= max; rate += res) { |
|---|
| 370 | + |
|---|
| 371 | + /* Filter out invalid rates on Presonus Studio 1810c */ |
|---|
| 372 | + if (chip->usb_id == USB_ID(0x194f, 0x010c) && |
|---|
| 373 | + !s1810c_valid_sample_rate(fp, rate)) |
|---|
| 374 | + goto skip_rate; |
|---|
| 375 | + |
|---|
| 326 | 376 | /* Filter out invalid rates on Focusrite devices */ |
|---|
| 327 | 377 | if (USB_ID_VENDOR(chip->usb_id) == 0x1235 && |
|---|
| 328 | 378 | !focusrite_valid_sample_rate(chip, fp, rate)) |
|---|
| .. | .. |
|---|
| 352 | 402 | return nr_rates; |
|---|
| 353 | 403 | } |
|---|
| 354 | 404 | |
|---|
| 405 | +/* Line6 Helix series and the Rode Rodecaster Pro don't support the |
|---|
| 406 | + * UAC2_CS_RANGE usb function call. Return a static table of known |
|---|
| 407 | + * clock rates. |
|---|
| 408 | + */ |
|---|
| 409 | +static int line6_parse_audio_format_rates_quirk(struct snd_usb_audio *chip, |
|---|
| 410 | + struct audioformat *fp) |
|---|
| 411 | +{ |
|---|
| 412 | + switch (chip->usb_id) { |
|---|
| 413 | + case USB_ID(0x0e41, 0x4241): /* Line6 Helix */ |
|---|
| 414 | + case USB_ID(0x0e41, 0x4242): /* Line6 Helix Rack */ |
|---|
| 415 | + case USB_ID(0x0e41, 0x4244): /* Line6 Helix LT */ |
|---|
| 416 | + case USB_ID(0x0e41, 0x4246): /* Line6 HX-Stomp */ |
|---|
| 417 | + case USB_ID(0x0e41, 0x4253): /* Line6 HX-Stomp XL */ |
|---|
| 418 | + case USB_ID(0x0e41, 0x4247): /* Line6 Pod Go */ |
|---|
| 419 | + case USB_ID(0x0e41, 0x4248): /* Line6 Helix >= fw 2.82 */ |
|---|
| 420 | + case USB_ID(0x0e41, 0x4249): /* Line6 Helix Rack >= fw 2.82 */ |
|---|
| 421 | + case USB_ID(0x0e41, 0x424a): /* Line6 Helix LT >= fw 2.82 */ |
|---|
| 422 | + case USB_ID(0x0e41, 0x424b): /* Line6 Pod Go */ |
|---|
| 423 | + case USB_ID(0x19f7, 0x0011): /* Rode Rodecaster Pro */ |
|---|
| 424 | + return set_fixed_rate(fp, 48000, SNDRV_PCM_RATE_48000); |
|---|
| 425 | + } |
|---|
| 426 | + |
|---|
| 427 | + return -ENODEV; |
|---|
| 428 | +} |
|---|
| 429 | + |
|---|
| 355 | 430 | /* |
|---|
| 356 | 431 | * parse the format descriptor and stores the possible sample rates |
|---|
| 357 | 432 | * on the audioformat table (audio class v2 and v3). |
|---|
| .. | .. |
|---|
| 361 | 436 | { |
|---|
| 362 | 437 | struct usb_device *dev = chip->dev; |
|---|
| 363 | 438 | unsigned char tmp[2], *data; |
|---|
| 364 | | - int nr_triplets, data_size, ret = 0; |
|---|
| 439 | + int nr_triplets, data_size, ret = 0, ret_l6; |
|---|
| 365 | 440 | int clock = snd_usb_clock_find_source(chip, fp, false); |
|---|
| 366 | 441 | |
|---|
| 367 | 442 | if (clock < 0) { |
|---|
| .. | .. |
|---|
| 379 | 454 | tmp, sizeof(tmp)); |
|---|
| 380 | 455 | |
|---|
| 381 | 456 | if (ret < 0) { |
|---|
| 382 | | - dev_err(&dev->dev, |
|---|
| 383 | | - "%s(): unable to retrieve number of sample rates (clock %d)\n", |
|---|
| 457 | + /* line6 helix devices don't support UAC2_CS_CONTROL_SAM_FREQ call */ |
|---|
| 458 | + ret_l6 = line6_parse_audio_format_rates_quirk(chip, fp); |
|---|
| 459 | + if (ret_l6 == -ENODEV) { |
|---|
| 460 | + /* no line6 device found continue showing the error */ |
|---|
| 461 | + dev_err(&dev->dev, |
|---|
| 462 | + "%s(): unable to retrieve number of sample rates (clock %d)\n", |
|---|
| 384 | 463 | __func__, clock); |
|---|
| 464 | + goto err; |
|---|
| 465 | + } |
|---|
| 466 | + if (ret_l6 == 0) { |
|---|
| 467 | + dev_info(&dev->dev, |
|---|
| 468 | + "%s(): unable to retrieve number of sample rates: set it to a predefined value (clock %d).\n", |
|---|
| 469 | + __func__, clock); |
|---|
| 470 | + return 0; |
|---|
| 471 | + } |
|---|
| 472 | + ret = ret_l6; |
|---|
| 385 | 473 | goto err; |
|---|
| 386 | 474 | } |
|---|
| 387 | 475 | |
|---|