/drivers/input/mouse/synaptics.c

https://bitbucket.org/evzijst/gittest · C · 700 lines · 500 code · 116 blank · 84 comment · 109 complexity · d5d499576292ff7eeb66ee9099144715 MD5 · raw file

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