Ahoi OpenBSD,

My trackball reports two out of its four buttons in a non-standard way.
I've patched my kernel with a new USB quirk for this situation. [*]

I'd like to contribute this if you want it; please let me know if this
is the way to do it or if you'd like any changes.

--pesco
(sending from off-list)


[*] The buttons appear in the HID descriptor like normal, except with
their "usage" set to a vendor-reserved page. The quirk makes the driver
treat this page like the standard button page.

Index: sys/dev/usb/ums.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ums.c,v
retrieving revision 1.43
diff -u -p -r1.43 ums.c
--- sys/dev/usb/ums.c	12 Jan 2016 19:16:21 -0000	1.43
+++ sys/dev/usb/ums.c	20 Sep 2016 19:21:54 -0000
@@ -143,6 +143,8 @@ ums_attach(struct device *parent, struct
 		qflags |= HIDMS_MS_BAD_CLASS;
 	if (quirks & UQ_MS_LEADING_BYTE)
 		qflags |= HIDMS_LEADINGBYTE;
+	if (quirks & UQ_MS_VENDOR_BUTTONS)
+		qflags |= HIDMS_VENDOR_BUTTONS;
 
 	if (hidms_setup(self, ms, qflags, uha->reportid, desc, size) != 0)
 		return;
Index: sys/dev/usb/usb_quirks.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb_quirks.c,v
retrieving revision 1.74
diff -u -p -r1.74 usb_quirks.c
--- sys/dev/usb/usb_quirks.c	27 Nov 2015 10:59:32 -0000	1.74
+++ sys/dev/usb/usb_quirks.c	20 Sep 2016 19:21:54 -0000
@@ -150,6 +150,9 @@ const struct usbd_quirk_entry {
  { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLNOTEBOOK2,
 	ANY, { UQ_MS_BAD_CLASS | UQ_MS_LEADING_BYTE }},
 
+ { USB_VENDOR_KENSINGTON, USB_PRODUCT_KENSINGTON_SLIMBLADE,
+	ANY, { UQ_MS_VENDOR_BUTTONS }},
+
  { 0, 0, 0, { 0 } }
 };
 
Index: sys/dev/usb/usb_quirks.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb_quirks.h,v
retrieving revision 1.16
diff -u -p -r1.16 usb_quirks.h
--- sys/dev/usb/usb_quirks.h	19 Jul 2010 05:08:37 -0000	1.16
+++ sys/dev/usb/usb_quirks.h	20 Sep 2016 19:21:55 -0000
@@ -49,6 +49,8 @@ struct usbd_quirks {
 #define UQ_MS_LEADING_BYTE	0x00010000 /* mouse sends unknown leading byte */
 #define UQ_EHCI_NEEDTO_DISOWN	0x00020000 /* must hand device over to USB 1.1
 						if attached to EHCI */
+#define UQ_MS_VENDOR_BUTTONS	0x00040000 /* mouse reports extra buttons in
+						vendor page */
 };
 
 extern const struct usbd_quirks usbd_no_quirk;
Index: sys/dev/usb/usbdevs
===================================================================
RCS file: /cvs/src/sys/dev/usb/usbdevs,v
retrieving revision 1.668
diff -u -p -r1.668 usbdevs
--- sys/dev/usb/usbdevs	12 Sep 2016 07:55:33 -0000	1.668
+++ sys/dev/usb/usbdevs	20 Sep 2016 19:21:55 -0000
@@ -2397,6 +2397,7 @@ product KENSINGTON TURBOBALL	0x1005	Turb
 product KENSINGTON ORBIT_MAC	0x1009	Orbit trackball for Mac
 product KENSINGTON BT_EDR	0x105e	Bluetooth
 product KENSINGTON VIDEOCAM_VGA	0x5002	VideoCAM VGA
+product KENSINGTON SLIMBLADE	0x2041	Slimblade Trackball
 
 /* Keyspan products */
 product KEYSPAN USA28_NF	0x0101	USA-28 serial
Index: sys/dev/usb/usbdevs.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usbdevs.h,v
retrieving revision 1.680
diff -u -p -r1.680 usbdevs.h
--- sys/dev/usb/usbdevs.h	12 Sep 2016 07:56:29 -0000	1.680
+++ sys/dev/usb/usbdevs.h	20 Sep 2016 19:21:56 -0000
@@ -2404,6 +2404,7 @@
 #define	USB_PRODUCT_KENSINGTON_ORBIT_MAC	0x1009		/* Orbit trackball for Mac */
 #define	USB_PRODUCT_KENSINGTON_BT_EDR	0x105e		/* Bluetooth */
 #define	USB_PRODUCT_KENSINGTON_VIDEOCAM_VGA	0x5002		/* VideoCAM VGA */
+#define	USB_PRODUCT_KENSINGTON_SLIMBLADE	0x2041		/* Slimblade Trackball */
 
 /* Keyspan products */
 #define	USB_PRODUCT_KEYSPAN_USA28_NF	0x0101		/* USA-28 serial */
Index: sys/dev/usb/usbdevs_data.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usbdevs_data.h,v
retrieving revision 1.674
diff -u -p -r1.674 usbdevs_data.h
--- sys/dev/usb/usbdevs_data.h	12 Sep 2016 07:56:29 -0000	1.674
+++ sys/dev/usb/usbdevs_data.h	20 Sep 2016 19:21:58 -0000
@@ -5166,6 +5166,10 @@ const struct usb_known_product usb_known
 	    "VideoCAM VGA",
 	},
 	{
+	    USB_VENDOR_KENSINGTON, USB_PRODUCT_KENSINGTON_SLIMBLADE,
+	    "Slimblade Trackball",
+	},
+	{
 	    USB_VENDOR_KEYSPAN, USB_PRODUCT_KEYSPAN_USA28_NF,
 	    "USA-28 serial",
 	},
Index: sys/dev/hid/hidms.c
===================================================================
RCS file: /cvs/src/sys/dev/hid/hidms.c,v
retrieving revision 1.3
diff -u -p -r1.3 hidms.c
--- sys/dev/hid/hidms.c	22 May 2016 22:06:11 -0000	1.3
+++ sys/dev/hid/hidms.c	20 Sep 2016 19:22:44 -0000
@@ -191,6 +191,21 @@ hidms_setup(struct device *self, struct 
 			break;
 	ms->sc_num_buttons = i - 1;
 
+	/* 
+	 * The Kensington Slimblade reports some of its buttons as binary
+	 * inputs in the first vendor usage page (0xff00). Add such inputs
+	 * as buttons if the device has this quirk.
+	 */
+	if (ms->sc_flags & HIDMS_VENDOR_BUTTONS) {
+		const int b = ms->sc_num_buttons;
+		for (i = 1; b + i <= MAX_BUTTONS; i++)
+			if (!hid_locate(desc, dlen,
+			    HID_USAGE2(HUP_MICROSOFT, i),
+			    id, hid_input, &ms->sc_loc_btn[b + i - 1], NULL))
+				break;
+		ms->sc_num_buttons += i;
+	}
+
 	if (hid_locate(desc, dlen, HID_USAGE2(HUP_DIGITIZERS,
 	    HUD_TIP_SWITCH), id, hid_input,
 	    &ms->sc_loc_btn[ms->sc_num_buttons], NULL)){
Index: sys/dev/hid/hidmsvar.h
===================================================================
RCS file: /cvs/src/sys/dev/hid/hidmsvar.h,v
retrieving revision 1.1
diff -u -p -r1.1 hidmsvar.h
--- sys/dev/hid/hidmsvar.h	8 Jan 2016 15:54:13 -0000	1.1
+++ sys/dev/hid/hidmsvar.h	20 Sep 2016 19:22:44 -0000
@@ -43,18 +43,19 @@ struct tsscale {
 struct hidms {
 	int		sc_enabled;
 	int		sc_flags;	/* device configuration */
-#define HIDMS_SPUR_BUT_UP	0x001	/* spurious button up events */
-#define HIDMS_Z			0x002	/* Z direction available */
-#define HIDMS_REVZ		0x004	/* Z-axis is reversed */
-#define HIDMS_W			0x008	/* W direction available */
-#define HIDMS_REVW		0x010	/* W-axis is reversed */
-#define HIDMS_LEADINGBYTE	0x020	/* Unknown leading byte */
-#define HIDMS_ABSX		0x040	/* X-axis is absolute */
-#define HIDMS_ABSY		0x080	/* Y-axis is absolute */
-#define HIDMS_TIP		0x100   /* Tip switch on a digitiser pen */
-#define HIDMS_BARREL		0x200	/* Barrel switch on a digitiser pen */
-#define HIDMS_ERASER		0x400   /* Eraser switch on a digitiser pen */
-#define HIDMS_MS_BAD_CLASS	0x800	/* Mouse doesn't identify properly */
+#define HIDMS_SPUR_BUT_UP	0x0001	/* spurious button up events */
+#define HIDMS_Z			0x0002	/* Z direction available */
+#define HIDMS_REVZ		0x0004	/* Z-axis is reversed */
+#define HIDMS_W			0x0008	/* W direction available */
+#define HIDMS_REVW		0x0010	/* W-axis is reversed */
+#define HIDMS_LEADINGBYTE	0x0020	/* Unknown leading byte */
+#define HIDMS_ABSX		0x0040	/* X-axis is absolute */
+#define HIDMS_ABSY		0x0080	/* Y-axis is absolute */
+#define HIDMS_TIP		0x0100   /* Tip switch on a digitiser pen */
+#define HIDMS_BARREL		0x0200	/* Barrel switch on a digitiser pen */
+#define HIDMS_ERASER		0x0400   /* Eraser switch on a digitiser pen */
+#define HIDMS_MS_BAD_CLASS	0x0800	/* Mouse doesn't identify properly */
+#define HIDMS_VENDOR_BUTTONS	0x1000	/* extra buttons in vendor page */
 
 	int		sc_num_buttons;
 	u_int32_t	sc_buttons;	/* mouse button status */

Reply via email to