synaptics.c 50 KB

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