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