Sun May 30 13:20:01 2021 UTC ()
synaptics(4): New sysctl knob for debug output.

Set hw.synaptics.debug=1 to re-enable it; the compile-time DIAGNOSTIC
option was inappropriate for this.


(riastradh)
diff -r1.70 -r1.71 src/sys/dev/pckbport/synaptics.c

cvs diff -r1.70 -r1.71 src/sys/dev/pckbport/synaptics.c (expand / switch to unified diff)

--- src/sys/dev/pckbport/synaptics.c 2020/10/01 17:13:19 1.70
+++ src/sys/dev/pckbport/synaptics.c 2021/05/30 13:20:01 1.71
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: synaptics.c,v 1.70 2020/10/01 17:13:19 nia Exp $ */ 1/* $NetBSD: synaptics.c,v 1.71 2021/05/30 13:20:01 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005, Steve C. Woodford 4 * Copyright (c) 2005, Steve C. Woodford
5 * Copyright (c) 2004, Ales Krenek 5 * Copyright (c) 2004, Ales Krenek
6 * Copyright (c) 2004, Kentaro A. Kurahone 6 * Copyright (c) 2004, Kentaro A. Kurahone
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * * Redistributions of source code must retain the above copyright 13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -38,27 +38,27 @@ @@ -38,27 +38,27 @@
38/* 38/*
39 * TODO: 39 * TODO:
40 * - Make the sysctl values per-instance instead of global. 40 * - Make the sysctl values per-instance instead of global.
41 * - Consider setting initial scaling factors at runtime according 41 * - Consider setting initial scaling factors at runtime according
42 * to the values returned by the 'Read Resolutions' command. 42 * to the values returned by the 'Read Resolutions' command.
43 * - Support the serial protocol (we only support PS/2 for now) 43 * - Support the serial protocol (we only support PS/2 for now)
44 * - Support auto-repeat for up/down button Z-axis emulation. 44 * - Support auto-repeat for up/down button Z-axis emulation.
45 * - Maybe add some more gestures (can we use Palm support somehow?) 45 * - Maybe add some more gestures (can we use Palm support somehow?)
46 */ 46 */
47 47
48#include "opt_pms.h" 48#include "opt_pms.h"
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.70 2020/10/01 17:13:19 nia Exp $"); 51__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.71 2021/05/30 13:20:01 riastradh Exp $");
52 52
53#include <sys/param.h> 53#include <sys/param.h>
54#include <sys/systm.h> 54#include <sys/systm.h>
55#include <sys/device.h> 55#include <sys/device.h>
56#include <sys/ioctl.h> 56#include <sys/ioctl.h>
57#include <sys/sysctl.h> 57#include <sys/sysctl.h>
58#include <sys/kernel.h> 58#include <sys/kernel.h>
59#include <sys/proc.h> 59#include <sys/proc.h>
60 60
61#include <sys/bus.h> 61#include <sys/bus.h>
62 62
63#include <dev/pckbport/pckbportvar.h> 63#include <dev/pckbport/pckbportvar.h>
64 64
@@ -115,26 +115,36 @@ static int synaptics_button3 = SYNAPTICS @@ -115,26 +115,36 @@ static int synaptics_button3 = SYNAPTICS
115static int synaptics_two_fingers_emul = 0; 115static int synaptics_two_fingers_emul = 0;
116static int synaptics_scale_x = 16; 116static int synaptics_scale_x = 16;
117static int synaptics_scale_y = 16; 117static int synaptics_scale_y = 16;
118static int synaptics_scale_z = 32; 118static int synaptics_scale_z = 32;
119static int synaptics_max_speed_x = 32; 119static int synaptics_max_speed_x = 32;
120static int synaptics_max_speed_y = 32; 120static int synaptics_max_speed_y = 32;
121static int synaptics_max_speed_z = 2; 121static int synaptics_max_speed_z = 2;
122static int synaptics_movement_threshold = 4; 122static int synaptics_movement_threshold = 4;
123static int synaptics_fscroll_min = 13; 123static int synaptics_fscroll_min = 13;
124static int synaptics_fscroll_max = 14; 124static int synaptics_fscroll_max = 14;
125static int synaptics_dz_hold = 30; 125static int synaptics_dz_hold = 30;
126static int synaptics_movement_enable = 1; 126static int synaptics_movement_enable = 1;
127static bool synaptics_aux_mid_button_scroll = TRUE; 127static bool synaptics_aux_mid_button_scroll = TRUE;
 128static int synaptics_debug = 0;
 129
 130#define DPRINTF(SC, FMT, ARGS...) do \
 131{ \
 132 if (synaptics_debug) { \
 133 struct pms_softc *_dprintf_psc = \
 134 container_of((SC), struct pms_softc, u.synaptics); \
 135 device_printf(_dprintf_psc->sc_dev, FMT, ##ARGS); \
 136 } \
 137} while (0)
128 138
129/* Sysctl nodes. */ 139/* Sysctl nodes. */
130static int synaptics_button_boundary_nodenum; 140static int synaptics_button_boundary_nodenum;
131static int synaptics_button2_nodenum; 141static int synaptics_button2_nodenum;
132static int synaptics_button3_nodenum; 142static int synaptics_button3_nodenum;
133static int synaptics_up_down_emul_nodenum; 143static int synaptics_up_down_emul_nodenum;
134static int synaptics_up_down_motion_delta_nodenum; 144static int synaptics_up_down_motion_delta_nodenum;
135static int synaptics_gesture_move_nodenum; 145static int synaptics_gesture_move_nodenum;
136static int synaptics_gesture_length_nodenum; 146static int synaptics_gesture_length_nodenum;
137static int synaptics_edge_left_nodenum; 147static int synaptics_edge_left_nodenum;
138static int synaptics_edge_right_nodenum; 148static int synaptics_edge_right_nodenum;
139static int synaptics_edge_top_nodenum; 149static int synaptics_edge_top_nodenum;
140static int synaptics_edge_bottom_nodenum; 150static int synaptics_edge_bottom_nodenum;
@@ -834,26 +844,37 @@ pms_sysctl_synaptics(struct sysctllog ** @@ -834,26 +844,37 @@ pms_sysctl_synaptics(struct sysctllog **
834 synaptics_dz_hold_nodenum = node->sysctl_num; 844 synaptics_dz_hold_nodenum = node->sysctl_num;
835 845
836 if ((rc = sysctl_createv(clog, 0, NULL, &node, 846 if ((rc = sysctl_createv(clog, 0, NULL, &node,
837 CTLFLAG_PERMANENT | CTLFLAG_READWRITE, 847 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
838 CTLTYPE_BOOL, "aux_mid_button_scroll", 848 CTLTYPE_BOOL, "aux_mid_button_scroll",
839 SYSCTL_DESCR("Interpet Y-Axis movement with the middle button held as scrolling on the passthrough device (e.g. TrackPoint)"), 849 SYSCTL_DESCR("Interpet Y-Axis movement with the middle button held as scrolling on the passthrough device (e.g. TrackPoint)"),
840 pms_sysctl_synaptics_verify, 0, 850 pms_sysctl_synaptics_verify, 0,
841 &synaptics_aux_mid_button_scroll, 851 &synaptics_aux_mid_button_scroll,
842 0, CTL_HW, root_num, CTL_CREATE, 852 0, CTL_HW, root_num, CTL_CREATE,
843 CTL_EOL)) != 0) 853 CTL_EOL)) != 0)
844 goto err; 854 goto err;
845 855
846 synaptics_aux_mid_button_scroll_nodenum = node->sysctl_num; 856 synaptics_aux_mid_button_scroll_nodenum = node->sysctl_num;
 857
 858 if ((rc = sysctl_createv(clog, 0, NULL, &node,
 859 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
 860 CTLTYPE_INT, "debug",
 861 SYSCTL_DESCR("Enable debug output"),
 862 NULL, 0,
 863 &synaptics_debug,
 864 0, CTL_HW, root_num, CTL_CREATE,
 865 CTL_EOL)) != 0)
 866 goto err;
 867
847 return; 868 return;
848 869
849err: 870err:
850 aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc); 871 aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
851} 872}
852 873
853static int 874static int
854pms_sysctl_synaptics_verify(SYSCTLFN_ARGS) 875pms_sysctl_synaptics_verify(SYSCTLFN_ARGS)
855{ 876{
856 int error, t; 877 int error, t;
857 struct sysctlnode node; 878 struct sysctlnode node;
858 879
859 node = *rnode; 880 node = *rnode;
@@ -1384,49 +1405,47 @@ synaptics_gesture_detect(struct synaptic @@ -1384,49 +1405,47 @@ synaptics_gesture_detect(struct synaptic
1384 * 'synaptics_gesture_length' packets, this is treated 1405 * 'synaptics_gesture_length' packets, this is treated
1385 * as a double-click. Otherwise we will emulate holding 1406 * as a double-click. Otherwise we will emulate holding
1386 * the left button down whilst dragging the mouse. 1407 * the left button down whilst dragging the mouse.
1387 */ 1408 */
1388 if (SYN_IS_SINGLE_TAP(sc->gesture_type)) 1409 if (SYN_IS_SINGLE_TAP(sc->gesture_type))
1389 sc->gesture_type |= SYN_GESTURE_DRAG; 1410 sc->gesture_type |= SYN_GESTURE_DRAG;
1390 1411
1391 sc->gesture_start_x = abs(sp->sp_x); 1412 sc->gesture_start_x = abs(sp->sp_x);
1392 sc->gesture_start_y = abs(sp->sp_y); 1413 sc->gesture_start_y = abs(sp->sp_y);
1393 sc->gesture_move_x = 0; 1414 sc->gesture_move_x = 0;
1394 sc->gesture_move_y = 0; 1415 sc->gesture_move_y = 0;
1395 sc->gesture_start_packet = sc->total_packets[0]; 1416 sc->gesture_start_packet = sc->total_packets[0];
1396 1417
1397#ifdef DIAGNOSTIC 1418 DPRINTF(sc, "Finger applied:"
1398 aprint_debug("Finger applied: gesture_start_x: %d gesture_start_y: %d\n", 1419 " gesture_start_x: %d"
1399 sc->gesture_start_x, sc->gesture_start_y); 1420 " gesture_start_y: %d\n",
1400#endif 1421 sc->gesture_start_x, sc->gesture_start_y);
1401 } else 1422 } else
1402 if (fingers == 0 && sc->prev_fingers != 0) { 1423 if (fingers == 0 && sc->prev_fingers != 0) {
1403 /* 1424 /*
1404 * Finger was just removed. 1425 * Finger was just removed.
1405 * Check if the contact time and finger movement were 1426 * Check if the contact time and finger movement were
1406 * small enough to qualify as a gesture. 1427 * small enough to qualify as a gesture.
1407 * Ignore finger movement if multiple fingers were 1428 * Ignore finger movement if multiple fingers were
1408 * detected (the pad may report coordinates for any 1429 * detected (the pad may report coordinates for any
1409 * of the fingers). 1430 * of the fingers).
1410 */ 1431 */
1411 1432
1412#ifdef DIAGNOSTIC 1433 DPRINTF(sc, "Finger removed: gesture_len: %d (%d)\n",
1413 aprint_debug("Finger removed: gesture_len: %d (%d)\n", 1434 gesture_len, synaptics_gesture_length);
1414 gesture_len, synaptics_gesture_length); 1435 DPRINTF(sc, "gesture_move_x: %d (%d) sp_x: %d\n",
1415 aprint_debug("gesture_move_x: %d (%d) sp_x: %d\n", 1436 sc->gesture_move_x, synaptics_gesture_move, abs(sp->sp_x));
1416 sc->gesture_move_x, synaptics_gesture_move, abs(sp->sp_x)); 1437 DPRINTF(sc, "gesture_move_y: %d (%d) sp_y: %d\n",
1417 aprint_debug("gesture_move_y: %d (%d) sp_y: %d\n", 1438 sc->gesture_move_y, synaptics_gesture_move, abs(sp->sp_y));
1418 sc->gesture_move_y, synaptics_gesture_move, abs(sp->sp_y)); 
1419#endif 
1420 1439
1421 if (gesture_len < synaptics_gesture_length && 1440 if (gesture_len < synaptics_gesture_length &&
1422 ((sc->gesture_move_x < synaptics_gesture_move && 1441 ((sc->gesture_move_x < synaptics_gesture_move &&
1423 sc->gesture_move_y < synaptics_gesture_move))) { 1442 sc->gesture_move_y < synaptics_gesture_move))) {
1424 /* 1443 /*
1425 * Looking good so far. 1444 * Looking good so far.
1426 */ 1445 */
1427 if (SYN_IS_DRAG(sc->gesture_type)) { 1446 if (SYN_IS_DRAG(sc->gesture_type)) {
1428 /* 1447 /*
1429 * Promote this gesture to double-click. 1448 * Promote this gesture to double-click.
1430 */ 1449 */
1431 sc->gesture_type |= SYN_GESTURE_DOUBLE; 1450 sc->gesture_type |= SYN_GESTURE_DOUBLE;
1432 sc->gesture_type &= ~SYN_GESTURE_SINGLE; 1451 sc->gesture_type &= ~SYN_GESTURE_SINGLE;