1 // SPDX-License-Identifier: GPL-2.0-only
3 * Synaptics TouchPad PS/2 mouse driver
5 * 2003 Dmitry Torokhov <dtor@mail.ru>
6 * Added support for pass-through port. Special thanks to Peter Berg Larsen
7 * for explaining various Synaptics quirks.
9 * 2003 Peter Osterlund <petero2@telia.com>
10 * Ported to 2.5 input device infrastructure.
12 * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch>
13 * start merging tpconfig and gpm code to a xfree-input module
14 * adding some changes and extensions (ex. 3rd and 4th button)
16 * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu>
17 * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com>
18 * code for the special synaptics commands (from the tpconfig-source)
20 * Trademarks are the property of their respective owners.
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/dmi.h>
26 #include <linux/input/mt.h>
27 #include <linux/serio.h>
28 #include <linux/libps2.h>
29 #include <linux/rmi.h>
30 #include <linux/i2c.h>
31 #include <linux/slab.h>
33 #include "synaptics.h"
36 * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
37 * section 2.3.2, which says that they should be valid regardless of the
38 * actual size of the sensor.
39 * Note that newer firmware allows querying device for maximum useable
46 #define XMIN_NOMINAL 1472
47 #define XMAX_NOMINAL 5472
48 #define YMIN_NOMINAL 1408
49 #define YMAX_NOMINAL 4448
51 /* Size in bits of absolute position values reported by the hardware */
52 #define ABS_POS_BITS 13
55 * These values should represent the absolute maximum value that will
56 * be reported for a positive position value. Some Synaptics firmware
57 * uses this value to indicate a finger near the edge of the touchpad
58 * whose precise position cannot be determined.
60 * At least one touchpad is known to report positions in excess of this
61 * value which are actually negative values truncated to the 13-bit
62 * reporting range. These values have never been observed to be lower
63 * than 8184 (i.e. -8), so we treat all values greater than 8176 as
64 * negative and any other value as positive.
66 #define X_MAX_POSITIVE 8176
67 #define Y_MAX_POSITIVE 8176
69 /* maximum ABS_MT_POSITION displacement (in mm) */
72 /*****************************************************************************
73 * Stuff we need even when we do not want native Synaptics support
74 ****************************************************************************/
77 * Set the synaptics touchpad mode byte by special commands
79 static int synaptics_mode_cmd(struct psmouse *psmouse, u8 mode)
84 error = ps2_sliced_command(&psmouse->ps2dev, mode);
88 param[0] = SYN_PS_SET_MODE2;
89 error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE);
96 int synaptics_detect(struct psmouse *psmouse, bool set_properties)
98 struct ps2dev *ps2dev = &psmouse->ps2dev;
101 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
102 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
103 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
104 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
105 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
107 if (param[1] != 0x47)
110 if (set_properties) {
111 psmouse->vendor = "Synaptics";
112 psmouse->name = "TouchPad";
118 void synaptics_reset(struct psmouse *psmouse)
120 /* reset touchpad back to relative mode, gestures enabled */
121 synaptics_mode_cmd(psmouse, 0);
124 #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
125 defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
127 /* This list has been kindly provided by Synaptics. */
128 static const char * const topbuttonpad_pnp_ids[] = {
138 "LEN0033", /* Helix */
139 "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
140 "LEN0035", /* X240 */
141 "LEN0036", /* T440 */
142 "LEN0037", /* X1 Carbon 2nd */
144 "LEN0039", /* T440s */
146 "LEN0042", /* Yoga */
150 "LEN2000", /* S540 */
151 "LEN2001", /* Edge E431 */
152 "LEN2002", /* Edge E531 */
154 "LEN2004", /* L440 */
156 "LEN2006", /* Edge E440/E540 */
165 static const char * const smbus_pnp_ids[] = {
166 /* all of the topbuttonpad_pnp_ids are valid, we just add some extras */
167 "LEN0048", /* X1 Carbon 3 */
168 "LEN0046", /* X250 */
169 "LEN004a", /* W541 */
171 "LEN005e", /* T560 */
172 "LEN006c", /* T470s */
173 "LEN0071", /* T480 */
174 "LEN0072", /* X1 Carbon Gen 5 (2017) - Elan/ALPS trackpoint */
175 "LEN0073", /* X1 Carbon G5 (Elantech) */
176 "LEN0091", /* X1 Carbon 6 */
177 "LEN0092", /* X1 Carbon 6 */
178 "LEN0093", /* T480 */
179 "LEN0096", /* X280 */
180 "LEN0097", /* X280 -> ALPS trackpoint */
181 "LEN009b", /* T580 */
182 "LEN200f", /* T450s */
183 "LEN2054", /* E480 */
184 "LEN2055", /* E580 */
185 "SYN3052", /* HP EliteBook 840 G4 */
186 "SYN3221", /* HP 15-ay000 */
187 "SYN323d", /* HP Spectre X360 13-w013dx */
191 static const char * const forcepad_pnp_ids[] = {
198 * Send a command to the synaptics touchpad by special commands
200 static int synaptics_send_cmd(struct psmouse *psmouse, u8 cmd, u8 *param)
204 error = ps2_sliced_command(&psmouse->ps2dev, cmd);
208 error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO);
215 static int synaptics_query_int(struct psmouse *psmouse, u8 query_cmd, u32 *val)
223 error = synaptics_send_cmd(psmouse, query_cmd, resp.buf + 1);
227 *val = be32_to_cpu(resp.be_val);
233 * See also the SYN_ID_* macros
235 static int synaptics_identify(struct psmouse *psmouse,
236 struct synaptics_device_info *info)
240 error = synaptics_query_int(psmouse, SYN_QUE_IDENTIFY, &info->identity);
244 return SYN_ID_IS_SYNAPTICS(info->identity) ? 0 : -ENXIO;
248 * Read the model-id bytes from the touchpad
249 * see also SYN_MODEL_* macros
251 static int synaptics_model_id(struct psmouse *psmouse,
252 struct synaptics_device_info *info)
254 return synaptics_query_int(psmouse, SYN_QUE_MODEL, &info->model_id);
258 * Read the firmware id from the touchpad
260 static int synaptics_firmware_id(struct psmouse *psmouse,
261 struct synaptics_device_info *info)
263 return synaptics_query_int(psmouse, SYN_QUE_FIRMWARE_ID,
268 * Read the board id and the "More Extended Queries" from the touchpad
269 * The board id is encoded in the "QUERY MODES" response
271 static int synaptics_query_modes(struct psmouse *psmouse,
272 struct synaptics_device_info *info)
277 /* firmwares prior 7.5 have no board_id encoded */
278 if (SYN_ID_FULL(info->identity) < 0x705)
281 error = synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid);
285 info->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
287 if (SYN_MEXT_CAP_BIT(bid[0]))
288 return synaptics_query_int(psmouse, SYN_QUE_MEXT_CAPAB_10,
295 * Read the capability-bits from the touchpad
296 * see also the SYN_CAP_* macros
298 static int synaptics_capability(struct psmouse *psmouse,
299 struct synaptics_device_info *info)
303 error = synaptics_query_int(psmouse, SYN_QUE_CAPABILITIES,
304 &info->capabilities);
308 info->ext_cap = info->ext_cap_0c = 0;
311 * Older firmwares had submodel ID fixed to 0x47
313 if (SYN_ID_FULL(info->identity) < 0x705 &&
314 SYN_CAP_SUBMODEL_ID(info->capabilities) != 0x47) {
319 * Unless capExtended is set the rest of the flags should be ignored
321 if (!SYN_CAP_EXTENDED(info->capabilities))
322 info->capabilities = 0;
324 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 1) {
325 error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB,
328 psmouse_warn(psmouse,
329 "device claims to have extended capabilities, but I'm not able to read them.\n");
332 * if nExtBtn is greater than 8 it should be considered
333 * invalid and treated as 0
335 if (SYN_CAP_MULTI_BUTTON_NO(info->ext_cap) > 8)
336 info->ext_cap &= ~SYN_CAP_MB_MASK;
340 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 4) {
341 error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB_0C,
344 psmouse_warn(psmouse,
345 "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
352 * Read touchpad resolution and maximum reported coordinates
353 * Resolution is left zero if touchpad does not support the query
355 static int synaptics_resolution(struct psmouse *psmouse,
356 struct synaptics_device_info *info)
361 if (SYN_ID_MAJOR(info->identity) < 4)
364 error = synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp);
366 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
367 info->x_res = resp[0]; /* x resolution in units/mm */
368 info->y_res = resp[2]; /* y resolution in units/mm */
372 if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 5 &&
373 SYN_CAP_MAX_DIMENSIONS(info->ext_cap_0c)) {
374 error = synaptics_send_cmd(psmouse,
375 SYN_QUE_EXT_MAX_COORDS, resp);
377 psmouse_warn(psmouse,
378 "device claims to have max coordinates query, but I'm not able to read it.\n");
380 info->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
381 info->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
382 psmouse_info(psmouse,
383 "queried max coordinates: x [..%d], y [..%d]\n",
384 info->x_max, info->y_max);
388 if (SYN_CAP_MIN_DIMENSIONS(info->ext_cap_0c) &&
389 (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 7 ||
391 * Firmware v8.1 does not report proper number of extended
392 * capabilities, but has been proven to report correct min
395 SYN_ID_FULL(info->identity) == 0x801)) {
396 error = synaptics_send_cmd(psmouse,
397 SYN_QUE_EXT_MIN_COORDS, resp);
399 psmouse_warn(psmouse,
400 "device claims to have min coordinates query, but I'm not able to read it.\n");
402 info->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
403 info->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
404 psmouse_info(psmouse,
405 "queried min coordinates: x [%d..], y [%d..]\n",
406 info->x_min, info->y_min);
413 static int synaptics_query_hardware(struct psmouse *psmouse,
414 struct synaptics_device_info *info)
418 memset(info, 0, sizeof(*info));
420 error = synaptics_identify(psmouse, info);
424 error = synaptics_model_id(psmouse, info);
428 error = synaptics_firmware_id(psmouse, info);
432 error = synaptics_query_modes(psmouse, info);
436 error = synaptics_capability(psmouse, info);
440 error = synaptics_resolution(psmouse, info);
447 #endif /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
449 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
451 static bool cr48_profile_sensor;
453 #define ANY_BOARD_ID 0
454 struct min_max_quirk {
455 const char * const *pnp_ids;
459 u32 x_min, x_max, y_min, y_max;
462 static const struct min_max_quirk min_max_pnpid_table[] = {
464 (const char * const []){"LEN0033", NULL},
465 {ANY_BOARD_ID, ANY_BOARD_ID},
466 1024, 5052, 2258, 4832
469 (const char * const []){"LEN0042", NULL},
470 {ANY_BOARD_ID, ANY_BOARD_ID},
471 1232, 5710, 1156, 4696
474 (const char * const []){"LEN0034", "LEN0036", "LEN0037",
475 "LEN0039", "LEN2002", "LEN2004",
477 {ANY_BOARD_ID, 2961},
478 1024, 5112, 2024, 4832
481 (const char * const []){"LEN2000", NULL},
482 {ANY_BOARD_ID, ANY_BOARD_ID},
483 1024, 5113, 2021, 4832
486 (const char * const []){"LEN2001", NULL},
487 {ANY_BOARD_ID, ANY_BOARD_ID},
488 1024, 5022, 2508, 4832
491 (const char * const []){"LEN2006", NULL},
493 1024, 5045, 2457, 4832
496 (const char * const []){"LEN2006", NULL},
497 {ANY_BOARD_ID, ANY_BOARD_ID},
498 1264, 5675, 1171, 4688
503 /*****************************************************************************
504 * Synaptics communications functions
505 ****************************************************************************/
508 * Synaptics touchpads report the y coordinate from bottom to top, which is
509 * opposite from what userspace expects.
510 * This function is used to invert y before reporting.
512 static int synaptics_invert_y(int y)
514 return YMAX_NOMINAL + YMIN_NOMINAL - y;
518 * Apply quirk(s) if the hardware matches
520 static void synaptics_apply_quirks(struct psmouse *psmouse,
521 struct synaptics_device_info *info)
525 for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
526 if (!psmouse_matches_pnp_id(psmouse,
527 min_max_pnpid_table[i].pnp_ids))
530 if (min_max_pnpid_table[i].board_id.min != ANY_BOARD_ID &&
531 info->board_id < min_max_pnpid_table[i].board_id.min)
534 if (min_max_pnpid_table[i].board_id.max != ANY_BOARD_ID &&
535 info->board_id > min_max_pnpid_table[i].board_id.max)
538 info->x_min = min_max_pnpid_table[i].x_min;
539 info->x_max = min_max_pnpid_table[i].x_max;
540 info->y_min = min_max_pnpid_table[i].y_min;
541 info->y_max = min_max_pnpid_table[i].y_max;
542 psmouse_info(psmouse,
543 "quirked min/max coordinates: x [%d..%d], y [%d..%d]\n",
544 info->x_min, info->x_max,
545 info->y_min, info->y_max);
550 static bool synaptics_has_agm(struct synaptics_data *priv)
552 return (SYN_CAP_ADV_GESTURE(priv->info.ext_cap_0c) ||
553 SYN_CAP_IMAGE_SENSOR(priv->info.ext_cap_0c));
556 static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
558 static u8 param = 0xc8;
561 error = ps2_sliced_command(&psmouse->ps2dev, SYN_QUE_MODEL);
565 error = ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE);
572 static int synaptics_set_mode(struct psmouse *psmouse)
574 struct synaptics_data *priv = psmouse->private;
578 if (priv->absolute_mode)
579 priv->mode |= SYN_BIT_ABSOLUTE_MODE;
580 if (priv->disable_gesture)
581 priv->mode |= SYN_BIT_DISABLE_GESTURE;
582 if (psmouse->rate >= 80)
583 priv->mode |= SYN_BIT_HIGH_RATE;
584 if (SYN_CAP_EXTENDED(priv->info.capabilities))
585 priv->mode |= SYN_BIT_W_MODE;
587 error = synaptics_mode_cmd(psmouse, priv->mode);
591 if (priv->absolute_mode && synaptics_has_agm(priv)) {
592 error = synaptics_set_advanced_gesture_mode(psmouse);
595 "Advanced gesture mode init failed: %d\n",
604 static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
606 struct synaptics_data *priv = psmouse->private;
609 priv->mode |= SYN_BIT_HIGH_RATE;
612 priv->mode &= ~SYN_BIT_HIGH_RATE;
616 synaptics_mode_cmd(psmouse, priv->mode);
619 /*****************************************************************************
620 * Synaptics pass-through PS/2 port support
621 ****************************************************************************/
622 static int synaptics_pt_write(struct serio *serio, u8 c)
624 struct psmouse *parent = serio_get_drvdata(serio->parent);
625 u8 rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
628 error = ps2_sliced_command(&parent->ps2dev, c);
632 error = ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE);
639 static int synaptics_pt_start(struct serio *serio)
641 struct psmouse *parent = serio_get_drvdata(serio->parent);
642 struct synaptics_data *priv = parent->private;
644 serio_pause_rx(parent->ps2dev.serio);
645 priv->pt_port = serio;
646 serio_continue_rx(parent->ps2dev.serio);
651 static void synaptics_pt_stop(struct serio *serio)
653 struct psmouse *parent = serio_get_drvdata(serio->parent);
654 struct synaptics_data *priv = parent->private;
656 serio_pause_rx(parent->ps2dev.serio);
657 priv->pt_port = NULL;
658 serio_continue_rx(parent->ps2dev.serio);
661 static int synaptics_is_pt_packet(u8 *buf)
663 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
666 static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet)
668 struct psmouse *child = serio_get_drvdata(ptport);
670 if (child && child->state == PSMOUSE_ACTIVATED) {
671 serio_interrupt(ptport, packet[1], 0);
672 serio_interrupt(ptport, packet[4], 0);
673 serio_interrupt(ptport, packet[5], 0);
674 if (child->pktsize == 4)
675 serio_interrupt(ptport, packet[2], 0);
677 serio_interrupt(ptport, packet[1], 0);
681 static void synaptics_pt_activate(struct psmouse *psmouse)
683 struct synaptics_data *priv = psmouse->private;
684 struct psmouse *child = serio_get_drvdata(priv->pt_port);
686 /* adjust the touchpad to child's choice of protocol */
688 if (child->pktsize == 4)
689 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
691 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
693 if (synaptics_mode_cmd(psmouse, priv->mode))
694 psmouse_warn(psmouse,
695 "failed to switch guest protocol\n");
699 static void synaptics_pt_create(struct psmouse *psmouse)
703 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
706 "not enough memory for pass-through port\n");
710 serio->id.type = SERIO_PS_PSTHRU;
711 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
712 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->phys));
713 serio->write = synaptics_pt_write;
714 serio->start = synaptics_pt_start;
715 serio->stop = synaptics_pt_stop;
716 serio->parent = psmouse->ps2dev.serio;
718 psmouse->pt_activate = synaptics_pt_activate;
720 psmouse_info(psmouse, "serio: %s port at %s\n",
721 serio->name, psmouse->phys);
722 serio_register_port(serio);
725 /*****************************************************************************
726 * Functions to interpret the absolute mode packets
727 ****************************************************************************/
729 static void synaptics_parse_agm(const u8 buf[],
730 struct synaptics_data *priv,
731 struct synaptics_hw_state *hw)
733 struct synaptics_hw_state *agm = &priv->agm;
736 agm_packet_type = (buf[5] & 0x30) >> 4;
737 switch (agm_packet_type) {
739 /* Gesture packet: (x, y, z) half resolution */
741 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
742 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
743 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
747 /* AGM-CONTACT packet: we are only interested in the count */
748 priv->agm_count = buf[1];
756 static void synaptics_parse_ext_buttons(const u8 buf[],
757 struct synaptics_data *priv,
758 struct synaptics_hw_state *hw)
760 unsigned int ext_bits =
761 (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) + 1) >> 1;
762 unsigned int ext_mask = GENMASK(ext_bits - 1, 0);
764 hw->ext_buttons = buf[4] & ext_mask;
765 hw->ext_buttons |= (buf[5] & ext_mask) << ext_bits;
768 static int synaptics_parse_hw_state(const u8 buf[],
769 struct synaptics_data *priv,
770 struct synaptics_hw_state *hw)
772 memset(hw, 0, sizeof(struct synaptics_hw_state));
774 if (SYN_MODEL_NEWABS(priv->info.model_id)) {
775 hw->w = (((buf[0] & 0x30) >> 2) |
776 ((buf[0] & 0x04) >> 1) |
777 ((buf[3] & 0x04) >> 2));
779 if (synaptics_has_agm(priv) && hw->w == 2) {
780 synaptics_parse_agm(buf, priv, hw);
784 hw->x = (((buf[3] & 0x10) << 8) |
785 ((buf[1] & 0x0f) << 8) |
787 hw->y = (((buf[3] & 0x20) << 7) |
788 ((buf[1] & 0xf0) << 4) |
792 hw->left = (buf[0] & 0x01) ? 1 : 0;
793 hw->right = (buf[0] & 0x02) ? 1 : 0;
795 if (priv->is_forcepad) {
797 * ForcePads, like Clickpads, use middle button
798 * bits to report primary button clicks.
799 * Unfortunately they report primary button not
800 * only when user presses on the pad above certain
801 * threshold, but also when there are more than one
802 * finger on the touchpad, which interferes with
803 * out multi-finger gestures.
807 priv->press = priv->report_press = false;
808 } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
810 * Single-finger touch with pressure above
811 * the threshold. If pressure stays long
812 * enough, we'll start reporting primary
813 * button. We rely on the device continuing
814 * sending data even if finger does not
818 priv->press_start = jiffies;
820 } else if (time_after(jiffies,
822 msecs_to_jiffies(50))) {
823 priv->report_press = true;
829 hw->left = priv->report_press;
831 } else if (SYN_CAP_CLICKPAD(priv->info.ext_cap_0c)) {
833 * Clickpad's button is transmitted as middle button,
834 * however, since it is primary button, we will report
837 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
839 } else if (SYN_CAP_MIDDLE_BUTTON(priv->info.capabilities)) {
840 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
842 hw->scroll = (s8)buf[1];
845 if (SYN_CAP_FOUR_BUTTON(priv->info.capabilities)) {
846 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
847 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
850 if (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) > 0 &&
851 ((buf[0] ^ buf[3]) & 0x02)) {
852 synaptics_parse_ext_buttons(buf, priv, hw);
855 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
856 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
858 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
859 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
861 hw->left = (buf[0] & 0x01) ? 1 : 0;
862 hw->right = (buf[0] & 0x02) ? 1 : 0;
866 * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE
867 * is used by some firmware to indicate a finger at the edge of
868 * the touchpad whose precise position cannot be determined, so
869 * convert these values to the maximum axis value.
871 if (hw->x > X_MAX_POSITIVE)
872 hw->x -= 1 << ABS_POS_BITS;
873 else if (hw->x == X_MAX_POSITIVE)
876 if (hw->y > Y_MAX_POSITIVE)
877 hw->y -= 1 << ABS_POS_BITS;
878 else if (hw->y == Y_MAX_POSITIVE)
884 static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
885 bool active, int x, int y)
887 input_mt_slot(dev, slot);
888 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
890 input_report_abs(dev, ABS_MT_POSITION_X, x);
891 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
895 static void synaptics_report_semi_mt_data(struct input_dev *dev,
896 const struct synaptics_hw_state *a,
897 const struct synaptics_hw_state *b,
900 if (num_fingers >= 2) {
901 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
903 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
905 } else if (num_fingers == 1) {
906 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
907 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
909 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
910 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
914 static void synaptics_report_ext_buttons(struct psmouse *psmouse,
915 const struct synaptics_hw_state *hw)
917 struct input_dev *dev = psmouse->dev;
918 struct synaptics_data *priv = psmouse->private;
919 int ext_bits = (SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap) + 1) >> 1;
922 if (!SYN_CAP_MULTI_BUTTON_NO(priv->info.ext_cap))
925 /* Bug in FW 8.1 & 8.2, buttons are reported only when ExtBit is 1 */
926 if ((SYN_ID_FULL(priv->info.identity) == 0x801 ||
927 SYN_ID_FULL(priv->info.identity) == 0x802) &&
928 !((psmouse->packet[0] ^ psmouse->packet[3]) & 0x02))
931 if (!SYN_CAP_EXT_BUTTONS_STICK(priv->info.ext_cap_10)) {
932 for (i = 0; i < ext_bits; i++) {
933 input_report_key(dev, BTN_0 + 2 * i,
934 hw->ext_buttons & BIT(i));
935 input_report_key(dev, BTN_1 + 2 * i,
936 hw->ext_buttons & BIT(i + ext_bits));
942 * This generation of touchpads has the trackstick buttons
943 * physically wired to the touchpad. Re-route them through
944 * the pass-through interface.
949 /* The trackstick expects at most 3 buttons */
950 pt_buttons = SYN_EXT_BUTTON_STICK_L(hw->ext_buttons) |
951 SYN_EXT_BUTTON_STICK_R(hw->ext_buttons) << 1 |
952 SYN_EXT_BUTTON_STICK_M(hw->ext_buttons) << 2;
954 serio_interrupt(priv->pt_port,
955 PSMOUSE_OOB_EXTRA_BTNS, SERIO_OOB_DATA);
956 serio_interrupt(priv->pt_port, pt_buttons, SERIO_OOB_DATA);
960 static void synaptics_report_buttons(struct psmouse *psmouse,
961 const struct synaptics_hw_state *hw)
963 struct input_dev *dev = psmouse->dev;
964 struct synaptics_data *priv = psmouse->private;
966 input_report_key(dev, BTN_LEFT, hw->left);
967 input_report_key(dev, BTN_RIGHT, hw->right);
969 if (SYN_CAP_MIDDLE_BUTTON(priv->info.capabilities))
970 input_report_key(dev, BTN_MIDDLE, hw->middle);
972 if (SYN_CAP_FOUR_BUTTON(priv->info.capabilities)) {
973 input_report_key(dev, BTN_FORWARD, hw->up);
974 input_report_key(dev, BTN_BACK, hw->down);
977 synaptics_report_ext_buttons(psmouse, hw);
980 static void synaptics_report_mt_data(struct psmouse *psmouse,
981 const struct synaptics_hw_state *sgm,
984 struct input_dev *dev = psmouse->dev;
985 struct synaptics_data *priv = psmouse->private;
986 const struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
987 struct input_mt_pos pos[2];
988 int slot[2], nsemi, i;
990 nsemi = clamp_val(num_fingers, 0, 2);
992 for (i = 0; i < nsemi; i++) {
994 pos[i].y = synaptics_invert_y(hw[i]->y);
997 input_mt_assign_slots(dev, slot, pos, nsemi, DMAX * priv->info.x_res);
999 for (i = 0; i < nsemi; i++) {
1000 input_mt_slot(dev, slot[i]);
1001 input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
1002 input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
1003 input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
1004 input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
1007 input_mt_drop_unused(dev);
1009 /* Don't use active slot count to generate BTN_TOOL events. */
1010 input_mt_report_pointer_emulation(dev, false);
1012 /* Send the number of fingers reported by touchpad itself. */
1013 input_mt_report_finger_count(dev, num_fingers);
1015 synaptics_report_buttons(psmouse, sgm);
1020 static void synaptics_image_sensor_process(struct psmouse *psmouse,
1021 struct synaptics_hw_state *sgm)
1023 struct synaptics_data *priv = psmouse->private;
1027 * Update mt_state using the new finger count and current mt_state.
1031 else if (sgm->w >= 4)
1033 else if (sgm->w == 0)
1035 else if (sgm->w == 1)
1036 num_fingers = priv->agm_count ? priv->agm_count : 3;
1040 /* Send resulting input events to user space */
1041 synaptics_report_mt_data(psmouse, sgm, num_fingers);
1044 static bool synaptics_has_multifinger(struct synaptics_data *priv)
1046 if (SYN_CAP_MULTIFINGER(priv->info.capabilities))
1049 /* Advanced gesture mode also sends multi finger data */
1050 return synaptics_has_agm(priv);
1054 * called for each full received packet from the touchpad
1056 static void synaptics_process_packet(struct psmouse *psmouse)
1058 struct input_dev *dev = psmouse->dev;
1059 struct synaptics_data *priv = psmouse->private;
1060 struct synaptics_device_info *info = &priv->info;
1061 struct synaptics_hw_state hw;
1065 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
1068 if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
1069 synaptics_image_sensor_process(psmouse, &hw);
1074 priv->scroll += hw.scroll;
1076 while (priv->scroll >= 4) {
1077 input_report_key(dev, BTN_BACK, !hw.down);
1079 input_report_key(dev, BTN_BACK, hw.down);
1083 while (priv->scroll <= -4) {
1084 input_report_key(dev, BTN_FORWARD, !hw.up);
1086 input_report_key(dev, BTN_FORWARD, hw.up);
1093 if (hw.z > 0 && hw.x > 1) {
1096 if (SYN_CAP_EXTENDED(info->capabilities)) {
1099 if (synaptics_has_multifinger(priv))
1100 num_fingers = hw.w + 2;
1103 if (SYN_MODEL_PEN(info->model_id))
1104 ; /* Nothing, treat a pen as a single finger */
1107 if (SYN_CAP_PALMDETECT(info->capabilities))
1108 finger_width = hw.w;
1117 if (cr48_profile_sensor) {
1118 synaptics_report_mt_data(psmouse, &hw, num_fingers);
1122 if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c))
1123 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
1127 * BTN_TOUCH has to be first as mousedev relies on it when doing
1128 * absolute -> relative conversion
1130 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
1131 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
1133 if (num_fingers > 0) {
1134 input_report_abs(dev, ABS_X, hw.x);
1135 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
1137 input_report_abs(dev, ABS_PRESSURE, hw.z);
1139 if (SYN_CAP_PALMDETECT(info->capabilities))
1140 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
1142 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
1143 if (synaptics_has_multifinger(priv)) {
1144 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
1145 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
1148 synaptics_report_buttons(psmouse, &hw);
1153 static bool synaptics_validate_byte(struct psmouse *psmouse,
1154 int idx, enum synaptics_pkt_type pkt_type)
1156 static const u8 newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
1157 static const u8 newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
1158 static const u8 newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
1159 static const u8 oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
1160 static const u8 oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
1161 const u8 *packet = psmouse->packet;
1163 if (idx < 0 || idx > 4)
1169 case SYN_NEWABS_RELAXED:
1170 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
1172 case SYN_NEWABS_STRICT:
1173 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
1176 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
1179 psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
1184 static enum synaptics_pkt_type
1185 synaptics_detect_pkt_type(struct psmouse *psmouse)
1189 for (i = 0; i < 5; i++) {
1190 if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
1191 psmouse_info(psmouse, "using relaxed packet validation\n");
1192 return SYN_NEWABS_RELAXED;
1196 return SYN_NEWABS_STRICT;
1199 static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
1201 struct synaptics_data *priv = psmouse->private;
1203 if (psmouse->pktcnt >= 6) { /* Full packet received */
1204 if (unlikely(priv->pkt_type == SYN_NEWABS))
1205 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
1207 if (SYN_CAP_PASS_THROUGH(priv->info.capabilities) &&
1208 synaptics_is_pt_packet(psmouse->packet)) {
1210 synaptics_pass_pt_packet(priv->pt_port,
1213 synaptics_process_packet(psmouse);
1215 return PSMOUSE_FULL_PACKET;
1218 return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
1219 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
1222 /*****************************************************************************
1223 * Driver initialization/cleanup functions
1224 ****************************************************************************/
1225 static void set_abs_position_params(struct input_dev *dev,
1226 struct synaptics_device_info *info,
1227 int x_code, int y_code)
1229 int x_min = info->x_min ?: XMIN_NOMINAL;
1230 int x_max = info->x_max ?: XMAX_NOMINAL;
1231 int y_min = info->y_min ?: YMIN_NOMINAL;
1232 int y_max = info->y_max ?: YMAX_NOMINAL;
1233 int fuzz = SYN_CAP_REDUCED_FILTERING(info->ext_cap_0c) ?
1234 SYN_REDUCED_FILTER_FUZZ : 0;
1236 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
1237 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
1238 input_abs_set_res(dev, x_code, info->x_res);
1239 input_abs_set_res(dev, y_code, info->y_res);
1242 static int set_input_params(struct psmouse *psmouse,
1243 struct synaptics_data *priv)
1245 struct input_dev *dev = psmouse->dev;
1246 struct synaptics_device_info *info = &priv->info;
1250 /* Reset default psmouse capabilities */
1251 __clear_bit(EV_REL, dev->evbit);
1252 bitmap_zero(dev->relbit, REL_CNT);
1253 bitmap_zero(dev->keybit, KEY_CNT);
1255 /* Things that apply to both modes */
1256 __set_bit(INPUT_PROP_POINTER, dev->propbit);
1258 input_set_capability(dev, EV_KEY, BTN_LEFT);
1260 /* Clickpads report only left button */
1261 if (!SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
1262 input_set_capability(dev, EV_KEY, BTN_RIGHT);
1263 if (SYN_CAP_MIDDLE_BUTTON(info->capabilities))
1264 input_set_capability(dev, EV_KEY, BTN_MIDDLE);
1267 if (!priv->absolute_mode) {
1269 input_set_capability(dev, EV_REL, REL_X);
1270 input_set_capability(dev, EV_REL, REL_Y);
1275 set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
1276 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
1278 if (cr48_profile_sensor)
1279 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1281 if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
1282 set_abs_position_params(dev, info,
1283 ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
1284 /* Image sensors can report per-contact pressure */
1285 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1287 error = input_mt_init_slots(dev, 2,
1288 INPUT_MT_POINTER | INPUT_MT_TRACK);
1292 /* Image sensors can signal 4 and 5 finger clicks */
1293 input_set_capability(dev, EV_KEY, BTN_TOOL_QUADTAP);
1294 input_set_capability(dev, EV_KEY, BTN_TOOL_QUINTTAP);
1295 } else if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c)) {
1296 set_abs_position_params(dev, info,
1297 ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
1299 * Profile sensor in CR-48 tracks contacts reasonably well,
1300 * other non-image sensors with AGM use semi-mt.
1302 error = input_mt_init_slots(dev, 2,
1304 (cr48_profile_sensor ?
1311 * For semi-mt devices we send ABS_X/Y ourselves instead of
1312 * input_mt_report_pointer_emulation. But
1313 * input_mt_init_slots() resets the fuzz to 0, leading to a
1314 * filtered ABS_MT_POSITION_X but an unfiltered ABS_X
1315 * position. Let's re-initialize ABS_X/Y here.
1317 if (!cr48_profile_sensor)
1318 set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
1321 if (SYN_CAP_PALMDETECT(info->capabilities))
1322 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
1324 input_set_capability(dev, EV_KEY, BTN_TOUCH);
1325 input_set_capability(dev, EV_KEY, BTN_TOOL_FINGER);
1327 if (synaptics_has_multifinger(priv)) {
1328 input_set_capability(dev, EV_KEY, BTN_TOOL_DOUBLETAP);
1329 input_set_capability(dev, EV_KEY, BTN_TOOL_TRIPLETAP);
1332 if (SYN_CAP_FOUR_BUTTON(info->capabilities) ||
1333 SYN_CAP_MIDDLE_BUTTON(info->capabilities)) {
1334 input_set_capability(dev, EV_KEY, BTN_FORWARD);
1335 input_set_capability(dev, EV_KEY, BTN_BACK);
1338 if (!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
1339 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(info->ext_cap); i++)
1340 input_set_capability(dev, EV_KEY, BTN_0 + i);
1342 if (SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
1343 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
1344 if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1345 !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
1346 __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
1352 static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
1353 void *data, char *buf)
1355 struct synaptics_data *priv = psmouse->private;
1357 return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
1360 static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
1361 void *data, const char *buf,
1364 struct synaptics_data *priv = psmouse->private;
1368 err = kstrtouint(buf, 10, &value);
1375 if (value == priv->disable_gesture)
1378 priv->disable_gesture = value;
1380 priv->mode |= SYN_BIT_DISABLE_GESTURE;
1382 priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
1384 if (synaptics_mode_cmd(psmouse, priv->mode))
1390 PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
1391 synaptics_show_disable_gesture,
1392 synaptics_set_disable_gesture);
1394 static void synaptics_disconnect(struct psmouse *psmouse)
1396 struct synaptics_data *priv = psmouse->private;
1399 * We might have left a breadcrumb when trying to
1400 * set up SMbus companion.
1402 psmouse_smbus_cleanup(psmouse);
1404 if (!priv->absolute_mode &&
1405 SYN_ID_DISGEST_SUPPORTED(priv->info.identity))
1406 device_remove_file(&psmouse->ps2dev.serio->dev,
1407 &psmouse_attr_disable_gesture.dattr);
1409 synaptics_reset(psmouse);
1411 psmouse->private = NULL;
1414 static int synaptics_reconnect(struct psmouse *psmouse)
1416 struct synaptics_data *priv = psmouse->private;
1417 struct synaptics_device_info info;
1423 psmouse_reset(psmouse);
1426 * On some boxes, right after resuming, the touchpad
1427 * needs some time to finish initializing (I assume
1428 * it needs time to calibrate) and start responding
1429 * to Synaptics-specific queries, so let's wait a
1434 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
1435 error = synaptics_detect(psmouse, 0);
1436 } while (error && ++retry < 3);
1442 psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
1444 error = synaptics_query_hardware(psmouse, &info);
1446 psmouse_err(psmouse, "Unable to query device.\n");
1450 error = synaptics_set_mode(psmouse);
1452 psmouse_err(psmouse, "Unable to initialize device.\n");
1456 if (info.identity != priv->info.identity ||
1457 info.model_id != priv->info.model_id ||
1458 info.capabilities != priv->info.capabilities ||
1459 info.ext_cap != priv->info.ext_cap) {
1460 psmouse_err(psmouse,
1461 "hardware appears to be different: id(%u-%u), model(%u-%u), caps(%x-%x), ext(%x-%x).\n",
1462 priv->info.identity, info.identity,
1463 priv->info.model_id, info.model_id,
1464 priv->info.capabilities, info.capabilities,
1465 priv->info.ext_cap, info.ext_cap);
1472 static bool impaired_toshiba_kbc;
1474 static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
1475 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
1477 /* Toshiba Satellite */
1479 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1480 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
1484 /* Toshiba Dynabook */
1486 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1487 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
1491 /* Toshiba Portege M300 */
1493 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1494 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
1499 /* Toshiba Portege M300 */
1501 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1502 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
1503 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
1511 static bool broken_olpc_ec;
1513 static const struct dmi_system_id olpc_dmi_table[] __initconst = {
1514 #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1516 /* OLPC XO-1 or XO-1.5 */
1518 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
1519 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
1526 static const struct dmi_system_id __initconst cr48_dmi_table[] = {
1527 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
1529 /* Cr-48 Chromebook (Codename Mario) */
1531 DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
1532 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
1539 void __init synaptics_module_init(void)
1541 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
1542 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
1543 cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
1546 static int synaptics_init_ps2(struct psmouse *psmouse,
1547 struct synaptics_device_info *info,
1550 struct synaptics_data *priv;
1553 synaptics_apply_quirks(psmouse, info);
1555 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
1560 priv->absolute_mode = absolute_mode;
1561 if (SYN_ID_DISGEST_SUPPORTED(info->identity))
1562 priv->disable_gesture = true;
1565 * Unfortunately ForcePad capability is not exported over PS/2,
1566 * so we have to resort to checking PNP IDs.
1568 priv->is_forcepad = psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids);
1570 err = synaptics_set_mode(psmouse);
1572 psmouse_err(psmouse, "Unable to initialize device.\n");
1576 priv->pkt_type = SYN_MODEL_NEWABS(info->model_id) ?
1577 SYN_NEWABS : SYN_OLDABS;
1579 psmouse_info(psmouse,
1580 "Touchpad model: %lu, fw: %lu.%lu, id: %#x, caps: %#x/%#x/%#x/%#x, board id: %u, fw id: %u\n",
1581 SYN_ID_MODEL(info->identity),
1582 SYN_ID_MAJOR(info->identity), SYN_ID_MINOR(info->identity),
1584 info->capabilities, info->ext_cap, info->ext_cap_0c,
1585 info->ext_cap_10, info->board_id, info->firmware_id);
1587 err = set_input_params(psmouse, priv);
1589 psmouse_err(psmouse,
1590 "failed to set up capabilities: %d\n", err);
1595 * Encode touchpad model so that it can be used to set
1596 * input device->id.version and be visible to userspace.
1597 * Because version is __u16 we have to drop something.
1598 * Hardware info bits seem to be good candidates as they
1599 * are documented to be for Synaptics corp. internal use.
1601 psmouse->model = ((info->model_id & 0x00ff0000) >> 8) |
1602 (info->model_id & 0x000000ff);
1604 if (absolute_mode) {
1605 psmouse->protocol_handler = synaptics_process_byte;
1606 psmouse->pktsize = 6;
1608 /* Relative mode follows standard PS/2 mouse protocol */
1609 psmouse->protocol_handler = psmouse_process_byte;
1610 psmouse->pktsize = 3;
1613 psmouse->set_rate = synaptics_set_rate;
1614 psmouse->disconnect = synaptics_disconnect;
1615 psmouse->reconnect = synaptics_reconnect;
1616 psmouse->cleanup = synaptics_reset;
1617 /* Synaptics can usually stay in sync without extra help */
1618 psmouse->resync_time = 0;
1620 if (SYN_CAP_PASS_THROUGH(info->capabilities))
1621 synaptics_pt_create(psmouse);
1624 * Toshiba's KBC seems to have trouble handling data from
1625 * Synaptics at full rate. Switch to a lower rate (roughly
1626 * the same rate as a standard PS/2 mouse).
1628 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
1629 psmouse_info(psmouse,
1630 "Toshiba %s detected, limiting rate to 40pps.\n",
1631 dmi_get_system_info(DMI_PRODUCT_NAME));
1635 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(info->identity)) {
1636 err = device_create_file(&psmouse->ps2dev.serio->dev,
1637 &psmouse_attr_disable_gesture.dattr);
1639 psmouse_err(psmouse,
1640 "Failed to create disable_gesture attribute (%d)",
1653 static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
1655 struct synaptics_device_info info;
1658 psmouse_reset(psmouse);
1660 error = synaptics_query_hardware(psmouse, &info);
1662 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1666 return synaptics_init_ps2(psmouse, &info, absolute_mode);
1669 int synaptics_init_absolute(struct psmouse *psmouse)
1671 return __synaptics_init(psmouse, true);
1674 int synaptics_init_relative(struct psmouse *psmouse)
1676 return __synaptics_init(psmouse, false);
1679 static int synaptics_setup_ps2(struct psmouse *psmouse,
1680 struct synaptics_device_info *info)
1682 bool absolute_mode = true;
1686 * The OLPC XO has issues with Synaptics' absolute mode; the constant
1687 * packet spew overloads the EC such that key presses on the keyboard
1688 * are missed. Given that, don't even attempt to use Absolute mode.
1689 * Relative mode seems to work just fine.
1691 if (broken_olpc_ec) {
1692 psmouse_info(psmouse,
1693 "OLPC XO detected, forcing relative protocol.\n");
1694 absolute_mode = false;
1697 error = synaptics_init_ps2(psmouse, info, absolute_mode);
1701 return absolute_mode ? PSMOUSE_SYNAPTICS : PSMOUSE_SYNAPTICS_RELATIVE;
1704 #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
1706 void __init synaptics_module_init(void)
1710 static int __maybe_unused
1711 synaptics_setup_ps2(struct psmouse *psmouse,
1712 struct synaptics_device_info *info)
1717 #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */
1719 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS
1722 * The newest Synaptics device can use a secondary bus (called InterTouch) which
1723 * provides a better bandwidth and allow a better control of the touchpads.
1724 * This is used to decide if we need to use this bus or not.
1727 SYNAPTICS_INTERTOUCH_NOT_SET = -1,
1728 SYNAPTICS_INTERTOUCH_OFF,
1729 SYNAPTICS_INTERTOUCH_ON,
1732 static int synaptics_intertouch = IS_ENABLED(CONFIG_RMI4_SMB) ?
1733 SYNAPTICS_INTERTOUCH_NOT_SET : SYNAPTICS_INTERTOUCH_OFF;
1734 module_param_named(synaptics_intertouch, synaptics_intertouch, int, 0644);
1735 MODULE_PARM_DESC(synaptics_intertouch, "Use a secondary bus for the Synaptics device.");
1737 static int synaptics_create_intertouch(struct psmouse *psmouse,
1738 struct synaptics_device_info *info,
1739 bool leave_breadcrumbs)
1742 psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1743 !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10);
1744 const struct rmi_device_platform_data pdata = {
1746 .sensor_type = rmi_sensor_touchpad,
1747 .axis_align.flip_y = true,
1748 .kernel_tracking = false,
1749 .topbuttonpad = topbuttonpad,
1752 .buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
1753 .trackstick_buttons =
1754 !!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
1757 const struct i2c_board_info intertouch_board = {
1758 I2C_BOARD_INFO("rmi4_smbus", 0x2c),
1759 .flags = I2C_CLIENT_HOST_NOTIFY,
1762 return psmouse_smbus_init(psmouse, &intertouch_board,
1763 &pdata, sizeof(pdata), true,
1768 * synaptics_setup_intertouch - called once the PS/2 devices are enumerated
1769 * and decides to instantiate a SMBus InterTouch device.
1771 static int synaptics_setup_intertouch(struct psmouse *psmouse,
1772 struct synaptics_device_info *info,
1773 bool leave_breadcrumbs)
1777 if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_OFF)
1780 if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_NOT_SET) {
1781 if (!psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
1782 !psmouse_matches_pnp_id(psmouse, smbus_pnp_ids)) {
1784 if (!psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids))
1785 psmouse_info(psmouse,
1786 "Your touchpad (%s) says it can support a different bus. "
1787 "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",
1788 psmouse->ps2dev.serio->firmware_id);
1794 psmouse_info(psmouse, "Trying to set up SMBus access\n");
1796 error = synaptics_create_intertouch(psmouse, info, leave_breadcrumbs);
1798 if (error == -EAGAIN)
1799 psmouse_info(psmouse, "SMbus companion is not ready yet\n");
1801 psmouse_err(psmouse, "unable to create intertouch device\n");
1809 int synaptics_init_smbus(struct psmouse *psmouse)
1811 struct synaptics_device_info info;
1814 psmouse_reset(psmouse);
1816 error = synaptics_query_hardware(psmouse, &info);
1818 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1822 if (!SYN_CAP_INTERTOUCH(info.ext_cap_0c))
1825 return synaptics_create_intertouch(psmouse, &info, false);
1828 #else /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
1830 static int __maybe_unused
1831 synaptics_setup_intertouch(struct psmouse *psmouse,
1832 struct synaptics_device_info *info,
1833 bool leave_breadcrumbs)
1838 int synaptics_init_smbus(struct psmouse *psmouse)
1843 #endif /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
1845 #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
1846 defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
1848 int synaptics_init(struct psmouse *psmouse)
1850 struct synaptics_device_info info;
1854 psmouse_reset(psmouse);
1856 error = synaptics_query_hardware(psmouse, &info);
1858 psmouse_err(psmouse, "Unable to query device: %d\n", error);
1862 if (SYN_CAP_INTERTOUCH(info.ext_cap_0c)) {
1863 if ((!IS_ENABLED(CONFIG_RMI4_SMB) ||
1864 !IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)) &&
1865 /* Forcepads need F21, which is not ready */
1866 !psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids)) {
1867 psmouse_warn(psmouse,
1868 "The touchpad can support a better bus than the too old PS/2 protocol. "
1869 "Make sure MOUSE_PS2_SYNAPTICS_SMBUS and RMI4_SMB are enabled to get a better touchpad experience.\n");
1872 error = synaptics_setup_intertouch(psmouse, &info, true);
1874 return PSMOUSE_SYNAPTICS_SMBUS;
1877 retval = synaptics_setup_ps2(psmouse, &info);
1880 * Not using any flavor of Synaptics support, so clean up
1881 * SMbus breadcrumbs, if any.
1883 psmouse_smbus_cleanup(psmouse);
1889 #else /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
1891 int synaptics_init(struct psmouse *psmouse)
1896 #endif /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */