0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <linux/module.h>
0024 #include <linux/delay.h>
0025 #include <linux/dmi.h>
0026 #include <linux/input/mt.h>
0027 #include <linux/serio.h>
0028 #include <linux/libps2.h>
0029 #include <linux/rmi.h>
0030 #include <linux/i2c.h>
0031 #include <linux/slab.h>
0032 #include "psmouse.h"
0033 #include "synaptics.h"
0034
0035
0036
0037
0038
0039
0040
0041
0042 #define XMIN 0
0043 #define XMAX 6143
0044 #define YMIN 0
0045 #define YMAX 6143
0046 #define XMIN_NOMINAL 1472
0047 #define XMAX_NOMINAL 5472
0048 #define YMIN_NOMINAL 1408
0049 #define YMAX_NOMINAL 4448
0050
0051
0052 #define ABS_POS_BITS 13
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 #define X_MAX_POSITIVE 8176
0067 #define Y_MAX_POSITIVE 8176
0068
0069
0070 #define DMAX 10
0071
0072
0073
0074
0075
0076
0077
0078
0079 static int synaptics_mode_cmd(struct psmouse *psmouse, u8 mode)
0080 {
0081 u8 param[1];
0082 int error;
0083
0084 error = ps2_sliced_command(&psmouse->ps2dev, mode);
0085 if (error)
0086 return error;
0087
0088 param[0] = SYN_PS_SET_MODE2;
0089 error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE);
0090 if (error)
0091 return error;
0092
0093 return 0;
0094 }
0095
0096 int synaptics_detect(struct psmouse *psmouse, bool set_properties)
0097 {
0098 struct ps2dev *ps2dev = &psmouse->ps2dev;
0099 u8 param[4] = { 0 };
0100
0101 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
0102 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
0103 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
0104 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
0105 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
0106
0107 if (param[1] != 0x47)
0108 return -ENODEV;
0109
0110 if (set_properties) {
0111 psmouse->vendor = "Synaptics";
0112 psmouse->name = "TouchPad";
0113 }
0114
0115 return 0;
0116 }
0117
0118 void synaptics_reset(struct psmouse *psmouse)
0119 {
0120
0121 synaptics_mode_cmd(psmouse, 0);
0122 }
0123
0124 #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
0125 defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
0126
0127
0128 static const char * const topbuttonpad_pnp_ids[] = {
0129 "LEN0017",
0130 "LEN0018",
0131 "LEN0019",
0132 "LEN0023",
0133 "LEN002A",
0134 "LEN002B",
0135 "LEN002C",
0136 "LEN002D",
0137 "LEN002E",
0138 "LEN0033",
0139 "LEN0034",
0140 "LEN0035",
0141 "LEN0036",
0142 "LEN0037",
0143 "LEN0038",
0144 "LEN0039",
0145 "LEN0041",
0146 "LEN0042",
0147 "LEN0045",
0148 "LEN0047",
0149 "LEN2000",
0150 "LEN2001",
0151 "LEN2002",
0152 "LEN2003",
0153 "LEN2004",
0154 "LEN2005",
0155 "LEN2006",
0156 "LEN2007",
0157 "LEN2008",
0158 "LEN2009",
0159 "LEN200A",
0160 "LEN200B",
0161 NULL
0162 };
0163
0164 static const char * const smbus_pnp_ids[] = {
0165
0166 "LEN0048",
0167 "LEN0046",
0168 "LEN0049",
0169 "LEN004a",
0170 "LEN005b",
0171 "LEN005e",
0172 "LEN006c",
0173 "LEN007a",
0174 "LEN0071",
0175 "LEN0072",
0176 "LEN0073",
0177 "LEN0091",
0178 "LEN0092",
0179 "LEN0093",
0180 "LEN0096",
0181 "LEN0097",
0182 "LEN0099",
0183 "LEN009b",
0184 "LEN0402",
0185 "LEN200f",
0186 "LEN2044",
0187 "LEN2054",
0188 "LEN2055",
0189 "LEN2068",
0190 "SYN3052",
0191 "SYN3221",
0192 "SYN323d",
0193 "SYN3257",
0194 NULL
0195 };
0196
0197 static const char * const forcepad_pnp_ids[] = {
0198 "SYN300D",
0199 "SYN3014",
0200 NULL
0201 };
0202
0203
0204
0205
0206 static int synaptics_send_cmd(struct psmouse *psmouse, u8 cmd, u8 *param)
0207 {
0208 int error;
0209
0210 error = ps2_sliced_command(&psmouse->ps2dev, cmd);
0211 if (error)
0212 return error;
0213
0214 error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO);
0215 if (error)
0216 return error;
0217
0218 return 0;
0219 }
0220
0221 static int synaptics_query_int(struct psmouse *psmouse, u8 query_cmd, u32 *val)
0222 {
0223 int error;
0224 union {
0225 __be32 be_val;
0226 char buf[4];
0227 } resp = { 0 };
0228
0229 error = synaptics_send_cmd(psmouse, query_cmd, resp.buf + 1);
0230 if (error)
0231 return error;
0232
0233 *val = be32_to_cpu(resp.be_val);
0234 return 0;
0235 }
0236
0237
0238
0239
0240
0241 static int synaptics_identify(struct psmouse *psmouse,
0242 struct synaptics_device_info *info)
0243 {
0244 int error;
0245
0246 error = synaptics_query_int(psmouse, SYN_QUE_IDENTIFY, &info->identity);
0247 if (error)
0248 return error;
0249
0250 return SYN_ID_IS_SYNAPTICS(info->identity) ? 0 : -ENXIO;
0251 }
0252
0253
0254
0255
0256
0257 static int synaptics_model_id(struct psmouse *psmouse,
0258 struct synaptics_device_info *info)
0259 {
0260 return synaptics_query_int(psmouse, SYN_QUE_MODEL, &info->model_id);
0261 }
0262
0263
0264
0265
0266 static int synaptics_firmware_id(struct psmouse *psmouse,
0267 struct synaptics_device_info *info)
0268 {
0269 return synaptics_query_int(psmouse, SYN_QUE_FIRMWARE_ID,
0270 &info->firmware_id);
0271 }
0272
0273
0274
0275
0276
0277 static int synaptics_query_modes(struct psmouse *psmouse,
0278 struct synaptics_device_info *info)
0279 {
0280 u8 bid[3];
0281 int error;
0282
0283
0284 if (SYN_ID_FULL(info->identity) < 0x705)
0285 return 0;
0286
0287 error = synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid);
0288 if (error)
0289 return error;
0290
0291 info->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
0292
0293 if (SYN_MEXT_CAP_BIT(bid[0]))
0294 return synaptics_query_int(psmouse, SYN_QUE_MEXT_CAPAB_10,
0295 &info->ext_cap_10);
0296
0297 return 0;
0298 }
0299
0300
0301
0302
0303
0304 static int synaptics_capability(struct psmouse *psmouse,
0305 struct synaptics_device_info *info)
0306 {
0307 int error;
0308
0309 error = synaptics_query_int(psmouse, SYN_QUE_CAPABILITIES,
0310 &info->capabilities);
0311 if (error)
0312 return error;
0313
0314 info->ext_cap = info->ext_cap_0c = 0;
0315
0316
0317
0318
0319 if (SYN_ID_FULL(info->identity) < 0x705 &&
0320 SYN_CAP_SUBMODEL_ID(info->capabilities) != 0x47) {
0321 return -ENXIO;
0322 }
0323
0324
0325
0326
0327 if (!SYN_CAP_EXTENDED(info->capabilities))
0328 info->capabilities = 0;
0329
0330 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 1) {
0331 error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB,
0332 &info->ext_cap);
0333 if (error) {
0334 psmouse_warn(psmouse,
0335 "device claims to have extended capabilities, but I'm not able to read them.\n");
0336 } else {
0337
0338
0339
0340
0341 if (SYN_CAP_MULTI_BUTTON_NO(info->ext_cap) > 8)
0342 info->ext_cap &= ~SYN_CAP_MB_MASK;
0343 }
0344 }
0345
0346 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 4) {
0347 error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB_0C,
0348 &info->ext_cap_0c);
0349 if (error)
0350 psmouse_warn(psmouse,
0351 "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
0352 }
0353
0354 return 0;
0355 }
0356
0357
0358
0359
0360
0361 static int synaptics_resolution(struct psmouse *psmouse,
0362 struct synaptics_device_info *info)
0363 {
0364 u8 resp[3];
0365 int error;
0366
0367 if (SYN_ID_MAJOR(info->identity) < 4)
0368 return 0;
0369
0370 error = synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp);
0371 if (!error) {
0372 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
0373 info->x_res = resp[0];
0374 info->y_res = resp[2];
0375 }
0376 }
0377
0378 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 5 &&
0379 SYN_CAP_MAX_DIMENSIONS(info->ext_cap_0c)) {
0380 error = synaptics_send_cmd(psmouse,
0381 SYN_QUE_EXT_MAX_COORDS, resp);
0382 if (error) {
0383 psmouse_warn(psmouse,
0384 "device claims to have max coordinates query, but I'm not able to read it.\n");
0385 } else {
0386 info->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
0387 info->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
0388 psmouse_info(psmouse,
0389 "queried max coordinates: x [..%d], y [..%d]\n",
0390 info->x_max, info->y_max);
0391 }
0392 }
0393
0394 if (SYN_CAP_MIN_DIMENSIONS(info->ext_cap_0c) &&
0395 (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 7 ||
0396
0397
0398
0399
0400
0401 SYN_ID_FULL(info->identity) == 0x801)) {
0402 error = synaptics_send_cmd(psmouse,
0403 SYN_QUE_EXT_MIN_COORDS, resp);
0404 if (error) {
0405 psmouse_warn(psmouse,
0406 "device claims to have min coordinates query, but I'm not able to read it.\n");
0407 } else {
0408 info->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
0409 info->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
0410 psmouse_info(psmouse,
0411 "queried min coordinates: x [%d..], y [%d..]\n",
0412 info->x_min, info->y_min);
0413 }
0414 }
0415
0416 return 0;
0417 }
0418
0419 static int synaptics_query_hardware(struct psmouse *psmouse,
0420 struct synaptics_device_info *info)
0421 {
0422 int error;
0423
0424 memset(info, 0, sizeof(*info));
0425
0426 error = synaptics_identify(psmouse, info);
0427 if (error)
0428 return error;
0429
0430 error = synaptics_model_id(psmouse, info);
0431 if (error)
0432 return error;
0433
0434 error = synaptics_firmware_id(psmouse, info);
0435 if (error)
0436 return error;
0437
0438 error = synaptics_query_modes(psmouse, info);
0439 if (error)
0440 return error;
0441
0442 error = synaptics_capability(psmouse, info);
0443 if (error)
0444 return error;
0445
0446 error = synaptics_resolution(psmouse, info);
0447 if (error)
0448 return error;
0449
0450 return 0;
0451 }
0452
0453 #endif
0454
0455 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
0456
0457 static bool cr48_profile_sensor;
0458
0459 #define ANY_BOARD_ID 0
0460 struct min_max_quirk {
0461 const char * const *pnp_ids;
0462 struct {
0463 u32 min, max;
0464 } board_id;
0465 u32 x_min, x_max, y_min, y_max;
0466 };
0467
0468 static const struct min_max_quirk min_max_pnpid_table[] = {
0469 {
0470 (const char * const []){"LEN0033", NULL},
0471 {ANY_BOARD_ID, ANY_BOARD_ID},
0472 1024, 5052, 2258, 4832
0473 },
0474 {
0475 (const char * const []){"LEN0042", NULL},
0476 {ANY_BOARD_ID, ANY_BOARD_ID},
0477 1232, 5710, 1156, 4696
0478 },
0479 {
0480 (const char * const []){"LEN0034", "LEN0036", "LEN0037",
0481 "LEN0039", "LEN2002", "LEN2004",
0482 NULL},
0483 {ANY_BOARD_ID, 2961},
0484 1024, 5112, 2024, 4832
0485 },
0486 {
0487 (const char * const []){"LEN2000", NULL},
0488 {ANY_BOARD_ID, ANY_BOARD_ID},
0489 1024, 5113, 2021, 4832
0490 },
0491 {
0492 (const char * const []){"LEN2001", NULL},
0493 {ANY_BOARD_ID, ANY_BOARD_ID},
0494 1024, 5022, 2508, 4832
0495 },
0496 {
0497 (const char * const []){"LEN2006", NULL},
0498 {2691, 2691},
0499 1024, 5045, 2457, 4832
0500 },
0501 {
0502 (const char * const []){"LEN2006", NULL},
0503 {ANY_BOARD_ID, ANY_BOARD_ID},
0504 1264, 5675, 1171, 4688
0505 },
0506 { }
0507 };
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518 static int synaptics_invert_y(int y)
0519 {
0520 return YMAX_NOMINAL + YMIN_NOMINAL - y;
0521 }
0522
0523
0524
0525
0526 static void synaptics_apply_quirks(struct psmouse *psmouse,
0527 struct synaptics_device_info *info)
0528 {
0529 int i;
0530
0531 for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
0532 if (!psmouse_matches_pnp_id(psmouse,
0533 min_max_pnpid_table[i].pnp_ids))
0534 continue;
0535
0536 if (min_max_pnpid_table[i].board_id.min != ANY_BOARD_ID &&
0537 info->board_id < min_max_pnpid_table[i].board_id.min)
0538 continue;
0539
0540 if (min_max_pnpid_table[i].board_id.max != ANY_BOARD_ID &&
0541 info->board_id > min_max_pnpid_table[i].board_id.max)
0542 continue;
0543
0544 info->x_min = min_max_pnpid_table[i].x_min;
0545 info->x_max = min_max_pnpid_table[i].x_max;
0546 info->y_min = min_max_pnpid_table[i].y_min;
0547 info->y_max = min_max_pnpid_table[i].y_max;
0548 psmouse_info(psmouse,
0549 "quirked min/max coordinates: x [%d..%d], y [%d..%d]\n",
0550 info->x_min, info->x_max,
0551 info->y_min, info->y_max);
0552 break;
0553 }
0554 }
0555
0556 static bool synaptics_has_agm(struct synaptics_data *priv)
0557 {
0558 return (SYN_CAP_ADV_GESTURE(priv->info.ext_cap_0c) ||
0559 SYN_CAP_IMAGE_SENSOR(priv->info.ext_cap_0c));
0560 }
0561
0562 static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
0563 {
0564 static u8 param = 0xc8;
0565 int error;
0566
0567 error = ps2_sliced_command(&psmouse->ps2dev, SYN_QUE_MODEL);
0568 if (error)
0569 return error;
0570
0571 error = ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE);
0572 if (error)
0573 return error;
0574
0575 return 0;
0576 }
0577
0578 static int synaptics_set_mode(struct psmouse *psmouse)
0579 {
0580 struct synaptics_data *priv = psmouse->private;
0581 int error;
0582
0583 priv->mode = 0;
0584 if (priv->absolute_mode)
0585 priv->mode |= SYN_BIT_ABSOLUTE_MODE;
0586 if (priv->disable_gesture)
0587 priv->mode |= SYN_BIT_DISABLE_GESTURE;
0588 if (psmouse->rate >= 80)
0589 priv->mode |= SYN_BIT_HIGH_RATE;
0590 if (SYN_CAP_EXTENDED(priv->info.capabilities))
0591 priv->mode |= SYN_BIT_W_MODE;
0592
0593 error = synaptics_mode_cmd(psmouse, priv->mode);
0594 if (error)
0595 return error;
0596
0597 if (priv->absolute_mode && synaptics_has_agm(priv)) {
0598 error = synaptics_set_advanced_gesture_mode(psmouse);
0599 if (error) {
0600 psmouse_err(psmouse,
0601 "Advanced gesture mode init failed: %d\n",
0602 error);
0603 return error;
0604 }
0605 }
0606
0607 return 0;
0608 }
0609
0610 static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
0611 {
0612 struct synaptics_data *priv = psmouse->private;
0613
0614 if (rate >= 80) {
0615 priv->mode |= SYN_BIT_HIGH_RATE;
0616 psmouse->rate = 80;
0617 } else {
0618 priv->mode &= ~SYN_BIT_HIGH_RATE;
0619 psmouse->rate = 40;
0620 }
0621
0622 synaptics_mode_cmd(psmouse, priv->mode);
0623 }
0624
0625
0626
0627
0628 static int synaptics_pt_write(struct serio *serio, u8 c)
0629 {
0630 struct psmouse *parent = serio_get_drvdata(serio->parent);
0631 u8 rate_param = SYN_PS_CLIENT_CMD;
0632 int error;
0633
0634 error = ps2_sliced_command(&parent->ps2dev, c);
0635 if (error)
0636 return error;
0637
0638 error = ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE);
0639 if (error)
0640 return error;
0641
0642 return 0;
0643 }
0644
0645 static int synaptics_pt_start(struct serio *serio)
0646 {
0647 struct psmouse *parent = serio_get_drvdata(serio->parent);
0648 struct synaptics_data *priv = parent->private;
0649
0650 serio_pause_rx(parent->ps2dev.serio);
0651 priv->pt_port = serio;
0652 serio_continue_rx(parent->ps2dev.serio);
0653
0654 return 0;
0655 }
0656
0657 static void synaptics_pt_stop(struct serio *serio)
0658 {
0659 struct psmouse *parent = serio_get_drvdata(serio->parent);
0660 struct synaptics_data *priv = parent->private;
0661
0662 serio_pause_rx(parent->ps2dev.serio);
0663 priv->pt_port = NULL;
0664 serio_continue_rx(parent->ps2dev.serio);
0665 }
0666
0667 static int synaptics_is_pt_packet(u8 *buf)
0668 {
0669 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
0670 }
0671
0672 static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet)
0673 {
0674 struct psmouse *child = serio_get_drvdata(ptport);
0675
0676 if (child && child->state == PSMOUSE_ACTIVATED) {
0677 serio_interrupt(ptport, packet[1], 0);
0678 serio_interrupt(ptport, packet[4], 0);
0679 serio_interrupt(ptport, packet[5], 0);
0680 if (child->pktsize == 4)
0681 serio_interrupt(ptport, packet[2], 0);
0682 } else {
0683 serio_interrupt(ptport, packet[1], 0);
0684 }
0685 }
0686
0687 static void synaptics_pt_activate(struct psmouse *psmouse)
0688 {
0689 struct synaptics_data *priv = psmouse->private;
0690 struct psmouse *child = serio_get_drvdata(priv->pt_port);
0691
0692
0693 if (child) {
0694 if (child->pktsize == 4)
0695 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
0696 else
0697 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
0698
0699 if (synaptics_mode_cmd(psmouse, priv->mode))
0700 psmouse_warn(psmouse,
0701 "failed to switch guest protocol\n");
0702 }
0703 }
0704
0705 static void synaptics_pt_create(struct psmouse *psmouse)
0706 {
0707 struct serio *serio;
0708
0709 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
0710 if (!serio) {
0711 psmouse_err(psmouse,
0712 "not enough memory for pass-through port\n");
0713 return;
0714 }
0715
0716 serio->id.type = SERIO_PS_PSTHRU;
0717 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
0718 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->phys));
0719 serio->write = synaptics_pt_write;
0720 serio->start = synaptics_pt_start;
0721 serio->stop = synaptics_pt_stop;
0722 serio->parent = psmouse->ps2dev.serio;
0723
0724 psmouse->pt_activate = synaptics_pt_activate;
0725
0726 psmouse_info(psmouse, "serio: %s port at %s\n",
0727 serio->name, psmouse->phys);
0728 serio_register_port(serio);
0729 }
0730
0731
0732
0733
0734
0735 static void synaptics_parse_agm(const u8 buf[],
0736 struct synaptics_data *priv,
0737 struct synaptics_hw_state *hw)
0738 {
0739 struct synaptics_hw_state *agm = &priv->agm;
0740 int agm_packet_type;
0741
0742 agm_packet_type = (buf[5] & 0x30) >> 4;
0743 switch (agm_packet_type) {
0744 case 1:
0745
0746 agm->w = hw->w;
0747 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
0748 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
0749 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
0750 break;
0751
0752 case 2:
0753
0754 priv->agm_count = buf[1];
0755 break;
0756
0757 default:
0758 break;
0759 }
0760 }
0761
0762 static void synaptics_parse_ext_buttons(const u8 buf[],
0763 struct synaptics_data *priv,
0764 struct synaptics_hw_state *hw)
0765 {
0766 unsigned int ext_bits =
0767 (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) + 1) >> 1;
0768 unsigned int ext_mask = GENMASK(ext_bits - 1, 0);
0769
0770 hw->ext_buttons = buf[4] & ext_mask;
0771 hw->ext_buttons |= (buf[5] & ext_mask) << ext_bits;
0772 }
0773
0774 static int synaptics_parse_hw_state(const u8 buf[],
0775 struct synaptics_data *priv,
0776 struct synaptics_hw_state *hw)
0777 {
0778 memset(hw, 0, sizeof(struct synaptics_hw_state));
0779
0780 if (SYN_MODEL_NEWABS(priv->info.model_id)) {
0781 hw->w = (((buf[0] & 0x30) >> 2) |
0782 ((buf[0] & 0x04) >> 1) |
0783 ((buf[3] & 0x04) >> 2));
0784
0785 if (synaptics_has_agm(priv) && hw->w == 2) {
0786 synaptics_parse_agm(buf, priv, hw);
0787 return 1;
0788 }
0789
0790 hw->x = (((buf[3] & 0x10) << 8) |
0791 ((buf[1] & 0x0f) << 8) |
0792 buf[4]);
0793 hw->y = (((buf[3] & 0x20) << 7) |
0794 ((buf[1] & 0xf0) << 4) |
0795 buf[5]);
0796 hw->z = buf[2];
0797
0798 hw->left = (buf[0] & 0x01) ? 1 : 0;
0799 hw->right = (buf[0] & 0x02) ? 1 : 0;
0800
0801 if (priv->is_forcepad) {
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811 if (hw->z == 0) {
0812
0813 priv->press = priv->report_press = false;
0814 } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
0815
0816
0817
0818
0819
0820
0821
0822
0823 if (!priv->press) {
0824 priv->press_start = jiffies;
0825 priv->press = true;
0826 } else if (time_after(jiffies,
0827 priv->press_start +
0828 msecs_to_jiffies(50))) {
0829 priv->report_press = true;
0830 }
0831 } else {
0832 priv->press = false;
0833 }
0834
0835 hw->left = priv->report_press;
0836
0837 } else if (SYN_CAP_CLICKPAD(priv->info.ext_cap_0c)) {
0838
0839
0840
0841
0842
0843 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
0844
0845 } else if (SYN_CAP_MIDDLE_BUTTON(priv->info.capabilities)) {
0846 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
0847 if (hw->w == 2)
0848 hw->scroll = (s8)buf[1];
0849 }
0850
0851 if (SYN_CAP_FOUR_BUTTON(priv->info.capabilities)) {
0852 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
0853 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
0854 }
0855
0856 if (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) > 0 &&
0857 ((buf[0] ^ buf[3]) & 0x02)) {
0858 synaptics_parse_ext_buttons(buf, priv, hw);
0859 }
0860 } else {
0861 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
0862 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
0863
0864 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
0865 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
0866
0867 hw->left = (buf[0] & 0x01) ? 1 : 0;
0868 hw->right = (buf[0] & 0x02) ? 1 : 0;
0869 }
0870
0871
0872
0873
0874
0875
0876
0877 if (hw->x > X_MAX_POSITIVE)
0878 hw->x -= 1 << ABS_POS_BITS;
0879 else if (hw->x == X_MAX_POSITIVE)
0880 hw->x = XMAX;
0881
0882 if (hw->y > Y_MAX_POSITIVE)
0883 hw->y -= 1 << ABS_POS_BITS;
0884 else if (hw->y == Y_MAX_POSITIVE)
0885 hw->y = YMAX;
0886
0887 return 0;
0888 }
0889
0890 static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
0891 bool active, int x, int y)
0892 {
0893 input_mt_slot(dev, slot);
0894 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
0895 if (active) {
0896 input_report_abs(dev, ABS_MT_POSITION_X, x);
0897 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
0898 }
0899 }
0900
0901 static void synaptics_report_semi_mt_data(struct input_dev *dev,
0902 const struct synaptics_hw_state *a,
0903 const struct synaptics_hw_state *b,
0904 int num_fingers)
0905 {
0906 if (num_fingers >= 2) {
0907 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
0908 min(a->y, b->y));
0909 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
0910 max(a->y, b->y));
0911 } else if (num_fingers == 1) {
0912 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
0913 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
0914 } else {
0915 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
0916 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
0917 }
0918 }
0919
0920 static void synaptics_report_ext_buttons(struct psmouse *psmouse,
0921 const struct synaptics_hw_state *hw)
0922 {
0923 struct input_dev *dev = psmouse->dev;
0924 struct synaptics_data *priv = psmouse->private;
0925 int ext_bits = (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) + 1) >> 1;
0926 int i;
0927
0928 if (!SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap))
0929 return;
0930
0931
0932 if ((SYN_ID_FULL(priv->info.identity) == 0x801 ||
0933 SYN_ID_FULL(priv->info.identity) == 0x802) &&
0934 !((psmouse->packet[0] ^ psmouse->packet[3]) & 0x02))
0935 return;
0936
0937 if (!SYN_CAP_EXT_BUTTONS_STICK(priv->info.ext_cap_10)) {
0938 for (i = 0; i < ext_bits; i++) {
0939 input_report_key(dev, BTN_0 + 2 * i,
0940 hw->ext_buttons & BIT(i));
0941 input_report_key(dev, BTN_1 + 2 * i,
0942 hw->ext_buttons & BIT(i + ext_bits));
0943 }
0944 return;
0945 }
0946
0947
0948
0949
0950
0951
0952 if (priv->pt_port) {
0953 u8 pt_buttons;
0954
0955
0956 pt_buttons = SYN_EXT_BUTTON_STICK_L(hw->ext_buttons) |
0957 SYN_EXT_BUTTON_STICK_R(hw->ext_buttons) << 1 |
0958 SYN_EXT_BUTTON_STICK_M(hw->ext_buttons) << 2;
0959
0960 serio_interrupt(priv->pt_port,
0961 PSMOUSE_OOB_EXTRA_BTNS, SERIO_OOB_DATA);
0962 serio_interrupt(priv->pt_port, pt_buttons, SERIO_OOB_DATA);
0963 }
0964 }
0965
0966 static void synaptics_report_buttons(struct psmouse *psmouse,
0967 const struct synaptics_hw_state *hw)
0968 {
0969 struct input_dev *dev = psmouse->dev;
0970 struct synaptics_data *priv = psmouse->private;
0971
0972 input_report_key(dev, BTN_LEFT, hw->left);
0973 input_report_key(dev, BTN_RIGHT, hw->right);
0974
0975 if (SYN_CAP_MIDDLE_BUTTON(priv->info.capabilities))
0976 input_report_key(dev, BTN_MIDDLE, hw->middle);
0977
0978 if (SYN_CAP_FOUR_BUTTON(priv->info.capabilities)) {
0979 input_report_key(dev, BTN_FORWARD, hw->up);
0980 input_report_key(dev, BTN_BACK, hw->down);
0981 }
0982
0983 synaptics_report_ext_buttons(psmouse, hw);
0984 }
0985
0986 static void synaptics_report_mt_data(struct psmouse *psmouse,
0987 const struct synaptics_hw_state *sgm,
0988 int num_fingers)
0989 {
0990 struct input_dev *dev = psmouse->dev;
0991 struct synaptics_data *priv = psmouse->private;
0992 const struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
0993 struct input_mt_pos pos[2];
0994 int slot[2], nsemi, i;
0995
0996 nsemi = clamp_val(num_fingers, 0, 2);
0997
0998 for (i = 0; i < nsemi; i++) {
0999 pos[i].x = hw[i]->x;
1000 pos[i].y = synaptics_invert_y(hw[i]->y);
1001 }
1002
1003 input_mt_assign_slots(dev, slot, pos, nsemi, DMAX * priv->info.x_res);
1004
1005 for (i = 0; i < nsemi; i++) {
1006 input_mt_slot(dev, slot[i]);
1007 input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
1008 input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
1009 input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
1010 input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
1011 }
1012
1013 input_mt_drop_unused(dev);
1014
1015
1016 input_mt_report_pointer_emulation(dev, false);
1017
1018
1019 input_mt_report_finger_count(dev, num_fingers);
1020
1021 synaptics_report_buttons(psmouse, sgm);
1022
1023 input_sync(dev);
1024 }
1025
1026 static void synaptics_image_sensor_process(struct psmouse *psmouse,
1027 struct synaptics_hw_state *sgm)
1028 {
1029 struct synaptics_data *priv = psmouse->private;
1030 int num_fingers;
1031
1032
1033
1034
1035 if (sgm->z == 0)
1036 num_fingers = 0;
1037 else if (sgm->w >= 4)
1038 num_fingers = 1;
1039 else if (sgm->w == 0)
1040 num_fingers = 2;
1041 else if (sgm->w == 1)
1042 num_fingers = priv->agm_count ? priv->agm_count : 3;
1043 else
1044 num_fingers = 4;
1045
1046
1047 synaptics_report_mt_data(psmouse, sgm, num_fingers);
1048 }
1049
1050 static bool synaptics_has_multifinger(struct synaptics_data *priv)
1051 {
1052 if (SYN_CAP_MULTIFINGER(priv->info.capabilities))
1053 return true;
1054
1055
1056 return synaptics_has_agm(priv);
1057 }
1058
1059
1060
1061
1062 static void synaptics_process_packet(struct psmouse *psmouse)
1063 {
1064 struct input_dev *dev = psmouse->dev;
1065 struct synaptics_data *priv = psmouse->private;
1066 struct synaptics_device_info *info = &priv->info;
1067 struct synaptics_hw_state hw;
1068 int num_fingers;
1069 int finger_width;
1070
1071 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
1072 return;
1073
1074 if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
1075 synaptics_image_sensor_process(psmouse, &hw);
1076 return;
1077 }
1078
1079 if (hw.scroll) {
1080 priv->scroll += hw.scroll;
1081
1082 while (priv->scroll >= 4) {
1083 input_report_key(dev, BTN_BACK, !hw.down);
1084 input_sync(dev);
1085 input_report_key(dev, BTN_BACK, hw.down);
1086 input_sync(dev);
1087 priv->scroll -= 4;
1088 }
1089 while (priv->scroll <= -4) {
1090 input_report_key(dev, BTN_FORWARD, !hw.up);
1091 input_sync(dev);
1092 input_report_key(dev, BTN_FORWARD, hw.up);
1093 input_sync(dev);
1094 priv->scroll += 4;
1095 }
1096 return;
1097 }
1098
1099 if (hw.z > 0 && hw.x > 1) {
1100 num_fingers = 1;
1101 finger_width = 5;
1102 if (SYN_CAP_EXTENDED(info->capabilities)) {
1103 switch (hw.w) {
1104 case 0 ... 1:
1105 if (synaptics_has_multifinger(priv))
1106 num_fingers = hw.w + 2;
1107 break;
1108 case 2:
1109
1110
1111
1112
1113
1114 break;
1115 case 4 ... 15:
1116 if (SYN_CAP_PALMDETECT(info->capabilities))
1117 finger_width = hw.w;
1118 break;
1119 }
1120 }
1121 } else {
1122 num_fingers = 0;
1123 finger_width = 0;
1124 }
1125
1126 if (cr48_profile_sensor) {
1127 synaptics_report_mt_data(psmouse, &hw, num_fingers);
1128 return;
1129 }
1130
1131 if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c))
1132 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
1133 num_fingers);
1134
1135
1136
1137
1138
1139 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
1140 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
1141
1142 if (num_fingers > 0) {
1143 input_report_abs(dev, ABS_X, hw.x);
1144 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
1145 }
1146 input_report_abs(dev, ABS_PRESSURE, hw.z);
1147
1148 if (SYN_CAP_PALMDETECT(info->capabilities))
1149 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
1150
1151 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
1152 if (synaptics_has_multifinger(priv)) {
1153 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
1154 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
1155 }
1156
1157 synaptics_report_buttons(psmouse, &hw);
1158
1159 input_sync(dev);
1160 }
1161
1162 static bool synaptics_validate_byte(struct psmouse *psmouse,
1163 int idx, enum synaptics_pkt_type pkt_type)
1164 {
1165 static const u8 newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
1166 static const u8 newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
1167 static const u8 newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
1168 static const u8 oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
1169 static const u8 oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
1170 const u8 *packet = psmouse->packet;
1171
1172 if (idx < 0 || idx > 4)
1173 return false;
1174
1175 switch (pkt_type) {
1176
1177 case SYN_NEWABS:
1178 case SYN_NEWABS_RELAXED:
1179 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
1180
1181 case SYN_NEWABS_STRICT:
1182 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
1183
1184 case SYN_OLDABS:
1185 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
1186
1187 default:
1188 psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
1189 return false;
1190 }
1191 }
1192
1193 static enum synaptics_pkt_type
1194 synaptics_detect_pkt_type(struct psmouse *psmouse)
1195 {
1196 int i;
1197
1198 for (i = 0; i < 5; i++) {
1199 if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
1200 psmouse_info(psmouse, "using relaxed packet validation\n");
1201 return SYN_NEWABS_RELAXED;
1202 }
1203 }
1204
1205 return SYN_NEWABS_STRICT;
1206 }
1207
1208 static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
1209 {
1210 struct synaptics_data *priv = psmouse->private;
1211
1212 if (psmouse->pktcnt >= 6) {
1213 if (unlikely(priv->pkt_type == SYN_NEWABS))
1214 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
1215
1216 if (SYN_CAP_PASS_THROUGH(priv->info.capabilities) &&
1217 synaptics_is_pt_packet(psmouse->packet)) {
1218 if (priv->pt_port)
1219 synaptics_pass_pt_packet(priv->pt_port,
1220 psmouse->packet);
1221 } else
1222 synaptics_process_packet(psmouse);
1223
1224 return PSMOUSE_FULL_PACKET;
1225 }
1226
1227 return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
1228 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
1229 }
1230
1231
1232
1233
1234 static void set_abs_position_params(struct input_dev *dev,
1235 struct synaptics_device_info *info,
1236 int x_code, int y_code)
1237 {
1238 int x_min = info->x_min ?: XMIN_NOMINAL;
1239 int x_max = info->x_max ?: XMAX_NOMINAL;
1240 int y_min = info->y_min ?: YMIN_NOMINAL;
1241 int y_max = info->y_max ?: YMAX_NOMINAL;
1242 int fuzz = SYN_CAP_REDUCED_FILTERING(info->ext_cap_0c) ?
1243 SYN_REDUCED_FILTER_FUZZ : 0;
1244
1245 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
1246 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
1247 input_abs_set_res(dev, x_code, info->x_res);
1248 input_abs_set_res(dev, y_code, info->y_res);
1249 }
1250
1251 static int set_input_params(struct psmouse *psmouse,
1252 struct synaptics_data *priv)
1253 {
1254 struct input_dev *dev = psmouse->dev;
1255 struct synaptics_device_info *info = &priv->info;
1256 int i;
1257 int error;
1258
1259
1260 __clear_bit(EV_REL, dev->evbit);
1261 bitmap_zero(dev->relbit, REL_CNT);
1262 bitmap_zero(dev->keybit, KEY_CNT);
1263
1264
1265 __set_bit(INPUT_PROP_POINTER, dev->propbit);
1266
1267 input_set_capability(dev, EV_KEY, BTN_LEFT);
1268
1269
1270 if (!SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
1271 input_set_capability(dev, EV_KEY, BTN_RIGHT);
1272 if (SYN_CAP_MIDDLE_BUTTON(info->capabilities))
1273 input_set_capability(dev, EV_KEY, BTN_MIDDLE);
1274 }
1275
1276 if (!priv->absolute_mode) {
1277
1278 input_set_capability(dev, EV_REL, REL_X);
1279 input_set_capability(dev, EV_REL, REL_Y);
1280 return 0;
1281 }
1282
1283
1284 set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
1285 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
1286
1287 if (cr48_profile_sensor)
1288 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1289
1290 if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
1291 set_abs_position_params(dev, info,
1292 ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
1293
1294 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1295
1296 error = input_mt_init_slots(dev, 2,
1297 INPUT_MT_POINTER | INPUT_MT_TRACK);
1298 if (error)
1299 return error;
1300
1301
1302 input_set_capability(dev, EV_KEY, BTN_TOOL_QUADTAP);
1303 input_set_capability(dev, EV_KEY, BTN_TOOL_QUINTTAP);
1304 } else if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c)) {
1305 set_abs_position_params(dev, info,
1306 ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
1307
1308
1309
1310
1311 error = input_mt_init_slots(dev, 2,
1312 INPUT_MT_POINTER |
1313 (cr48_profile_sensor ?
1314 INPUT_MT_TRACK :
1315 INPUT_MT_SEMI_MT));
1316 if (error)
1317 return error;
1318
1319
1320
1321
1322
1323
1324
1325
1326 if (!cr48_profile_sensor)
1327 set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
1328 }
1329
1330 if (SYN_CAP_PALMDETECT(info->capabilities))
1331 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
1332
1333 input_set_capability(dev, EV_KEY, BTN_TOUCH);
1334 input_set_capability(dev, EV_KEY, BTN_TOOL_FINGER);
1335
1336 if (synaptics_has_multifinger(priv)) {
1337 input_set_capability(dev, EV_KEY, BTN_TOOL_DOUBLETAP);
1338 input_set_capability(dev, EV_KEY, BTN_TOOL_TRIPLETAP);
1339 }
1340
1341 if (SYN_CAP_FOUR_BUTTON(info->capabilities) ||
1342 SYN_CAP_MIDDLE_BUTTON(info->capabilities)) {
1343 input_set_capability(dev, EV_KEY, BTN_FORWARD);
1344 input_set_capability(dev, EV_KEY, BTN_BACK);
1345 }
1346
1347 if (!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
1348 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(info->ext_cap); i++)
1349 input_set_capability(dev, EV_KEY, BTN_0 + i);
1350
1351 if (SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
1352 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
1353 if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1354 !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
1355 __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
1356 }
1357
1358 return 0;
1359 }
1360
1361 static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
1362 void *data, char *buf)
1363 {
1364 struct synaptics_data *priv = psmouse->private;
1365
1366 return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
1367 }
1368
1369 static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
1370 void *data, const char *buf,
1371 size_t len)
1372 {
1373 struct synaptics_data *priv = psmouse->private;
1374 unsigned int value;
1375 int err;
1376
1377 err = kstrtouint(buf, 10, &value);
1378 if (err)
1379 return err;
1380
1381 if (value > 1)
1382 return -EINVAL;
1383
1384 if (value == priv->disable_gesture)
1385 return len;
1386
1387 priv->disable_gesture = value;
1388 if (value)
1389 priv->mode |= SYN_BIT_DISABLE_GESTURE;
1390 else
1391 priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
1392
1393 if (synaptics_mode_cmd(psmouse, priv->mode))
1394 return -EIO;
1395
1396 return len;
1397 }
1398
1399 PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
1400 synaptics_show_disable_gesture,
1401 synaptics_set_disable_gesture);
1402
1403 static void synaptics_disconnect(struct psmouse *psmouse)
1404 {
1405 struct synaptics_data *priv = psmouse->private;
1406
1407
1408
1409
1410
1411 psmouse_smbus_cleanup(psmouse);
1412
1413 if (!priv->absolute_mode &&
1414 SYN_ID_DISGEST_SUPPORTED(priv->info.identity))
1415 device_remove_file(&psmouse->ps2dev.serio->dev,
1416 &psmouse_attr_disable_gesture.dattr);
1417
1418 synaptics_reset(psmouse);
1419 kfree(priv);
1420 psmouse->private = NULL;
1421 }
1422
1423 static int synaptics_reconnect(struct psmouse *psmouse)
1424 {
1425 struct synaptics_data *priv = psmouse->private;
1426 struct synaptics_device_info info;
1427 u8 param[2];
1428 int retry = 0;
1429 int error;
1430
1431 do {
1432 psmouse_reset(psmouse);
1433 if (retry) {
1434
1435
1436
1437
1438
1439
1440
1441 ssleep(1);
1442 }
1443 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
1444 error = synaptics_detect(psmouse, 0);
1445 } while (error && ++retry < 3);
1446
1447 if (error)
1448 return error;
1449
1450 if (retry > 1)
1451 psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
1452
1453 error = synaptics_query_hardware(psmouse, &info);
1454 if (error) {
1455 psmouse_err(psmouse, "Unable to query device.\n");
1456 return error;
1457 }
1458
1459 error = synaptics_set_mode(psmouse);
1460 if (error) {
1461 psmouse_err(psmouse, "Unable to initialize device.\n");
1462 return error;
1463 }
1464
1465 if (info.identity != priv->info.identity ||
1466 info.model_id != priv->info.model_id ||
1467 info.capabilities != priv->info.capabilities ||
1468 info.ext_cap != priv->info.ext_cap) {
1469 psmouse_err(psmouse,
1470 "hardware appears to be different: id(%u-%u), model(%u-%u), caps(%x-%x), ext(%x-%x).\n",
1471 priv->info.identity, info.identity,
1472 priv->info.model_id, info.model_id,
1473 priv->info.capabilities, info.capabilities,
1474 priv->info.ext_cap, info.ext_cap);
1475 return -ENXIO;
1476 }
1477
1478 return 0;
1479 }
1480
1481 static bool impaired_toshiba_kbc;
1482
1483 static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
1484 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
1485 {
1486
1487 .matches = {
1488 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1489 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
1490 },
1491 },
1492 {
1493
1494 .matches = {
1495 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1496 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
1497 },
1498 },
1499 {
1500
1501 .matches = {
1502 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1503 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
1504 },
1505
1506 },
1507 {
1508
1509 .matches = {
1510 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1511 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
1512 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
1513 },
1514
1515 },
1516 #endif
1517 { }
1518 };
1519
1520 static bool broken_olpc_ec;
1521
1522 static const struct dmi_system_id olpc_dmi_table[] __initconst = {
1523 #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1524 {
1525
1526 .matches = {
1527 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
1528 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
1529 },
1530 },
1531 #endif
1532 { }
1533 };
1534
1535 static const struct dmi_system_id __initconst cr48_dmi_table[] = {
1536 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
1537 {
1538
1539 .matches = {
1540 DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
1541 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
1542 },
1543 },
1544 #endif
1545 { }
1546 };
1547
1548 void __init synaptics_module_init(void)
1549 {
1550 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
1551 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
1552 cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
1553 }
1554
1555 static int synaptics_init_ps2(struct psmouse *psmouse,
1556 struct synaptics_device_info *info,
1557 bool absolute_mode)
1558 {
1559 struct synaptics_data *priv;
1560 int err;
1561
1562 synaptics_apply_quirks(psmouse, info);
1563
1564 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
1565 if (!priv)
1566 return -ENOMEM;
1567
1568 priv->info = *info;
1569 priv->absolute_mode = absolute_mode;
1570 if (SYN_ID_DISGEST_SUPPORTED(info->identity))
1571 priv->disable_gesture = true;
1572
1573
1574
1575
1576
1577 priv->is_forcepad = psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids);
1578
1579 err = synaptics_set_mode(psmouse);
1580 if (err) {
1581 psmouse_err(psmouse, "Unable to initialize device.\n");
1582 goto init_fail;
1583 }
1584
1585 priv->pkt_type = SYN_MODEL_NEWABS(info->model_id) ?
1586 SYN_NEWABS : SYN_OLDABS;
1587
1588 psmouse_info(psmouse,
1589 "Touchpad model: %lu, fw: %lu.%lu, id: %#x, caps: %#x/%#x/%#x/%#x, board id: %u, fw id: %u\n",
1590 SYN_ID_MODEL(info->identity),
1591 SYN_ID_MAJOR(info->identity), SYN_ID_MINOR(info->identity),
1592 info->model_id,
1593 info->capabilities, info->ext_cap, info->ext_cap_0c,
1594 info->ext_cap_10, info->board_id, info->firmware_id);
1595
1596 err = set_input_params(psmouse, priv);
1597 if (err) {
1598 psmouse_err(psmouse,
1599 "failed to set up capabilities: %d\n", err);
1600 goto init_fail;
1601 }
1602
1603
1604
1605
1606
1607
1608
1609
1610 psmouse->model = ((info->model_id & 0x00ff0000) >> 8) |
1611 (info->model_id & 0x000000ff);
1612
1613 if (absolute_mode) {
1614 psmouse->protocol_handler = synaptics_process_byte;
1615 psmouse->pktsize = 6;
1616 } else {
1617
1618 psmouse->protocol_handler = psmouse_process_byte;
1619 psmouse->pktsize = 3;
1620 }
1621
1622 psmouse->set_rate = synaptics_set_rate;
1623 psmouse->disconnect = synaptics_disconnect;
1624 psmouse->reconnect = synaptics_reconnect;
1625 psmouse->cleanup = synaptics_reset;
1626
1627 psmouse->resync_time = 0;
1628
1629 if (SYN_CAP_PASS_THROUGH(info->capabilities))
1630 synaptics_pt_create(psmouse);
1631
1632
1633
1634
1635
1636
1637 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
1638 psmouse_info(psmouse,
1639 "Toshiba %s detected, limiting rate to 40pps.\n",
1640 dmi_get_system_info(DMI_PRODUCT_NAME));
1641 psmouse->rate = 40;
1642 }
1643
1644 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(info->identity)) {
1645 err = device_create_file(&psmouse->ps2dev.serio->dev,
1646 &psmouse_attr_disable_gesture.dattr);
1647 if (err) {
1648 psmouse_err(psmouse,
1649 "Failed to create disable_gesture attribute (%d)",
1650 err);
1651 goto init_fail;
1652 }
1653 }
1654
1655 return 0;
1656
1657 init_fail:
1658 kfree(priv);
1659 return err;
1660 }
1661
1662 static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
1663 {
1664 struct synaptics_device_info info;
1665 int error;
1666
1667 psmouse_reset(psmouse);
1668
1669 error = synaptics_query_hardware(psmouse, &info);
1670 if (error) {
1671 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1672 return error;
1673 }
1674
1675 return synaptics_init_ps2(psmouse, &info, absolute_mode);
1676 }
1677
1678 int synaptics_init_absolute(struct psmouse *psmouse)
1679 {
1680 return __synaptics_init(psmouse, true);
1681 }
1682
1683 int synaptics_init_relative(struct psmouse *psmouse)
1684 {
1685 return __synaptics_init(psmouse, false);
1686 }
1687
1688 static int synaptics_setup_ps2(struct psmouse *psmouse,
1689 struct synaptics_device_info *info)
1690 {
1691 bool absolute_mode = true;
1692 int error;
1693
1694
1695
1696
1697
1698
1699
1700 if (broken_olpc_ec) {
1701 psmouse_info(psmouse,
1702 "OLPC XO detected, forcing relative protocol.\n");
1703 absolute_mode = false;
1704 }
1705
1706 error = synaptics_init_ps2(psmouse, info, absolute_mode);
1707 if (error)
1708 return error;
1709
1710 return absolute_mode ? PSMOUSE_SYNAPTICS : PSMOUSE_SYNAPTICS_RELATIVE;
1711 }
1712
1713 #else
1714
1715 void __init synaptics_module_init(void)
1716 {
1717 }
1718
1719 static int __maybe_unused
1720 synaptics_setup_ps2(struct psmouse *psmouse,
1721 struct synaptics_device_info *info)
1722 {
1723 return -ENOSYS;
1724 }
1725
1726 #endif
1727
1728 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS
1729
1730
1731
1732
1733
1734
1735 enum {
1736 SYNAPTICS_INTERTOUCH_NOT_SET = -1,
1737 SYNAPTICS_INTERTOUCH_OFF,
1738 SYNAPTICS_INTERTOUCH_ON,
1739 };
1740
1741 static int synaptics_intertouch = IS_ENABLED(CONFIG_RMI4_SMB) ?
1742 SYNAPTICS_INTERTOUCH_NOT_SET : SYNAPTICS_INTERTOUCH_OFF;
1743 module_param_named(synaptics_intertouch, synaptics_intertouch, int, 0644);
1744 MODULE_PARM_DESC(synaptics_intertouch, "Use a secondary bus for the Synaptics device.");
1745
1746 static int synaptics_create_intertouch(struct psmouse *psmouse,
1747 struct synaptics_device_info *info,
1748 bool leave_breadcrumbs)
1749 {
1750 bool topbuttonpad =
1751 psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1752 !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10);
1753 const struct rmi_device_platform_data pdata = {
1754 .sensor_pdata = {
1755 .sensor_type = rmi_sensor_touchpad,
1756 .axis_align.flip_y = true,
1757 .kernel_tracking = false,
1758 .topbuttonpad = topbuttonpad,
1759 },
1760 .gpio_data = {
1761 .buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
1762 .trackstick_buttons =
1763 !!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
1764 },
1765 };
1766 const struct i2c_board_info intertouch_board = {
1767 I2C_BOARD_INFO("rmi4_smbus", 0x2c),
1768 .flags = I2C_CLIENT_HOST_NOTIFY,
1769 };
1770
1771 return psmouse_smbus_init(psmouse, &intertouch_board,
1772 &pdata, sizeof(pdata), true,
1773 leave_breadcrumbs);
1774 }
1775
1776
1777
1778
1779
1780 static int synaptics_setup_intertouch(struct psmouse *psmouse,
1781 struct synaptics_device_info *info,
1782 bool leave_breadcrumbs)
1783 {
1784 int error;
1785
1786 if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_OFF)
1787 return -ENXIO;
1788
1789 if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_NOT_SET) {
1790 if (!psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1791 !psmouse_matches_pnp_id(psmouse, smbus_pnp_ids)) {
1792
1793 if (!psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids))
1794 psmouse_info(psmouse,
1795 "Your touchpad (%s) says it can support a different bus. "
1796 "If i2c-hid and hid-rmi are not used, you might want to try setting psmouse.synaptics_intertouch to 1 and report this to linux-input@vger.kernel.org.\n",
1797 psmouse->ps2dev.serio->firmware_id);
1798
1799 return -ENXIO;
1800 }
1801 }
1802
1803 psmouse_info(psmouse, "Trying to set up SMBus access\n");
1804
1805 error = synaptics_create_intertouch(psmouse, info, leave_breadcrumbs);
1806 if (error) {
1807 if (error == -EAGAIN)
1808 psmouse_info(psmouse, "SMbus companion is not ready yet\n");
1809 else
1810 psmouse_err(psmouse, "unable to create intertouch device\n");
1811
1812 return error;
1813 }
1814
1815 return 0;
1816 }
1817
1818 int synaptics_init_smbus(struct psmouse *psmouse)
1819 {
1820 struct synaptics_device_info info;
1821 int error;
1822
1823 psmouse_reset(psmouse);
1824
1825 error = synaptics_query_hardware(psmouse, &info);
1826 if (error) {
1827 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1828 return error;
1829 }
1830
1831 if (!SYN_CAP_INTERTOUCH(info.ext_cap_0c))
1832 return -ENXIO;
1833
1834 return synaptics_create_intertouch(psmouse, &info, false);
1835 }
1836
1837 #else
1838
1839 static int __maybe_unused
1840 synaptics_setup_intertouch(struct psmouse *psmouse,
1841 struct synaptics_device_info *info,
1842 bool leave_breadcrumbs)
1843 {
1844 return -ENOSYS;
1845 }
1846
1847 int synaptics_init_smbus(struct psmouse *psmouse)
1848 {
1849 return -ENOSYS;
1850 }
1851
1852 #endif
1853
1854 #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
1855 defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
1856
1857 int synaptics_init(struct psmouse *psmouse)
1858 {
1859 struct synaptics_device_info info;
1860 int error;
1861 int retval;
1862
1863 psmouse_reset(psmouse);
1864
1865 error = synaptics_query_hardware(psmouse, &info);
1866 if (error) {
1867 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1868 return error;
1869 }
1870
1871 if (SYN_CAP_INTERTOUCH(info.ext_cap_0c)) {
1872 if ((!IS_ENABLED(CONFIG_RMI4_SMB) ||
1873 !IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)) &&
1874
1875 !psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids)) {
1876 psmouse_warn(psmouse,
1877 "The touchpad can support a better bus than the too old PS/2 protocol. "
1878 "Make sure MOUSE_PS2_SYNAPTICS_SMBUS and RMI4_SMB are enabled to get a better touchpad experience.\n");
1879 }
1880
1881 error = synaptics_setup_intertouch(psmouse, &info, true);
1882 if (!error)
1883 return PSMOUSE_SYNAPTICS_SMBUS;
1884 }
1885
1886 retval = synaptics_setup_ps2(psmouse, &info);
1887 if (retval < 0) {
1888
1889
1890
1891
1892 psmouse_smbus_cleanup(psmouse);
1893 }
1894
1895 return retval;
1896 }
1897
1898 #else
1899
1900 int synaptics_init(struct psmouse *psmouse)
1901 {
1902 return -ENOSYS;
1903 }
1904
1905 #endif