elantech.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  1. /*
  2. * Elantech Touchpad driver (v6)
  3. *
  4. * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * Trademarks are the property of their respective owners.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/dmi.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/input.h>
  17. #include <linux/input/mt.h>
  18. #include <linux/serio.h>
  19. #include <linux/libps2.h>
  20. #include <asm/unaligned.h>
  21. #include "psmouse.h"
  22. #include "elantech.h"
  23. #define elantech_debug(fmt, ...) \
  24. do { \
  25. if (etd->debug) \
  26. psmouse_printk(KERN_DEBUG, psmouse, \
  27. fmt, ##__VA_ARGS__); \
  28. } while (0)
  29. /*
  30. * Send a Synaptics style sliced query command
  31. */
  32. static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c,
  33. unsigned char *param)
  34. {
  35. if (psmouse_sliced_command(psmouse, c) ||
  36. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  37. psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c);
  38. return -1;
  39. }
  40. return 0;
  41. }
  42. /*
  43. * V3 and later support this fast command
  44. */
  45. static int elantech_send_cmd(struct psmouse *psmouse, unsigned char c,
  46. unsigned char *param)
  47. {
  48. struct ps2dev *ps2dev = &psmouse->ps2dev;
  49. if (ps2_command(ps2dev, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  50. ps2_command(ps2dev, NULL, c) ||
  51. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  52. psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c);
  53. return -1;
  54. }
  55. return 0;
  56. }
  57. /*
  58. * A retrying version of ps2_command
  59. */
  60. static int elantech_ps2_command(struct psmouse *psmouse,
  61. unsigned char *param, int command)
  62. {
  63. struct ps2dev *ps2dev = &psmouse->ps2dev;
  64. struct elantech_data *etd = psmouse->private;
  65. int rc;
  66. int tries = ETP_PS2_COMMAND_TRIES;
  67. do {
  68. rc = ps2_command(ps2dev, param, command);
  69. if (rc == 0)
  70. break;
  71. tries--;
  72. elantech_debug("retrying ps2 command 0x%02x (%d).\n",
  73. command, tries);
  74. msleep(ETP_PS2_COMMAND_DELAY);
  75. } while (tries > 0);
  76. if (rc)
  77. psmouse_err(psmouse, "ps2 command 0x%02x failed.\n", command);
  78. return rc;
  79. }
  80. /*
  81. * Send an Elantech style special command to read a value from a register
  82. */
  83. static int elantech_read_reg(struct psmouse *psmouse, unsigned char reg,
  84. unsigned char *val)
  85. {
  86. struct elantech_data *etd = psmouse->private;
  87. unsigned char param[3];
  88. int rc = 0;
  89. if (reg < 0x07 || reg > 0x26)
  90. return -1;
  91. if (reg > 0x11 && reg < 0x20)
  92. return -1;
  93. switch (etd->hw_version) {
  94. case 1:
  95. if (psmouse_sliced_command(psmouse, ETP_REGISTER_READ) ||
  96. psmouse_sliced_command(psmouse, reg) ||
  97. ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  98. rc = -1;
  99. }
  100. break;
  101. case 2:
  102. if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  103. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READ) ||
  104. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  105. elantech_ps2_command(psmouse, NULL, reg) ||
  106. elantech_ps2_command(psmouse, param, PSMOUSE_CMD_GETINFO)) {
  107. rc = -1;
  108. }
  109. break;
  110. case 3 ... 4:
  111. if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  112. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
  113. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  114. elantech_ps2_command(psmouse, NULL, reg) ||
  115. elantech_ps2_command(psmouse, param, PSMOUSE_CMD_GETINFO)) {
  116. rc = -1;
  117. }
  118. break;
  119. }
  120. if (rc)
  121. psmouse_err(psmouse, "failed to read register 0x%02x.\n", reg);
  122. else if (etd->hw_version != 4)
  123. *val = param[0];
  124. else
  125. *val = param[1];
  126. return rc;
  127. }
  128. /*
  129. * Send an Elantech style special command to write a register with a value
  130. */
  131. static int elantech_write_reg(struct psmouse *psmouse, unsigned char reg,
  132. unsigned char val)
  133. {
  134. struct elantech_data *etd = psmouse->private;
  135. int rc = 0;
  136. if (reg < 0x07 || reg > 0x26)
  137. return -1;
  138. if (reg > 0x11 && reg < 0x20)
  139. return -1;
  140. switch (etd->hw_version) {
  141. case 1:
  142. if (psmouse_sliced_command(psmouse, ETP_REGISTER_WRITE) ||
  143. psmouse_sliced_command(psmouse, reg) ||
  144. psmouse_sliced_command(psmouse, val) ||
  145. ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) {
  146. rc = -1;
  147. }
  148. break;
  149. case 2:
  150. if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  151. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_WRITE) ||
  152. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  153. elantech_ps2_command(psmouse, NULL, reg) ||
  154. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  155. elantech_ps2_command(psmouse, NULL, val) ||
  156. elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
  157. rc = -1;
  158. }
  159. break;
  160. case 3:
  161. if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  162. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
  163. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  164. elantech_ps2_command(psmouse, NULL, reg) ||
  165. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  166. elantech_ps2_command(psmouse, NULL, val) ||
  167. elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
  168. rc = -1;
  169. }
  170. break;
  171. case 4:
  172. if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  173. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
  174. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  175. elantech_ps2_command(psmouse, NULL, reg) ||
  176. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  177. elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
  178. elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
  179. elantech_ps2_command(psmouse, NULL, val) ||
  180. elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
  181. rc = -1;
  182. }
  183. break;
  184. }
  185. if (rc)
  186. psmouse_err(psmouse,
  187. "failed to write register 0x%02x with value 0x%02x.\n",
  188. reg, val);
  189. return rc;
  190. }
  191. /*
  192. * Dump a complete mouse movement packet to the syslog
  193. */
  194. static void elantech_packet_dump(struct psmouse *psmouse)
  195. {
  196. psmouse_printk(KERN_DEBUG, psmouse, "PS/2 packet [%*ph]\n",
  197. psmouse->pktsize, psmouse->packet);
  198. }
  199. /*
  200. * Interpret complete data packets and report absolute mode input events for
  201. * hardware version 1. (4 byte packets)
  202. */
  203. static void elantech_report_absolute_v1(struct psmouse *psmouse)
  204. {
  205. struct input_dev *dev = psmouse->dev;
  206. struct elantech_data *etd = psmouse->private;
  207. unsigned char *packet = psmouse->packet;
  208. int fingers;
  209. if (etd->fw_version < 0x020000) {
  210. /*
  211. * byte 0: D U p1 p2 1 p3 R L
  212. * byte 1: f 0 th tw x9 x8 y9 y8
  213. */
  214. fingers = ((packet[1] & 0x80) >> 7) +
  215. ((packet[1] & 0x30) >> 4);
  216. } else {
  217. /*
  218. * byte 0: n1 n0 p2 p1 1 p3 R L
  219. * byte 1: 0 0 0 0 x9 x8 y9 y8
  220. */
  221. fingers = (packet[0] & 0xc0) >> 6;
  222. }
  223. if (etd->jumpy_cursor) {
  224. if (fingers != 1) {
  225. etd->single_finger_reports = 0;
  226. } else if (etd->single_finger_reports < 2) {
  227. /* Discard first 2 reports of one finger, bogus */
  228. etd->single_finger_reports++;
  229. elantech_debug("discarding packet\n");
  230. return;
  231. }
  232. }
  233. input_report_key(dev, BTN_TOUCH, fingers != 0);
  234. /*
  235. * byte 2: x7 x6 x5 x4 x3 x2 x1 x0
  236. * byte 3: y7 y6 y5 y4 y3 y2 y1 y0
  237. */
  238. if (fingers) {
  239. input_report_abs(dev, ABS_X,
  240. ((packet[1] & 0x0c) << 6) | packet[2]);
  241. input_report_abs(dev, ABS_Y,
  242. etd->y_max - (((packet[1] & 0x03) << 8) | packet[3]));
  243. }
  244. input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
  245. input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
  246. input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
  247. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  248. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  249. if (etd->fw_version < 0x020000 &&
  250. (etd->capabilities[0] & ETP_CAP_HAS_ROCKER)) {
  251. /* rocker up */
  252. input_report_key(dev, BTN_FORWARD, packet[0] & 0x40);
  253. /* rocker down */
  254. input_report_key(dev, BTN_BACK, packet[0] & 0x80);
  255. }
  256. input_sync(dev);
  257. }
  258. static void elantech_set_slot(struct input_dev *dev, int slot, bool active,
  259. unsigned int x, unsigned int y)
  260. {
  261. input_mt_slot(dev, slot);
  262. input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
  263. if (active) {
  264. input_report_abs(dev, ABS_MT_POSITION_X, x);
  265. input_report_abs(dev, ABS_MT_POSITION_Y, y);
  266. }
  267. }
  268. /* x1 < x2 and y1 < y2 when two fingers, x = y = 0 when not pressed */
  269. static void elantech_report_semi_mt_data(struct input_dev *dev,
  270. unsigned int num_fingers,
  271. unsigned int x1, unsigned int y1,
  272. unsigned int x2, unsigned int y2)
  273. {
  274. elantech_set_slot(dev, 0, num_fingers != 0, x1, y1);
  275. elantech_set_slot(dev, 1, num_fingers >= 2, x2, y2);
  276. }
  277. /*
  278. * Interpret complete data packets and report absolute mode input events for
  279. * hardware version 2. (6 byte packets)
  280. */
  281. static void elantech_report_absolute_v2(struct psmouse *psmouse)
  282. {
  283. struct elantech_data *etd = psmouse->private;
  284. struct input_dev *dev = psmouse->dev;
  285. unsigned char *packet = psmouse->packet;
  286. unsigned int fingers, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  287. unsigned int width = 0, pres = 0;
  288. /* byte 0: n1 n0 . . . . R L */
  289. fingers = (packet[0] & 0xc0) >> 6;
  290. switch (fingers) {
  291. case 3:
  292. /*
  293. * Same as one finger, except report of more than 3 fingers:
  294. * byte 3: n4 . w1 w0 . . . .
  295. */
  296. if (packet[3] & 0x80)
  297. fingers = 4;
  298. /* pass through... */
  299. case 1:
  300. /*
  301. * byte 1: . . . . x11 x10 x9 x8
  302. * byte 2: x7 x6 x5 x4 x4 x2 x1 x0
  303. */
  304. x1 = ((packet[1] & 0x0f) << 8) | packet[2];
  305. /*
  306. * byte 4: . . . . y11 y10 y9 y8
  307. * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
  308. */
  309. y1 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
  310. pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
  311. width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4);
  312. break;
  313. case 2:
  314. /*
  315. * The coordinate of each finger is reported separately
  316. * with a lower resolution for two finger touches:
  317. * byte 0: . . ay8 ax8 . . . .
  318. * byte 1: ax7 ax6 ax5 ax4 ax3 ax2 ax1 ax0
  319. */
  320. x1 = (((packet[0] & 0x10) << 4) | packet[1]) << 2;
  321. /* byte 2: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0 */
  322. y1 = etd->y_max -
  323. ((((packet[0] & 0x20) << 3) | packet[2]) << 2);
  324. /*
  325. * byte 3: . . by8 bx8 . . . .
  326. * byte 4: bx7 bx6 bx5 bx4 bx3 bx2 bx1 bx0
  327. */
  328. x2 = (((packet[3] & 0x10) << 4) | packet[4]) << 2;
  329. /* byte 5: by7 by8 by5 by4 by3 by2 by1 by0 */
  330. y2 = etd->y_max -
  331. ((((packet[3] & 0x20) << 3) | packet[5]) << 2);
  332. /* Unknown so just report sensible values */
  333. pres = 127;
  334. width = 7;
  335. break;
  336. }
  337. input_report_key(dev, BTN_TOUCH, fingers != 0);
  338. if (fingers != 0) {
  339. input_report_abs(dev, ABS_X, x1);
  340. input_report_abs(dev, ABS_Y, y1);
  341. }
  342. elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
  343. input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
  344. input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
  345. input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
  346. input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
  347. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  348. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  349. if (etd->reports_pressure) {
  350. input_report_abs(dev, ABS_PRESSURE, pres);
  351. input_report_abs(dev, ABS_TOOL_WIDTH, width);
  352. }
  353. input_sync(dev);
  354. }
  355. static void elantech_report_trackpoint(struct psmouse *psmouse,
  356. int packet_type)
  357. {
  358. /*
  359. * byte 0: 0 0 sx sy 0 M R L
  360. * byte 1:~sx 0 0 0 0 0 0 0
  361. * byte 2:~sy 0 0 0 0 0 0 0
  362. * byte 3: 0 0 ~sy ~sx 0 1 1 0
  363. * byte 4: x7 x6 x5 x4 x3 x2 x1 x0
  364. * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
  365. *
  366. * x and y are written in two's complement spread
  367. * over 9 bits with sx/sy the relative top bit and
  368. * x7..x0 and y7..y0 the lower bits.
  369. * The sign of y is opposite to what the input driver
  370. * expects for a relative movement
  371. */
  372. struct elantech_data *etd = psmouse->private;
  373. struct input_dev *tp_dev = etd->tp_dev;
  374. unsigned char *packet = psmouse->packet;
  375. int x, y;
  376. u32 t;
  377. t = get_unaligned_le32(&packet[0]);
  378. switch (t & ~7U) {
  379. case 0x06000030U:
  380. case 0x16008020U:
  381. case 0x26800010U:
  382. case 0x36808000U:
  383. x = packet[4] - (int)((packet[1]^0x80) << 1);
  384. y = (int)((packet[2]^0x80) << 1) - packet[5];
  385. input_report_key(tp_dev, BTN_LEFT, packet[0] & 0x01);
  386. input_report_key(tp_dev, BTN_RIGHT, packet[0] & 0x02);
  387. input_report_key(tp_dev, BTN_MIDDLE, packet[0] & 0x04);
  388. input_report_rel(tp_dev, REL_X, x);
  389. input_report_rel(tp_dev, REL_Y, y);
  390. input_sync(tp_dev);
  391. break;
  392. default:
  393. /* Dump unexpected packet sequences if debug=1 (default) */
  394. if (etd->debug == 1)
  395. elantech_packet_dump(psmouse);
  396. break;
  397. }
  398. }
  399. /*
  400. * Interpret complete data packets and report absolute mode input events for
  401. * hardware version 3. (12 byte packets for two fingers)
  402. */
  403. static void elantech_report_absolute_v3(struct psmouse *psmouse,
  404. int packet_type)
  405. {
  406. struct input_dev *dev = psmouse->dev;
  407. struct elantech_data *etd = psmouse->private;
  408. unsigned char *packet = psmouse->packet;
  409. unsigned int fingers = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  410. unsigned int width = 0, pres = 0;
  411. /* byte 0: n1 n0 . . . . R L */
  412. fingers = (packet[0] & 0xc0) >> 6;
  413. switch (fingers) {
  414. case 3:
  415. case 1:
  416. /*
  417. * byte 1: . . . . x11 x10 x9 x8
  418. * byte 2: x7 x6 x5 x4 x4 x2 x1 x0
  419. */
  420. x1 = ((packet[1] & 0x0f) << 8) | packet[2];
  421. /*
  422. * byte 4: . . . . y11 y10 y9 y8
  423. * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
  424. */
  425. y1 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
  426. break;
  427. case 2:
  428. if (packet_type == PACKET_V3_HEAD) {
  429. /*
  430. * byte 1: . . . . ax11 ax10 ax9 ax8
  431. * byte 2: ax7 ax6 ax5 ax4 ax3 ax2 ax1 ax0
  432. */
  433. etd->mt[0].x = ((packet[1] & 0x0f) << 8) | packet[2];
  434. /*
  435. * byte 4: . . . . ay11 ay10 ay9 ay8
  436. * byte 5: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0
  437. */
  438. etd->mt[0].y = etd->y_max -
  439. (((packet[4] & 0x0f) << 8) | packet[5]);
  440. /*
  441. * wait for next packet
  442. */
  443. return;
  444. }
  445. /* packet_type == PACKET_V3_TAIL */
  446. x1 = etd->mt[0].x;
  447. y1 = etd->mt[0].y;
  448. x2 = ((packet[1] & 0x0f) << 8) | packet[2];
  449. y2 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
  450. break;
  451. }
  452. pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
  453. width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4);
  454. input_report_key(dev, BTN_TOUCH, fingers != 0);
  455. if (fingers != 0) {
  456. input_report_abs(dev, ABS_X, x1);
  457. input_report_abs(dev, ABS_Y, y1);
  458. }
  459. elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
  460. input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
  461. input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
  462. input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
  463. /* For clickpads map both buttons to BTN_LEFT */
  464. if (etd->fw_version & 0x001000) {
  465. input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
  466. } else {
  467. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  468. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  469. }
  470. input_report_abs(dev, ABS_PRESSURE, pres);
  471. input_report_abs(dev, ABS_TOOL_WIDTH, width);
  472. input_sync(dev);
  473. }
  474. static void elantech_input_sync_v4(struct psmouse *psmouse)
  475. {
  476. struct input_dev *dev = psmouse->dev;
  477. struct elantech_data *etd = psmouse->private;
  478. unsigned char *packet = psmouse->packet;
  479. /* For clickpads map both buttons to BTN_LEFT */
  480. if (etd->fw_version & 0x001000) {
  481. input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
  482. } else {
  483. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  484. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  485. input_report_key(dev, BTN_MIDDLE, packet[0] & 0x04);
  486. }
  487. input_mt_report_pointer_emulation(dev, true);
  488. input_sync(dev);
  489. }
  490. static void process_packet_status_v4(struct psmouse *psmouse)
  491. {
  492. struct input_dev *dev = psmouse->dev;
  493. unsigned char *packet = psmouse->packet;
  494. unsigned fingers;
  495. int i;
  496. /* notify finger state change */
  497. fingers = packet[1] & 0x1f;
  498. for (i = 0; i < ETP_MAX_FINGERS; i++) {
  499. if ((fingers & (1 << i)) == 0) {
  500. input_mt_slot(dev, i);
  501. input_mt_report_slot_state(dev, MT_TOOL_FINGER, false);
  502. }
  503. }
  504. elantech_input_sync_v4(psmouse);
  505. }
  506. static void process_packet_head_v4(struct psmouse *psmouse)
  507. {
  508. struct input_dev *dev = psmouse->dev;
  509. struct elantech_data *etd = psmouse->private;
  510. unsigned char *packet = psmouse->packet;
  511. int id = ((packet[3] & 0xe0) >> 5) - 1;
  512. int pres, traces;
  513. if (id < 0)
  514. return;
  515. etd->mt[id].x = ((packet[1] & 0x0f) << 8) | packet[2];
  516. etd->mt[id].y = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
  517. pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
  518. traces = (packet[0] & 0xf0) >> 4;
  519. input_mt_slot(dev, id);
  520. input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
  521. input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x);
  522. input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y);
  523. input_report_abs(dev, ABS_MT_PRESSURE, pres);
  524. input_report_abs(dev, ABS_MT_TOUCH_MAJOR, traces * etd->width);
  525. /* report this for backwards compatibility */
  526. input_report_abs(dev, ABS_TOOL_WIDTH, traces);
  527. elantech_input_sync_v4(psmouse);
  528. }
  529. static void process_packet_motion_v4(struct psmouse *psmouse)
  530. {
  531. struct input_dev *dev = psmouse->dev;
  532. struct elantech_data *etd = psmouse->private;
  533. unsigned char *packet = psmouse->packet;
  534. int weight, delta_x1 = 0, delta_y1 = 0, delta_x2 = 0, delta_y2 = 0;
  535. int id, sid;
  536. id = ((packet[0] & 0xe0) >> 5) - 1;
  537. if (id < 0)
  538. return;
  539. sid = ((packet[3] & 0xe0) >> 5) - 1;
  540. weight = (packet[0] & 0x10) ? ETP_WEIGHT_VALUE : 1;
  541. /*
  542. * Motion packets give us the delta of x, y values of specific fingers,
  543. * but in two's complement. Let the compiler do the conversion for us.
  544. * Also _enlarge_ the numbers to int, in case of overflow.
  545. */
  546. delta_x1 = (signed char)packet[1];
  547. delta_y1 = (signed char)packet[2];
  548. delta_x2 = (signed char)packet[4];
  549. delta_y2 = (signed char)packet[5];
  550. etd->mt[id].x += delta_x1 * weight;
  551. etd->mt[id].y -= delta_y1 * weight;
  552. input_mt_slot(dev, id);
  553. input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x);
  554. input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y);
  555. if (sid >= 0) {
  556. etd->mt[sid].x += delta_x2 * weight;
  557. etd->mt[sid].y -= delta_y2 * weight;
  558. input_mt_slot(dev, sid);
  559. input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[sid].x);
  560. input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[sid].y);
  561. }
  562. elantech_input_sync_v4(psmouse);
  563. }
  564. static void elantech_report_absolute_v4(struct psmouse *psmouse,
  565. int packet_type)
  566. {
  567. switch (packet_type) {
  568. case PACKET_V4_STATUS:
  569. process_packet_status_v4(psmouse);
  570. break;
  571. case PACKET_V4_HEAD:
  572. process_packet_head_v4(psmouse);
  573. break;
  574. case PACKET_V4_MOTION:
  575. process_packet_motion_v4(psmouse);
  576. break;
  577. case PACKET_UNKNOWN:
  578. default:
  579. /* impossible to get here */
  580. break;
  581. }
  582. }
  583. static int elantech_packet_check_v1(struct psmouse *psmouse)
  584. {
  585. struct elantech_data *etd = psmouse->private;
  586. unsigned char *packet = psmouse->packet;
  587. unsigned char p1, p2, p3;
  588. /* Parity bits are placed differently */
  589. if (etd->fw_version < 0x020000) {
  590. /* byte 0: D U p1 p2 1 p3 R L */
  591. p1 = (packet[0] & 0x20) >> 5;
  592. p2 = (packet[0] & 0x10) >> 4;
  593. } else {
  594. /* byte 0: n1 n0 p2 p1 1 p3 R L */
  595. p1 = (packet[0] & 0x10) >> 4;
  596. p2 = (packet[0] & 0x20) >> 5;
  597. }
  598. p3 = (packet[0] & 0x04) >> 2;
  599. return etd->parity[packet[1]] == p1 &&
  600. etd->parity[packet[2]] == p2 &&
  601. etd->parity[packet[3]] == p3;
  602. }
  603. static int elantech_debounce_check_v2(struct psmouse *psmouse)
  604. {
  605. /*
  606. * When we encounter packet that matches this exactly, it means the
  607. * hardware is in debounce status. Just ignore the whole packet.
  608. */
  609. static const u8 debounce_packet[] = {
  610. 0x84, 0xff, 0xff, 0x02, 0xff, 0xff
  611. };
  612. unsigned char *packet = psmouse->packet;
  613. return !memcmp(packet, debounce_packet, sizeof(debounce_packet));
  614. }
  615. static int elantech_packet_check_v2(struct psmouse *psmouse)
  616. {
  617. struct elantech_data *etd = psmouse->private;
  618. unsigned char *packet = psmouse->packet;
  619. /*
  620. * V2 hardware has two flavors. Older ones that do not report pressure,
  621. * and newer ones that reports pressure and width. With newer ones, all
  622. * packets (1, 2, 3 finger touch) have the same constant bits. With
  623. * older ones, 1/3 finger touch packets and 2 finger touch packets
  624. * have different constant bits.
  625. * With all three cases, if the constant bits are not exactly what I
  626. * expected, I consider them invalid.
  627. */
  628. if (etd->reports_pressure)
  629. return (packet[0] & 0x0c) == 0x04 &&
  630. (packet[3] & 0x0f) == 0x02;
  631. if ((packet[0] & 0xc0) == 0x80)
  632. return (packet[0] & 0x0c) == 0x0c &&
  633. (packet[3] & 0x0e) == 0x08;
  634. return (packet[0] & 0x3c) == 0x3c &&
  635. (packet[1] & 0xf0) == 0x00 &&
  636. (packet[3] & 0x3e) == 0x38 &&
  637. (packet[4] & 0xf0) == 0x00;
  638. }
  639. /*
  640. * We check the constant bits to determine what packet type we get,
  641. * so packet checking is mandatory for v3 and later hardware.
  642. */
  643. static int elantech_packet_check_v3(struct psmouse *psmouse)
  644. {
  645. struct elantech_data *etd = psmouse->private;
  646. static const u8 debounce_packet[] = {
  647. 0xc4, 0xff, 0xff, 0x02, 0xff, 0xff
  648. };
  649. unsigned char *packet = psmouse->packet;
  650. /*
  651. * check debounce first, it has the same signature in byte 0
  652. * and byte 3 as PACKET_V3_HEAD.
  653. */
  654. if (!memcmp(packet, debounce_packet, sizeof(debounce_packet)))
  655. return PACKET_DEBOUNCE;
  656. /*
  657. * If the hardware flag 'crc_enabled' is set the packets have
  658. * different signatures.
  659. */
  660. if (etd->crc_enabled) {
  661. if ((packet[3] & 0x09) == 0x08)
  662. return PACKET_V3_HEAD;
  663. if ((packet[3] & 0x09) == 0x09)
  664. return PACKET_V3_TAIL;
  665. } else {
  666. if ((packet[0] & 0x0c) == 0x04 && (packet[3] & 0xcf) == 0x02)
  667. return PACKET_V3_HEAD;
  668. if ((packet[0] & 0x0c) == 0x0c && (packet[3] & 0xce) == 0x0c)
  669. return PACKET_V3_TAIL;
  670. if ((packet[3] & 0x0f) == 0x06)
  671. return PACKET_TRACKPOINT;
  672. }
  673. return PACKET_UNKNOWN;
  674. }
  675. static int elantech_packet_check_v4(struct psmouse *psmouse)
  676. {
  677. struct elantech_data *etd = psmouse->private;
  678. unsigned char *packet = psmouse->packet;
  679. unsigned char packet_type = packet[3] & 0x03;
  680. unsigned int ic_version;
  681. bool sanity_check;
  682. if (etd->tp_dev && (packet[3] & 0x0f) == 0x06)
  683. return PACKET_TRACKPOINT;
  684. /* This represents the version of IC body. */
  685. ic_version = (etd->fw_version & 0x0f0000) >> 16;
  686. /*
  687. * Sanity check based on the constant bits of a packet.
  688. * The constant bits change depending on the value of
  689. * the hardware flag 'crc_enabled' and the version of
  690. * the IC body, but are the same for every packet,
  691. * regardless of the type.
  692. */
  693. if (etd->crc_enabled)
  694. sanity_check = ((packet[3] & 0x08) == 0x00);
  695. else if (ic_version == 7 && etd->samples[1] == 0x2A)
  696. sanity_check = ((packet[3] & 0x1c) == 0x10);
  697. else
  698. sanity_check = ((packet[0] & 0x0c) == 0x04 &&
  699. (packet[3] & 0x1c) == 0x10);
  700. if (!sanity_check)
  701. return PACKET_UNKNOWN;
  702. switch (packet_type) {
  703. case 0:
  704. return PACKET_V4_STATUS;
  705. case 1:
  706. return PACKET_V4_HEAD;
  707. case 2:
  708. return PACKET_V4_MOTION;
  709. }
  710. return PACKET_UNKNOWN;
  711. }
  712. /*
  713. * Process byte stream from mouse and handle complete packets
  714. */
  715. static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
  716. {
  717. struct elantech_data *etd = psmouse->private;
  718. int packet_type;
  719. if (psmouse->pktcnt < psmouse->pktsize)
  720. return PSMOUSE_GOOD_DATA;
  721. if (etd->debug > 1)
  722. elantech_packet_dump(psmouse);
  723. switch (etd->hw_version) {
  724. case 1:
  725. if (etd->paritycheck && !elantech_packet_check_v1(psmouse))
  726. return PSMOUSE_BAD_DATA;
  727. elantech_report_absolute_v1(psmouse);
  728. break;
  729. case 2:
  730. /* ignore debounce */
  731. if (elantech_debounce_check_v2(psmouse))
  732. return PSMOUSE_FULL_PACKET;
  733. if (etd->paritycheck && !elantech_packet_check_v2(psmouse))
  734. return PSMOUSE_BAD_DATA;
  735. elantech_report_absolute_v2(psmouse);
  736. break;
  737. case 3:
  738. packet_type = elantech_packet_check_v3(psmouse);
  739. switch (packet_type) {
  740. case PACKET_UNKNOWN:
  741. return PSMOUSE_BAD_DATA;
  742. case PACKET_DEBOUNCE:
  743. /* ignore debounce */
  744. break;
  745. case PACKET_TRACKPOINT:
  746. elantech_report_trackpoint(psmouse, packet_type);
  747. break;
  748. default:
  749. elantech_report_absolute_v3(psmouse, packet_type);
  750. break;
  751. }
  752. break;
  753. case 4:
  754. packet_type = elantech_packet_check_v4(psmouse);
  755. switch (packet_type) {
  756. case PACKET_UNKNOWN:
  757. return PSMOUSE_BAD_DATA;
  758. case PACKET_TRACKPOINT:
  759. elantech_report_trackpoint(psmouse, packet_type);
  760. break;
  761. default:
  762. elantech_report_absolute_v4(psmouse, packet_type);
  763. break;
  764. }
  765. break;
  766. }
  767. return PSMOUSE_FULL_PACKET;
  768. }
  769. /*
  770. * This writes the reg_07 value again to the hardware at the end of every
  771. * set_rate call because the register loses its value. reg_07 allows setting
  772. * absolute mode on v4 hardware
  773. */
  774. static void elantech_set_rate_restore_reg_07(struct psmouse *psmouse,
  775. unsigned int rate)
  776. {
  777. struct elantech_data *etd = psmouse->private;
  778. etd->original_set_rate(psmouse, rate);
  779. if (elantech_write_reg(psmouse, 0x07, etd->reg_07))
  780. psmouse_err(psmouse, "restoring reg_07 failed\n");
  781. }
  782. /*
  783. * Put the touchpad into absolute mode
  784. */
  785. static int elantech_set_absolute_mode(struct psmouse *psmouse)
  786. {
  787. struct elantech_data *etd = psmouse->private;
  788. unsigned char val;
  789. int tries = ETP_READ_BACK_TRIES;
  790. int rc = 0;
  791. switch (etd->hw_version) {
  792. case 1:
  793. etd->reg_10 = 0x16;
  794. etd->reg_11 = 0x8f;
  795. if (elantech_write_reg(psmouse, 0x10, etd->reg_10) ||
  796. elantech_write_reg(psmouse, 0x11, etd->reg_11)) {
  797. rc = -1;
  798. }
  799. break;
  800. case 2:
  801. /* Windows driver values */
  802. etd->reg_10 = 0x54;
  803. etd->reg_11 = 0x88; /* 0x8a */
  804. etd->reg_21 = 0x60; /* 0x00 */
  805. if (elantech_write_reg(psmouse, 0x10, etd->reg_10) ||
  806. elantech_write_reg(psmouse, 0x11, etd->reg_11) ||
  807. elantech_write_reg(psmouse, 0x21, etd->reg_21)) {
  808. rc = -1;
  809. }
  810. break;
  811. case 3:
  812. if (etd->set_hw_resolution)
  813. etd->reg_10 = 0x0b;
  814. else
  815. etd->reg_10 = 0x01;
  816. if (elantech_write_reg(psmouse, 0x10, etd->reg_10))
  817. rc = -1;
  818. break;
  819. case 4:
  820. etd->reg_07 = 0x01;
  821. if (elantech_write_reg(psmouse, 0x07, etd->reg_07))
  822. rc = -1;
  823. goto skip_readback_reg_10; /* v4 has no reg 0x10 to read */
  824. }
  825. if (rc == 0) {
  826. /*
  827. * Read back reg 0x10. For hardware version 1 we must make
  828. * sure the absolute mode bit is set. For hardware version 2
  829. * the touchpad is probably initializing and not ready until
  830. * we read back the value we just wrote.
  831. */
  832. do {
  833. rc = elantech_read_reg(psmouse, 0x10, &val);
  834. if (rc == 0)
  835. break;
  836. tries--;
  837. elantech_debug("retrying read (%d).\n", tries);
  838. msleep(ETP_READ_BACK_DELAY);
  839. } while (tries > 0);
  840. if (rc) {
  841. psmouse_err(psmouse,
  842. "failed to read back register 0x10.\n");
  843. } else if (etd->hw_version == 1 &&
  844. !(val & ETP_R10_ABSOLUTE_MODE)) {
  845. psmouse_err(psmouse,
  846. "touchpad refuses to switch to absolute mode.\n");
  847. rc = -1;
  848. }
  849. }
  850. skip_readback_reg_10:
  851. if (rc)
  852. psmouse_err(psmouse, "failed to initialise registers.\n");
  853. return rc;
  854. }
  855. static int elantech_set_range(struct psmouse *psmouse,
  856. unsigned int *x_min, unsigned int *y_min,
  857. unsigned int *x_max, unsigned int *y_max,
  858. unsigned int *width)
  859. {
  860. struct elantech_data *etd = psmouse->private;
  861. unsigned char param[3];
  862. unsigned char traces;
  863. switch (etd->hw_version) {
  864. case 1:
  865. *x_min = ETP_XMIN_V1;
  866. *y_min = ETP_YMIN_V1;
  867. *x_max = ETP_XMAX_V1;
  868. *y_max = ETP_YMAX_V1;
  869. break;
  870. case 2:
  871. if (etd->fw_version == 0x020800 ||
  872. etd->fw_version == 0x020b00 ||
  873. etd->fw_version == 0x020030) {
  874. *x_min = ETP_XMIN_V2;
  875. *y_min = ETP_YMIN_V2;
  876. *x_max = ETP_XMAX_V2;
  877. *y_max = ETP_YMAX_V2;
  878. } else {
  879. int i;
  880. int fixed_dpi;
  881. i = (etd->fw_version > 0x020800 &&
  882. etd->fw_version < 0x020900) ? 1 : 2;
  883. if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
  884. return -1;
  885. fixed_dpi = param[1] & 0x10;
  886. if (((etd->fw_version >> 16) == 0x14) && fixed_dpi) {
  887. if (etd->send_cmd(psmouse, ETP_SAMPLE_QUERY, param))
  888. return -1;
  889. *x_max = (etd->capabilities[1] - i) * param[1] / 2;
  890. *y_max = (etd->capabilities[2] - i) * param[2] / 2;
  891. } else if (etd->fw_version == 0x040216) {
  892. *x_max = 819;
  893. *y_max = 405;
  894. } else if (etd->fw_version == 0x040219 || etd->fw_version == 0x040215) {
  895. *x_max = 900;
  896. *y_max = 500;
  897. } else {
  898. *x_max = (etd->capabilities[1] - i) * 64;
  899. *y_max = (etd->capabilities[2] - i) * 64;
  900. }
  901. }
  902. break;
  903. case 3:
  904. if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
  905. return -1;
  906. *x_max = (0x0f & param[0]) << 8 | param[1];
  907. *y_max = (0xf0 & param[0]) << 4 | param[2];
  908. break;
  909. case 4:
  910. if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
  911. return -1;
  912. *x_max = (0x0f & param[0]) << 8 | param[1];
  913. *y_max = (0xf0 & param[0]) << 4 | param[2];
  914. traces = etd->capabilities[1];
  915. if ((traces < 2) || (traces > *x_max))
  916. return -1;
  917. *width = *x_max / (traces - 1);
  918. break;
  919. }
  920. return 0;
  921. }
  922. /*
  923. * (value from firmware) * 10 + 790 = dpi
  924. * we also have to convert dpi to dots/mm (*10/254 to avoid floating point)
  925. */
  926. static unsigned int elantech_convert_res(unsigned int val)
  927. {
  928. return (val * 10 + 790) * 10 / 254;
  929. }
  930. static int elantech_get_resolution_v4(struct psmouse *psmouse,
  931. unsigned int *x_res,
  932. unsigned int *y_res)
  933. {
  934. unsigned char param[3];
  935. if (elantech_send_cmd(psmouse, ETP_RESOLUTION_QUERY, param))
  936. return -1;
  937. *x_res = elantech_convert_res(param[1] & 0x0f);
  938. *y_res = elantech_convert_res((param[1] & 0xf0) >> 4);
  939. return 0;
  940. }
  941. /*
  942. * Advertise INPUT_PROP_BUTTONPAD for clickpads. The testing of bit 12 in
  943. * fw_version for this is based on the following fw_version & caps table:
  944. *
  945. * Laptop-model: fw_version: caps: buttons:
  946. * Acer S3 0x461f00 10, 13, 0e clickpad
  947. * Acer S7-392 0x581f01 50, 17, 0d clickpad
  948. * Acer V5-131 0x461f02 01, 16, 0c clickpad
  949. * Acer V5-551 0x461f00 ? clickpad
  950. * Asus K53SV 0x450f01 78, 15, 0c 2 hw buttons
  951. * Asus G46VW 0x460f02 00, 18, 0c 2 hw buttons
  952. * Asus G750JX 0x360f00 00, 16, 0c 2 hw buttons
  953. * Asus TP500LN 0x381f17 10, 14, 0e clickpad
  954. * Asus X750JN 0x381f17 10, 14, 0e clickpad
  955. * Asus UX31 0x361f00 20, 15, 0e clickpad
  956. * Asus UX32VD 0x361f02 00, 15, 0e clickpad
  957. * Avatar AVIU-145A2 0x361f00 ? clickpad
  958. * Fujitsu LIFEBOOK E544 0x470f00 d0, 12, 09 2 hw buttons
  959. * Fujitsu LIFEBOOK E546 0x470f00 50, 12, 09 2 hw buttons
  960. * Fujitsu LIFEBOOK E547 0x470f00 50, 12, 09 2 hw buttons
  961. * Fujitsu LIFEBOOK E554 0x570f01 40, 14, 0c 2 hw buttons
  962. * Fujitsu LIFEBOOK E557 0x570f01 40, 14, 0c 2 hw buttons
  963. * Fujitsu T725 0x470f01 05, 12, 09 2 hw buttons
  964. * Fujitsu H730 0x570f00 c0, 14, 0c 3 hw buttons (**)
  965. * Gigabyte U2442 0x450f01 58, 17, 0c 2 hw buttons
  966. * Lenovo L430 0x350f02 b9, 15, 0c 2 hw buttons (*)
  967. * Lenovo L530 0x350f02 b9, 15, 0c 2 hw buttons (*)
  968. * Samsung NF210 0x150b00 78, 14, 0a 2 hw buttons
  969. * Samsung NP770Z5E 0x575f01 10, 15, 0f clickpad
  970. * Samsung NP700Z5B 0x361f06 21, 15, 0f clickpad
  971. * Samsung NP900X3E-A02 0x575f03 ? clickpad
  972. * Samsung NP-QX410 0x851b00 19, 14, 0c clickpad
  973. * Samsung RC512 0x450f00 08, 15, 0c 2 hw buttons
  974. * Samsung RF710 0x450f00 ? 2 hw buttons
  975. * System76 Pangolin 0x250f01 ? 2 hw buttons
  976. * (*) + 3 trackpoint buttons
  977. * (**) + 0 trackpoint buttons
  978. * Note: Lenovo L430 and Lenovo L530 have the same fw_version/caps
  979. */
  980. static void elantech_set_buttonpad_prop(struct psmouse *psmouse)
  981. {
  982. struct input_dev *dev = psmouse->dev;
  983. struct elantech_data *etd = psmouse->private;
  984. if (etd->fw_version & 0x001000) {
  985. __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
  986. __clear_bit(BTN_RIGHT, dev->keybit);
  987. }
  988. }
  989. /*
  990. * Some hw_version 4 models do have a middle button
  991. */
  992. static const struct dmi_system_id elantech_dmi_has_middle_button[] = {
  993. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  994. {
  995. /* Fujitsu H730 has a middle button */
  996. .matches = {
  997. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  998. DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
  999. },
  1000. },
  1001. {
  1002. /* Fujitsu H760 also has a middle button */
  1003. .matches = {
  1004. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1005. DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H760"),
  1006. },
  1007. },
  1008. #endif
  1009. { }
  1010. };
  1011. /*
  1012. * Set the appropriate event bits for the input subsystem
  1013. */
  1014. static int elantech_set_input_params(struct psmouse *psmouse)
  1015. {
  1016. struct input_dev *dev = psmouse->dev;
  1017. struct elantech_data *etd = psmouse->private;
  1018. unsigned int x_min = 0, y_min = 0, x_max = 0, y_max = 0, width = 0;
  1019. unsigned int x_res = 31, y_res = 31;
  1020. if (elantech_set_range(psmouse, &x_min, &y_min, &x_max, &y_max, &width))
  1021. return -1;
  1022. __set_bit(INPUT_PROP_POINTER, dev->propbit);
  1023. __set_bit(EV_KEY, dev->evbit);
  1024. __set_bit(EV_ABS, dev->evbit);
  1025. __clear_bit(EV_REL, dev->evbit);
  1026. __set_bit(BTN_LEFT, dev->keybit);
  1027. if (dmi_check_system(elantech_dmi_has_middle_button))
  1028. __set_bit(BTN_MIDDLE, dev->keybit);
  1029. __set_bit(BTN_RIGHT, dev->keybit);
  1030. __set_bit(BTN_TOUCH, dev->keybit);
  1031. __set_bit(BTN_TOOL_FINGER, dev->keybit);
  1032. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  1033. __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
  1034. switch (etd->hw_version) {
  1035. case 1:
  1036. /* Rocker button */
  1037. if (etd->fw_version < 0x020000 &&
  1038. (etd->capabilities[0] & ETP_CAP_HAS_ROCKER)) {
  1039. __set_bit(BTN_FORWARD, dev->keybit);
  1040. __set_bit(BTN_BACK, dev->keybit);
  1041. }
  1042. input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
  1043. input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
  1044. break;
  1045. case 2:
  1046. __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
  1047. __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
  1048. /* fall through */
  1049. case 3:
  1050. if (etd->hw_version == 3)
  1051. elantech_set_buttonpad_prop(psmouse);
  1052. input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
  1053. input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
  1054. if (etd->reports_pressure) {
  1055. input_set_abs_params(dev, ABS_PRESSURE, ETP_PMIN_V2,
  1056. ETP_PMAX_V2, 0, 0);
  1057. input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
  1058. ETP_WMAX_V2, 0, 0);
  1059. }
  1060. input_mt_init_slots(dev, 2, INPUT_MT_SEMI_MT);
  1061. input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
  1062. input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
  1063. break;
  1064. case 4:
  1065. if (elantech_get_resolution_v4(psmouse, &x_res, &y_res)) {
  1066. /*
  1067. * if query failed, print a warning and leave the values
  1068. * zero to resemble synaptics.c behavior.
  1069. */
  1070. psmouse_warn(psmouse, "couldn't query resolution data.\n");
  1071. }
  1072. elantech_set_buttonpad_prop(psmouse);
  1073. __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
  1074. /* For X to recognize me as touchpad. */
  1075. input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
  1076. input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
  1077. /*
  1078. * range of pressure and width is the same as v2,
  1079. * report ABS_PRESSURE, ABS_TOOL_WIDTH for compatibility.
  1080. */
  1081. input_set_abs_params(dev, ABS_PRESSURE, ETP_PMIN_V2,
  1082. ETP_PMAX_V2, 0, 0);
  1083. input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
  1084. ETP_WMAX_V2, 0, 0);
  1085. /* Multitouch capable pad, up to 5 fingers. */
  1086. input_mt_init_slots(dev, ETP_MAX_FINGERS, 0);
  1087. input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
  1088. input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
  1089. input_set_abs_params(dev, ABS_MT_PRESSURE, ETP_PMIN_V2,
  1090. ETP_PMAX_V2, 0, 0);
  1091. /*
  1092. * The firmware reports how many trace lines the finger spans,
  1093. * convert to surface unit as Protocol-B requires.
  1094. */
  1095. input_set_abs_params(dev, ABS_MT_TOUCH_MAJOR, 0,
  1096. ETP_WMAX_V2 * width, 0, 0);
  1097. break;
  1098. }
  1099. input_abs_set_res(dev, ABS_X, x_res);
  1100. input_abs_set_res(dev, ABS_Y, y_res);
  1101. if (etd->hw_version > 1) {
  1102. input_abs_set_res(dev, ABS_MT_POSITION_X, x_res);
  1103. input_abs_set_res(dev, ABS_MT_POSITION_Y, y_res);
  1104. }
  1105. etd->y_max = y_max;
  1106. etd->width = width;
  1107. return 0;
  1108. }
  1109. struct elantech_attr_data {
  1110. size_t field_offset;
  1111. unsigned char reg;
  1112. };
  1113. /*
  1114. * Display a register value by reading a sysfs entry
  1115. */
  1116. static ssize_t elantech_show_int_attr(struct psmouse *psmouse, void *data,
  1117. char *buf)
  1118. {
  1119. struct elantech_data *etd = psmouse->private;
  1120. struct elantech_attr_data *attr = data;
  1121. unsigned char *reg = (unsigned char *) etd + attr->field_offset;
  1122. int rc = 0;
  1123. if (attr->reg)
  1124. rc = elantech_read_reg(psmouse, attr->reg, reg);
  1125. return sprintf(buf, "0x%02x\n", (attr->reg && rc) ? -1 : *reg);
  1126. }
  1127. /*
  1128. * Write a register value by writing a sysfs entry
  1129. */
  1130. static ssize_t elantech_set_int_attr(struct psmouse *psmouse,
  1131. void *data, const char *buf, size_t count)
  1132. {
  1133. struct elantech_data *etd = psmouse->private;
  1134. struct elantech_attr_data *attr = data;
  1135. unsigned char *reg = (unsigned char *) etd + attr->field_offset;
  1136. unsigned char value;
  1137. int err;
  1138. err = kstrtou8(buf, 16, &value);
  1139. if (err)
  1140. return err;
  1141. /* Do we need to preserve some bits for version 2 hardware too? */
  1142. if (etd->hw_version == 1) {
  1143. if (attr->reg == 0x10)
  1144. /* Force absolute mode always on */
  1145. value |= ETP_R10_ABSOLUTE_MODE;
  1146. else if (attr->reg == 0x11)
  1147. /* Force 4 byte mode always on */
  1148. value |= ETP_R11_4_BYTE_MODE;
  1149. }
  1150. if (!attr->reg || elantech_write_reg(psmouse, attr->reg, value) == 0)
  1151. *reg = value;
  1152. return count;
  1153. }
  1154. #define ELANTECH_INT_ATTR(_name, _register) \
  1155. static struct elantech_attr_data elantech_attr_##_name = { \
  1156. .field_offset = offsetof(struct elantech_data, _name), \
  1157. .reg = _register, \
  1158. }; \
  1159. PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
  1160. &elantech_attr_##_name, \
  1161. elantech_show_int_attr, \
  1162. elantech_set_int_attr)
  1163. ELANTECH_INT_ATTR(reg_07, 0x07);
  1164. ELANTECH_INT_ATTR(reg_10, 0x10);
  1165. ELANTECH_INT_ATTR(reg_11, 0x11);
  1166. ELANTECH_INT_ATTR(reg_20, 0x20);
  1167. ELANTECH_INT_ATTR(reg_21, 0x21);
  1168. ELANTECH_INT_ATTR(reg_22, 0x22);
  1169. ELANTECH_INT_ATTR(reg_23, 0x23);
  1170. ELANTECH_INT_ATTR(reg_24, 0x24);
  1171. ELANTECH_INT_ATTR(reg_25, 0x25);
  1172. ELANTECH_INT_ATTR(reg_26, 0x26);
  1173. ELANTECH_INT_ATTR(debug, 0);
  1174. ELANTECH_INT_ATTR(paritycheck, 0);
  1175. ELANTECH_INT_ATTR(crc_enabled, 0);
  1176. static struct attribute *elantech_attrs[] = {
  1177. &psmouse_attr_reg_07.dattr.attr,
  1178. &psmouse_attr_reg_10.dattr.attr,
  1179. &psmouse_attr_reg_11.dattr.attr,
  1180. &psmouse_attr_reg_20.dattr.attr,
  1181. &psmouse_attr_reg_21.dattr.attr,
  1182. &psmouse_attr_reg_22.dattr.attr,
  1183. &psmouse_attr_reg_23.dattr.attr,
  1184. &psmouse_attr_reg_24.dattr.attr,
  1185. &psmouse_attr_reg_25.dattr.attr,
  1186. &psmouse_attr_reg_26.dattr.attr,
  1187. &psmouse_attr_debug.dattr.attr,
  1188. &psmouse_attr_paritycheck.dattr.attr,
  1189. &psmouse_attr_crc_enabled.dattr.attr,
  1190. NULL
  1191. };
  1192. static const struct attribute_group elantech_attr_group = {
  1193. .attrs = elantech_attrs,
  1194. };
  1195. static bool elantech_is_signature_valid(const unsigned char *param)
  1196. {
  1197. static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10 };
  1198. int i;
  1199. if (param[0] == 0)
  1200. return false;
  1201. if (param[1] == 0)
  1202. return true;
  1203. /*
  1204. * Some hw_version >= 4 models have a revision higher then 20. Meaning
  1205. * that param[2] may be 10 or 20, skip the rates check for these.
  1206. */
  1207. if ((param[0] & 0x0f) >= 0x06 && (param[1] & 0xaf) == 0x0f &&
  1208. param[2] < 40)
  1209. return true;
  1210. for (i = 0; i < ARRAY_SIZE(rates); i++)
  1211. if (param[2] == rates[i])
  1212. return false;
  1213. return true;
  1214. }
  1215. /*
  1216. * Use magic knock to detect Elantech touchpad
  1217. */
  1218. int elantech_detect(struct psmouse *psmouse, bool set_properties)
  1219. {
  1220. struct ps2dev *ps2dev = &psmouse->ps2dev;
  1221. unsigned char param[3];
  1222. ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
  1223. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  1224. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1225. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1226. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1227. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  1228. psmouse_dbg(psmouse, "sending Elantech magic knock failed.\n");
  1229. return -1;
  1230. }
  1231. /*
  1232. * Report this in case there are Elantech models that use a different
  1233. * set of magic numbers
  1234. */
  1235. if (param[0] != 0x3c || param[1] != 0x03 ||
  1236. (param[2] != 0xc8 && param[2] != 0x00)) {
  1237. psmouse_dbg(psmouse,
  1238. "unexpected magic knock result 0x%02x, 0x%02x, 0x%02x.\n",
  1239. param[0], param[1], param[2]);
  1240. return -1;
  1241. }
  1242. /*
  1243. * Query touchpad's firmware version and see if it reports known
  1244. * value to avoid mis-detection. Logitech mice are known to respond
  1245. * to Elantech magic knock and there might be more.
  1246. */
  1247. if (synaptics_send_cmd(psmouse, ETP_FW_VERSION_QUERY, param)) {
  1248. psmouse_dbg(psmouse, "failed to query firmware version.\n");
  1249. return -1;
  1250. }
  1251. psmouse_dbg(psmouse,
  1252. "Elantech version query result 0x%02x, 0x%02x, 0x%02x.\n",
  1253. param[0], param[1], param[2]);
  1254. if (!elantech_is_signature_valid(param)) {
  1255. psmouse_dbg(psmouse,
  1256. "Probably not a real Elantech touchpad. Aborting.\n");
  1257. return -1;
  1258. }
  1259. if (set_properties) {
  1260. psmouse->vendor = "Elantech";
  1261. psmouse->name = "Touchpad";
  1262. }
  1263. return 0;
  1264. }
  1265. /*
  1266. * Clean up sysfs entries when disconnecting
  1267. */
  1268. static void elantech_disconnect(struct psmouse *psmouse)
  1269. {
  1270. struct elantech_data *etd = psmouse->private;
  1271. if (etd->tp_dev)
  1272. input_unregister_device(etd->tp_dev);
  1273. sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
  1274. &elantech_attr_group);
  1275. kfree(psmouse->private);
  1276. psmouse->private = NULL;
  1277. }
  1278. /*
  1279. * Put the touchpad back into absolute mode when reconnecting
  1280. */
  1281. static int elantech_reconnect(struct psmouse *psmouse)
  1282. {
  1283. psmouse_reset(psmouse);
  1284. if (elantech_detect(psmouse, 0))
  1285. return -1;
  1286. if (elantech_set_absolute_mode(psmouse)) {
  1287. psmouse_err(psmouse,
  1288. "failed to put touchpad back into absolute mode.\n");
  1289. return -1;
  1290. }
  1291. return 0;
  1292. }
  1293. /*
  1294. * Some hw_version 4 models do not work with crc_disabled
  1295. */
  1296. static const struct dmi_system_id elantech_dmi_force_crc_enabled[] = {
  1297. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1298. {
  1299. /* Fujitsu H730 does not work with crc_enabled == 0 */
  1300. .matches = {
  1301. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1302. DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
  1303. },
  1304. },
  1305. {
  1306. /* Fujitsu H760 does not work with crc_enabled == 0 */
  1307. .matches = {
  1308. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1309. DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H760"),
  1310. },
  1311. },
  1312. {
  1313. /* Fujitsu LIFEBOOK E544 does not work with crc_enabled == 0 */
  1314. .matches = {
  1315. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1316. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E544"),
  1317. },
  1318. },
  1319. {
  1320. /* Fujitsu LIFEBOOK E546 does not work with crc_enabled == 0 */
  1321. .matches = {
  1322. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1323. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E546"),
  1324. },
  1325. },
  1326. {
  1327. /* Fujitsu LIFEBOOK E547 does not work with crc_enabled == 0 */
  1328. .matches = {
  1329. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1330. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E547"),
  1331. },
  1332. },
  1333. {
  1334. /* Fujitsu LIFEBOOK E554 does not work with crc_enabled == 0 */
  1335. .matches = {
  1336. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1337. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E554"),
  1338. },
  1339. },
  1340. {
  1341. /* Fujitsu LIFEBOOK E556 does not work with crc_enabled == 0 */
  1342. .matches = {
  1343. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1344. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E556"),
  1345. },
  1346. },
  1347. {
  1348. /* Fujitsu LIFEBOOK E557 does not work with crc_enabled == 0 */
  1349. .matches = {
  1350. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1351. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E557"),
  1352. },
  1353. },
  1354. {
  1355. /* Fujitsu LIFEBOOK U745 does not work with crc_enabled == 0 */
  1356. .matches = {
  1357. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  1358. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK U745"),
  1359. },
  1360. },
  1361. #endif
  1362. { }
  1363. };
  1364. /*
  1365. * Some hw_version 3 models go into error state when we try to set
  1366. * bit 3 and/or bit 1 of r10.
  1367. */
  1368. static const struct dmi_system_id no_hw_res_dmi_table[] = {
  1369. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  1370. {
  1371. /* Gigabyte U2442 */
  1372. .matches = {
  1373. DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
  1374. DMI_MATCH(DMI_PRODUCT_NAME, "U2442"),
  1375. },
  1376. },
  1377. #endif
  1378. { }
  1379. };
  1380. /*
  1381. * determine hardware version and set some properties according to it.
  1382. */
  1383. static int elantech_set_properties(struct elantech_data *etd)
  1384. {
  1385. /* This represents the version of IC body. */
  1386. int ver = (etd->fw_version & 0x0f0000) >> 16;
  1387. /* Early version of Elan touchpads doesn't obey the rule. */
  1388. if (etd->fw_version < 0x020030 || etd->fw_version == 0x020600)
  1389. etd->hw_version = 1;
  1390. else {
  1391. switch (ver) {
  1392. case 2:
  1393. case 4:
  1394. etd->hw_version = 2;
  1395. break;
  1396. case 5:
  1397. etd->hw_version = 3;
  1398. break;
  1399. case 6 ... 14:
  1400. etd->hw_version = 4;
  1401. break;
  1402. default:
  1403. return -1;
  1404. }
  1405. }
  1406. /* decide which send_cmd we're gonna use early */
  1407. etd->send_cmd = etd->hw_version >= 3 ? elantech_send_cmd :
  1408. synaptics_send_cmd;
  1409. /* Turn on packet checking by default */
  1410. etd->paritycheck = 1;
  1411. /*
  1412. * This firmware suffers from misreporting coordinates when
  1413. * a touch action starts causing the mouse cursor or scrolled page
  1414. * to jump. Enable a workaround.
  1415. */
  1416. etd->jumpy_cursor =
  1417. (etd->fw_version == 0x020022 || etd->fw_version == 0x020600);
  1418. if (etd->hw_version > 1) {
  1419. /* For now show extra debug information */
  1420. etd->debug = 1;
  1421. if (etd->fw_version >= 0x020800)
  1422. etd->reports_pressure = true;
  1423. }
  1424. /*
  1425. * The signatures of v3 and v4 packets change depending on the
  1426. * value of this hardware flag.
  1427. */
  1428. etd->crc_enabled = (etd->fw_version & 0x4000) == 0x4000 ||
  1429. dmi_check_system(elantech_dmi_force_crc_enabled);
  1430. /* Enable real hardware resolution on hw_version 3 ? */
  1431. etd->set_hw_resolution = !dmi_check_system(no_hw_res_dmi_table);
  1432. return 0;
  1433. }
  1434. /*
  1435. * Initialize the touchpad and create sysfs entries
  1436. */
  1437. int elantech_init(struct psmouse *psmouse)
  1438. {
  1439. struct elantech_data *etd;
  1440. int i;
  1441. int error = -EINVAL;
  1442. unsigned char param[3];
  1443. struct input_dev *tp_dev;
  1444. psmouse->private = etd = kzalloc(sizeof(struct elantech_data), GFP_KERNEL);
  1445. if (!etd)
  1446. return -ENOMEM;
  1447. psmouse_reset(psmouse);
  1448. etd->parity[0] = 1;
  1449. for (i = 1; i < 256; i++)
  1450. etd->parity[i] = etd->parity[i & (i - 1)] ^ 1;
  1451. /*
  1452. * Do the version query again so we can store the result
  1453. */
  1454. if (synaptics_send_cmd(psmouse, ETP_FW_VERSION_QUERY, param)) {
  1455. psmouse_err(psmouse, "failed to query firmware version.\n");
  1456. goto init_fail;
  1457. }
  1458. etd->fw_version = (param[0] << 16) | (param[1] << 8) | param[2];
  1459. if (elantech_set_properties(etd)) {
  1460. psmouse_err(psmouse, "unknown hardware version, aborting...\n");
  1461. goto init_fail;
  1462. }
  1463. psmouse_info(psmouse,
  1464. "assuming hardware version %d (with firmware version 0x%02x%02x%02x)\n",
  1465. etd->hw_version, param[0], param[1], param[2]);
  1466. if (etd->send_cmd(psmouse, ETP_CAPABILITIES_QUERY,
  1467. etd->capabilities)) {
  1468. psmouse_err(psmouse, "failed to query capabilities.\n");
  1469. goto init_fail;
  1470. }
  1471. psmouse_info(psmouse,
  1472. "Synaptics capabilities query result 0x%02x, 0x%02x, 0x%02x.\n",
  1473. etd->capabilities[0], etd->capabilities[1],
  1474. etd->capabilities[2]);
  1475. if (etd->hw_version != 1) {
  1476. if (etd->send_cmd(psmouse, ETP_SAMPLE_QUERY, etd->samples)) {
  1477. psmouse_err(psmouse, "failed to query sample data\n");
  1478. goto init_fail;
  1479. }
  1480. psmouse_info(psmouse,
  1481. "Elan sample query result %02x, %02x, %02x\n",
  1482. etd->samples[0], etd->samples[1], etd->samples[2]);
  1483. }
  1484. if (etd->samples[1] == 0x74 && etd->hw_version == 0x03) {
  1485. /*
  1486. * This module has a bug which makes absolute mode
  1487. * unusable, so let's abort so we'll be using standard
  1488. * PS/2 protocol.
  1489. */
  1490. psmouse_info(psmouse,
  1491. "absolute mode broken, forcing standard PS/2 protocol\n");
  1492. goto init_fail;
  1493. }
  1494. if (elantech_set_absolute_mode(psmouse)) {
  1495. psmouse_err(psmouse,
  1496. "failed to put touchpad into absolute mode.\n");
  1497. goto init_fail;
  1498. }
  1499. if (etd->fw_version == 0x381f17) {
  1500. etd->original_set_rate = psmouse->set_rate;
  1501. psmouse->set_rate = elantech_set_rate_restore_reg_07;
  1502. }
  1503. if (elantech_set_input_params(psmouse)) {
  1504. psmouse_err(psmouse, "failed to query touchpad range.\n");
  1505. goto init_fail;
  1506. }
  1507. error = sysfs_create_group(&psmouse->ps2dev.serio->dev.kobj,
  1508. &elantech_attr_group);
  1509. if (error) {
  1510. psmouse_err(psmouse,
  1511. "failed to create sysfs attributes, error: %d.\n",
  1512. error);
  1513. goto init_fail;
  1514. }
  1515. /* The MSB indicates the presence of the trackpoint */
  1516. if ((etd->capabilities[0] & 0x80) == 0x80) {
  1517. tp_dev = input_allocate_device();
  1518. if (!tp_dev) {
  1519. error = -ENOMEM;
  1520. goto init_fail_tp_alloc;
  1521. }
  1522. etd->tp_dev = tp_dev;
  1523. snprintf(etd->tp_phys, sizeof(etd->tp_phys), "%s/input1",
  1524. psmouse->ps2dev.serio->phys);
  1525. tp_dev->phys = etd->tp_phys;
  1526. tp_dev->name = "ETPS/2 Elantech TrackPoint";
  1527. tp_dev->id.bustype = BUS_I8042;
  1528. tp_dev->id.vendor = 0x0002;
  1529. tp_dev->id.product = PSMOUSE_ELANTECH;
  1530. tp_dev->id.version = 0x0000;
  1531. tp_dev->dev.parent = &psmouse->ps2dev.serio->dev;
  1532. tp_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  1533. tp_dev->relbit[BIT_WORD(REL_X)] =
  1534. BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  1535. tp_dev->keybit[BIT_WORD(BTN_LEFT)] =
  1536. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) |
  1537. BIT_MASK(BTN_RIGHT);
  1538. __set_bit(INPUT_PROP_POINTER, tp_dev->propbit);
  1539. __set_bit(INPUT_PROP_POINTING_STICK, tp_dev->propbit);
  1540. error = input_register_device(etd->tp_dev);
  1541. if (error < 0)
  1542. goto init_fail_tp_reg;
  1543. }
  1544. psmouse->protocol_handler = elantech_process_byte;
  1545. psmouse->disconnect = elantech_disconnect;
  1546. psmouse->reconnect = elantech_reconnect;
  1547. psmouse->pktsize = etd->hw_version > 1 ? 6 : 4;
  1548. return 0;
  1549. init_fail_tp_reg:
  1550. input_free_device(tp_dev);
  1551. init_fail_tp_alloc:
  1552. sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
  1553. &elantech_attr_group);
  1554. init_fail:
  1555. psmouse_reset(psmouse);
  1556. kfree(etd);
  1557. return error;
  1558. }