synaptics.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. /*
  2. * Synaptics TouchPad PS/2 mouse driver
  3. *
  4. * 2003 Dmitry Torokhov <dtor@mail.ru>
  5. * Added support for pass-through port. Special thanks to Peter Berg Larsen
  6. * for explaining various Synaptics quirks.
  7. *
  8. * 2003 Peter Osterlund <petero2@telia.com>
  9. * Ported to 2.5 input device infrastructure.
  10. *
  11. * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch>
  12. * start merging tpconfig and gpm code to a xfree-input module
  13. * adding some changes and extensions (ex. 3rd and 4th button)
  14. *
  15. * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu>
  16. * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com>
  17. * code for the special synaptics commands (from the tpconfig-source)
  18. *
  19. * This program is free software; you can redistribute it and/or modify it
  20. * under the terms of the GNU General Public License version 2 as published by
  21. * the Free Software Foundation.
  22. *
  23. * Trademarks are the property of their respective owners.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/delay.h>
  27. #include <linux/dmi.h>
  28. #include <linux/input/mt.h>
  29. #include <linux/serio.h>
  30. #include <linux/libps2.h>
  31. #include <linux/slab.h>
  32. #include "psmouse.h"
  33. #include "synaptics.h"
  34. /*
  35. * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
  36. * section 2.3.2, which says that they should be valid regardless of the
  37. * actual size of the sensor.
  38. * Note that newer firmware allows querying device for maximum useable
  39. * coordinates.
  40. */
  41. #define XMIN 0
  42. #define XMAX 6143
  43. #define YMIN 0
  44. #define YMAX 6143
  45. #define XMIN_NOMINAL 1472
  46. #define XMAX_NOMINAL 5472
  47. #define YMIN_NOMINAL 1408
  48. #define YMAX_NOMINAL 4448
  49. /* Size in bits of absolute position values reported by the hardware */
  50. #define ABS_POS_BITS 13
  51. /*
  52. * These values should represent the absolute maximum value that will
  53. * be reported for a positive position value. Some Synaptics firmware
  54. * uses this value to indicate a finger near the edge of the touchpad
  55. * whose precise position cannot be determined.
  56. *
  57. * At least one touchpad is known to report positions in excess of this
  58. * value which are actually negative values truncated to the 13-bit
  59. * reporting range. These values have never been observed to be lower
  60. * than 8184 (i.e. -8), so we treat all values greater than 8176 as
  61. * negative and any other value as positive.
  62. */
  63. #define X_MAX_POSITIVE 8176
  64. #define Y_MAX_POSITIVE 8176
  65. /* maximum ABS_MT_POSITION displacement (in mm) */
  66. #define DMAX 10
  67. /*****************************************************************************
  68. * Stuff we need even when we do not want native Synaptics support
  69. ****************************************************************************/
  70. /*
  71. * Set the synaptics touchpad mode byte by special commands
  72. */
  73. static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
  74. {
  75. unsigned char param[1];
  76. if (psmouse_sliced_command(psmouse, mode))
  77. return -1;
  78. param[0] = SYN_PS_SET_MODE2;
  79. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
  80. return -1;
  81. return 0;
  82. }
  83. int synaptics_detect(struct psmouse *psmouse, bool set_properties)
  84. {
  85. struct ps2dev *ps2dev = &psmouse->ps2dev;
  86. unsigned char param[4];
  87. param[0] = 0;
  88. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  89. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  90. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  91. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  92. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
  93. if (param[1] != 0x47)
  94. return -ENODEV;
  95. if (set_properties) {
  96. psmouse->vendor = "Synaptics";
  97. psmouse->name = "TouchPad";
  98. }
  99. return 0;
  100. }
  101. void synaptics_reset(struct psmouse *psmouse)
  102. {
  103. /* reset touchpad back to relative mode, gestures enabled */
  104. synaptics_mode_cmd(psmouse, 0);
  105. }
  106. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
  107. static bool cr48_profile_sensor;
  108. struct min_max_quirk {
  109. const char * const *pnp_ids;
  110. int x_min, x_max, y_min, y_max;
  111. };
  112. static const struct min_max_quirk min_max_pnpid_table[] = {
  113. {
  114. (const char * const []){"LEN0033", NULL},
  115. 1024, 5052, 2258, 4832
  116. },
  117. {
  118. (const char * const []){"LEN0035", "LEN0042", NULL},
  119. 1232, 5710, 1156, 4696
  120. },
  121. {
  122. (const char * const []){"LEN0034", "LEN0036", "LEN0037",
  123. "LEN0039", "LEN2002", "LEN2004",
  124. NULL},
  125. 1024, 5112, 2024, 4832
  126. },
  127. {
  128. (const char * const []){"LEN2001", NULL},
  129. 1024, 5022, 2508, 4832
  130. },
  131. {
  132. (const char * const []){"LEN2006", NULL},
  133. 1264, 5675, 1171, 4688
  134. },
  135. { }
  136. };
  137. /* This list has been kindly provided by Synaptics. */
  138. static const char * const topbuttonpad_pnp_ids[] = {
  139. "LEN0017",
  140. "LEN0018",
  141. "LEN0019",
  142. "LEN0023",
  143. "LEN002A",
  144. "LEN002B",
  145. "LEN002C",
  146. "LEN002D",
  147. "LEN002E",
  148. "LEN0033", /* Helix */
  149. "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
  150. "LEN0035", /* X240 */
  151. "LEN0036", /* T440 */
  152. "LEN0037", /* X1 Carbon 2nd */
  153. "LEN0038",
  154. "LEN0039", /* T440s */
  155. "LEN0041",
  156. "LEN0042", /* Yoga */
  157. "LEN0045",
  158. "LEN0046",
  159. "LEN0047",
  160. "LEN0048",
  161. "LEN0049",
  162. "LEN2000",
  163. "LEN2001", /* Edge E431 */
  164. "LEN2002", /* Edge E531 */
  165. "LEN2003",
  166. "LEN2004", /* L440 */
  167. "LEN2005",
  168. "LEN2006",
  169. "LEN2007",
  170. "LEN2008",
  171. "LEN2009",
  172. "LEN200A",
  173. "LEN200B",
  174. NULL
  175. };
  176. /*****************************************************************************
  177. * Synaptics communications functions
  178. ****************************************************************************/
  179. /*
  180. * Synaptics touchpads report the y coordinate from bottom to top, which is
  181. * opposite from what userspace expects.
  182. * This function is used to invert y before reporting.
  183. */
  184. static int synaptics_invert_y(int y)
  185. {
  186. return YMAX_NOMINAL + YMIN_NOMINAL - y;
  187. }
  188. /*
  189. * Send a command to the synpatics touchpad by special commands
  190. */
  191. static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
  192. {
  193. if (psmouse_sliced_command(psmouse, c))
  194. return -1;
  195. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
  196. return -1;
  197. return 0;
  198. }
  199. /*
  200. * Read the model-id bytes from the touchpad
  201. * see also SYN_MODEL_* macros
  202. */
  203. static int synaptics_model_id(struct psmouse *psmouse)
  204. {
  205. struct synaptics_data *priv = psmouse->private;
  206. unsigned char mi[3];
  207. if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
  208. return -1;
  209. priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
  210. return 0;
  211. }
  212. /*
  213. * Read the board id from the touchpad
  214. * The board id is encoded in the "QUERY MODES" response
  215. */
  216. static int synaptics_board_id(struct psmouse *psmouse)
  217. {
  218. struct synaptics_data *priv = psmouse->private;
  219. unsigned char bid[3];
  220. if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid))
  221. return -1;
  222. priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
  223. return 0;
  224. }
  225. /*
  226. * Read the firmware id from the touchpad
  227. */
  228. static int synaptics_firmware_id(struct psmouse *psmouse)
  229. {
  230. struct synaptics_data *priv = psmouse->private;
  231. unsigned char fwid[3];
  232. if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid))
  233. return -1;
  234. priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
  235. return 0;
  236. }
  237. /*
  238. * Read the capability-bits from the touchpad
  239. * see also the SYN_CAP_* macros
  240. */
  241. static int synaptics_capability(struct psmouse *psmouse)
  242. {
  243. struct synaptics_data *priv = psmouse->private;
  244. unsigned char cap[3];
  245. if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
  246. return -1;
  247. priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  248. priv->ext_cap = priv->ext_cap_0c = 0;
  249. /*
  250. * Older firmwares had submodel ID fixed to 0x47
  251. */
  252. if (SYN_ID_FULL(priv->identity) < 0x705 &&
  253. SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
  254. return -1;
  255. }
  256. /*
  257. * Unless capExtended is set the rest of the flags should be ignored
  258. */
  259. if (!SYN_CAP_EXTENDED(priv->capabilities))
  260. priv->capabilities = 0;
  261. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
  262. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
  263. psmouse_warn(psmouse,
  264. "device claims to have extended capabilities, but I'm not able to read them.\n");
  265. } else {
  266. priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  267. /*
  268. * if nExtBtn is greater than 8 it should be considered
  269. * invalid and treated as 0
  270. */
  271. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
  272. priv->ext_cap &= 0xff0fff;
  273. }
  274. }
  275. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
  276. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
  277. psmouse_warn(psmouse,
  278. "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
  279. } else {
  280. priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  281. }
  282. }
  283. return 0;
  284. }
  285. /*
  286. * Identify Touchpad
  287. * See also the SYN_ID_* macros
  288. */
  289. static int synaptics_identify(struct psmouse *psmouse)
  290. {
  291. struct synaptics_data *priv = psmouse->private;
  292. unsigned char id[3];
  293. if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
  294. return -1;
  295. priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
  296. if (SYN_ID_IS_SYNAPTICS(priv->identity))
  297. return 0;
  298. return -1;
  299. }
  300. /*
  301. * Read touchpad resolution and maximum reported coordinates
  302. * Resolution is left zero if touchpad does not support the query
  303. */
  304. static int synaptics_resolution(struct psmouse *psmouse)
  305. {
  306. struct synaptics_data *priv = psmouse->private;
  307. unsigned char resp[3];
  308. int i;
  309. if (SYN_ID_MAJOR(priv->identity) < 4)
  310. return 0;
  311. if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) {
  312. if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
  313. priv->x_res = resp[0]; /* x resolution in units/mm */
  314. priv->y_res = resp[2]; /* y resolution in units/mm */
  315. }
  316. }
  317. for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
  318. if (psmouse_matches_pnp_id(psmouse,
  319. min_max_pnpid_table[i].pnp_ids)) {
  320. priv->x_min = min_max_pnpid_table[i].x_min;
  321. priv->x_max = min_max_pnpid_table[i].x_max;
  322. priv->y_min = min_max_pnpid_table[i].y_min;
  323. priv->y_max = min_max_pnpid_table[i].y_max;
  324. return 0;
  325. }
  326. }
  327. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
  328. SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
  329. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
  330. psmouse_warn(psmouse,
  331. "device claims to have max coordinates query, but I'm not able to read it.\n");
  332. } else {
  333. priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
  334. priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
  335. }
  336. }
  337. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 &&
  338. SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c)) {
  339. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) {
  340. psmouse_warn(psmouse,
  341. "device claims to have min coordinates query, but I'm not able to read it.\n");
  342. } else {
  343. priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
  344. priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
  345. }
  346. }
  347. return 0;
  348. }
  349. static int synaptics_query_hardware(struct psmouse *psmouse)
  350. {
  351. if (synaptics_identify(psmouse))
  352. return -1;
  353. if (synaptics_model_id(psmouse))
  354. return -1;
  355. if (synaptics_firmware_id(psmouse))
  356. return -1;
  357. if (synaptics_board_id(psmouse))
  358. return -1;
  359. if (synaptics_capability(psmouse))
  360. return -1;
  361. if (synaptics_resolution(psmouse))
  362. return -1;
  363. return 0;
  364. }
  365. static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
  366. {
  367. static unsigned char param = 0xc8;
  368. struct synaptics_data *priv = psmouse->private;
  369. if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
  370. SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
  371. return 0;
  372. if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
  373. return -1;
  374. if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
  375. return -1;
  376. /* Advanced gesture mode also sends multi finger data */
  377. priv->capabilities |= BIT(1);
  378. return 0;
  379. }
  380. static int synaptics_set_mode(struct psmouse *psmouse)
  381. {
  382. struct synaptics_data *priv = psmouse->private;
  383. priv->mode = 0;
  384. if (priv->absolute_mode)
  385. priv->mode |= SYN_BIT_ABSOLUTE_MODE;
  386. if (priv->disable_gesture)
  387. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  388. if (psmouse->rate >= 80)
  389. priv->mode |= SYN_BIT_HIGH_RATE;
  390. if (SYN_CAP_EXTENDED(priv->capabilities))
  391. priv->mode |= SYN_BIT_W_MODE;
  392. if (synaptics_mode_cmd(psmouse, priv->mode))
  393. return -1;
  394. if (priv->absolute_mode &&
  395. synaptics_set_advanced_gesture_mode(psmouse)) {
  396. psmouse_err(psmouse, "Advanced gesture mode init failed.\n");
  397. return -1;
  398. }
  399. return 0;
  400. }
  401. static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
  402. {
  403. struct synaptics_data *priv = psmouse->private;
  404. if (rate >= 80) {
  405. priv->mode |= SYN_BIT_HIGH_RATE;
  406. psmouse->rate = 80;
  407. } else {
  408. priv->mode &= ~SYN_BIT_HIGH_RATE;
  409. psmouse->rate = 40;
  410. }
  411. synaptics_mode_cmd(psmouse, priv->mode);
  412. }
  413. /*****************************************************************************
  414. * Synaptics pass-through PS/2 port support
  415. ****************************************************************************/
  416. static int synaptics_pt_write(struct serio *serio, unsigned char c)
  417. {
  418. struct psmouse *parent = serio_get_drvdata(serio->parent);
  419. char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
  420. if (psmouse_sliced_command(parent, c))
  421. return -1;
  422. if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
  423. return -1;
  424. return 0;
  425. }
  426. static int synaptics_pt_start(struct serio *serio)
  427. {
  428. struct psmouse *parent = serio_get_drvdata(serio->parent);
  429. struct synaptics_data *priv = parent->private;
  430. serio_pause_rx(parent->ps2dev.serio);
  431. priv->pt_port = serio;
  432. serio_continue_rx(parent->ps2dev.serio);
  433. return 0;
  434. }
  435. static void synaptics_pt_stop(struct serio *serio)
  436. {
  437. struct psmouse *parent = serio_get_drvdata(serio->parent);
  438. struct synaptics_data *priv = parent->private;
  439. serio_pause_rx(parent->ps2dev.serio);
  440. priv->pt_port = NULL;
  441. serio_continue_rx(parent->ps2dev.serio);
  442. }
  443. static int synaptics_is_pt_packet(unsigned char *buf)
  444. {
  445. return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
  446. }
  447. static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
  448. {
  449. struct psmouse *child = serio_get_drvdata(ptport);
  450. if (child && child->state == PSMOUSE_ACTIVATED) {
  451. serio_interrupt(ptport, packet[1], 0);
  452. serio_interrupt(ptport, packet[4], 0);
  453. serio_interrupt(ptport, packet[5], 0);
  454. if (child->pktsize == 4)
  455. serio_interrupt(ptport, packet[2], 0);
  456. } else
  457. serio_interrupt(ptport, packet[1], 0);
  458. }
  459. static void synaptics_pt_activate(struct psmouse *psmouse)
  460. {
  461. struct synaptics_data *priv = psmouse->private;
  462. struct psmouse *child = serio_get_drvdata(priv->pt_port);
  463. /* adjust the touchpad to child's choice of protocol */
  464. if (child) {
  465. if (child->pktsize == 4)
  466. priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
  467. else
  468. priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
  469. if (synaptics_mode_cmd(psmouse, priv->mode))
  470. psmouse_warn(psmouse,
  471. "failed to switch guest protocol\n");
  472. }
  473. }
  474. static void synaptics_pt_create(struct psmouse *psmouse)
  475. {
  476. struct serio *serio;
  477. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  478. if (!serio) {
  479. psmouse_err(psmouse,
  480. "not enough memory for pass-through port\n");
  481. return;
  482. }
  483. serio->id.type = SERIO_PS_PSTHRU;
  484. strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
  485. strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
  486. serio->write = synaptics_pt_write;
  487. serio->start = synaptics_pt_start;
  488. serio->stop = synaptics_pt_stop;
  489. serio->parent = psmouse->ps2dev.serio;
  490. psmouse->pt_activate = synaptics_pt_activate;
  491. psmouse_info(psmouse, "serio: %s port at %s\n",
  492. serio->name, psmouse->phys);
  493. serio_register_port(serio);
  494. }
  495. /*****************************************************************************
  496. * Functions to interpret the absolute mode packets
  497. ****************************************************************************/
  498. static void synaptics_parse_agm(const unsigned char buf[],
  499. struct synaptics_data *priv,
  500. struct synaptics_hw_state *hw)
  501. {
  502. struct synaptics_hw_state *agm = &priv->agm;
  503. int agm_packet_type;
  504. agm_packet_type = (buf[5] & 0x30) >> 4;
  505. switch (agm_packet_type) {
  506. case 1:
  507. /* Gesture packet: (x, y, z) half resolution */
  508. agm->w = hw->w;
  509. agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
  510. agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
  511. agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
  512. break;
  513. case 2:
  514. /* AGM-CONTACT packet: we are only interested in the count */
  515. priv->agm_count = buf[1];
  516. break;
  517. default:
  518. break;
  519. }
  520. }
  521. static bool is_forcepad;
  522. static int synaptics_parse_hw_state(const unsigned char buf[],
  523. struct synaptics_data *priv,
  524. struct synaptics_hw_state *hw)
  525. {
  526. memset(hw, 0, sizeof(struct synaptics_hw_state));
  527. if (SYN_MODEL_NEWABS(priv->model_id)) {
  528. hw->w = (((buf[0] & 0x30) >> 2) |
  529. ((buf[0] & 0x04) >> 1) |
  530. ((buf[3] & 0x04) >> 2));
  531. if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
  532. SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
  533. hw->w == 2) {
  534. synaptics_parse_agm(buf, priv, hw);
  535. return 1;
  536. }
  537. hw->x = (((buf[3] & 0x10) << 8) |
  538. ((buf[1] & 0x0f) << 8) |
  539. buf[4]);
  540. hw->y = (((buf[3] & 0x20) << 7) |
  541. ((buf[1] & 0xf0) << 4) |
  542. buf[5]);
  543. hw->z = buf[2];
  544. hw->left = (buf[0] & 0x01) ? 1 : 0;
  545. hw->right = (buf[0] & 0x02) ? 1 : 0;
  546. if (is_forcepad) {
  547. /*
  548. * ForcePads, like Clickpads, use middle button
  549. * bits to report primary button clicks.
  550. * Unfortunately they report primary button not
  551. * only when user presses on the pad above certain
  552. * threshold, but also when there are more than one
  553. * finger on the touchpad, which interferes with
  554. * out multi-finger gestures.
  555. */
  556. if (hw->z == 0) {
  557. /* No contacts */
  558. priv->press = priv->report_press = false;
  559. } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
  560. /*
  561. * Single-finger touch with pressure above
  562. * the threshold. If pressure stays long
  563. * enough, we'll start reporting primary
  564. * button. We rely on the device continuing
  565. * sending data even if finger does not
  566. * move.
  567. */
  568. if (!priv->press) {
  569. priv->press_start = jiffies;
  570. priv->press = true;
  571. } else if (time_after(jiffies,
  572. priv->press_start +
  573. msecs_to_jiffies(50))) {
  574. priv->report_press = true;
  575. }
  576. } else {
  577. priv->press = false;
  578. }
  579. hw->left = priv->report_press;
  580. } else if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  581. /*
  582. * Clickpad's button is transmitted as middle button,
  583. * however, since it is primary button, we will report
  584. * it as BTN_LEFT.
  585. */
  586. hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  587. } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  588. hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  589. if (hw->w == 2)
  590. hw->scroll = (signed char)(buf[1]);
  591. }
  592. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  593. hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  594. hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
  595. }
  596. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
  597. ((buf[0] ^ buf[3]) & 0x02)) {
  598. switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
  599. default:
  600. /*
  601. * if nExtBtn is greater than 8 it should be
  602. * considered invalid and treated as 0
  603. */
  604. break;
  605. case 8:
  606. hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
  607. hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
  608. case 6:
  609. hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
  610. hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
  611. case 4:
  612. hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
  613. hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
  614. case 2:
  615. hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
  616. hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
  617. }
  618. }
  619. } else {
  620. hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
  621. hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
  622. hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
  623. hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
  624. hw->left = (buf[0] & 0x01) ? 1 : 0;
  625. hw->right = (buf[0] & 0x02) ? 1 : 0;
  626. }
  627. /*
  628. * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE
  629. * is used by some firmware to indicate a finger at the edge of
  630. * the touchpad whose precise position cannot be determined, so
  631. * convert these values to the maximum axis value.
  632. */
  633. if (hw->x > X_MAX_POSITIVE)
  634. hw->x -= 1 << ABS_POS_BITS;
  635. else if (hw->x == X_MAX_POSITIVE)
  636. hw->x = XMAX;
  637. if (hw->y > Y_MAX_POSITIVE)
  638. hw->y -= 1 << ABS_POS_BITS;
  639. else if (hw->y == Y_MAX_POSITIVE)
  640. hw->y = YMAX;
  641. return 0;
  642. }
  643. static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
  644. bool active, int x, int y)
  645. {
  646. input_mt_slot(dev, slot);
  647. input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
  648. if (active) {
  649. input_report_abs(dev, ABS_MT_POSITION_X, x);
  650. input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
  651. }
  652. }
  653. static void synaptics_report_semi_mt_data(struct input_dev *dev,
  654. const struct synaptics_hw_state *a,
  655. const struct synaptics_hw_state *b,
  656. int num_fingers)
  657. {
  658. if (num_fingers >= 2) {
  659. synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
  660. min(a->y, b->y));
  661. synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
  662. max(a->y, b->y));
  663. } else if (num_fingers == 1) {
  664. synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
  665. synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
  666. } else {
  667. synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
  668. synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
  669. }
  670. }
  671. static void synaptics_report_buttons(struct psmouse *psmouse,
  672. const struct synaptics_hw_state *hw)
  673. {
  674. struct input_dev *dev = psmouse->dev;
  675. struct synaptics_data *priv = psmouse->private;
  676. int i;
  677. input_report_key(dev, BTN_LEFT, hw->left);
  678. input_report_key(dev, BTN_RIGHT, hw->right);
  679. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  680. input_report_key(dev, BTN_MIDDLE, hw->middle);
  681. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  682. input_report_key(dev, BTN_FORWARD, hw->up);
  683. input_report_key(dev, BTN_BACK, hw->down);
  684. }
  685. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
  686. input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i));
  687. }
  688. static void synaptics_report_mt_data(struct psmouse *psmouse,
  689. const struct synaptics_hw_state *sgm,
  690. int num_fingers)
  691. {
  692. struct input_dev *dev = psmouse->dev;
  693. struct synaptics_data *priv = psmouse->private;
  694. const struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
  695. struct input_mt_pos pos[2];
  696. int slot[2], nsemi, i;
  697. nsemi = clamp_val(num_fingers, 0, 2);
  698. for (i = 0; i < nsemi; i++) {
  699. pos[i].x = hw[i]->x;
  700. pos[i].y = synaptics_invert_y(hw[i]->y);
  701. }
  702. input_mt_assign_slots(dev, slot, pos, nsemi, DMAX * priv->x_res);
  703. for (i = 0; i < nsemi; i++) {
  704. input_mt_slot(dev, slot[i]);
  705. input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
  706. input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
  707. input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
  708. input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
  709. }
  710. input_mt_drop_unused(dev);
  711. /* Don't use active slot count to generate BTN_TOOL events. */
  712. input_mt_report_pointer_emulation(dev, false);
  713. /* Send the number of fingers reported by touchpad itself. */
  714. input_mt_report_finger_count(dev, num_fingers);
  715. synaptics_report_buttons(psmouse, sgm);
  716. input_sync(dev);
  717. }
  718. static void synaptics_image_sensor_process(struct psmouse *psmouse,
  719. struct synaptics_hw_state *sgm)
  720. {
  721. struct synaptics_data *priv = psmouse->private;
  722. int num_fingers;
  723. /*
  724. * Update mt_state using the new finger count and current mt_state.
  725. */
  726. if (sgm->z == 0)
  727. num_fingers = 0;
  728. else if (sgm->w >= 4)
  729. num_fingers = 1;
  730. else if (sgm->w == 0)
  731. num_fingers = 2;
  732. else if (sgm->w == 1)
  733. num_fingers = priv->agm_count ? priv->agm_count : 3;
  734. else
  735. num_fingers = 4;
  736. /* Send resulting input events to user space */
  737. synaptics_report_mt_data(psmouse, sgm, num_fingers);
  738. }
  739. /*
  740. * called for each full received packet from the touchpad
  741. */
  742. static void synaptics_process_packet(struct psmouse *psmouse)
  743. {
  744. struct input_dev *dev = psmouse->dev;
  745. struct synaptics_data *priv = psmouse->private;
  746. struct synaptics_hw_state hw;
  747. int num_fingers;
  748. int finger_width;
  749. if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
  750. return;
  751. if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
  752. synaptics_image_sensor_process(psmouse, &hw);
  753. return;
  754. }
  755. if (hw.scroll) {
  756. priv->scroll += hw.scroll;
  757. while (priv->scroll >= 4) {
  758. input_report_key(dev, BTN_BACK, !hw.down);
  759. input_sync(dev);
  760. input_report_key(dev, BTN_BACK, hw.down);
  761. input_sync(dev);
  762. priv->scroll -= 4;
  763. }
  764. while (priv->scroll <= -4) {
  765. input_report_key(dev, BTN_FORWARD, !hw.up);
  766. input_sync(dev);
  767. input_report_key(dev, BTN_FORWARD, hw.up);
  768. input_sync(dev);
  769. priv->scroll += 4;
  770. }
  771. return;
  772. }
  773. if (hw.z > 0 && hw.x > 1) {
  774. num_fingers = 1;
  775. finger_width = 5;
  776. if (SYN_CAP_EXTENDED(priv->capabilities)) {
  777. switch (hw.w) {
  778. case 0 ... 1:
  779. if (SYN_CAP_MULTIFINGER(priv->capabilities))
  780. num_fingers = hw.w + 2;
  781. break;
  782. case 2:
  783. if (SYN_MODEL_PEN(priv->model_id))
  784. ; /* Nothing, treat a pen as a single finger */
  785. break;
  786. case 4 ... 15:
  787. if (SYN_CAP_PALMDETECT(priv->capabilities))
  788. finger_width = hw.w;
  789. break;
  790. }
  791. }
  792. } else {
  793. num_fingers = 0;
  794. finger_width = 0;
  795. }
  796. if (cr48_profile_sensor) {
  797. synaptics_report_mt_data(psmouse, &hw, num_fingers);
  798. return;
  799. }
  800. if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
  801. synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
  802. num_fingers);
  803. /* Post events
  804. * BTN_TOUCH has to be first as mousedev relies on it when doing
  805. * absolute -> relative conversion
  806. */
  807. if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
  808. if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
  809. if (num_fingers > 0) {
  810. input_report_abs(dev, ABS_X, hw.x);
  811. input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
  812. }
  813. input_report_abs(dev, ABS_PRESSURE, hw.z);
  814. if (SYN_CAP_PALMDETECT(priv->capabilities))
  815. input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
  816. input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
  817. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  818. input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
  819. input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
  820. }
  821. synaptics_report_buttons(psmouse, &hw);
  822. input_sync(dev);
  823. }
  824. static int synaptics_validate_byte(struct psmouse *psmouse,
  825. int idx, unsigned char pkt_type)
  826. {
  827. static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
  828. static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
  829. static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
  830. static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
  831. static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
  832. const char *packet = psmouse->packet;
  833. if (idx < 0 || idx > 4)
  834. return 0;
  835. switch (pkt_type) {
  836. case SYN_NEWABS:
  837. case SYN_NEWABS_RELAXED:
  838. return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
  839. case SYN_NEWABS_STRICT:
  840. return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
  841. case SYN_OLDABS:
  842. return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
  843. default:
  844. psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
  845. return 0;
  846. }
  847. }
  848. static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
  849. {
  850. int i;
  851. for (i = 0; i < 5; i++)
  852. if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
  853. psmouse_info(psmouse, "using relaxed packet validation\n");
  854. return SYN_NEWABS_RELAXED;
  855. }
  856. return SYN_NEWABS_STRICT;
  857. }
  858. static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
  859. {
  860. struct synaptics_data *priv = psmouse->private;
  861. if (psmouse->pktcnt >= 6) { /* Full packet received */
  862. if (unlikely(priv->pkt_type == SYN_NEWABS))
  863. priv->pkt_type = synaptics_detect_pkt_type(psmouse);
  864. if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
  865. synaptics_is_pt_packet(psmouse->packet)) {
  866. if (priv->pt_port)
  867. synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
  868. } else
  869. synaptics_process_packet(psmouse);
  870. return PSMOUSE_FULL_PACKET;
  871. }
  872. return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
  873. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  874. }
  875. /*****************************************************************************
  876. * Driver initialization/cleanup functions
  877. ****************************************************************************/
  878. static void set_abs_position_params(struct input_dev *dev,
  879. struct synaptics_data *priv, int x_code,
  880. int y_code)
  881. {
  882. int x_min = priv->x_min ?: XMIN_NOMINAL;
  883. int x_max = priv->x_max ?: XMAX_NOMINAL;
  884. int y_min = priv->y_min ?: YMIN_NOMINAL;
  885. int y_max = priv->y_max ?: YMAX_NOMINAL;
  886. int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
  887. SYN_REDUCED_FILTER_FUZZ : 0;
  888. input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
  889. input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
  890. input_abs_set_res(dev, x_code, priv->x_res);
  891. input_abs_set_res(dev, y_code, priv->y_res);
  892. }
  893. static void set_input_params(struct psmouse *psmouse,
  894. struct synaptics_data *priv)
  895. {
  896. struct input_dev *dev = psmouse->dev;
  897. int i;
  898. /* Things that apply to both modes */
  899. __set_bit(INPUT_PROP_POINTER, dev->propbit);
  900. __set_bit(EV_KEY, dev->evbit);
  901. __set_bit(BTN_LEFT, dev->keybit);
  902. __set_bit(BTN_RIGHT, dev->keybit);
  903. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  904. __set_bit(BTN_MIDDLE, dev->keybit);
  905. if (!priv->absolute_mode) {
  906. /* Relative mode */
  907. __set_bit(EV_REL, dev->evbit);
  908. __set_bit(REL_X, dev->relbit);
  909. __set_bit(REL_Y, dev->relbit);
  910. return;
  911. }
  912. /* Absolute mode */
  913. __set_bit(EV_ABS, dev->evbit);
  914. set_abs_position_params(dev, priv, ABS_X, ABS_Y);
  915. input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
  916. if (cr48_profile_sensor)
  917. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  918. if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
  919. set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
  920. ABS_MT_POSITION_Y);
  921. /* Image sensors can report per-contact pressure */
  922. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  923. input_mt_init_slots(dev, 2, INPUT_MT_POINTER | INPUT_MT_TRACK);
  924. /* Image sensors can signal 4 and 5 finger clicks */
  925. __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
  926. __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
  927. } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
  928. set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
  929. ABS_MT_POSITION_Y);
  930. /*
  931. * Profile sensor in CR-48 tracks contacts reasonably well,
  932. * other non-image sensors with AGM use semi-mt.
  933. */
  934. input_mt_init_slots(dev, 2,
  935. INPUT_MT_POINTER |
  936. (cr48_profile_sensor ?
  937. INPUT_MT_TRACK : INPUT_MT_SEMI_MT));
  938. }
  939. if (SYN_CAP_PALMDETECT(priv->capabilities))
  940. input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
  941. __set_bit(BTN_TOUCH, dev->keybit);
  942. __set_bit(BTN_TOOL_FINGER, dev->keybit);
  943. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  944. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  945. __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
  946. }
  947. if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
  948. SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  949. __set_bit(BTN_FORWARD, dev->keybit);
  950. __set_bit(BTN_BACK, dev->keybit);
  951. }
  952. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
  953. __set_bit(BTN_0 + i, dev->keybit);
  954. __clear_bit(EV_REL, dev->evbit);
  955. __clear_bit(REL_X, dev->relbit);
  956. __clear_bit(REL_Y, dev->relbit);
  957. if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  958. __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
  959. if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids))
  960. __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
  961. /* Clickpads report only left button */
  962. __clear_bit(BTN_RIGHT, dev->keybit);
  963. __clear_bit(BTN_MIDDLE, dev->keybit);
  964. }
  965. }
  966. static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
  967. void *data, char *buf)
  968. {
  969. struct synaptics_data *priv = psmouse->private;
  970. return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
  971. }
  972. static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
  973. void *data, const char *buf,
  974. size_t len)
  975. {
  976. struct synaptics_data *priv = psmouse->private;
  977. unsigned int value;
  978. int err;
  979. err = kstrtouint(buf, 10, &value);
  980. if (err)
  981. return err;
  982. if (value > 1)
  983. return -EINVAL;
  984. if (value == priv->disable_gesture)
  985. return len;
  986. priv->disable_gesture = value;
  987. if (value)
  988. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  989. else
  990. priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
  991. if (synaptics_mode_cmd(psmouse, priv->mode))
  992. return -EIO;
  993. return len;
  994. }
  995. PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
  996. synaptics_show_disable_gesture,
  997. synaptics_set_disable_gesture);
  998. static void synaptics_disconnect(struct psmouse *psmouse)
  999. {
  1000. struct synaptics_data *priv = psmouse->private;
  1001. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity))
  1002. device_remove_file(&psmouse->ps2dev.serio->dev,
  1003. &psmouse_attr_disable_gesture.dattr);
  1004. synaptics_reset(psmouse);
  1005. kfree(priv);
  1006. psmouse->private = NULL;
  1007. }
  1008. static int synaptics_reconnect(struct psmouse *psmouse)
  1009. {
  1010. struct synaptics_data *priv = psmouse->private;
  1011. struct synaptics_data old_priv = *priv;
  1012. unsigned char param[2];
  1013. int retry = 0;
  1014. int error;
  1015. do {
  1016. psmouse_reset(psmouse);
  1017. if (retry) {
  1018. /*
  1019. * On some boxes, right after resuming, the touchpad
  1020. * needs some time to finish initializing (I assume
  1021. * it needs time to calibrate) and start responding
  1022. * to Synaptics-specific queries, so let's wait a
  1023. * bit.
  1024. */
  1025. ssleep(1);
  1026. }
  1027. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
  1028. error = synaptics_detect(psmouse, 0);
  1029. } while (error && ++retry < 3);
  1030. if (error)
  1031. return -1;
  1032. if (retry > 1)
  1033. psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
  1034. if (synaptics_query_hardware(psmouse)) {
  1035. psmouse_err(psmouse, "Unable to query device.\n");
  1036. return -1;
  1037. }
  1038. if (synaptics_set_mode(psmouse)) {
  1039. psmouse_err(psmouse, "Unable to initialize device.\n");
  1040. return -1;
  1041. }
  1042. if (old_priv.identity != priv->identity ||
  1043. old_priv.model_id != priv->model_id ||
  1044. old_priv.capabilities != priv->capabilities ||
  1045. old_priv.ext_cap != priv->ext_cap) {
  1046. psmouse_err(psmouse,
  1047. "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
  1048. old_priv.identity, priv->identity,
  1049. old_priv.model_id, priv->model_id,
  1050. old_priv.capabilities, priv->capabilities,
  1051. old_priv.ext_cap, priv->ext_cap);
  1052. return -1;
  1053. }
  1054. return 0;
  1055. }
  1056. static bool impaired_toshiba_kbc;
  1057. static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
  1058. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1059. {
  1060. /* Toshiba Satellite */
  1061. .matches = {
  1062. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1063. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  1064. },
  1065. },
  1066. {
  1067. /* Toshiba Dynabook */
  1068. .matches = {
  1069. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1070. DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
  1071. },
  1072. },
  1073. {
  1074. /* Toshiba Portege M300 */
  1075. .matches = {
  1076. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1077. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
  1078. },
  1079. },
  1080. {
  1081. /* Toshiba Portege M300 */
  1082. .matches = {
  1083. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1084. DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
  1085. DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
  1086. },
  1087. },
  1088. #endif
  1089. { }
  1090. };
  1091. static bool broken_olpc_ec;
  1092. static const struct dmi_system_id olpc_dmi_table[] __initconst = {
  1093. #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
  1094. {
  1095. /* OLPC XO-1 or XO-1.5 */
  1096. .matches = {
  1097. DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
  1098. DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
  1099. },
  1100. },
  1101. #endif
  1102. { }
  1103. };
  1104. static const struct dmi_system_id __initconst cr48_dmi_table[] = {
  1105. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1106. {
  1107. /* Cr-48 Chromebook (Codename Mario) */
  1108. .matches = {
  1109. DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
  1110. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  1111. },
  1112. },
  1113. #endif
  1114. { }
  1115. };
  1116. static const struct dmi_system_id forcepad_dmi_table[] __initconst = {
  1117. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1118. {
  1119. .matches = {
  1120. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1121. DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook Folio 1040 G1"),
  1122. },
  1123. },
  1124. #endif
  1125. { }
  1126. };
  1127. void __init synaptics_module_init(void)
  1128. {
  1129. impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
  1130. broken_olpc_ec = dmi_check_system(olpc_dmi_table);
  1131. cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
  1132. /*
  1133. * Unfortunately ForcePad capability is not exported over PS/2,
  1134. * so we have to resort to checking DMI.
  1135. */
  1136. is_forcepad = dmi_check_system(forcepad_dmi_table);
  1137. }
  1138. static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
  1139. {
  1140. struct synaptics_data *priv;
  1141. int err = -1;
  1142. /*
  1143. * The OLPC XO has issues with Synaptics' absolute mode; the constant
  1144. * packet spew overloads the EC such that key presses on the keyboard
  1145. * are missed. Given that, don't even attempt to use Absolute mode.
  1146. * Relative mode seems to work just fine.
  1147. */
  1148. if (absolute_mode && broken_olpc_ec) {
  1149. psmouse_info(psmouse,
  1150. "OLPC XO detected, not enabling Synaptics protocol.\n");
  1151. return -ENODEV;
  1152. }
  1153. psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
  1154. if (!priv)
  1155. return -ENOMEM;
  1156. psmouse_reset(psmouse);
  1157. if (synaptics_query_hardware(psmouse)) {
  1158. psmouse_err(psmouse, "Unable to query device.\n");
  1159. goto init_fail;
  1160. }
  1161. priv->absolute_mode = absolute_mode;
  1162. if (SYN_ID_DISGEST_SUPPORTED(priv->identity))
  1163. priv->disable_gesture = true;
  1164. if (synaptics_set_mode(psmouse)) {
  1165. psmouse_err(psmouse, "Unable to initialize device.\n");
  1166. goto init_fail;
  1167. }
  1168. priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
  1169. psmouse_info(psmouse,
  1170. "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n",
  1171. SYN_ID_MODEL(priv->identity),
  1172. SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
  1173. priv->model_id,
  1174. priv->capabilities, priv->ext_cap, priv->ext_cap_0c,
  1175. priv->board_id, priv->firmware_id);
  1176. set_input_params(psmouse, priv);
  1177. /*
  1178. * Encode touchpad model so that it can be used to set
  1179. * input device->id.version and be visible to userspace.
  1180. * Because version is __u16 we have to drop something.
  1181. * Hardware info bits seem to be good candidates as they
  1182. * are documented to be for Synaptics corp. internal use.
  1183. */
  1184. psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
  1185. (priv->model_id & 0x000000ff);
  1186. if (absolute_mode) {
  1187. psmouse->protocol_handler = synaptics_process_byte;
  1188. psmouse->pktsize = 6;
  1189. } else {
  1190. /* Relative mode follows standard PS/2 mouse protocol */
  1191. psmouse->protocol_handler = psmouse_process_byte;
  1192. psmouse->pktsize = 3;
  1193. }
  1194. psmouse->set_rate = synaptics_set_rate;
  1195. psmouse->disconnect = synaptics_disconnect;
  1196. psmouse->reconnect = synaptics_reconnect;
  1197. psmouse->cleanup = synaptics_reset;
  1198. /* Synaptics can usually stay in sync without extra help */
  1199. psmouse->resync_time = 0;
  1200. if (SYN_CAP_PASS_THROUGH(priv->capabilities))
  1201. synaptics_pt_create(psmouse);
  1202. /*
  1203. * Toshiba's KBC seems to have trouble handling data from
  1204. * Synaptics at full rate. Switch to a lower rate (roughly
  1205. * the same rate as a standard PS/2 mouse).
  1206. */
  1207. if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
  1208. psmouse_info(psmouse,
  1209. "Toshiba %s detected, limiting rate to 40pps.\n",
  1210. dmi_get_system_info(DMI_PRODUCT_NAME));
  1211. psmouse->rate = 40;
  1212. }
  1213. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) {
  1214. err = device_create_file(&psmouse->ps2dev.serio->dev,
  1215. &psmouse_attr_disable_gesture.dattr);
  1216. if (err) {
  1217. psmouse_err(psmouse,
  1218. "Failed to create disable_gesture attribute (%d)",
  1219. err);
  1220. goto init_fail;
  1221. }
  1222. }
  1223. return 0;
  1224. init_fail:
  1225. kfree(priv);
  1226. return err;
  1227. }
  1228. int synaptics_init(struct psmouse *psmouse)
  1229. {
  1230. return __synaptics_init(psmouse, true);
  1231. }
  1232. int synaptics_init_relative(struct psmouse *psmouse)
  1233. {
  1234. return __synaptics_init(psmouse, false);
  1235. }
  1236. #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1237. void __init synaptics_module_init(void)
  1238. {
  1239. }
  1240. int synaptics_init(struct psmouse *psmouse)
  1241. {
  1242. return -ENOSYS;
  1243. }
  1244. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */