synaptics.c 50 KB

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