提交 8f898e92 编写于 作者: C Clemens Ladisch

ALSA: usb-audio: store protocol version in struct audioformat

Instead of reading bInterfaceProtocol from the descriptor whenever it's
needed, store this value in the audioformat structure.  Besides
simplifying some code, this will allow us to correctly handle vendor-
specific devices where the descriptors are marked with other values.
Signed-off-by: NClemens Ladisch <clemens@ladisch.de>
上级 f722406f
...@@ -21,6 +21,7 @@ struct audioformat { ...@@ -21,6 +21,7 @@ struct audioformat {
unsigned char endpoint; /* endpoint */ unsigned char endpoint; /* endpoint */
unsigned char ep_attr; /* endpoint attributes */ unsigned char ep_attr; /* endpoint attributes */
unsigned char datainterval; /* log_2 of data packet interval */ unsigned char datainterval; /* log_2 of data packet interval */
unsigned char protocol; /* UAC_VERSION_1/2 */
unsigned int maxpacksize; /* max. packet size */ unsigned int maxpacksize; /* max. packet size */
unsigned int rates; /* rate bitmasks */ unsigned int rates; /* rate bitmasks */
unsigned int rate_min, rate_max; /* min/max rates */ unsigned int rate_min, rate_max; /* min/max rates */
......
...@@ -407,9 +407,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface, ...@@ -407,9 +407,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts, struct usb_host_interface *alts,
struct audioformat *fmt, int rate) struct audioformat *fmt, int rate)
{ {
struct usb_interface_descriptor *altsd = get_iface_desc(alts); switch (fmt->protocol) {
switch (altsd->bInterfaceProtocol) {
case UAC_VERSION_1: case UAC_VERSION_1:
default: default:
return set_sample_rate_v1(chip, iface, alts, fmt, rate); return set_sample_rate_v1(chip, iface, alts, fmt, rate);
......
...@@ -43,13 +43,12 @@ ...@@ -43,13 +43,12 @@
*/ */
static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
struct audioformat *fp, struct audioformat *fp,
unsigned int format, void *_fmt, unsigned int format, void *_fmt)
int protocol)
{ {
int sample_width, sample_bytes; int sample_width, sample_bytes;
u64 pcm_formats = 0; u64 pcm_formats = 0;
switch (protocol) { switch (fp->protocol) {
case UAC_VERSION_1: case UAC_VERSION_1:
default: { default: {
struct uac_format_type_i_discrete_descriptor *fmt = _fmt; struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
...@@ -360,11 +359,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, ...@@ -360,11 +359,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
*/ */
static int parse_audio_format_i(struct snd_usb_audio *chip, static int parse_audio_format_i(struct snd_usb_audio *chip,
struct audioformat *fp, unsigned int format, struct audioformat *fp, unsigned int format,
struct uac_format_type_i_continuous_descriptor *fmt, struct uac_format_type_i_continuous_descriptor *fmt)
struct usb_host_interface *iface)
{ {
struct usb_interface_descriptor *altsd = get_iface_desc(iface);
int protocol = altsd->bInterfaceProtocol;
snd_pcm_format_t pcm_format; snd_pcm_format_t pcm_format;
int ret; int ret;
...@@ -387,8 +383,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, ...@@ -387,8 +383,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
} }
fp->formats = pcm_format_to_bits(pcm_format); fp->formats = pcm_format_to_bits(pcm_format);
} else { } else {
fp->formats = parse_audio_format_i_type(chip, fp, format, fp->formats = parse_audio_format_i_type(chip, fp, format, fmt);
fmt, protocol);
if (!fp->formats) if (!fp->formats)
return -EINVAL; return -EINVAL;
} }
...@@ -398,11 +393,8 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, ...@@ -398,11 +393,8 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
* proprietary class specific descriptor. * proprietary class specific descriptor.
* audio class v2 uses class specific EP0 range requests for that. * audio class v2 uses class specific EP0 range requests for that.
*/ */
switch (protocol) { switch (fp->protocol) {
default: default:
snd_printdd(KERN_WARNING "%d:%u:%d : invalid protocol version %d, assuming v1\n",
chip->dev->devnum, fp->iface, fp->altsetting, protocol);
/* fall through */
case UAC_VERSION_1: case UAC_VERSION_1:
fp->channels = fmt->bNrChannels; fp->channels = fmt->bNrChannels;
ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7); ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7);
...@@ -427,12 +419,9 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, ...@@ -427,12 +419,9 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
*/ */
static int parse_audio_format_ii(struct snd_usb_audio *chip, static int parse_audio_format_ii(struct snd_usb_audio *chip,
struct audioformat *fp, struct audioformat *fp,
int format, void *_fmt, int format, void *_fmt)
struct usb_host_interface *iface)
{ {
int brate, framesize, ret; int brate, framesize, ret;
struct usb_interface_descriptor *altsd = get_iface_desc(iface);
int protocol = altsd->bInterfaceProtocol;
switch (format) { switch (format) {
case UAC_FORMAT_TYPE_II_AC3: case UAC_FORMAT_TYPE_II_AC3:
...@@ -452,11 +441,8 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, ...@@ -452,11 +441,8 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
fp->channels = 1; fp->channels = 1;
switch (protocol) { switch (fp->protocol) {
default: default:
snd_printdd(KERN_WARNING "%d:%u:%d : invalid protocol version %d, assuming v1\n",
chip->dev->devnum, fp->iface, fp->altsetting, protocol);
/* fall through */
case UAC_VERSION_1: { case UAC_VERSION_1: {
struct uac_format_type_ii_discrete_descriptor *fmt = _fmt; struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
brate = le16_to_cpu(fmt->wMaxBitRate); brate = le16_to_cpu(fmt->wMaxBitRate);
...@@ -483,17 +469,17 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, ...@@ -483,17 +469,17 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
int snd_usb_parse_audio_format(struct snd_usb_audio *chip, int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
struct audioformat *fp, unsigned int format, struct audioformat *fp, unsigned int format,
struct uac_format_type_i_continuous_descriptor *fmt, struct uac_format_type_i_continuous_descriptor *fmt,
int stream, struct usb_host_interface *iface) int stream)
{ {
int err; int err;
switch (fmt->bFormatType) { switch (fmt->bFormatType) {
case UAC_FORMAT_TYPE_I: case UAC_FORMAT_TYPE_I:
case UAC_FORMAT_TYPE_III: case UAC_FORMAT_TYPE_III:
err = parse_audio_format_i(chip, fp, format, fmt, iface); err = parse_audio_format_i(chip, fp, format, fmt);
break; break;
case UAC_FORMAT_TYPE_II: case UAC_FORMAT_TYPE_II:
err = parse_audio_format_ii(chip, fp, format, fmt, iface); err = parse_audio_format_ii(chip, fp, format, fmt);
break; break;
default: default:
snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
int snd_usb_parse_audio_format(struct snd_usb_audio *chip, int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
struct audioformat *fp, unsigned int format, struct audioformat *fp, unsigned int format,
struct uac_format_type_i_continuous_descriptor *fmt, struct uac_format_type_i_continuous_descriptor *fmt,
int stream, struct usb_host_interface *iface); int stream);
#endif /* __USBAUDIO_FORMAT_H */ #endif /* __USBAUDIO_FORMAT_H */
...@@ -202,13 +202,11 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, ...@@ -202,13 +202,11 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts, struct usb_host_interface *alts,
struct audioformat *fmt) struct audioformat *fmt)
{ {
struct usb_interface_descriptor *altsd = get_iface_desc(alts);
/* if endpoint doesn't have pitch control, bail out */ /* if endpoint doesn't have pitch control, bail out */
if (!(fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL)) if (!(fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL))
return 0; return 0;
switch (altsd->bInterfaceProtocol) { switch (fmt->protocol) {
case UAC_VERSION_1: case UAC_VERSION_1:
default: default:
return init_pitch_v1(chip, iface, alts, fmt); return init_pitch_v1(chip, iface, alts, fmt);
......
...@@ -635,6 +635,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) ...@@ -635,6 +635,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
fp->datainterval = snd_usb_parse_datainterval(chip, alts); fp->datainterval = snd_usb_parse_datainterval(chip, alts);
fp->protocol = protocol;
fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
fp->channels = num_channels; fp->channels = num_channels;
if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
...@@ -676,7 +677,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) ...@@ -676,7 +677,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
} }
/* ok, let's parse further... */ /* ok, let's parse further... */
if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) {
kfree(fp->rate_table); kfree(fp->rate_table);
kfree(fp->chmap); kfree(fp->chmap);
kfree(fp); kfree(fp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册