synaptics.c 20 KB

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