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

Collapse All | Expand All

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