synaptics.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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/dmi.h>
  27. #include <linux/input.h>
  28. #include <linux/serio.h>
  29. #include <linux/libps2.h>
  30. #include <linux/slab.h>
  31. #include "psmouse.h"
  32. #include "synaptics.h"
  33. /*
  34. * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
  35. * section 2.3.2, which says that they should be valid regardless of the
  36. * actual size of the sensor.
  37. * Note that newer firmware allows querying device for maximum useable
  38. * coordinates.
  39. */
  40. #define XMIN_NOMINAL 1472
  41. #define XMAX_NOMINAL 5472
  42. #define YMIN_NOMINAL 1408
  43. #define YMAX_NOMINAL 4448
  44. /*****************************************************************************
  45. * Stuff we need even when we do not want native Synaptics support
  46. ****************************************************************************/
  47. /*
  48. * Set the synaptics touchpad mode byte by special commands
  49. */
  50. static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
  51. {
  52. unsigned char param[1];
  53. if (psmouse_sliced_command(psmouse, mode))
  54. return -1;
  55. param[0] = SYN_PS_SET_MODE2;
  56. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
  57. return -1;
  58. return 0;
  59. }
  60. int synaptics_detect(struct psmouse *psmouse, bool set_properties)
  61. {
  62. struct ps2dev *ps2dev = &psmouse->ps2dev;
  63. unsigned char param[4];
  64. param[0] = 0;
  65. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  66. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  67. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  68. ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
  69. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
  70. if (param[1] != 0x47)
  71. return -ENODEV;
  72. if (set_properties) {
  73. psmouse->vendor = "Synaptics";
  74. psmouse->name = "TouchPad";
  75. }
  76. return 0;
  77. }
  78. void synaptics_reset(struct psmouse *psmouse)
  79. {
  80. /* reset touchpad back to relative mode, gestures enabled */
  81. synaptics_mode_cmd(psmouse, 0);
  82. }
  83. #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
  84. /*****************************************************************************
  85. * Synaptics communications functions
  86. ****************************************************************************/
  87. /*
  88. * Send a command to the synpatics touchpad by special commands
  89. */
  90. static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
  91. {
  92. if (psmouse_sliced_command(psmouse, c))
  93. return -1;
  94. if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
  95. return -1;
  96. return 0;
  97. }
  98. /*
  99. * Read the model-id bytes from the touchpad
  100. * see also SYN_MODEL_* macros
  101. */
  102. static int synaptics_model_id(struct psmouse *psmouse)
  103. {
  104. struct synaptics_data *priv = psmouse->private;
  105. unsigned char mi[3];
  106. if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
  107. return -1;
  108. priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
  109. return 0;
  110. }
  111. /*
  112. * Read the capability-bits from the touchpad
  113. * see also the SYN_CAP_* macros
  114. */
  115. static int synaptics_capability(struct psmouse *psmouse)
  116. {
  117. struct synaptics_data *priv = psmouse->private;
  118. unsigned char cap[3];
  119. if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
  120. return -1;
  121. priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  122. priv->ext_cap = priv->ext_cap_0c = 0;
  123. if (!SYN_CAP_VALID(priv->capabilities))
  124. return -1;
  125. /*
  126. * Unless capExtended is set the rest of the flags should be ignored
  127. */
  128. if (!SYN_CAP_EXTENDED(priv->capabilities))
  129. priv->capabilities = 0;
  130. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
  131. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
  132. printk(KERN_ERR "Synaptics claims to have extended capabilities,"
  133. " but I'm not able to read them.\n");
  134. } else {
  135. priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  136. /*
  137. * if nExtBtn is greater than 8 it should be considered
  138. * invalid and treated as 0
  139. */
  140. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
  141. priv->ext_cap &= 0xff0fff;
  142. }
  143. }
  144. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
  145. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
  146. printk(KERN_ERR "Synaptics claims to have extended capability 0x0c,"
  147. " but I'm not able to read it.\n");
  148. } else {
  149. priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
  150. }
  151. }
  152. return 0;
  153. }
  154. /*
  155. * Identify Touchpad
  156. * See also the SYN_ID_* macros
  157. */
  158. static int synaptics_identify(struct psmouse *psmouse)
  159. {
  160. struct synaptics_data *priv = psmouse->private;
  161. unsigned char id[3];
  162. if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
  163. return -1;
  164. priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
  165. if (SYN_ID_IS_SYNAPTICS(priv->identity))
  166. return 0;
  167. return -1;
  168. }
  169. /*
  170. * Read touchpad resolution and maximum reported coordinates
  171. * Resolution is left zero if touchpad does not support the query
  172. */
  173. static int synaptics_resolution(struct psmouse *psmouse)
  174. {
  175. struct synaptics_data *priv = psmouse->private;
  176. unsigned char res[3];
  177. unsigned char max[3];
  178. if (SYN_ID_MAJOR(priv->identity) < 4)
  179. return 0;
  180. if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, res) == 0) {
  181. if (res[0] != 0 && (res[1] & 0x80) && res[2] != 0) {
  182. priv->x_res = res[0]; /* x resolution in units/mm */
  183. priv->y_res = res[2]; /* y resolution in units/mm */
  184. }
  185. }
  186. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
  187. SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
  188. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_DIMENSIONS, max)) {
  189. printk(KERN_ERR "Synaptics claims to have dimensions query,"
  190. " but I'm not able to read it.\n");
  191. } else {
  192. priv->x_max = (max[0] << 5) | ((max[1] & 0x0f) << 1);
  193. priv->y_max = (max[2] << 5) | ((max[1] & 0xf0) >> 3);
  194. }
  195. }
  196. return 0;
  197. }
  198. static int synaptics_query_hardware(struct psmouse *psmouse)
  199. {
  200. if (synaptics_identify(psmouse))
  201. return -1;
  202. if (synaptics_model_id(psmouse))
  203. return -1;
  204. if (synaptics_capability(psmouse))
  205. return -1;
  206. if (synaptics_resolution(psmouse))
  207. return -1;
  208. return 0;
  209. }
  210. static int synaptics_set_absolute_mode(struct psmouse *psmouse)
  211. {
  212. struct synaptics_data *priv = psmouse->private;
  213. priv->mode = SYN_BIT_ABSOLUTE_MODE;
  214. if (SYN_ID_MAJOR(priv->identity) >= 4)
  215. priv->mode |= SYN_BIT_DISABLE_GESTURE;
  216. if (SYN_CAP_EXTENDED(priv->capabilities))
  217. priv->mode |= SYN_BIT_W_MODE;
  218. if (synaptics_mode_cmd(psmouse, priv->mode))
  219. return -1;
  220. return 0;
  221. }
  222. static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
  223. {
  224. struct synaptics_data *priv = psmouse->private;
  225. if (rate >= 80) {
  226. priv->mode |= SYN_BIT_HIGH_RATE;
  227. psmouse->rate = 80;
  228. } else {
  229. priv->mode &= ~SYN_BIT_HIGH_RATE;
  230. psmouse->rate = 40;
  231. }
  232. synaptics_mode_cmd(psmouse, priv->mode);
  233. }
  234. /*****************************************************************************
  235. * Synaptics pass-through PS/2 port support
  236. ****************************************************************************/
  237. static int synaptics_pt_write(struct serio *serio, unsigned char c)
  238. {
  239. struct psmouse *parent = serio_get_drvdata(serio->parent);
  240. char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
  241. if (psmouse_sliced_command(parent, c))
  242. return -1;
  243. if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
  244. return -1;
  245. return 0;
  246. }
  247. static inline int synaptics_is_pt_packet(unsigned char *buf)
  248. {
  249. return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
  250. }
  251. static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
  252. {
  253. struct psmouse *child = serio_get_drvdata(ptport);
  254. if (child && child->state == PSMOUSE_ACTIVATED) {
  255. serio_interrupt(ptport, packet[1], 0);
  256. serio_interrupt(ptport, packet[4], 0);
  257. serio_interrupt(ptport, packet[5], 0);
  258. if (child->pktsize == 4)
  259. serio_interrupt(ptport, packet[2], 0);
  260. } else
  261. serio_interrupt(ptport, packet[1], 0);
  262. }
  263. static void synaptics_pt_activate(struct psmouse *psmouse)
  264. {
  265. struct serio *ptport = psmouse->ps2dev.serio->child;
  266. struct psmouse *child = serio_get_drvdata(ptport);
  267. struct synaptics_data *priv = psmouse->private;
  268. /* adjust the touchpad to child's choice of protocol */
  269. if (child) {
  270. if (child->pktsize == 4)
  271. priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
  272. else
  273. priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
  274. if (synaptics_mode_cmd(psmouse, priv->mode))
  275. printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
  276. }
  277. }
  278. static void synaptics_pt_create(struct psmouse *psmouse)
  279. {
  280. struct serio *serio;
  281. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  282. if (!serio) {
  283. printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
  284. return;
  285. }
  286. serio->id.type = SERIO_PS_PSTHRU;
  287. strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
  288. strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
  289. serio->write = synaptics_pt_write;
  290. serio->parent = psmouse->ps2dev.serio;
  291. psmouse->pt_activate = synaptics_pt_activate;
  292. printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
  293. serio_register_port(serio);
  294. }
  295. /*****************************************************************************
  296. * Functions to interpret the absolute mode packets
  297. ****************************************************************************/
  298. static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw)
  299. {
  300. memset(hw, 0, sizeof(struct synaptics_hw_state));
  301. if (SYN_MODEL_NEWABS(priv->model_id)) {
  302. hw->x = (((buf[3] & 0x10) << 8) |
  303. ((buf[1] & 0x0f) << 8) |
  304. buf[4]);
  305. hw->y = (((buf[3] & 0x20) << 7) |
  306. ((buf[1] & 0xf0) << 4) |
  307. buf[5]);
  308. hw->z = buf[2];
  309. hw->w = (((buf[0] & 0x30) >> 2) |
  310. ((buf[0] & 0x04) >> 1) |
  311. ((buf[3] & 0x04) >> 2));
  312. hw->left = (buf[0] & 0x01) ? 1 : 0;
  313. hw->right = (buf[0] & 0x02) ? 1 : 0;
  314. if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  315. /*
  316. * Clickpad's button is transmitted as middle button,
  317. * however, since it is primary button, we will report
  318. * it as BTN_LEFT.
  319. */
  320. hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  321. } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  322. hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  323. if (hw->w == 2)
  324. hw->scroll = (signed char)(buf[1]);
  325. }
  326. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  327. hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
  328. hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
  329. }
  330. if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
  331. ((buf[0] ^ buf[3]) & 0x02)) {
  332. switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
  333. default:
  334. /*
  335. * if nExtBtn is greater than 8 it should be
  336. * considered invalid and treated as 0
  337. */
  338. break;
  339. case 8:
  340. hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
  341. hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
  342. case 6:
  343. hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
  344. hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
  345. case 4:
  346. hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
  347. hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
  348. case 2:
  349. hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
  350. hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
  351. }
  352. }
  353. } else {
  354. hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
  355. hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
  356. hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
  357. hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
  358. hw->left = (buf[0] & 0x01) ? 1 : 0;
  359. hw->right = (buf[0] & 0x02) ? 1 : 0;
  360. }
  361. }
  362. /*
  363. * called for each full received packet from the touchpad
  364. */
  365. static void synaptics_process_packet(struct psmouse *psmouse)
  366. {
  367. struct input_dev *dev = psmouse->dev;
  368. struct synaptics_data *priv = psmouse->private;
  369. struct synaptics_hw_state hw;
  370. int num_fingers;
  371. int finger_width;
  372. int i;
  373. synaptics_parse_hw_state(psmouse->packet, priv, &hw);
  374. if (hw.scroll) {
  375. priv->scroll += hw.scroll;
  376. while (priv->scroll >= 4) {
  377. input_report_key(dev, BTN_BACK, !hw.down);
  378. input_sync(dev);
  379. input_report_key(dev, BTN_BACK, hw.down);
  380. input_sync(dev);
  381. priv->scroll -= 4;
  382. }
  383. while (priv->scroll <= -4) {
  384. input_report_key(dev, BTN_FORWARD, !hw.up);
  385. input_sync(dev);
  386. input_report_key(dev, BTN_FORWARD, hw.up);
  387. input_sync(dev);
  388. priv->scroll += 4;
  389. }
  390. return;
  391. }
  392. if (hw.z > 0) {
  393. num_fingers = 1;
  394. finger_width = 5;
  395. if (SYN_CAP_EXTENDED(priv->capabilities)) {
  396. switch (hw.w) {
  397. case 0 ... 1:
  398. if (SYN_CAP_MULTIFINGER(priv->capabilities))
  399. num_fingers = hw.w + 2;
  400. break;
  401. case 2:
  402. if (SYN_MODEL_PEN(priv->model_id))
  403. ; /* Nothing, treat a pen as a single finger */
  404. break;
  405. case 4 ... 15:
  406. if (SYN_CAP_PALMDETECT(priv->capabilities))
  407. finger_width = hw.w;
  408. break;
  409. }
  410. }
  411. } else {
  412. num_fingers = 0;
  413. finger_width = 0;
  414. }
  415. /* Post events
  416. * BTN_TOUCH has to be first as mousedev relies on it when doing
  417. * absolute -> relative conversion
  418. */
  419. if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
  420. if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
  421. if (hw.z > 0) {
  422. input_report_abs(dev, ABS_X, hw.x);
  423. input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y);
  424. }
  425. input_report_abs(dev, ABS_PRESSURE, hw.z);
  426. input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
  427. input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
  428. input_report_key(dev, BTN_LEFT, hw.left);
  429. input_report_key(dev, BTN_RIGHT, hw.right);
  430. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  431. input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
  432. input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
  433. }
  434. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  435. input_report_key(dev, BTN_MIDDLE, hw.middle);
  436. if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
  437. input_report_key(dev, BTN_FORWARD, hw.up);
  438. input_report_key(dev, BTN_BACK, hw.down);
  439. }
  440. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
  441. input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
  442. input_sync(dev);
  443. }
  444. static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
  445. {
  446. static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
  447. static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
  448. static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
  449. static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
  450. static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
  451. if (idx < 0 || idx > 4)
  452. return 0;
  453. switch (pkt_type) {
  454. case SYN_NEWABS:
  455. case SYN_NEWABS_RELAXED:
  456. return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
  457. case SYN_NEWABS_STRICT:
  458. return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
  459. case SYN_OLDABS:
  460. return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
  461. default:
  462. printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
  463. return 0;
  464. }
  465. }
  466. static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
  467. {
  468. int i;
  469. for (i = 0; i < 5; i++)
  470. if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
  471. printk(KERN_INFO "synaptics: using relaxed packet validation\n");
  472. return SYN_NEWABS_RELAXED;
  473. }
  474. return SYN_NEWABS_STRICT;
  475. }
  476. static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
  477. {
  478. struct synaptics_data *priv = psmouse->private;
  479. if (psmouse->pktcnt >= 6) { /* Full packet received */
  480. if (unlikely(priv->pkt_type == SYN_NEWABS))
  481. priv->pkt_type = synaptics_detect_pkt_type(psmouse);
  482. if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) {
  483. if (psmouse->ps2dev.serio->child)
  484. synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet);
  485. } else
  486. synaptics_process_packet(psmouse);
  487. return PSMOUSE_FULL_PACKET;
  488. }
  489. return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
  490. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  491. }
  492. /*****************************************************************************
  493. * Driver initialization/cleanup functions
  494. ****************************************************************************/
  495. static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
  496. {
  497. int i;
  498. __set_bit(EV_ABS, dev->evbit);
  499. input_set_abs_params(dev, ABS_X,
  500. XMIN_NOMINAL, priv->x_max ?: XMAX_NOMINAL, 0, 0);
  501. input_set_abs_params(dev, ABS_Y,
  502. YMIN_NOMINAL, priv->y_max ?: YMAX_NOMINAL, 0, 0);
  503. input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
  504. __set_bit(ABS_TOOL_WIDTH, dev->absbit);
  505. __set_bit(EV_KEY, dev->evbit);
  506. __set_bit(BTN_TOUCH, dev->keybit);
  507. __set_bit(BTN_TOOL_FINGER, dev->keybit);
  508. __set_bit(BTN_LEFT, dev->keybit);
  509. __set_bit(BTN_RIGHT, dev->keybit);
  510. if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
  511. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  512. __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
  513. }
  514. if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
  515. __set_bit(BTN_MIDDLE, dev->keybit);
  516. if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
  517. SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
  518. __set_bit(BTN_FORWARD, dev->keybit);
  519. __set_bit(BTN_BACK, dev->keybit);
  520. }
  521. for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
  522. __set_bit(BTN_0 + i, dev->keybit);
  523. __clear_bit(EV_REL, dev->evbit);
  524. __clear_bit(REL_X, dev->relbit);
  525. __clear_bit(REL_Y, dev->relbit);
  526. dev->absres[ABS_X] = priv->x_res;
  527. dev->absres[ABS_Y] = priv->y_res;
  528. if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
  529. /* Clickpads report only left button */
  530. __clear_bit(BTN_RIGHT, dev->keybit);
  531. __clear_bit(BTN_MIDDLE, dev->keybit);
  532. }
  533. }
  534. static void synaptics_disconnect(struct psmouse *psmouse)
  535. {
  536. synaptics_reset(psmouse);
  537. kfree(psmouse->private);
  538. psmouse->private = NULL;
  539. }
  540. static int synaptics_reconnect(struct psmouse *psmouse)
  541. {
  542. struct synaptics_data *priv = psmouse->private;
  543. struct synaptics_data old_priv = *priv;
  544. psmouse_reset(psmouse);
  545. if (synaptics_detect(psmouse, 0))
  546. return -1;
  547. if (synaptics_query_hardware(psmouse)) {
  548. printk(KERN_ERR "Unable to query Synaptics hardware.\n");
  549. return -1;
  550. }
  551. if (old_priv.identity != priv->identity ||
  552. old_priv.model_id != priv->model_id ||
  553. old_priv.capabilities != priv->capabilities ||
  554. old_priv.ext_cap != priv->ext_cap)
  555. return -1;
  556. if (synaptics_set_absolute_mode(psmouse)) {
  557. printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
  558. return -1;
  559. }
  560. return 0;
  561. }
  562. static bool impaired_toshiba_kbc;
  563. static const struct dmi_system_id __initconst toshiba_dmi_table[] = {
  564. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  565. {
  566. /* Toshiba Satellite */
  567. .matches = {
  568. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  569. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  570. },
  571. },
  572. {
  573. /* Toshiba Dynabook */
  574. .matches = {
  575. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  576. DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
  577. },
  578. },
  579. {
  580. /* Toshiba Portege M300 */
  581. .matches = {
  582. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  583. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
  584. },
  585. },
  586. {
  587. /* Toshiba Portege M300 */
  588. .matches = {
  589. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  590. DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
  591. DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
  592. },
  593. },
  594. { }
  595. #endif
  596. };
  597. void __init synaptics_module_init(void)
  598. {
  599. impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
  600. }
  601. int synaptics_init(struct psmouse *psmouse)
  602. {
  603. struct synaptics_data *priv;
  604. psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
  605. if (!priv)
  606. return -1;
  607. psmouse_reset(psmouse);
  608. if (synaptics_query_hardware(psmouse)) {
  609. printk(KERN_ERR "Unable to query Synaptics hardware.\n");
  610. goto init_fail;
  611. }
  612. if (synaptics_set_absolute_mode(psmouse)) {
  613. printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
  614. goto init_fail;
  615. }
  616. priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
  617. printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",
  618. SYN_ID_MODEL(priv->identity),
  619. SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
  620. priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
  621. set_input_params(psmouse->dev, priv);
  622. /*
  623. * Encode touchpad model so that it can be used to set
  624. * input device->id.version and be visible to userspace.
  625. * Because version is __u16 we have to drop something.
  626. * Hardware info bits seem to be good candidates as they
  627. * are documented to be for Synaptics corp. internal use.
  628. */
  629. psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
  630. (priv->model_id & 0x000000ff);
  631. psmouse->protocol_handler = synaptics_process_byte;
  632. psmouse->set_rate = synaptics_set_rate;
  633. psmouse->disconnect = synaptics_disconnect;
  634. psmouse->reconnect = synaptics_reconnect;
  635. psmouse->cleanup = synaptics_reset;
  636. psmouse->pktsize = 6;
  637. /* Synaptics can usually stay in sync without extra help */
  638. psmouse->resync_time = 0;
  639. if (SYN_CAP_PASS_THROUGH(priv->capabilities))
  640. synaptics_pt_create(psmouse);
  641. /*
  642. * Toshiba's KBC seems to have trouble handling data from
  643. * Synaptics as full rate, switch to lower rate which is roughly
  644. * thye same as rate of standard PS/2 mouse.
  645. */
  646. if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
  647. printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
  648. dmi_get_system_info(DMI_PRODUCT_NAME));
  649. psmouse->rate = 40;
  650. }
  651. return 0;
  652. init_fail:
  653. kfree(priv);
  654. return -1;
  655. }
  656. bool synaptics_supported(void)
  657. {
  658. return true;
  659. }
  660. #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
  661. void __init synaptics_module_init(void)
  662. {
  663. }
  664. int synaptics_init(struct psmouse *psmouse)
  665. {
  666. return -ENOSYS;
  667. }
  668. bool synaptics_supported(void)
  669. {
  670. return false;
  671. }
  672. #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */