synaptics.c 20 KB

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