format.c 15.6 KB
Newer Older
Daniel Mack's avatar
Daniel Mack committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <linux/init.h>
19
#include <linux/slab.h>
Daniel Mack's avatar
Daniel Mack committed
20
21
#include <linux/usb.h>
#include <linux/usb/audio.h>
Daniel Mack's avatar
Daniel Mack committed
22
#include <linux/usb/audio-v2.h>
23
#include <linux/usb/audio-v3.h>
Daniel Mack's avatar
Daniel Mack committed
24
25
26
27
28
29
30
31
32

#include <sound/core.h>
#include <sound/pcm.h>

#include "usbaudio.h"
#include "card.h"
#include "quirks.h"
#include "helper.h"
#include "debug.h"
33
#include "clock.h"
34
#include "format.h"
Daniel Mack's avatar
Daniel Mack committed
35
36
37
38
39
40
41
42

/*
 * parse the audio format type I descriptor
 * and returns the corresponding pcm format
 *
 * @dev: usb device
 * @fp: audioformat record
 * @format: the format tag (wFormatTag)
43
 * @fmt: the format type descriptor (v1/v2) or AudioStreaming descriptor (v3)
Daniel Mack's avatar
Daniel Mack committed
44
 */
45
static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
Daniel Mack's avatar
Daniel Mack committed
46
				     struct audioformat *fp,
47
				     u64 format, void *_fmt)
Daniel Mack's avatar
Daniel Mack committed
48
49
{
	int sample_width, sample_bytes;
50
	u64 pcm_formats = 0;
Daniel Mack's avatar
Daniel Mack committed
51

52
	switch (fp->protocol) {
53
54
	case UAC_VERSION_1:
	default: {
Daniel Mack's avatar
Daniel Mack committed
55
56
57
		struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
		sample_width = fmt->bBitResolution;
		sample_bytes = fmt->bSubframeSize;
58
		format = 1ULL << format;
Daniel Mack's avatar
Daniel Mack committed
59
60
61
62
63
64
65
		break;
	}

	case UAC_VERSION_2: {
		struct uac_format_type_i_ext_descriptor *fmt = _fmt;
		sample_width = fmt->bBitResolution;
		sample_bytes = fmt->bSubslotSize;
66

67
		if (format & UAC2_FORMAT_TYPE_I_RAW_DATA) {
68
			pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
69
70
71
			/* flag potentially raw DSD capable altsettings */
			fp->dsd_raw = true;
		}
72

73
		format <<= 1;
Daniel Mack's avatar
Daniel Mack committed
74
75
		break;
	}
76
77
78
79
80
81
82
83
84
85
86
87
	case UAC_VERSION_3: {
		struct uac3_as_header_descriptor *as = _fmt;

		sample_width = as->bBitResolution;
		sample_bytes = as->bSubslotSize;

		if (format & UAC3_FORMAT_TYPE_I_RAW_DATA)
			pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;

		format <<= 1;
		break;
	}
Daniel Mack's avatar
Daniel Mack committed
88
89
	}

90
91
	if ((pcm_formats == 0) &&
	    (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
92
		/* some devices don't define this correctly... */
93
94
		usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
			fp->iface, fp->altsetting);
95
96
97
		format = 1 << UAC_FORMAT_TYPE_I_PCM;
	}
	if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
98
99
100
101
		if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
		     /* Edirol SD-90 */
		     (chip->usb_id == USB_ID(0x0582, 0x000c))) &&
		     /* Roland SC-D70 */
102
103
104
		    sample_width == 24 && sample_bytes == 2)
			sample_bytes = 3;
		else if (sample_width > sample_bytes * 8) {
105
106
107
			usb_audio_info(chip, "%u:%d : sample bitwidth %d in over sample bytes %d\n",
				 fp->iface, fp->altsetting,
				 sample_width, sample_bytes);
Daniel Mack's avatar
Daniel Mack committed
108
109
110
111
		}
		/* check the format byte size */
		switch (sample_bytes) {
		case 1:
112
			pcm_formats |= SNDRV_PCM_FMTBIT_S8;
Daniel Mack's avatar
Daniel Mack committed
113
114
115
			break;
		case 2:
			if (snd_usb_is_big_endian_format(chip, fp))
116
				pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */
Daniel Mack's avatar
Daniel Mack committed
117
			else
118
				pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE;
Daniel Mack's avatar
Daniel Mack committed
119
120
121
			break;
		case 3:
			if (snd_usb_is_big_endian_format(chip, fp))
122
				pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */
Daniel Mack's avatar
Daniel Mack committed
123
			else
124
				pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE;
Daniel Mack's avatar
Daniel Mack committed
125
126
			break;
		case 4:
127
			pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE;
Daniel Mack's avatar
Daniel Mack committed
128
129
			break;
		default:
130
131
132
133
			usb_audio_info(chip,
				 "%u:%d : unsupported sample bitwidth %d in %d bytes\n",
				 fp->iface, fp->altsetting,
				 sample_width, sample_bytes);
Daniel Mack's avatar
Daniel Mack committed
134
135
			break;
		}
136
137
	}
	if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
Daniel Mack's avatar
Daniel Mack committed
138
139
140
		/* Dallas DS4201 workaround: it advertises U8 format, but really
		   supports S8. */
		if (chip->usb_id == USB_ID(0x04fa, 0x4201))
141
142
143
144
145
146
147
148
149
150
151
152
153
154
			pcm_formats |= SNDRV_PCM_FMTBIT_S8;
		else
			pcm_formats |= SNDRV_PCM_FMTBIT_U8;
	}
	if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
		pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
	}
	if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
		pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
	}
	if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
		pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
	}
	if (format & ~0x3f) {
155
		usb_audio_info(chip,
156
			 "%u:%d : unsupported format bits %#llx\n",
157
			 fp->iface, fp->altsetting, format);
Daniel Mack's avatar
Daniel Mack committed
158
	}
159
160
161

	pcm_formats |= snd_usb_interface_dsd_format_quirks(chip, fp, sample_bytes);

162
	return pcm_formats;
Daniel Mack's avatar
Daniel Mack committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
}


/*
 * parse the format descriptor and stores the possible sample rates
 * on the audioformat table (audio class v1).
 *
 * @dev: usb device
 * @fp: audioformat record
 * @fmt: the format descriptor
 * @offset: the start offset of descriptor pointing the rate type
 *          (7 for type I and II, 8 for type II)
 */
static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
				       unsigned char *fmt, int offset)
{
	int nr_rates = fmt[offset];

	if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
182
183
184
		usb_audio_err(chip,
			"%u:%d : invalid UAC_FORMAT_TYPE desc\n",
			fp->iface, fp->altsetting);
185
		return -EINVAL;
Daniel Mack's avatar
Daniel Mack committed
186
187
188
189
190
191
192
193
	}

	if (nr_rates) {
		/*
		 * build the rate table and bitmap flags
		 */
		int r, idx;

194
195
		fp->rate_table = kmalloc_array(nr_rates, sizeof(int),
					       GFP_KERNEL);
196
		if (fp->rate_table == NULL)
197
			return -ENOMEM;
Daniel Mack's avatar
Daniel Mack committed
198
199
200
201
202
203
204
205

		fp->nr_rates = 0;
		fp->rate_min = fp->rate_max = 0;
		for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
			unsigned int rate = combine_triple(&fmt[idx]);
			if (!rate)
				continue;
			/* C-Media CM6501 mislabels its 96 kHz altsetting */
206
			/* Terratec Aureon 7.1 USB C-Media 6206, too */
Daniel Mack's avatar
Daniel Mack committed
207
208
			if (rate == 48000 && nr_rates == 1 &&
			    (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
209
210
			     chip->usb_id == USB_ID(0x0d8c, 0x0102) ||
			     chip->usb_id == USB_ID(0x0ccd, 0x00b1)) &&
Daniel Mack's avatar
Daniel Mack committed
211
212
			    fp->altsetting == 5 && fp->maxpacksize == 392)
				rate = 96000;
213
214
215
216
			/* Creative VF0420/VF0470 Live Cams report 16 kHz instead of 8kHz */
			if (rate == 16000 &&
			    (chip->usb_id == USB_ID(0x041e, 0x4064) ||
			     chip->usb_id == USB_ID(0x041e, 0x4068)))
Daniel Mack's avatar
Daniel Mack committed
217
218
219
220
221
222
223
224
225
226
227
228
				rate = 8000;

			fp->rate_table[fp->nr_rates] = rate;
			if (!fp->rate_min || rate < fp->rate_min)
				fp->rate_min = rate;
			if (!fp->rate_max || rate > fp->rate_max)
				fp->rate_max = rate;
			fp->rates |= snd_pcm_rate_to_rate_bit(rate);
			fp->nr_rates++;
		}
		if (!fp->nr_rates) {
			hwc_debug("All rates were zero. Skipping format!\n");
229
			return -EINVAL;
Daniel Mack's avatar
Daniel Mack committed
230
231
232
233
234
235
236
237
238
239
		}
	} else {
		/* continuous rates */
		fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
		fp->rate_min = combine_triple(&fmt[offset + 1]);
		fp->rate_max = combine_triple(&fmt[offset + 4]);
	}
	return 0;
}

240
241
242
243
244
245
/*
 * Helper function to walk the array of sample rate triplets reported by
 * the device. The problem is that we need to parse whole array first to
 * get to know how many sample rates we have to expect.
 * Then fp->rate_table can be allocated and filled.
 */
246
247
static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
					struct audioformat *fp, int nr_triplets,
248
249
250
251
252
253
254
255
256
257
					const unsigned char *data)
{
	int i, nr_rates = 0;

	fp->rates = fp->rate_min = fp->rate_max = 0;

	for (i = 0; i < nr_triplets; i++) {
		int min = combine_quad(&data[2 + 12 * i]);
		int max = combine_quad(&data[6 + 12 * i]);
		int res = combine_quad(&data[10 + 12 * i]);
258
		unsigned int rate;
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

		if ((max < 0) || (min < 0) || (res < 0) || (max < min))
			continue;

		/*
		 * for ranges with res == 1, we announce a continuous sample
		 * rate range, and this function should return 0 for no further
		 * parsing.
		 */
		if (res == 1) {
			fp->rate_min = min;
			fp->rate_max = max;
			fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
			return 0;
		}

		for (rate = min; rate <= max; rate += res) {
			if (fp->rate_table)
				fp->rate_table[nr_rates] = rate;
			if (!fp->rate_min || rate < fp->rate_min)
				fp->rate_min = rate;
			if (!fp->rate_max || rate > fp->rate_max)
				fp->rate_max = rate;
			fp->rates |= snd_pcm_rate_to_rate_bit(rate);

			nr_rates++;
285
			if (nr_rates >= MAX_NR_RATES) {
286
				usb_audio_err(chip, "invalid uac2 rates\n");
287
288
				break;
			}
289
290
291
292
293
294
295
296
297
298

			/* avoid endless loop */
			if (res == 0)
				break;
		}
	}

	return nr_rates;
}

Daniel Mack's avatar
Daniel Mack committed
299
300
/*
 * parse the format descriptor and stores the possible sample rates
301
 * on the audioformat table (audio class v2 and v3).
Daniel Mack's avatar
Daniel Mack committed
302
 */
303
static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip,
304
				       struct audioformat *fp)
Daniel Mack's avatar
Daniel Mack committed
305
306
307
{
	struct usb_device *dev = chip->dev;
	unsigned char tmp[2], *data;
308
	int nr_triplets, data_size, ret = 0;
309
310
	int clock = snd_usb_clock_find_source(chip, fp->protocol,
					      fp->clock, false);
Daniel Mack's avatar
Daniel Mack committed
311

312
	if (clock < 0) {
313
314
		dev_err(&dev->dev,
			"%s(): unable to find clock source (clock %d)\n",
315
316
317
318
				__func__, clock);
		goto err;
	}

Daniel Mack's avatar
Daniel Mack committed
319
320
321
	/* get the number of sample rates first by only fetching 2 bytes */
	ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
			      USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
322
323
			      UAC2_CS_CONTROL_SAM_FREQ << 8,
			      snd_usb_ctrl_intf(chip) | (clock << 8),
324
			      tmp, sizeof(tmp));
Daniel Mack's avatar
Daniel Mack committed
325
326

	if (ret < 0) {
327
328
		dev_err(&dev->dev,
			"%s(): unable to retrieve number of sample rates (clock %d)\n",
329
				__func__, clock);
Daniel Mack's avatar
Daniel Mack committed
330
331
332
		goto err;
	}

333
334
	nr_triplets = (tmp[1] << 8) | tmp[0];
	data_size = 2 + 12 * nr_triplets;
Daniel Mack's avatar
Daniel Mack committed
335
336
337
338
339
340
341
342
	data = kzalloc(data_size, GFP_KERNEL);
	if (!data) {
		ret = -ENOMEM;
		goto err;
	}

	/* now get the full information */
	ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
343
			      USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
344
345
			      UAC2_CS_CONTROL_SAM_FREQ << 8,
			      snd_usb_ctrl_intf(chip) | (clock << 8),
346
			      data, data_size);
Daniel Mack's avatar
Daniel Mack committed
347
348

	if (ret < 0) {
349
350
		dev_err(&dev->dev,
			"%s(): unable to retrieve sample rate range (clock %d)\n",
351
				__func__, clock);
Daniel Mack's avatar
Daniel Mack committed
352
353
354
355
		ret = -EINVAL;
		goto err_free;
	}

356
357
358
359
360
	/* Call the triplet parser, and make sure fp->rate_table is NULL.
	 * We just use the return value to know how many sample rates we
	 * will have to deal with. */
	kfree(fp->rate_table);
	fp->rate_table = NULL;
361
	fp->nr_rates = parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
362
363
364
365
366
367
368

	if (fp->nr_rates == 0) {
		/* SNDRV_PCM_RATE_CONTINUOUS */
		ret = 0;
		goto err_free;
	}

369
	fp->rate_table = kmalloc_array(fp->nr_rates, sizeof(int), GFP_KERNEL);
Daniel Mack's avatar
Daniel Mack committed
370
371
372
373
374
	if (!fp->rate_table) {
		ret = -ENOMEM;
		goto err_free;
	}

375
376
	/* Call the triplet parser again, but this time, fp->rate_table is
	 * allocated, so the rates will be stored */
377
	parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
Daniel Mack's avatar
Daniel Mack committed
378
379
380
381
382
383
384
385
386
387
388

err_free:
	kfree(data);
err:
	return ret;
}

/*
 * parse the format type I and III descriptors
 */
static int parse_audio_format_i(struct snd_usb_audio *chip,
389
390
				struct audioformat *fp, u64 format,
				void *_fmt)
Daniel Mack's avatar
Daniel Mack committed
391
{
392
	snd_pcm_format_t pcm_format;
393
	unsigned int fmt_type;
394
	int ret;
Daniel Mack's avatar
Daniel Mack committed
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
	switch (fp->protocol) {
	default:
	case UAC_VERSION_1:
	case UAC_VERSION_2: {
		struct uac_format_type_i_continuous_descriptor *fmt = _fmt;

		fmt_type = fmt->bFormatType;
		break;
	}
	case UAC_VERSION_3: {
		/* fp->fmt_type is already set in this case */
		fmt_type = fp->fmt_type;
		break;
	}
	}

	if (fmt_type == UAC_FORMAT_TYPE_III) {
Daniel Mack's avatar
Daniel Mack committed
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
		/* FIXME: the format type is really IECxxx
		 *        but we give normal PCM format to get the existing
		 *        apps working...
		 */
		switch (chip->usb_id) {

		case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
			if (chip->setup == 0x00 && 
			    fp->altsetting == 6)
				pcm_format = SNDRV_PCM_FORMAT_S16_BE;
			else
				pcm_format = SNDRV_PCM_FORMAT_S16_LE;
			break;
		default:
			pcm_format = SNDRV_PCM_FORMAT_S16_LE;
		}
429
		fp->formats = pcm_format_to_bits(pcm_format);
Daniel Mack's avatar
Daniel Mack committed
430
	} else {
431
		fp->formats = parse_audio_format_i_type(chip, fp, format, _fmt);
432
		if (!fp->formats)
433
			return -EINVAL;
Daniel Mack's avatar
Daniel Mack committed
434
435
436
437
438
439
440
	}

	/* gather possible sample rates */
	/* audio class v1 reports possible sample rates as part of the
	 * proprietary class specific descriptor.
	 * audio class v2 uses class specific EP0 range requests for that.
	 */
441
	switch (fp->protocol) {
442
	default:
443
444
445
	case UAC_VERSION_1: {
		struct uac_format_type_i_continuous_descriptor *fmt = _fmt;

Daniel Mack's avatar
Daniel Mack committed
446
		fp->channels = fmt->bNrChannels;
447
		ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7);
Daniel Mack's avatar
Daniel Mack committed
448
		break;
449
	}
Daniel Mack's avatar
Daniel Mack committed
450
	case UAC_VERSION_2:
451
	case UAC_VERSION_3: {
Daniel Mack's avatar
Daniel Mack committed
452
		/* fp->channels is already set in this case */
453
		ret = parse_audio_format_rates_v2v3(chip, fp);
Daniel Mack's avatar
Daniel Mack committed
454
455
		break;
	}
456
	}
Daniel Mack's avatar
Daniel Mack committed
457
458

	if (fp->channels < 1) {
459
460
461
		usb_audio_err(chip,
			"%u:%d : invalid channels %d\n",
			fp->iface, fp->altsetting, fp->channels);
462
		return -EINVAL;
Daniel Mack's avatar
Daniel Mack committed
463
464
465
466
467
468
469
470
471
472
	}

	return ret;
}

/*
 * parse the format type II descriptor
 */
static int parse_audio_format_ii(struct snd_usb_audio *chip,
				 struct audioformat *fp,
473
				 u64 format, void *_fmt)
Daniel Mack's avatar
Daniel Mack committed
474
475
476
477
478
479
{
	int brate, framesize, ret;

	switch (format) {
	case UAC_FORMAT_TYPE_II_AC3:
		/* FIXME: there is no AC3 format defined yet */
480
481
		// fp->formats = SNDRV_PCM_FMTBIT_AC3;
		fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */
Daniel Mack's avatar
Daniel Mack committed
482
483
		break;
	case UAC_FORMAT_TYPE_II_MPEG:
484
		fp->formats = SNDRV_PCM_FMTBIT_MPEG;
Daniel Mack's avatar
Daniel Mack committed
485
486
		break;
	default:
487
		usb_audio_info(chip,
488
			 "%u:%d : unknown format tag %#llx is detected.  processed as MPEG.\n",
489
			 fp->iface, fp->altsetting, format);
490
		fp->formats = SNDRV_PCM_FMTBIT_MPEG;
Daniel Mack's avatar
Daniel Mack committed
491
492
493
494
495
		break;
	}

	fp->channels = 1;

496
	switch (fp->protocol) {
497
	default:
Daniel Mack's avatar
Daniel Mack committed
498
499
500
501
	case UAC_VERSION_1: {
		struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
		brate = le16_to_cpu(fmt->wMaxBitRate);
		framesize = le16_to_cpu(fmt->wSamplesPerFrame);
502
		usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
Daniel Mack's avatar
Daniel Mack committed
503
504
505
506
507
508
509
510
		fp->frame_size = framesize;
		ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
		break;
	}
	case UAC_VERSION_2: {
		struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
		brate = le16_to_cpu(fmt->wMaxBitRate);
		framesize = le16_to_cpu(fmt->wSamplesPerFrame);
511
		usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
Daniel Mack's avatar
Daniel Mack committed
512
		fp->frame_size = framesize;
513
		ret = parse_audio_format_rates_v2v3(chip, fp);
Daniel Mack's avatar
Daniel Mack committed
514
515
516
517
518
519
520
		break;
	}
	}

	return ret;
}

521
int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
522
			       struct audioformat *fp, u64 format,
523
			       struct uac_format_type_i_continuous_descriptor *fmt,
524
			       int stream)
Daniel Mack's avatar
Daniel Mack committed
525
526
527
{
	int err;

528
	switch (fmt->bFormatType) {
Daniel Mack's avatar
Daniel Mack committed
529
530
	case UAC_FORMAT_TYPE_I:
	case UAC_FORMAT_TYPE_III:
531
		err = parse_audio_format_i(chip, fp, format, fmt);
Daniel Mack's avatar
Daniel Mack committed
532
533
		break;
	case UAC_FORMAT_TYPE_II:
534
		err = parse_audio_format_ii(chip, fp, format, fmt);
Daniel Mack's avatar
Daniel Mack committed
535
536
		break;
	default:
537
538
539
540
		usb_audio_info(chip,
			 "%u:%d : format type %d is not supported yet\n",
			 fp->iface, fp->altsetting,
			 fmt->bFormatType);
541
		return -ENOTSUPP;
Daniel Mack's avatar
Daniel Mack committed
542
	}
543
	fp->fmt_type = fmt->bFormatType;
Daniel Mack's avatar
Daniel Mack committed
544
545
546
547
548
549
550
551
552
553
	if (err < 0)
		return err;
#if 1
	/* FIXME: temporary hack for extigy/audigy 2 nx/zs */
	/* extigy apparently supports sample rates other than 48k
	 * but not in ordinary way.  so we enable only 48k atm.
	 */
	if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
	    chip->usb_id == USB_ID(0x041e, 0x3020) ||
	    chip->usb_id == USB_ID(0x041e, 0x3061)) {
554
		if (fmt->bFormatType == UAC_FORMAT_TYPE_I &&
Daniel Mack's avatar
Daniel Mack committed
555
556
		    fp->rates != SNDRV_PCM_RATE_48000 &&
		    fp->rates != SNDRV_PCM_RATE_96000)
557
			return -ENOTSUPP;
Daniel Mack's avatar
Daniel Mack committed
558
559
560
561
562
	}
#endif
	return 0;
}

563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
int snd_usb_parse_audio_format_v3(struct snd_usb_audio *chip,
			       struct audioformat *fp,
			       struct uac3_as_header_descriptor *as,
			       int stream)
{
	u64 format = le64_to_cpu(as->bmFormats);
	int err;

	/*
	 * Type I format bits are D0..D6
	 * This test works because type IV is not supported
	 */
	if (format & 0x7f)
		fp->fmt_type = UAC_FORMAT_TYPE_I;
	else
		fp->fmt_type = UAC_FORMAT_TYPE_III;

	err = parse_audio_format_i(chip, fp, format, as);
	if (err < 0)
		return err;

	return 0;
}