synaptics.c 48 KB

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