alps.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * ALPS touchpad PS/2 mouse driver
  3. *
  4. * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
  5. * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
  6. * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
  7. * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
  8. *
  9. * ALPS detection, tap switching and status querying info is taken from
  10. * tpconfig utility (by C. Scott Ananian and Bruce Kall).
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published by
  14. * the Free Software Foundation.
  15. */
  16. #include <linux/input.h>
  17. #include <linux/serio.h>
  18. #include <linux/libps2.h>
  19. #include "psmouse.h"
  20. #include "alps.h"
  21. #undef DEBUG
  22. #ifdef DEBUG
  23. #define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
  24. #else
  25. #define dbg(format, arg...) do {} while (0)
  26. #endif
  27. #define ALPS_OLDPROTO 0x01 /* old style input */
  28. #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
  29. #define ALPS_PASS 0x04 /* device has a pass-through port */
  30. #define ALPS_WHEEL 0x08 /* hardware wheel present */
  31. #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
  32. #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
  33. #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
  34. static const struct alps_model_info alps_model_data[] = {
  35. { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
  36. { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
  37. { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
  38. { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
  39. { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */
  40. { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
  41. { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
  42. { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
  43. { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
  44. { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
  45. { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
  46. { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
  47. { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
  48. { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
  49. { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
  50. { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
  51. { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
  52. { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
  53. { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude E6500 */
  54. { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
  55. };
  56. /*
  57. * XXX - this entry is suspicious. First byte has zero lower nibble,
  58. * which is what a normal mouse would report. Also, the value 0x0e
  59. * isn't valid per PS/2 spec.
  60. */
  61. /*
  62. * ALPS abolute Mode - new format
  63. *
  64. * byte 0: 1 ? ? ? 1 ? ? ?
  65. * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
  66. * byte 2: 0 x10 x9 x8 x7 ? fin ges
  67. * byte 3: 0 y9 y8 y7 1 M R L
  68. * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
  69. * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
  70. *
  71. * ?'s can have different meanings on different models,
  72. * such as wheel rotation, extra buttons, stick buttons
  73. * on a dualpoint, etc.
  74. */
  75. static void alps_process_packet(struct psmouse *psmouse)
  76. {
  77. struct alps_data *priv = psmouse->private;
  78. const struct alps_model_info *model = priv->i;
  79. unsigned char *packet = psmouse->packet;
  80. struct input_dev *dev = psmouse->dev;
  81. struct input_dev *dev2 = priv->dev2;
  82. int x, y, z, ges, fin, left, right, middle;
  83. int back = 0, forward = 0;
  84. if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */
  85. input_report_key(dev2, BTN_LEFT, packet[0] & 1);
  86. input_report_key(dev2, BTN_RIGHT, packet[0] & 2);
  87. input_report_key(dev2, BTN_MIDDLE, packet[0] & 4);
  88. input_report_rel(dev2, REL_X,
  89. packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
  90. input_report_rel(dev2, REL_Y,
  91. packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
  92. input_sync(dev2);
  93. return;
  94. }
  95. if (model->flags & ALPS_OLDPROTO) {
  96. left = packet[2] & 0x10;
  97. right = packet[2] & 0x08;
  98. middle = 0;
  99. x = packet[1] | ((packet[0] & 0x07) << 7);
  100. y = packet[4] | ((packet[3] & 0x07) << 7);
  101. z = packet[5];
  102. } else {
  103. left = packet[3] & 1;
  104. right = packet[3] & 2;
  105. middle = packet[3] & 4;
  106. x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
  107. y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
  108. z = packet[5];
  109. }
  110. if (model->flags & ALPS_FW_BK_1) {
  111. back = packet[0] & 0x10;
  112. forward = packet[2] & 4;
  113. }
  114. if (model->flags & ALPS_FW_BK_2) {
  115. back = packet[3] & 4;
  116. forward = packet[2] & 4;
  117. if ((middle = forward && back))
  118. forward = back = 0;
  119. }
  120. ges = packet[2] & 1;
  121. fin = packet[2] & 2;
  122. if ((model->flags & ALPS_DUALPOINT) && z == 127) {
  123. input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
  124. input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
  125. input_report_key(dev2, BTN_LEFT, left);
  126. input_report_key(dev2, BTN_RIGHT, right);
  127. input_report_key(dev2, BTN_MIDDLE, middle);
  128. input_sync(dev);
  129. input_sync(dev2);
  130. return;
  131. }
  132. input_report_key(dev, BTN_LEFT, left);
  133. input_report_key(dev, BTN_RIGHT, right);
  134. input_report_key(dev, BTN_MIDDLE, middle);
  135. /* Convert hardware tap to a reasonable Z value */
  136. if (ges && !fin)
  137. z = 40;
  138. /*
  139. * A "tap and drag" operation is reported by the hardware as a transition
  140. * from (!fin && ges) to (fin && ges). This should be translated to the
  141. * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
  142. */
  143. if (ges && fin && !priv->prev_fin) {
  144. input_report_abs(dev, ABS_X, x);
  145. input_report_abs(dev, ABS_Y, y);
  146. input_report_abs(dev, ABS_PRESSURE, 0);
  147. input_report_key(dev, BTN_TOOL_FINGER, 0);
  148. input_sync(dev);
  149. }
  150. priv->prev_fin = fin;
  151. if (z > 30)
  152. input_report_key(dev, BTN_TOUCH, 1);
  153. if (z < 25)
  154. input_report_key(dev, BTN_TOUCH, 0);
  155. if (z > 0) {
  156. input_report_abs(dev, ABS_X, x);
  157. input_report_abs(dev, ABS_Y, y);
  158. }
  159. input_report_abs(dev, ABS_PRESSURE, z);
  160. input_report_key(dev, BTN_TOOL_FINGER, z > 0);
  161. if (model->flags & ALPS_WHEEL)
  162. input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
  163. if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
  164. input_report_key(dev, BTN_FORWARD, forward);
  165. input_report_key(dev, BTN_BACK, back);
  166. }
  167. if (model->flags & ALPS_FOUR_BUTTONS) {
  168. input_report_key(dev, BTN_0, packet[2] & 4);
  169. input_report_key(dev, BTN_1, packet[0] & 0x10);
  170. input_report_key(dev, BTN_2, packet[3] & 4);
  171. input_report_key(dev, BTN_3, packet[0] & 0x20);
  172. }
  173. input_sync(dev);
  174. }
  175. static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
  176. {
  177. struct alps_data *priv = psmouse->private;
  178. if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
  179. if (psmouse->pktcnt == 3) {
  180. alps_process_packet(psmouse);
  181. return PSMOUSE_FULL_PACKET;
  182. }
  183. return PSMOUSE_GOOD_DATA;
  184. }
  185. if ((psmouse->packet[0] & priv->i->mask0) != priv->i->byte0)
  186. return PSMOUSE_BAD_DATA;
  187. /* Bytes 2 - 6 should have 0 in the highest bit */
  188. if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
  189. (psmouse->packet[psmouse->pktcnt - 1] & 0x80))
  190. return PSMOUSE_BAD_DATA;
  191. if (psmouse->pktcnt == 6) {
  192. alps_process_packet(psmouse);
  193. return PSMOUSE_FULL_PACKET;
  194. }
  195. return PSMOUSE_GOOD_DATA;
  196. }
  197. static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
  198. {
  199. struct ps2dev *ps2dev = &psmouse->ps2dev;
  200. static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
  201. unsigned char param[4];
  202. int i;
  203. /*
  204. * First try "E6 report".
  205. * ALPS should return 0,0,10 or 0,0,100
  206. */
  207. param[0] = 0;
  208. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
  209. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  210. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  211. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
  212. return NULL;
  213. param[0] = param[1] = param[2] = 0xff;
  214. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  215. return NULL;
  216. dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
  217. if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
  218. return NULL;
  219. /*
  220. * Now try "E7 report". Allowed responses are in
  221. * alps_model_data[].signature
  222. */
  223. param[0] = 0;
  224. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
  225. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  226. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  227. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
  228. return NULL;
  229. param[0] = param[1] = param[2] = 0xff;
  230. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  231. return NULL;
  232. dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
  233. if (version) {
  234. for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
  235. /* empty */;
  236. *version = (param[0] << 8) | (param[1] << 4) | i;
  237. }
  238. for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
  239. if (!memcmp(param, alps_model_data[i].signature,
  240. sizeof(alps_model_data[i].signature)))
  241. return alps_model_data + i;
  242. return NULL;
  243. }
  244. /*
  245. * For DualPoint devices select the device that should respond to
  246. * subsequent commands. It looks like glidepad is behind stickpointer,
  247. * I'd thought it would be other way around...
  248. */
  249. static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
  250. {
  251. struct ps2dev *ps2dev = &psmouse->ps2dev;
  252. int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
  253. if (ps2_command(ps2dev, NULL, cmd) ||
  254. ps2_command(ps2dev, NULL, cmd) ||
  255. ps2_command(ps2dev, NULL, cmd) ||
  256. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
  257. return -1;
  258. /* we may get 3 more bytes, just ignore them */
  259. ps2_drain(ps2dev, 3, 100);
  260. return 0;
  261. }
  262. static int alps_absolute_mode(struct psmouse *psmouse)
  263. {
  264. struct ps2dev *ps2dev = &psmouse->ps2dev;
  265. /* Try ALPS magic knock - 4 disable before enable */
  266. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  267. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  268. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  269. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  270. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
  271. return -1;
  272. /*
  273. * Switch mouse to poll (remote) mode so motion data will not
  274. * get in our way
  275. */
  276. return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
  277. }
  278. static int alps_get_status(struct psmouse *psmouse, char *param)
  279. {
  280. struct ps2dev *ps2dev = &psmouse->ps2dev;
  281. /* Get status: 0xF5 0xF5 0xF5 0xE9 */
  282. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  283. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  284. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  285. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  286. return -1;
  287. dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
  288. return 0;
  289. }
  290. /*
  291. * Turn touchpad tapping on or off. The sequences are:
  292. * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
  293. * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
  294. * My guess that 0xE9 (GetInfo) is here as a sync point.
  295. * For models that also have stickpointer (DualPoints) its tapping
  296. * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
  297. * we don't fiddle with it.
  298. */
  299. static int alps_tap_mode(struct psmouse *psmouse, int enable)
  300. {
  301. struct ps2dev *ps2dev = &psmouse->ps2dev;
  302. int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
  303. unsigned char tap_arg = enable ? 0x0A : 0x00;
  304. unsigned char param[4];
  305. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
  306. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  307. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  308. ps2_command(ps2dev, &tap_arg, cmd))
  309. return -1;
  310. if (alps_get_status(psmouse, param))
  311. return -1;
  312. return 0;
  313. }
  314. /*
  315. * alps_poll() - poll the touchpad for current motion packet.
  316. * Used in resync.
  317. */
  318. static int alps_poll(struct psmouse *psmouse)
  319. {
  320. struct alps_data *priv = psmouse->private;
  321. unsigned char buf[6];
  322. bool poll_failed;
  323. if (priv->i->flags & ALPS_PASS)
  324. alps_passthrough_mode(psmouse, true);
  325. poll_failed = ps2_command(&psmouse->ps2dev, buf,
  326. PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
  327. if (priv->i->flags & ALPS_PASS)
  328. alps_passthrough_mode(psmouse, false);
  329. if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
  330. return -1;
  331. if ((psmouse->badbyte & 0xc8) == 0x08) {
  332. /*
  333. * Poll the track stick ...
  334. */
  335. if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
  336. return -1;
  337. }
  338. memcpy(psmouse->packet, buf, sizeof(buf));
  339. return 0;
  340. }
  341. static int alps_hw_init(struct psmouse *psmouse)
  342. {
  343. struct alps_data *priv = psmouse->private;
  344. const struct alps_model_info *model = priv->i;
  345. if ((model->flags & ALPS_PASS) &&
  346. alps_passthrough_mode(psmouse, true)) {
  347. return -1;
  348. }
  349. if (alps_tap_mode(psmouse, true)) {
  350. printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
  351. return -1;
  352. }
  353. if (alps_absolute_mode(psmouse)) {
  354. printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
  355. return -1;
  356. }
  357. if ((model->flags & ALPS_PASS) &&
  358. alps_passthrough_mode(psmouse, false)) {
  359. return -1;
  360. }
  361. /* ALPS needs stream mode, otherwise it won't report any data */
  362. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
  363. printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
  364. return -1;
  365. }
  366. return 0;
  367. }
  368. static int alps_reconnect(struct psmouse *psmouse)
  369. {
  370. const struct alps_model_info *model;
  371. psmouse_reset(psmouse);
  372. model = alps_get_model(psmouse, NULL);
  373. if (!model)
  374. return -1;
  375. return alps_hw_init(psmouse);
  376. }
  377. static void alps_disconnect(struct psmouse *psmouse)
  378. {
  379. struct alps_data *priv = psmouse->private;
  380. psmouse_reset(psmouse);
  381. input_unregister_device(priv->dev2);
  382. kfree(priv);
  383. }
  384. int alps_init(struct psmouse *psmouse)
  385. {
  386. struct alps_data *priv;
  387. const struct alps_model_info *model;
  388. struct input_dev *dev1 = psmouse->dev, *dev2;
  389. int version;
  390. priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
  391. dev2 = input_allocate_device();
  392. if (!priv || !dev2)
  393. goto init_fail;
  394. priv->dev2 = dev2;
  395. psmouse->private = priv;
  396. model = alps_get_model(psmouse, &version);
  397. if (!model)
  398. goto init_fail;
  399. priv->i = model;
  400. if (alps_hw_init(psmouse))
  401. goto init_fail;
  402. dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
  403. dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
  404. dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
  405. dev1->keybit[BIT_WORD(BTN_LEFT)] |=
  406. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
  407. dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
  408. input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
  409. input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
  410. input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
  411. if (model->flags & ALPS_WHEEL) {
  412. dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
  413. dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
  414. }
  415. if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
  416. dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
  417. dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
  418. }
  419. if (model->flags & ALPS_FOUR_BUTTONS) {
  420. dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
  421. dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
  422. dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
  423. dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
  424. } else {
  425. dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
  426. }
  427. snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
  428. dev2->phys = priv->phys;
  429. dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
  430. dev2->id.bustype = BUS_I8042;
  431. dev2->id.vendor = 0x0002;
  432. dev2->id.product = PSMOUSE_ALPS;
  433. dev2->id.version = 0x0000;
  434. dev2->dev.parent = &psmouse->ps2dev.serio->dev;
  435. dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  436. dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  437. dev2->keybit[BIT_WORD(BTN_LEFT)] =
  438. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  439. if (input_register_device(priv->dev2))
  440. goto init_fail;
  441. psmouse->protocol_handler = alps_process_byte;
  442. psmouse->poll = alps_poll;
  443. psmouse->disconnect = alps_disconnect;
  444. psmouse->reconnect = alps_reconnect;
  445. psmouse->pktsize = 6;
  446. /* We are having trouble resyncing ALPS touchpads so disable it for now */
  447. psmouse->resync_time = 0;
  448. return 0;
  449. init_fail:
  450. psmouse_reset(psmouse);
  451. input_free_device(dev2);
  452. kfree(priv);
  453. psmouse->private = NULL;
  454. return -1;
  455. }
  456. int alps_detect(struct psmouse *psmouse, bool set_properties)
  457. {
  458. int version;
  459. const struct alps_model_info *model;
  460. model = alps_get_model(psmouse, &version);
  461. if (!model)
  462. return -1;
  463. if (set_properties) {
  464. psmouse->vendor = "ALPS";
  465. psmouse->name = model->flags & ALPS_DUALPOINT ?
  466. "DualPoint TouchPad" : "GlidePoint";
  467. psmouse->model = version;
  468. }
  469. return 0;
  470. }