svn commit: r337288 - head/sys/dev/usb/input

Vladimir Kondratyev wulf at FreeBSD.org
Sat Aug 4 12:29:10 UTC 2018


Author: wulf
Date: Sat Aug  4 12:29:08 2018
New Revision: 337288
URL: https://svnweb.freebsd.org/changeset/base/337288

Log:
  wmt(4): Read Microsoft's "Touch Hardware Quality Assurance" certificate blob
  
  if present to enable some devices like WaveShare touchscreens. Unlike
  Windows we discard content of the blob. We try mimic Windows driver
  behaviour from the USB device point of view.
  
  Submitted by:	glebius (initial version)

Modified:
  head/sys/dev/usb/input/wmt.c

Modified: head/sys/dev/usb/input/wmt.c
==============================================================================
--- head/sys/dev/usb/input/wmt.c	Sat Aug  4 12:24:37 2018	(r337287)
+++ head/sys/dev/usb/input/wmt.c	Sat Aug  4 12:29:08 2018	(r337288)
@@ -206,6 +206,8 @@ struct wmt_softc
 	struct hid_location	cont_max_loc;
 	uint32_t		cont_max_rlen;
 	uint8_t			cont_max_rid;
+	uint32_t		thqa_cert_rlen;
+	uint8_t			thqa_cert_rid;
 
 	uint8_t			buf[WMT_BSIZE] __aligned(4);
 };
@@ -324,6 +326,13 @@ wmt_attach(device_t dev)
 		DPRINTF("Feature report %hhu size invalid or too large: %u\n",
 		    sc->cont_max_rid, sc->cont_max_rlen);
 
+	/* Fetch THQA certificate to enable some devices like WaveShare */
+	if (sc->thqa_cert_rlen > 0 && sc->thqa_cert_rlen <= WMT_BSIZE &&
+	    sc->thqa_cert_rid != sc->cont_max_rid)
+		(void)usbd_req_get_report(uaa->device, NULL, sc->buf,
+		    sc->thqa_cert_rlen, uaa->info.bIfaceIndex,
+		    UHID_FEATURE_REPORT, sc->thqa_cert_rid);
+
 	mtx_init(&sc->mtx, "wmt lock", NULL, MTX_DEF);
 
 	err = usbd_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
@@ -586,6 +595,7 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr,
 	int32_t cont_count_max = 0;
 	uint8_t report_id = 0;
 	uint8_t cont_max_rid = 0;
+	uint8_t thqa_cert_rid = 0;
 	bool touch_coll = false;
 	bool finger_coll = false;
 	bool cont_count_found = false;
@@ -593,6 +603,7 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr,
 
 #define WMT_HI_ABSOLUTE(hi)	\
 	(((hi).flags & (HIO_CONST|HIO_VARIABLE|HIO_RELATIVE)) == HIO_VARIABLE)
+#define	HUMS_THQA_CERT	0xC5
 
 	/* Parse features for maximum contact count */
 	hd = hid_start_parse(d_ptr, d_len, 1 << hid_feature);
@@ -608,6 +619,11 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr,
 				touch_coll = false;
 			break;
 		case hid_feature:
+			if (hi.collevel == 1 && touch_coll && hi.usage ==
+			      HID_USAGE2(HUP_MICROSOFT, HUMS_THQA_CERT)) {
+				thqa_cert_rid = hi.report_ID;
+				break;
+			}
 			if (hi.collevel == 1 && touch_coll &&
 			    WMT_HI_ABSOLUTE(hi) && hi.usage ==
 			      HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACT_MAX)) {
@@ -763,11 +779,15 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr,
 
 	sc->cont_max_rlen = wmt_hid_report_size(d_ptr, d_len, hid_feature,
 	    cont_max_rid);
+	if (thqa_cert_rid > 0)
+		sc->thqa_cert_rlen = wmt_hid_report_size(d_ptr, d_len,
+		    hid_feature, thqa_cert_rid);
 
 	sc->report_id = report_id;
 	sc->caps = caps;
 	sc->nconts_max = cont;
 	sc->cont_max_rid = cont_max_rid;
+	sc->thqa_cert_rid = thqa_cert_rid;
 
 	/* Announce information about the touch device */
 	device_printf(sc->dev,


More information about the svn-src-head mailing list