forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
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>
....@@ -89,6 +76,8 @@
8976 }
9077 }
9178
79
+ fp->fmt_bits = sample_width;
80
+
9281 if ((pcm_formats == 0) &&
9382 (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
9483 /* some devices don't define this correctly... */
....@@ -164,6 +153,19 @@
164153 return pcm_formats;
165154 }
166155
156
+static int set_fixed_rate(struct audioformat *fp, int rate, int rate_bits)
157
+{
158
+ kfree(fp->rate_table);
159
+ fp->rate_table = kmalloc(sizeof(int), GFP_KERNEL);
160
+ if (!fp->rate_table)
161
+ return -ENOMEM;
162
+ fp->nr_rates = 1;
163
+ fp->rate_min = rate;
164
+ fp->rate_max = rate;
165
+ fp->rates = rate_bits;
166
+ fp->rate_table[0] = rate;
167
+ return 0;
168
+}
167169
168170 /*
169171 * parse the format descriptor and stores the possible sample rates
....@@ -238,7 +240,45 @@
238240 fp->rate_min = combine_triple(&fmt[offset + 1]);
239241 fp->rate_max = combine_triple(&fmt[offset + 4]);
240242 }
243
+
244
+ /* Jabra Evolve 65 headset */
245
+ if (chip->usb_id == USB_ID(0x0b0e, 0x030b)) {
246
+ /* only 48kHz for playback while keeping 16kHz for capture */
247
+ if (fp->nr_rates != 1)
248
+ return set_fixed_rate(fp, 48000, SNDRV_PCM_RATE_48000);
249
+ }
250
+
241251 return 0;
252
+}
253
+
254
+
255
+/*
256
+ * Presonus Studio 1810c supports a limited set of sampling
257
+ * rates per altsetting but reports the full set each time.
258
+ * If we don't filter out the unsupported rates and attempt
259
+ * to configure the card, it will hang refusing to do any
260
+ * further audio I/O until a hard reset is performed.
261
+ *
262
+ * The list of supported rates per altsetting (set of available
263
+ * I/O channels) is described in the owner's manual, section 2.2.
264
+ */
265
+static bool s1810c_valid_sample_rate(struct audioformat *fp,
266
+ unsigned int rate)
267
+{
268
+ switch (fp->altsetting) {
269
+ case 1:
270
+ /* All ADAT ports available */
271
+ return rate <= 48000;
272
+ case 2:
273
+ /* Half of ADAT ports available */
274
+ return (rate == 88200 || rate == 96000);
275
+ case 3:
276
+ /* Analog I/O only (no S/PDIF nor ADAT) */
277
+ return rate >= 176400;
278
+ default:
279
+ return false;
280
+ }
281
+ return false;
242282 }
243283
244284 /*
....@@ -323,6 +363,12 @@
323363 }
324364
325365 for (rate = min; rate <= max; rate += res) {
366
+
367
+ /* Filter out invalid rates on Presonus Studio 1810c */
368
+ if (chip->usb_id == USB_ID(0x194f, 0x010c) &&
369
+ !s1810c_valid_sample_rate(fp, rate))
370
+ goto skip_rate;
371
+
326372 /* Filter out invalid rates on Focusrite devices */
327373 if (USB_ID_VENDOR(chip->usb_id) == 0x1235 &&
328374 !focusrite_valid_sample_rate(chip, fp, rate))
....@@ -352,6 +398,30 @@
352398 return nr_rates;
353399 }
354400
401
+/* Line6 Helix series and the Rode Rodecaster Pro don't support the
402
+ * UAC2_CS_RANGE usb function call. Return a static table of known
403
+ * clock rates.
404
+ */
405
+static int line6_parse_audio_format_rates_quirk(struct snd_usb_audio *chip,
406
+ struct audioformat *fp)
407
+{
408
+ switch (chip->usb_id) {
409
+ case USB_ID(0x0e41, 0x4241): /* Line6 Helix */
410
+ case USB_ID(0x0e41, 0x4242): /* Line6 Helix Rack */
411
+ case USB_ID(0x0e41, 0x4244): /* Line6 Helix LT */
412
+ case USB_ID(0x0e41, 0x4246): /* Line6 HX-Stomp */
413
+ case USB_ID(0x0e41, 0x4253): /* Line6 HX-Stomp XL */
414
+ case USB_ID(0x0e41, 0x4247): /* Line6 Pod Go */
415
+ case USB_ID(0x0e41, 0x4248): /* Line6 Helix >= fw 2.82 */
416
+ case USB_ID(0x0e41, 0x4249): /* Line6 Helix Rack >= fw 2.82 */
417
+ case USB_ID(0x0e41, 0x424a): /* Line6 Helix LT >= fw 2.82 */
418
+ case USB_ID(0x19f7, 0x0011): /* Rode Rodecaster Pro */
419
+ return set_fixed_rate(fp, 48000, SNDRV_PCM_RATE_48000);
420
+ }
421
+
422
+ return -ENODEV;
423
+}
424
+
355425 /*
356426 * parse the format descriptor and stores the possible sample rates
357427 * on the audioformat table (audio class v2 and v3).
....@@ -361,7 +431,7 @@
361431 {
362432 struct usb_device *dev = chip->dev;
363433 unsigned char tmp[2], *data;
364
- int nr_triplets, data_size, ret = 0;
434
+ int nr_triplets, data_size, ret = 0, ret_l6;
365435 int clock = snd_usb_clock_find_source(chip, fp, false);
366436
367437 if (clock < 0) {
....@@ -379,9 +449,22 @@
379449 tmp, sizeof(tmp));
380450
381451 if (ret < 0) {
382
- dev_err(&dev->dev,
383
- "%s(): unable to retrieve number of sample rates (clock %d)\n",
452
+ /* line6 helix devices don't support UAC2_CS_CONTROL_SAM_FREQ call */
453
+ ret_l6 = line6_parse_audio_format_rates_quirk(chip, fp);
454
+ if (ret_l6 == -ENODEV) {
455
+ /* no line6 device found continue showing the error */
456
+ dev_err(&dev->dev,
457
+ "%s(): unable to retrieve number of sample rates (clock %d)\n",
384458 __func__, clock);
459
+ goto err;
460
+ }
461
+ if (ret_l6 == 0) {
462
+ dev_info(&dev->dev,
463
+ "%s(): unable to retrieve number of sample rates: set it to a predefined value (clock %d).\n",
464
+ __func__, clock);
465
+ return 0;
466
+ }
467
+ ret = ret_l6;
385468 goto err;
386469 }
387470