format.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  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. */
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/usb.h>
  20. #include <linux/usb/audio.h>
  21. #include <linux/usb/audio-v2.h>
  22. #include <linux/usb/audio-v3.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include "usbaudio.h"
  26. #include "card.h"
  27. #include "quirks.h"
  28. #include "helper.h"
  29. #include "debug.h"
  30. #include "clock.h"
  31. #include "format.h"
  32. /*
  33. * parse the audio format type I descriptor
  34. * and returns the corresponding pcm format
  35. *
  36. * @dev: usb device
  37. * @fp: audioformat record
  38. * @format: the format tag (wFormatTag)
  39. * @fmt: the format type descriptor (v1/v2) or AudioStreaming descriptor (v3)
  40. */
  41. static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
  42. struct audioformat *fp,
  43. u64 format, void *_fmt)
  44. {
  45. int sample_width, sample_bytes;
  46. u64 pcm_formats = 0;
  47. switch (fp->protocol) {
  48. case UAC_VERSION_1:
  49. default: {
  50. struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
  51. if (format >= 64)
  52. return 0; /* invalid format */
  53. sample_width = fmt->bBitResolution;
  54. sample_bytes = fmt->bSubframeSize;
  55. format = 1ULL << format;
  56. break;
  57. }
  58. case UAC_VERSION_2: {
  59. struct uac_format_type_i_ext_descriptor *fmt = _fmt;
  60. sample_width = fmt->bBitResolution;
  61. sample_bytes = fmt->bSubslotSize;
  62. if (format & UAC2_FORMAT_TYPE_I_RAW_DATA) {
  63. pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
  64. /* flag potentially raw DSD capable altsettings */
  65. fp->dsd_raw = true;
  66. }
  67. format <<= 1;
  68. break;
  69. }
  70. case UAC_VERSION_3: {
  71. struct uac3_as_header_descriptor *as = _fmt;
  72. sample_width = as->bBitResolution;
  73. sample_bytes = as->bSubslotSize;
  74. if (format & UAC3_FORMAT_TYPE_I_RAW_DATA)
  75. pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
  76. format <<= 1;
  77. break;
  78. }
  79. }
  80. if ((pcm_formats == 0) &&
  81. (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
  82. /* some devices don't define this correctly... */
  83. usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
  84. fp->iface, fp->altsetting);
  85. format = 1 << UAC_FORMAT_TYPE_I_PCM;
  86. }
  87. if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
  88. if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
  89. /* Edirol SD-90 */
  90. (chip->usb_id == USB_ID(0x0582, 0x000c))) &&
  91. /* Roland SC-D70 */
  92. sample_width == 24 && sample_bytes == 2)
  93. sample_bytes = 3;
  94. else if (sample_width > sample_bytes * 8) {
  95. usb_audio_info(chip, "%u:%d : sample bitwidth %d in over sample bytes %d\n",
  96. fp->iface, fp->altsetting,
  97. sample_width, sample_bytes);
  98. }
  99. /* check the format byte size */
  100. switch (sample_bytes) {
  101. case 1:
  102. pcm_formats |= SNDRV_PCM_FMTBIT_S8;
  103. break;
  104. case 2:
  105. if (snd_usb_is_big_endian_format(chip, fp))
  106. pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */
  107. else
  108. pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE;
  109. break;
  110. case 3:
  111. if (snd_usb_is_big_endian_format(chip, fp))
  112. pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */
  113. else
  114. pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE;
  115. break;
  116. case 4:
  117. pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE;
  118. break;
  119. default:
  120. usb_audio_info(chip,
  121. "%u:%d : unsupported sample bitwidth %d in %d bytes\n",
  122. fp->iface, fp->altsetting,
  123. sample_width, sample_bytes);
  124. break;
  125. }
  126. }
  127. if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
  128. /* Dallas DS4201 workaround: it advertises U8 format, but really
  129. supports S8. */
  130. if (chip->usb_id == USB_ID(0x04fa, 0x4201))
  131. pcm_formats |= SNDRV_PCM_FMTBIT_S8;
  132. else
  133. pcm_formats |= SNDRV_PCM_FMTBIT_U8;
  134. }
  135. if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
  136. pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
  137. }
  138. if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
  139. pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
  140. }
  141. if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
  142. pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
  143. }
  144. if (format & ~0x3f) {
  145. usb_audio_info(chip,
  146. "%u:%d : unsupported format bits %#llx\n",
  147. fp->iface, fp->altsetting, format);
  148. }
  149. pcm_formats |= snd_usb_interface_dsd_format_quirks(chip, fp, sample_bytes);
  150. return pcm_formats;
  151. }
  152. /*
  153. * parse the format descriptor and stores the possible sample rates
  154. * on the audioformat table (audio class v1).
  155. *
  156. * @dev: usb device
  157. * @fp: audioformat record
  158. * @fmt: the format descriptor
  159. * @offset: the start offset of descriptor pointing the rate type
  160. * (7 for type I and II, 8 for type II)
  161. */
  162. static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
  163. unsigned char *fmt, int offset)
  164. {
  165. int nr_rates = fmt[offset];
  166. if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
  167. usb_audio_err(chip,
  168. "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
  169. fp->iface, fp->altsetting);
  170. return -EINVAL;
  171. }
  172. if (nr_rates) {
  173. /*
  174. * build the rate table and bitmap flags
  175. */
  176. int r, idx;
  177. fp->rate_table = kmalloc_array(nr_rates, sizeof(int),
  178. GFP_KERNEL);
  179. if (fp->rate_table == NULL)
  180. return -ENOMEM;
  181. fp->nr_rates = 0;
  182. fp->rate_min = fp->rate_max = 0;
  183. for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
  184. unsigned int rate = combine_triple(&fmt[idx]);
  185. if (!rate)
  186. continue;
  187. /* C-Media CM6501 mislabels its 96 kHz altsetting */
  188. /* Terratec Aureon 7.1 USB C-Media 6206, too */
  189. if (rate == 48000 && nr_rates == 1 &&
  190. (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
  191. chip->usb_id == USB_ID(0x0d8c, 0x0102) ||
  192. chip->usb_id == USB_ID(0x0ccd, 0x00b1)) &&
  193. fp->altsetting == 5 && fp->maxpacksize == 392)
  194. rate = 96000;
  195. /* Creative VF0420/VF0470 Live Cams report 16 kHz instead of 8kHz */
  196. if (rate == 16000 &&
  197. (chip->usb_id == USB_ID(0x041e, 0x4064) ||
  198. chip->usb_id == USB_ID(0x041e, 0x4068)))
  199. rate = 8000;
  200. fp->rate_table[fp->nr_rates] = rate;
  201. if (!fp->rate_min || rate < fp->rate_min)
  202. fp->rate_min = rate;
  203. if (!fp->rate_max || rate > fp->rate_max)
  204. fp->rate_max = rate;
  205. fp->rates |= snd_pcm_rate_to_rate_bit(rate);
  206. fp->nr_rates++;
  207. }
  208. if (!fp->nr_rates) {
  209. hwc_debug("All rates were zero. Skipping format!\n");
  210. return -EINVAL;
  211. }
  212. } else {
  213. /* continuous rates */
  214. fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
  215. fp->rate_min = combine_triple(&fmt[offset + 1]);
  216. fp->rate_max = combine_triple(&fmt[offset + 4]);
  217. }
  218. return 0;
  219. }
  220. /*
  221. * Many Focusrite devices supports a limited set of sampling rates per
  222. * altsetting. Maximum rate is exposed in the last 4 bytes of Format Type
  223. * descriptor which has a non-standard bLength = 10.
  224. */
  225. static bool focusrite_valid_sample_rate(struct snd_usb_audio *chip,
  226. struct audioformat *fp,
  227. unsigned int rate)
  228. {
  229. struct usb_interface *iface;
  230. struct usb_host_interface *alts;
  231. unsigned char *fmt;
  232. unsigned int max_rate;
  233. iface = usb_ifnum_to_if(chip->dev, fp->iface);
  234. if (!iface)
  235. return true;
  236. alts = &iface->altsetting[fp->altset_idx];
  237. fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen,
  238. NULL, UAC_FORMAT_TYPE);
  239. if (!fmt)
  240. return true;
  241. if (fmt[0] == 10) { /* bLength */
  242. max_rate = combine_quad(&fmt[6]);
  243. /* Validate max rate */
  244. if (max_rate != 48000 &&
  245. max_rate != 96000 &&
  246. max_rate != 192000 &&
  247. max_rate != 384000) {
  248. usb_audio_info(chip,
  249. "%u:%d : unexpected max rate: %u\n",
  250. fp->iface, fp->altsetting, max_rate);
  251. return true;
  252. }
  253. return rate <= max_rate;
  254. }
  255. return true;
  256. }
  257. /*
  258. * Helper function to walk the array of sample rate triplets reported by
  259. * the device. The problem is that we need to parse whole array first to
  260. * get to know how many sample rates we have to expect.
  261. * Then fp->rate_table can be allocated and filled.
  262. */
  263. static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
  264. struct audioformat *fp, int nr_triplets,
  265. const unsigned char *data)
  266. {
  267. int i, nr_rates = 0;
  268. fp->rates = fp->rate_min = fp->rate_max = 0;
  269. for (i = 0; i < nr_triplets; i++) {
  270. int min = combine_quad(&data[2 + 12 * i]);
  271. int max = combine_quad(&data[6 + 12 * i]);
  272. int res = combine_quad(&data[10 + 12 * i]);
  273. unsigned int rate;
  274. if ((max < 0) || (min < 0) || (res < 0) || (max < min))
  275. continue;
  276. /*
  277. * for ranges with res == 1, we announce a continuous sample
  278. * rate range, and this function should return 0 for no further
  279. * parsing.
  280. */
  281. if (res == 1) {
  282. fp->rate_min = min;
  283. fp->rate_max = max;
  284. fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
  285. return 0;
  286. }
  287. for (rate = min; rate <= max; rate += res) {
  288. /* Filter out invalid rates on Focusrite devices */
  289. if (USB_ID_VENDOR(chip->usb_id) == 0x1235 &&
  290. !focusrite_valid_sample_rate(chip, fp, rate))
  291. goto skip_rate;
  292. if (fp->rate_table)
  293. fp->rate_table[nr_rates] = rate;
  294. if (!fp->rate_min || rate < fp->rate_min)
  295. fp->rate_min = rate;
  296. if (!fp->rate_max || rate > fp->rate_max)
  297. fp->rate_max = rate;
  298. fp->rates |= snd_pcm_rate_to_rate_bit(rate);
  299. nr_rates++;
  300. if (nr_rates >= MAX_NR_RATES) {
  301. usb_audio_err(chip, "invalid uac2 rates\n");
  302. break;
  303. }
  304. skip_rate:
  305. /* avoid endless loop */
  306. if (res == 0)
  307. break;
  308. }
  309. }
  310. return nr_rates;
  311. }
  312. /*
  313. * parse the format descriptor and stores the possible sample rates
  314. * on the audioformat table (audio class v2 and v3).
  315. */
  316. static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip,
  317. struct audioformat *fp)
  318. {
  319. struct usb_device *dev = chip->dev;
  320. unsigned char tmp[2], *data;
  321. int nr_triplets, data_size, ret = 0;
  322. int clock = snd_usb_clock_find_source(chip, fp, false);
  323. if (clock < 0) {
  324. dev_err(&dev->dev,
  325. "%s(): unable to find clock source (clock %d)\n",
  326. __func__, clock);
  327. goto err;
  328. }
  329. /* get the number of sample rates first by only fetching 2 bytes */
  330. ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
  331. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
  332. UAC2_CS_CONTROL_SAM_FREQ << 8,
  333. snd_usb_ctrl_intf(chip) | (clock << 8),
  334. tmp, sizeof(tmp));
  335. if (ret < 0) {
  336. dev_err(&dev->dev,
  337. "%s(): unable to retrieve number of sample rates (clock %d)\n",
  338. __func__, clock);
  339. goto err;
  340. }
  341. nr_triplets = (tmp[1] << 8) | tmp[0];
  342. data_size = 2 + 12 * nr_triplets;
  343. data = kzalloc(data_size, GFP_KERNEL);
  344. if (!data) {
  345. ret = -ENOMEM;
  346. goto err;
  347. }
  348. /* now get the full information */
  349. ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
  350. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
  351. UAC2_CS_CONTROL_SAM_FREQ << 8,
  352. snd_usb_ctrl_intf(chip) | (clock << 8),
  353. data, data_size);
  354. if (ret < 0) {
  355. dev_err(&dev->dev,
  356. "%s(): unable to retrieve sample rate range (clock %d)\n",
  357. __func__, clock);
  358. ret = -EINVAL;
  359. goto err_free;
  360. }
  361. /* Call the triplet parser, and make sure fp->rate_table is NULL.
  362. * We just use the return value to know how many sample rates we
  363. * will have to deal with. */
  364. kfree(fp->rate_table);
  365. fp->rate_table = NULL;
  366. fp->nr_rates = parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
  367. if (fp->nr_rates == 0) {
  368. /* SNDRV_PCM_RATE_CONTINUOUS */
  369. ret = 0;
  370. goto err_free;
  371. }
  372. fp->rate_table = kmalloc_array(fp->nr_rates, sizeof(int), GFP_KERNEL);
  373. if (!fp->rate_table) {
  374. ret = -ENOMEM;
  375. goto err_free;
  376. }
  377. /* Call the triplet parser again, but this time, fp->rate_table is
  378. * allocated, so the rates will be stored */
  379. parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
  380. err_free:
  381. kfree(data);
  382. err:
  383. return ret;
  384. }
  385. /*
  386. * parse the format type I and III descriptors
  387. */
  388. static int parse_audio_format_i(struct snd_usb_audio *chip,
  389. struct audioformat *fp, u64 format,
  390. void *_fmt)
  391. {
  392. snd_pcm_format_t pcm_format;
  393. unsigned int fmt_type;
  394. int ret;
  395. switch (fp->protocol) {
  396. default:
  397. case UAC_VERSION_1:
  398. case UAC_VERSION_2: {
  399. struct uac_format_type_i_continuous_descriptor *fmt = _fmt;
  400. fmt_type = fmt->bFormatType;
  401. break;
  402. }
  403. case UAC_VERSION_3: {
  404. /* fp->fmt_type is already set in this case */
  405. fmt_type = fp->fmt_type;
  406. break;
  407. }
  408. }
  409. if (fmt_type == UAC_FORMAT_TYPE_III) {
  410. /* FIXME: the format type is really IECxxx
  411. * but we give normal PCM format to get the existing
  412. * apps working...
  413. */
  414. switch (chip->usb_id) {
  415. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  416. if (chip->setup == 0x00 &&
  417. fp->altsetting == 6)
  418. pcm_format = SNDRV_PCM_FORMAT_S16_BE;
  419. else
  420. pcm_format = SNDRV_PCM_FORMAT_S16_LE;
  421. break;
  422. default:
  423. pcm_format = SNDRV_PCM_FORMAT_S16_LE;
  424. }
  425. fp->formats = pcm_format_to_bits(pcm_format);
  426. } else {
  427. fp->formats = parse_audio_format_i_type(chip, fp, format, _fmt);
  428. if (!fp->formats)
  429. return -EINVAL;
  430. }
  431. /* gather possible sample rates */
  432. /* audio class v1 reports possible sample rates as part of the
  433. * proprietary class specific descriptor.
  434. * audio class v2 uses class specific EP0 range requests for that.
  435. */
  436. switch (fp->protocol) {
  437. default:
  438. case UAC_VERSION_1: {
  439. struct uac_format_type_i_continuous_descriptor *fmt = _fmt;
  440. fp->channels = fmt->bNrChannels;
  441. ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7);
  442. break;
  443. }
  444. case UAC_VERSION_2:
  445. case UAC_VERSION_3: {
  446. /* fp->channels is already set in this case */
  447. ret = parse_audio_format_rates_v2v3(chip, fp);
  448. break;
  449. }
  450. }
  451. if (fp->channels < 1) {
  452. usb_audio_err(chip,
  453. "%u:%d : invalid channels %d\n",
  454. fp->iface, fp->altsetting, fp->channels);
  455. return -EINVAL;
  456. }
  457. return ret;
  458. }
  459. /*
  460. * parse the format type II descriptor
  461. */
  462. static int parse_audio_format_ii(struct snd_usb_audio *chip,
  463. struct audioformat *fp,
  464. u64 format, void *_fmt)
  465. {
  466. int brate, framesize, ret;
  467. switch (format) {
  468. case UAC_FORMAT_TYPE_II_AC3:
  469. /* FIXME: there is no AC3 format defined yet */
  470. // fp->formats = SNDRV_PCM_FMTBIT_AC3;
  471. fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */
  472. break;
  473. case UAC_FORMAT_TYPE_II_MPEG:
  474. fp->formats = SNDRV_PCM_FMTBIT_MPEG;
  475. break;
  476. default:
  477. usb_audio_info(chip,
  478. "%u:%d : unknown format tag %#llx is detected. processed as MPEG.\n",
  479. fp->iface, fp->altsetting, format);
  480. fp->formats = SNDRV_PCM_FMTBIT_MPEG;
  481. break;
  482. }
  483. fp->channels = 1;
  484. switch (fp->protocol) {
  485. default:
  486. case UAC_VERSION_1: {
  487. struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
  488. brate = le16_to_cpu(fmt->wMaxBitRate);
  489. framesize = le16_to_cpu(fmt->wSamplesPerFrame);
  490. usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
  491. fp->frame_size = framesize;
  492. ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
  493. break;
  494. }
  495. case UAC_VERSION_2: {
  496. struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
  497. brate = le16_to_cpu(fmt->wMaxBitRate);
  498. framesize = le16_to_cpu(fmt->wSamplesPerFrame);
  499. usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
  500. fp->frame_size = framesize;
  501. ret = parse_audio_format_rates_v2v3(chip, fp);
  502. break;
  503. }
  504. }
  505. return ret;
  506. }
  507. int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
  508. struct audioformat *fp, u64 format,
  509. struct uac_format_type_i_continuous_descriptor *fmt,
  510. int stream)
  511. {
  512. int err;
  513. switch (fmt->bFormatType) {
  514. case UAC_FORMAT_TYPE_I:
  515. case UAC_FORMAT_TYPE_III:
  516. err = parse_audio_format_i(chip, fp, format, fmt);
  517. break;
  518. case UAC_FORMAT_TYPE_II:
  519. err = parse_audio_format_ii(chip, fp, format, fmt);
  520. break;
  521. default:
  522. usb_audio_info(chip,
  523. "%u:%d : format type %d is not supported yet\n",
  524. fp->iface, fp->altsetting,
  525. fmt->bFormatType);
  526. return -ENOTSUPP;
  527. }
  528. fp->fmt_type = fmt->bFormatType;
  529. if (err < 0)
  530. return err;
  531. #if 1
  532. /* FIXME: temporary hack for extigy/audigy 2 nx/zs */
  533. /* extigy apparently supports sample rates other than 48k
  534. * but not in ordinary way. so we enable only 48k atm.
  535. */
  536. if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
  537. chip->usb_id == USB_ID(0x041e, 0x3020) ||
  538. chip->usb_id == USB_ID(0x041e, 0x3061)) {
  539. if (fmt->bFormatType == UAC_FORMAT_TYPE_I &&
  540. fp->rates != SNDRV_PCM_RATE_48000 &&
  541. fp->rates != SNDRV_PCM_RATE_96000)
  542. return -ENOTSUPP;
  543. }
  544. #endif
  545. return 0;
  546. }
  547. int snd_usb_parse_audio_format_v3(struct snd_usb_audio *chip,
  548. struct audioformat *fp,
  549. struct uac3_as_header_descriptor *as,
  550. int stream)
  551. {
  552. u64 format = le64_to_cpu(as->bmFormats);
  553. int err;
  554. /*
  555. * Type I format bits are D0..D6
  556. * This test works because type IV is not supported
  557. */
  558. if (format & 0x7f)
  559. fp->fmt_type = UAC_FORMAT_TYPE_I;
  560. else
  561. fp->fmt_type = UAC_FORMAT_TYPE_III;
  562. err = parse_audio_format_i(chip, fp, format, as);
  563. if (err < 0)
  564. return err;
  565. return 0;
  566. }