254
static void elantech_set_slot(struct input_dev *dev, int slot, bool active,
255
unsigned int x, unsigned int y)
257
input_mt_slot(dev, slot);
258
input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
260
input_report_abs(dev, ABS_MT_POSITION_X, x);
261
input_report_abs(dev, ABS_MT_POSITION_Y, y);
265
/* x1 < x2 and y1 < y2 when two fingers, x = y = 0 when not pressed */
266
static void elantech_report_semi_mt_data(struct input_dev *dev,
267
unsigned int num_fingers,
268
unsigned int x1, unsigned int y1,
269
unsigned int x2, unsigned int y2)
271
elantech_set_slot(dev, 0, num_fingers != 0, x1, y1);
272
elantech_set_slot(dev, 1, num_fingers == 2, x2, y2);
246
276
* Interpret complete data packets and report absolute mode input events for
247
277
* hardware version 2. (6 byte packets)
249
279
static void elantech_report_absolute_v2(struct psmouse *psmouse)
281
struct elantech_data *etd = psmouse->private;
251
282
struct input_dev *dev = psmouse->dev;
252
283
unsigned char *packet = psmouse->packet;
253
int fingers, x1, y1, x2, y2;
284
unsigned int fingers, x1 = 0, y1 = 0, x2 = 0, y2 = 0, width = 0, pres = 0;
255
286
/* byte 0: n1 n0 . . . . R L */
256
287
fingers = (packet[0] & 0xc0) >> 6;
270
301
* byte 1: . . . . . x10 x9 x8
271
302
* byte 2: x7 x6 x5 x4 x4 x2 x1 x0
273
input_report_abs(dev, ABS_X,
274
((packet[1] & 0x07) << 8) | packet[2]);
304
x1 = ((packet[1] & 0x07) << 8) | packet[2];
276
306
* byte 4: . . . . . . y9 y8
277
307
* byte 5: y7 y6 y5 y4 y3 y2 y1 y0
279
input_report_abs(dev, ABS_Y,
280
ETP_YMAX_V2 - (((packet[4] & 0x03) << 8) | packet[5]));
309
y1 = etd->y_max - (((packet[4] & 0x03) << 8) | packet[5]);
311
input_report_abs(dev, ABS_X, x1);
312
input_report_abs(dev, ABS_Y, y1);
314
pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
315
width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4);
290
325
x1 = ((packet[0] & 0x10) << 4) | packet[1];
291
326
/* byte 2: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0 */
292
y1 = ETP_2FT_YMAX - (((packet[0] & 0x20) << 3) | packet[2]);
327
y1 = etd->y_max_2ft - (((packet[0] & 0x20) << 3) | packet[2]);
294
329
* byte 3: . . by8 bx8 . . . .
295
330
* byte 4: bx7 bx6 bx5 bx4 bx3 bx2 bx1 bx0
297
332
x2 = ((packet[3] & 0x10) << 4) | packet[4];
298
333
/* byte 5: by7 by8 by5 by4 by3 by2 by1 by0 */
299
y2 = ETP_2FT_YMAX - (((packet[3] & 0x20) << 3) | packet[5]);
334
y2 = etd->y_max_2ft - (((packet[3] & 0x20) << 3) | packet[5]);
301
336
* For compatibility with the X Synaptics driver scale up
302
337
* one coordinate and report as ordinary mouse movent
304
339
input_report_abs(dev, ABS_X, x1 << 2);
305
340
input_report_abs(dev, ABS_Y, y1 << 2);
307
* For compatibility with the proprietary X Elantech driver
308
* report both coordinates as hat coordinates
310
input_report_abs(dev, ABS_HAT0X, x1);
311
input_report_abs(dev, ABS_HAT0Y, y1);
312
input_report_abs(dev, ABS_HAT1X, x2);
313
input_report_abs(dev, ABS_HAT1Y, y2);
342
/* Unknown so just report sensible values */
348
elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
317
349
input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
318
350
input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
319
351
input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
320
352
input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
321
353
input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
322
354
input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
355
if (etd->reports_pressure) {
356
input_report_abs(dev, ABS_PRESSURE, pres);
357
input_report_abs(dev, ABS_TOOL_WIDTH, width);
363
static int elantech_v3_is_noise(unsigned int x, unsigned int y)
365
return x == 0xfff && y == 0xfff;
369
* Interpret complete data packets and report absolute mode input events for
370
* hardware version 3. (6 byte packets)
372
static void elantech_report_absolute_v3(struct psmouse *psmouse)
374
struct elantech_data *etd = psmouse->private;
375
struct input_dev *dev = psmouse->dev;
376
unsigned char *packet1 = psmouse->packet;
377
unsigned char *packet2 = NULL;
378
unsigned int fingers, width = 0, pres = 0;
379
unsigned int x1, y1, x2 = 0, y2 = 0;
381
/* byte 0: n1 n0 . . . . R L */
382
fingers = (packet1[0] & 0xc0) >> 6;
385
* Need to receive two packets for 2-touch events. If this
386
* is the first packet, store it away and wait for the second.
387
* We don't support parity in v3, so use that storage.
389
if (fingers == 2 && (packet1[0] & 0x0c) == 0x04 &&
390
(packet1[3] & 0xcf) == 0x2) {
391
memcpy(etd->parity, packet1, psmouse->pktsize);
396
* If this the second packet of a two-fingered touch event we
397
* need to process the previous packet stashed away in
401
packet1 = etd->parity;
402
packet2 = psmouse->packet;
405
x1 = ((packet1[1] & 0x0f) << 8) | packet1[2];
406
y1 = ((packet1[4] & 0x0f) << 8) | packet1[5];
407
if (elantech_v3_is_noise(x1, y1))
409
y1 = etd->y_max - y1;
412
x2 = ((packet2[1] & 0x0f) << 8) | packet2[2];
413
y2 = etd->y_max - (((packet2[4] & 0x0f) << 8) | packet2[5]);
416
pres = (packet1[1] & 0xf0) | ((packet1[4] & 0xf0) >> 4);
417
width = ((packet1[0] & 0x30) >> 2) | ((packet1[3] & 0x30) >> 4);
419
elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
421
input_report_key(dev, BTN_TOUCH, fingers != 0);
422
input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
423
input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
424
input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
425
input_report_abs(dev, ABS_PRESSURE, pres);
426
input_report_abs(dev, ABS_TOOL_WIDTH, width);
429
input_report_abs(dev, ABS_X, x1);
430
input_report_abs(dev, ABS_Y, y1);
433
input_report_key(dev, BTN_LEFT, packet1[0] & 0x01);
434
input_report_key(dev, BTN_RIGHT, packet1[0] & 0x02);
327
440
static int elantech_check_parity_v1(struct psmouse *psmouse)
465
588
switch (etd->hw_version) {
590
etd->x_max = ETP_XMAX_V1;
591
etd->y_max = ETP_YMAX_V1;
467
593
/* Rocker button */
468
594
if (etd->fw_version < 0x020000 &&
469
595
(etd->capabilities & ETP_CAP_HAS_ROCKER)) {
470
596
__set_bit(BTN_FORWARD, dev->keybit);
471
597
__set_bit(BTN_BACK, dev->keybit);
473
input_set_abs_params(dev, ABS_X, ETP_XMIN_V1, ETP_XMAX_V1, 0, 0);
474
input_set_abs_params(dev, ABS_Y, ETP_YMIN_V1, ETP_YMAX_V1, 0, 0);
599
input_set_abs_params(dev, ABS_X, ETP_XMIN_V1, etd->x_max, 0, 0);
600
input_set_abs_params(dev, ABS_Y, ETP_YMIN_V1, etd->y_max, 0, 0);
478
604
__set_bit(BTN_TOOL_QUADTAP, dev->keybit);
479
input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, ETP_XMAX_V2, 0, 0);
480
input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, ETP_YMAX_V2, 0, 0);
481
input_set_abs_params(dev, ABS_HAT0X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0);
482
input_set_abs_params(dev, ABS_HAT0Y, ETP_2FT_YMIN, ETP_2FT_YMAX, 0, 0);
483
input_set_abs_params(dev, ABS_HAT1X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0);
484
input_set_abs_params(dev, ABS_HAT1Y, ETP_2FT_YMIN, ETP_2FT_YMAX, 0, 0);
607
if (etd->hw_version == 3) {
608
if (synaptics_send_cmd(psmouse, ETP_FW_ID_QUERY, param))
611
etd->x_max = (param[0] & 0x0f) << 8 | param[1];
612
etd->y_max = (param[0] & 0xf0) << 4 | param[2];
613
etd->y_max_2ft = etd->y_max;
614
elantech_debug("x_max = %d, y_max = %d\n",
615
etd->x_max, etd->y_max);
617
etd->x_max = ETP_XMAX_V2;
618
etd->y_max = ETP_YMAX_V2;
619
etd->y_max_2ft = ETP_2FT_YMAX;
622
input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, etd->x_max, 0, 0);
623
input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, etd->y_max, 0, 0);
624
if (etd->reports_pressure) {
625
input_set_abs_params(dev, ABS_PRESSURE, ETP_PMIN_V2,
627
input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
630
__set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
631
input_mt_init_slots(dev, 2);
632
input_set_abs_params(dev, ABS_MT_POSITION_X, ETP_XMIN_V2, etd->x_max, 0, 0);
633
input_set_abs_params(dev, ABS_MT_POSITION_Y, ETP_YMIN_V2, etd->y_max, 0, 0);
489
640
struct elantech_attr_data {