192
190
xf86FlushInput(fd);
193
191
PS2DBG(ErrorF("Reset the Touchpad...\n"));
194
192
if (!ps2_putbyte(fd, PS2_CMD_RESET)) {
195
PS2DBG(ErrorF("...failed\n"));
193
PS2DBG(ErrorF("...failed\n"));
198
196
xf86WaitForInput(fd, 4000000);
199
197
if (ps2_getbyte(fd, &r[0]) && ps2_getbyte(fd, &r[1])) {
200
if (r[0] == 0xAA && r[1] == 0x00) {
201
PS2DBG(ErrorF("...done\n"));
204
PS2DBG(ErrorF("...failed. Wrong reset ack 0x%02x, 0x%02x\n", r[0], r[1]));
198
if (r[0] == 0xAA && r[1] == 0x00) {
199
PS2DBG(ErrorF("...done\n"));
204
("...failed. Wrong reset ack 0x%02x, 0x%02x\n", r[0], r[1]));
208
208
PS2DBG(ErrorF("...failed\n"));
223
223
synhw->model_id = 0;
224
224
if (ps2_send_cmd(fd, SYN_QUE_MODEL) &&
225
ps2_getbyte(fd, &mi[0]) &&
226
ps2_getbyte(fd, &mi[1]) &&
227
ps2_getbyte(fd, &mi[2])) {
228
synhw->model_id = (mi[0] << 16) | (mi[1] << 8) | mi[2];
229
PS2DBG(ErrorF("model-id %06X\n", synhw->model_id));
230
PS2DBG(ErrorF("...done.\n"));
225
ps2_getbyte(fd, &mi[0]) &&
226
ps2_getbyte(fd, &mi[1]) && ps2_getbyte(fd, &mi[2])) {
227
synhw->model_id = (mi[0] << 16) | (mi[1] << 8) | mi[2];
228
PS2DBG(ErrorF("model-id %06X\n", synhw->model_id));
229
PS2DBG(ErrorF("...done.\n"));
233
232
PS2DBG(ErrorF("...failed.\n"));
248
247
synhw->capabilities = 0;
249
248
synhw->ext_cap = 0;
250
249
if (ps2_send_cmd(fd, SYN_QUE_CAPABILITIES) &&
251
ps2_getbyte(fd, &cap[0]) &&
252
ps2_getbyte(fd, &cap[1]) &&
253
ps2_getbyte(fd, &cap[2])) {
254
synhw->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
255
PS2DBG(ErrorF("capabilities %06X\n", synhw->capabilities));
256
if (SYN_CAP_VALID(synhw)) {
257
if (SYN_EXT_CAP_REQUESTS(synhw)) {
258
if (ps2_send_cmd(fd, SYN_QUE_EXT_CAPAB) &&
259
ps2_getbyte(fd, &cap[0]) &&
260
ps2_getbyte(fd, &cap[1]) &&
261
ps2_getbyte(fd, &cap[2])) {
262
synhw->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
263
PS2DBG(ErrorF("ext-capability %06X\n", synhw->ext_cap));
265
PS2DBG(ErrorF("synaptics says, that it has extended-capabilities, "
266
"but I cannot read them."));
269
PS2DBG(ErrorF("...done.\n"));
250
ps2_getbyte(fd, &cap[0]) &&
251
ps2_getbyte(fd, &cap[1]) && ps2_getbyte(fd, &cap[2])) {
252
synhw->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
253
PS2DBG(ErrorF("capabilities %06X\n", synhw->capabilities));
254
if (SYN_CAP_VALID(synhw)) {
255
if (SYN_EXT_CAP_REQUESTS(synhw)) {
256
if (ps2_send_cmd(fd, SYN_QUE_EXT_CAPAB) &&
257
ps2_getbyte(fd, &cap[0]) &&
258
ps2_getbyte(fd, &cap[1]) && ps2_getbyte(fd, &cap[2])) {
259
synhw->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
260
PS2DBG(ErrorF("ext-capability %06X\n", synhw->ext_cap));
264
("synaptics says, that it has extended-capabilities, "
265
"but I cannot read them."));
268
PS2DBG(ErrorF("...done.\n"));
273
272
PS2DBG(ErrorF("...failed.\n"));
288
287
synhw->identity = 0;
289
288
if (ps2_send_cmd(fd, SYN_QUE_IDENTIFY) &&
290
ps2_getbyte(fd, &id[0]) &&
291
ps2_getbyte(fd, &id[1]) &&
292
ps2_getbyte(fd, &id[2])) {
293
synhw->identity = (id[0] << 16) | (id[1] << 8) | id[2];
294
PS2DBG(ErrorF("ident %06X\n", synhw->identity));
295
if (SYN_ID_IS_SYNAPTICS(synhw)) {
296
PS2DBG(ErrorF("...done.\n"));
289
ps2_getbyte(fd, &id[0]) &&
290
ps2_getbyte(fd, &id[1]) && ps2_getbyte(fd, &id[2])) {
291
synhw->identity = (id[0] << 16) | (id[1] << 8) | id[2];
292
PS2DBG(ErrorF("ident %06X\n", synhw->identity));
293
if (SYN_ID_IS_SYNAPTICS(synhw)) {
294
PS2DBG(ErrorF("...done.\n"));
300
298
PS2DBG(ErrorF("...failed.\n"));
318
ps2_query_is_synaptics(InputInfoPtr pInfo, int fd, struct PS2SynapticsHwInfo* synhw)
316
ps2_query_is_synaptics(InputInfoPtr pInfo, int fd,
317
struct PS2SynapticsHwInfo *synhw)
322
321
for (i = 0; i < 3; i++) {
323
if (ps2_synaptics_disable_device(fd))
322
if (ps2_synaptics_disable_device(fd))
327
326
xf86WaitForInput(fd, 20000);
328
327
xf86FlushInput(fd);
329
328
if (ps2_synaptics_identify(fd, synhw)) {
332
xf86IDrvMsg(pInfo, X_ERROR, "Query no Synaptics: %06X\n", synhw->identity);
332
xf86IDrvMsg(pInfo, X_ERROR, "Query no Synaptics: %06X\n",
338
339
ps2_print_ident(InputInfoPtr pInfo, const struct PS2SynapticsHwInfo *synhw)
340
xf86IDrvMsg(pInfo, X_PROBED, " Synaptics Touchpad, model: %d\n", SYN_ID_MODEL(synhw));
341
xf86IDrvMsg(pInfo, X_PROBED, " Synaptics Touchpad, model: %d\n",
342
SYN_ID_MODEL(synhw));
341
343
xf86IDrvMsg(pInfo, X_PROBED, " Firmware: %d.%d\n", SYN_ID_MAJOR(synhw),
342
SYN_ID_MINOR(synhw));
344
SYN_ID_MINOR(synhw));
344
346
if (SYN_MODEL_ROT180(synhw))
345
xf86IDrvMsg(pInfo, X_PROBED, " 180 degree mounted touchpad\n");
347
xf86IDrvMsg(pInfo, X_PROBED, " 180 degree mounted touchpad\n");
346
348
if (SYN_MODEL_PORTRAIT(synhw))
347
xf86IDrvMsg(pInfo, X_PROBED, " portrait touchpad\n");
349
xf86IDrvMsg(pInfo, X_PROBED, " portrait touchpad\n");
348
350
xf86IDrvMsg(pInfo, X_PROBED, " Sensor: %d\n", SYN_MODEL_SENSOR(synhw));
349
351
if (SYN_MODEL_NEWABS(synhw))
350
xf86IDrvMsg(pInfo, X_PROBED, " new absolute packet format\n");
352
xf86IDrvMsg(pInfo, X_PROBED, " new absolute packet format\n");
351
353
if (SYN_MODEL_PEN(synhw))
352
xf86IDrvMsg(pInfo, X_PROBED, " pen detection\n");
354
xf86IDrvMsg(pInfo, X_PROBED, " pen detection\n");
354
356
if (SYN_CAP_EXTENDED(synhw)) {
355
xf86IDrvMsg(pInfo, X_PROBED, " Touchpad has extended capability bits\n");
356
if (SYN_CAP_MULTI_BUTTON_NO(synhw))
357
xf86IDrvMsg(pInfo, X_PROBED, " -> %d multi buttons, i.e. besides standard buttons\n",
358
(int)(SYN_CAP_MULTI_BUTTON_NO(synhw)));
359
if (SYN_CAP_MIDDLE_BUTTON(synhw))
360
xf86IDrvMsg(pInfo, X_PROBED, " -> middle button\n");
361
if (SYN_CAP_FOUR_BUTTON(synhw))
362
xf86IDrvMsg(pInfo, X_PROBED, " -> four buttons\n");
363
if (SYN_CAP_MULTIFINGER(synhw))
364
xf86IDrvMsg(pInfo, X_PROBED, " -> multifinger detection\n");
365
if (SYN_CAP_PALMDETECT(synhw))
366
xf86IDrvMsg(pInfo, X_PROBED, " -> palm detection\n");
367
if (SYN_CAP_PASSTHROUGH(synhw))
368
xf86IDrvMsg(pInfo, X_PROBED, " -> pass-through port\n");
357
xf86IDrvMsg(pInfo, X_PROBED,
358
" Touchpad has extended capability bits\n");
359
if (SYN_CAP_MULTI_BUTTON_NO(synhw))
360
xf86IDrvMsg(pInfo, X_PROBED,
361
" -> %d multi buttons, i.e. besides standard buttons\n",
362
(int) (SYN_CAP_MULTI_BUTTON_NO(synhw)));
363
if (SYN_CAP_MIDDLE_BUTTON(synhw))
364
xf86IDrvMsg(pInfo, X_PROBED, " -> middle button\n");
365
if (SYN_CAP_FOUR_BUTTON(synhw))
366
xf86IDrvMsg(pInfo, X_PROBED, " -> four buttons\n");
367
if (SYN_CAP_MULTIFINGER(synhw))
368
xf86IDrvMsg(pInfo, X_PROBED, " -> multifinger detection\n");
369
if (SYN_CAP_PALMDETECT(synhw))
370
xf86IDrvMsg(pInfo, X_PROBED, " -> palm detection\n");
371
if (SYN_CAP_PASSTHROUGH(synhw))
372
xf86IDrvMsg(pInfo, X_PROBED, " -> pass-through port\n");
382
386
PS2QueryHardware(InputInfoPtr pInfo)
385
SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private;
389
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
386
390
struct PS2SynapticsHwInfo *synhw;
388
392
if (!priv->proto_data)
389
393
priv->proto_data = calloc(1, sizeof(struct PS2SynapticsHwInfo));
390
synhw = (struct PS2SynapticsHwInfo*)priv->proto_data;
394
synhw = (struct PS2SynapticsHwInfo *) priv->proto_data;
392
396
/* is the synaptics touchpad active? */
393
397
if (!ps2_query_is_synaptics(pInfo, pInfo->fd, synhw))
396
400
xf86IDrvMsg(pInfo, X_PROBED, "synaptics touchpad found\n");
398
402
if (!ps2_synaptics_reset(pInfo->fd))
399
xf86IDrvMsg(pInfo, X_ERROR, "reset failed\n");
403
xf86IDrvMsg(pInfo, X_ERROR, "reset failed\n");
401
405
if (!ps2_synaptics_identify(pInfo->fd, synhw))
404
408
if (!ps2_synaptics_model_id(pInfo->fd, synhw))
407
411
if (!ps2_synaptics_capability(pInfo->fd, synhw))
410
414
mode = SYN_BIT_ABSOLUTE_MODE | SYN_BIT_HIGH_RATE;
411
415
if (SYN_ID_MAJOR(synhw) >= 4)
412
mode |= SYN_BIT_DISABLE_GESTURE;
416
mode |= SYN_BIT_DISABLE_GESTURE;
413
417
if (SYN_CAP_EXTENDED(synhw))
414
mode |= SYN_BIT_W_MODE;
418
mode |= SYN_BIT_W_MODE;
415
419
if (!ps2_synaptics_set_mode(pInfo->fd, mode))
418
422
ps2_synaptics_enable_device(pInfo->fd);
432
436
int newabs = SYN_MODEL_NEWABS(synhw);
434
438
if (newabs ? ((buf[0] & 0xC0) != 0x80) : ((buf[0] & 0xC0) != 0xC0)) {
435
DBG(4, "Synaptics driver lost sync at 1st byte\n");
439
DBG(4, "Synaptics driver lost sync at 1st byte\n");
439
443
if (!newabs && ((buf[1] & 0x60) != 0x00)) {
440
DBG(4, "Synaptics driver lost sync at 2nd byte\n");
444
DBG(4, "Synaptics driver lost sync at 2nd byte\n");
444
448
if ((newabs ? ((buf[3] & 0xC0) != 0xC0) : ((buf[3] & 0xC0) != 0x80))) {
445
DBG(4, "Synaptics driver lost sync at 4th byte\n");
449
DBG(4, "Synaptics driver lost sync at 4th byte\n");
449
453
if (!newabs && ((buf[4] & 0x60) != 0x00)) {
450
DBG(4, "Synaptics driver lost sync at 5th byte\n");
454
DBG(4, "Synaptics driver lost sync at 5th byte\n");
458
462
ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
459
struct SynapticsProtocolOperations *proto_ops,
460
struct CommData *comm)
463
struct SynapticsProtocolOperations *proto_ops,
464
struct CommData *comm)
466
470
while ((c = XisbRead(comm->buffer)) >= 0) {
467
u = (unsigned char)c;
469
/* test if there is a reset sequence received */
470
if ((c == 0x00) && (comm->lastByte == 0xAA)) {
471
if (xf86WaitForInput(pInfo->fd, 50000) == 0) {
472
DBG(7, "Reset received\n");
473
proto_ops->QueryHardware(pInfo);
475
DBG(3, "faked reset received\n");
479
/* to avoid endless loops */
481
xf86IDrvMsg(pInfo, X_ERROR, "Synaptics driver lost sync... got gigantic packet!\n");
485
comm->protoBuf[comm->protoBufTail++] = u;
487
/* Check that we have a valid packet. If not, we are out of sync,
488
so we throw away the first byte in the packet.*/
489
if (comm->protoBufTail >= 6) {
490
if (!ps2_packet_ok(synhw, comm)) {
492
for (i = 0; i < comm->protoBufTail - 1; i++)
493
comm->protoBuf[i] = comm->protoBuf[i + 1];
494
comm->protoBufTail--;
496
if (comm->outOfSync > MAX_UNSYNC_PACKETS) {
498
DBG(3, "Synaptics synchronization lost too long -> reset touchpad.\n");
499
proto_ops->QueryHardware(pInfo); /* including a reset */
505
if (comm->protoBufTail >= 6) { /* Full packet received */
506
if (comm->outOfSync > 0) {
508
DBG(4, "Synaptics driver resynced.\n");
510
comm->protoBufTail = 0;
471
u = (unsigned char) c;
473
/* test if there is a reset sequence received */
474
if ((c == 0x00) && (comm->lastByte == 0xAA)) {
475
if (xf86WaitForInput(pInfo->fd, 50000) == 0) {
476
DBG(7, "Reset received\n");
477
proto_ops->QueryHardware(pInfo);
480
DBG(3, "faked reset received\n");
484
/* to avoid endless loops */
486
xf86IDrvMsg(pInfo, X_ERROR,
487
"Synaptics driver lost sync... got gigantic packet!\n");
491
comm->protoBuf[comm->protoBufTail++] = u;
493
/* Check that we have a valid packet. If not, we are out of sync,
494
so we throw away the first byte in the packet. */
495
if (comm->protoBufTail >= 6) {
496
if (!ps2_packet_ok(synhw, comm)) {
499
for (i = 0; i < comm->protoBufTail - 1; i++)
500
comm->protoBuf[i] = comm->protoBuf[i + 1];
501
comm->protoBufTail--;
503
if (comm->outOfSync > MAX_UNSYNC_PACKETS) {
506
"Synaptics synchronization lost too long -> reset touchpad.\n");
507
proto_ops->QueryHardware(pInfo); /* including a reset */
513
if (comm->protoBufTail >= 6) { /* Full packet received */
514
if (comm->outOfSync > 0) {
516
DBG(4, "Synaptics driver resynced.\n");
518
comm->protoBufTail = 0;
519
527
PS2ReadHwStateProto(InputInfoPtr pInfo,
520
struct SynapticsProtocolOperations *proto_ops,
521
struct CommData *comm, struct SynapticsHwState *hwRet)
528
struct SynapticsProtocolOperations *proto_ops,
529
struct CommData *comm, struct SynapticsHwState *hwRet)
523
531
unsigned char *buf = comm->protoBuf;
524
532
struct SynapticsHwState *hw = comm->hwState;
525
SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private;
533
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
526
534
SynapticsParameters *para = &priv->synpara;
527
535
struct PS2SynapticsHwInfo *synhw;
531
synhw = (struct PS2SynapticsHwInfo*)priv->proto_data;
539
synhw = (struct PS2SynapticsHwInfo *) priv->proto_data;
534
541
xf86IDrvMsg(pInfo, X_ERROR,
535
542
"PS2ReadHwState, synhw is NULL. This is a bug.\n");
539
546
newabs = SYN_MODEL_NEWABS(synhw);
541
548
if (!ps2_synaptics_get_packet(pInfo, synhw, proto_ops, comm))
544
551
/* Handle normal packets */
545
552
hw->x = hw->y = hw->z = hw->numFingers = hw->fingerWidth = 0;
546
553
hw->left = hw->right = hw->up = hw->down = hw->middle = FALSE;
547
554
for (i = 0; i < 8; i++)
548
hw->multi[i] = FALSE;
550
if (newabs) { /* newer protos...*/
551
DBG(7, "using new protocols\n");
552
hw->x = (((buf[3] & 0x10) << 8) |
553
((buf[1] & 0x0f) << 8) |
555
hw->y = (((buf[3] & 0x20) << 7) |
556
((buf[1] & 0xf0) << 4) |
560
w = (((buf[0] & 0x30) >> 2) |
561
((buf[0] & 0x04) >> 1) |
562
((buf[3] & 0x04) >> 2));
564
hw->left = (buf[0] & 0x01) ? 1 : 0;
565
hw->right = (buf[0] & 0x02) ? 1 : 0;
567
if (SYN_CAP_EXTENDED(synhw)) {
568
if (SYN_CAP_MIDDLE_BUTTON(synhw)) {
569
hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
571
if (SYN_CAP_FOUR_BUTTON(synhw)) {
572
hw->up = ((buf[3] & 0x01)) ? 1 : 0;
575
hw->down = ((buf[3] & 0x02)) ? 1 : 0;
577
hw->down = !hw->down;
579
if (SYN_CAP_MULTI_BUTTON_NO(synhw)) {
580
if ((buf[3] & 2) ? !hw->right : hw->right) {
581
switch (SYN_CAP_MULTI_BUTTON_NO(synhw) & ~0x01) {
585
hw->multi[7] = ((buf[5] & 0x08)) ? 1 : 0;
586
hw->multi[6] = ((buf[4] & 0x08)) ? 1 : 0;
588
hw->multi[5] = ((buf[5] & 0x04)) ? 1 : 0;
589
hw->multi[4] = ((buf[4] & 0x04)) ? 1 : 0;
591
hw->multi[3] = ((buf[5] & 0x02)) ? 1 : 0;
592
hw->multi[2] = ((buf[4] & 0x02)) ? 1 : 0;
594
hw->multi[1] = ((buf[5] & 0x01)) ? 1 : 0;
595
hw->multi[0] = ((buf[4] & 0x01)) ? 1 : 0;
600
} else { /* old proto...*/
601
DBG(7, "using old protocol\n");
602
hw->x = (((buf[1] & 0x1F) << 8) |
604
hw->y = (((buf[4] & 0x1F) << 8) |
607
hw->z = (((buf[0] & 0x30) << 2) |
609
w = (((buf[1] & 0x80) >> 4) |
610
((buf[0] & 0x04) >> 1));
612
hw->left = (buf[0] & 0x01) ? 1 : 0;
613
hw->right = (buf[0] & 0x02) ? 1 : 0;
555
hw->multi[i] = FALSE;
557
if (newabs) { /* newer protos... */
558
DBG(7, "using new protocols\n");
559
hw->x = (((buf[3] & 0x10) << 8) | ((buf[1] & 0x0f) << 8) | buf[4]);
560
hw->y = (((buf[3] & 0x20) << 7) | ((buf[1] & 0xf0) << 4) | buf[5]);
563
w = (((buf[0] & 0x30) >> 2) |
564
((buf[0] & 0x04) >> 1) | ((buf[3] & 0x04) >> 2));
566
hw->left = (buf[0] & 0x01) ? 1 : 0;
567
hw->right = (buf[0] & 0x02) ? 1 : 0;
569
if (SYN_CAP_EXTENDED(synhw)) {
570
if (SYN_CAP_MIDDLE_BUTTON(synhw)) {
571
hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
573
if (SYN_CAP_FOUR_BUTTON(synhw)) {
574
hw->up = ((buf[3] & 0x01)) ? 1 : 0;
577
hw->down = ((buf[3] & 0x02)) ? 1 : 0;
579
hw->down = !hw->down;
581
if (SYN_CAP_MULTI_BUTTON_NO(synhw)) {
582
if ((buf[3] & 2) ? !hw->right : hw->right) {
583
switch (SYN_CAP_MULTI_BUTTON_NO(synhw) & ~0x01) {
587
hw->multi[7] = ((buf[5] & 0x08)) ? 1 : 0;
588
hw->multi[6] = ((buf[4] & 0x08)) ? 1 : 0;
590
hw->multi[5] = ((buf[5] & 0x04)) ? 1 : 0;
591
hw->multi[4] = ((buf[4] & 0x04)) ? 1 : 0;
593
hw->multi[3] = ((buf[5] & 0x02)) ? 1 : 0;
594
hw->multi[2] = ((buf[4] & 0x02)) ? 1 : 0;
596
hw->multi[1] = ((buf[5] & 0x01)) ? 1 : 0;
597
hw->multi[0] = ((buf[4] & 0x01)) ? 1 : 0;
603
else { /* old proto... */
604
DBG(7, "using old protocol\n");
605
hw->x = (((buf[1] & 0x1F) << 8) | buf[2]);
606
hw->y = (((buf[4] & 0x1F) << 8) | buf[5]);
608
hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
609
w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
611
hw->left = (buf[0] & 0x01) ? 1 : 0;
612
hw->right = (buf[0] & 0x02) ? 1 : 0;
616
615
hw->y = YMAX_NOMINAL + YMIN_NOMINAL - hw->y;
618
617
if (hw->z >= para->finger_high) {
621
* Use capability bits to decide if the w value is valid.
622
* If not, set it to 5, which corresponds to a finger of
625
if (SYN_CAP_EXTENDED(synhw)) {
626
if ((w >= 0) && (w <= 1)) {
627
w_ok = SYN_CAP_MULTIFINGER(synhw);
629
w_ok = SYN_MODEL_PEN(synhw);
630
} else if ((w >= 4) && (w <= 15)) {
631
w_ok = SYN_CAP_PALMDETECT(synhw);
621
* Use capability bits to decide if the w value is valid.
622
* If not, set it to 5, which corresponds to a finger of
625
if (SYN_CAP_EXTENDED(synhw)) {
626
if ((w >= 0) && (w <= 1)) {
627
w_ok = SYN_CAP_MULTIFINGER(synhw);
630
w_ok = SYN_MODEL_PEN(synhw);
632
else if ((w >= 4) && (w <= 15)) {
633
w_ok = SYN_CAP_PALMDETECT(synhw);
652
654
hw->millis = GetTimeInMillis();
653
655
SynapticsCopyHwState(hwRet, hw);