synaptics.c 51 KB

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