synaptics.c 19 KB

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