View | Details | Raw Unified | Return to bug 205690 | Differences between
and this patch

Collapse All | Expand All

(-)b/sys/dev/atkbdc/psm.c (-447 / +1545 lines)
Lines 81-86 __FBSDID("$FreeBSD$"); Link Here
81
#include <sys/sysctl.h>
81
#include <sys/sysctl.h>
82
#include <sys/time.h>
82
#include <sys/time.h>
83
#include <sys/uio.h>
83
#include <sys/uio.h>
84
#include <sys/libkern.h>
84
85
85
#include <sys/limits.h>
86
#include <sys/limits.h>
86
#include <sys/mouse.h>
87
#include <sys/mouse.h>
Lines 161-200 typedef struct packetbuf { Link Here
161
#define	PSM_PACKETQUEUE	128
162
#define	PSM_PACKETQUEUE	128
162
#endif
163
#endif
163
164
164
enum {
165
	SYNAPTICS_SYSCTL_MIN_PRESSURE,
166
	SYNAPTICS_SYSCTL_MAX_PRESSURE,
167
	SYNAPTICS_SYSCTL_MAX_WIDTH,
168
	SYNAPTICS_SYSCTL_MARGIN_TOP,
169
	SYNAPTICS_SYSCTL_MARGIN_RIGHT,
170
	SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
171
	SYNAPTICS_SYSCTL_MARGIN_LEFT,
172
	SYNAPTICS_SYSCTL_NA_TOP,
173
	SYNAPTICS_SYSCTL_NA_RIGHT,
174
	SYNAPTICS_SYSCTL_NA_BOTTOM,
175
	SYNAPTICS_SYSCTL_NA_LEFT,
176
	SYNAPTICS_SYSCTL_WINDOW_MIN,
177
	SYNAPTICS_SYSCTL_WINDOW_MAX,
178
	SYNAPTICS_SYSCTL_MULTIPLICATOR,
179
	SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
180
	SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
181
	SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
182
	SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
183
	SYNAPTICS_SYSCTL_DIV_MIN,
184
	SYNAPTICS_SYSCTL_DIV_MAX,
185
	SYNAPTICS_SYSCTL_DIV_MAX_NA,
186
	SYNAPTICS_SYSCTL_DIV_LEN,
187
	SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
188
	SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
189
	SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
190
	SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
191
	SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
192
	SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
193
	SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
194
	SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
195
	SYNAPTICS_SYSCTL_TOUCHPAD_OFF
196
};
197
198
typedef struct synapticsinfo {
165
typedef struct synapticsinfo {
199
	struct sysctl_ctx_list	 sysctl_ctx;
166
	struct sysctl_ctx_list	 sysctl_ctx;
200
	struct sysctl_oid	*sysctl_tree;
167
	struct sysctl_oid	*sysctl_tree;
Lines 231-236 typedef struct synapticsinfo { Link Here
231
	int			 vscroll_div_min;
198
	int			 vscroll_div_min;
232
	int			 vscroll_div_max;
199
	int			 vscroll_div_max;
233
	int			 touchpad_off;
200
	int			 touchpad_off;
201
	int			 softbuttons_y;
202
	int			 softbutton2_x;
203
	int			 softbutton3_x;
234
} synapticsinfo_t;
204
} synapticsinfo_t;
235
205
236
typedef struct synapticspacket {
206
typedef struct synapticspacket {
Lines 246-267 typedef struct synapticspacket { Link Here
246
    ((synhw).infoMajor > (major) ||					\
216
    ((synhw).infoMajor > (major) ||					\
247
     ((synhw).infoMajor == (major) && (synhw).infoMinor >= (minor)))
217
     ((synhw).infoMajor == (major) && (synhw).infoMinor >= (minor)))
248
218
249
typedef struct synapticsaction {
219
typedef struct smoother {
250
	synapticspacket_t	queue[SYNAPTICS_PACKETQUEUE];
220
	synapticspacket_t	queue[SYNAPTICS_PACKETQUEUE];
251
	int			queue_len;
221
	int			queue_len;
252
	int			queue_cursor;
222
	int			queue_cursor;
253
	int			window_min;
254
	int			start_x;
223
	int			start_x;
255
	int			start_y;
224
	int			start_y;
256
	int			avg_dx;
225
	int			avg_dx;
257
	int			avg_dy;
226
	int			avg_dy;
258
	int			squelch_x;
227
	int			squelch_x;
259
	int			squelch_y;
228
	int			squelch_y;
229
	int			is_fuzzy;
230
	int			active;
231
} smoother_t;
232
233
typedef struct gesture {
234
	int			window_min;
260
	int			fingers_nb;
235
	int			fingers_nb;
261
	int			tap_button;
236
	int			tap_button;
262
	int			in_taphold;
237
	int			in_taphold;
263
	int			in_vscroll;
238
	int			in_vscroll;
264
} synapticsaction_t;
239
	int			zmax;		/* maximum pressure value */
240
	struct timeval		taptimeout;	/* tap timeout for touchpads */
241
} gesture_t;
265
242
266
enum {
243
enum {
267
	TRACKPOINT_SYSCTL_SENSITIVITY,
244
	TRACKPOINT_SYSCTL_SENSITIVITY,
Lines 295-300 typedef struct trackpointinfo { Link Here
295
	int	skipback;
272
	int	skipback;
296
} trackpointinfo_t;
273
} trackpointinfo_t;
297
274
275
typedef struct finger {
276
	int			x;
277
	int			y;
278
	int			p;
279
	int			w;
280
	int			flags;
281
} finger_t;
282
#define	PSM_FINGERS		2	/* # of processed fingers */
283
#define	PSM_FINGER_IS_PEN	(1<<0)
284
#define	PSM_FINGER_FUZZY	(1<<1)
285
#define	PSM_FINGER_IS_SET(f) ((f).x != -1 && (f).y != -1 && (f).p != 0)
286
#define	PSM_FINGER_RESET(f) do \
287
	(f) = (finger_t) { .x = -1, .y = -1, .p = 0, .w = 0, .flags = 0 }; \
288
while (0)
289
290
typedef struct elantechhw {
291
	int			hwversion;
292
	int			fwversion;
293
	int			sizex;
294
	int			sizey;
295
	int			dpmmx;
296
	int			dpmmy;
297
	int			ntracesx;
298
	int			ntracesy;
299
	int			issemimt;
300
	int			isclickpad;
301
	int			hascrc;
302
	int			hastrackpad;
303
	int			haspressure;
304
} elantechhw_t;
305
306
/* minimum versions supported by this driver */
307
#define	ELANTECH_HW_IS_V1(fwver) ((fwver) < 0x020030 || (fwver) == 0x020600)
308
309
#define	ELANTECH_MAGIC(magic)				\
310
	((magic)[0] == 0x3c && (magic)[1] == 0x03 &&	\
311
	((magic)[2] == 0xc8 || (magic)[2] == 0x00))
312
313
#define	ELANTECH_FW_ID		0x00
314
#define	ELANTECH_FW_VERSION	0x01
315
#define	ELANTECH_CAPABILITIES	0x02
316
#define	ELANTECH_SAMPLE		0x03
317
#define	ELANTECH_RESOLUTION	0x04
318
#define	ELANTECH_REG_READ	0x10
319
#define	ELANTECH_REG_WRITE	0x11
320
#define	ELANTECH_REG_RDWR	0x00
321
#define	ELANTECH_CUSTOM_CMD	0xf8
322
323
#define	ELANTECH_MAX_FINGERS	2
324
325
#define	ELANTECH_FINGER_DEFAULT_P tap_threshold
326
#define	ELANTECH_FINGER_DEFAULT_W 1
327
#define	ELANTECH_FINGER_SET_XYP(pb) (finger_t) {			\
328
    .x = (((pb)->ipacket[1] & 0x0f) << 8) | (pb)->ipacket[2],		\
329
    .y = (((pb)->ipacket[4] & 0x0f) << 8) | (pb)->ipacket[5],		\
330
    .p = ((pb)->ipacket[1] & 0xf0) | (((pb)->ipacket[4] >> 4) & 0x0f),	\
331
    .w = ELANTECH_FINGER_DEFAULT_W,					\
332
    .flags = 0								\
333
}
334
335
enum {
336
	ELANTECH_PKT_NOP,
337
	ELANTECH_PKT_TRACKPOINT,
338
	ELANTECH_PKT_V2_COMMON,
339
	ELANTECH_PKT_V2_2FINGER,
340
	ELANTECH_PKT_V3,
341
	ELANTECH_PKT_V4_STATUS,
342
	ELANTECH_PKT_V4_HEAD,
343
	ELANTECH_PKT_V4_MOTION
344
};
345
346
#define	ELANTECH_PKT_IS_TRACKPOINT(pb) (((pb)->ipacket[3] & 0x0f) == 0x06)
347
#define	ELANTECH_PKT_IS_DEBOUNCE(pb, hwversion) ((hwversion) == 4 ? 0 :	\
348
    (pb)->ipacket[0] == ((hwversion) == 2 ? 0x84 : 0xc4) &&		\
349
    (pb)->ipacket[1] == 0xff && (pb)->ipacket[2] == 0xff &&		\
350
    (pb)->ipacket[3] == 0x02 && (pb)->ipacket[4] == 0xff &&		\
351
    (pb)->ipacket[5] == 0xff)
352
#define	ELANTECH_PKT_IS_V2(pb) 						\
353
    (((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x0f) == 0x02)
354
#define	ELANTECH_PKT_IS_V3_HEAD(pb, hascrc) ((hascrc) ? 		\
355
    ((pb)->ipacket[3] & 0x09) == 0x08 : 				\
356
    ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0xcf) == 0x02)
357
#define	ELANTECH_PKT_IS_V3_TAIL(pb, hascrc) ((hascrc) ? 		\
358
    ((pb)->ipacket[3] & 0x09) == 0x09 : 				\
359
    ((pb)->ipacket[0] & 0x0c) == 0x0c && ((pb)->ipacket[3] & 0xce) == 0x0c)
360
#define	ELANTECH_PKT_IS_V4(pb, hascrc) ((hascrc) ? 			\
361
    ((pb)->ipacket[3] & 0x08) == 0x00 :					\
362
    ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x1c) == 0x10)
363
364
typedef struct elantechaction {
365
	finger_t		fingers[ELANTECH_MAX_FINGERS];
366
	int			mask;
367
} elantechaction_t;
368
298
/* driver control block */
369
/* driver control block */
299
struct psm_softc {		/* Driver status information */
370
struct psm_softc {		/* Driver status information */
300
	int		unit;
371
	int		unit;
Lines 308-314 struct psm_softc { /* Driver status information */ Link Here
308
	mousehw_t	hw;		/* hardware information */
379
	mousehw_t	hw;		/* hardware information */
309
	synapticshw_t	synhw;		/* Synaptics hardware information */
380
	synapticshw_t	synhw;		/* Synaptics hardware information */
310
	synapticsinfo_t	syninfo;	/* Synaptics configuration */
381
	synapticsinfo_t	syninfo;	/* Synaptics configuration */
311
	synapticsaction_t synaction;	/* Synaptics action context */
382
	smoother_t	smoother[PSM_FINGERS];	/* Motion smoothing */
383
	gesture_t	gesture;	/* Gesture context */
384
	elantechhw_t	elanhw;		/* Elantech hardware information */
385
	elantechaction_t elanaction;	/* Elantech action context */
312
	int		tphw;		/* TrackPoint hardware information */
386
	int		tphw;		/* TrackPoint hardware information */
313
	trackpointinfo_t tpinfo;	/* TrackPoint configuration */
387
	trackpointinfo_t tpinfo;	/* TrackPoint configuration */
314
	mousemode_t	mode;		/* operation mode */
388
	mousemode_t	mode;		/* operation mode */
Lines 324-336 struct psm_softc { /* Driver status information */ Link Here
324
	int		xaverage;	/* average X position */
398
	int		xaverage;	/* average X position */
325
	int		yaverage;	/* average Y position */
399
	int		yaverage;	/* average Y position */
326
	int		squelch; /* level to filter movement at low speed */
400
	int		squelch; /* level to filter movement at low speed */
327
	int		zmax;	/* maximum pressure value for touchpads */
328
	int		syncerrors; /* # of bytes discarded to synchronize */
401
	int		syncerrors; /* # of bytes discarded to synchronize */
329
	int		pkterrors;  /* # of packets failed during quaranteen. */
402
	int		pkterrors;  /* # of packets failed during quaranteen. */
330
	struct timeval	inputtimeout;
403
	struct timeval	inputtimeout;
331
	struct timeval	lastsoftintr;	/* time of last soft interrupt */
404
	struct timeval	lastsoftintr;	/* time of last soft interrupt */
332
	struct timeval	lastinputerr;	/* time last sync error happened */
405
	struct timeval	lastinputerr;	/* time last sync error happened */
333
	struct timeval	taptimeout;	/* tap timeout for touchpads */
406
	struct timeval	idletimeout;
407
	packetbuf_t	idlepacket;	/* packet to send after idle timeout */
334
	int		watchdog;	/* watchdog timer flag */
408
	int		watchdog;	/* watchdog timer flag */
335
	struct callout	callout;	/* watchdog timer call out */
409
	struct callout	callout;	/* watchdog timer call out */
336
	struct callout	softcallout; /* buffer timer call out */
410
	struct callout	softcallout; /* buffer timer call out */
Lines 389-394 TUNABLE_INT("hw.psm.synaptics_support", &synaptics_support); Link Here
389
static int trackpoint_support = 0;
463
static int trackpoint_support = 0;
390
TUNABLE_INT("hw.psm.trackpoint_support", &trackpoint_support);
464
TUNABLE_INT("hw.psm.trackpoint_support", &trackpoint_support);
391
465
466
static int elantech_support = 0;
467
TUNABLE_INT("hw.psm.elantech_support", &elantech_support);
468
392
static int verbose = PSM_DEBUG;
469
static int verbose = PSM_DEBUG;
393
TUNABLE_INT("debug.psm.loglevel", &verbose);
470
TUNABLE_INT("debug.psm.loglevel", &verbose);
394
471
Lines 411-416 typedef struct old_mousemode { Link Here
411
	int	accelfactor;
488
	int	accelfactor;
412
} old_mousemode_t;
489
} old_mousemode_t;
413
490
491
#define SYN_OFFSET(field) offsetof(struct psm_softc, syninfo.field)
492
enum {
493
	SYNAPTICS_SYSCTL_MIN_PRESSURE =		SYN_OFFSET(min_pressure),
494
	SYNAPTICS_SYSCTL_MAX_PRESSURE =		SYN_OFFSET(max_pressure),
495
	SYNAPTICS_SYSCTL_MAX_WIDTH =		SYN_OFFSET(max_width),
496
	SYNAPTICS_SYSCTL_MARGIN_TOP =		SYN_OFFSET(margin_top),
497
	SYNAPTICS_SYSCTL_MARGIN_RIGHT =		SYN_OFFSET(margin_right),
498
	SYNAPTICS_SYSCTL_MARGIN_BOTTOM =	SYN_OFFSET(margin_bottom),
499
	SYNAPTICS_SYSCTL_MARGIN_LEFT =		SYN_OFFSET(margin_left),
500
	SYNAPTICS_SYSCTL_NA_TOP =		SYN_OFFSET(na_top),
501
	SYNAPTICS_SYSCTL_NA_RIGHT =		SYN_OFFSET(na_right),
502
	SYNAPTICS_SYSCTL_NA_BOTTOM =		SYN_OFFSET(na_bottom),
503
	SYNAPTICS_SYSCTL_NA_LEFT = 		SYN_OFFSET(na_left),
504
	SYNAPTICS_SYSCTL_WINDOW_MIN =		SYN_OFFSET(window_min),
505
	SYNAPTICS_SYSCTL_WINDOW_MAX =		SYN_OFFSET(window_max),
506
	SYNAPTICS_SYSCTL_MULTIPLICATOR =	SYN_OFFSET(multiplicator),
507
	SYNAPTICS_SYSCTL_WEIGHT_CURRENT =	SYN_OFFSET(weight_current),
508
	SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS =	SYN_OFFSET(weight_previous),
509
	SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA =	SYN_OFFSET(weight_previous_na),
510
	SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED =	SYN_OFFSET(weight_len_squared),
511
	SYNAPTICS_SYSCTL_DIV_MIN =		SYN_OFFSET(div_min),
512
	SYNAPTICS_SYSCTL_DIV_MAX =		SYN_OFFSET(div_max),
513
	SYNAPTICS_SYSCTL_DIV_MAX_NA =		SYN_OFFSET(div_max_na),
514
	SYNAPTICS_SYSCTL_DIV_LEN =		SYN_OFFSET(div_len),
515
	SYNAPTICS_SYSCTL_TAP_MAX_DELTA =	SYN_OFFSET(tap_max_delta),
516
	SYNAPTICS_SYSCTL_TAP_MIN_QUEUE =	SYN_OFFSET(tap_min_queue),
517
	SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT =	SYN_OFFSET(taphold_timeout),
518
	SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA =	SYN_OFFSET(vscroll_hor_area),
519
	SYNAPTICS_SYSCTL_VSCROLL_VER_AREA =	SYN_OFFSET(vscroll_ver_area),
520
	SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA =	SYN_OFFSET(vscroll_min_delta),
521
	SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN =	SYN_OFFSET(vscroll_div_min),
522
	SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX =	SYN_OFFSET(vscroll_div_max),
523
	SYNAPTICS_SYSCTL_TOUCHPAD_OFF =		SYN_OFFSET(touchpad_off),
524
	SYNAPTICS_SYSCTL_SOFTBUTTONS_Y =	SYN_OFFSET(softbuttons_y),
525
	SYNAPTICS_SYSCTL_SOFTBUTTON2_X =	SYN_OFFSET(softbutton2_x),
526
	SYNAPTICS_SYSCTL_SOFTBUTTON3_X =	SYN_OFFSET(softbutton3_x),
527
};
528
414
/* packet formatting function */
529
/* packet formatting function */
415
typedef int	packetfunc_t(struct psm_softc *, u_char *, int *, int,
530
typedef int	packetfunc_t(struct psm_softc *, u_char *, int *, int,
416
    mousestatus_t *);
531
    mousestatus_t *);
Lines 446-451 static int doopen(struct psm_softc *, int); Link Here
446
static int	reinitialize(struct psm_softc *, int);
561
static int	reinitialize(struct psm_softc *, int);
447
static char	*model_name(int);
562
static char	*model_name(int);
448
static void	psmsoftintr(void *);
563
static void	psmsoftintr(void *);
564
static void	psmsoftintridle(void *);
449
static void	psmintr(void *);
565
static void	psmintr(void *);
450
static void	psmtimeout(void *);
566
static void	psmtimeout(void *);
451
static int	timeelapsed(const struct timeval *, int, int,
567
static int	timeelapsed(const struct timeval *, int, int,
Lines 458-463 static int proc_synaptics(struct psm_softc *, packetbuf_t *, Link Here
458
		    mousestatus_t *, int *, int *, int *);
574
		    mousestatus_t *, int *, int *, int *);
459
static void	proc_versapad(struct psm_softc *, packetbuf_t *,
575
static void	proc_versapad(struct psm_softc *, packetbuf_t *,
460
		    mousestatus_t *, int *, int *, int *);
576
		    mousestatus_t *, int *, int *, int *);
577
static int	proc_elantech(struct psm_softc *, packetbuf_t *,
578
		    mousestatus_t *, int *, int *, int *);
579
static int	psmpalmdetect(struct psm_softc *, finger_t *, int);
580
static void	psmgestures(struct psm_softc *, finger_t *, int,
581
		    mousestatus_t *);
582
static void	psmsmoother(struct psm_softc *, finger_t *, int,
583
		    mousestatus_t *, int *, int *);
584
static int	psmsoftbuttons(struct psm_softc *, finger_t *, int);
461
static int	tame_mouse(struct psm_softc *, packetbuf_t *, mousestatus_t *,
585
static int	tame_mouse(struct psm_softc *, packetbuf_t *, mousestatus_t *,
462
		    u_char *);
586
		    u_char *);
463
587
Lines 480-485 static probefunc_t enable_mmanplus; Link Here
480
static probefunc_t	enable_synaptics;
604
static probefunc_t	enable_synaptics;
481
static probefunc_t	enable_trackpoint;
605
static probefunc_t	enable_trackpoint;
482
static probefunc_t	enable_versapad;
606
static probefunc_t	enable_versapad;
607
static probefunc_t	enable_elantech;
483
608
484
static void set_trackpoint_parameters(struct psm_softc *sc);
609
static void set_trackpoint_parameters(struct psm_softc *sc);
485
static void synaptics_passthrough_on(struct psm_softc *sc);
610
static void synaptics_passthrough_on(struct psm_softc *sc);
Lines 511-516 static struct { Link Here
511
	  0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus },
636
	  0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus },
512
	{ MOUSE_MODEL_SYNAPTICS,	/* Synaptics Touchpad */
637
	{ MOUSE_MODEL_SYNAPTICS,	/* Synaptics Touchpad */
513
	  0xc0, MOUSE_SYNAPTICS_PACKETSIZE, enable_synaptics },
638
	  0xc0, MOUSE_SYNAPTICS_PACKETSIZE, enable_synaptics },
639
	{ MOUSE_MODEL_ELANTECH,		/* Elantech Touchpad */
640
	  0x04, MOUSE_ELANTECH_PACKETSIZE, enable_elantech },
514
	{ MOUSE_MODEL_INTELLI,		/* Microsoft IntelliMouse */
641
	{ MOUSE_MODEL_INTELLI,		/* Microsoft IntelliMouse */
515
	  0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli },
642
	  0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli },
516
	{ MOUSE_MODEL_GLIDEPOINT,	/* ALPS GlidePoint */
643
	{ MOUSE_MODEL_GLIDEPOINT,	/* ALPS GlidePoint */
Lines 762-767 model_name(int model) Link Here
762
		{ MOUSE_MODEL_4DPLUS,		"4D+ Mouse" },
889
		{ MOUSE_MODEL_4DPLUS,		"4D+ Mouse" },
763
		{ MOUSE_MODEL_SYNAPTICS,	"Synaptics Touchpad" },
890
		{ MOUSE_MODEL_SYNAPTICS,	"Synaptics Touchpad" },
764
		{ MOUSE_MODEL_TRACKPOINT,	"IBM/Lenovo TrackPoint" },
891
		{ MOUSE_MODEL_TRACKPOINT,	"IBM/Lenovo TrackPoint" },
892
		{ MOUSE_MODEL_ELANTECH,		"Elantech Touchpad" },
765
		{ MOUSE_MODEL_GENERIC,		"Generic PS/2 mouse" },
893
		{ MOUSE_MODEL_GENERIC,		"Generic PS/2 mouse" },
766
		{ MOUSE_MODEL_UNKNOWN,		"Unknown" },
894
		{ MOUSE_MODEL_UNKNOWN,		"Unknown" },
767
	};
895
	};
Lines 1504-1509 psmattach(device_t dev) Link Here
1504
	case MOUSE_MODEL_SYNAPTICS:
1632
	case MOUSE_MODEL_SYNAPTICS:
1505
	case MOUSE_MODEL_GLIDEPOINT:
1633
	case MOUSE_MODEL_GLIDEPOINT:
1506
	case MOUSE_MODEL_VERSAPAD:
1634
	case MOUSE_MODEL_VERSAPAD:
1635
	case MOUSE_MODEL_ELANTECH:
1507
		sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
1636
		sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
1508
		break;
1637
		break;
1509
	default:
1638
	default:
Lines 1512-1517 psmattach(device_t dev) Link Here
1512
		break;
1641
		break;
1513
	}
1642
	}
1514
1643
1644
	/* Elantech trackpad`s sync bit differs from touchpad`s one */
1645
	if (sc->hw.model == MOUSE_MODEL_ELANTECH &&
1646
	    (sc->elanhw.hascrc || sc->elanhw.hastrackpad))
1647
		sc->config |= PSM_CONFIG_NOCHECKSYNC;
1648
1515
	if (!verbose)
1649
	if (!verbose)
1516
		printf("psm%d: model %s, device ID %d\n",
1650
		printf("psm%d: model %s, device ID %d\n",
1517
		    unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
1651
		    unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
Lines 2627-2633 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
2627
{
2761
{
2628
	static int touchpad_buttons;
2762
	static int touchpad_buttons;
2629
	static int guest_buttons;
2763
	static int guest_buttons;
2630
	int w, x0, y0;
2764
	finger_t f;
2765
	int w, nfingers;
2631
2766
2632
	/* TouchPad PS/2 absolute mode message format with capFourButtons:
2767
	/* TouchPad PS/2 absolute mode message format with capFourButtons:
2633
	 *
2768
	 *
Lines 2806-2812 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
2806
			pb->ipacket[4] &= ~(mask);
2941
			pb->ipacket[4] &= ~(mask);
2807
			pb->ipacket[5] &= ~(mask);
2942
			pb->ipacket[5] &= ~(mask);
2808
		} else	if (!sc->syninfo.directional_scrolls &&
2943
		} else	if (!sc->syninfo.directional_scrolls &&
2809
		    !sc->synaction.in_vscroll) {
2944
		    !sc->gesture.in_vscroll) {
2810
			/*
2945
			/*
2811
			 * Keep reporting MOUSE DOWN until we get a new packet
2946
			 * Keep reporting MOUSE DOWN until we get a new packet
2812
			 * indicating otherwise.
2947
			 * indicating otherwise.
Lines 2814-2906 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
2814
			touchpad_buttons |= sc->extended_buttons;
2949
			touchpad_buttons |= sc->extended_buttons;
2815
		}
2950
		}
2816
	}
2951
	}
2952
2953
	f.x = ((pb->ipacket[3] & 0x10) << 8) |
2954
	    ((pb->ipacket[1] & 0x0f) << 8) |
2955
	    pb->ipacket[4];
2956
	f.y = ((pb->ipacket[3] & 0x20) << 7) |
2957
	    ((pb->ipacket[1] & 0xf0) << 4) |
2958
	    pb->ipacket[5];
2959
	f.p = *z;
2960
	f.w = w;
2961
	f.flags = w == 2 ? PSM_FINGER_IS_PEN : 0;
2962
	f.flags |= w < 2 ? PSM_FINGER_FUZZY : 0;
2963
	nfingers = w < 2 ? w + 2 : 1;
2964
2817
	/* Handle ClickPad. */
2965
	/* Handle ClickPad. */
2818
	if (sc->synhw.capClickPad &&
2966
	if (sc->synhw.capClickPad)
2819
	    ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x01))
2967
		touchpad_buttons |= psmsoftbuttons(sc, &f,
2820
		touchpad_buttons |= MOUSE_BUTTON1DOWN;
2968
		    (pb->ipacket[0] ^ pb->ipacket[3]) & 0x01);
2821
2969
2822
	ms->button = touchpad_buttons | guest_buttons;
2970
	ms->button = touchpad_buttons | guest_buttons;
2823
2971
2972
	/* Palm detection doesn't terminate the current action. */
2973
	if (!psmpalmdetect(sc, &f, nfingers)) {
2974
		psmgestures(sc, &f, nfingers, ms);
2975
		psmsmoother(sc, &f, 0, ms, x, y);
2976
	} else {
2977
		VLOG(2, (LOG_DEBUG, "synaptics: palm detected! (%d)\n", f.w));
2978
	}
2979
2980
SYNAPTICS_END:
2981
	/*
2982
	 * Use the extra buttons as a scrollwheel
2983
	 *
2984
	 * XXX X.Org uses the Z axis for vertical wheel only,
2985
	 * whereas moused(8) understands special values to differ
2986
	 * vertical and horizontal wheels.
2987
	 *
2988
	 * xf86-input-mouse needs therefore a small patch to
2989
	 * understand these special values. Without it, the
2990
	 * horizontal wheel acts as a vertical wheel in X.Org.
2991
	 *
2992
	 * That's why the horizontal wheel is disabled by
2993
	 * default for now.
2994
	 */
2995
	if (ms->button & MOUSE_BUTTON4DOWN) {
2996
		*z = -1;
2997
		ms->button &= ~MOUSE_BUTTON4DOWN;
2998
	} else if (ms->button & MOUSE_BUTTON5DOWN) {
2999
		*z = 1;
3000
		ms->button &= ~MOUSE_BUTTON5DOWN;
3001
	} else if (ms->button & MOUSE_BUTTON6DOWN) {
3002
		*z = -2;
3003
		ms->button &= ~MOUSE_BUTTON6DOWN;
3004
	} else if (ms->button & MOUSE_BUTTON7DOWN) {
3005
		*z = 2;
3006
		ms->button &= ~MOUSE_BUTTON7DOWN;
3007
	} else
3008
		*z = 0;
3009
3010
	return (0);
3011
}
3012
3013
static int
3014
psmpalmdetect(struct psm_softc *sc, finger_t *f, int nfingers)
3015
{
3016
	if (!(
3017
	    ((sc->synhw.capMultiFinger ||
3018
	      sc->synhw.capAdvancedGestures) && nfingers > 1) ||
3019
	    (sc->synhw.capPalmDetect && f->w <= sc->syninfo.max_width) ||
3020
	    (!sc->synhw.capPalmDetect && f->p <= sc->syninfo.max_pressure) ||
3021
	    (sc->synhw.capPen && f->flags & PSM_FINGER_IS_PEN))) {
3022
		/*
3023
		 * We consider the packet irrelevant for the current
3024
		 * action when:
3025
		 *  - the width isn't comprised in:
3026
		 *    [1; max_width]
3027
		 *  - the pressure isn't comprised in:
3028
		 *    [min_pressure; max_pressure]
3029
		 *  - pen aren't supported but PSM_FINGER_IS_PEN is set
3030
		 */
3031
		return (1);
3032
	}
3033
	return (0);
3034
}
3035
3036
static void
3037
psmgestures(struct psm_softc *sc, finger_t *f, int nfingers, mousestatus_t *ms)
3038
{
3039
	smoother_t *smoother;
3040
	gesture_t *gest;
3041
3042
	smoother = &sc->smoother[0];
3043
	gest = &sc->gesture;
3044
2824
	/*
3045
	/*
2825
	 * Check pressure to detect a real wanted action on the
3046
	 * Check pressure to detect a real wanted action on the
2826
	 * touchpad.
3047
	 * touchpad.
2827
	 */
3048
	 */
2828
	if (*z >= sc->syninfo.min_pressure) {
3049
	if (f->p >= sc->syninfo.min_pressure) {
2829
		synapticsaction_t *synaction;
3050
		int x0, y0;
2830
		int cursor, peer, window;
3051
		int dxp, dyp;
2831
		int dx, dy, dxp, dyp;
2832
		int max_width, max_pressure;
2833
		int margin_top, margin_right, margin_bottom, margin_left;
3052
		int margin_top, margin_right, margin_bottom, margin_left;
2834
		int na_top, na_right, na_bottom, na_left;
2835
		int window_min, window_max;
3053
		int window_min, window_max;
2836
		int multiplicator;
2837
		int weight_current, weight_previous, weight_len_squared;
2838
		int div_min, div_max, div_len;
2839
		int vscroll_hor_area, vscroll_ver_area;
3054
		int vscroll_hor_area, vscroll_ver_area;
2840
		int two_finger_scroll;
3055
		int two_finger_scroll;
2841
		int len, weight_prev_x, weight_prev_y;
3056
		int max_x, max_y;
2842
		int div_max_x, div_max_y, div_x, div_y;
2843
		int exiting_scroll;
2844
3057
2845
		/* Read sysctl. */
3058
		/* Read sysctl. */
2846
		/* XXX Verify values? */
3059
		/* XXX Verify values? */
2847
		max_width = sc->syninfo.max_width;
2848
		max_pressure = sc->syninfo.max_pressure;
2849
		margin_top = sc->syninfo.margin_top;
3060
		margin_top = sc->syninfo.margin_top;
2850
		margin_right = sc->syninfo.margin_right;
3061
		margin_right = sc->syninfo.margin_right;
2851
		margin_bottom = sc->syninfo.margin_bottom;
3062
		margin_bottom = sc->syninfo.margin_bottom;
2852
		margin_left = sc->syninfo.margin_left;
3063
		margin_left = sc->syninfo.margin_left;
2853
		na_top = sc->syninfo.na_top;
2854
		na_right = sc->syninfo.na_right;
2855
		na_bottom = sc->syninfo.na_bottom;
2856
		na_left = sc->syninfo.na_left;
2857
		window_min = sc->syninfo.window_min;
3064
		window_min = sc->syninfo.window_min;
2858
		window_max = sc->syninfo.window_max;
3065
		window_max = sc->syninfo.window_max;
2859
		multiplicator = sc->syninfo.multiplicator;
2860
		weight_current = sc->syninfo.weight_current;
2861
		weight_previous = sc->syninfo.weight_previous;
2862
		weight_len_squared = sc->syninfo.weight_len_squared;
2863
		div_min = sc->syninfo.div_min;
2864
		div_max = sc->syninfo.div_max;
2865
		div_len = sc->syninfo.div_len;
2866
		vscroll_hor_area = sc->syninfo.vscroll_hor_area;
3066
		vscroll_hor_area = sc->syninfo.vscroll_hor_area;
2867
		vscroll_ver_area = sc->syninfo.vscroll_ver_area;
3067
		vscroll_ver_area = sc->syninfo.vscroll_ver_area;
2868
		two_finger_scroll = sc->syninfo.two_finger_scroll;
3068
		two_finger_scroll = sc->syninfo.two_finger_scroll;
2869
3069
		max_x = sc->synhw.maximumXCoord;
2870
		exiting_scroll = 0;
3070
		max_y = sc->synhw.maximumYCoord;
2871
2872
		/* Palm detection. */
2873
		if (!(
2874
		    ((sc->synhw.capMultiFinger ||
2875
		      sc->synhw.capAdvancedGestures) && (w == 0 || w == 1)) ||
2876
		    (sc->synhw.capPalmDetect && w >= 4 && w <= max_width) ||
2877
		    (!sc->synhw.capPalmDetect && *z <= max_pressure) ||
2878
		    (sc->synhw.capPen && w == 2))) {
2879
			/*
2880
			 * We consider the packet irrelevant for the current
2881
			 * action when:
2882
			 *  - the width isn't comprised in:
2883
			 *    [4; max_width]
2884
			 *  - the pressure isn't comprised in:
2885
			 *    [min_pressure; max_pressure]
2886
			 *  - pen aren't supported but w is 2
2887
			 *
2888
			 *  Note that this doesn't terminate the current action.
2889
			 */
2890
			VLOG(2, (LOG_DEBUG,
2891
			    "synaptics: palm detected! (%d)\n", w));
2892
			goto SYNAPTICS_END;
2893
		}
2894
3071
2895
		/* Read current absolute position. */
3072
		/* Read current absolute position. */
2896
		x0 = ((pb->ipacket[3] & 0x10) << 8) |
3073
		x0 = f->x;
2897
		    ((pb->ipacket[1] & 0x0f) << 8) |
3074
		y0 = f->y;
2898
		    pb->ipacket[4];
3075
2899
		y0 = ((pb->ipacket[3] & 0x20) << 7) |
3076
		/*
2900
		    ((pb->ipacket[1] & 0xf0) << 4) |
3077
		 * Limit the coordinates to the specified margins because
2901
		    pb->ipacket[5];
3078
		 * this area isn't very reliable.
3079
		 */
3080
		if (x0 <= margin_left)
3081
			x0 = margin_left;
3082
		else if (x0 >= max_x - margin_right)
3083
			x0 = max_x - margin_right;
3084
		if (y0 <= margin_bottom)
3085
			y0 = margin_bottom;
3086
		else if (y0 >= max_y - margin_top)
3087
			y0 = max_y - margin_top;
2902
3088
2903
		synaction = &(sc->synaction);
3089
		VLOG(3, (LOG_DEBUG, "synaptics: ipacket: [%d, %d], %d, %d\n",
3090
		    x0, y0, f->p, f->w));
2904
3091
2905
		/*
3092
		/*
2906
		 * If the action is just beginning, init the structure and
3093
		 * If the action is just beginning, init the structure and
Lines 2909-3015 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
2909
		if (!(sc->flags & PSM_FLAGS_FINGERDOWN)) {
3096
		if (!(sc->flags & PSM_FLAGS_FINGERDOWN)) {
2910
			VLOG(3, (LOG_DEBUG, "synaptics: ----\n"));
3097
			VLOG(3, (LOG_DEBUG, "synaptics: ----\n"));
2911
3098
2912
			/* Store the first point of this action. */
2913
			synaction->start_x = x0;
2914
			synaction->start_y = y0;
2915
			dx = dy = 0;
2916
2917
			/* Initialize queue. */
3099
			/* Initialize queue. */
2918
			synaction->queue_cursor = SYNAPTICS_PACKETQUEUE;
3100
			gest->window_min = window_min;
2919
			synaction->queue_len = 0;
2920
			synaction->window_min = window_min;
2921
2922
			/* Reset average. */
2923
			synaction->avg_dx = 0;
2924
			synaction->avg_dy = 0;
2925
2926
			/* Reset squelch. */
2927
			synaction->squelch_x = 0;
2928
			synaction->squelch_y = 0;
2929
3101
2930
			/* Reset pressure peak. */
3102
			/* Reset pressure peak. */
2931
			sc->zmax = 0;
3103
			gest->zmax = 0;
2932
3104
2933
			/* Reset fingers count. */
3105
			/* Reset fingers count. */
2934
			synaction->fingers_nb = 0;
3106
			gest->fingers_nb = 0;
2935
3107
2936
			/* Reset virtual scrolling state. */
3108
			/* Reset virtual scrolling state. */
2937
			synaction->in_vscroll = 0;
3109
			gest->in_vscroll = 0;
2938
3110
2939
			/* Compute tap timeout. */
3111
			/* Compute tap timeout. */
2940
			sc->taptimeout.tv_sec  = tap_timeout / 1000000;
3112
			gest->taptimeout.tv_sec  = tap_timeout / 1000000;
2941
			sc->taptimeout.tv_usec = tap_timeout % 1000000;
3113
			gest->taptimeout.tv_usec = tap_timeout % 1000000;
2942
			timevaladd(&sc->taptimeout, &sc->lastsoftintr);
3114
			timevaladd(&gest->taptimeout, &sc->lastsoftintr);
2943
3115
2944
			sc->flags |= PSM_FLAGS_FINGERDOWN;
3116
			sc->flags |= PSM_FLAGS_FINGERDOWN;
2945
		} else {
2946
			/* Calculate the current delta. */
2947
			cursor = synaction->queue_cursor;
2948
			dx = x0 - synaction->queue[cursor].x;
2949
			dy = y0 - synaction->queue[cursor].y;
2950
		}
3117
		}
2951
3118
2952
		/* If in tap-hold, add the recorded button. */
3119
		/* If in tap-hold, add the recorded button. */
2953
		if (synaction->in_taphold)
3120
		if (gest->in_taphold)
2954
			ms->button |= synaction->tap_button;
3121
			ms->button |= gest->tap_button;
2955
2956
		/*
2957
		 * From now on, we can use the SYNAPTICS_END label to skip
2958
		 * the current packet.
2959
		 */
2960
2961
		/*
2962
		 * Limit the coordinates to the specified margins because
2963
		 * this area isn't very reliable.
2964
		 */
2965
		if (x0 <= margin_left)
2966
			x0 = margin_left;
2967
		else if (x0 >= 6143 - margin_right)
2968
			x0 = 6143 - margin_right;
2969
		if (y0 <= margin_bottom)
2970
			y0 = margin_bottom;
2971
		else if (y0 >= 6143 - margin_top)
2972
			y0 = 6143 - margin_top;
2973
2974
		VLOG(3, (LOG_DEBUG, "synaptics: ipacket: [%d, %d], %d, %d\n",
2975
		    x0, y0, *z, w));
2976
2977
		/* Queue this new packet. */
2978
		cursor = SYNAPTICS_QUEUE_CURSOR(synaction->queue_cursor - 1);
2979
		synaction->queue[cursor].x = x0;
2980
		synaction->queue[cursor].y = y0;
2981
		synaction->queue_cursor = cursor;
2982
		if (synaction->queue_len < SYNAPTICS_PACKETQUEUE)
2983
			synaction->queue_len++;
2984
		VLOG(5, (LOG_DEBUG,
2985
		    "synaptics: cursor[%d]: x=%d, y=%d, dx=%d, dy=%d\n",
2986
		    cursor, x0, y0, dx, dy));
2987
3122
2988
		/*
3123
		/*
2989
		 * For tap, we keep the maximum number of fingers and the
3124
		 * For tap, we keep the maximum number of fingers and the
2990
		 * pressure peak. Also with multiple fingers, we increase
3125
		 * pressure peak. Also with multiple fingers, we increase
2991
		 * the minimum window.
3126
		 * the minimum window.
2992
		 */
3127
		 */
2993
		switch (w) {
3128
		if (nfingers > 1)
2994
		case 1: /* Three or more fingers. */
3129
			gest->window_min = window_max;
2995
			synaction->fingers_nb = imax(3, synaction->fingers_nb);
3130
		gest->fingers_nb = imax(nfingers, gest->fingers_nb);
2996
			synaction->window_min = window_max;
3131
		gest->zmax = imax(f->p, gest->zmax);
2997
			break;
2998
		case 0: /* Two fingers. */
2999
			synaction->fingers_nb = imax(2, synaction->fingers_nb);
3000
			synaction->window_min = window_max;
3001
			break;
3002
		default: /* One finger or undetectable. */
3003
			synaction->fingers_nb = imax(1, synaction->fingers_nb);
3004
		}
3005
		sc->zmax = imax(*z, sc->zmax);
3006
3132
3007
		/* Do we have enough packets to consider this a movement? */
3133
		/* Do we have enough packets to consider this a gesture? */
3008
		if (synaction->queue_len < synaction->window_min)
3134
		if (smoother->queue_len + 1 < gest->window_min)
3009
			goto SYNAPTICS_END;
3135
			return;
3010
3136
3011
		/* Is a scrolling action occurring? */
3137
		/* Is a scrolling action occurring? */
3012
		if (!synaction->in_taphold && !synaction->in_vscroll) {
3138
		if (!gest->in_taphold && !ms->button &&
3139
		    (!gest->in_vscroll || two_finger_scroll)) {
3013
			/*
3140
			/*
3014
			 * A scrolling action must not conflict with a tap
3141
			 * A scrolling action must not conflict with a tap
3015
			 * action. Here are the conditions to consider a
3142
			 * action. Here are the conditions to consider a
Lines 3020-3031 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3020
			 *       first should be above a configurable minimum
3147
			 *       first should be above a configurable minimum
3021
			 *     . tap timed out
3148
			 *     . tap timed out
3022
			 */
3149
			 */
3023
			dxp = abs(synaction->queue[synaction->queue_cursor].x -
3150
			dxp = abs(x0 - smoother->start_x);
3024
			    synaction->start_x);
3151
			dyp = abs(y0 - smoother->start_y);
3025
			dyp = abs(synaction->queue[synaction->queue_cursor].y -
3026
			    synaction->start_y);
3027
3152
3028
			if (timevalcmp(&sc->lastsoftintr, &sc->taptimeout, >) ||
3153
			if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, >) ||
3029
			    dxp >= sc->syninfo.vscroll_min_delta ||
3154
			    dxp >= sc->syninfo.vscroll_min_delta ||
3030
			    dyp >= sc->syninfo.vscroll_min_delta) {
3155
			    dyp >= sc->syninfo.vscroll_min_delta) {
3031
				/*
3156
				/*
Lines 3034-3209 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3034
				 * as that keeps the maximum number of fingers.
3159
				 * as that keeps the maximum number of fingers.
3035
				 */
3160
				 */
3036
				if (two_finger_scroll) {
3161
				if (two_finger_scroll) {
3037
					if (w == 0) {
3162
					if (nfingers == 2) {
3038
						synaction->in_vscroll +=
3163
						gest->in_vscroll +=
3039
						    dyp ? 2 : 0;
3164
						    dyp ? 2 : 0;
3040
						synaction->in_vscroll +=
3165
						gest->in_vscroll +=
3041
						    dxp ? 1 : 0;
3166
						    dxp ? 1 : 0;
3042
					}
3167
					}
3043
				} else {
3168
				} else {
3044
					/* Check for horizontal scrolling. */
3169
					/* Check for horizontal scrolling. */
3045
					if ((vscroll_hor_area > 0 &&
3170
					if ((vscroll_hor_area > 0 &&
3046
					    synaction->start_y <=
3171
					    smoother->start_y <=
3047
					        vscroll_hor_area) ||
3172
					        vscroll_hor_area) ||
3048
					    (vscroll_hor_area < 0 &&
3173
					    (vscroll_hor_area < 0 &&
3049
					     synaction->start_y >=
3174
					     smoother->start_y >=
3050
					     6143 + vscroll_hor_area))
3175
					     max_y + vscroll_hor_area))
3051
						synaction->in_vscroll += 2;
3176
						gest->in_vscroll += 2;
3052
3177
3053
					/* Check for vertical scrolling. */
3178
					/* Check for vertical scrolling. */
3054
					if ((vscroll_ver_area > 0 &&
3179
					if ((vscroll_ver_area > 0 &&
3055
					    synaction->start_x <=
3180
					    smoother->start_x <=
3056
						vscroll_ver_area) ||
3181
						vscroll_ver_area) ||
3057
					    (vscroll_ver_area < 0 &&
3182
					    (vscroll_ver_area < 0 &&
3058
					     synaction->start_x >=
3183
					     smoother->start_x >=
3059
					     6143 + vscroll_ver_area))
3184
					     max_x + vscroll_ver_area))
3060
						synaction->in_vscroll += 1;
3185
						gest->in_vscroll += 1;
3061
				}
3186
				}
3062
3187
3063
				/* Avoid conflicts if area overlaps. */
3188
				/* Avoid conflicts if area overlaps. */
3064
				if (synaction->in_vscroll >= 3)
3189
				if (gest->in_vscroll >= 3)
3065
					synaction->in_vscroll =
3190
					gest->in_vscroll =
3066
					    (dxp > dyp) ? 2 : 1;
3191
					    (dxp > dyp) ? 2 : 1;
3067
			}
3192
			}
3068
		}
3193
		}
3069
		/*
3194
		/*
3070
		 * Reset two finger scrolling when the number of fingers
3195
		 * Reset two finger scrolling when the number of fingers
3071
		 * is different from two.
3196
		 * is different from two or any button is pressed.
3072
		 */
3197
		 */
3073
		if (two_finger_scroll && w != 0 && synaction->in_vscroll != 0) {
3198
		if (two_finger_scroll && gest->in_vscroll != 0 &&
3074
			synaction->in_vscroll = 0;
3199
		    (nfingers != 2 || ms->button))
3075
			exiting_scroll = 1;
3200
			gest->in_vscroll = 0;
3076
		}
3077
3201
3078
		VLOG(5, (LOG_DEBUG,
3202
		VLOG(5, (LOG_DEBUG,
3079
			"synaptics: virtual scrolling: %s "
3203
			"synaptics: virtual scrolling: %s "
3080
			"(direction=%d, dxp=%d, dyp=%d, fingers=%d)\n",
3204
			"(direction=%d, dxp=%d, dyp=%d, fingers=%d)\n",
3081
			synaction->in_vscroll ? "YES" : "NO",
3205
			gest->in_vscroll ? "YES" : "NO",
3082
			synaction->in_vscroll, dxp, dyp,
3206
			gest->in_vscroll, dxp, dyp,
3083
			synaction->fingers_nb));
3207
			gest->fingers_nb));
3084
3085
		weight_prev_x = weight_prev_y = weight_previous;
3086
		div_max_x = div_max_y = div_max;
3087
3088
		if (synaction->in_vscroll) {
3089
			/* Dividers are different with virtual scrolling. */
3090
			div_min = sc->syninfo.vscroll_div_min;
3091
			div_max_x = div_max_y = sc->syninfo.vscroll_div_max;
3092
		} else {
3093
			/*
3094
			 * There's a lot of noise in coordinates when
3095
			 * the finger is on the touchpad's borders. When
3096
			 * using this area, we apply a special weight and
3097
			 * div.
3098
			 */
3099
			if (x0 <= na_left || x0 >= 6143 - na_right) {
3100
				weight_prev_x = sc->syninfo.weight_previous_na;
3101
				div_max_x = sc->syninfo.div_max_na;
3102
			}
3103
3104
			if (y0 <= na_bottom || y0 >= 6143 - na_top) {
3105
				weight_prev_y = sc->syninfo.weight_previous_na;
3106
				div_max_y = sc->syninfo.div_max_na;
3107
			}
3108
		}
3109
3110
		/*
3111
		 * Calculate weights for the average operands and
3112
		 * the divisor. Both depend on the distance between
3113
		 * the current packet and a previous one (based on the
3114
		 * window width).
3115
		 */
3116
		window = imin(synaction->queue_len, window_max);
3117
		peer = SYNAPTICS_QUEUE_CURSOR(cursor + window - 1);
3118
		dxp = abs(x0 - synaction->queue[peer].x) + 1;
3119
		dyp = abs(y0 - synaction->queue[peer].y) + 1;
3120
		len = (dxp * dxp) + (dyp * dyp);
3121
		weight_prev_x = imin(weight_prev_x,
3122
		    weight_len_squared * weight_prev_x / len);
3123
		weight_prev_y = imin(weight_prev_y,
3124
		    weight_len_squared * weight_prev_y / len);
3125
3126
		len = (dxp + dyp) / 2;
3127
		div_x = div_len * div_max_x / len;
3128
		div_x = imin(div_max_x, div_x);
3129
		div_x = imax(div_min, div_x);
3130
		div_y = div_len * div_max_y / len;
3131
		div_y = imin(div_max_y, div_y);
3132
		div_y = imax(div_min, div_y);
3133
3134
		VLOG(3, (LOG_DEBUG,
3135
		    "synaptics: peer=%d, len=%d, weight=%d/%d, div=%d/%d\n",
3136
		    peer, len, weight_prev_x, weight_prev_y, div_x, div_y));
3137
3138
		/* Compute averages. */
3139
		synaction->avg_dx =
3140
		    (weight_current * dx * multiplicator +
3141
		     weight_prev_x * synaction->avg_dx) /
3142
		    (weight_current + weight_prev_x);
3143
3144
		synaction->avg_dy =
3145
		    (weight_current * dy * multiplicator +
3146
		     weight_prev_y * synaction->avg_dy) /
3147
		    (weight_current + weight_prev_y);
3148
3149
		VLOG(5, (LOG_DEBUG,
3150
		    "synaptics: avg_dx~=%d, avg_dy~=%d\n",
3151
		    synaction->avg_dx / multiplicator,
3152
		    synaction->avg_dy / multiplicator));
3153
3154
		/* Use these averages to calculate x & y. */
3155
		synaction->squelch_x += synaction->avg_dx;
3156
		*x = synaction->squelch_x / (div_x * multiplicator);
3157
		synaction->squelch_x = synaction->squelch_x %
3158
		    (div_x * multiplicator);
3159
3160
		synaction->squelch_y += synaction->avg_dy;
3161
		*y = synaction->squelch_y / (div_y * multiplicator);
3162
		synaction->squelch_y = synaction->squelch_y %
3163
		    (div_y * multiplicator);
3164
3208
3165
		if (synaction->in_vscroll) {
3166
			switch(synaction->in_vscroll) {
3167
			case 1: /* Vertical scrolling. */
3168
				if (*y != 0)
3169
					ms->button |= (*y > 0) ?
3170
					    MOUSE_BUTTON4DOWN :
3171
					    MOUSE_BUTTON5DOWN;
3172
				break;
3173
			case 2: /* Horizontal scrolling. */
3174
				if (*x != 0)
3175
					ms->button |= (*x > 0) ?
3176
					    MOUSE_BUTTON7DOWN :
3177
					    MOUSE_BUTTON6DOWN;
3178
				break;
3179
			}
3180
3181
			/* The pointer is not moved. */
3182
			*x = *y = 0;
3183
		} else {
3184
			/* On exit the x/y pos may jump, ignore this */
3185
			if (exiting_scroll)
3186
				*x = *y = 0;
3187
3188
			VLOG(3, (LOG_DEBUG, "synaptics: [%d, %d] -> [%d, %d]\n",
3189
			    dx, dy, *x, *y));
3190
		}
3191
	} else if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3209
	} else if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3192
		/*
3210
		/*
3193
		 * An action is currently taking place but the pressure
3211
		 * An action is currently taking place but the pressure
3194
		 * dropped under the minimum, putting an end to it.
3212
		 * dropped under the minimum, putting an end to it.
3195
		 */
3213
		 */
3196
		synapticsaction_t *synaction;
3197
		int taphold_timeout, dx, dy, tap_max_delta;
3214
		int taphold_timeout, dx, dy, tap_max_delta;
3198
3215
3199
		synaction = &(sc->synaction);
3216
		dx = abs(smoother->queue[smoother->queue_cursor].x -
3200
		dx = abs(synaction->queue[synaction->queue_cursor].x -
3217
		    smoother->start_x);
3201
		    synaction->start_x);
3218
		dy = abs(smoother->queue[smoother->queue_cursor].y -
3202
		dy = abs(synaction->queue[synaction->queue_cursor].y -
3219
		    smoother->start_y);
3203
		    synaction->start_y);
3204
3220
3205
		/* Max delta is disabled for multi-fingers tap. */
3221
		/* Max delta is disabled for multi-fingers tap. */
3206
		if (synaction->fingers_nb > 1)
3222
		if (gest->fingers_nb > 1)
3207
			tap_max_delta = imax(dx, dy);
3223
			tap_max_delta = imax(dx, dy);
3208
		else
3224
		else
3209
			tap_max_delta = sc->syninfo.tap_max_delta;
3225
			tap_max_delta = sc->syninfo.tap_max_delta;
Lines 3214-3225 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3214
		VLOG(3, (LOG_DEBUG,
3230
		VLOG(3, (LOG_DEBUG,
3215
		    "synaptics: zmax=%d, dx=%d, dy=%d, "
3231
		    "synaptics: zmax=%d, dx=%d, dy=%d, "
3216
		    "delta=%d, fingers=%d, queue=%d\n",
3232
		    "delta=%d, fingers=%d, queue=%d\n",
3217
		    sc->zmax, dx, dy, tap_max_delta, synaction->fingers_nb,
3233
		    gest->zmax, dx, dy, tap_max_delta, gest->fingers_nb,
3218
		    synaction->queue_len));
3234
		    smoother->queue_len));
3219
		if (!synaction->in_vscroll && sc->zmax >= tap_threshold &&
3235
		if (!gest->in_vscroll && gest->zmax >= tap_threshold &&
3220
		    timevalcmp(&sc->lastsoftintr, &sc->taptimeout, <=) &&
3236
		    timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=) &&
3221
		    dx <= tap_max_delta && dy <= tap_max_delta &&
3237
		    dx <= tap_max_delta && dy <= tap_max_delta &&
3222
		    synaction->queue_len >= sc->syninfo.tap_min_queue) {
3238
		    smoother->queue_len >= sc->syninfo.tap_min_queue) {
3223
			/*
3239
			/*
3224
			 * We have a tap if:
3240
			 * We have a tap if:
3225
			 *   - the maximum pressure went over tap_threshold
3241
			 *   - the maximum pressure went over tap_threshold
Lines 3228-3239 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3228
			 * To handle tap-hold, we must delay any button push to
3244
			 * To handle tap-hold, we must delay any button push to
3229
			 * the next action.
3245
			 * the next action.
3230
			 */
3246
			 */
3231
			if (synaction->in_taphold) {
3247
			if (gest->in_taphold) {
3232
				/*
3248
				/*
3233
				 * This is the second and last tap of a
3249
				 * This is the second and last tap of a
3234
				 * double tap action, not a tap-hold.
3250
				 * double tap action, not a tap-hold.
3235
				 */
3251
				 */
3236
				synaction->in_taphold = 0;
3252
				gest->in_taphold = 0;
3237
3253
3238
				/*
3254
				/*
3239
				 * For double-tap to work:
3255
				 * For double-tap to work:
Lines 3245-3367 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3245
				 */
3261
				 */
3246
				VLOG(2, (LOG_DEBUG,
3262
				VLOG(2, (LOG_DEBUG,
3247
				    "synaptics: button RELEASE: %d\n",
3263
				    "synaptics: button RELEASE: %d\n",
3248
				    synaction->tap_button));
3264
				    gest->tap_button));
3249
				sc->flags |= PSM_FLAGS_FINGERDOWN;
3265
				sc->flags |= PSM_FLAGS_FINGERDOWN;
3266
3267
				/* Schedule button press on next interrupt */
3268
				sc->idletimeout.tv_sec  = psmhz > 1 ?
3269
				    0 : 1;
3270
				sc->idletimeout.tv_usec = psmhz > 1 ?
3271
				    1000000 / psmhz : 0;
3250
			} else {
3272
			} else {
3251
				/*
3273
				/*
3252
				 * This is the first tap: we set the
3274
				 * This is the first tap: we set the
3253
				 * tap-hold state and notify the button
3275
				 * tap-hold state and notify the button
3254
				 * down event.
3276
				 * down event.
3255
				 */
3277
				 */
3256
				synaction->in_taphold = 1;
3278
				gest->in_taphold = 1;
3257
				taphold_timeout = sc->syninfo.taphold_timeout;
3279
				taphold_timeout = sc->syninfo.taphold_timeout;
3258
				sc->taptimeout.tv_sec  = taphold_timeout /
3280
				gest->taptimeout.tv_sec  = taphold_timeout /
3259
				    1000000;
3281
				    1000000;
3260
				sc->taptimeout.tv_usec = taphold_timeout %
3282
				gest->taptimeout.tv_usec = taphold_timeout %
3261
				    1000000;
3283
				    1000000;
3262
				timevaladd(&sc->taptimeout, &sc->lastsoftintr);
3284
				sc->idletimeout = gest->taptimeout;
3285
				timevaladd(&gest->taptimeout,
3286
				    &sc->lastsoftintr);
3263
3287
3264
				switch (synaction->fingers_nb) {
3288
				switch (gest->fingers_nb) {
3265
				case 3:
3289
				case 3:
3266
					synaction->tap_button =
3290
					gest->tap_button =
3267
					    MOUSE_BUTTON2DOWN;
3291
					    MOUSE_BUTTON2DOWN;
3268
					break;
3292
					break;
3269
				case 2:
3293
				case 2:
3270
					synaction->tap_button =
3294
					gest->tap_button =
3271
					    MOUSE_BUTTON3DOWN;
3295
					    MOUSE_BUTTON3DOWN;
3272
					break;
3296
					break;
3273
				default:
3297
				default:
3274
					synaction->tap_button =
3298
					gest->tap_button =
3275
					    MOUSE_BUTTON1DOWN;
3299
					    MOUSE_BUTTON1DOWN;
3276
				}
3300
				}
3277
				VLOG(2, (LOG_DEBUG,
3301
				VLOG(2, (LOG_DEBUG,
3278
				    "synaptics: button PRESS: %d\n",
3302
				    "synaptics: button PRESS: %d\n",
3279
				    synaction->tap_button));
3303
				    gest->tap_button));
3280
				ms->button |= synaction->tap_button;
3304
				ms->button |= gest->tap_button;
3281
			}
3305
			}
3282
		} else {
3306
		} else {
3283
			/*
3307
			/*
3284
			 * Not enough pressure or timeout: reset
3308
			 * Not enough pressure or timeout: reset
3285
			 * tap-hold state.
3309
			 * tap-hold state.
3286
			 */
3310
			 */
3287
			if (synaction->in_taphold) {
3311
			if (gest->in_taphold) {
3288
				VLOG(2, (LOG_DEBUG,
3312
				VLOG(2, (LOG_DEBUG,
3289
				    "synaptics: button RELEASE: %d\n",
3313
				    "synaptics: button RELEASE: %d\n",
3290
				    synaction->tap_button));
3314
				    gest->tap_button));
3291
				synaction->in_taphold = 0;
3315
				gest->in_taphold = 0;
3292
			} else {
3316
			} else {
3293
				VLOG(2, (LOG_DEBUG,
3317
				VLOG(2, (LOG_DEBUG,
3294
				    "synaptics: not a tap-hold\n"));
3318
				    "synaptics: not a tap-hold\n"));
3295
			}
3319
			}
3296
		}
3320
		}
3297
	} else if (!(sc->flags & PSM_FLAGS_FINGERDOWN) &&
3321
	} else if (!(sc->flags & PSM_FLAGS_FINGERDOWN) && gest->in_taphold) {
3298
	    sc->synaction.in_taphold) {
3299
		/*
3322
		/*
3300
		 * For a tap-hold to work, the button must remain down at
3323
		 * For a tap-hold to work, the button must remain down at
3301
		 * least until timeout (where the in_taphold flags will be
3324
		 * least until timeout (where the in_taphold flags will be
3302
		 * cleared) or during the next action.
3325
		 * cleared) or during the next action.
3303
		 */
3326
		 */
3304
		if (timevalcmp(&sc->lastsoftintr, &sc->taptimeout, <=)) {
3327
		if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=)) {
3305
			ms->button |= sc->synaction.tap_button;
3328
			ms->button |= gest->tap_button;
3306
		} else {
3329
		} else {
3307
			VLOG(2, (LOG_DEBUG,
3330
			VLOG(2, (LOG_DEBUG, "synaptics: button RELEASE: %d\n",
3308
			    "synaptics: button RELEASE: %d\n",
3331
			    gest->tap_button));
3309
			    sc->synaction.tap_button));
3332
			gest->in_taphold = 0;
3310
			sc->synaction.in_taphold = 0;
3311
		}
3333
		}
3312
	}
3334
	}
3313
3335
3314
SYNAPTICS_END:
3336
	return;
3315
	/*
3316
	 * Use the extra buttons as a scrollwheel
3317
	 *
3318
	 * XXX X.Org uses the Z axis for vertical wheel only,
3319
	 * whereas moused(8) understands special values to differ
3320
	 * vertical and horizontal wheels.
3321
	 *
3322
	 * xf86-input-mouse needs therefore a small patch to
3323
	 * understand these special values. Without it, the
3324
	 * horizontal wheel acts as a vertical wheel in X.Org.
3325
	 *
3326
	 * That's why the horizontal wheel is disabled by
3327
	 * default for now.
3328
	 */
3329
3330
	if (ms->button & MOUSE_BUTTON4DOWN) {
3331
		*z = -1;
3332
		ms->button &= ~MOUSE_BUTTON4DOWN;
3333
	} else if (ms->button & MOUSE_BUTTON5DOWN) {
3334
		*z = 1;
3335
		ms->button &= ~MOUSE_BUTTON5DOWN;
3336
	} else if (ms->button & MOUSE_BUTTON6DOWN) {
3337
		*z = -2;
3338
		ms->button &= ~MOUSE_BUTTON6DOWN;
3339
	} else if (ms->button & MOUSE_BUTTON7DOWN) {
3340
		*z = 2;
3341
		ms->button &= ~MOUSE_BUTTON7DOWN;
3342
	} else
3343
		*z = 0;
3344
3345
	return (0);
3346
}
3337
}
3347
3338
3348
static void
3339
static void
3349
proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3340
psmsmoother(struct psm_softc *sc, finger_t *f, int smoother_id,
3350
    int *x, int *y, int *z)
3341
    mousestatus_t *ms, int *x, int *y)
3351
{
3342
{
3352
	static int butmap_versapad[8] = {
3343
	smoother_t *smoother = &sc->smoother[smoother_id];
3353
		0,
3344
	gesture_t *gest = &(sc->gesture);
3354
		MOUSE_BUTTON3DOWN,
3355
		0,
3356
		MOUSE_BUTTON3DOWN,
3357
		MOUSE_BUTTON1DOWN,
3358
		MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
3359
		MOUSE_BUTTON1DOWN,
3360
		MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
3361
	};
3362
	int c, x0, y0;
3363
3345
3364
	/* VersaPad PS/2 absolute mode message format
3346
	/*
3347
	 * Check pressure to detect a real wanted action on the
3348
	 * touchpad.
3349
	 */
3350
	if (f->p >= sc->syninfo.min_pressure) {
3351
		int x0, y0;
3352
		int cursor, peer, window;
3353
		int dx, dy, dxp, dyp;
3354
		int max_width, max_pressure;
3355
		int margin_top, margin_right, margin_bottom, margin_left;
3356
		int na_top, na_right, na_bottom, na_left;
3357
		int window_min, window_max;
3358
		int multiplicator;
3359
		int weight_current, weight_previous, weight_len_squared;
3360
		int div_min, div_max, div_len;
3361
		int vscroll_hor_area, vscroll_ver_area;
3362
		int two_finger_scroll;
3363
		int max_x, max_y;
3364
		int len, weight_prev_x, weight_prev_y;
3365
		int div_max_x, div_max_y, div_x, div_y;
3366
		int is_fuzzy;
3367
3368
		/* Read sysctl. */
3369
		/* XXX Verify values? */
3370
		max_width = sc->syninfo.max_width;
3371
		max_pressure = sc->syninfo.max_pressure;
3372
		margin_top = sc->syninfo.margin_top;
3373
		margin_right = sc->syninfo.margin_right;
3374
		margin_bottom = sc->syninfo.margin_bottom;
3375
		margin_left = sc->syninfo.margin_left;
3376
		na_top = sc->syninfo.na_top;
3377
		na_right = sc->syninfo.na_right;
3378
		na_bottom = sc->syninfo.na_bottom;
3379
		na_left = sc->syninfo.na_left;
3380
		window_min = sc->syninfo.window_min;
3381
		window_max = sc->syninfo.window_max;
3382
		multiplicator = sc->syninfo.multiplicator;
3383
		weight_current = sc->syninfo.weight_current;
3384
		weight_previous = sc->syninfo.weight_previous;
3385
		weight_len_squared = sc->syninfo.weight_len_squared;
3386
		div_min = sc->syninfo.div_min;
3387
		div_max = sc->syninfo.div_max;
3388
		div_len = sc->syninfo.div_len;
3389
		vscroll_hor_area = sc->syninfo.vscroll_hor_area;
3390
		vscroll_ver_area = sc->syninfo.vscroll_ver_area;
3391
		two_finger_scroll = sc->syninfo.two_finger_scroll;
3392
		max_x = sc->synhw.maximumXCoord;
3393
		max_y = sc->synhw.maximumYCoord;
3394
3395
		is_fuzzy = (f->flags & PSM_FINGER_FUZZY) != 0;
3396
3397
		/* Read current absolute position. */
3398
		x0 = f->x;
3399
		y0 = f->y;
3400
3401
		/*
3402
		 * Limit the coordinates to the specified margins because
3403
		 * this area isn't very reliable.
3404
		 */
3405
		if (x0 <= margin_left)
3406
			x0 = margin_left;
3407
		else if (x0 >= max_x - margin_right)
3408
			x0 = max_x - margin_right;
3409
		if (y0 <= margin_bottom)
3410
			y0 = margin_bottom;
3411
		else if (y0 >= max_y - margin_top)
3412
			y0 = max_y - margin_top;
3413
3414
		/* If the action is just beginning, init the structure. */
3415
		if (smoother->active == 0) {
3416
			VLOG(3, (LOG_DEBUG, "smoother%d: ---\n", smoother_id));
3417
3418
			/* Store the first point of this action. */
3419
			smoother->start_x = x0;
3420
			smoother->start_y = y0;
3421
			dx = dy = 0;
3422
3423
			/* Initialize queue. */
3424
			smoother->queue_cursor = SYNAPTICS_PACKETQUEUE;
3425
			smoother->queue_len = 0;
3426
3427
			/* Reset average. */
3428
			smoother->avg_dx = 0;
3429
			smoother->avg_dy = 0;
3430
3431
			/* Reset squelch. */
3432
			smoother->squelch_x = 0;
3433
			smoother->squelch_y = 0;
3434
3435
			/* Activate queue */
3436
			smoother->active = 1;
3437
		} else {
3438
			/* Calculate the current delta. */
3439
			cursor = smoother->queue_cursor;
3440
			dx = x0 - smoother->queue[cursor].x;
3441
			dy = y0 - smoother->queue[cursor].y;
3442
		}
3443
3444
		VLOG(3, (LOG_DEBUG, "smoother%d: ipacket: [%d, %d], %d, %d\n",
3445
		    smoother_id, x0, y0, f->p, f->w));
3446
3447
		/* Queue this new packet. */
3448
		cursor = SYNAPTICS_QUEUE_CURSOR(smoother->queue_cursor - 1);
3449
		smoother->queue[cursor].x = x0;
3450
		smoother->queue[cursor].y = y0;
3451
		smoother->queue_cursor = cursor;
3452
		if (smoother->queue_len < SYNAPTICS_PACKETQUEUE)
3453
			smoother->queue_len++;
3454
		VLOG(5, (LOG_DEBUG,
3455
		    "smoother%d: cursor[%d]: x=%d, y=%d, dx=%d, dy=%d\n",
3456
		    smoother_id, cursor, x0, y0, dx, dy));
3457
3458
		/* Do we have enough packets to consider this a movement? */
3459
		if (smoother->queue_len < gest->window_min)
3460
			return;
3461
3462
		weight_prev_x = weight_prev_y = weight_previous;
3463
		div_max_x = div_max_y = div_max;
3464
3465
		if (gest->in_vscroll) {
3466
			/* Dividers are different with virtual scrolling. */
3467
			div_min = sc->syninfo.vscroll_div_min;
3468
			div_max_x = div_max_y = sc->syninfo.vscroll_div_max;
3469
		} else {
3470
			/*
3471
			 * There's a lot of noise in coordinates when
3472
			 * the finger is on the touchpad's borders. When
3473
			 * using this area, we apply a special weight and
3474
			 * div.
3475
			 */
3476
			if (x0 <= na_left || x0 >= max_x - na_right) {
3477
				weight_prev_x = sc->syninfo.weight_previous_na;
3478
				div_max_x = sc->syninfo.div_max_na;
3479
			}
3480
3481
			if (y0 <= na_bottom || y0 >= max_y - na_top) {
3482
				weight_prev_y = sc->syninfo.weight_previous_na;
3483
				div_max_y = sc->syninfo.div_max_na;
3484
			}
3485
		}
3486
3487
		/*
3488
		 * Calculate weights for the average operands and
3489
		 * the divisor. Both depend on the distance between
3490
		 * the current packet and a previous one (based on the
3491
		 * window width).
3492
		 */
3493
		window = imin(smoother->queue_len, window_max);
3494
		peer = SYNAPTICS_QUEUE_CURSOR(cursor + window - 1);
3495
		dxp = abs(x0 - smoother->queue[peer].x) + 1;
3496
		dyp = abs(y0 - smoother->queue[peer].y) + 1;
3497
		len = (dxp * dxp) + (dyp * dyp);
3498
		weight_prev_x = imin(weight_prev_x,
3499
		    weight_len_squared * weight_prev_x / len);
3500
		weight_prev_y = imin(weight_prev_y,
3501
		    weight_len_squared * weight_prev_y / len);
3502
3503
		len = (dxp + dyp) / 2;
3504
		div_x = div_len * div_max_x / len;
3505
		div_x = imin(div_max_x, div_x);
3506
		div_x = imax(div_min, div_x);
3507
		div_y = div_len * div_max_y / len;
3508
		div_y = imin(div_max_y, div_y);
3509
		div_y = imax(div_min, div_y);
3510
3511
		VLOG(3, (LOG_DEBUG,
3512
		    "smoother%d: peer=%d, len=%d, weight=%d/%d, div=%d/%d\n",
3513
		    smoother_id, peer, len, weight_prev_x, weight_prev_y,
3514
		    div_x, div_y));
3515
3516
		/* Compute averages. */
3517
		smoother->avg_dx =
3518
		    (weight_current * dx * multiplicator +
3519
		     weight_prev_x * smoother->avg_dx) /
3520
		    (weight_current + weight_prev_x);
3521
3522
		smoother->avg_dy =
3523
		    (weight_current * dy * multiplicator +
3524
		     weight_prev_y * smoother->avg_dy) /
3525
		    (weight_current + weight_prev_y);
3526
3527
		VLOG(5, (LOG_DEBUG,
3528
		    "smoother%d: avg_dx~=%d, avg_dy~=%d\n", smoother_id,
3529
		    smoother->avg_dx / multiplicator,
3530
		    smoother->avg_dy / multiplicator));
3531
3532
		/* Use these averages to calculate x & y. */
3533
		smoother->squelch_x += smoother->avg_dx;
3534
		dxp = smoother->squelch_x / (div_x * multiplicator);
3535
		smoother->squelch_x = smoother->squelch_x %
3536
		    (div_x * multiplicator);
3537
3538
		smoother->squelch_y += smoother->avg_dy;
3539
		dyp = smoother->squelch_y / (div_y * multiplicator);
3540
		smoother->squelch_y = smoother->squelch_y %
3541
		    (div_y * multiplicator);
3542
3543
		switch(gest->in_vscroll) {
3544
		case 0: /* Pointer movement. */
3545
			/* On real<->fuzzy finger switch the x/y pos jumps */
3546
			if (is_fuzzy == smoother->is_fuzzy) {
3547
				*x += dxp;
3548
				*y += dyp;
3549
			}
3550
3551
			VLOG(3, (LOG_DEBUG, "smoother%d: [%d, %d] -> [%d, %d]\n",
3552
			    smoother_id, dx, dy, dxp, dyp));
3553
			break;
3554
		case 1: /* Vertical scrolling. */
3555
			if (dyp != 0)
3556
				ms->button |= (dyp > 0) ?
3557
				    MOUSE_BUTTON4DOWN : MOUSE_BUTTON5DOWN;
3558
			break;
3559
		case 2: /* Horizontal scrolling. */
3560
			if (dxp != 0)
3561
				ms->button |= (dxp > 0) ?
3562
				    MOUSE_BUTTON7DOWN : MOUSE_BUTTON6DOWN;
3563
			break;
3564
		}
3565
3566
		smoother->is_fuzzy = is_fuzzy;
3567
3568
	} else {
3569
		/*
3570
		 * Deactivate queue. Note: We can not just reset queue here
3571
		 * as these values are still used by gesture processor.
3572
		 * So postpone reset till next touch.
3573
		 */
3574
		smoother->active = 0;
3575
	}
3576
}
3577
3578
static int
3579
psmsoftbuttons(struct psm_softc *sc, finger_t *f, int pressed)
3580
{
3581
	static int button = 0;
3582
	int y_ok, center_button, center_x, right_button, right_x;
3583
3584
	/* Dont change clickpad softbutton after pressing */
3585
	if (pressed && !button) {
3586
		y_ok = sc->syninfo.softbuttons_y >= 0 ?
3587
		    f->y < sc->syninfo.softbuttons_y :
3588
		    f->y > sc->synhw.maximumYCoord - sc->syninfo.softbuttons_y;
3589
3590
		center_button = MOUSE_BUTTON2DOWN;
3591
		center_x = sc->syninfo.softbutton2_x;
3592
		right_button = MOUSE_BUTTON3DOWN;
3593
		right_x = sc->syninfo.softbutton3_x;
3594
3595
		if (center_x > 0 && right_x > 0 && center_x > right_x) {
3596
			center_button = MOUSE_BUTTON3DOWN;
3597
			center_x = sc->syninfo.softbutton3_x;
3598
			right_button = MOUSE_BUTTON2DOWN;
3599
			right_x = sc->syninfo.softbutton2_x;
3600
		}
3601
3602
		if (right_x > 0 && f->x > right_x && y_ok)
3603
			button = right_button;
3604
		else if (center_x > 0 && f->x > center_x && y_ok)
3605
			button = center_button;
3606
		else
3607
			button = MOUSE_BUTTON1DOWN;
3608
		VLOG(2, (LOG_DEBUG, "softbutton: PRESS: %d\n", button));
3609
	}
3610
3611
	/* Clickpad releases */
3612
	if (!pressed && button) {
3613
		VLOG(2, (LOG_DEBUG, "softbutton: RELEASE: %d\n", button));
3614
		button = 0;
3615
	}
3616
3617
	return (button);
3618
}
3619
3620
static int
3621
proc_elantech(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3622
    int *x, int *y, int *z)
3623
{
3624
	static int touchpad_button, trackpoint_button;
3625
	finger_t fn, f[ELANTECH_MAX_FINGERS];
3626
	int pkt, id, scale, i, nfingers, mask;
3627
3628
	if (!elantech_support)
3629
		return (0);
3630
3631
	/* Determine packet format and do a sanity check for out of sync packets. */
3632
	if (ELANTECH_PKT_IS_DEBOUNCE(pb, sc->elanhw.hwversion))
3633
		pkt = ELANTECH_PKT_NOP;
3634
	else if (ELANTECH_PKT_IS_TRACKPOINT(pb))
3635
		pkt = ELANTECH_PKT_TRACKPOINT;
3636
	else
3637
	switch (sc->elanhw.hwversion) {
3638
	case 2:
3639
		if (!ELANTECH_PKT_IS_V2(pb))
3640
			return (-1);
3641
3642
		pkt = (pb->ipacket[0] & 0xc0) == 0x80 ?
3643
		    ELANTECH_PKT_V2_2FINGER : ELANTECH_PKT_V2_COMMON;
3644
		break;
3645
	case 3:
3646
		if (!ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc) &&
3647
		    !ELANTECH_PKT_IS_V3_TAIL(pb, sc->elanhw.hascrc))
3648
			return (-1);
3649
3650
		pkt = ELANTECH_PKT_V3;
3651
		break;
3652
	case 4:
3653
		if (!ELANTECH_PKT_IS_V4(pb, sc->elanhw.hascrc))
3654
			return (-1);
3655
3656
		switch (pb->ipacket[3] & 0x03) {
3657
		case 0x00:
3658
			pkt = ELANTECH_PKT_V4_STATUS;
3659
			break;
3660
		case 0x01:
3661
			pkt = ELANTECH_PKT_V4_HEAD;
3662
			break;
3663
		case 0x02:
3664
			pkt = ELANTECH_PKT_V4_MOTION;
3665
			break;
3666
		default:
3667
			return (-1);
3668
		}
3669
		break;
3670
	default:
3671
		return (-1);
3672
	}
3673
3674
	VLOG(5, (LOG_DEBUG, "elantech: ipacket format: %d\n", pkt));
3675
3676
	for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
3677
		PSM_FINGER_RESET(f[id]);
3678
3679
	*x = *y = *z = 0;
3680
	ms->button = ms->obutton;
3681
3682
	if (sc->syninfo.touchpad_off)
3683
		return (0);
3684
3685
	/* Common legend
3686
	 * L: Left mouse button pressed
3687
	 * R: Right mouse button pressed
3688
	 * N: number of fingers on touchpad
3689
	 * X: absolute x value (horizontal)
3690
	 * Y: absolute y value (vertical)
3691
	 * W; width of the finger touch
3692
	 * P: pressure
3693
	 */
3694
	switch (pkt) {
3695
	case ELANTECH_PKT_V2_COMMON:	/* HW V2. One/Three finger touch */
3696
		/*               7   6   5   4   3   2   1   0 (LSB)
3697
		 * -------------------------------------------
3698
		 * ipacket[0]:  N1  N0  W3  W2   .   .   R   L
3699
		 * ipacket[1]:  P7  P6  P5  P4 X11 X10  X9  X8
3700
		 * ipacket[2]:  X7  X6  X5  X4  X3  X2  X1  X0
3701
		 * ipacket[3]:  N4  VF  W1  W0   .   .   .  B2
3702
		 * ipacket[4]:  P3  P1  P2  P0 Y11 Y10  Y9  Y8
3703
		 * ipacket[5]:  Y7  Y6  Y5  Y4  Y3  Y2  Y1  Y0
3704
		 * -------------------------------------------
3705
		 * N4: set if more than 3 fingers (only in 3 fingers mode)
3706
		 * VF: a kind of flag? (only on EF123, 0 when finger
3707
		 *     is over one of the buttons, 1 otherwise)
3708
		 * B2: (on EF113 only, 0 otherwise), one button pressed
3709
		 * P & W is not reported on EF113 touchpads
3710
		 */
3711
		nfingers = (pb->ipacket[0] & 0xc0) >> 6;
3712
		if (nfingers == 3 && (pb->ipacket[3] & 0x80))
3713
			nfingers = 4;
3714
		mask = (1 << nfingers) - 1;
3715
3716
		fn = ELANTECH_FINGER_SET_XYP(pb);
3717
		if (sc->elanhw.haspressure) {
3718
			fn.w = ((pb->ipacket[0] & 0x30) >> 2) |
3719
			    ((pb->ipacket[3] & 0x30) >> 4);
3720
		} else {
3721
			fn.p = ELANTECH_FINGER_DEFAULT_P;
3722
			fn.w = ELANTECH_FINGER_DEFAULT_W;
3723
		}
3724
3725
		/*
3726
		 * HW v2 dont report exact finger positions when 3 or more
3727
		 * fingers are on touchpad. Use reported value as fingers
3728
		 * position as it is required for tap detection
3729
		 */
3730
		if (nfingers > 2)
3731
			fn.flags = PSM_FINGER_FUZZY;
3732
3733
		for (id = 0; id < imin(nfingers, ELANTECH_MAX_FINGERS); id++)
3734
			f[id] = fn;
3735
		break;
3736
3737
	case ELANTECH_PKT_V2_2FINGER:	/*HW V2. Two finger touch */
3738
		/*               7   6   5   4   3   2   1   0 (LSB)
3739
		 * -------------------------------------------
3740
		 * ipacket[0]:  N1  N0 AY8 AX8   .   .   R   L
3741
		 * ipacket[1]: AX7 AX6 AX5 AX4 AX3 AX2 AX1 AX0
3742
		 * ipacket[2]: AY7 AY6 AY5 AY4 AY3 AY2 AY1 AY0
3743
		 * ipacket[3]:   .   . BY8 BX8   .   .   .   .
3744
		 * ipacket[4]: BX7 BX6 BX5 BX4 BX3 BX2 BX1 BX0
3745
		 * ipacket[5]: BY7 BY6 BY5 BY4 BY3 BY2 BY1 BY0
3746
		 * -------------------------------------------
3747
		 * AX: lower-left finger absolute x value
3748
		 * AY: lower-left finger absolute y value
3749
		 * BX: upper-right finger absolute x value
3750
		 * BY: upper-right finger absolute y value
3751
		 */
3752
		nfingers = 2;
3753
		mask = (1 << nfingers) - 1;
3754
3755
		for (id = 0; id < imin(2, ELANTECH_MAX_FINGERS); id ++)
3756
			f[id] = (finger_t) {
3757
				.x = (((pb->ipacket[id * 3] & 0x10) << 4) |
3758
				    pb->ipacket[id * 3 + 1]) << 2,
3759
				.y = (((pb->ipacket[id * 3] & 0x20) << 3) |
3760
				    pb->ipacket[id * 3 + 2]) << 2,
3761
				.p = ELANTECH_FINGER_DEFAULT_P,
3762
				.w = ELANTECH_FINGER_DEFAULT_W,
3763
				/* HW ver.2 sends bounding box */
3764
				.flags = PSM_FINGER_FUZZY
3765
			};
3766
		break;
3767
3768
	case ELANTECH_PKT_V3:	/* HW Version 3 */
3769
		/*               7   6   5   4   3   2   1   0 (LSB)
3770
		 * -------------------------------------------
3771
		 * ipacket[0]:  N1  N0  W3  W2   0   1   R   L
3772
		 * ipacket[1]:  P7  P6  P5  P4 X11 X10  X9  X8
3773
		 * ipacket[2]:  X7  X6  X5  X4  X3  X2  X1  X0
3774
		 * ipacket[3]:   0   0  W1  W0   0   0   1   0
3775
		 * ipacket[4]:  P3  P1  P2  P0 Y11 Y10  Y9  Y8
3776
		 * ipacket[5]:  Y7  Y6  Y5  Y4  Y3  Y2  Y1  Y0
3777
		 * -------------------------------------------
3778
		 */
3779
		nfingers = (pb->ipacket[0] & 0xc0) >> 6;
3780
		mask = (1 << nfingers) - 1;
3781
		id = nfingers - 1;
3782
3783
		fn = ELANTECH_FINGER_SET_XYP(pb);
3784
		fn.w = ((pb->ipacket[0] & 0x30) >> 2) |
3785
		    ((pb->ipacket[3] & 0x30) >> 4);
3786
3787
		/*
3788
		 * HW v3 dont report exact finger positions when 3 or more
3789
		 * fingers are on touchpad. Use reported value as fingers
3790
		 * position as it is required for tap detection
3791
		 */
3792
		if (nfingers > 2)
3793
			fn.flags = PSM_FINGER_FUZZY;
3794
3795
		for (id = 0; id < imin(nfingers, ELANTECH_MAX_FINGERS); id++)
3796
			f[id] = fn;
3797
3798
		if (nfingers == 2) {
3799
			if (ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc)) {
3800
				sc->elanaction.fingers[0] = fn;
3801
				return (0);
3802
			} else
3803
				f[0] = sc->elanaction.fingers[0];
3804
		}
3805
		break;
3806
3807
	case ELANTECH_PKT_V4_STATUS:	/* HW Version 4. Status packet */
3808
		/*               7   6   5   4   3   2   1   0 (LSB)
3809
		 * -------------------------------------------
3810
		 * ipacket[0]:   .   .   .   .   0   1   R   L
3811
		 * ipacket[1]:   .   .   .  F4  F3  F2  F1  F0
3812
		 * ipacket[2]:   .   .   .   .   .   .   .   .
3813
		 * ipacket[3]:   .   .   .   1   0   0   0   0
3814
		 * ipacket[4]:  PL   .   .   .   .   .   .   .
3815
		 * ipacket[5]:   .   .   .   .   .   .   .   .
3816
		 * -------------------------------------------
3817
		 * Fn: finger n is on touchpad
3818
		 * PL: palm
3819
		 * HV ver4 sends a status packet to indicate that the numbers
3820
		 * or identities of the fingers has been changed
3821
		 */
3822
3823
		mask = pb->ipacket[1] & 0x1f;
3824
		nfingers = fls(mask);
3825
3826
		/* Skip "new finger is on touchpad" packets */
3827
		if ((sc->elanaction.mask & mask) == sc->elanaction.mask &&
3828
		    (mask & ~sc->elanaction.mask)) {
3829
			sc->elanaction.mask = mask;
3830
			return (0);
3831
		}
3832
3833
		break;
3834
3835
	case ELANTECH_PKT_V4_HEAD:	/* HW Version 4. Head packet */
3836
		/*               7   6   5   4   3   2   1   0 (LSB)
3837
		 * -------------------------------------------
3838
		 * ipacket[0]:  W3  W2  W1  W0   0   1   R   L
3839
		 * ipacket[1]:  P7  P6  P5  P4 X11 X10  X9  X8
3840
		 * ipacket[2]:  X7  X6  X5  X4  X3  X2  X1  X0
3841
		 * ipacket[3]: ID2 ID1 ID0   1   0   0   0   1
3842
		 * ipacket[4]:  P3  P1  P2  P0 Y11 Y10  Y9  Y8
3843
		 * ipacket[5]:  Y7  Y6  Y5  Y4  Y3  Y2  Y1  Y0
3844
		 * -------------------------------------------
3845
		 * ID: finger id
3846
		 * HW ver 4 sends head packets in two cases:
3847
		 * 1. One finger touch and movement.
3848
		 * 2. Next after status packet to tell new finger positions.
3849
		 */
3850
		mask = sc->elanaction.mask;
3851
		nfingers = fls(mask);
3852
		id = ((pb->ipacket[3] & 0xe0) >> 5) - 1;
3853
3854
		if (id >= 0 && id < ELANTECH_MAX_FINGERS) {
3855
			f[id] = ELANTECH_FINGER_SET_XYP(pb);
3856
			f[id].w = (pb->ipacket[0] & 0xf0) >> 4;
3857
		}
3858
		break;
3859
3860
	case ELANTECH_PKT_V4_MOTION:	/* HW Version 4. Motion packet */
3861
		/*               7   6   5   4   3   2   1   0 (LSB)
3862
		 * -------------------------------------------
3863
		 * ipacket[0]: ID2 ID1 ID0  OF   0   1   R   L
3864
		 * ipacket[1]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
3865
		 * ipacket[2]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
3866
		 * ipacket[3]: ID2 ID1 ID0   1   0   0   1   0
3867
		 * ipacket[4]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
3868
		 * ipacket[5]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
3869
		 * -------------------------------------------
3870
		 * OF: delta overflows (> 127 or < -128), in this case
3871
		 *     firmware sends us (delta x / 5) and (delta y / 5)
3872
		 * ID: finger id
3873
		 * DX: delta x (two's complement)
3874
		 * XY: delta y (two's complement)
3875
		 * byte 0 ~ 2 for one finger
3876
		 * byte 3 ~ 5 for another finger
3877
		 */
3878
		mask = sc->elanaction.mask;
3879
		nfingers = fls(mask);
3880
3881
		scale = (pb->ipacket[0] & 0x10) ? 5 : 1;
3882
		for (i = 0; i <= 3; i += 3) {
3883
			id = ((pb->ipacket[i] & 0xe0) >> 5) - 1;
3884
			if (id < 0 || id >= ELANTECH_MAX_FINGERS)
3885
				continue;
3886
3887
			if (PSM_FINGER_IS_SET(sc->elanaction.fingers[id])) {
3888
				f[id] = sc->elanaction.fingers[id];
3889
				f[id].x += imax(-f[id].x,
3890
				    (signed char)pb->ipacket[i+1] * scale);
3891
				f[id].y += imax(-f[id].y,
3892
				    (signed char)pb->ipacket[i+2] * scale);
3893
			} else {
3894
				VLOG(3, (LOG_DEBUG, "elantech: "
3895
				    "HW v4 motion packet skipped\n"));
3896
			}
3897
		}
3898
3899
		break;
3900
3901
	case ELANTECH_PKT_TRACKPOINT:
3902
		/*               7   6   5   4   3   2   1   0 (LSB)
3903
		 * -------------------------------------------
3904
		 * ipacket[0]:   0   0  SX  SY   0   M   R   L
3905
		 * ipacket[1]: ~SX   0   0   0   0   0   0   0
3906
		 * ipacket[2]: ~SY   0   0   0   0   0   0   0
3907
		 * ipacket[3]:   0   0 ~SY ~SX   0   1   1   0
3908
		 * ipacket[4]:  X7  X6  X5  X4  X3  X2  X1  X0
3909
		 * ipacket[5]:  Y7  Y6  Y5  Y4  Y3  Y2  Y1  Y0
3910
		 * -------------------------------------------
3911
		 * X and Y are written in two's complement spread
3912
		 * over 9 bits with SX/SY the relative top bit and
3913
		 * X7..X0 and Y7..Y0 the lower bits.
3914
		 */
3915
		*x = (pb->ipacket[0] & 0x20) ?
3916
		    pb->ipacket[4] - 256 : pb->ipacket[4];
3917
		*y = (pb->ipacket[0] & 0x10) ?
3918
		    pb->ipacket[5] - 256 : pb->ipacket[5];
3919
3920
		trackpoint_button =
3921
		    ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
3922
		    ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0) |
3923
		    ((pb->ipacket[0] & 0x04) ? MOUSE_BUTTON2DOWN : 0);
3924
3925
		ms->button = touchpad_button | trackpoint_button;
3926
		return (0);
3927
3928
	case ELANTECH_PKT_NOP:
3929
		return (0);
3930
3931
	default:
3932
		return (-1);
3933
	}
3934
3935
	for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
3936
		if (PSM_FINGER_IS_SET(f[id]))
3937
			VLOG(2, (LOG_DEBUG, "elantech: "
3938
			    "finger %d: down [%d, %d], %d, %d, %d\n", id + 1,
3939
			    f[id].x, f[id].y, f[id].p, f[id].w, f[id].flags));
3940
3941
	/* Touchpad button presses */
3942
	if (sc->elanhw.isclickpad) {
3943
		touchpad_button =
3944
		    psmsoftbuttons(sc, &f[0], pb->ipacket[0] & 0x03);
3945
	} else {
3946
		touchpad_button =
3947
		    ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
3948
		    ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0);
3949
	}
3950
3951
	ms->button = touchpad_button | trackpoint_button;
3952
3953
	/* Palm detection doesn't terminate the current action. */
3954
	if (!psmpalmdetect(sc, &f[0], nfingers)) {
3955
		/* Send finger 1 position to gesture processor */
3956
		if (PSM_FINGER_IS_SET(f[0]) || nfingers == 0)
3957
			psmgestures(sc, &f[0], imin(nfingers, 3), ms);
3958
		/* Send fingers positions to movement smoothers */
3959
		for (id = 0; id < PSM_FINGERS; id++)
3960
			if (PSM_FINGER_IS_SET(f[id]) || !(mask & (1 << id)))
3961
				psmsmoother(sc, &f[id], id, ms, x, y);
3962
	} else {
3963
		VLOG(2, (LOG_DEBUG, "elantech: palm detected! (%d)\n",
3964
		    f[0].w));
3965
	}
3966
3967
	/* Store current finger positions in action context */
3968
	for (id = 0; id < ELANTECH_MAX_FINGERS; id++) {
3969
		if (PSM_FINGER_IS_SET(f[id]))
3970
			sc->elanaction.fingers[id] = f[id];
3971
		if ((sc->elanaction.mask & (1 << id)) && !(mask & (1 << id)))
3972
			PSM_FINGER_RESET(sc->elanaction.fingers[id]);
3973
	}
3974
	sc->elanaction.mask = mask;
3975
3976
	/* Use the extra buttons as a scrollwheel */
3977
	if (ms->button & MOUSE_BUTTON4DOWN)
3978
		*z = -1;
3979
	else if (ms->button & MOUSE_BUTTON5DOWN)
3980
		*z = 1;
3981
	else if (ms->button & MOUSE_BUTTON6DOWN)
3982
		*z = -2;
3983
	else if (ms->button & MOUSE_BUTTON7DOWN)
3984
		*z = 2;
3985
	else
3986
		*z = 0;
3987
	ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
3988
	    MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
3989
3990
	return (0);
3991
}
3992
3993
static void
3994
proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3995
    int *x, int *y, int *z)
3996
{
3997
	static int butmap_versapad[8] = {
3998
		0,
3999
		MOUSE_BUTTON3DOWN,
4000
		0,
4001
		MOUSE_BUTTON3DOWN,
4002
		MOUSE_BUTTON1DOWN,
4003
		MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
4004
		MOUSE_BUTTON1DOWN,
4005
		MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
4006
	};
4007
	int c, x0, y0;
4008
4009
	/* VersaPad PS/2 absolute mode message format
3365
	 *
4010
	 *
3366
	 * [packet1]     7   6   5   4   3   2   1   0(LSB)
4011
	 * [packet1]     7   6   5   4   3   2   1   0(LSB)
3367
	 *  ipacket[0]:  1   1   0   A   1   L   T   R
4012
	 *  ipacket[0]:  1   1   0   A   1   L   T   R
Lines 3413-3418 proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms, Link Here
3413
}
4058
}
3414
4059
3415
static void
4060
static void
4061
psmsoftintridle(void *arg)
4062
{
4063
	struct psm_softc *sc = arg;
4064
	packetbuf_t *pb;
4065
4066
	/* Invoke soft handler only when pqueue is empty. Otherwise it will be
4067
	 * invoked from psmintr soon with pqueue filled with real data */
4068
	if (sc->pqueue_start == sc->pqueue_end &&
4069
	    sc->idlepacket.inputbytes > 0) {
4070
		/* Grow circular queue backwards to avoid race with psmintr */
4071
		if (--sc->pqueue_start < 0)
4072
			sc->pqueue_start = PSM_PACKETQUEUE - 1;
4073
4074
		pb = &sc->pqueue[sc->pqueue_start];
4075
		memcpy(pb, &sc->idlepacket, sizeof(packetbuf_t));
4076
		VLOG(4, (LOG_DEBUG,
4077
		    "psmsoftintridle: %02x %02x %02x %02x %02x %02x\n",
4078
		    pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
4079
		    pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
4080
4081
		psmsoftintr(arg);
4082
	}
4083
}
4084
4085
static void
3416
psmsoftintr(void *arg)
4086
psmsoftintr(void *arg)
3417
{
4087
{
3418
	/*
4088
	/*
Lines 3465-3470 psmsoftintr(void *arg) Link Here
3465
		if (sc->config & PSM_CONFIG_FORCETAP)
4135
		if (sc->config & PSM_CONFIG_FORCETAP)
3466
			ms.button |= ((c & MOUSE_PS2_TAP)) ?
4136
			ms.button |= ((c & MOUSE_PS2_TAP)) ?
3467
			    0 : MOUSE_BUTTON4DOWN;
4137
			    0 : MOUSE_BUTTON4DOWN;
4138
		timevalclear(&sc->idletimeout);
4139
		sc->idlepacket.inputbytes = 0;
3468
4140
3469
		switch (sc->hw.model) {
4141
		switch (sc->hw.model) {
3470
4142
Lines 3603-3608 psmsoftintr(void *arg) Link Here
3603
				goto next;
4275
				goto next;
3604
			break;
4276
			break;
3605
4277
4278
		case MOUSE_MODEL_ELANTECH:
4279
			if (proc_elantech(sc, pb, &ms, &x, &y, &z) != 0)
4280
				goto next;
4281
			break;
4282
3606
		case MOUSE_MODEL_TRACKPOINT:
4283
		case MOUSE_MODEL_TRACKPOINT:
3607
		case MOUSE_MODEL_GENERIC:
4284
		case MOUSE_MODEL_GENERIC:
3608
		default:
4285
		default:
Lines 3627-3632 psmsoftintr(void *arg) Link Here
3627
		}
4304
		}
3628
	}
4305
	}
3629
4306
4307
	/* Store last packet for reinjection if it has not been set already */
4308
	if (timevalisset(&sc->idletimeout) && sc->idlepacket.inputbytes == 0)
4309
		sc->idlepacket = *pb;
4310
3630
	ms.dx = x;
4311
	ms.dx = x;
3631
	ms.dy = y;
4312
	ms.dy = y;
3632
	ms.dz = z;
4313
	ms.dz = z;
Lines 3673-3678 next: Link Here
3673
		pgsigio(&sc->async, SIGIO, 0);
4354
		pgsigio(&sc->async, SIGIO, 0);
3674
	}
4355
	}
3675
	sc->state &= ~PSM_SOFTARMED;
4356
	sc->state &= ~PSM_SOFTARMED;
4357
4358
	/* schedule injection of predefined packet after idletimeout
4359
	 * if no data packets have been received from psmintr */
4360
	if (timevalisset(&sc->idletimeout)) {
4361
		sc->state |= PSM_SOFTARMED;
4362
		callout_reset(&sc->softcallout, tvtohz(&sc->idletimeout),
4363
		    psmsoftintridle, sc);
4364
		VLOG(2, (LOG_DEBUG, "softintr: callout set: %d ticks\n",
4365
		    tvtohz(&sc->idletimeout)));
4366
	}
3676
	splx(s);
4367
	splx(s);
3677
}
4368
}
3678
4369
Lines 4106-4115 enable_4dplus(struct psm_softc *sc, enum probearg arg) Link Here
4106
static int
4797
static int
4107
synaptics_sysctl(SYSCTL_HANDLER_ARGS)
4798
synaptics_sysctl(SYSCTL_HANDLER_ARGS)
4108
{
4799
{
4800
	struct psm_softc *sc;
4109
	int error, arg;
4801
	int error, arg;
4110
4802
4803
	if (oidp->oid_arg1 == NULL || oidp->oid_arg2 < 0 ||
4804
	    oidp->oid_arg2 > SYNAPTICS_SYSCTL_SOFTBUTTON3_X)
4805
		return (EINVAL);
4806
4807
	sc = oidp->oid_arg1;
4808
4111
	/* Read the current value. */
4809
	/* Read the current value. */
4112
	arg = *(int *)oidp->oid_arg1;
4810
	arg = *(int *)((char *)sc + oidp->oid_arg2);
4113
	error = sysctl_handle_int(oidp, &arg, 0, req);
4811
	error = sysctl_handle_int(oidp, &arg, 0, req);
4114
4812
4115
	/* Sanity check. */
4813
	/* Sanity check. */
Lines 4131-4144 synaptics_sysctl(SYSCTL_HANDLER_ARGS) Link Here
4131
			return (EINVAL);
4829
			return (EINVAL);
4132
		break;
4830
		break;
4133
	case SYNAPTICS_SYSCTL_MARGIN_TOP:
4831
	case SYNAPTICS_SYSCTL_MARGIN_TOP:
4134
	case SYNAPTICS_SYSCTL_MARGIN_RIGHT:
4135
	case SYNAPTICS_SYSCTL_MARGIN_BOTTOM:
4832
	case SYNAPTICS_SYSCTL_MARGIN_BOTTOM:
4136
	case SYNAPTICS_SYSCTL_MARGIN_LEFT:
4137
	case SYNAPTICS_SYSCTL_NA_TOP:
4833
	case SYNAPTICS_SYSCTL_NA_TOP:
4138
	case SYNAPTICS_SYSCTL_NA_RIGHT:
4139
	case SYNAPTICS_SYSCTL_NA_BOTTOM:
4834
	case SYNAPTICS_SYSCTL_NA_BOTTOM:
4835
		if (arg < 0 || arg > sc->synhw.maximumYCoord)
4836
			return (EINVAL);
4837
		break;
4838
	case SYNAPTICS_SYSCTL_SOFTBUTTON2_X:
4839
	case SYNAPTICS_SYSCTL_SOFTBUTTON3_X:
4840
		/* Softbuttons is clickpad only feature */
4841
		if (!sc->synhw.capClickPad && arg != 0)
4842
			return (EINVAL);
4843
		/* FALLTHROUGH */
4844
	case SYNAPTICS_SYSCTL_MARGIN_RIGHT:
4845
	case SYNAPTICS_SYSCTL_MARGIN_LEFT:
4846
	case SYNAPTICS_SYSCTL_NA_RIGHT:
4140
	case SYNAPTICS_SYSCTL_NA_LEFT:
4847
	case SYNAPTICS_SYSCTL_NA_LEFT:
4141
		if (arg < 0 || arg > 6143)
4848
		if (arg < 0 || arg > sc->synhw.maximumXCoord)
4142
			return (EINVAL);
4849
			return (EINVAL);
4143
		break;
4850
		break;
4144
	case SYNAPTICS_SYSCTL_WINDOW_MIN:
4851
	case SYNAPTICS_SYSCTL_WINDOW_MIN:
Lines 4168-4175 synaptics_sysctl(SYSCTL_HANDLER_ARGS) Link Here
4168
			return (EINVAL);
4875
			return (EINVAL);
4169
		break;
4876
		break;
4170
	case SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA:
4877
	case SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA:
4878
		if (arg < -sc->synhw.maximumXCoord ||
4879
		    arg > sc->synhw.maximumXCoord)
4880
			return (EINVAL);
4881
		break;
4882
	case SYNAPTICS_SYSCTL_SOFTBUTTONS_Y:
4883
		/* Softbuttons is clickpad only feature */
4884
		if (!sc->synhw.capClickPad && arg != 0)
4885
			return (EINVAL);
4886
		/* FALLTHROUGH */
4171
	case SYNAPTICS_SYSCTL_VSCROLL_VER_AREA:
4887
	case SYNAPTICS_SYSCTL_VSCROLL_VER_AREA:
4172
		if (arg < -6143 || arg > 6143)
4888
		if (arg < -sc->synhw.maximumYCoord ||
4889
		    arg > sc->synhw.maximumYCoord)
4173
			return (EINVAL);
4890
			return (EINVAL);
4174
		break;
4891
		break;
4175
        case SYNAPTICS_SYSCTL_TOUCHPAD_OFF:
4892
        case SYNAPTICS_SYSCTL_TOUCHPAD_OFF:
Lines 4181-4193 synaptics_sysctl(SYSCTL_HANDLER_ARGS) Link Here
4181
	}
4898
	}
4182
4899
4183
	/* Update. */
4900
	/* Update. */
4184
	*(int *)oidp->oid_arg1 = arg;
4901
	*(int *)((char *)sc + oidp->oid_arg2) = arg;
4185
4902
4186
	return (error);
4903
	return (error);
4187
}
4904
}
4188
4905
4189
static void
4906
static void
4190
synaptics_sysctl_create_tree(struct psm_softc *sc)
4907
synaptics_sysctl_create_softbuttons_tree(struct psm_softc *sc)
4908
{
4909
	/*
4910
	 * Set predefined sizes for softbuttons.
4911
	 * Values are taken to match HP Pavilion dv6 clickpad drawings
4912
	 * with right button divided on middle and right softbuttons
4913
	 */
4914
4915
	/* hw.psm.synaptics.softbuttons_y */
4916
	sc->syninfo.softbuttons_y = 1700;
4917
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4918
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4919
	    "softbuttons_y", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4920
	    sc, SYNAPTICS_SYSCTL_SOFTBUTTONS_Y,
4921
	    synaptics_sysctl, "I",
4922
	    "Vertical size of softbuttons area");
4923
4924
	/* hw.psm.synaptics.softbutton2_x */
4925
	sc->syninfo.softbutton2_x = 3600;
4926
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4927
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4928
	    "softbutton2_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4929
	    sc, SYNAPTICS_SYSCTL_SOFTBUTTON2_X,
4930
	    synaptics_sysctl, "I",
4931
	    "Horisontal position of 2-nd softbutton left edge (0-disable)");
4932
4933
	/* hw.psm.synaptics.softbutton3_x */
4934
	sc->syninfo.softbutton3_x = 4700;
4935
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4936
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4937
	    "softbutton3_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4938
	    sc, SYNAPTICS_SYSCTL_SOFTBUTTON3_X,
4939
	    synaptics_sysctl, "I",
4940
	    "Horisontal position of 3-rd softbutton left edge (0-disable)");
4941
}
4942
4943
static void
4944
synaptics_sysctl_create_tree(struct psm_softc *sc, const char *name,
4945
    const char *descr)
4191
{
4946
{
4192
4947
4193
	if (sc->syninfo.sysctl_tree != NULL)
4948
	if (sc->syninfo.sysctl_tree != NULL)
Lines 4196-4203 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4196
	/* Attach extra synaptics sysctl nodes under hw.psm.synaptics */
4951
	/* Attach extra synaptics sysctl nodes under hw.psm.synaptics */
4197
	sysctl_ctx_init(&sc->syninfo.sysctl_ctx);
4952
	sysctl_ctx_init(&sc->syninfo.sysctl_ctx);
4198
	sc->syninfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->syninfo.sysctl_ctx,
4953
	sc->syninfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->syninfo.sysctl_ctx,
4199
	    SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, "synaptics", CTLFLAG_RD,
4954
	    SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, name, CTLFLAG_RD,
4200
	    0, "Synaptics TouchPad");
4955
	    0, descr);
4201
4956
4202
	/* hw.psm.synaptics.directional_scrolls. */
4957
	/* hw.psm.synaptics.directional_scrolls. */
4203
	sc->syninfo.directional_scrolls = 0;
4958
	sc->syninfo.directional_scrolls = 0;
Lines 4230-4236 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4230
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4985
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4231
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4986
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4232
	    "min_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4987
	    "min_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4233
	    &sc->syninfo.min_pressure, SYNAPTICS_SYSCTL_MIN_PRESSURE,
4988
	    sc, SYNAPTICS_SYSCTL_MIN_PRESSURE,
4234
	    synaptics_sysctl, "I",
4989
	    synaptics_sysctl, "I",
4235
	    "Minimum pressure required to start an action");
4990
	    "Minimum pressure required to start an action");
4236
4991
Lines 4239-4245 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4239
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4994
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4240
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4995
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4241
	    "max_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4996
	    "max_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4242
	    &sc->syninfo.max_pressure, SYNAPTICS_SYSCTL_MAX_PRESSURE,
4997
	    sc, SYNAPTICS_SYSCTL_MAX_PRESSURE,
4243
	    synaptics_sysctl, "I",
4998
	    synaptics_sysctl, "I",
4244
	    "Maximum pressure to detect palm");
4999
	    "Maximum pressure to detect palm");
4245
5000
Lines 4248-4272 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4248
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5003
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4249
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5004
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4250
	    "max_width", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5005
	    "max_width", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4251
	    &sc->syninfo.max_width, SYNAPTICS_SYSCTL_MAX_WIDTH,
5006
	    sc, SYNAPTICS_SYSCTL_MAX_WIDTH,
4252
	    synaptics_sysctl, "I",
5007
	    synaptics_sysctl, "I",
4253
	    "Maximum finger width to detect palm");
5008
	    "Maximum finger width to detect palm");
4254
5009
4255
	/* hw.psm.synaptics.top_margin. */
5010
	/* hw.psm.synaptics.top_margin. */
4256
	sc->syninfo.margin_top = 200;
5011
	sc->syninfo.margin_top =
5012
	    imax(sc->synhw.maximumYCoord - 6143 + 200, 0);
4257
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5013
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4258
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5014
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4259
	    "margin_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5015
	    "margin_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4260
	    &sc->syninfo.margin_top, SYNAPTICS_SYSCTL_MARGIN_TOP,
5016
	    sc, SYNAPTICS_SYSCTL_MARGIN_TOP,
4261
	    synaptics_sysctl, "I",
5017
	    synaptics_sysctl, "I",
4262
	    "Top margin");
5018
	    "Top margin");
4263
5019
4264
	/* hw.psm.synaptics.right_margin. */
5020
	/* hw.psm.synaptics.right_margin. */
4265
	sc->syninfo.margin_right = 200;
5021
	sc->syninfo.margin_right =
5022
	    imax(sc->synhw.maximumXCoord - 6143 + 200, 0);
4266
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5023
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4267
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5024
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4268
	    "margin_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5025
	    "margin_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4269
	    &sc->syninfo.margin_right, SYNAPTICS_SYSCTL_MARGIN_RIGHT,
5026
	    sc, SYNAPTICS_SYSCTL_MARGIN_RIGHT,
4270
	    synaptics_sysctl, "I",
5027
	    synaptics_sysctl, "I",
4271
	    "Right margin");
5028
	    "Right margin");
4272
5029
Lines 4275-4281 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4275
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5032
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4276
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5033
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4277
	    "margin_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5034
	    "margin_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4278
	    &sc->syninfo.margin_bottom, SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
5035
	    sc, SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
4279
	    synaptics_sysctl, "I",
5036
	    synaptics_sysctl, "I",
4280
	    "Bottom margin");
5037
	    "Bottom margin");
4281
5038
Lines 4284-4309 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4284
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5041
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4285
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5042
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4286
	    "margin_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5043
	    "margin_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4287
	    &sc->syninfo.margin_left, SYNAPTICS_SYSCTL_MARGIN_LEFT,
5044
	    sc, SYNAPTICS_SYSCTL_MARGIN_LEFT,
4288
	    synaptics_sysctl, "I",
5045
	    synaptics_sysctl, "I",
4289
	    "Left margin");
5046
	    "Left margin");
4290
5047
4291
	/* hw.psm.synaptics.na_top. */
5048
	/* hw.psm.synaptics.na_top. */
4292
	sc->syninfo.na_top = 1783;
5049
	sc->syninfo.na_top = imax(sc->synhw.maximumXCoord - 6143 + 1783, 0);
4293
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5050
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4294
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5051
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4295
	    "na_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5052
	    "na_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4296
	    &sc->syninfo.na_top, SYNAPTICS_SYSCTL_NA_TOP,
5053
	    sc, SYNAPTICS_SYSCTL_NA_TOP,
4297
	    synaptics_sysctl, "I",
5054
	    synaptics_sysctl, "I",
4298
	    "Top noisy area, where weight_previous_na is used instead "
5055
	    "Top noisy area, where weight_previous_na is used instead "
4299
	    "of weight_previous");
5056
	    "of weight_previous");
4300
5057
4301
	/* hw.psm.synaptics.na_right. */
5058
	/* hw.psm.synaptics.na_right. */
4302
	sc->syninfo.na_right = 563;
5059
	sc->syninfo.na_right = imax(sc->synhw.maximumYCoord - 6143 + 563, 0);
4303
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5060
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4304
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5061
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4305
	    "na_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5062
	    "na_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4306
	    &sc->syninfo.na_right, SYNAPTICS_SYSCTL_NA_RIGHT,
5063
	    sc, SYNAPTICS_SYSCTL_NA_RIGHT,
4307
	    synaptics_sysctl, "I",
5064
	    synaptics_sysctl, "I",
4308
	    "Right noisy area, where weight_previous_na is used instead "
5065
	    "Right noisy area, where weight_previous_na is used instead "
4309
	    "of weight_previous");
5066
	    "of weight_previous");
Lines 4313-4319 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4313
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5070
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4314
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5071
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4315
	    "na_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5072
	    "na_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4316
	    &sc->syninfo.na_bottom, SYNAPTICS_SYSCTL_NA_BOTTOM,
5073
	    sc, SYNAPTICS_SYSCTL_NA_BOTTOM,
4317
	    synaptics_sysctl, "I",
5074
	    synaptics_sysctl, "I",
4318
	    "Bottom noisy area, where weight_previous_na is used instead "
5075
	    "Bottom noisy area, where weight_previous_na is used instead "
4319
	    "of weight_previous");
5076
	    "of weight_previous");
Lines 4323-4329 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4323
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5080
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4324
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5081
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4325
	    "na_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5082
	    "na_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4326
	    &sc->syninfo.na_left, SYNAPTICS_SYSCTL_NA_LEFT,
5083
	    sc, SYNAPTICS_SYSCTL_NA_LEFT,
4327
	    synaptics_sysctl, "I",
5084
	    synaptics_sysctl, "I",
4328
	    "Left noisy area, where weight_previous_na is used instead "
5085
	    "Left noisy area, where weight_previous_na is used instead "
4329
	    "of weight_previous");
5086
	    "of weight_previous");
Lines 4333-4339 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4333
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5090
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4334
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5091
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4335
	    "window_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5092
	    "window_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4336
	    &sc->syninfo.window_min, SYNAPTICS_SYSCTL_WINDOW_MIN,
5093
	    sc, SYNAPTICS_SYSCTL_WINDOW_MIN,
4337
	    synaptics_sysctl, "I",
5094
	    synaptics_sysctl, "I",
4338
	    "Minimum window size to start an action");
5095
	    "Minimum window size to start an action");
4339
5096
Lines 4342-4348 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4342
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5099
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4343
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5100
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4344
	    "window_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5101
	    "window_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4345
	    &sc->syninfo.window_max, SYNAPTICS_SYSCTL_WINDOW_MAX,
5102
	    sc, SYNAPTICS_SYSCTL_WINDOW_MAX,
4346
	    synaptics_sysctl, "I",
5103
	    synaptics_sysctl, "I",
4347
	    "Maximum window size");
5104
	    "Maximum window size");
4348
5105
Lines 4351-4357 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4351
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5108
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4352
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5109
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4353
	    "multiplicator", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5110
	    "multiplicator", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4354
	    &sc->syninfo.multiplicator, SYNAPTICS_SYSCTL_MULTIPLICATOR,
5111
	    sc, SYNAPTICS_SYSCTL_MULTIPLICATOR,
4355
	    synaptics_sysctl, "I",
5112
	    synaptics_sysctl, "I",
4356
	    "Multiplicator to increase precision in averages and divisions");
5113
	    "Multiplicator to increase precision in averages and divisions");
4357
5114
Lines 4360-4366 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4360
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5117
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4361
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5118
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4362
	    "weight_current", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5119
	    "weight_current", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4363
	    &sc->syninfo.weight_current, SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
5120
	    sc, SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
4364
	    synaptics_sysctl, "I",
5121
	    synaptics_sysctl, "I",
4365
	    "Weight of the current movement in the new average");
5122
	    "Weight of the current movement in the new average");
4366
5123
Lines 4369-4375 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4369
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5126
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4370
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5127
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4371
	    "weight_previous", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5128
	    "weight_previous", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4372
	    &sc->syninfo.weight_previous, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
5129
	    sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
4373
	    synaptics_sysctl, "I",
5130
	    synaptics_sysctl, "I",
4374
	    "Weight of the previous average");
5131
	    "Weight of the previous average");
4375
5132
Lines 4378-4385 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4378
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5135
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4379
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5136
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4380
	    "weight_previous_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5137
	    "weight_previous_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4381
	    &sc->syninfo.weight_previous_na,
5138
	    sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
4382
	    SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
4383
	    synaptics_sysctl, "I",
5139
	    synaptics_sysctl, "I",
4384
	    "Weight of the previous average (inside the noisy area)");
5140
	    "Weight of the previous average (inside the noisy area)");
4385
5141
Lines 4388-4395 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4388
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5144
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4389
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5145
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4390
	    "weight_len_squared", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5146
	    "weight_len_squared", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4391
	    &sc->syninfo.weight_len_squared,
5147
	    sc, SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
4392
	    SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
4393
	    synaptics_sysctl, "I",
5148
	    synaptics_sysctl, "I",
4394
	    "Length (squared) of segments where weight_previous "
5149
	    "Length (squared) of segments where weight_previous "
4395
	    "starts to decrease");
5150
	    "starts to decrease");
Lines 4399-4405 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4399
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5154
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4400
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5155
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4401
	    "div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5156
	    "div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4402
	    &sc->syninfo.div_min, SYNAPTICS_SYSCTL_DIV_MIN,
5157
	    sc, SYNAPTICS_SYSCTL_DIV_MIN,
4403
	    synaptics_sysctl, "I",
5158
	    synaptics_sysctl, "I",
4404
	    "Divisor for fast movements");
5159
	    "Divisor for fast movements");
4405
5160
Lines 4408-4414 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4408
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5163
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4409
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5164
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4410
	    "div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5165
	    "div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4411
	    &sc->syninfo.div_max, SYNAPTICS_SYSCTL_DIV_MAX,
5166
	    sc, SYNAPTICS_SYSCTL_DIV_MAX,
4412
	    synaptics_sysctl, "I",
5167
	    synaptics_sysctl, "I",
4413
	    "Divisor for slow movements");
5168
	    "Divisor for slow movements");
4414
5169
Lines 4417-4423 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4417
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5172
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4418
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5173
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4419
	    "div_max_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5174
	    "div_max_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4420
	    &sc->syninfo.div_max_na, SYNAPTICS_SYSCTL_DIV_MAX_NA,
5175
	    sc, SYNAPTICS_SYSCTL_DIV_MAX_NA,
4421
	    synaptics_sysctl, "I",
5176
	    synaptics_sysctl, "I",
4422
	    "Divisor with slow movements (inside the noisy area)");
5177
	    "Divisor with slow movements (inside the noisy area)");
4423
5178
Lines 4426-4432 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4426
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5181
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4427
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5182
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4428
	    "div_len", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5183
	    "div_len", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4429
	    &sc->syninfo.div_len, SYNAPTICS_SYSCTL_DIV_LEN,
5184
	    sc, SYNAPTICS_SYSCTL_DIV_LEN,
4430
	    synaptics_sysctl, "I",
5185
	    synaptics_sysctl, "I",
4431
	    "Length of segments where div_max starts to decrease");
5186
	    "Length of segments where div_max starts to decrease");
4432
5187
Lines 4435-4441 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4435
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5190
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4436
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5191
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4437
	    "tap_max_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5192
	    "tap_max_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4438
	    &sc->syninfo.tap_max_delta, SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
5193
	    sc, SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
4439
	    synaptics_sysctl, "I",
5194
	    synaptics_sysctl, "I",
4440
	    "Length of segments above which a tap is ignored");
5195
	    "Length of segments above which a tap is ignored");
4441
5196
Lines 4444-4460 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4444
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5199
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4445
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5200
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4446
	    "tap_min_queue", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5201
	    "tap_min_queue", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4447
	    &sc->syninfo.tap_min_queue, SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
5202
	    sc, SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
4448
	    synaptics_sysctl, "I",
5203
	    synaptics_sysctl, "I",
4449
	    "Number of packets required to consider a tap");
5204
	    "Number of packets required to consider a tap");
4450
5205
4451
	/* hw.psm.synaptics.taphold_timeout. */
5206
	/* hw.psm.synaptics.taphold_timeout. */
4452
	sc->synaction.in_taphold = 0;
5207
	sc->gesture.in_taphold = 0;
4453
	sc->syninfo.taphold_timeout = tap_timeout;
5208
	sc->syninfo.taphold_timeout = tap_timeout;
4454
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5209
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4455
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5210
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4456
	    "taphold_timeout", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5211
	    "taphold_timeout", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4457
	    &sc->syninfo.taphold_timeout, SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
5212
	    sc, SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
4458
	    synaptics_sysctl, "I",
5213
	    synaptics_sysctl, "I",
4459
	    "Maximum elapsed time between two taps to consider a tap-hold "
5214
	    "Maximum elapsed time between two taps to consider a tap-hold "
4460
	    "action");
5215
	    "action");
Lines 4464-4479 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4464
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5219
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4465
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5220
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4466
	    "vscroll_hor_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5221
	    "vscroll_hor_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4467
	    &sc->syninfo.vscroll_hor_area, SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
5222
	    sc, SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
4468
	    synaptics_sysctl, "I",
5223
	    synaptics_sysctl, "I",
4469
	    "Area reserved for horizontal virtual scrolling");
5224
	    "Area reserved for horizontal virtual scrolling");
4470
5225
4471
	/* hw.psm.synaptics.vscroll_ver_area. */
5226
	/* hw.psm.synaptics.vscroll_ver_area. */
4472
	sc->syninfo.vscroll_ver_area = -600;
5227
	sc->syninfo.vscroll_ver_area = -400 - sc->syninfo.margin_right;
4473
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5228
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4474
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5229
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4475
	    "vscroll_ver_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5230
	    "vscroll_ver_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4476
	    &sc->syninfo.vscroll_ver_area, SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
5231
	    sc, SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
4477
	    synaptics_sysctl, "I",
5232
	    synaptics_sysctl, "I",
4478
	    "Area reserved for vertical virtual scrolling");
5233
	    "Area reserved for vertical virtual scrolling");
4479
5234
Lines 4482-4489 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4482
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5237
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4483
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5238
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4484
	    "vscroll_min_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5239
	    "vscroll_min_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4485
	    &sc->syninfo.vscroll_min_delta,
5240
	    sc, SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
4486
	    SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
4487
	    synaptics_sysctl, "I",
5241
	    synaptics_sysctl, "I",
4488
	    "Minimum movement to consider virtual scrolling");
5242
	    "Minimum movement to consider virtual scrolling");
4489
5243
Lines 4492-4498 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4492
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5246
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4493
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5247
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4494
	    "vscroll_div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5248
	    "vscroll_div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4495
	    &sc->syninfo.vscroll_div_min, SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
5249
	    sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
4496
	    synaptics_sysctl, "I",
5250
	    synaptics_sysctl, "I",
4497
	    "Divisor for fast scrolling");
5251
	    "Divisor for fast scrolling");
4498
5252
Lines 4501-4507 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4501
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5255
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4502
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5256
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4503
	    "vscroll_div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5257
	    "vscroll_div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4504
	    &sc->syninfo.vscroll_div_max, SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
5258
	    sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
4505
	    synaptics_sysctl, "I",
5259
	    synaptics_sysctl, "I",
4506
	    "Divisor for slow scrolling");
5260
	    "Divisor for slow scrolling");
4507
5261
Lines 4510-4518 synaptics_sysctl_create_tree(struct psm_softc *sc) Link Here
4510
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5264
	SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4511
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5265
	    SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4512
	    "touchpad_off", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5266
	    "touchpad_off", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4513
	    &sc->syninfo.touchpad_off, SYNAPTICS_SYSCTL_TOUCHPAD_OFF,
5267
	    sc, SYNAPTICS_SYSCTL_TOUCHPAD_OFF,
4514
	    synaptics_sysctl, "I",
5268
	    synaptics_sysctl, "I",
4515
	    "Turn off touchpad");
5269
	    "Turn off touchpad");
5270
5271
	sc->syninfo.softbuttons_y = 0;
5272
	sc->syninfo.softbutton2_x = 0;
5273
	sc->syninfo.softbutton3_x = 0;
5274
5275
	/* skip softbuttons sysctl on not clickpads */
5276
	if (sc->synhw.capClickPad)
5277
		synaptics_sysctl_create_softbuttons_tree(sc);
4516
}
5278
}
4517
5279
4518
static int
5280
static int
Lines 4754-4760 enable_synaptics(struct psm_softc *sc, enum probearg arg) Link Here
4754
						     ((status[1] & 0x0f) << 1);
5516
						     ((status[1] & 0x0f) << 1);
4755
				synhw.maximumYCoord = (status[2] << 5) |
5517
				synhw.maximumYCoord = (status[2] << 5) |
4756
						     ((status[1] & 0xf0) >> 3);
5518
						     ((status[1] & 0xf0) >> 3);
4757
			}
5519
			} else
5520
				synhw.maximumXCoord = synhw.maximumYCoord =
5521
				    6143;
5522
4758
			if (synhw.capReportsMin) {
5523
			if (synhw.capReportsMin) {
4759
				if (!set_mouse_scaling(kbdc, 1))
5524
				if (!set_mouse_scaling(kbdc, 1))
4760
					return (FALSE);
5525
					return (FALSE);
Lines 4767-4773 enable_synaptics(struct psm_softc *sc, enum probearg arg) Link Here
4767
						     ((status[1] & 0x0f) << 1);
5532
						     ((status[1] & 0x0f) << 1);
4768
				synhw.minimumYCoord = (status[2] << 5) |
5533
				synhw.minimumYCoord = (status[2] << 5) |
4769
						     ((status[1] & 0xf0) >> 3);
5534
						     ((status[1] & 0xf0) >> 3);
4770
			}
5535
			} else
5536
				synhw.minimumXCoord = synhw.minimumYCoord = 0;
4771
5537
4772
			if (verbose >= 2) {
5538
			if (verbose >= 2) {
4773
				printf("  Continued capabilities:\n");
5539
				printf("  Continued capabilities:\n");
Lines 4854-4860 enable_synaptics(struct psm_softc *sc, enum probearg arg) Link Here
4854
5620
4855
	if (arg == PROBE) {
5621
	if (arg == PROBE) {
4856
		/* Create sysctl tree. */
5622
		/* Create sysctl tree. */
4857
		synaptics_sysctl_create_tree(sc);
5623
		synaptics_sysctl_create_tree(sc, "synaptics",
5624
		    "Synaptics TouchPad");
4858
		sc->hw.buttons = buttons;
5625
		sc->hw.buttons = buttons;
4859
	}
5626
	}
4860
5627
Lines 5171-5176 enable_versapad(struct psm_softc *sc, enum probearg arg) Link Here
5171
	return (TRUE);				/* PS/2 absolute mode */
5938
	return (TRUE);				/* PS/2 absolute mode */
5172
}
5939
}
5173
5940
5941
/* Elantech Touchpad */
5942
static int
5943
elantech_read_1(KBDC kbdc, int hwversion, int reg, int *val)
5944
{
5945
	int res, readcmd, retidx;
5946
	int resp[3];
5947
5948
	readcmd = hwversion == 2 ? ELANTECH_REG_READ : ELANTECH_REG_RDWR;
5949
	retidx = hwversion == 4 ? 1 : 0;
5950
5951
	res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5952
	res |= send_aux_command(kbdc, readcmd) != PSM_ACK;
5953
	res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5954
	res |= send_aux_command(kbdc, reg) != PSM_ACK;
5955
	res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
5956
5957
	if (res == 0)
5958
		*val = resp[retidx];
5959
5960
	return (res);
5961
}
5962
5963
static int
5964
elantech_write_1(KBDC kbdc, int hwversion, int reg, int val)
5965
{
5966
	int res, writecmd;
5967
5968
	writecmd = hwversion == 2 ? ELANTECH_REG_WRITE : ELANTECH_REG_RDWR;
5969
5970
	res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5971
	res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
5972
	res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5973
	res |= send_aux_command(kbdc, reg) != PSM_ACK;
5974
	if (hwversion == 4) {
5975
		res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5976
		res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
5977
	}
5978
	res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5979
	res |= send_aux_command(kbdc, val) != PSM_ACK;
5980
	res |= set_mouse_scaling(kbdc, 1) == 0;
5981
5982
	return (res);
5983
}
5984
5985
static int
5986
elantech_cmd(KBDC kbdc, int hwversion, int cmd, int *resp)
5987
{
5988
	int res;
5989
5990
	if (hwversion == 2) {
5991
		res = set_mouse_scaling(kbdc, 1) == 0;
5992
		res |= mouse_ext_command(kbdc, cmd) == 0;
5993
	} else {
5994
		res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
5995
		res |= send_aux_command(kbdc, cmd) != PSM_ACK;
5996
	}
5997
	res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
5998
5999
	return (res);
6000
}
6001
6002
static int
6003
elantech_init(KBDC kbdc, elantechhw_t *elanhw)
6004
{
6005
	int i, val, res, hwversion, reg10;
6006
6007
	/* set absolute mode */
6008
	hwversion = elanhw->hwversion;
6009
	reg10 = -1;
6010
	switch (hwversion) {
6011
	case 2:
6012
		reg10 = elanhw->fwversion == 0x020030 ? 0x54 : 0xc4;
6013
		res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
6014
		if (res)
6015
			break;
6016
		res = elantech_write_1(kbdc, hwversion, 0x11, 0x8A);
6017
		break;
6018
	case 3:
6019
		reg10 = 0x0b;
6020
		res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
6021
		break;
6022
	case 4:
6023
		res = elantech_write_1(kbdc, hwversion, 0x07, 0x01);
6024
		break;
6025
	default:
6026
		res = 1;
6027
	}
6028
6029
	/* Read back reg 0x10 to ensure hardware is ready. */
6030
	if (res == 0 && reg10 >= 0) {
6031
		for (i = 0; i < 5; i++) {
6032
			if (elantech_read_1(kbdc, hwversion, 0x10, &val) == 0)
6033
				break;
6034
			DELAY(2000);
6035
		}
6036
		if (i == 5)
6037
			res = 1;
6038
	}
6039
6040
	if (res)
6041
		printf("couldn't set absolute mode\n");
6042
6043
	return (res);
6044
}
6045
6046
static void
6047
elantech_init_synaptics(struct psm_softc *sc)
6048
{
6049
6050
	/* Set capabilites required by movement smother */
6051
	sc->synhw.infoMajor = sc->elanhw.hwversion;
6052
	sc->synhw.infoMinor = sc->elanhw.fwversion;
6053
	sc->synhw.infoXupmm = sc->elanhw.dpmmx;
6054
	sc->synhw.infoYupmm = sc->elanhw.dpmmy;
6055
	sc->synhw.verticalScroll = 0;
6056
	sc->synhw.nExtendedQueries = 4;
6057
	sc->synhw.capExtended = 1;
6058
	sc->synhw.capPassthrough = sc->elanhw.hastrackpad;
6059
	sc->synhw.capClickPad = sc->elanhw.isclickpad;
6060
	sc->synhw.capMultiFinger = 1;
6061
	sc->synhw.capAdvancedGestures = 1;
6062
	sc->synhw.capPalmDetect = 1;
6063
	sc->synhw.capPen = 0;
6064
	sc->synhw.capReportsMax = 1;
6065
	sc->synhw.maximumXCoord = sc->elanhw.sizex;
6066
	sc->synhw.maximumYCoord = sc->elanhw.sizey;
6067
	sc->synhw.capReportsMin = 1;
6068
	sc->synhw.minimumXCoord = 0;
6069
	sc->synhw.minimumYCoord = 0;
6070
6071
	if (sc->syninfo.sysctl_tree == NULL) {
6072
		synaptics_sysctl_create_tree(sc, "elantech",
6073
		    "Elantech Touchpad");
6074
6075
		/*
6076
		 * Adjust synaptic smoother tunables
6077
		 * 1. Disable finger detection pressure threshold. Unlike
6078
		 *    synaptics we assume the finger is acting when packet with
6079
		 *    its X&Y arrives not when pressure exceedes some threshold
6080
		 * 2. Disable unrelated features like margins and noisy areas
6081
		 * 3. Disable virtual scroll areas as 2nd finger is preferable
6082
		 * 4. For clickpads set bottom quarter as 3 equaly sized
6083
		 *    softbuttons
6084
		 * 5. Scale down divisors and movement lengths by a factor of 3
6085
		 *    where 3 is Synaptics to Elantech (~2200/800) dpi ratio
6086
		 */
6087
6088
		/* Disable finger detection pressure threshold */
6089
		sc->syninfo.min_pressure = 1;
6090
6091
		/* Use full area of touchpad */
6092
		sc->syninfo.margin_top = 0;
6093
		sc->syninfo.margin_right = 0;
6094
		sc->syninfo.margin_bottom = 0;
6095
		sc->syninfo.margin_left = 0;
6096
		/* Disable noisy area */
6097
		sc->syninfo.na_top = 0;
6098
		sc->syninfo.na_right = 0;
6099
		sc->syninfo.na_bottom = 0;
6100
		sc->syninfo.na_left = 0;
6101
6102
		/* Tune divisors and movement lengths */
6103
		sc->syninfo.weight_len_squared = 200;
6104
		sc->syninfo.div_min = 3;
6105
		sc->syninfo.div_max = 6;
6106
		sc->syninfo.div_max_na = 10;
6107
		sc->syninfo.div_len = 30;
6108
		sc->syninfo.tap_max_delta = 25;
6109
6110
		/* Disable virtual scrolling areas and tune its divisors */
6111
		sc->syninfo.vscroll_hor_area = 0;
6112
		sc->syninfo.vscroll_ver_area = 0;
6113
		sc->syninfo.vscroll_min_delta = 15;
6114
		sc->syninfo.vscroll_div_min = 30;
6115
		sc->syninfo.vscroll_div_max = 50;
6116
6117
		/* Set bottom quarter as 3 equaly sized softbuttons */
6118
		if (sc->elanhw.isclickpad) {
6119
			sc->syninfo.softbuttons_y = sc->elanhw.sizey / 4;
6120
			sc->syninfo.softbutton2_x = sc->elanhw.sizex / 3;
6121
			sc->syninfo.softbutton3_x = sc->elanhw.sizex * 2 / 3;
6122
		}
6123
	}
6124
6125
	return;
6126
}
6127
6128
static int
6129
enable_elantech(struct psm_softc *sc, enum probearg arg)
6130
{
6131
	static const int ic2hw[] =
6132
	/*IC: 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
6133
	    { 0, 0, 2, 0, 2, 3, 4, 4, 4, 4, 4, 0, 0, 4, 4, 0 };
6134
	elantechhw_t elanhw;
6135
	int icversion, hwversion, dptracex, dptracey, id, resp[3], dpix, dpiy;
6136
	KBDC kbdc = sc->kbdc;
6137
6138
	VLOG(3, (LOG_DEBUG, "elantech: BEGIN init\n"));
6139
6140
	set_mouse_scaling(kbdc, 1);
6141
	set_mouse_scaling(kbdc, 1);
6142
	set_mouse_scaling(kbdc, 1);
6143
	if (get_mouse_status(kbdc, resp, 0, 3) != 3)
6144
		return (FALSE);
6145
6146
	if (!ELANTECH_MAGIC(resp))
6147
		return (FALSE);
6148
6149
	/* Identify the Touchpad version. */
6150
	if (elantech_cmd(kbdc, 2, ELANTECH_FW_VERSION, resp))
6151
		return (FALSE);
6152
6153
	bzero(&elanhw, sizeof(elanhw));
6154
6155
	elanhw.fwversion = (resp[0] << 16) | (resp[1] << 8) | resp[2];
6156
	icversion = resp[0] & 0x0f;
6157
	hwversion = ic2hw[icversion];
6158
6159
	if (verbose >= 2)
6160
		printf("Elantech touchpad hardware v.%d firmware v.0x%06x\n",
6161
		    hwversion, elanhw.fwversion);
6162
6163
	if (ELANTECH_HW_IS_V1(elanhw.fwversion)) {
6164
		printf ("  Unsupported touchpad hardware (v1)\n");
6165
		return (FALSE);
6166
	}
6167
	if (hwversion == 0) {
6168
		printf ("  Unknown touchpad hardware (firmware v.0x%06x)\n",
6169
		    elanhw.fwversion);
6170
		return (FALSE);
6171
	}
6172
6173
	/* Get the Touchpad model information. */
6174
	elanhw.hwversion = hwversion;
6175
	elanhw.issemimt = hwversion == 2 || hwversion == 3;
6176
	elanhw.isclickpad = (resp[1] & 0x10) != 0;
6177
	elanhw.hascrc = (resp[1] & 0x40) != 0;
6178
	elanhw.haspressure = elanhw.fwversion >= 0x020800;
6179
6180
	/* Read the capability bits. */
6181
	if (elantech_cmd(kbdc, hwversion, ELANTECH_CAPABILITIES, resp) != 0) {
6182
		printf("  Failed to read capability bits\n");
6183
		return (FALSE);
6184
	}
6185
6186
	elanhw.ntracesx = resp[1] - 1;
6187
	elanhw.ntracesy = resp[2] - 1;
6188
	elanhw.hastrackpad = (resp[0] & 0x80) != 0;
6189
6190
	/* Get the touchpad resolution */
6191
	switch (hwversion) {
6192
	case 2:
6193
		elanhw.dpmmx = elanhw.dpmmy = 16; /*  400 dpi */
6194
		break;
6195
	case 4:
6196
		if (elantech_cmd(kbdc, hwversion, ELANTECH_RESOLUTION, resp)
6197
		    == 0) {
6198
			dpix = (resp[1] & 0x0f) * 10 + 790;
6199
			dpiy = ((resp[1] & 0xf0) >> 4) * 10 + 790;
6200
			elanhw.dpmmx = (dpix * 10 + 5) / 254;
6201
			elanhw.dpmmy = (dpiy * 10 + 5) / 254;
6202
			break;
6203
		}
6204
		/* FALLTHROUGH */
6205
	case 3:
6206
		elanhw.dpmmx = elanhw.dpmmy = 32; /* 800 dpi */
6207
		break;
6208
	}
6209
6210
	if (!elantech_support)
6211
		return (FALSE);
6212
6213
	if (elantech_init(kbdc, &elanhw)) {
6214
		printf("couldn't initialize elantech touchpad\n");
6215
		return (FALSE);
6216
	}
6217
6218
	/*
6219
	 * Get the touchpad reporting range.
6220
	 * On HW v.3 touchpads it should be done after switching hardware
6221
	 * to real resolution mode (by setting bit 3 of reg10)
6222
	 */
6223
	if (elantech_cmd(kbdc, hwversion, ELANTECH_FW_ID, resp) != 0) {
6224
		printf("  Failed to read touchpad size\n");
6225
		elanhw.sizex = 10000; /* Arbitrary high values to     */
6226
		elanhw.sizey = 10000; /* prevent clipping in smoother */
6227
	} else if (hwversion == 2) {
6228
		dptracex = dptracey = 64;
6229
		if ((elanhw.fwversion >> 16) == 0x14 && (resp[1] & 0x10) &&
6230
		    !elantech_cmd(kbdc, hwversion, ELANTECH_SAMPLE, resp)) {
6231
			dptracex = resp[1] / 2;
6232
			dptracey = resp[2] / 2;
6233
		}
6234
		elanhw.sizex = (elanhw.ntracesx - 1) * dptracex;
6235
		elanhw.sizey = (elanhw.ntracesy - 1) * dptracey;
6236
	} else {
6237
		elanhw.sizex = (resp[0] & 0x0f) << 8 | resp[1];
6238
		elanhw.sizey = (resp[0] & 0xf0) << 4 | resp[2];
6239
	}
6240
6241
	if (verbose >= 2) {
6242
		printf("  Model information:\n");
6243
		printf("   MaxX:     %d\n", elanhw.sizex);
6244
		printf("   MaxY:     %d\n", elanhw.sizey);
6245
		printf("   DpmmX:    %d\n", elanhw.dpmmx);
6246
		printf("   DpmmY:    %d\n", elanhw.dpmmy);
6247
		printf("   TracesX:  %d\n", elanhw.ntracesx);
6248
		printf("   TracesY:  %d\n", elanhw.ntracesy);
6249
		printf("   SemiMT:   %d\n", elanhw.issemimt);
6250
		printf("   Clickpad: %d\n", elanhw.isclickpad);
6251
		printf("   Trackpad: %d\n", elanhw.hastrackpad);
6252
		printf("   CRC:      %d\n", elanhw.hascrc);
6253
		printf("   Pressure: %d\n", elanhw.haspressure);
6254
	}
6255
6256
	VLOG(3, (LOG_DEBUG, "elantech: END init\n"));
6257
6258
	if (arg == PROBE) {
6259
		sc->elanhw = elanhw;
6260
		sc->hw.buttons = elanhw.isclickpad ? 1 : 3;
6261
6262
		/* Initialize synaptics movement smoother */
6263
		elantech_init_synaptics(sc);
6264
6265
		for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
6266
			PSM_FINGER_RESET(sc->elanaction.fingers[id]);
6267
	}
6268
6269
	return (TRUE);
6270
}
6271
5174
/*
6272
/*
5175
 * Return true if 'now' is earlier than (start + (secs.usecs)).
6273
 * Return true if 'now' is earlier than (start + (secs.usecs)).
5176
 * Now may be NULL and the function will fetch the current time from
6274
 * Now may be NULL and the function will fetch the current time from
(-)b/sys/sys/mouse.h (+4 lines)
Lines 170-175 typedef struct synapticshw { Link Here
170
#define MOUSE_MODEL_4DPLUS		12
170
#define MOUSE_MODEL_4DPLUS		12
171
#define MOUSE_MODEL_SYNAPTICS		13
171
#define MOUSE_MODEL_SYNAPTICS		13
172
#define	MOUSE_MODEL_TRACKPOINT		14
172
#define	MOUSE_MODEL_TRACKPOINT		14
173
#define	MOUSE_MODEL_ELANTECH		15
173
174
174
typedef struct mousemode {
175
typedef struct mousemode {
175
	int protocol;		/* MOUSE_PROTO_XXX */
176
	int protocol;		/* MOUSE_PROTO_XXX */
Lines 240-245 typedef struct mousevar { Link Here
240
/* Synaptics Touchpad */
241
/* Synaptics Touchpad */
241
#define MOUSE_SYNAPTICS_PACKETSIZE	6	/* '3' works better */
242
#define MOUSE_SYNAPTICS_PACKETSIZE	6	/* '3' works better */
242
243
244
/* Elantech Touchpad */
245
#define MOUSE_ELANTECH_PACKETSIZE	6
246
243
/* Microsoft Serial mouse data packet */
247
/* Microsoft Serial mouse data packet */
244
#define MOUSE_MSS_PACKETSIZE	3
248
#define MOUSE_MSS_PACKETSIZE	3
245
#define MOUSE_MSS_SYNCMASK	0x40
249
#define MOUSE_MSS_SYNCMASK	0x40
(-)b/usr.sbin/moused/moused.c (+1 lines)
Lines 246-251 static symtab_t rmodels[] = { Link Here
246
    { "4D+ Mouse",		MOUSE_MODEL_4DPLUS,		0 },
246
    { "4D+ Mouse",		MOUSE_MODEL_4DPLUS,		0 },
247
    { "Synaptics Touchpad",	MOUSE_MODEL_SYNAPTICS,		0 },
247
    { "Synaptics Touchpad",	MOUSE_MODEL_SYNAPTICS,		0 },
248
    { "TrackPoint",		MOUSE_MODEL_TRACKPOINT,		0 },
248
    { "TrackPoint",		MOUSE_MODEL_TRACKPOINT,		0 },
249
    { "Elantech Touchpad",	MOUSE_MODEL_ELANTECH,		0 },
249
    { "generic",		MOUSE_MODEL_GENERIC,		0 },
250
    { "generic",		MOUSE_MODEL_GENERIC,		0 },
250
    { NULL,			MOUSE_MODEL_UNKNOWN,		0 },
251
    { NULL,			MOUSE_MODEL_UNKNOWN,		0 },
251
};
252
};

Return to bug 205690