synaptics.c 48 KB

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