summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2005-12-31 04:22:34 +0000
committermux <mux@FreeBSD.org>2005-12-31 04:22:34 +0000
commit6012b1978aefdbd4147df3127d3a6b261d1d612f (patch)
tree58a6b5233b8eb1ebd4a67eb23c1f39e7b65659bf /sys
parent1edbd8766fcb57f6687dfffc86450b2b8faef66e (diff)
downloadFreeBSD-src-6012b1978aefdbd4147df3127d3a6b261d1d612f.zip
FreeBSD-src-6012b1978aefdbd4147df3127d3a6b261d1d612f.tar.gz
Add support for Xbox 360 gamepads. They are HID-capable devices, but
lack a report descriptor and don't use the standard interface class. This patch works around these deficiencies so that the uhid(4) driver can recognize and use those broken devices. PR: usb/90141 Submitted by: Ed Schouten <ed@fxq.nl> (with minor mods from me) MFC after: 1 week
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/usb/uhid.c27
-rw-r--r--sys/dev/usb/usb.h2
-rw-r--r--sys/dev/usb/uxb360gp_rdesc.h124
3 files changed, 149 insertions, 4 deletions
diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c
index 8b0e6e9..8fdf6d9 100644
--- a/sys/dev/usb/uhid.c
+++ b/sys/dev/usb/uhid.c
@@ -89,8 +89,9 @@ __FBSDID("$FreeBSD$");
#include <dev/usb/usbdi_util.h>
#include <dev/usb/hid.h>
-/* Report descriptor for broken Wacom Graphire */
+/* Replacement report descriptors for devices shipped with broken ones */
#include <dev/usb/ugraphire_rdesc.h>
+#include <dev/usb/uxb360gp_rdesc.h>
/* For hid blacklist quirk */
#include <dev/usb/usb_quirks.h>
@@ -193,8 +194,15 @@ USB_MATCH(uhid)
if (uaa->iface == NULL)
return (UMATCH_NONE);
id = usbd_get_interface_descriptor(uaa->iface);
- if (id == NULL || id->bInterfaceClass != UICLASS_HID)
+ if (id == NULL)
return (UMATCH_NONE);
+ if (id->bInterfaceClass != UICLASS_HID) {
+ /* The Xbox 360 gamepad doesn't use the HID class. */
+ if (id->bInterfaceClass != UICLASS_VENDOR ||
+ id->bInterfaceSubClass != UISUBCLASS_XBOX360_CONTROLLER ||
+ id->bInterfaceProtocol != UIPROTO_XBOX360_GAMEPAD)
+ return (UMATCH_NONE);
+ }
if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE)
return (UMATCH_NONE);
#if 0
@@ -212,7 +220,7 @@ USB_ATTACH(uhid)
usb_interface_descriptor_t *id;
usb_endpoint_descriptor_t *ed;
int size;
- void *desc;
+ void *descptr, *desc;
usbd_status err;
char devinfo[1024];
@@ -248,17 +256,28 @@ USB_ATTACH(uhid)
sc->sc_ep_addr = ed->bEndpointAddress;
+ descptr = NULL;
if (uaa->vendor == USB_VENDOR_WACOM &&
uaa->product == USB_PRODUCT_WACOM_GRAPHIRE /* &&
uaa->revision == 0x???? */) { /* XXX should use revision */
/* The report descriptor for the Wacom Graphire is broken. */
size = sizeof uhid_graphire_report_descr;
+ descptr = uhid_graphire_report_descr;
+ } else if (id->bInterfaceClass == UICLASS_VENDOR &&
+ id->bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER &&
+ id->bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD) {
+ /* The Xbox 360 gamepad has no report descriptor. */
+ size = sizeof uhid_xb360gp_report_descr;
+ descptr = uhid_xb360gp_report_descr;
+ }
+
+ if (descptr) {
desc = malloc(size, M_USBDEV, M_NOWAIT);
if (desc == NULL)
err = USBD_NOMEM;
else {
err = USBD_NORMAL_COMPLETION;
- memcpy(desc, uhid_graphire_report_descr, size);
+ memcpy(desc, descptr, size);
}
} else {
desc = NULL;
diff --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h
index f4559c1..07dd4b3 100644
--- a/sys/dev/usb/usb.h
+++ b/sys/dev/usb/usb.h
@@ -489,6 +489,8 @@ typedef struct {
#define UIPROTO_IRDA 0
#define UICLASS_VENDOR 0xff
+#define UISUBCLASS_XBOX360_CONTROLLER 0x5d
+#define UIPROTO_XBOX360_GAMEPAD 0x01
#define USB_HUB_MAX_DEPTH 5
diff --git a/sys/dev/usb/uxb360gp_rdesc.h b/sys/dev/usb/uxb360gp_rdesc.h
new file mode 100644
index 0000000..1aba944
--- /dev/null
+++ b/sys/dev/usb/uxb360gp_rdesc.h
@@ -0,0 +1,124 @@
+/*-
+ * Copyright (c) 2005 Ed Schouten <ed@fxq.nl>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * The descriptor has no output report format, thus preventing you from
+ * controlling the LEDs and the built-in rumblers.
+ */
+static uByte uhid_xb360gp_report_descr[] = {
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x05, /* USAGE (Gamepad) */
+ 0xa1, 0x01, /* COLLECTION (Application) */
+ /* Unused */
+ 0x75, 0x08, /* REPORT SIZE (8) */
+ 0x95, 0x01, /* REPORT COUNT (1) */
+ 0x81, 0x01, /* INPUT (Constant) */
+ /* Byte count */
+ 0x75, 0x08, /* REPORT SIZE (8) */
+ 0x95, 0x01, /* REPORT COUNT (1) */
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x3b, /* USAGE (Byte Count) */
+ 0x81, 0x01, /* INPUT (Constant) */
+ /* D-Pad */
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x01, /* USAGE (Pointer) */
+ 0xa1, 0x00, /* COLLECTION (Physical) */
+ 0x75, 0x01, /* REPORT SIZE (1) */
+ 0x15, 0x00, /* LOGICAL MINIMUM (0) */
+ 0x25, 0x01, /* LOGICAL MAXIMUM (1) */
+ 0x35, 0x00, /* PHYSICAL MINIMUM (0) */
+ 0x45, 0x01, /* PHYSICAL MAXIMUM (1) */
+ 0x95, 0x04, /* REPORT COUNT (4) */
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x90, /* USAGE (D-Pad Up) */
+ 0x09, 0x91, /* USAGE (D-Pad Down) */
+ 0x09, 0x93, /* USAGE (D-Pad Left) */
+ 0x09, 0x92, /* USAGE (D-Pad Right) */
+ 0x81, 0x02, /* INPUT (Data, Variable, Absolute) */
+ 0xc0, /* END COLLECTION */
+ /* Buttons 5-11 */
+ 0x75, 0x01, /* REPORT SIZE (1) */
+ 0x15, 0x00, /* LOGICAL MINIMUM (0) */
+ 0x25, 0x01, /* LOGICAL MAXIMUM (1) */
+ 0x35, 0x00, /* PHYSICAL MINIMUM (0) */
+ 0x45, 0x01, /* PHYSICAL MAXIMUM (1) */
+ 0x95, 0x07, /* REPORT COUNT (7) */
+ 0x05, 0x09, /* USAGE PAGE (Button) */
+ 0x09, 0x08, /* USAGE (Button 8) */
+ 0x09, 0x07, /* USAGE (Button 7) */
+ 0x09, 0x09, /* USAGE (Button 9) */
+ 0x09, 0x0a, /* USAGE (Button 10) */
+ 0x09, 0x05, /* USAGE (Button 5) */
+ 0x09, 0x06, /* USAGE (Button 6) */
+ 0x09, 0x0b, /* USAGE (Button 11) */
+ 0x81, 0x02, /* INPUT (Data, Variable, Absolute) */
+ /* Unused */
+ 0x75, 0x01, /* REPORT SIZE (1) */
+ 0x95, 0x01, /* REPORT COUNT (1) */
+ 0x81, 0x01, /* INPUT (Constant) */
+ /* Buttons 1-4 */
+ 0x75, 0x01, /* REPORT SIZE (1) */
+ 0x15, 0x00, /* LOGICAL MINIMUM (0) */
+ 0x25, 0x01, /* LOGICAL MAXIMUM (1) */
+ 0x35, 0x00, /* PHYSICAL MINIMUM (0) */
+ 0x45, 0x01, /* PHYSICAL MAXIMUM (1) */
+ 0x95, 0x04, /* REPORT COUNT (4) */
+ 0x05, 0x09, /* USAGE PAGE (Button) */
+ 0x19, 0x01, /* USAGE MINIMUM (Button 1) */
+ 0x29, 0x04, /* USAGE MAXIMUM (Button 4) */
+ 0x81, 0x02, /* INPUT (Data, Variable, Absolute) */
+ /* Triggers */
+ 0x75, 0x08, /* REPORT SIZE (8) */
+ 0x15, 0x00, /* LOGICAL MINIMUM (0) */
+ 0x26, 0xff, 0x00, /* LOGICAL MAXIMUM (255) */
+ 0x35, 0x00, /* PHYSICAL MINIMUM (0) */
+ 0x46, 0xff, 0x00, /* PHYSICAL MAXIMUM (255) */
+ 0x95, 0x02, /* REPORT SIZE (2) */
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x32, /* USAGE (Z) */
+ 0x09, 0x35, /* USAGE (Rz) */
+ 0x81, 0x02, /* INPUT (Data, Variable, Absolute) */
+ /* Sticks */
+ 0x75, 0x10, /* REPORT SIZE (16) */
+ 0x16, 0x00, 0x80, /* LOGICAL MINIMUM (-32768) */
+ 0x26, 0xff, 0x7f, /* LOGICAL MAXIMUM (32767) */
+ 0x36, 0x00, 0x80, /* PHYSICAL MINIMUM (-32768) */
+ 0x46, 0xff, 0x7f, /* PHYSICAL MAXIMUM (32767) */
+ 0x95, 0x04, /* REPORT COUNT (4) */
+ 0x05, 0x01, /* USAGE PAGE (Generic Desktop) */
+ 0x09, 0x30, /* USAGE (X) */
+ 0x09, 0x31, /* USAGE (Y) */
+ 0x09, 0x33, /* USAGE (Rx) */
+ 0x09, 0x34, /* USAGE (Ry) */
+ 0x81, 0x02, /* INPUT (Data, Variable, Absolute) */
+ /* Unused */
+ 0x75, 0x30, /* REPORT SIZE (48) */
+ 0x95, 0x01, /* REPORT COUNT (1) */
+ 0x81, 0x01, /* INPUT (Constant) */
+ 0xc0, /* END COLLECTION */
+};
OpenPOWER on IntegriCloud