git: 00e2c99eb73a - stable/13 - wsp: Add sysctl tunable for Z-Axis inversion

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Sun, 30 Apr 2023 06:58:04 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=00e2c99eb73aca5e46940c7993631314d485713a

commit 00e2c99eb73aca5e46940c7993631314d485713a
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-02-08 21:26:42 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2023-04-30 06:56:18 +0000

    wsp: Add sysctl tunable for Z-Axis inversion
    
    This adds a new sysctl to Wellspring Touchpad driver for controlling
    Z-Axis (2-finger vertical scroll) direction "hw.usb.wsp.z_invert".
    
    Submitted by:   James Wright <james.wright_AT_digital-chaos_DOT_com>
    Reviewed by:    wulf
    PR:             253321
    Differential revision:  https://reviews.freebsd.org/D28521
    
    (cherry picked from commit d8c6d4c7321d4c969216bda8f792b45ed00afd64)
---
 share/man/man4/wsp.4    | 7 ++++++-
 sys/dev/usb/input/wsp.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/share/man/man4/wsp.4 b/share/man/man4/wsp.4
index 70a1219533dc..847c79c71f29 100644
--- a/share/man/man4/wsp.4
+++ b/share/man/man4/wsp.4
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd January 15, 2018
+.Dd February 9, 2021
 .Dt WSP 4
 .Os
 .Sh NAME
@@ -67,6 +67,11 @@ Pointer sensitivity can be controlled using the sysctl tunable
 Tap to left-click can be controlled using the sysctl tunable
 .Nm hw.usb.wsp.enable_single_tap_clicks ,
 set to 0 to disable single tap clicks or 1 to enable them (default).
+Z-Axis sensitivity can be controlled using the sysctl tunable
+.Nm hw.usb.wsp.z_factor .
+Z-Axis inversion can be controlled using the sysctl tunable
+.Nm hw.usb.wsp.z_invert ,
+set to 0 to disable (default) or 1 to enable inversion.
 .Sh FILES
 .Nm
 creates a blocking pseudo-device file,
diff --git a/sys/dev/usb/input/wsp.c b/sys/dev/usb/input/wsp.c
index b1492f1f4c0c..c2da3df598c5 100644
--- a/sys/dev/usb/input/wsp.c
+++ b/sys/dev/usb/input/wsp.c
@@ -95,6 +95,7 @@ SYSCTL_INT(_hw_usb_wsp, OID_AUTO, debug, CTLFLAG_RWTUN,
 static struct wsp_tuning {
 	int	scale_factor;
 	int	z_factor;
+	int	z_invert;
 	int	pressure_touch_threshold;
 	int	pressure_untouch_threshold;
 	int	pressure_tap_threshold;
@@ -105,6 +106,7 @@ static struct wsp_tuning {
 {
 	.scale_factor = 12,
 	.z_factor = 5,
+	.z_invert = 0,
 	.pressure_touch_threshold = 50,
 	.pressure_untouch_threshold = 10,
 	.pressure_tap_threshold = 120,
@@ -117,6 +119,7 @@ wsp_runing_rangecheck(struct wsp_tuning *ptun)
 {
 	WSP_CLAMP(ptun->scale_factor, 1, 63);
 	WSP_CLAMP(ptun->z_factor, 1, 63);
+	WSP_CLAMP(ptun->z_invert, 0, 1);
 	WSP_CLAMP(ptun->pressure_touch_threshold, 1, 255);
 	WSP_CLAMP(ptun->pressure_untouch_threshold, 1, 255);
 	WSP_CLAMP(ptun->pressure_tap_threshold, 1, 255);
@@ -128,6 +131,8 @@ SYSCTL_INT(_hw_usb_wsp, OID_AUTO, scale_factor, CTLFLAG_RWTUN,
     &wsp_tuning.scale_factor, 0, "movement scale factor");
 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, z_factor, CTLFLAG_RWTUN,
     &wsp_tuning.z_factor, 0, "Z-axis scale factor");
+SYSCTL_INT(_hw_usb_wsp, OID_AUTO, z_invert, CTLFLAG_RWTUN,
+    &wsp_tuning.z_invert, 0, "enable Z-axis inversion");
 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_touch_threshold, CTLFLAG_RWTUN,
     &wsp_tuning.pressure_touch_threshold, 0, "touch pressure threshold");
 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_untouch_threshold, CTLFLAG_RWTUN,
@@ -1226,7 +1231,7 @@ wsp_intr_callback(struct usb_xfer *xfer, usb_error_t error)
 
 				dx = dy = 0;
 				if (sc->dz_count == 0)
-					dz = sc->dz_sum / tun.z_factor;
+					dz = (sc->dz_sum / tun.z_factor) * (tun.z_invert ? -1 : 1);
 				if (sc->scr_mode == WSP_SCR_HOR || 
 				    abs(sc->pos_x[0] - sc->pos_x[1]) > MAX_DISTANCE ||
 				    abs(sc->pos_y[0] - sc->pos_y[1]) > MAX_DISTANCE)