[Midnightbsd-cvs] src [12246] trunk/sys/dev/sound/usb: extend the vendor class USB audio quirk to cover devices without the control descriptor
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Aug 8 22:52:56 EDT 2019
Revision: 12246
http://svnweb.midnightbsd.org/src/?rev=12246
Author: laffer1
Date: 2019-08-08 22:52:56 -0400 (Thu, 08 Aug 2019)
Log Message:
-----------
extend the vendor class USB audio quirk to cover devices without the control descriptor
Modified Paths:
--------------
trunk/sys/dev/sound/usb/uaudio.c
trunk/sys/dev/sound/usb/uaudioreg.h
Modified: trunk/sys/dev/sound/usb/uaudio.c
===================================================================
--- trunk/sys/dev/sound/usb/uaudio.c 2019-08-09 02:49:11 UTC (rev 12245)
+++ trunk/sys/dev/sound/usb/uaudio.c 2019-08-09 02:52:56 UTC (rev 12246)
@@ -1,6 +1,6 @@
/* $MidnightBSD$ */
/* $NetBSD: uaudio.c,v 1.91 2004/11/05 17:46:14 kent Exp $ */
-/* $FreeBSD: stable/10/sys/dev/sound/usb/uaudio.c 315249 2017-03-14 15:21:41Z hselasky $ */
+/* $FreeBSD: stable/10/sys/dev/sound/usb/uaudio.c 345546 2019-03-26 13:53:33Z hselasky $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: stable/10/sys/dev/sound/usb/uaudio.c 315249 2017-03-14 15:21:41Z hselasky $");
+__FBSDID("$FreeBSD: stable/10/sys/dev/sound/usb/uaudio.c 345546 2019-03-26 13:53:33Z hselasky $");
/*
* USB audio specs: http://www.usb.org/developers/devclass_docs/audio10.pdf
@@ -99,7 +99,7 @@
static int uaudio_buffer_ms = 8;
#ifdef USB_DEBUG
-static int uaudio_debug = 0;
+static int uaudio_debug;
static SYSCTL_NODE(_hw_usb, OID_AUTO, uaudio, CTLFLAG_RW, 0, "USB uaudio");
@@ -141,6 +141,8 @@
SYSCTL_PROC(_hw_usb_uaudio, OID_AUTO, buffer_ms, CTLTYPE_INT | CTLFLAG_RWTUN,
0, sizeof(int), uaudio_buffer_ms_sysctl, "I",
"uaudio buffering delay from 2ms to 8ms");
+#else
+#define uaudio_debug 0
#endif
#define UAUDIO_NFRAMES 64 /* must be factor of 8 due HS-USB */
@@ -1523,7 +1525,8 @@
{
struct usb_device_request req;
usb_error_t error;
- uint8_t data[255];
+#define UAUDIO20_MAX_RATES 32 /* we support at maxium 32 rates */
+ uint8_t data[2 + UAUDIO20_MAX_RATES * 12];
uint16_t actlen;
uint16_t rates;
uint16_t x;
@@ -1535,19 +1538,57 @@
req.bRequest = UA20_CS_RANGE;
USETW2(req.wValue, UA20_CS_SAM_FREQ_CONTROL, 0);
USETW2(req.wIndex, clockid, iface_no);
- USETW(req.wLength, 255);
+ /*
+ * Assume there is at least one rate to begin with, else some
+ * devices might refuse to return the USB descriptor:
+ */
+ USETW(req.wLength, (2 + 1 * 12));
- error = usbd_do_request_flags(udev, NULL, &req, data,
+ error = usbd_do_request_flags(udev, NULL, &req, data,
USB_SHORT_XFER_OK, &actlen, USB_DEFAULT_TIMEOUT);
- if (error != 0 || actlen < 2)
- return (USB_ERR_INVAL);
+ if (error != 0 || actlen < 2) {
+ /*
+ * Likely the descriptor doesn't fit into the supplied
+ * buffer. Try using a larger buffer and see if that
+ * helps:
+ */
+ rates = MIN(UAUDIO20_MAX_RATES, (255 - 2) / 12);
+ error = USB_ERR_INVAL;
+ } else {
+ rates = UGETW(data);
- rates = data[0] | (data[1] << 8);
+ if (rates > UAUDIO20_MAX_RATES) {
+ DPRINTF("Too many rates truncating to %d\n", UAUDIO20_MAX_RATES);
+ rates = UAUDIO20_MAX_RATES;
+ error = USB_ERR_INVAL;
+ } else if (rates > 1) {
+ DPRINTF("Need to read full rate descriptor\n");
+ error = USB_ERR_INVAL;
+ }
+ }
+
+ if (error != 0) {
+ /*
+ * Try to read full rate descriptor.
+ */
+ actlen = (2 + rates * 12);
+
+ USETW(req.wLength, actlen);
+
+ error = usbd_do_request_flags(udev, NULL, &req, data,
+ USB_SHORT_XFER_OK, &actlen, USB_DEFAULT_TIMEOUT);
+
+ if (error != 0 || actlen < 2)
+ return (USB_ERR_INVAL);
+
+ rates = UGETW(data);
+ }
+
actlen = (actlen - 2) / 12;
if (rates > actlen) {
- DPRINTF("Too many rates\n");
+ DPRINTF("Too many rates truncating to %d\n", actlen);
rates = actlen;
}
@@ -1709,7 +1750,7 @@
continue;
}
- if ((acdp != NULL) &&
+ if ((acdp != NULL || sc->sc_uq_au_vendor_class != 0) &&
(desc->bDescriptorType == UDESC_CS_INTERFACE) &&
(desc->bDescriptorSubtype == AS_GENERAL) &&
(asid.v1 == NULL)) {
@@ -1725,7 +1766,7 @@
}
}
}
- if ((acdp != NULL) &&
+ if ((acdp != NULL || sc->sc_uq_au_vendor_class != 0) &&
(desc->bDescriptorType == UDESC_CS_INTERFACE) &&
(desc->bDescriptorSubtype == FORMAT_TYPE) &&
(asf1d.v1 == NULL)) {
@@ -1764,7 +1805,7 @@
continue;
}
}
- if ((acdp != NULL) &&
+ if ((acdp != NULL || sc->sc_uq_au_vendor_class != 0) &&
(desc->bDescriptorType == UDESC_CS_ENDPOINT) &&
(desc->bDescriptorSubtype == AS_GENERAL) &&
(sed.v1 == NULL)) {
@@ -2166,6 +2207,14 @@
break;
case USB_ST_SETUP:
+ /*
+ * Check if the recording stream can be used as a
+ * source of jitter information to save some
+ * isochronous bandwidth:
+ */
+ if (ch->priv_sc->sc_rec_chan.num_alt != 0 &&
+ uaudio_debug == 0)
+ break;
usbd_xfer_set_frames(xfer, 1);
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_framelen(xfer));
usbd_transfer_submit(xfer);
Modified: trunk/sys/dev/sound/usb/uaudioreg.h
===================================================================
--- trunk/sys/dev/sound/usb/uaudioreg.h 2019-08-09 02:49:11 UTC (rev 12245)
+++ trunk/sys/dev/sound/usb/uaudioreg.h 2019-08-09 02:52:56 UTC (rev 12246)
@@ -1,6 +1,6 @@
/* $MidnightBSD$ */
/* $NetBSD: uaudioreg.h,v 1.12 2004/11/05 19:08:29 kent Exp $ */
-/* $FreeBSD: stable/10/sys/dev/sound/usb/uaudioreg.h 272423 2014-10-02 16:57:44Z hselasky $ */
+/* $FreeBSD: stable/10/sys/dev/sound/usb/uaudioreg.h 345546 2019-03-26 13:53:33Z hselasky $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#ifndef _UAUDIOREG_H_
#define _UAUDIOREG_H_
-#define UAUDIO_VERSION 0x0100
+#define UAUDIO_VERSION_10 0x0100
#define UAUDIO_VERSION_20 0x0200
#define UAUDIO_VERSION_30 0x0300
More information about the Midnightbsd-cvs
mailing list