hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/usb/format.c
....@@ -1,18 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
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
- *
163 */
174
185 #include <linux/init.h>
....@@ -53,8 +40,12 @@
5340 case UAC_VERSION_1:
5441 default: {
5542 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
+ }
5849 sample_width = fmt->bBitResolution;
5950 sample_bytes = fmt->bSubframeSize;
6051 format = 1ULL << format;
....@@ -88,6 +79,8 @@
8879 break;
8980 }
9081 }
82
+
83
+ fp->fmt_bits = sample_width;
9184
9285 if ((pcm_formats == 0) &&
9386 (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
....@@ -164,6 +157,19 @@
164157 return pcm_formats;
165158 }
166159
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
+}
167173
168174 /*
169175 * parse the format descriptor and stores the possible sample rates
....@@ -238,7 +244,45 @@
238244 fp->rate_min = combine_triple(&fmt[offset + 1]);
239245 fp->rate_max = combine_triple(&fmt[offset + 4]);
240246 }
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
+
241255 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;
242286 }
243287
244288 /*
....@@ -323,6 +367,12 @@
323367 }
324368
325369 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
+
326376 /* Filter out invalid rates on Focusrite devices */
327377 if (USB_ID_VENDOR(chip->usb_id) == 0x1235 &&
328378 !focusrite_valid_sample_rate(chip, fp, rate))
....@@ -352,6 +402,31 @@
352402 return nr_rates;
353403 }
354404
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
+
355430 /*
356431 * parse the format descriptor and stores the possible sample rates
357432 * on the audioformat table (audio class v2 and v3).
....@@ -361,7 +436,7 @@
361436 {
362437 struct usb_device *dev = chip->dev;
363438 unsigned char tmp[2], *data;
364
- int nr_triplets, data_size, ret = 0;
439
+ int nr_triplets, data_size, ret = 0, ret_l6;
365440 int clock = snd_usb_clock_find_source(chip, fp, false);
366441
367442 if (clock < 0) {
....@@ -379,9 +454,22 @@
379454 tmp, sizeof(tmp));
380455
381456 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",
384463 __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;
385473 goto err;
386474 }
387475