synaptics.c 50 KB

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