synaptics.c 50 KB

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