synaptics.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  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 = psmouse_sliced_command(psmouse, 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 = psmouse_sliced_command(psmouse, 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 = psmouse_sliced_command(psmouse, 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 = psmouse_sliced_command(parent, 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 void 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. /* Things that apply to both modes */
  1046. __set_bit(INPUT_PROP_POINTER, dev->propbit);
  1047. __set_bit(EV_KEY, dev->evbit);
  1048. __set_bit(BTN_LEFT, dev->keybit);
  1049. __set_bit(BTN_RIGHT, dev->keybit);
  1050. if (SYN_CAP_MIDDLE_BUTTON(info->capabilities))
  1051. __set_bit(BTN_MIDDLE, dev->keybit);
  1052. if (!priv->absolute_mode) {
  1053. /* Relative mode */
  1054. __set_bit(EV_REL, dev->evbit);
  1055. __set_bit(REL_X, dev->relbit);
  1056. __set_bit(REL_Y, dev->relbit);
  1057. return;
  1058. }
  1059. /* Absolute mode */
  1060. __set_bit(EV_ABS, dev->evbit);
  1061. set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
  1062. input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
  1063. if (cr48_profile_sensor)
  1064. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1065. if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
  1066. set_abs_position_params(dev, info,
  1067. ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
  1068. /* Image sensors can report per-contact pressure */
  1069. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1070. input_mt_init_slots(dev, 2, INPUT_MT_POINTER | INPUT_MT_TRACK);
  1071. /* Image sensors can signal 4 and 5 finger clicks */
  1072. __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
  1073. __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
  1074. } else if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c)) {
  1075. set_abs_position_params(dev, info,
  1076. ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
  1077. /*
  1078. * Profile sensor in CR-48 tracks contacts reasonably well,
  1079. * other non-image sensors with AGM use semi-mt.
  1080. */
  1081. input_mt_init_slots(dev, 2,
  1082. INPUT_MT_POINTER |
  1083. (cr48_profile_sensor ?
  1084. INPUT_MT_TRACK : INPUT_MT_SEMI_MT));
  1085. }
  1086. if (SYN_CAP_PALMDETECT(info->capabilities))
  1087. input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
  1088. __set_bit(BTN_TOUCH, dev->keybit);
  1089. __set_bit(BTN_TOOL_FINGER, dev->keybit);
  1090. if (synaptics_has_multifinger(priv)) {
  1091. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  1092. __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
  1093. }
  1094. if (SYN_CAP_FOUR_BUTTON(info->capabilities) ||
  1095. SYN_CAP_MIDDLE_BUTTON(info->capabilities)) {
  1096. __set_bit(BTN_FORWARD, dev->keybit);
  1097. __set_bit(BTN_BACK, dev->keybit);
  1098. }
  1099. if (!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
  1100. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(info->ext_cap); i++)
  1101. __set_bit(BTN_0 + i, dev->keybit);
  1102. __clear_bit(EV_REL, dev->evbit);
  1103. __clear_bit(REL_X, dev->relbit);
  1104. __clear_bit(REL_Y, dev->relbit);
  1105. if (SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
  1106. __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
  1107. if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1108. !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
  1109. __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
  1110. /* Clickpads report only left button */
  1111. __clear_bit(BTN_RIGHT, dev->keybit);
  1112. __clear_bit(BTN_MIDDLE, dev->keybit);
  1113. }
  1114. }
  1115. static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
  1116. void *data, char *buf)
  1117. {
  1118. struct synaptics_data *priv = psmouse->private;
  1119. return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
  1120. }
  1121. static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
  1122. void *data, const char *buf,
  1123. size_t len)
  1124. {
  1125. struct synaptics_data *priv = psmouse->private;
  1126. unsigned int value;
  1127. int err;
  1128. err = kstrtouint(buf, 10, &value);
  1129. if (err)
  1130. return err;
  1131. if (value > 1)
  1132. return -EINVAL;
  1133. if (value == priv->disable_gesture)
  1134. return len;
  1135. priv->disable_gesture = value;
  1136. if (value)
  1137. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  1138. else
  1139. priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
  1140. if (synaptics_mode_cmd(psmouse, priv->mode))
  1141. return -EIO;
  1142. return len;
  1143. }
  1144. PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
  1145. synaptics_show_disable_gesture,
  1146. synaptics_set_disable_gesture);
  1147. static void synaptics_disconnect(struct psmouse *psmouse)
  1148. {
  1149. struct synaptics_data *priv = psmouse->private;
  1150. /*
  1151. * We might have left a breadcrumb when trying to
  1152. * set up SMbus companion.
  1153. */
  1154. psmouse_smbus_cleanup(psmouse);
  1155. if (!priv->absolute_mode &&
  1156. SYN_ID_DISGEST_SUPPORTED(priv->info.identity))
  1157. device_remove_file(&psmouse->ps2dev.serio->dev,
  1158. &psmouse_attr_disable_gesture.dattr);
  1159. synaptics_reset(psmouse);
  1160. kfree(priv);
  1161. psmouse->private = NULL;
  1162. }
  1163. static int synaptics_reconnect(struct psmouse *psmouse)
  1164. {
  1165. struct synaptics_data *priv = psmouse->private;
  1166. struct synaptics_device_info info;
  1167. u8 param[2];
  1168. int retry = 0;
  1169. int error;
  1170. do {
  1171. psmouse_reset(psmouse);
  1172. if (retry) {
  1173. /*
  1174. * On some boxes, right after resuming, the touchpad
  1175. * needs some time to finish initializing (I assume
  1176. * it needs time to calibrate) and start responding
  1177. * to Synaptics-specific queries, so let's wait a
  1178. * bit.
  1179. */
  1180. ssleep(1);
  1181. }
  1182. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
  1183. error = synaptics_detect(psmouse, 0);
  1184. } while (error && ++retry < 3);
  1185. if (error)
  1186. return error;
  1187. if (retry > 1)
  1188. psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
  1189. error = synaptics_query_hardware(psmouse, &info);
  1190. if (error) {
  1191. psmouse_err(psmouse, "Unable to query device.\n");
  1192. return error;
  1193. }
  1194. error = synaptics_set_mode(psmouse);
  1195. if (error) {
  1196. psmouse_err(psmouse, "Unable to initialize device.\n");
  1197. return error;
  1198. }
  1199. if (info.identity != priv->info.identity ||
  1200. info.model_id != priv->info.model_id ||
  1201. info.capabilities != priv->info.capabilities ||
  1202. info.ext_cap != priv->info.ext_cap) {
  1203. psmouse_err(psmouse,
  1204. "hardware appears to be different: id(%u-%u), model(%u-%u), caps(%x-%x), ext(%x-%x).\n",
  1205. priv->info.identity, info.identity,
  1206. priv->info.model_id, info.model_id,
  1207. priv->info.capabilities, info.capabilities,
  1208. priv->info.ext_cap, info.ext_cap);
  1209. return -ENXIO;
  1210. }
  1211. return 0;
  1212. }
  1213. static bool impaired_toshiba_kbc;
  1214. static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
  1215. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1216. {
  1217. /* Toshiba Satellite */
  1218. .matches = {
  1219. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1220. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  1221. },
  1222. },
  1223. {
  1224. /* Toshiba Dynabook */
  1225. .matches = {
  1226. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1227. DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
  1228. },
  1229. },
  1230. {
  1231. /* Toshiba Portege M300 */
  1232. .matches = {
  1233. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1234. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
  1235. },
  1236. },
  1237. {
  1238. /* Toshiba Portege M300 */
  1239. .matches = {
  1240. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1241. DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
  1242. DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
  1243. },
  1244. },
  1245. #endif
  1246. { }
  1247. };
  1248. static bool broken_olpc_ec;
  1249. static const struct dmi_system_id olpc_dmi_table[] __initconst = {
  1250. #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
  1251. {
  1252. /* OLPC XO-1 or XO-1.5 */
  1253. .matches = {
  1254. DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
  1255. DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
  1256. },
  1257. },
  1258. #endif
  1259. { }
  1260. };
  1261. static const struct dmi_system_id __initconst cr48_dmi_table[] = {
  1262. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1263. {
  1264. /* Cr-48 Chromebook (Codename Mario) */
  1265. .matches = {
  1266. DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
  1267. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  1268. },
  1269. },
  1270. #endif
  1271. { }
  1272. };
  1273. void __init synaptics_module_init(void)
  1274. {
  1275. impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
  1276. broken_olpc_ec = dmi_check_system(olpc_dmi_table);
  1277. cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
  1278. }
  1279. static int synaptics_init_ps2(struct psmouse *psmouse,
  1280. struct synaptics_device_info *info,
  1281. bool absolute_mode)
  1282. {
  1283. struct synaptics_data *priv;
  1284. int err;
  1285. synaptics_apply_quirks(psmouse, info);
  1286. psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
  1287. if (!priv)
  1288. return -ENOMEM;
  1289. priv->info = *info;
  1290. priv->absolute_mode = absolute_mode;
  1291. if (SYN_ID_DISGEST_SUPPORTED(info->identity))
  1292. priv->disable_gesture = true;
  1293. /*
  1294. * Unfortunately ForcePad capability is not exported over PS/2,
  1295. * so we have to resort to checking PNP IDs.
  1296. */
  1297. priv->is_forcepad = psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids);
  1298. err = synaptics_set_mode(psmouse);
  1299. if (err) {
  1300. psmouse_err(psmouse, "Unable to initialize device.\n");
  1301. goto init_fail;
  1302. }
  1303. priv->pkt_type = SYN_MODEL_NEWABS(info->model_id) ?
  1304. SYN_NEWABS : SYN_OLDABS;
  1305. psmouse_info(psmouse,
  1306. "Touchpad model: %lu, fw: %lu.%lu, id: %#x, caps: %#x/%#x/%#x/%#x, board id: %u, fw id: %u\n",
  1307. SYN_ID_MODEL(info->identity),
  1308. SYN_ID_MAJOR(info->identity), SYN_ID_MINOR(info->identity),
  1309. info->model_id,
  1310. info->capabilities, info->ext_cap, info->ext_cap_0c,
  1311. info->ext_cap_10, info->board_id, info->firmware_id);
  1312. set_input_params(psmouse, priv);
  1313. /*
  1314. * Encode touchpad model so that it can be used to set
  1315. * input device->id.version and be visible to userspace.
  1316. * Because version is __u16 we have to drop something.
  1317. * Hardware info bits seem to be good candidates as they
  1318. * are documented to be for Synaptics corp. internal use.
  1319. */
  1320. psmouse->model = ((info->model_id & 0x00ff0000) >> 8) |
  1321. (info->model_id & 0x000000ff);
  1322. if (absolute_mode) {
  1323. psmouse->protocol_handler = synaptics_process_byte;
  1324. psmouse->pktsize = 6;
  1325. } else {
  1326. /* Relative mode follows standard PS/2 mouse protocol */
  1327. psmouse->protocol_handler = psmouse_process_byte;
  1328. psmouse->pktsize = 3;
  1329. }
  1330. psmouse->set_rate = synaptics_set_rate;
  1331. psmouse->disconnect = synaptics_disconnect;
  1332. psmouse->reconnect = synaptics_reconnect;
  1333. psmouse->cleanup = synaptics_reset;
  1334. /* Synaptics can usually stay in sync without extra help */
  1335. psmouse->resync_time = 0;
  1336. if (SYN_CAP_PASS_THROUGH(info->capabilities))
  1337. synaptics_pt_create(psmouse);
  1338. /*
  1339. * Toshiba's KBC seems to have trouble handling data from
  1340. * Synaptics at full rate. Switch to a lower rate (roughly
  1341. * the same rate as a standard PS/2 mouse).
  1342. */
  1343. if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
  1344. psmouse_info(psmouse,
  1345. "Toshiba %s detected, limiting rate to 40pps.\n",
  1346. dmi_get_system_info(DMI_PRODUCT_NAME));
  1347. psmouse->rate = 40;
  1348. }
  1349. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(info->identity)) {
  1350. err = device_create_file(&psmouse->ps2dev.serio->dev,
  1351. &psmouse_attr_disable_gesture.dattr);
  1352. if (err) {
  1353. psmouse_err(psmouse,
  1354. "Failed to create disable_gesture attribute (%d)",
  1355. err);
  1356. goto init_fail;
  1357. }
  1358. }
  1359. return 0;
  1360. init_fail:
  1361. kfree(priv);
  1362. return err;
  1363. }
  1364. static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
  1365. {
  1366. struct synaptics_device_info info;
  1367. int error;
  1368. psmouse_reset(psmouse);
  1369. error = synaptics_query_hardware(psmouse, &info);
  1370. if (error) {
  1371. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1372. return error;
  1373. }
  1374. return synaptics_init_ps2(psmouse, &info, absolute_mode);
  1375. }
  1376. int synaptics_init_absolute(struct psmouse *psmouse)
  1377. {
  1378. return __synaptics_init(psmouse, true);
  1379. }
  1380. int synaptics_init_relative(struct psmouse *psmouse)
  1381. {
  1382. return __synaptics_init(psmouse, false);
  1383. }
  1384. static int synaptics_setup_ps2(struct psmouse *psmouse,
  1385. struct synaptics_device_info *info)
  1386. {
  1387. bool absolute_mode = true;
  1388. int error;
  1389. /*
  1390. * The OLPC XO has issues with Synaptics' absolute mode; the constant
  1391. * packet spew overloads the EC such that key presses on the keyboard
  1392. * are missed. Given that, don't even attempt to use Absolute mode.
  1393. * Relative mode seems to work just fine.
  1394. */
  1395. if (broken_olpc_ec) {
  1396. psmouse_info(psmouse,
  1397. "OLPC XO detected, forcing relative protocol.\n");
  1398. absolute_mode = false;
  1399. }
  1400. error = synaptics_init_ps2(psmouse, info, absolute_mode);
  1401. if (error)
  1402. return error;
  1403. return absolute_mode ? PSMOUSE_SYNAPTICS : PSMOUSE_SYNAPTICS_RELATIVE;
  1404. }
  1405. #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1406. void __init synaptics_module_init(void)
  1407. {
  1408. }
  1409. static int __maybe_unused
  1410. synaptics_setup_ps2(struct psmouse *psmouse,
  1411. struct synaptics_device_info *info)
  1412. {
  1413. return -ENOSYS;
  1414. }
  1415. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1416. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS
  1417. /*
  1418. * The newest Synaptics device can use a secondary bus (called InterTouch) which
  1419. * provides a better bandwidth and allow a better control of the touchpads.
  1420. * This is used to decide if we need to use this bus or not.
  1421. */
  1422. enum {
  1423. SYNAPTICS_INTERTOUCH_NOT_SET = -1,
  1424. SYNAPTICS_INTERTOUCH_OFF,
  1425. SYNAPTICS_INTERTOUCH_ON,
  1426. };
  1427. static int synaptics_intertouch = IS_ENABLED(CONFIG_RMI4_SMB) ?
  1428. SYNAPTICS_INTERTOUCH_NOT_SET : SYNAPTICS_INTERTOUCH_OFF;
  1429. module_param_named(synaptics_intertouch, synaptics_intertouch, int, 0644);
  1430. MODULE_PARM_DESC(synaptics_intertouch, "Use a secondary bus for the Synaptics device.");
  1431. static int synaptics_create_intertouch(struct psmouse *psmouse,
  1432. struct synaptics_device_info *info,
  1433. bool leave_breadcrumbs)
  1434. {
  1435. bool topbuttonpad =
  1436. psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1437. !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10);
  1438. const struct rmi_device_platform_data pdata = {
  1439. .sensor_pdata = {
  1440. .sensor_type = rmi_sensor_touchpad,
  1441. .axis_align.flip_y = true,
  1442. /* to prevent cursors jumps: */
  1443. .kernel_tracking = true,
  1444. .topbuttonpad = topbuttonpad,
  1445. },
  1446. .f30_data = {
  1447. .buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
  1448. .trackstick_buttons =
  1449. !!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
  1450. },
  1451. };
  1452. const struct i2c_board_info intertouch_board = {
  1453. I2C_BOARD_INFO("rmi4_smbus", 0x2c),
  1454. .flags = I2C_CLIENT_HOST_NOTIFY,
  1455. };
  1456. return psmouse_smbus_init(psmouse, &intertouch_board,
  1457. &pdata, sizeof(pdata),
  1458. leave_breadcrumbs);
  1459. }
  1460. /**
  1461. * synaptics_setup_intertouch - called once the PS/2 devices are enumerated
  1462. * and decides to instantiate a SMBus InterTouch device.
  1463. */
  1464. static int synaptics_setup_intertouch(struct psmouse *psmouse,
  1465. struct synaptics_device_info *info,
  1466. bool leave_breadcrumbs)
  1467. {
  1468. int error;
  1469. if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_OFF)
  1470. return -ENXIO;
  1471. if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_NOT_SET) {
  1472. if (!psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1473. !psmouse_matches_pnp_id(psmouse, smbus_pnp_ids)) {
  1474. if (!psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids))
  1475. psmouse_info(psmouse,
  1476. "Your touchpad (%s) says it can support a different bus. "
  1477. "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",
  1478. psmouse->ps2dev.serio->firmware_id);
  1479. return -ENXIO;
  1480. }
  1481. }
  1482. psmouse_info(psmouse, "Trying to set up SMBus access\n");
  1483. error = synaptics_create_intertouch(psmouse, info, leave_breadcrumbs);
  1484. if (error) {
  1485. if (error == -EAGAIN)
  1486. psmouse_info(psmouse, "SMbus companion is not ready yet\n");
  1487. else
  1488. psmouse_err(psmouse, "unable to create intertouch device\n");
  1489. return error;
  1490. }
  1491. return 0;
  1492. }
  1493. int synaptics_init_smbus(struct psmouse *psmouse)
  1494. {
  1495. struct synaptics_device_info info;
  1496. int error;
  1497. psmouse_reset(psmouse);
  1498. error = synaptics_query_hardware(psmouse, &info);
  1499. if (error) {
  1500. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1501. return error;
  1502. }
  1503. if (!SYN_CAP_INTERTOUCH(info.ext_cap_0c))
  1504. return -ENXIO;
  1505. return synaptics_create_intertouch(psmouse, &info, false);
  1506. }
  1507. #else /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1508. static int __maybe_unused
  1509. synaptics_setup_intertouch(struct psmouse *psmouse,
  1510. struct synaptics_device_info *info,
  1511. bool leave_breadcrumbs)
  1512. {
  1513. return -ENOSYS;
  1514. }
  1515. int synaptics_init_smbus(struct psmouse *psmouse)
  1516. {
  1517. return -ENOSYS;
  1518. }
  1519. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1520. #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
  1521. defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
  1522. int synaptics_init(struct psmouse *psmouse)
  1523. {
  1524. struct synaptics_device_info info;
  1525. int error;
  1526. int retval;
  1527. psmouse_reset(psmouse);
  1528. error = synaptics_query_hardware(psmouse, &info);
  1529. if (error) {
  1530. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1531. return error;
  1532. }
  1533. if (SYN_CAP_INTERTOUCH(info.ext_cap_0c)) {
  1534. if ((!IS_ENABLED(CONFIG_RMI4_SMB) ||
  1535. !IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)) &&
  1536. /* Forcepads need F21, which is not ready */
  1537. !psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids)) {
  1538. psmouse_warn(psmouse,
  1539. "The touchpad can support a better bus than the too old PS/2 protocol. "
  1540. "Make sure MOUSE_PS2_SYNAPTICS_SMBUS and RMI4_SMB are enabled to get a better touchpad experience.\n");
  1541. }
  1542. error = synaptics_setup_intertouch(psmouse, &info, true);
  1543. if (!error)
  1544. return PSMOUSE_SYNAPTICS_SMBUS;
  1545. }
  1546. retval = synaptics_setup_ps2(psmouse, &info);
  1547. if (retval < 0) {
  1548. /*
  1549. * Not using any flavor of Synaptics support, so clean up
  1550. * SMbus breadcrumbs, if any.
  1551. */
  1552. psmouse_smbus_cleanup(psmouse);
  1553. }
  1554. return retval;
  1555. }
  1556. #else /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1557. int synaptics_init(struct psmouse *psmouse)
  1558. {
  1559. return -ENOSYS;
  1560. }
  1561. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */