Skip to content

Commit 8f898e9

Browse files
committed
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: Clemens Ladisch <clemens@ladisch.de>
1 parent f722406 commit 8f898e9

File tree

6 files changed

+16
-32
lines changed

6 files changed

+16
-32
lines changed

sound/usb/card.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct audioformat {
2121
unsigned char endpoint; /* endpoint */
2222
unsigned char ep_attr; /* endpoint attributes */
2323
unsigned char datainterval; /* log_2 of data packet interval */
24+
unsigned char protocol; /* UAC_VERSION_1/2 */
2425
unsigned int maxpacksize; /* max. packet size */
2526
unsigned int rates; /* rate bitmasks */
2627
unsigned int rate_min, rate_max; /* min/max rates */

sound/usb/clock.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
407407
struct usb_host_interface *alts,
408408
struct audioformat *fmt, int rate)
409409
{
410-
struct usb_interface_descriptor *altsd = get_iface_desc(alts);
411-
412-
switch (altsd->bInterfaceProtocol) {
410+
switch (fmt->protocol) {
413411
case UAC_VERSION_1:
414412
default:
415413
return set_sample_rate_v1(chip, iface, alts, fmt, rate);

sound/usb/format.c

+10-24
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@
4343
*/
4444
static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
4545
struct audioformat *fp,
46-
unsigned int format, void *_fmt,
47-
int protocol)
46+
unsigned int format, void *_fmt)
4847
{
4948
int sample_width, sample_bytes;
5049
u64 pcm_formats = 0;
5150

52-
switch (protocol) {
51+
switch (fp->protocol) {
5352
case UAC_VERSION_1:
5453
default: {
5554
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,
360359
*/
361360
static int parse_audio_format_i(struct snd_usb_audio *chip,
362361
struct audioformat *fp, unsigned int format,
363-
struct uac_format_type_i_continuous_descriptor *fmt,
364-
struct usb_host_interface *iface)
362+
struct uac_format_type_i_continuous_descriptor *fmt)
365363
{
366-
struct usb_interface_descriptor *altsd = get_iface_desc(iface);
367-
int protocol = altsd->bInterfaceProtocol;
368364
snd_pcm_format_t pcm_format;
369365
int ret;
370366

@@ -387,8 +383,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
387383
}
388384
fp->formats = pcm_format_to_bits(pcm_format);
389385
} else {
390-
fp->formats = parse_audio_format_i_type(chip, fp, format,
391-
fmt, protocol);
386+
fp->formats = parse_audio_format_i_type(chip, fp, format, fmt);
392387
if (!fp->formats)
393388
return -EINVAL;
394389
}
@@ -398,11 +393,8 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
398393
* proprietary class specific descriptor.
399394
* audio class v2 uses class specific EP0 range requests for that.
400395
*/
401-
switch (protocol) {
396+
switch (fp->protocol) {
402397
default:
403-
snd_printdd(KERN_WARNING "%d:%u:%d : invalid protocol version %d, assuming v1\n",
404-
chip->dev->devnum, fp->iface, fp->altsetting, protocol);
405-
/* fall through */
406398
case UAC_VERSION_1:
407399
fp->channels = fmt->bNrChannels;
408400
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,
427419
*/
428420
static int parse_audio_format_ii(struct snd_usb_audio *chip,
429421
struct audioformat *fp,
430-
int format, void *_fmt,
431-
struct usb_host_interface *iface)
422+
int format, void *_fmt)
432423
{
433424
int brate, framesize, ret;
434-
struct usb_interface_descriptor *altsd = get_iface_desc(iface);
435-
int protocol = altsd->bInterfaceProtocol;
436425

437426
switch (format) {
438427
case UAC_FORMAT_TYPE_II_AC3:
@@ -452,11 +441,8 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
452441

453442
fp->channels = 1;
454443

455-
switch (protocol) {
444+
switch (fp->protocol) {
456445
default:
457-
snd_printdd(KERN_WARNING "%d:%u:%d : invalid protocol version %d, assuming v1\n",
458-
chip->dev->devnum, fp->iface, fp->altsetting, protocol);
459-
/* fall through */
460446
case UAC_VERSION_1: {
461447
struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
462448
brate = le16_to_cpu(fmt->wMaxBitRate);
@@ -483,17 +469,17 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
483469
int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
484470
struct audioformat *fp, unsigned int format,
485471
struct uac_format_type_i_continuous_descriptor *fmt,
486-
int stream, struct usb_host_interface *iface)
472+
int stream)
487473
{
488474
int err;
489475

490476
switch (fmt->bFormatType) {
491477
case UAC_FORMAT_TYPE_I:
492478
case UAC_FORMAT_TYPE_III:
493-
err = parse_audio_format_i(chip, fp, format, fmt, iface);
479+
err = parse_audio_format_i(chip, fp, format, fmt);
494480
break;
495481
case UAC_FORMAT_TYPE_II:
496-
err = parse_audio_format_ii(chip, fp, format, fmt, iface);
482+
err = parse_audio_format_ii(chip, fp, format, fmt);
497483
break;
498484
default:
499485
snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",

sound/usb/format.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
55
struct audioformat *fp, unsigned int format,
66
struct uac_format_type_i_continuous_descriptor *fmt,
7-
int stream, struct usb_host_interface *iface);
7+
int stream);
88

99
#endif /* __USBAUDIO_FORMAT_H */

sound/usb/pcm.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
202202
struct usb_host_interface *alts,
203203
struct audioformat *fmt)
204204
{
205-
struct usb_interface_descriptor *altsd = get_iface_desc(alts);
206-
207205
/* if endpoint doesn't have pitch control, bail out */
208206
if (!(fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL))
209207
return 0;
210208

211-
switch (altsd->bInterfaceProtocol) {
209+
switch (fmt->protocol) {
212210
case UAC_VERSION_1:
213211
default:
214212
return init_pitch_v1(chip, iface, alts, fmt);

sound/usb/stream.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
635635
fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
636636
fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
637637
fp->datainterval = snd_usb_parse_datainterval(chip, alts);
638+
fp->protocol = protocol;
638639
fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
639640
fp->channels = num_channels;
640641
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)
676677
}
677678

678679
/* ok, let's parse further... */
679-
if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
680+
if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) {
680681
kfree(fp->rate_table);
681682
kfree(fp->chmap);
682683
kfree(fp);

0 commit comments

Comments
 (0)