From owner-dev-commits-src-main@freebsd.org Wed Jan 20 20:10:43 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5979A4D8C48; Wed, 20 Jan 2021 20:10:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DLc8g2814z3mXc; Wed, 20 Jan 2021 20:10:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3C6D81F498; Wed, 20 Jan 2021 20:10:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10KKAhPL045041; Wed, 20 Jan 2021 20:10:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10KKAhAO045040; Wed, 20 Jan 2021 20:10:43 GMT (envelope-from git) Date: Wed, 20 Jan 2021 20:10:43 GMT Message-Id: <202101202010.10KKAhAO045040@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: fa656aefe43b - main - hconf(4): Do not fetch report before writing new usage values back. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fa656aefe43b91a06191d4a99e11876998a50c46 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2021 20:10:43 -0000 The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=fa656aefe43b91a06191d4a99e11876998a50c46 commit fa656aefe43b91a06191d4a99e11876998a50c46 Author: Vladimir Kondratyev AuthorDate: 2021-01-20 20:10:06 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-01-20 20:10:06 +0000 hconf(4): Do not fetch report before writing new usage values back. There is a report that reading of surface/button switch feature report causes SYN1B7D touchpad malfunction. As specs does not require it to be readable assume that report usages have default value on attach and last written value during operation. Do not apply default usage values on attachment and resume. While here fix manpage typos and add avg@ to copyright header. Reported by: Jakob Alvermark Reviewed by: avg Differential revision: https://reviews.freebsd.org/D28196 --- share/man/man4/hconf.4 | 8 +++---- sys/dev/hid/hconf.c | 57 ++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/share/man/man4/hconf.4 b/share/man/man4/hconf.4 index 4d595e9f1c6c..944f3376b187 100644 --- a/share/man/man4/hconf.4 +++ b/share/man/man4/hconf.4 @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 14, 2020 +.Dd January 18, 2021 .Dt HCONF 4 .Os .Sh NAME @@ -61,11 +61,11 @@ Debug parameter is available as .Xr loader 8 tunable as well. .Bl -tag -width indent -.It Va dev.hmt.*.input_mode +.It Va dev.hconf.*.input_mode HID device input mode: 0 = mouse, 3 = touchpad. -.It Va dev.hmt.*.surface_switch +.It Va dev.hconf.*.surface_switch Enable / disable switch for surface: 1 = on, 0 = off. -.It Va dev.hmt.*.buttons_switch +.It Va dev.hconf.*.buttons_switch Enable / disable switch for buttons: 1 = on, 0 = off. .It Va hw.hid.hconf.debug Debug output level, where 0 is debugging disabled and larger values increase diff --git a/sys/dev/hid/hconf.c b/sys/dev/hid/hconf.c index 71650421ee33..cb0465e71b3e 100644 --- a/sys/dev/hid/hconf.c +++ b/sys/dev/hid/hconf.c @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2019 Vladimir Kondratyev + * Copyright (c) 2020 Andriy Gapon * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,21 +70,25 @@ struct feature_control_descr { const char *name; const char *descr; uint16_t usage; + u_int value; } feature_control_descrs[] = { [INPUT_MODE] = { .name = "input_mode", .descr = "HID device input mode: 0 = mouse, 3 = touchpad", - .usage = HUD_INPUT_MODE + .usage = HUD_INPUT_MODE, + .value = HCONF_INPUT_MODE_MOUSE, }, [SURFACE_SWITCH] = { .name = "surface_switch", .descr = "Enable / disable switch for surface: 1 = on, 0 = off", - .usage = HUD_SURFACE_SWITCH + .usage = HUD_SURFACE_SWITCH, + .value = 1, }, [BUTTONS_SWITCH] = { .name = "buttons_switch", .descr = "Enable / disable switch for buttons: 1 = on, 0 = off", - .usage = HUD_BUTTONS_SWITCH + .usage = HUD_BUTTONS_SWITCH, + .value = 1, }, }; @@ -145,35 +150,25 @@ hconf_set_feature_control(struct hconf_softc *sc, int ctrl_id, u_int val) fbuf = malloc(fc->rlen, M_TEMP, M_WAITOK | M_ZERO); sx_xlock(&sc->lock); - /* Reports are not strictly required to be readable */ - error = hid_get_report(sc->dev, fbuf, fc->rlen, NULL, - HID_FEATURE_REPORT, fc->rid); - /* - * If the report is write-only, then we have to check for other controls - * that may share the same report and set their bits as well. + * Assume the report is write-only. Then we have to check for other + * controls that may share the same report and set their bits as well. */ - if (error != 0) { - bzero(fbuf + 1, fc->rlen - 1); - for (i = 0; i < nitems(sc->feature_controls); i++) { - struct feature_control *ofc = &sc->feature_controls[i]; - - /* Skip unrelated report IDs. */ - if (ofc->rid != fc->rid) - continue; - /* Skip self. */ - if (ofc == fc) - continue; - KASSERT(fc->rlen == ofc->rlen, - ("different lengths for report %d: %d vs %d\n", - fc->rid, fc->rlen, ofc->rlen)); - hid_put_udata(fbuf + 1, ofc->rlen - 1, &ofc->loc, - ofc->val); - } + bzero(fbuf + 1, fc->rlen - 1); + for (i = 0; i < nitems(sc->feature_controls); i++) { + struct feature_control *ofc = &sc->feature_controls[i]; + + /* Skip unrelated report IDs. */ + if (ofc->rid != fc->rid) + continue; + KASSERT(fc->rlen == ofc->rlen, + ("different lengths for report %d: %d vs %d\n", + fc->rid, fc->rlen, ofc->rlen)); + hid_put_udata(fbuf + 1, ofc->rlen - 1, &ofc->loc, + i == ctrl_id ? val : ofc->val); } fbuf[0] = fc->rid; - hid_put_udata(fbuf + 1, fc->rlen - 1, &fc->loc, val); error = hid_set_report(sc->dev, fbuf, fc->rlen, HID_FEATURE_REPORT, fc->rid); @@ -277,11 +272,9 @@ hconf_attach(device_t dev) sc, i, hconf_feature_control_handler, "I", feature_control_descrs[i].descr); } + sc->feature_controls[i].val = feature_control_descrs[i].value; } - /* Fully enable (at least, try to). */ - (void)hconf_set_feature_control(sc, SURFACE_SWITCH, 1); - (void)hconf_set_feature_control(sc, BUTTONS_SWITCH, 1); return (0); } @@ -305,6 +298,10 @@ hconf_resume(device_t dev) for (i = 0; i < nitems(sc->feature_controls); i++) { if (sc->feature_controls[i].rlen < 2) continue; + /* Do not update usages to default value */ + if (sc->feature_controls[i].val == + feature_control_descrs[i].value) + continue; error = hconf_set_feature_control(sc, i, sc->feature_controls[i].val); if (error != 0) {