synaptics.c 50 KB

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