synaptics.c 49 KB

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