synaptics.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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. /*****************************************************************************
  66. * Stuff we need even when we do not want native Synaptics support
  67. ****************************************************************************/
  68. /*
  69. * Set the synaptics touchpad mode byte by special commands
  70. */
  71. static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
  72. {
  73. unsigned char param[1];
  74. if (psmouse_sliced_command(psmouse, mode))
  75. return -1;
  76. param[0] = SYN_PS_SET_MODE2;
  77. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
  78. return -1;
  79. return 0;
  80. }
  81. int synaptics_detect(struct psmouse *psmouse, bool set_properties)
  82. {
  83. struct ps2dev *ps2dev = &psmouse->ps2dev;
  84. unsigned char param[4];
  85. param[0] = 0;
  86. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  87. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  88. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  89. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  90. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
  91. if (param[1] != 0x47)
  92. return -ENODEV;
  93. if (set_properties) {
  94. psmouse->vendor = "Synaptics";
  95. psmouse->name = "TouchPad";
  96. }
  97. return 0;
  98. }
  99. void synaptics_reset(struct psmouse *psmouse)
  100. {
  101. /* reset touchpad back to relative mode, gestures enabled */
  102. synaptics_mode_cmd(psmouse, 0);
  103. }
  104. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
  105. static bool cr48_profile_sensor;
  106. #define ANY_BOARD_ID 0
  107. struct min_max_quirk {
  108. const char * const *pnp_ids;
  109. struct {
  110. unsigned long int min, max;
  111. } board_id;
  112. int x_min, x_max, y_min, y_max;
  113. };
  114. static const struct min_max_quirk min_max_pnpid_table[] = {
  115. {
  116. (const char * const []){"LEN0033", NULL},
  117. {ANY_BOARD_ID, ANY_BOARD_ID},
  118. 1024, 5052, 2258, 4832
  119. },
  120. {
  121. (const char * const []){"LEN0042", NULL},
  122. {ANY_BOARD_ID, ANY_BOARD_ID},
  123. 1232, 5710, 1156, 4696
  124. },
  125. {
  126. (const char * const []){"LEN0034", "LEN0036", "LEN0037",
  127. "LEN0039", "LEN2002", "LEN2004",
  128. NULL},
  129. {ANY_BOARD_ID, 2961},
  130. 1024, 5112, 2024, 4832
  131. },
  132. {
  133. (const char * const []){"LEN2000", NULL},
  134. {ANY_BOARD_ID, ANY_BOARD_ID},
  135. 1024, 5113, 2021, 4832
  136. },
  137. {
  138. (const char * const []){"LEN2001", NULL},
  139. {ANY_BOARD_ID, ANY_BOARD_ID},
  140. 1024, 5022, 2508, 4832
  141. },
  142. {
  143. (const char * const []){"LEN2006", NULL},
  144. {ANY_BOARD_ID, ANY_BOARD_ID},
  145. 1264, 5675, 1171, 4688
  146. },
  147. { }
  148. };
  149. /* This list has been kindly provided by Synaptics. */
  150. static const char * const topbuttonpad_pnp_ids[] = {
  151. "LEN0017",
  152. "LEN0018",
  153. "LEN0019",
  154. "LEN0023",
  155. "LEN002A",
  156. "LEN002B",
  157. "LEN002C",
  158. "LEN002D",
  159. "LEN002E",
  160. "LEN0033", /* Helix */
  161. "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
  162. "LEN0035", /* X240 */
  163. "LEN0036", /* T440 */
  164. "LEN0037", /* X1 Carbon 2nd */
  165. "LEN0038",
  166. "LEN0039", /* T440s */
  167. "LEN0041",
  168. "LEN0042", /* Yoga */
  169. "LEN0045",
  170. "LEN0046",
  171. "LEN0047",
  172. "LEN0048",
  173. "LEN0049",
  174. "LEN2000", /* S540 */
  175. "LEN2001", /* Edge E431 */
  176. "LEN2002", /* Edge E531 */
  177. "LEN2003",
  178. "LEN2004", /* L440 */
  179. "LEN2005",
  180. "LEN2006",
  181. "LEN2007",
  182. "LEN2008",
  183. "LEN2009",
  184. "LEN200A",
  185. "LEN200B",
  186. NULL
  187. };
  188. /*****************************************************************************
  189. * Synaptics communications functions
  190. ****************************************************************************/
  191. /*
  192. * Synaptics touchpads report the y coordinate from bottom to top, which is
  193. * opposite from what userspace expects.
  194. * This function is used to invert y before reporting.
  195. */
  196. static int synaptics_invert_y(int y)
  197. {
  198. return YMAX_NOMINAL + YMIN_NOMINAL - y;
  199. }
  200. /*
  201. * Send a command to the synpatics touchpad by special commands
  202. */
  203. static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
  204. {
  205. if (psmouse_sliced_command(psmouse, c))
  206. return -1;
  207. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
  208. return -1;
  209. return 0;
  210. }
  211. /*
  212. * Read the model-id bytes from the touchpad
  213. * see also SYN_MODEL_* macros
  214. */
  215. static int synaptics_model_id(struct psmouse *psmouse)
  216. {
  217. struct synaptics_data *priv = psmouse->private;
  218. unsigned char mi[3];
  219. if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
  220. return -1;
  221. priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
  222. return 0;
  223. }
  224. /*
  225. * Read the board id from the touchpad
  226. * The board id is encoded in the "QUERY MODES" response
  227. */
  228. static int synaptics_board_id(struct psmouse *psmouse)
  229. {
  230. struct synaptics_data *priv = psmouse->private;
  231. unsigned char bid[3];
  232. /* firmwares prior 7.5 have no board_id encoded */
  233. if (SYN_ID_FULL(priv->identity) < 0x705)
  234. return 0;
  235. if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid))
  236. return -1;
  237. priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
  238. return 0;
  239. }
  240. /*
  241. * Read the firmware id from the touchpad
  242. */
  243. static int synaptics_firmware_id(struct psmouse *psmouse)
  244. {
  245. struct synaptics_data *priv = psmouse->private;
  246. unsigned char fwid[3];
  247. if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid))
  248. return -1;
  249. priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
  250. return 0;
  251. }
  252. /*
  253. * Read the capability-bits from the touchpad
  254. * see also the SYN_CAP_* macros
  255. */
  256. static int synaptics_capability(struct psmouse *psmouse)
  257. {
  258. struct synaptics_data *priv = psmouse->private;
  259. unsigned char cap[3];
  260. if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
  261. return -1;
  262. priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  263. priv->ext_cap = priv->ext_cap_0c = 0;
  264. /*
  265. * Older firmwares had submodel ID fixed to 0x47
  266. */
  267. if (SYN_ID_FULL(priv->identity) < 0x705 &&
  268. SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
  269. return -1;
  270. }
  271. /*
  272. * Unless capExtended is set the rest of the flags should be ignored
  273. */
  274. if (!SYN_CAP_EXTENDED(priv->capabilities))
  275. priv->capabilities = 0;
  276. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
  277. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
  278. psmouse_warn(psmouse,
  279. "device claims to have extended capabilities, but I'm not able to read them.\n");
  280. } else {
  281. priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  282. /*
  283. * if nExtBtn is greater than 8 it should be considered
  284. * invalid and treated as 0
  285. */
  286. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
  287. priv->ext_cap &= 0xff0fff;
  288. }
  289. }
  290. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
  291. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
  292. psmouse_warn(psmouse,
  293. "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
  294. } else {
  295. priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  296. }
  297. }
  298. return 0;
  299. }
  300. /*
  301. * Identify Touchpad
  302. * See also the SYN_ID_* macros
  303. */
  304. static int synaptics_identify(struct psmouse *psmouse)
  305. {
  306. struct synaptics_data *priv = psmouse->private;
  307. unsigned char id[3];
  308. if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
  309. return -1;
  310. priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
  311. if (SYN_ID_IS_SYNAPTICS(priv->identity))
  312. return 0;
  313. return -1;
  314. }
  315. /*
  316. * Read touchpad resolution and maximum reported coordinates
  317. * Resolution is left zero if touchpad does not support the query
  318. */
  319. static int synaptics_resolution(struct psmouse *psmouse)
  320. {
  321. struct synaptics_data *priv = psmouse->private;
  322. unsigned char resp[3];
  323. if (SYN_ID_MAJOR(priv->identity) < 4)
  324. return 0;
  325. if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) {
  326. if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
  327. priv->x_res = resp[0]; /* x resolution in units/mm */
  328. priv->y_res = resp[2]; /* y resolution in units/mm */
  329. }
  330. }
  331. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
  332. SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
  333. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
  334. psmouse_warn(psmouse,
  335. "device claims to have max coordinates query, but I'm not able to read it.\n");
  336. } else {
  337. priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
  338. priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
  339. psmouse_info(psmouse,
  340. "queried max coordinates: x [..%d], y [..%d]\n",
  341. priv->x_max, priv->y_max);
  342. }
  343. }
  344. if (SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c) &&
  345. (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 ||
  346. /*
  347. * Firmware v8.1 does not report proper number of extended
  348. * capabilities, but has been proven to report correct min
  349. * coordinates.
  350. */
  351. SYN_ID_FULL(priv->identity) == 0x801)) {
  352. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) {
  353. psmouse_warn(psmouse,
  354. "device claims to have min coordinates query, but I'm not able to read it.\n");
  355. } else {
  356. priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
  357. priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
  358. psmouse_info(psmouse,
  359. "queried min coordinates: x [%d..], y [%d..]\n",
  360. priv->x_min, priv->y_min);
  361. }
  362. }
  363. return 0;
  364. }
  365. /*
  366. * Apply quirk(s) if the hardware matches
  367. */
  368. static void synaptics_apply_quirks(struct psmouse *psmouse)
  369. {
  370. struct synaptics_data *priv = psmouse->private;
  371. int i;
  372. for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
  373. if (!psmouse_matches_pnp_id(psmouse,
  374. min_max_pnpid_table[i].pnp_ids))
  375. continue;
  376. if (min_max_pnpid_table[i].board_id.min != ANY_BOARD_ID &&
  377. priv->board_id < min_max_pnpid_table[i].board_id.min)
  378. continue;
  379. if (min_max_pnpid_table[i].board_id.max != ANY_BOARD_ID &&
  380. priv->board_id > min_max_pnpid_table[i].board_id.max)
  381. continue;
  382. priv->x_min = min_max_pnpid_table[i].x_min;
  383. priv->x_max = min_max_pnpid_table[i].x_max;
  384. priv->y_min = min_max_pnpid_table[i].y_min;
  385. priv->y_max = min_max_pnpid_table[i].y_max;
  386. psmouse_info(psmouse,
  387. "quirked min/max coordinates: x [%d..%d], y [%d..%d]\n",
  388. priv->x_min, priv->x_max,
  389. priv->y_min, priv->y_max);
  390. break;
  391. }
  392. }
  393. static int synaptics_query_hardware(struct psmouse *psmouse)
  394. {
  395. if (synaptics_identify(psmouse))
  396. return -1;
  397. if (synaptics_model_id(psmouse))
  398. return -1;
  399. if (synaptics_firmware_id(psmouse))
  400. return -1;
  401. if (synaptics_board_id(psmouse))
  402. return -1;
  403. if (synaptics_capability(psmouse))
  404. return -1;
  405. if (synaptics_resolution(psmouse))
  406. return -1;
  407. synaptics_apply_quirks(psmouse);
  408. return 0;
  409. }
  410. static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
  411. {
  412. static unsigned char param = 0xc8;
  413. struct synaptics_data *priv = psmouse->private;
  414. if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
  415. SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
  416. return 0;
  417. if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
  418. return -1;
  419. if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
  420. return -1;
  421. /* Advanced gesture mode also sends multi finger data */
  422. priv->capabilities |= BIT(1);
  423. return 0;
  424. }
  425. static int synaptics_set_mode(struct psmouse *psmouse)
  426. {
  427. struct synaptics_data *priv = psmouse->private;
  428. priv->mode = 0;
  429. if (priv->absolute_mode)
  430. priv->mode |= SYN_BIT_ABSOLUTE_MODE;
  431. if (priv->disable_gesture)
  432. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  433. if (psmouse->rate >= 80)
  434. priv->mode |= SYN_BIT_HIGH_RATE;
  435. if (SYN_CAP_EXTENDED(priv->capabilities))
  436. priv->mode |= SYN_BIT_W_MODE;
  437. if (synaptics_mode_cmd(psmouse, priv->mode))
  438. return -1;
  439. if (priv->absolute_mode &&
  440. synaptics_set_advanced_gesture_mode(psmouse)) {
  441. psmouse_err(psmouse, "Advanced gesture mode init failed.\n");
  442. return -1;
  443. }
  444. return 0;
  445. }
  446. static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
  447. {
  448. struct synaptics_data *priv = psmouse->private;
  449. if (rate >= 80) {
  450. priv->mode |= SYN_BIT_HIGH_RATE;
  451. psmouse->rate = 80;
  452. } else {
  453. priv->mode &= ~SYN_BIT_HIGH_RATE;
  454. psmouse->rate = 40;
  455. }
  456. synaptics_mode_cmd(psmouse, priv->mode);
  457. }
  458. /*****************************************************************************
  459. * Synaptics pass-through PS/2 port support
  460. ****************************************************************************/
  461. static int synaptics_pt_write(struct serio *serio, unsigned char c)
  462. {
  463. struct psmouse *parent = serio_get_drvdata(serio->parent);
  464. char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
  465. if (psmouse_sliced_command(parent, c))
  466. return -1;
  467. if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
  468. return -1;
  469. return 0;
  470. }
  471. static int synaptics_pt_start(struct serio *serio)
  472. {
  473. struct psmouse *parent = serio_get_drvdata(serio->parent);
  474. struct synaptics_data *priv = parent->private;
  475. serio_pause_rx(parent->ps2dev.serio);
  476. priv->pt_port = serio;
  477. serio_continue_rx(parent->ps2dev.serio);
  478. return 0;
  479. }
  480. static void synaptics_pt_stop(struct serio *serio)
  481. {
  482. struct psmouse *parent = serio_get_drvdata(serio->parent);
  483. struct synaptics_data *priv = parent->private;
  484. serio_pause_rx(parent->ps2dev.serio);
  485. priv->pt_port = NULL;
  486. serio_continue_rx(parent->ps2dev.serio);
  487. }
  488. static int synaptics_is_pt_packet(unsigned char *buf)
  489. {
  490. return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
  491. }
  492. static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
  493. {
  494. struct psmouse *child = serio_get_drvdata(ptport);
  495. if (child && child->state == PSMOUSE_ACTIVATED) {
  496. serio_interrupt(ptport, packet[1], 0);
  497. serio_interrupt(ptport, packet[4], 0);
  498. serio_interrupt(ptport, packet[5], 0);
  499. if (child->pktsize == 4)
  500. serio_interrupt(ptport, packet[2], 0);
  501. } else
  502. serio_interrupt(ptport, packet[1], 0);
  503. }
  504. static void synaptics_pt_activate(struct psmouse *psmouse)
  505. {
  506. struct synaptics_data *priv = psmouse->private;
  507. struct psmouse *child = serio_get_drvdata(priv->pt_port);
  508. /* adjust the touchpad to child's choice of protocol */
  509. if (child) {
  510. if (child->pktsize == 4)
  511. priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
  512. else
  513. priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
  514. if (synaptics_mode_cmd(psmouse, priv->mode))
  515. psmouse_warn(psmouse,
  516. "failed to switch guest protocol\n");
  517. }
  518. }
  519. static void synaptics_pt_create(struct psmouse *psmouse)
  520. {
  521. struct serio *serio;
  522. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  523. if (!serio) {
  524. psmouse_err(psmouse,
  525. "not enough memory for pass-through port\n");
  526. return;
  527. }
  528. serio->id.type = SERIO_PS_PSTHRU;
  529. strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
  530. strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
  531. serio->write = synaptics_pt_write;
  532. serio->start = synaptics_pt_start;
  533. serio->stop = synaptics_pt_stop;
  534. serio->parent = psmouse->ps2dev.serio;
  535. psmouse->pt_activate = synaptics_pt_activate;
  536. psmouse_info(psmouse, "serio: %s port at %s\n",
  537. serio->name, psmouse->phys);
  538. serio_register_port(serio);
  539. }
  540. /*****************************************************************************
  541. * Functions to interpret the absolute mode packets
  542. ****************************************************************************/
  543. static void synaptics_mt_state_set(struct synaptics_mt_state *state, int count,
  544. int sgm, int agm)
  545. {
  546. state->count = count;
  547. state->sgm = sgm;
  548. state->agm = agm;
  549. }
  550. static void synaptics_parse_agm(const unsigned char buf[],
  551. struct synaptics_data *priv,
  552. struct synaptics_hw_state *hw)
  553. {
  554. struct synaptics_hw_state *agm = &priv->agm;
  555. int agm_packet_type;
  556. agm_packet_type = (buf[5] & 0x30) >> 4;
  557. switch (agm_packet_type) {
  558. case 1:
  559. /* Gesture packet: (x, y, z) half resolution */
  560. agm->w = hw->w;
  561. agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
  562. agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
  563. agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
  564. break;
  565. case 2:
  566. /* AGM-CONTACT packet: (count, sgm, agm) */
  567. synaptics_mt_state_set(&agm->mt_state, buf[1], buf[2], buf[4]);
  568. break;
  569. default:
  570. break;
  571. }
  572. /* Record that at least one AGM has been received since last SGM */
  573. priv->agm_pending = true;
  574. }
  575. static void synaptics_parse_ext_buttons(const unsigned char buf[],
  576. struct synaptics_data *priv,
  577. struct synaptics_hw_state *hw)
  578. {
  579. unsigned int ext_bits =
  580. (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) + 1) >> 1;
  581. unsigned int ext_mask = GENMASK(ext_bits - 1, 0);
  582. hw->ext_buttons = buf[4] & ext_mask;
  583. hw->ext_buttons |= (buf[5] & ext_mask) << ext_bits;
  584. }
  585. static bool is_forcepad;
  586. static int synaptics_parse_hw_state(const unsigned char buf[],
  587. struct synaptics_data *priv,
  588. struct synaptics_hw_state *hw)
  589. {
  590. memset(hw, 0, sizeof(struct synaptics_hw_state));
  591. if (SYN_MODEL_NEWABS(priv->model_id)) {
  592. hw->w = (((buf[0] & 0x30) >> 2) |
  593. ((buf[0] & 0x04) >> 1) |
  594. ((buf[3] & 0x04) >> 2));
  595. if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
  596. SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
  597. hw->w == 2) {
  598. synaptics_parse_agm(buf, priv, hw);
  599. return 1;
  600. }
  601. hw->x = (((buf[3] & 0x10) << 8) |
  602. ((buf[1] & 0x0f) << 8) |
  603. buf[4]);
  604. hw->y = (((buf[3] & 0x20) << 7) |
  605. ((buf[1] & 0xf0) << 4) |
  606. buf[5]);
  607. hw->z = buf[2];
  608. hw->left = (buf[0] & 0x01) ? 1 : 0;
  609. hw->right = (buf[0] & 0x02) ? 1 : 0;
  610. if (is_forcepad) {
  611. /*
  612. * ForcePads, like Clickpads, use middle button
  613. * bits to report primary button clicks.
  614. * Unfortunately they report primary button not
  615. * only when user presses on the pad above certain
  616. * threshold, but also when there are more than one
  617. * finger on the touchpad, which interferes with
  618. * out multi-finger gestures.
  619. */
  620. if (hw->z == 0) {
  621. /* No contacts */
  622. priv->press = priv->report_press = false;
  623. } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
  624. /*
  625. * Single-finger touch with pressure above
  626. * the threshold. If pressure stays long
  627. * enough, we'll start reporting primary
  628. * button. We rely on the device continuing
  629. * sending data even if finger does not
  630. * move.
  631. */
  632. if (!priv->press) {
  633. priv->press_start = jiffies;
  634. priv->press = true;
  635. } else if (time_after(jiffies,
  636. priv->press_start +
  637. msecs_to_jiffies(50))) {
  638. priv->report_press = true;
  639. }
  640. } else {
  641. priv->press = false;
  642. }
  643. hw->left = priv->report_press;
  644. } else if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  645. /*
  646. * Clickpad's button is transmitted as middle button,
  647. * however, since it is primary button, we will report
  648. * it as BTN_LEFT.
  649. */
  650. hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  651. } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  652. hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  653. if (hw->w == 2)
  654. hw->scroll = (signed char)(buf[1]);
  655. }
  656. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  657. hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  658. hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
  659. }
  660. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 0 &&
  661. ((buf[0] ^ buf[3]) & 0x02)) {
  662. synaptics_parse_ext_buttons(buf, priv, hw);
  663. }
  664. } else {
  665. hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
  666. hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
  667. hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
  668. hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
  669. hw->left = (buf[0] & 0x01) ? 1 : 0;
  670. hw->right = (buf[0] & 0x02) ? 1 : 0;
  671. }
  672. /*
  673. * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE
  674. * is used by some firmware to indicate a finger at the edge of
  675. * the touchpad whose precise position cannot be determined, so
  676. * convert these values to the maximum axis value.
  677. */
  678. if (hw->x > X_MAX_POSITIVE)
  679. hw->x -= 1 << ABS_POS_BITS;
  680. else if (hw->x == X_MAX_POSITIVE)
  681. hw->x = XMAX;
  682. if (hw->y > Y_MAX_POSITIVE)
  683. hw->y -= 1 << ABS_POS_BITS;
  684. else if (hw->y == Y_MAX_POSITIVE)
  685. hw->y = YMAX;
  686. return 0;
  687. }
  688. static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
  689. bool active, int x, int y)
  690. {
  691. input_mt_slot(dev, slot);
  692. input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
  693. if (active) {
  694. input_report_abs(dev, ABS_MT_POSITION_X, x);
  695. input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
  696. }
  697. }
  698. static void synaptics_report_semi_mt_data(struct input_dev *dev,
  699. const struct synaptics_hw_state *a,
  700. const struct synaptics_hw_state *b,
  701. int num_fingers)
  702. {
  703. if (num_fingers >= 2) {
  704. synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
  705. min(a->y, b->y));
  706. synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
  707. max(a->y, b->y));
  708. } else if (num_fingers == 1) {
  709. synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
  710. synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
  711. } else {
  712. synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
  713. synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
  714. }
  715. }
  716. static void synaptics_report_ext_buttons(struct psmouse *psmouse,
  717. const struct synaptics_hw_state *hw)
  718. {
  719. struct input_dev *dev = psmouse->dev;
  720. struct synaptics_data *priv = psmouse->private;
  721. int ext_bits = (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) + 1) >> 1;
  722. int i;
  723. if (!SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap))
  724. return;
  725. /* Bug in FW 8.1, buttons are reported only when ExtBit is 1 */
  726. if (SYN_ID_FULL(priv->identity) == 0x801 &&
  727. !((psmouse->packet[0] ^ psmouse->packet[3]) & 0x02))
  728. return;
  729. for (i = 0; i < ext_bits; i++) {
  730. input_report_key(dev, BTN_0 + 2 * i,
  731. hw->ext_buttons & (1 << i));
  732. input_report_key(dev, BTN_1 + 2 * i,
  733. hw->ext_buttons & (1 << (i + ext_bits)));
  734. }
  735. }
  736. static void synaptics_report_buttons(struct psmouse *psmouse,
  737. const struct synaptics_hw_state *hw)
  738. {
  739. struct input_dev *dev = psmouse->dev;
  740. struct synaptics_data *priv = psmouse->private;
  741. input_report_key(dev, BTN_LEFT, hw->left);
  742. input_report_key(dev, BTN_RIGHT, hw->right);
  743. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  744. input_report_key(dev, BTN_MIDDLE, hw->middle);
  745. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  746. input_report_key(dev, BTN_FORWARD, hw->up);
  747. input_report_key(dev, BTN_BACK, hw->down);
  748. }
  749. synaptics_report_ext_buttons(psmouse, hw);
  750. }
  751. static void synaptics_report_slot(struct input_dev *dev, int slot,
  752. const struct synaptics_hw_state *hw)
  753. {
  754. input_mt_slot(dev, slot);
  755. input_mt_report_slot_state(dev, MT_TOOL_FINGER, (hw != NULL));
  756. if (!hw)
  757. return;
  758. input_report_abs(dev, ABS_MT_POSITION_X, hw->x);
  759. input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(hw->y));
  760. input_report_abs(dev, ABS_MT_PRESSURE, hw->z);
  761. }
  762. static void synaptics_report_mt_data(struct psmouse *psmouse,
  763. struct synaptics_mt_state *mt_state,
  764. const struct synaptics_hw_state *sgm)
  765. {
  766. struct input_dev *dev = psmouse->dev;
  767. struct synaptics_data *priv = psmouse->private;
  768. struct synaptics_hw_state *agm = &priv->agm;
  769. struct synaptics_mt_state *old = &priv->mt_state;
  770. switch (mt_state->count) {
  771. case 0:
  772. synaptics_report_slot(dev, 0, NULL);
  773. synaptics_report_slot(dev, 1, NULL);
  774. break;
  775. case 1:
  776. if (mt_state->sgm == -1) {
  777. synaptics_report_slot(dev, 0, NULL);
  778. synaptics_report_slot(dev, 1, NULL);
  779. } else if (mt_state->sgm == 0) {
  780. synaptics_report_slot(dev, 0, sgm);
  781. synaptics_report_slot(dev, 1, NULL);
  782. } else {
  783. synaptics_report_slot(dev, 0, NULL);
  784. synaptics_report_slot(dev, 1, sgm);
  785. }
  786. break;
  787. default:
  788. /*
  789. * If the finger slot contained in SGM is valid, and either
  790. * hasn't changed, or is new, or the old SGM has now moved to
  791. * AGM, then report SGM in MTB slot 0.
  792. * Otherwise, empty MTB slot 0.
  793. */
  794. if (mt_state->sgm != -1 &&
  795. (mt_state->sgm == old->sgm ||
  796. old->sgm == -1 || mt_state->agm == old->sgm))
  797. synaptics_report_slot(dev, 0, sgm);
  798. else
  799. synaptics_report_slot(dev, 0, NULL);
  800. /*
  801. * If the finger slot contained in AGM is valid, and either
  802. * hasn't changed, or is new, then report AGM in MTB slot 1.
  803. * Otherwise, empty MTB slot 1.
  804. *
  805. * However, in the case where the AGM is new, make sure that
  806. * that it is either the same as the old SGM, or there was no
  807. * SGM.
  808. *
  809. * Otherwise, if the SGM was just 1, and the new AGM is 2, then
  810. * the new AGM will keep the old SGM's tracking ID, which can
  811. * cause apparent drumroll. This happens if in the following
  812. * valid finger sequence:
  813. *
  814. * Action SGM AGM (MTB slot:Contact)
  815. * 1. Touch contact 0 (0:0)
  816. * 2. Touch contact 1 (0:0, 1:1)
  817. * 3. Lift contact 0 (1:1)
  818. * 4. Touch contacts 2,3 (0:2, 1:3)
  819. *
  820. * In step 4, contact 3, in AGM must not be given the same
  821. * tracking ID as contact 1 had in step 3. To avoid this,
  822. * the first agm with contact 3 is dropped and slot 1 is
  823. * invalidated (tracking ID = -1).
  824. */
  825. if (mt_state->agm != -1 &&
  826. (mt_state->agm == old->agm ||
  827. (old->agm == -1 &&
  828. (old->sgm == -1 || mt_state->agm == old->sgm))))
  829. synaptics_report_slot(dev, 1, agm);
  830. else
  831. synaptics_report_slot(dev, 1, NULL);
  832. break;
  833. }
  834. /* Don't use active slot count to generate BTN_TOOL events. */
  835. input_mt_report_pointer_emulation(dev, false);
  836. /* Send the number of fingers reported by touchpad itself. */
  837. input_mt_report_finger_count(dev, mt_state->count);
  838. synaptics_report_buttons(psmouse, sgm);
  839. input_sync(dev);
  840. }
  841. /* Handle case where mt_state->count = 0 */
  842. static void synaptics_image_sensor_0f(struct synaptics_data *priv,
  843. struct synaptics_mt_state *mt_state)
  844. {
  845. synaptics_mt_state_set(mt_state, 0, -1, -1);
  846. priv->mt_state_lost = false;
  847. }
  848. /* Handle case where mt_state->count = 1 */
  849. static void synaptics_image_sensor_1f(struct synaptics_data *priv,
  850. struct synaptics_mt_state *mt_state)
  851. {
  852. struct synaptics_hw_state *agm = &priv->agm;
  853. struct synaptics_mt_state *old = &priv->mt_state;
  854. /*
  855. * If the last AGM was (0,0,0), and there is only one finger left,
  856. * then we absolutely know that SGM contains slot 0, and all other
  857. * fingers have been removed.
  858. */
  859. if (priv->agm_pending && agm->z == 0) {
  860. synaptics_mt_state_set(mt_state, 1, 0, -1);
  861. priv->mt_state_lost = false;
  862. return;
  863. }
  864. switch (old->count) {
  865. case 0:
  866. synaptics_mt_state_set(mt_state, 1, 0, -1);
  867. break;
  868. case 1:
  869. /*
  870. * If mt_state_lost, then the previous transition was 3->1,
  871. * and SGM now contains either slot 0 or 1, but we don't know
  872. * which. So, we just assume that the SGM now contains slot 1.
  873. *
  874. * If pending AGM and either:
  875. * (a) the previous SGM slot contains slot 0, or
  876. * (b) there was no SGM slot
  877. * then, the SGM now contains slot 1
  878. *
  879. * Case (a) happens with very rapid "drum roll" gestures, where
  880. * slot 0 finger is lifted and a new slot 1 finger touches
  881. * within one reporting interval.
  882. *
  883. * Case (b) happens if initially two or more fingers tap
  884. * briefly, and all but one lift before the end of the first
  885. * reporting interval.
  886. *
  887. * (In both these cases, slot 0 will becomes empty, so SGM
  888. * contains slot 1 with the new finger)
  889. *
  890. * Else, if there was no previous SGM, it now contains slot 0.
  891. *
  892. * Otherwise, SGM still contains the same slot.
  893. */
  894. if (priv->mt_state_lost ||
  895. (priv->agm_pending && old->sgm <= 0))
  896. synaptics_mt_state_set(mt_state, 1, 1, -1);
  897. else if (old->sgm == -1)
  898. synaptics_mt_state_set(mt_state, 1, 0, -1);
  899. break;
  900. case 2:
  901. /*
  902. * If mt_state_lost, we don't know which finger SGM contains.
  903. *
  904. * So, report 1 finger, but with both slots empty.
  905. * We will use slot 1 on subsequent 1->1
  906. */
  907. if (priv->mt_state_lost) {
  908. synaptics_mt_state_set(mt_state, 1, -1, -1);
  909. break;
  910. }
  911. /*
  912. * Since the last AGM was NOT (0,0,0), it was the finger in
  913. * slot 0 that has been removed.
  914. * So, SGM now contains previous AGM's slot, and AGM is now
  915. * empty.
  916. */
  917. synaptics_mt_state_set(mt_state, 1, old->agm, -1);
  918. break;
  919. case 3:
  920. /*
  921. * Since last AGM was not (0,0,0), we don't know which finger
  922. * is left.
  923. *
  924. * So, report 1 finger, but with both slots empty.
  925. * We will use slot 1 on subsequent 1->1
  926. */
  927. synaptics_mt_state_set(mt_state, 1, -1, -1);
  928. priv->mt_state_lost = true;
  929. break;
  930. case 4:
  931. case 5:
  932. /* mt_state was updated by AGM-CONTACT packet */
  933. break;
  934. }
  935. }
  936. /* Handle case where mt_state->count = 2 */
  937. static void synaptics_image_sensor_2f(struct synaptics_data *priv,
  938. struct synaptics_mt_state *mt_state)
  939. {
  940. struct synaptics_mt_state *old = &priv->mt_state;
  941. switch (old->count) {
  942. case 0:
  943. synaptics_mt_state_set(mt_state, 2, 0, 1);
  944. break;
  945. case 1:
  946. /*
  947. * If previous SGM contained slot 1 or higher, SGM now contains
  948. * slot 0 (the newly touching finger) and AGM contains SGM's
  949. * previous slot.
  950. *
  951. * Otherwise, SGM still contains slot 0 and AGM now contains
  952. * slot 1.
  953. */
  954. if (old->sgm >= 1)
  955. synaptics_mt_state_set(mt_state, 2, 0, old->sgm);
  956. else
  957. synaptics_mt_state_set(mt_state, 2, 0, 1);
  958. break;
  959. case 2:
  960. /*
  961. * If mt_state_lost, SGM now contains either finger 1 or 2, but
  962. * we don't know which.
  963. * So, we just assume that the SGM contains slot 0 and AGM 1.
  964. */
  965. if (priv->mt_state_lost)
  966. synaptics_mt_state_set(mt_state, 2, 0, 1);
  967. /*
  968. * Otherwise, use the same mt_state, since it either hasn't
  969. * changed, or was updated by a recently received AGM-CONTACT
  970. * packet.
  971. */
  972. break;
  973. case 3:
  974. /*
  975. * 3->2 transitions have two unsolvable problems:
  976. * 1) no indication is given which finger was removed
  977. * 2) no way to tell if agm packet was for finger 3
  978. * before 3->2, or finger 2 after 3->2.
  979. *
  980. * So, report 2 fingers, but empty all slots.
  981. * We will guess slots [0,1] on subsequent 2->2.
  982. */
  983. synaptics_mt_state_set(mt_state, 2, -1, -1);
  984. priv->mt_state_lost = true;
  985. break;
  986. case 4:
  987. case 5:
  988. /* mt_state was updated by AGM-CONTACT packet */
  989. break;
  990. }
  991. }
  992. /* Handle case where mt_state->count = 3 */
  993. static void synaptics_image_sensor_3f(struct synaptics_data *priv,
  994. struct synaptics_mt_state *mt_state)
  995. {
  996. struct synaptics_mt_state *old = &priv->mt_state;
  997. switch (old->count) {
  998. case 0:
  999. synaptics_mt_state_set(mt_state, 3, 0, 2);
  1000. break;
  1001. case 1:
  1002. /*
  1003. * If previous SGM contained slot 2 or higher, SGM now contains
  1004. * slot 0 (one of the newly touching fingers) and AGM contains
  1005. * SGM's previous slot.
  1006. *
  1007. * Otherwise, SGM now contains slot 0 and AGM contains slot 2.
  1008. */
  1009. if (old->sgm >= 2)
  1010. synaptics_mt_state_set(mt_state, 3, 0, old->sgm);
  1011. else
  1012. synaptics_mt_state_set(mt_state, 3, 0, 2);
  1013. break;
  1014. case 2:
  1015. /*
  1016. * If the AGM previously contained slot 3 or higher, then the
  1017. * newly touching finger is in the lowest available slot.
  1018. *
  1019. * If SGM was previously 1 or higher, then the new SGM is
  1020. * now slot 0 (with a new finger), otherwise, the new finger
  1021. * is now in a hidden slot between 0 and AGM's slot.
  1022. *
  1023. * In all such cases, the SGM now contains slot 0, and the AGM
  1024. * continues to contain the same slot as before.
  1025. */
  1026. if (old->agm >= 3) {
  1027. synaptics_mt_state_set(mt_state, 3, 0, old->agm);
  1028. break;
  1029. }
  1030. /*
  1031. * After some 3->1 and all 3->2 transitions, we lose track
  1032. * of which slot is reported by SGM and AGM.
  1033. *
  1034. * For 2->3 in this state, report 3 fingers, but empty all
  1035. * slots, and we will guess (0,2) on a subsequent 0->3.
  1036. *
  1037. * To userspace, the resulting transition will look like:
  1038. * 2:[0,1] -> 3:[-1,-1] -> 3:[0,2]
  1039. */
  1040. if (priv->mt_state_lost) {
  1041. synaptics_mt_state_set(mt_state, 3, -1, -1);
  1042. break;
  1043. }
  1044. /*
  1045. * If the (SGM,AGM) really previously contained slots (0, 1),
  1046. * then we cannot know what slot was just reported by the AGM,
  1047. * because the 2->3 transition can occur either before or after
  1048. * the AGM packet. Thus, this most recent AGM could contain
  1049. * either the same old slot 1 or the new slot 2.
  1050. * Subsequent AGMs will be reporting slot 2.
  1051. *
  1052. * To userspace, the resulting transition will look like:
  1053. * 2:[0,1] -> 3:[0,-1] -> 3:[0,2]
  1054. */
  1055. synaptics_mt_state_set(mt_state, 3, 0, -1);
  1056. break;
  1057. case 3:
  1058. /*
  1059. * If, for whatever reason, the previous agm was invalid,
  1060. * Assume SGM now contains slot 0, AGM now contains slot 2.
  1061. */
  1062. if (old->agm <= 2)
  1063. synaptics_mt_state_set(mt_state, 3, 0, 2);
  1064. /*
  1065. * mt_state either hasn't changed, or was updated by a recently
  1066. * received AGM-CONTACT packet.
  1067. */
  1068. break;
  1069. case 4:
  1070. case 5:
  1071. /* mt_state was updated by AGM-CONTACT packet */
  1072. break;
  1073. }
  1074. }
  1075. /* Handle case where mt_state->count = 4, or = 5 */
  1076. static void synaptics_image_sensor_45f(struct synaptics_data *priv,
  1077. struct synaptics_mt_state *mt_state)
  1078. {
  1079. /* mt_state was updated correctly by AGM-CONTACT packet */
  1080. priv->mt_state_lost = false;
  1081. }
  1082. static void synaptics_image_sensor_process(struct psmouse *psmouse,
  1083. struct synaptics_hw_state *sgm)
  1084. {
  1085. struct synaptics_data *priv = psmouse->private;
  1086. struct synaptics_hw_state *agm = &priv->agm;
  1087. struct synaptics_mt_state mt_state;
  1088. /* Initialize using current mt_state (as updated by last agm) */
  1089. mt_state = agm->mt_state;
  1090. /*
  1091. * Update mt_state using the new finger count and current mt_state.
  1092. */
  1093. if (sgm->z == 0)
  1094. synaptics_image_sensor_0f(priv, &mt_state);
  1095. else if (sgm->w >= 4)
  1096. synaptics_image_sensor_1f(priv, &mt_state);
  1097. else if (sgm->w == 0)
  1098. synaptics_image_sensor_2f(priv, &mt_state);
  1099. else if (sgm->w == 1 && mt_state.count <= 3)
  1100. synaptics_image_sensor_3f(priv, &mt_state);
  1101. else
  1102. synaptics_image_sensor_45f(priv, &mt_state);
  1103. /* Send resulting input events to user space */
  1104. synaptics_report_mt_data(psmouse, &mt_state, sgm);
  1105. /* Store updated mt_state */
  1106. priv->mt_state = agm->mt_state = mt_state;
  1107. priv->agm_pending = false;
  1108. }
  1109. static void synaptics_profile_sensor_process(struct psmouse *psmouse,
  1110. struct synaptics_hw_state *sgm,
  1111. int num_fingers)
  1112. {
  1113. struct input_dev *dev = psmouse->dev;
  1114. struct synaptics_data *priv = psmouse->private;
  1115. struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
  1116. struct input_mt_pos pos[2];
  1117. int slot[2], nsemi, i;
  1118. nsemi = clamp_val(num_fingers, 0, 2);
  1119. for (i = 0; i < nsemi; i++) {
  1120. pos[i].x = hw[i]->x;
  1121. pos[i].y = synaptics_invert_y(hw[i]->y);
  1122. }
  1123. input_mt_assign_slots(dev, slot, pos, nsemi);
  1124. for (i = 0; i < nsemi; i++) {
  1125. input_mt_slot(dev, slot[i]);
  1126. input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
  1127. input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
  1128. input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
  1129. input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
  1130. }
  1131. input_mt_drop_unused(dev);
  1132. input_mt_report_pointer_emulation(dev, false);
  1133. input_mt_report_finger_count(dev, num_fingers);
  1134. synaptics_report_buttons(psmouse, sgm);
  1135. input_sync(dev);
  1136. }
  1137. /*
  1138. * called for each full received packet from the touchpad
  1139. */
  1140. static void synaptics_process_packet(struct psmouse *psmouse)
  1141. {
  1142. struct input_dev *dev = psmouse->dev;
  1143. struct synaptics_data *priv = psmouse->private;
  1144. struct synaptics_hw_state hw;
  1145. int num_fingers;
  1146. int finger_width;
  1147. if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
  1148. return;
  1149. if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
  1150. synaptics_image_sensor_process(psmouse, &hw);
  1151. return;
  1152. }
  1153. if (hw.scroll) {
  1154. priv->scroll += hw.scroll;
  1155. while (priv->scroll >= 4) {
  1156. input_report_key(dev, BTN_BACK, !hw.down);
  1157. input_sync(dev);
  1158. input_report_key(dev, BTN_BACK, hw.down);
  1159. input_sync(dev);
  1160. priv->scroll -= 4;
  1161. }
  1162. while (priv->scroll <= -4) {
  1163. input_report_key(dev, BTN_FORWARD, !hw.up);
  1164. input_sync(dev);
  1165. input_report_key(dev, BTN_FORWARD, hw.up);
  1166. input_sync(dev);
  1167. priv->scroll += 4;
  1168. }
  1169. return;
  1170. }
  1171. if (hw.z > 0 && hw.x > 1) {
  1172. num_fingers = 1;
  1173. finger_width = 5;
  1174. if (SYN_CAP_EXTENDED(priv->capabilities)) {
  1175. switch (hw.w) {
  1176. case 0 ... 1:
  1177. if (SYN_CAP_MULTIFINGER(priv->capabilities))
  1178. num_fingers = hw.w + 2;
  1179. break;
  1180. case 2:
  1181. if (SYN_MODEL_PEN(priv->model_id))
  1182. ; /* Nothing, treat a pen as a single finger */
  1183. break;
  1184. case 4 ... 15:
  1185. if (SYN_CAP_PALMDETECT(priv->capabilities))
  1186. finger_width = hw.w;
  1187. break;
  1188. }
  1189. }
  1190. } else {
  1191. num_fingers = 0;
  1192. finger_width = 0;
  1193. }
  1194. if (cr48_profile_sensor) {
  1195. synaptics_profile_sensor_process(psmouse, &hw, num_fingers);
  1196. return;
  1197. }
  1198. if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
  1199. synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
  1200. num_fingers);
  1201. /* Post events
  1202. * BTN_TOUCH has to be first as mousedev relies on it when doing
  1203. * absolute -> relative conversion
  1204. */
  1205. if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
  1206. if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
  1207. if (num_fingers > 0) {
  1208. input_report_abs(dev, ABS_X, hw.x);
  1209. input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
  1210. }
  1211. input_report_abs(dev, ABS_PRESSURE, hw.z);
  1212. if (SYN_CAP_PALMDETECT(priv->capabilities))
  1213. input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
  1214. input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
  1215. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  1216. input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
  1217. input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
  1218. }
  1219. synaptics_report_buttons(psmouse, &hw);
  1220. input_sync(dev);
  1221. }
  1222. static int synaptics_validate_byte(struct psmouse *psmouse,
  1223. int idx, unsigned char pkt_type)
  1224. {
  1225. static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
  1226. static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
  1227. static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
  1228. static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
  1229. static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
  1230. const char *packet = psmouse->packet;
  1231. if (idx < 0 || idx > 4)
  1232. return 0;
  1233. switch (pkt_type) {
  1234. case SYN_NEWABS:
  1235. case SYN_NEWABS_RELAXED:
  1236. return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
  1237. case SYN_NEWABS_STRICT:
  1238. return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
  1239. case SYN_OLDABS:
  1240. return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
  1241. default:
  1242. psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
  1243. return 0;
  1244. }
  1245. }
  1246. static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
  1247. {
  1248. int i;
  1249. for (i = 0; i < 5; i++)
  1250. if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
  1251. psmouse_info(psmouse, "using relaxed packet validation\n");
  1252. return SYN_NEWABS_RELAXED;
  1253. }
  1254. return SYN_NEWABS_STRICT;
  1255. }
  1256. static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
  1257. {
  1258. struct synaptics_data *priv = psmouse->private;
  1259. if (psmouse->pktcnt >= 6) { /* Full packet received */
  1260. if (unlikely(priv->pkt_type == SYN_NEWABS))
  1261. priv->pkt_type = synaptics_detect_pkt_type(psmouse);
  1262. if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
  1263. synaptics_is_pt_packet(psmouse->packet)) {
  1264. if (priv->pt_port)
  1265. synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
  1266. } else
  1267. synaptics_process_packet(psmouse);
  1268. return PSMOUSE_FULL_PACKET;
  1269. }
  1270. return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
  1271. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  1272. }
  1273. /*****************************************************************************
  1274. * Driver initialization/cleanup functions
  1275. ****************************************************************************/
  1276. static void set_abs_position_params(struct input_dev *dev,
  1277. struct synaptics_data *priv, int x_code,
  1278. int y_code)
  1279. {
  1280. int x_min = priv->x_min ?: XMIN_NOMINAL;
  1281. int x_max = priv->x_max ?: XMAX_NOMINAL;
  1282. int y_min = priv->y_min ?: YMIN_NOMINAL;
  1283. int y_max = priv->y_max ?: YMAX_NOMINAL;
  1284. int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
  1285. SYN_REDUCED_FILTER_FUZZ : 0;
  1286. input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
  1287. input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
  1288. input_abs_set_res(dev, x_code, priv->x_res);
  1289. input_abs_set_res(dev, y_code, priv->y_res);
  1290. }
  1291. static void set_input_params(struct psmouse *psmouse,
  1292. struct synaptics_data *priv)
  1293. {
  1294. struct input_dev *dev = psmouse->dev;
  1295. int i;
  1296. /* Things that apply to both modes */
  1297. __set_bit(INPUT_PROP_POINTER, dev->propbit);
  1298. __set_bit(EV_KEY, dev->evbit);
  1299. __set_bit(BTN_LEFT, dev->keybit);
  1300. __set_bit(BTN_RIGHT, dev->keybit);
  1301. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  1302. __set_bit(BTN_MIDDLE, dev->keybit);
  1303. if (!priv->absolute_mode) {
  1304. /* Relative mode */
  1305. __set_bit(EV_REL, dev->evbit);
  1306. __set_bit(REL_X, dev->relbit);
  1307. __set_bit(REL_Y, dev->relbit);
  1308. return;
  1309. }
  1310. /* Absolute mode */
  1311. __set_bit(EV_ABS, dev->evbit);
  1312. set_abs_position_params(dev, priv, ABS_X, ABS_Y);
  1313. input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
  1314. if (cr48_profile_sensor)
  1315. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1316. if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
  1317. set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
  1318. ABS_MT_POSITION_Y);
  1319. /* Image sensors can report per-contact pressure */
  1320. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1321. input_mt_init_slots(dev, 2, INPUT_MT_POINTER);
  1322. /* Image sensors can signal 4 and 5 finger clicks */
  1323. __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
  1324. __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
  1325. } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
  1326. set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
  1327. ABS_MT_POSITION_Y);
  1328. /*
  1329. * Profile sensor in CR-48 tracks contacts reasonably well,
  1330. * other non-image sensors with AGM use semi-mt.
  1331. */
  1332. input_mt_init_slots(dev, 2,
  1333. INPUT_MT_POINTER |
  1334. (cr48_profile_sensor ?
  1335. INPUT_MT_TRACK : INPUT_MT_SEMI_MT));
  1336. }
  1337. if (SYN_CAP_PALMDETECT(priv->capabilities))
  1338. input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
  1339. __set_bit(BTN_TOUCH, dev->keybit);
  1340. __set_bit(BTN_TOOL_FINGER, dev->keybit);
  1341. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  1342. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  1343. __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
  1344. }
  1345. if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
  1346. SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  1347. __set_bit(BTN_FORWARD, dev->keybit);
  1348. __set_bit(BTN_BACK, dev->keybit);
  1349. }
  1350. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
  1351. __set_bit(BTN_0 + i, dev->keybit);
  1352. __clear_bit(EV_REL, dev->evbit);
  1353. __clear_bit(REL_X, dev->relbit);
  1354. __clear_bit(REL_Y, dev->relbit);
  1355. if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  1356. __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
  1357. if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids))
  1358. __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
  1359. /* Clickpads report only left button */
  1360. __clear_bit(BTN_RIGHT, dev->keybit);
  1361. __clear_bit(BTN_MIDDLE, dev->keybit);
  1362. }
  1363. }
  1364. static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
  1365. void *data, char *buf)
  1366. {
  1367. struct synaptics_data *priv = psmouse->private;
  1368. return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
  1369. }
  1370. static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
  1371. void *data, const char *buf,
  1372. size_t len)
  1373. {
  1374. struct synaptics_data *priv = psmouse->private;
  1375. unsigned int value;
  1376. int err;
  1377. err = kstrtouint(buf, 10, &value);
  1378. if (err)
  1379. return err;
  1380. if (value > 1)
  1381. return -EINVAL;
  1382. if (value == priv->disable_gesture)
  1383. return len;
  1384. priv->disable_gesture = value;
  1385. if (value)
  1386. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  1387. else
  1388. priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
  1389. if (synaptics_mode_cmd(psmouse, priv->mode))
  1390. return -EIO;
  1391. return len;
  1392. }
  1393. PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
  1394. synaptics_show_disable_gesture,
  1395. synaptics_set_disable_gesture);
  1396. static void synaptics_disconnect(struct psmouse *psmouse)
  1397. {
  1398. struct synaptics_data *priv = psmouse->private;
  1399. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity))
  1400. device_remove_file(&psmouse->ps2dev.serio->dev,
  1401. &psmouse_attr_disable_gesture.dattr);
  1402. synaptics_reset(psmouse);
  1403. kfree(priv);
  1404. psmouse->private = NULL;
  1405. }
  1406. static int synaptics_reconnect(struct psmouse *psmouse)
  1407. {
  1408. struct synaptics_data *priv = psmouse->private;
  1409. struct synaptics_data old_priv = *priv;
  1410. unsigned char param[2];
  1411. int retry = 0;
  1412. int error;
  1413. do {
  1414. psmouse_reset(psmouse);
  1415. if (retry) {
  1416. /*
  1417. * On some boxes, right after resuming, the touchpad
  1418. * needs some time to finish initializing (I assume
  1419. * it needs time to calibrate) and start responding
  1420. * to Synaptics-specific queries, so let's wait a
  1421. * bit.
  1422. */
  1423. ssleep(1);
  1424. }
  1425. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
  1426. error = synaptics_detect(psmouse, 0);
  1427. } while (error && ++retry < 3);
  1428. if (error)
  1429. return -1;
  1430. if (retry > 1)
  1431. psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
  1432. if (synaptics_query_hardware(psmouse)) {
  1433. psmouse_err(psmouse, "Unable to query device.\n");
  1434. return -1;
  1435. }
  1436. if (synaptics_set_mode(psmouse)) {
  1437. psmouse_err(psmouse, "Unable to initialize device.\n");
  1438. return -1;
  1439. }
  1440. if (old_priv.identity != priv->identity ||
  1441. old_priv.model_id != priv->model_id ||
  1442. old_priv.capabilities != priv->capabilities ||
  1443. old_priv.ext_cap != priv->ext_cap) {
  1444. psmouse_err(psmouse,
  1445. "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
  1446. old_priv.identity, priv->identity,
  1447. old_priv.model_id, priv->model_id,
  1448. old_priv.capabilities, priv->capabilities,
  1449. old_priv.ext_cap, priv->ext_cap);
  1450. return -1;
  1451. }
  1452. return 0;
  1453. }
  1454. static bool impaired_toshiba_kbc;
  1455. static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
  1456. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1457. {
  1458. /* Toshiba Satellite */
  1459. .matches = {
  1460. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1461. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  1462. },
  1463. },
  1464. {
  1465. /* Toshiba Dynabook */
  1466. .matches = {
  1467. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1468. DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
  1469. },
  1470. },
  1471. {
  1472. /* Toshiba Portege M300 */
  1473. .matches = {
  1474. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1475. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
  1476. },
  1477. },
  1478. {
  1479. /* Toshiba Portege M300 */
  1480. .matches = {
  1481. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1482. DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
  1483. DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
  1484. },
  1485. },
  1486. #endif
  1487. { }
  1488. };
  1489. static bool broken_olpc_ec;
  1490. static const struct dmi_system_id olpc_dmi_table[] __initconst = {
  1491. #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
  1492. {
  1493. /* OLPC XO-1 or XO-1.5 */
  1494. .matches = {
  1495. DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
  1496. DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
  1497. },
  1498. },
  1499. #endif
  1500. { }
  1501. };
  1502. static const struct dmi_system_id __initconst cr48_dmi_table[] = {
  1503. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1504. {
  1505. /* Cr-48 Chromebook (Codename Mario) */
  1506. .matches = {
  1507. DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
  1508. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  1509. },
  1510. },
  1511. #endif
  1512. { }
  1513. };
  1514. static const struct dmi_system_id forcepad_dmi_table[] __initconst = {
  1515. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1516. {
  1517. .matches = {
  1518. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1519. DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook Folio 1040 G1"),
  1520. },
  1521. },
  1522. #endif
  1523. { }
  1524. };
  1525. void __init synaptics_module_init(void)
  1526. {
  1527. impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
  1528. broken_olpc_ec = dmi_check_system(olpc_dmi_table);
  1529. cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
  1530. /*
  1531. * Unfortunately ForcePad capability is not exported over PS/2,
  1532. * so we have to resort to checking DMI.
  1533. */
  1534. is_forcepad = dmi_check_system(forcepad_dmi_table);
  1535. }
  1536. static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
  1537. {
  1538. struct synaptics_data *priv;
  1539. int err = -1;
  1540. /*
  1541. * The OLPC XO has issues with Synaptics' absolute mode; the constant
  1542. * packet spew overloads the EC such that key presses on the keyboard
  1543. * are missed. Given that, don't even attempt to use Absolute mode.
  1544. * Relative mode seems to work just fine.
  1545. */
  1546. if (absolute_mode && broken_olpc_ec) {
  1547. psmouse_info(psmouse,
  1548. "OLPC XO detected, not enabling Synaptics protocol.\n");
  1549. return -ENODEV;
  1550. }
  1551. psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
  1552. if (!priv)
  1553. return -ENOMEM;
  1554. psmouse_reset(psmouse);
  1555. if (synaptics_query_hardware(psmouse)) {
  1556. psmouse_err(psmouse, "Unable to query device.\n");
  1557. goto init_fail;
  1558. }
  1559. priv->absolute_mode = absolute_mode;
  1560. if (SYN_ID_DISGEST_SUPPORTED(priv->identity))
  1561. priv->disable_gesture = true;
  1562. if (synaptics_set_mode(psmouse)) {
  1563. psmouse_err(psmouse, "Unable to initialize device.\n");
  1564. goto init_fail;
  1565. }
  1566. priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
  1567. psmouse_info(psmouse,
  1568. "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n",
  1569. SYN_ID_MODEL(priv->identity),
  1570. SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
  1571. priv->model_id,
  1572. priv->capabilities, priv->ext_cap, priv->ext_cap_0c,
  1573. priv->board_id, priv->firmware_id);
  1574. set_input_params(psmouse, priv);
  1575. /*
  1576. * Encode touchpad model so that it can be used to set
  1577. * input device->id.version and be visible to userspace.
  1578. * Because version is __u16 we have to drop something.
  1579. * Hardware info bits seem to be good candidates as they
  1580. * are documented to be for Synaptics corp. internal use.
  1581. */
  1582. psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
  1583. (priv->model_id & 0x000000ff);
  1584. if (absolute_mode) {
  1585. psmouse->protocol_handler = synaptics_process_byte;
  1586. psmouse->pktsize = 6;
  1587. } else {
  1588. /* Relative mode follows standard PS/2 mouse protocol */
  1589. psmouse->protocol_handler = psmouse_process_byte;
  1590. psmouse->pktsize = 3;
  1591. }
  1592. psmouse->set_rate = synaptics_set_rate;
  1593. psmouse->disconnect = synaptics_disconnect;
  1594. psmouse->reconnect = synaptics_reconnect;
  1595. psmouse->cleanup = synaptics_reset;
  1596. /* Synaptics can usually stay in sync without extra help */
  1597. psmouse->resync_time = 0;
  1598. if (SYN_CAP_PASS_THROUGH(priv->capabilities))
  1599. synaptics_pt_create(psmouse);
  1600. /*
  1601. * Toshiba's KBC seems to have trouble handling data from
  1602. * Synaptics at full rate. Switch to a lower rate (roughly
  1603. * the same rate as a standard PS/2 mouse).
  1604. */
  1605. if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
  1606. psmouse_info(psmouse,
  1607. "Toshiba %s detected, limiting rate to 40pps.\n",
  1608. dmi_get_system_info(DMI_PRODUCT_NAME));
  1609. psmouse->rate = 40;
  1610. }
  1611. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) {
  1612. err = device_create_file(&psmouse->ps2dev.serio->dev,
  1613. &psmouse_attr_disable_gesture.dattr);
  1614. if (err) {
  1615. psmouse_err(psmouse,
  1616. "Failed to create disable_gesture attribute (%d)",
  1617. err);
  1618. goto init_fail;
  1619. }
  1620. }
  1621. return 0;
  1622. init_fail:
  1623. kfree(priv);
  1624. return err;
  1625. }
  1626. int synaptics_init(struct psmouse *psmouse)
  1627. {
  1628. return __synaptics_init(psmouse, true);
  1629. }
  1630. int synaptics_init_relative(struct psmouse *psmouse)
  1631. {
  1632. return __synaptics_init(psmouse, false);
  1633. }
  1634. bool synaptics_supported(void)
  1635. {
  1636. return true;
  1637. }
  1638. #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1639. void __init synaptics_module_init(void)
  1640. {
  1641. }
  1642. int synaptics_init(struct psmouse *psmouse)
  1643. {
  1644. return -ENOSYS;
  1645. }
  1646. bool synaptics_supported(void)
  1647. {
  1648. return false;
  1649. }
  1650. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */