synaptics.c 49 KB

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