synaptics.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Synaptics TouchPad PS/2 mouse driver
  4. *
  5. * 2003 Dmitry Torokhov <[email protected]>
  6. * Added support for pass-through port. Special thanks to Peter Berg Larsen
  7. * for explaining various Synaptics quirks.
  8. *
  9. * 2003 Peter Osterlund <[email protected]>
  10. * Ported to 2.5 input device infrastructure.
  11. *
  12. * Copyright (C) 2001 Stefan Gmeiner <[email protected]>
  13. * start merging tpconfig and gpm code to a xfree-input module
  14. * adding some changes and extensions (ex. 3rd and 4th button)
  15. *
  16. * Copyright (c) 1997 C. Scott Ananian <[email protected]>
  17. * Copyright (c) 1998-2000 Bruce Kalk <[email protected]>
  18. * code for the special synaptics commands (from the tpconfig-source)
  19. *
  20. * Trademarks are the property of their respective owners.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/delay.h>
  24. #include <linux/dmi.h>
  25. #include <linux/input/mt.h>
  26. #include <linux/serio.h>
  27. #include <linux/libps2.h>
  28. #include <linux/rmi.h>
  29. #include <linux/i2c.h>
  30. #include <linux/slab.h>
  31. #include "psmouse.h"
  32. #include "synaptics.h"
  33. /*
  34. * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
  35. * section 2.3.2, which says that they should be valid regardless of the
  36. * actual size of the sensor.
  37. * Note that newer firmware allows querying device for maximum useable
  38. * coordinates.
  39. */
  40. #define XMIN 0
  41. #define XMAX 6143
  42. #define YMIN 0
  43. #define YMAX 6143
  44. #define XMIN_NOMINAL 1472
  45. #define XMAX_NOMINAL 5472
  46. #define YMIN_NOMINAL 1408
  47. #define YMAX_NOMINAL 4448
  48. /* Size in bits of absolute position values reported by the hardware */
  49. #define ABS_POS_BITS 13
  50. /*
  51. * These values should represent the absolute maximum value that will
  52. * be reported for a positive position value. Some Synaptics firmware
  53. * uses this value to indicate a finger near the edge of the touchpad
  54. * whose precise position cannot be determined.
  55. *
  56. * At least one touchpad is known to report positions in excess of this
  57. * value which are actually negative values truncated to the 13-bit
  58. * reporting range. These values have never been observed to be lower
  59. * than 8184 (i.e. -8), so we treat all values greater than 8176 as
  60. * negative and any other value as positive.
  61. */
  62. #define X_MAX_POSITIVE 8176
  63. #define Y_MAX_POSITIVE 8176
  64. /* maximum ABS_MT_POSITION displacement (in mm) */
  65. #define DMAX 10
  66. /*****************************************************************************
  67. * Stuff we need even when we do not want native Synaptics support
  68. ****************************************************************************/
  69. /*
  70. * Set the synaptics touchpad mode byte by special commands
  71. */
  72. static int synaptics_mode_cmd(struct psmouse *psmouse, u8 mode)
  73. {
  74. u8 param[1];
  75. int error;
  76. error = ps2_sliced_command(&psmouse->ps2dev, mode);
  77. if (error)
  78. return error;
  79. param[0] = SYN_PS_SET_MODE2;
  80. error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE);
  81. if (error)
  82. return error;
  83. return 0;
  84. }
  85. int synaptics_detect(struct psmouse *psmouse, bool set_properties)
  86. {
  87. struct ps2dev *ps2dev = &psmouse->ps2dev;
  88. u8 param[4] = { 0 };
  89. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  90. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  91. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  92. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  93. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
  94. if (param[1] != 0x47)
  95. return -ENODEV;
  96. if (set_properties) {
  97. psmouse->vendor = "Synaptics";
  98. psmouse->name = "TouchPad";
  99. }
  100. return 0;
  101. }
  102. void synaptics_reset(struct psmouse *psmouse)
  103. {
  104. /* reset touchpad back to relative mode, gestures enabled */
  105. synaptics_mode_cmd(psmouse, 0);
  106. }
  107. #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
  108. defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
  109. /* This list has been kindly provided by Synaptics. */
  110. static const char * const topbuttonpad_pnp_ids[] = {
  111. "LEN0017",
  112. "LEN0018",
  113. "LEN0019",
  114. "LEN0023",
  115. "LEN002A",
  116. "LEN002B",
  117. "LEN002C",
  118. "LEN002D",
  119. "LEN002E",
  120. "LEN0033", /* Helix */
  121. "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
  122. "LEN0035", /* X240 */
  123. "LEN0036", /* T440 */
  124. "LEN0037", /* X1 Carbon 2nd */
  125. "LEN0038",
  126. "LEN0039", /* T440s */
  127. "LEN0041",
  128. "LEN0042", /* Yoga */
  129. "LEN0045",
  130. "LEN0047",
  131. "LEN2000", /* S540 */
  132. "LEN2001", /* Edge E431 */
  133. "LEN2002", /* Edge E531 */
  134. "LEN2003",
  135. "LEN2004", /* L440 */
  136. "LEN2005",
  137. "LEN2006", /* Edge E440/E540 */
  138. "LEN2007",
  139. "LEN2008",
  140. "LEN2009",
  141. "LEN200A",
  142. "LEN200B",
  143. NULL
  144. };
  145. static const char * const smbus_pnp_ids[] = {
  146. /* all of the topbuttonpad_pnp_ids are valid, we just add some extras */
  147. "LEN0048", /* X1 Carbon 3 */
  148. "LEN0046", /* X250 */
  149. "LEN0049", /* Yoga 11e */
  150. "LEN004a", /* W541 */
  151. "LEN005b", /* P50 */
  152. "LEN005e", /* T560 */
  153. "LEN006c", /* T470s */
  154. "LEN007a", /* T470s */
  155. "LEN0071", /* T480 */
  156. "LEN0072", /* X1 Carbon Gen 5 (2017) - Elan/ALPS trackpoint */
  157. "LEN0073", /* X1 Carbon G5 (Elantech) */
  158. "LEN0091", /* X1 Carbon 6 */
  159. "LEN0092", /* X1 Carbon 6 */
  160. "LEN0093", /* T480 */
  161. "LEN0096", /* X280 */
  162. "LEN0097", /* X280 -> ALPS trackpoint */
  163. "LEN0099", /* X1 Extreme Gen 1 / P1 Gen 1 */
  164. "LEN009b", /* T580 */
  165. "LEN0402", /* X1 Extreme Gen 2 / P1 Gen 2 */
  166. "LEN040f", /* P1 Gen 3 */
  167. "LEN200f", /* T450s */
  168. "LEN2044", /* L470 */
  169. "LEN2054", /* E480 */
  170. "LEN2055", /* E580 */
  171. "LEN2068", /* T14 Gen 1 */
  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 synaptics 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. strscpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
  615. strscpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->phys));
  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. /*
  947. * SYN_MODEL_PEN(info->model_id): even if
  948. * the device supports pen, we treat it as
  949. * a single finger.
  950. */
  951. break;
  952. case 4 ... 15:
  953. if (SYN_CAP_PALMDETECT(info->capabilities))
  954. finger_width = hw.w;
  955. break;
  956. }
  957. }
  958. } else {
  959. num_fingers = 0;
  960. finger_width = 0;
  961. }
  962. if (cr48_profile_sensor) {
  963. synaptics_report_mt_data(psmouse, &hw, num_fingers);
  964. return;
  965. }
  966. if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c))
  967. synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
  968. num_fingers);
  969. /* Post events
  970. * BTN_TOUCH has to be first as mousedev relies on it when doing
  971. * absolute -> relative conversion
  972. */
  973. if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
  974. if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
  975. if (num_fingers > 0) {
  976. input_report_abs(dev, ABS_X, hw.x);
  977. input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
  978. }
  979. input_report_abs(dev, ABS_PRESSURE, hw.z);
  980. if (SYN_CAP_PALMDETECT(info->capabilities))
  981. input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
  982. input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
  983. if (synaptics_has_multifinger(priv)) {
  984. input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
  985. input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
  986. }
  987. synaptics_report_buttons(psmouse, &hw);
  988. input_sync(dev);
  989. }
  990. static bool synaptics_validate_byte(struct psmouse *psmouse,
  991. int idx, enum synaptics_pkt_type pkt_type)
  992. {
  993. static const u8 newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
  994. static const u8 newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
  995. static const u8 newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
  996. static const u8 oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
  997. static const u8 oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
  998. const u8 *packet = psmouse->packet;
  999. if (idx < 0 || idx > 4)
  1000. return false;
  1001. switch (pkt_type) {
  1002. case SYN_NEWABS:
  1003. case SYN_NEWABS_RELAXED:
  1004. return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
  1005. case SYN_NEWABS_STRICT:
  1006. return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
  1007. case SYN_OLDABS:
  1008. return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
  1009. default:
  1010. psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
  1011. return false;
  1012. }
  1013. }
  1014. static enum synaptics_pkt_type
  1015. synaptics_detect_pkt_type(struct psmouse *psmouse)
  1016. {
  1017. int i;
  1018. for (i = 0; i < 5; i++) {
  1019. if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
  1020. psmouse_info(psmouse, "using relaxed packet validation\n");
  1021. return SYN_NEWABS_RELAXED;
  1022. }
  1023. }
  1024. return SYN_NEWABS_STRICT;
  1025. }
  1026. static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
  1027. {
  1028. struct synaptics_data *priv = psmouse->private;
  1029. if (psmouse->pktcnt >= 6) { /* Full packet received */
  1030. if (unlikely(priv->pkt_type == SYN_NEWABS))
  1031. priv->pkt_type = synaptics_detect_pkt_type(psmouse);
  1032. if (SYN_CAP_PASS_THROUGH(priv->info.capabilities) &&
  1033. synaptics_is_pt_packet(psmouse->packet)) {
  1034. if (priv->pt_port)
  1035. synaptics_pass_pt_packet(priv->pt_port,
  1036. psmouse->packet);
  1037. } else
  1038. synaptics_process_packet(psmouse);
  1039. return PSMOUSE_FULL_PACKET;
  1040. }
  1041. return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
  1042. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  1043. }
  1044. /*****************************************************************************
  1045. * Driver initialization/cleanup functions
  1046. ****************************************************************************/
  1047. static void set_abs_position_params(struct input_dev *dev,
  1048. struct synaptics_device_info *info,
  1049. int x_code, int y_code)
  1050. {
  1051. int x_min = info->x_min ?: XMIN_NOMINAL;
  1052. int x_max = info->x_max ?: XMAX_NOMINAL;
  1053. int y_min = info->y_min ?: YMIN_NOMINAL;
  1054. int y_max = info->y_max ?: YMAX_NOMINAL;
  1055. int fuzz = SYN_CAP_REDUCED_FILTERING(info->ext_cap_0c) ?
  1056. SYN_REDUCED_FILTER_FUZZ : 0;
  1057. input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
  1058. input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
  1059. input_abs_set_res(dev, x_code, info->x_res);
  1060. input_abs_set_res(dev, y_code, info->y_res);
  1061. }
  1062. static int set_input_params(struct psmouse *psmouse,
  1063. struct synaptics_data *priv)
  1064. {
  1065. struct input_dev *dev = psmouse->dev;
  1066. struct synaptics_device_info *info = &priv->info;
  1067. int i;
  1068. int error;
  1069. /* Reset default psmouse capabilities */
  1070. __clear_bit(EV_REL, dev->evbit);
  1071. bitmap_zero(dev->relbit, REL_CNT);
  1072. bitmap_zero(dev->keybit, KEY_CNT);
  1073. /* Things that apply to both modes */
  1074. __set_bit(INPUT_PROP_POINTER, dev->propbit);
  1075. input_set_capability(dev, EV_KEY, BTN_LEFT);
  1076. /* Clickpads report only left button */
  1077. if (!SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
  1078. input_set_capability(dev, EV_KEY, BTN_RIGHT);
  1079. if (SYN_CAP_MIDDLE_BUTTON(info->capabilities))
  1080. input_set_capability(dev, EV_KEY, BTN_MIDDLE);
  1081. }
  1082. if (!priv->absolute_mode) {
  1083. /* Relative mode */
  1084. input_set_capability(dev, EV_REL, REL_X);
  1085. input_set_capability(dev, EV_REL, REL_Y);
  1086. return 0;
  1087. }
  1088. /* Absolute mode */
  1089. set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
  1090. input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
  1091. if (cr48_profile_sensor)
  1092. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1093. if (SYN_CAP_IMAGE_SENSOR(info->ext_cap_0c)) {
  1094. set_abs_position_params(dev, info,
  1095. ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
  1096. /* Image sensors can report per-contact pressure */
  1097. input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  1098. error = input_mt_init_slots(dev, 2,
  1099. INPUT_MT_POINTER | INPUT_MT_TRACK);
  1100. if (error)
  1101. return error;
  1102. /* Image sensors can signal 4 and 5 finger clicks */
  1103. input_set_capability(dev, EV_KEY, BTN_TOOL_QUADTAP);
  1104. input_set_capability(dev, EV_KEY, BTN_TOOL_QUINTTAP);
  1105. } else if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c)) {
  1106. set_abs_position_params(dev, info,
  1107. ABS_MT_POSITION_X, ABS_MT_POSITION_Y);
  1108. /*
  1109. * Profile sensor in CR-48 tracks contacts reasonably well,
  1110. * other non-image sensors with AGM use semi-mt.
  1111. */
  1112. error = input_mt_init_slots(dev, 2,
  1113. INPUT_MT_POINTER |
  1114. (cr48_profile_sensor ?
  1115. INPUT_MT_TRACK :
  1116. INPUT_MT_SEMI_MT));
  1117. if (error)
  1118. return error;
  1119. /*
  1120. * For semi-mt devices we send ABS_X/Y ourselves instead of
  1121. * input_mt_report_pointer_emulation. But
  1122. * input_mt_init_slots() resets the fuzz to 0, leading to a
  1123. * filtered ABS_MT_POSITION_X but an unfiltered ABS_X
  1124. * position. Let's re-initialize ABS_X/Y here.
  1125. */
  1126. if (!cr48_profile_sensor)
  1127. set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y);
  1128. }
  1129. if (SYN_CAP_PALMDETECT(info->capabilities))
  1130. input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
  1131. input_set_capability(dev, EV_KEY, BTN_TOUCH);
  1132. input_set_capability(dev, EV_KEY, BTN_TOOL_FINGER);
  1133. if (synaptics_has_multifinger(priv)) {
  1134. input_set_capability(dev, EV_KEY, BTN_TOOL_DOUBLETAP);
  1135. input_set_capability(dev, EV_KEY, BTN_TOOL_TRIPLETAP);
  1136. }
  1137. if (SYN_CAP_FOUR_BUTTON(info->capabilities) ||
  1138. SYN_CAP_MIDDLE_BUTTON(info->capabilities)) {
  1139. input_set_capability(dev, EV_KEY, BTN_FORWARD);
  1140. input_set_capability(dev, EV_KEY, BTN_BACK);
  1141. }
  1142. if (!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
  1143. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(info->ext_cap); i++)
  1144. input_set_capability(dev, EV_KEY, BTN_0 + i);
  1145. if (SYN_CAP_CLICKPAD(info->ext_cap_0c)) {
  1146. __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
  1147. if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1148. !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10))
  1149. __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
  1150. }
  1151. return 0;
  1152. }
  1153. static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
  1154. void *data, char *buf)
  1155. {
  1156. struct synaptics_data *priv = psmouse->private;
  1157. return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
  1158. }
  1159. static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
  1160. void *data, const char *buf,
  1161. size_t len)
  1162. {
  1163. struct synaptics_data *priv = psmouse->private;
  1164. unsigned int value;
  1165. int err;
  1166. err = kstrtouint(buf, 10, &value);
  1167. if (err)
  1168. return err;
  1169. if (value > 1)
  1170. return -EINVAL;
  1171. if (value == priv->disable_gesture)
  1172. return len;
  1173. priv->disable_gesture = value;
  1174. if (value)
  1175. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  1176. else
  1177. priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
  1178. if (synaptics_mode_cmd(psmouse, priv->mode))
  1179. return -EIO;
  1180. return len;
  1181. }
  1182. PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
  1183. synaptics_show_disable_gesture,
  1184. synaptics_set_disable_gesture);
  1185. static void synaptics_disconnect(struct psmouse *psmouse)
  1186. {
  1187. struct synaptics_data *priv = psmouse->private;
  1188. /*
  1189. * We might have left a breadcrumb when trying to
  1190. * set up SMbus companion.
  1191. */
  1192. psmouse_smbus_cleanup(psmouse);
  1193. if (!priv->absolute_mode &&
  1194. SYN_ID_DISGEST_SUPPORTED(priv->info.identity))
  1195. device_remove_file(&psmouse->ps2dev.serio->dev,
  1196. &psmouse_attr_disable_gesture.dattr);
  1197. synaptics_reset(psmouse);
  1198. kfree(priv);
  1199. psmouse->private = NULL;
  1200. }
  1201. static int synaptics_reconnect(struct psmouse *psmouse)
  1202. {
  1203. struct synaptics_data *priv = psmouse->private;
  1204. struct synaptics_device_info info;
  1205. u8 param[2];
  1206. int retry = 0;
  1207. int error;
  1208. do {
  1209. psmouse_reset(psmouse);
  1210. if (retry) {
  1211. /*
  1212. * On some boxes, right after resuming, the touchpad
  1213. * needs some time to finish initializing (I assume
  1214. * it needs time to calibrate) and start responding
  1215. * to Synaptics-specific queries, so let's wait a
  1216. * bit.
  1217. */
  1218. ssleep(1);
  1219. }
  1220. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
  1221. error = synaptics_detect(psmouse, 0);
  1222. } while (error && ++retry < 3);
  1223. if (error)
  1224. return error;
  1225. if (retry > 1)
  1226. psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
  1227. error = synaptics_query_hardware(psmouse, &info);
  1228. if (error) {
  1229. psmouse_err(psmouse, "Unable to query device.\n");
  1230. return error;
  1231. }
  1232. error = synaptics_set_mode(psmouse);
  1233. if (error) {
  1234. psmouse_err(psmouse, "Unable to initialize device.\n");
  1235. return error;
  1236. }
  1237. if (info.identity != priv->info.identity ||
  1238. info.model_id != priv->info.model_id ||
  1239. info.capabilities != priv->info.capabilities ||
  1240. info.ext_cap != priv->info.ext_cap) {
  1241. psmouse_err(psmouse,
  1242. "hardware appears to be different: id(%u-%u), model(%u-%u), caps(%x-%x), ext(%x-%x).\n",
  1243. priv->info.identity, info.identity,
  1244. priv->info.model_id, info.model_id,
  1245. priv->info.capabilities, info.capabilities,
  1246. priv->info.ext_cap, info.ext_cap);
  1247. return -ENXIO;
  1248. }
  1249. return 0;
  1250. }
  1251. static bool impaired_toshiba_kbc;
  1252. static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
  1253. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1254. {
  1255. /* Toshiba Satellite */
  1256. .matches = {
  1257. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1258. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  1259. },
  1260. },
  1261. {
  1262. /* Toshiba Dynabook */
  1263. .matches = {
  1264. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1265. DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
  1266. },
  1267. },
  1268. {
  1269. /* Toshiba Portege M300 */
  1270. .matches = {
  1271. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1272. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
  1273. },
  1274. },
  1275. {
  1276. /* Toshiba Portege M300 */
  1277. .matches = {
  1278. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1279. DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
  1280. DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
  1281. },
  1282. },
  1283. #endif
  1284. { }
  1285. };
  1286. static bool broken_olpc_ec;
  1287. static const struct dmi_system_id olpc_dmi_table[] __initconst = {
  1288. #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
  1289. {
  1290. /* OLPC XO-1 or XO-1.5 */
  1291. .matches = {
  1292. DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
  1293. DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
  1294. },
  1295. },
  1296. #endif
  1297. { }
  1298. };
  1299. static const struct dmi_system_id __initconst cr48_dmi_table[] = {
  1300. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1301. {
  1302. /* Cr-48 Chromebook (Codename Mario) */
  1303. .matches = {
  1304. DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
  1305. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  1306. },
  1307. },
  1308. #endif
  1309. { }
  1310. };
  1311. void __init synaptics_module_init(void)
  1312. {
  1313. impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
  1314. broken_olpc_ec = dmi_check_system(olpc_dmi_table);
  1315. cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
  1316. }
  1317. static int synaptics_init_ps2(struct psmouse *psmouse,
  1318. struct synaptics_device_info *info,
  1319. bool absolute_mode)
  1320. {
  1321. struct synaptics_data *priv;
  1322. int err;
  1323. synaptics_apply_quirks(psmouse, info);
  1324. psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
  1325. if (!priv)
  1326. return -ENOMEM;
  1327. priv->info = *info;
  1328. priv->absolute_mode = absolute_mode;
  1329. if (SYN_ID_DISGEST_SUPPORTED(info->identity))
  1330. priv->disable_gesture = true;
  1331. /*
  1332. * Unfortunately ForcePad capability is not exported over PS/2,
  1333. * so we have to resort to checking PNP IDs.
  1334. */
  1335. priv->is_forcepad = psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids);
  1336. err = synaptics_set_mode(psmouse);
  1337. if (err) {
  1338. psmouse_err(psmouse, "Unable to initialize device.\n");
  1339. goto init_fail;
  1340. }
  1341. priv->pkt_type = SYN_MODEL_NEWABS(info->model_id) ?
  1342. SYN_NEWABS : SYN_OLDABS;
  1343. psmouse_info(psmouse,
  1344. "Touchpad model: %lu, fw: %lu.%lu, id: %#x, caps: %#x/%#x/%#x/%#x, board id: %u, fw id: %u\n",
  1345. SYN_ID_MODEL(info->identity),
  1346. SYN_ID_MAJOR(info->identity), SYN_ID_MINOR(info->identity),
  1347. info->model_id,
  1348. info->capabilities, info->ext_cap, info->ext_cap_0c,
  1349. info->ext_cap_10, info->board_id, info->firmware_id);
  1350. err = set_input_params(psmouse, priv);
  1351. if (err) {
  1352. psmouse_err(psmouse,
  1353. "failed to set up capabilities: %d\n", err);
  1354. goto init_fail;
  1355. }
  1356. /*
  1357. * Encode touchpad model so that it can be used to set
  1358. * input device->id.version and be visible to userspace.
  1359. * Because version is __u16 we have to drop something.
  1360. * Hardware info bits seem to be good candidates as they
  1361. * are documented to be for Synaptics corp. internal use.
  1362. */
  1363. psmouse->model = ((info->model_id & 0x00ff0000) >> 8) |
  1364. (info->model_id & 0x000000ff);
  1365. if (absolute_mode) {
  1366. psmouse->protocol_handler = synaptics_process_byte;
  1367. psmouse->pktsize = 6;
  1368. } else {
  1369. /* Relative mode follows standard PS/2 mouse protocol */
  1370. psmouse->protocol_handler = psmouse_process_byte;
  1371. psmouse->pktsize = 3;
  1372. }
  1373. psmouse->set_rate = synaptics_set_rate;
  1374. psmouse->disconnect = synaptics_disconnect;
  1375. psmouse->reconnect = synaptics_reconnect;
  1376. psmouse->fast_reconnect = NULL;
  1377. psmouse->cleanup = synaptics_reset;
  1378. /* Synaptics can usually stay in sync without extra help */
  1379. psmouse->resync_time = 0;
  1380. if (SYN_CAP_PASS_THROUGH(info->capabilities))
  1381. synaptics_pt_create(psmouse);
  1382. /*
  1383. * Toshiba's KBC seems to have trouble handling data from
  1384. * Synaptics at full rate. Switch to a lower rate (roughly
  1385. * the same rate as a standard PS/2 mouse).
  1386. */
  1387. if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
  1388. psmouse_info(psmouse,
  1389. "Toshiba %s detected, limiting rate to 40pps.\n",
  1390. dmi_get_system_info(DMI_PRODUCT_NAME));
  1391. psmouse->rate = 40;
  1392. }
  1393. if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(info->identity)) {
  1394. err = device_create_file(&psmouse->ps2dev.serio->dev,
  1395. &psmouse_attr_disable_gesture.dattr);
  1396. if (err) {
  1397. psmouse_err(psmouse,
  1398. "Failed to create disable_gesture attribute (%d)",
  1399. err);
  1400. goto init_fail;
  1401. }
  1402. }
  1403. return 0;
  1404. init_fail:
  1405. kfree(priv);
  1406. return err;
  1407. }
  1408. static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
  1409. {
  1410. struct synaptics_device_info info;
  1411. int error;
  1412. psmouse_reset(psmouse);
  1413. error = synaptics_query_hardware(psmouse, &info);
  1414. if (error) {
  1415. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1416. return error;
  1417. }
  1418. return synaptics_init_ps2(psmouse, &info, absolute_mode);
  1419. }
  1420. int synaptics_init_absolute(struct psmouse *psmouse)
  1421. {
  1422. return __synaptics_init(psmouse, true);
  1423. }
  1424. int synaptics_init_relative(struct psmouse *psmouse)
  1425. {
  1426. return __synaptics_init(psmouse, false);
  1427. }
  1428. static int synaptics_setup_ps2(struct psmouse *psmouse,
  1429. struct synaptics_device_info *info)
  1430. {
  1431. bool absolute_mode = true;
  1432. int error;
  1433. /*
  1434. * The OLPC XO has issues with Synaptics' absolute mode; the constant
  1435. * packet spew overloads the EC such that key presses on the keyboard
  1436. * are missed. Given that, don't even attempt to use Absolute mode.
  1437. * Relative mode seems to work just fine.
  1438. */
  1439. if (broken_olpc_ec) {
  1440. psmouse_info(psmouse,
  1441. "OLPC XO detected, forcing relative protocol.\n");
  1442. absolute_mode = false;
  1443. }
  1444. error = synaptics_init_ps2(psmouse, info, absolute_mode);
  1445. if (error)
  1446. return error;
  1447. return absolute_mode ? PSMOUSE_SYNAPTICS : PSMOUSE_SYNAPTICS_RELATIVE;
  1448. }
  1449. #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1450. void __init synaptics_module_init(void)
  1451. {
  1452. }
  1453. static int __maybe_unused
  1454. synaptics_setup_ps2(struct psmouse *psmouse,
  1455. struct synaptics_device_info *info)
  1456. {
  1457. return -ENOSYS;
  1458. }
  1459. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */
  1460. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS
  1461. /*
  1462. * The newest Synaptics device can use a secondary bus (called InterTouch) which
  1463. * provides a better bandwidth and allow a better control of the touchpads.
  1464. * This is used to decide if we need to use this bus or not.
  1465. */
  1466. enum {
  1467. SYNAPTICS_INTERTOUCH_NOT_SET = -1,
  1468. SYNAPTICS_INTERTOUCH_OFF,
  1469. SYNAPTICS_INTERTOUCH_ON,
  1470. };
  1471. static int synaptics_intertouch = IS_ENABLED(CONFIG_RMI4_SMB) ?
  1472. SYNAPTICS_INTERTOUCH_NOT_SET : SYNAPTICS_INTERTOUCH_OFF;
  1473. module_param_named(synaptics_intertouch, synaptics_intertouch, int, 0644);
  1474. MODULE_PARM_DESC(synaptics_intertouch, "Use a secondary bus for the Synaptics device.");
  1475. static int synaptics_create_intertouch(struct psmouse *psmouse,
  1476. struct synaptics_device_info *info,
  1477. bool leave_breadcrumbs)
  1478. {
  1479. bool topbuttonpad =
  1480. psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1481. !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10);
  1482. const struct rmi_device_platform_data pdata = {
  1483. .reset_delay_ms = 30,
  1484. .sensor_pdata = {
  1485. .sensor_type = rmi_sensor_touchpad,
  1486. .axis_align.flip_y = true,
  1487. .kernel_tracking = false,
  1488. .topbuttonpad = topbuttonpad,
  1489. },
  1490. .gpio_data = {
  1491. .buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
  1492. .trackstick_buttons =
  1493. !!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
  1494. },
  1495. };
  1496. const struct i2c_board_info intertouch_board = {
  1497. I2C_BOARD_INFO("rmi4_smbus", 0x2c),
  1498. .flags = I2C_CLIENT_HOST_NOTIFY,
  1499. };
  1500. return psmouse_smbus_init(psmouse, &intertouch_board,
  1501. &pdata, sizeof(pdata), true,
  1502. leave_breadcrumbs);
  1503. }
  1504. /*
  1505. * synaptics_setup_intertouch - called once the PS/2 devices are enumerated
  1506. * and decides to instantiate a SMBus InterTouch device.
  1507. */
  1508. static int synaptics_setup_intertouch(struct psmouse *psmouse,
  1509. struct synaptics_device_info *info,
  1510. bool leave_breadcrumbs)
  1511. {
  1512. int error;
  1513. if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_OFF)
  1514. return -ENXIO;
  1515. if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_NOT_SET) {
  1516. if (!psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
  1517. !psmouse_matches_pnp_id(psmouse, smbus_pnp_ids)) {
  1518. if (!psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids))
  1519. psmouse_info(psmouse,
  1520. "Your touchpad (%s) says it can support a different bus. "
  1521. "If i2c-hid and hid-rmi are not used, you might want to try setting psmouse.synaptics_intertouch to 1 and report this to [email protected].\n",
  1522. psmouse->ps2dev.serio->firmware_id);
  1523. return -ENXIO;
  1524. }
  1525. }
  1526. psmouse_info(psmouse, "Trying to set up SMBus access\n");
  1527. error = synaptics_create_intertouch(psmouse, info, leave_breadcrumbs);
  1528. if (error) {
  1529. if (error == -EAGAIN)
  1530. psmouse_info(psmouse, "SMbus companion is not ready yet\n");
  1531. else
  1532. psmouse_err(psmouse, "unable to create intertouch device\n");
  1533. return error;
  1534. }
  1535. return 0;
  1536. }
  1537. int synaptics_init_smbus(struct psmouse *psmouse)
  1538. {
  1539. struct synaptics_device_info info;
  1540. int error;
  1541. psmouse_reset(psmouse);
  1542. error = synaptics_query_hardware(psmouse, &info);
  1543. if (error) {
  1544. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1545. return error;
  1546. }
  1547. if (!SYN_CAP_INTERTOUCH(info.ext_cap_0c))
  1548. return -ENXIO;
  1549. return synaptics_create_intertouch(psmouse, &info, false);
  1550. }
  1551. #else /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1552. static int __maybe_unused
  1553. synaptics_setup_intertouch(struct psmouse *psmouse,
  1554. struct synaptics_device_info *info,
  1555. bool leave_breadcrumbs)
  1556. {
  1557. return -ENOSYS;
  1558. }
  1559. int synaptics_init_smbus(struct psmouse *psmouse)
  1560. {
  1561. return -ENOSYS;
  1562. }
  1563. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1564. #if defined(CONFIG_MOUSE_PS2_SYNAPTICS) || \
  1565. defined(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)
  1566. int synaptics_init(struct psmouse *psmouse)
  1567. {
  1568. struct synaptics_device_info info;
  1569. int error;
  1570. int retval;
  1571. psmouse_reset(psmouse);
  1572. error = synaptics_query_hardware(psmouse, &info);
  1573. if (error) {
  1574. psmouse_err(psmouse, "Unable to query device: %d\n", error);
  1575. return error;
  1576. }
  1577. if (SYN_CAP_INTERTOUCH(info.ext_cap_0c)) {
  1578. if ((!IS_ENABLED(CONFIG_RMI4_SMB) ||
  1579. !IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS)) &&
  1580. /* Forcepads need F21, which is not ready */
  1581. !psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids)) {
  1582. psmouse_warn(psmouse,
  1583. "The touchpad can support a better bus than the too old PS/2 protocol. "
  1584. "Make sure MOUSE_PS2_SYNAPTICS_SMBUS and RMI4_SMB are enabled to get a better touchpad experience.\n");
  1585. }
  1586. error = synaptics_setup_intertouch(psmouse, &info, true);
  1587. if (!error)
  1588. return PSMOUSE_SYNAPTICS_SMBUS;
  1589. }
  1590. retval = synaptics_setup_ps2(psmouse, &info);
  1591. if (retval < 0) {
  1592. /*
  1593. * Not using any flavor of Synaptics support, so clean up
  1594. * SMbus breadcrumbs, if any.
  1595. */
  1596. psmouse_smbus_cleanup(psmouse);
  1597. }
  1598. return retval;
  1599. }
  1600. #else /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */
  1601. int synaptics_init(struct psmouse *psmouse)
  1602. {
  1603. return -ENOSYS;
  1604. }
  1605. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS || CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS */