1e5779998SDaniel Mack /* 2e5779998SDaniel Mack * This program is free software; you can redistribute it and/or modify 3e5779998SDaniel Mack * it under the terms of the GNU General Public License as published by 4e5779998SDaniel Mack * the Free Software Foundation; either version 2 of the License, or 5e5779998SDaniel Mack * (at your option) any later version. 6e5779998SDaniel Mack * 7e5779998SDaniel Mack * This program is distributed in the hope that it will be useful, 8e5779998SDaniel Mack * but WITHOUT ANY WARRANTY; without even the implied warranty of 9e5779998SDaniel Mack * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10e5779998SDaniel Mack * GNU General Public License for more details. 11e5779998SDaniel Mack * 12e5779998SDaniel Mack * You should have received a copy of the GNU General Public License 13e5779998SDaniel Mack * along with this program; if not, write to the Free Software 14e5779998SDaniel Mack * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15e5779998SDaniel Mack * 16e5779998SDaniel Mack */ 17e5779998SDaniel Mack 18e5779998SDaniel Mack #include <linux/init.h> 1936db0456SStephen Rothwell #include <linux/slab.h> 20e5779998SDaniel Mack #include <linux/usb.h> 21e5779998SDaniel Mack #include <linux/usb/audio.h> 227e847894SDaniel Mack #include <linux/usb/audio-v2.h> 23e5779998SDaniel Mack 24e5779998SDaniel Mack #include <sound/core.h> 25e5779998SDaniel Mack #include <sound/pcm.h> 26e5779998SDaniel Mack 27e5779998SDaniel Mack #include "usbaudio.h" 28e5779998SDaniel Mack #include "card.h" 29e5779998SDaniel Mack #include "quirks.h" 30e5779998SDaniel Mack #include "helper.h" 31e5779998SDaniel Mack #include "debug.h" 32e5779998SDaniel Mack 33e5779998SDaniel Mack /* 34e5779998SDaniel Mack * parse the audio format type I descriptor 35e5779998SDaniel Mack * and returns the corresponding pcm format 36e5779998SDaniel Mack * 37e5779998SDaniel Mack * @dev: usb device 38e5779998SDaniel Mack * @fp: audioformat record 39e5779998SDaniel Mack * @format: the format tag (wFormatTag) 40e5779998SDaniel Mack * @fmt: the format type descriptor 41e5779998SDaniel Mack */ 4229088fefSClemens Ladisch static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, 43e5779998SDaniel Mack struct audioformat *fp, 44e5779998SDaniel Mack int format, void *_fmt, 45e5779998SDaniel Mack int protocol) 46e5779998SDaniel Mack { 47e5779998SDaniel Mack int sample_width, sample_bytes; 4829088fefSClemens Ladisch u64 pcm_formats; 49e5779998SDaniel Mack 50e5779998SDaniel Mack switch (protocol) { 51e5779998SDaniel Mack case UAC_VERSION_1: { 52e5779998SDaniel Mack struct uac_format_type_i_discrete_descriptor *fmt = _fmt; 53e5779998SDaniel Mack sample_width = fmt->bBitResolution; 54e5779998SDaniel Mack sample_bytes = fmt->bSubframeSize; 5529088fefSClemens Ladisch format = 1 << format; 56e5779998SDaniel Mack break; 57e5779998SDaniel Mack } 58e5779998SDaniel Mack 59e5779998SDaniel Mack case UAC_VERSION_2: { 60e5779998SDaniel Mack struct uac_format_type_i_ext_descriptor *fmt = _fmt; 61e5779998SDaniel Mack sample_width = fmt->bBitResolution; 62e5779998SDaniel Mack sample_bytes = fmt->bSubslotSize; 6329088fefSClemens Ladisch format <<= 1; 64e5779998SDaniel Mack break; 65e5779998SDaniel Mack } 66e5779998SDaniel Mack 67e5779998SDaniel Mack default: 68e5779998SDaniel Mack return -EINVAL; 69e5779998SDaniel Mack } 70e5779998SDaniel Mack 7129088fefSClemens Ladisch pcm_formats = 0; 72e5779998SDaniel Mack 7329088fefSClemens Ladisch if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) { 7429088fefSClemens Ladisch /* some devices don't define this correctly... */ 75e5779998SDaniel Mack snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", 76e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting); 7729088fefSClemens Ladisch format = 1 << UAC_FORMAT_TYPE_I_PCM; 7829088fefSClemens Ladisch } 7929088fefSClemens Ladisch if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 80e5779998SDaniel Mack if (sample_width > sample_bytes * 8) { 81e5779998SDaniel Mack snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 82e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting, 83e5779998SDaniel Mack sample_width, sample_bytes); 84e5779998SDaniel Mack } 85e5779998SDaniel Mack /* check the format byte size */ 86e5779998SDaniel Mack switch (sample_bytes) { 87e5779998SDaniel Mack case 1: 8829088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S8; 89e5779998SDaniel Mack break; 90e5779998SDaniel Mack case 2: 91e5779998SDaniel Mack if (snd_usb_is_big_endian_format(chip, fp)) 9229088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */ 93e5779998SDaniel Mack else 9429088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE; 95e5779998SDaniel Mack break; 96e5779998SDaniel Mack case 3: 97e5779998SDaniel Mack if (snd_usb_is_big_endian_format(chip, fp)) 9829088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */ 99e5779998SDaniel Mack else 10029088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE; 101e5779998SDaniel Mack break; 102e5779998SDaniel Mack case 4: 10329088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE; 104e5779998SDaniel Mack break; 105e5779998SDaniel Mack default: 106e5779998SDaniel Mack snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", 107e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting, 108e5779998SDaniel Mack sample_width, sample_bytes); 109e5779998SDaniel Mack break; 110e5779998SDaniel Mack } 11129088fefSClemens Ladisch } 11229088fefSClemens Ladisch if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) { 113e5779998SDaniel Mack /* Dallas DS4201 workaround: it advertises U8 format, but really 114e5779998SDaniel Mack supports S8. */ 115e5779998SDaniel Mack if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 11629088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_S8; 11729088fefSClemens Ladisch else 11829088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_U8; 119e5779998SDaniel Mack } 12029088fefSClemens Ladisch if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) { 12129088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 12229088fefSClemens Ladisch } 12329088fefSClemens Ladisch if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) { 12429088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW; 12529088fefSClemens Ladisch } 12629088fefSClemens Ladisch if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) { 12729088fefSClemens Ladisch pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW; 12829088fefSClemens Ladisch } 12929088fefSClemens Ladisch if (format & ~0x3f) { 13029088fefSClemens Ladisch snd_printk(KERN_INFO "%d:%u:%d : unsupported format bits %#x\n", 13129088fefSClemens Ladisch chip->dev->devnum, fp->iface, fp->altsetting, format); 13229088fefSClemens Ladisch } 13329088fefSClemens Ladisch return pcm_formats; 134e5779998SDaniel Mack } 135e5779998SDaniel Mack 136e5779998SDaniel Mack 137e5779998SDaniel Mack /* 138e5779998SDaniel Mack * parse the format descriptor and stores the possible sample rates 139e5779998SDaniel Mack * on the audioformat table (audio class v1). 140e5779998SDaniel Mack * 141e5779998SDaniel Mack * @dev: usb device 142e5779998SDaniel Mack * @fp: audioformat record 143e5779998SDaniel Mack * @fmt: the format descriptor 144e5779998SDaniel Mack * @offset: the start offset of descriptor pointing the rate type 145e5779998SDaniel Mack * (7 for type I and II, 8 for type II) 146e5779998SDaniel Mack */ 147e5779998SDaniel Mack static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp, 148e5779998SDaniel Mack unsigned char *fmt, int offset) 149e5779998SDaniel Mack { 150e5779998SDaniel Mack int nr_rates = fmt[offset]; 151e5779998SDaniel Mack 152e5779998SDaniel Mack if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { 153e5779998SDaniel Mack snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", 154e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting); 155e5779998SDaniel Mack return -1; 156e5779998SDaniel Mack } 157e5779998SDaniel Mack 158e5779998SDaniel Mack if (nr_rates) { 159e5779998SDaniel Mack /* 160e5779998SDaniel Mack * build the rate table and bitmap flags 161e5779998SDaniel Mack */ 162e5779998SDaniel Mack int r, idx; 163e5779998SDaniel Mack 164e5779998SDaniel Mack fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 165e5779998SDaniel Mack if (fp->rate_table == NULL) { 166e5779998SDaniel Mack snd_printk(KERN_ERR "cannot malloc\n"); 167e5779998SDaniel Mack return -1; 168e5779998SDaniel Mack } 169e5779998SDaniel Mack 170e5779998SDaniel Mack fp->nr_rates = 0; 171e5779998SDaniel Mack fp->rate_min = fp->rate_max = 0; 172e5779998SDaniel Mack for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) { 173e5779998SDaniel Mack unsigned int rate = combine_triple(&fmt[idx]); 174e5779998SDaniel Mack if (!rate) 175e5779998SDaniel Mack continue; 176e5779998SDaniel Mack /* C-Media CM6501 mislabels its 96 kHz altsetting */ 177e5779998SDaniel Mack if (rate == 48000 && nr_rates == 1 && 178e5779998SDaniel Mack (chip->usb_id == USB_ID(0x0d8c, 0x0201) || 179e5779998SDaniel Mack chip->usb_id == USB_ID(0x0d8c, 0x0102)) && 180e5779998SDaniel Mack fp->altsetting == 5 && fp->maxpacksize == 392) 181e5779998SDaniel Mack rate = 96000; 182e5779998SDaniel Mack /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */ 183e5779998SDaniel Mack if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068)) 184e5779998SDaniel Mack rate = 8000; 185e5779998SDaniel Mack 186e5779998SDaniel Mack fp->rate_table[fp->nr_rates] = rate; 187e5779998SDaniel Mack if (!fp->rate_min || rate < fp->rate_min) 188e5779998SDaniel Mack fp->rate_min = rate; 189e5779998SDaniel Mack if (!fp->rate_max || rate > fp->rate_max) 190e5779998SDaniel Mack fp->rate_max = rate; 191e5779998SDaniel Mack fp->rates |= snd_pcm_rate_to_rate_bit(rate); 192e5779998SDaniel Mack fp->nr_rates++; 193e5779998SDaniel Mack } 194e5779998SDaniel Mack if (!fp->nr_rates) { 195e5779998SDaniel Mack hwc_debug("All rates were zero. Skipping format!\n"); 196e5779998SDaniel Mack return -1; 197e5779998SDaniel Mack } 198e5779998SDaniel Mack } else { 199e5779998SDaniel Mack /* continuous rates */ 200e5779998SDaniel Mack fp->rates = SNDRV_PCM_RATE_CONTINUOUS; 201e5779998SDaniel Mack fp->rate_min = combine_triple(&fmt[offset + 1]); 202e5779998SDaniel Mack fp->rate_max = combine_triple(&fmt[offset + 4]); 203e5779998SDaniel Mack } 204e5779998SDaniel Mack return 0; 205e5779998SDaniel Mack } 206e5779998SDaniel Mack 207e5779998SDaniel Mack /* 208e5779998SDaniel Mack * parse the format descriptor and stores the possible sample rates 209e5779998SDaniel Mack * on the audioformat table (audio class v2). 210e5779998SDaniel Mack */ 211e5779998SDaniel Mack static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, 212e5779998SDaniel Mack struct audioformat *fp, 213e5779998SDaniel Mack struct usb_host_interface *iface) 214e5779998SDaniel Mack { 215e5779998SDaniel Mack struct usb_device *dev = chip->dev; 216e5779998SDaniel Mack unsigned char tmp[2], *data; 217e5779998SDaniel Mack int i, nr_rates, data_size, ret = 0; 218e5779998SDaniel Mack 219e5779998SDaniel Mack /* get the number of sample rates first by only fetching 2 bytes */ 220e5779998SDaniel Mack ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 221e5779998SDaniel Mack USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 22245d76056SDaniel Mack UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8, 22345d76056SDaniel Mack tmp, sizeof(tmp), 1000); 224e5779998SDaniel Mack 225e5779998SDaniel Mack if (ret < 0) { 226e5779998SDaniel Mack snd_printk(KERN_ERR "unable to retrieve number of sample rates\n"); 227e5779998SDaniel Mack goto err; 228e5779998SDaniel Mack } 229e5779998SDaniel Mack 230e5779998SDaniel Mack nr_rates = (tmp[1] << 8) | tmp[0]; 231e5779998SDaniel Mack data_size = 2 + 12 * nr_rates; 232e5779998SDaniel Mack data = kzalloc(data_size, GFP_KERNEL); 233e5779998SDaniel Mack if (!data) { 234e5779998SDaniel Mack ret = -ENOMEM; 235e5779998SDaniel Mack goto err; 236e5779998SDaniel Mack } 237e5779998SDaniel Mack 238e5779998SDaniel Mack /* now get the full information */ 239e5779998SDaniel Mack ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 240e5779998SDaniel Mack USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 24145d76056SDaniel Mack UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8, 24245d76056SDaniel Mack data, data_size, 1000); 243e5779998SDaniel Mack 244e5779998SDaniel Mack if (ret < 0) { 245e5779998SDaniel Mack snd_printk(KERN_ERR "unable to retrieve sample rate range\n"); 246e5779998SDaniel Mack ret = -EINVAL; 247e5779998SDaniel Mack goto err_free; 248e5779998SDaniel Mack } 249e5779998SDaniel Mack 250e5779998SDaniel Mack fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 251e5779998SDaniel Mack if (!fp->rate_table) { 252e5779998SDaniel Mack ret = -ENOMEM; 253e5779998SDaniel Mack goto err_free; 254e5779998SDaniel Mack } 255e5779998SDaniel Mack 256e5779998SDaniel Mack fp->nr_rates = 0; 257e5779998SDaniel Mack fp->rate_min = fp->rate_max = 0; 258e5779998SDaniel Mack 259e5779998SDaniel Mack for (i = 0; i < nr_rates; i++) { 260e5779998SDaniel Mack int rate = combine_quad(&data[2 + 12 * i]); 261e5779998SDaniel Mack 262e5779998SDaniel Mack fp->rate_table[fp->nr_rates] = rate; 263e5779998SDaniel Mack if (!fp->rate_min || rate < fp->rate_min) 264e5779998SDaniel Mack fp->rate_min = rate; 265e5779998SDaniel Mack if (!fp->rate_max || rate > fp->rate_max) 266e5779998SDaniel Mack fp->rate_max = rate; 267e5779998SDaniel Mack fp->rates |= snd_pcm_rate_to_rate_bit(rate); 268e5779998SDaniel Mack fp->nr_rates++; 269e5779998SDaniel Mack } 270e5779998SDaniel Mack 271e5779998SDaniel Mack err_free: 272e5779998SDaniel Mack kfree(data); 273e5779998SDaniel Mack err: 274e5779998SDaniel Mack return ret; 275e5779998SDaniel Mack } 276e5779998SDaniel Mack 277e5779998SDaniel Mack /* 278e5779998SDaniel Mack * parse the format type I and III descriptors 279e5779998SDaniel Mack */ 280e5779998SDaniel Mack static int parse_audio_format_i(struct snd_usb_audio *chip, 281*74754f97SDaniel Mack struct audioformat *fp, int format, 282*74754f97SDaniel Mack struct uac_format_type_i_continuous_descriptor *fmt, 283e5779998SDaniel Mack struct usb_host_interface *iface) 284e5779998SDaniel Mack { 285e5779998SDaniel Mack struct usb_interface_descriptor *altsd = get_iface_desc(iface); 286e5779998SDaniel Mack int protocol = altsd->bInterfaceProtocol; 287e5779998SDaniel Mack int pcm_format, ret; 288e5779998SDaniel Mack 289e5779998SDaniel Mack if (fmt->bFormatType == UAC_FORMAT_TYPE_III) { 290e5779998SDaniel Mack /* FIXME: the format type is really IECxxx 291e5779998SDaniel Mack * but we give normal PCM format to get the existing 292e5779998SDaniel Mack * apps working... 293e5779998SDaniel Mack */ 294e5779998SDaniel Mack switch (chip->usb_id) { 295e5779998SDaniel Mack 296e5779998SDaniel Mack case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 297e5779998SDaniel Mack if (chip->setup == 0x00 && 298e5779998SDaniel Mack fp->altsetting == 6) 299e5779998SDaniel Mack pcm_format = SNDRV_PCM_FORMAT_S16_BE; 300e5779998SDaniel Mack else 301e5779998SDaniel Mack pcm_format = SNDRV_PCM_FORMAT_S16_LE; 302e5779998SDaniel Mack break; 303e5779998SDaniel Mack default: 304e5779998SDaniel Mack pcm_format = SNDRV_PCM_FORMAT_S16_LE; 305e5779998SDaniel Mack } 30629088fefSClemens Ladisch fp->formats = 1uLL << pcm_format; 307e5779998SDaniel Mack } else { 30829088fefSClemens Ladisch fp->formats = parse_audio_format_i_type(chip, fp, format, 30929088fefSClemens Ladisch fmt, protocol); 31029088fefSClemens Ladisch if (!fp->formats) 311e5779998SDaniel Mack return -1; 312e5779998SDaniel Mack } 313e5779998SDaniel Mack 314e5779998SDaniel Mack /* gather possible sample rates */ 315e5779998SDaniel Mack /* audio class v1 reports possible sample rates as part of the 316e5779998SDaniel Mack * proprietary class specific descriptor. 317e5779998SDaniel Mack * audio class v2 uses class specific EP0 range requests for that. 318e5779998SDaniel Mack */ 319e5779998SDaniel Mack switch (protocol) { 320e5779998SDaniel Mack case UAC_VERSION_1: 321e5779998SDaniel Mack fp->channels = fmt->bNrChannels; 322*74754f97SDaniel Mack ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7); 323e5779998SDaniel Mack break; 324e5779998SDaniel Mack case UAC_VERSION_2: 325e5779998SDaniel Mack /* fp->channels is already set in this case */ 326e5779998SDaniel Mack ret = parse_audio_format_rates_v2(chip, fp, iface); 327e5779998SDaniel Mack break; 328e5779998SDaniel Mack } 329e5779998SDaniel Mack 330e5779998SDaniel Mack if (fp->channels < 1) { 331e5779998SDaniel Mack snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", 332e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); 333e5779998SDaniel Mack return -1; 334e5779998SDaniel Mack } 335e5779998SDaniel Mack 336e5779998SDaniel Mack return ret; 337e5779998SDaniel Mack } 338e5779998SDaniel Mack 339e5779998SDaniel Mack /* 340e5779998SDaniel Mack * parse the format type II descriptor 341e5779998SDaniel Mack */ 342e5779998SDaniel Mack static int parse_audio_format_ii(struct snd_usb_audio *chip, 343e5779998SDaniel Mack struct audioformat *fp, 344e5779998SDaniel Mack int format, void *_fmt, 345e5779998SDaniel Mack struct usb_host_interface *iface) 346e5779998SDaniel Mack { 347e5779998SDaniel Mack int brate, framesize, ret; 348e5779998SDaniel Mack struct usb_interface_descriptor *altsd = get_iface_desc(iface); 349e5779998SDaniel Mack int protocol = altsd->bInterfaceProtocol; 350e5779998SDaniel Mack 351e5779998SDaniel Mack switch (format) { 352e5779998SDaniel Mack case UAC_FORMAT_TYPE_II_AC3: 353e5779998SDaniel Mack /* FIXME: there is no AC3 format defined yet */ 354015eb0b0SClemens Ladisch // fp->formats = SNDRV_PCM_FMTBIT_AC3; 355015eb0b0SClemens Ladisch fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */ 356e5779998SDaniel Mack break; 357e5779998SDaniel Mack case UAC_FORMAT_TYPE_II_MPEG: 358015eb0b0SClemens Ladisch fp->formats = SNDRV_PCM_FMTBIT_MPEG; 359e5779998SDaniel Mack break; 360e5779998SDaniel Mack default: 361e5779998SDaniel Mack snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n", 362e5779998SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting, format); 363015eb0b0SClemens Ladisch fp->formats = SNDRV_PCM_FMTBIT_MPEG; 364e5779998SDaniel Mack break; 365e5779998SDaniel Mack } 366e5779998SDaniel Mack 367e5779998SDaniel Mack fp->channels = 1; 368e5779998SDaniel Mack 369e5779998SDaniel Mack switch (protocol) { 370e5779998SDaniel Mack case UAC_VERSION_1: { 371e5779998SDaniel Mack struct uac_format_type_ii_discrete_descriptor *fmt = _fmt; 372e5779998SDaniel Mack brate = le16_to_cpu(fmt->wMaxBitRate); 373e5779998SDaniel Mack framesize = le16_to_cpu(fmt->wSamplesPerFrame); 374e5779998SDaniel Mack snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 375e5779998SDaniel Mack fp->frame_size = framesize; 376e5779998SDaniel Mack ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */ 377e5779998SDaniel Mack break; 378e5779998SDaniel Mack } 379e5779998SDaniel Mack case UAC_VERSION_2: { 380e5779998SDaniel Mack struct uac_format_type_ii_ext_descriptor *fmt = _fmt; 381e5779998SDaniel Mack brate = le16_to_cpu(fmt->wMaxBitRate); 382e5779998SDaniel Mack framesize = le16_to_cpu(fmt->wSamplesPerFrame); 383e5779998SDaniel Mack snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 384e5779998SDaniel Mack fp->frame_size = framesize; 385e5779998SDaniel Mack ret = parse_audio_format_rates_v2(chip, fp, iface); 386e5779998SDaniel Mack break; 387e5779998SDaniel Mack } 388e5779998SDaniel Mack } 389e5779998SDaniel Mack 390e5779998SDaniel Mack return ret; 391e5779998SDaniel Mack } 392e5779998SDaniel Mack 393e5779998SDaniel Mack int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, 394*74754f97SDaniel Mack int format, struct uac_format_type_i_continuous_descriptor *fmt, 395*74754f97SDaniel Mack int stream, struct usb_host_interface *iface) 396e5779998SDaniel Mack { 397e5779998SDaniel Mack int err; 398e5779998SDaniel Mack 399*74754f97SDaniel Mack switch (fmt->bFormatType) { 400e5779998SDaniel Mack case UAC_FORMAT_TYPE_I: 401e5779998SDaniel Mack case UAC_FORMAT_TYPE_III: 402e5779998SDaniel Mack err = parse_audio_format_i(chip, fp, format, fmt, iface); 403e5779998SDaniel Mack break; 404e5779998SDaniel Mack case UAC_FORMAT_TYPE_II: 405e5779998SDaniel Mack err = parse_audio_format_ii(chip, fp, format, fmt, iface); 406e5779998SDaniel Mack break; 407e5779998SDaniel Mack default: 408e5779998SDaniel Mack snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", 409*74754f97SDaniel Mack chip->dev->devnum, fp->iface, fp->altsetting, 410*74754f97SDaniel Mack fmt->bFormatType); 411e5779998SDaniel Mack return -1; 412e5779998SDaniel Mack } 413*74754f97SDaniel Mack fp->fmt_type = fmt->bFormatType; 414e5779998SDaniel Mack if (err < 0) 415e5779998SDaniel Mack return err; 416e5779998SDaniel Mack #if 1 417e5779998SDaniel Mack /* FIXME: temporary hack for extigy/audigy 2 nx/zs */ 418e5779998SDaniel Mack /* extigy apparently supports sample rates other than 48k 419e5779998SDaniel Mack * but not in ordinary way. so we enable only 48k atm. 420e5779998SDaniel Mack */ 421e5779998SDaniel Mack if (chip->usb_id == USB_ID(0x041e, 0x3000) || 422e5779998SDaniel Mack chip->usb_id == USB_ID(0x041e, 0x3020) || 423e5779998SDaniel Mack chip->usb_id == USB_ID(0x041e, 0x3061)) { 424*74754f97SDaniel Mack if (fmt->bFormatType == UAC_FORMAT_TYPE_I && 425e5779998SDaniel Mack fp->rates != SNDRV_PCM_RATE_48000 && 426e5779998SDaniel Mack fp->rates != SNDRV_PCM_RATE_96000) 427e5779998SDaniel Mack return -1; 428e5779998SDaniel Mack } 429e5779998SDaniel Mack #endif 430e5779998SDaniel Mack return 0; 431e5779998SDaniel Mack } 432e5779998SDaniel Mack 433