synaptics.c 49 KB

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