[PATCH] usb-core bInterval quirks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds usb quirks to improve support for devices
 with non standard bInterval values. Quirks are added to support devices with
 bInterval values expressed as microframes or frames. The quirks cause the
 parse endpoint function to modify the reported bInterval to the standards
 conforming value.

There is currently code in the endpoint parser that checks for bIntervals that are outside
of the valid range (0-15 for USB 2+). In this case, the code assumes the bInterval is being
reported in 1ms frames. However, the correction is only applied if the original bInterval
value is out of the 0-15 range.

With one of these quirks applied to the device, the bInterval will be accurately adjusted
even when the misreported bInterval is in the 0-15 range.

Signed-off-by: James P Michels III <james.p.michels@xxxxxxxxx>
---
 drivers/usb/core/config.c  | 20 ++++++++++++++++++++
 drivers/usb/core/quirks.c  |  4 ++++
 include/linux/usb/quirks.h | 13 +++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 1ab4df1..1b343fe 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -228,6 +228,26 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
 		endpoint->desc.bInterval = n;
 	}
 
+	/* Adjust bInterval reported as frames for quirked devices */
+	if (to_usb_device(ddev)->quirks & USB_QUIRK_INTERVAL_AS_FRAMES) {
+		endpoint->desc.bInterval = fls(d->bInterval * 8);
+		if (endpoint->desc.bInterval > 16)
+			endpoint->desc.bInterval = 16;
+		dev_warn(ddev, "bInterval adjusted from %d to %d\n",
+			d->bInterval,
+			endpoint->desc.bInterval);
+	}
+
+	/* Adjust bInterval reported as microframes for quirked devices */
+	if (to_usb_device(ddev)->quirks & USB_QUIRK_INTERVAL_AS_MICROFRAMES) {
+		endpoint->desc.bInterval = fls(d->bInterval);
+		if (endpoint->desc.bInterval > 16)
+			endpoint->desc.bInterval = 16;
+		dev_warn(ddev, "bInterval adjusted from %d to %d\n",
+			d->bInterval,
+			endpoint->desc.bInterval);
+	}
+
 	/* Some buggy low-speed devices have Bulk endpoints, which is
 	 * explicitly forbidden by the USB spec.  In an attempt to make
 	 * them usable, we will try treating them as Interrupt endpoints.
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 739ee8e..29d2288 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -145,6 +145,10 @@ static const struct usb_device_id usb_quirk_list[] = {
 	/* SKYMEDI USB_DRIVE */
 	{ USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME },
 
+	/* Razer - Razer Blade Keyboard */
+	{ USB_DEVICE(0x1532, 0x0116), .driver_info =
+			USB_QUIRK_INTERVAL_AS_MICROFRAMES },
+
 	/* BUILDWIN Photo Frame */
 	{ USB_DEVICE(0x1908, 0x1315), .driver_info =
 			USB_QUIRK_HONOR_BNUMINTERFACES },
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index 52f944d..cec4ac2 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -30,4 +30,17 @@
    descriptor */
 #define USB_QUIRK_DELAY_INIT		0x00000040
 
+/* The USB 2.0 and USB 3.0 spec require the interval in microframes
+   (1 microframe = 125 microseconds) to be calculated as
+   interval = 2 ^ (bInterval -1).
+
+   Devices with this quirk report their bInterval as the result of
+   this calculation instead of the exponent variable used in the
+   calculation */
+#define USB_QUIRK_INTERVAL_AS_MICROFRAMES	0x00000080
+
+/* Devices with this quirk report their bInterval as the number of
+   frames per interval (1 frame = 1 millisecond) */
+#define USB_QUIRK_INTERVAL_AS_FRAMES	0x00000100
+
 #endif /* __LINUX_USB_QUIRKS_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux