Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Dec 2020 22:29:37 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 18a3b77e226e - wmt(4): Refactor 'Contact Count Maximum' parsing
Message-ID:  <202012232229.0BNMTbHL083057@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=18a3b77e226ef0f39f92579e0e261146d99a3bdb

commit 18a3b77e226ef0f39f92579e0e261146d99a3bdb
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2020-12-23 22:18:18 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2020-12-23 22:26:06 +0000

    wmt(4): Refactor 'Contact Count Maximum' parsing
    
    That is done mainly to reduce diff with upstream.
    
    Obtained from:  sysutils/iichid
---
 sys/dev/usb/input/wmt.c | 47 ++++++++++++++++++-----------------------------
 1 file changed, 18 insertions(+), 29 deletions(-)

diff --git a/sys/dev/usb/input/wmt.c b/sys/dev/usb/input/wmt.c
index 1377d8d1af40..927d019ea099 100644
--- a/sys/dev/usb/input/wmt.c
+++ b/sys/dev/usb/input/wmt.c
@@ -255,7 +255,6 @@ struct wmt_softc {
 		if (USAGE_SUPPORTED((caps), (usage)))
 
 static enum wmt_type wmt_hid_parse(struct wmt_softc *, const void *, uint16_t);
-static void wmt_cont_max_parse(struct wmt_softc *, const void *, uint16_t);
 static int wmt_set_input_mode(struct wmt_softc *, enum wmt_input_mode);
 
 static usb_callback_t	wmt_intr_callback;
@@ -340,6 +339,7 @@ wmt_attach(device_t dev)
 {
 	struct usb_attach_arg *uaa = device_get_ivars(dev);
 	struct wmt_softc *sc = device_get_softc(dev);
+	uint32_t cont_count_max;
 	int nbuttons, btn;
 	size_t i;
 	int err;
@@ -352,9 +352,16 @@ wmt_attach(device_t dev)
 		err = usbd_req_get_report(uaa->device, NULL, sc->buf,
 		    sc->cont_max_rlen, uaa->info.bIfaceIndex,
 		    UHID_FEATURE_REPORT, sc->cont_max_rid);
-		if (err == USB_ERR_NORMAL_COMPLETION)
-			wmt_cont_max_parse(sc, sc->buf, sc->cont_max_rlen);
-		else
+		if (err == USB_ERR_NORMAL_COMPLETION) {
+			cont_count_max = hid_get_data_unsigned(sc->buf + 1,
+			    sc->cont_max_rlen - 1, &sc->cont_max_loc);
+			/*
+			 * Feature report is a primary source of
+			 * 'Contact Count Maximum'
+			 */
+			if (cont_count_max > 0)
+				sc->ai[WMT_SLOT].max = cont_count_max - 1;
+		} else
 			DPRINTF("usbd_req_get_report error=(%s)\n",
 			    usbd_errstr(err));
 	} else
@@ -391,6 +398,13 @@ wmt_attach(device_t dev)
 			DPRINTF("Failed to set input mode: %d\n", err);
 	}
 
+	/* Cap contact count maximum to MAX_MT_SLOTS */
+	if (sc->ai[WMT_SLOT].max >= MAX_MT_SLOTS) {
+		DPRINTF("Hardware reported %d contacts while only %d is "
+		    "supported\n", (int)sc->ai[WMT_SLOT].max+1, MAX_MT_SLOTS);
+		sc->ai[WMT_SLOT].max = MAX_MT_SLOTS - 1;
+	}
+
 	if (/*usb_test_quirk(hw, UQ_MT_TIMESTAMP) ||*/ wmt_timestamps)
 		sc->do_timestamps = true;
 
@@ -972,10 +986,6 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
 	if (cont_count_max < 1)
 		cont_count_max = cont;
 
-	/* Cap contact count maximum to MAX_MT_SLOTS */
-	if (cont_count_max > MAX_MT_SLOTS)
-		cont_count_max = MAX_MT_SLOTS;
-
 	/* Set number of MT protocol type B slots */
 	sc->ai[WMT_SLOT] = (struct wmt_absinfo) {
 		.min = 0,
@@ -1009,27 +1019,6 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
 	return (type);
 }
 
-static void
-wmt_cont_max_parse(struct wmt_softc *sc, const void *r_ptr, uint16_t r_len)
-{
-	uint32_t cont_count_max;
-
-	cont_count_max = hid_get_data_unsigned((const uint8_t *)r_ptr + 1,
-	    r_len - 1, &sc->cont_max_loc);
-	if (cont_count_max > MAX_MT_SLOTS) {
-		DPRINTF("Hardware reported %d contacts while only %d is "
-		    "supported\n", (int)cont_count_max, MAX_MT_SLOTS);
-		cont_count_max = MAX_MT_SLOTS;
-	}
-	/* Feature report is a primary source of 'Contact Count Maximum' */
-	if (cont_count_max > 0 &&
-	    cont_count_max != sc->ai[WMT_SLOT].max + 1) {
-		sc->ai[WMT_SLOT].max = cont_count_max - 1;
-		device_printf(sc->dev, "%d feature report contacts",
-		    cont_count_max);
-	}
-}
-
 static int
 wmt_set_input_mode(struct wmt_softc *sc, enum wmt_input_mode mode)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012232229.0BNMTbHL083057>