alps.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  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. * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
  9. *
  10. * ALPS detection, tap switching and status querying info is taken from
  11. * tpconfig utility (by C. Scott Ananian and Bruce Kall).
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License version 2 as published by
  15. * the Free Software Foundation.
  16. */
  17. #include <linux/slab.h>
  18. #include <linux/input.h>
  19. #include <linux/input/mt.h>
  20. #include <linux/serio.h>
  21. #include <linux/libps2.h>
  22. #include "psmouse.h"
  23. #include "alps.h"
  24. /*
  25. * Definitions for ALPS version 3 and 4 command mode protocol
  26. */
  27. #define ALPS_V3_X_MAX 2000
  28. #define ALPS_V3_Y_MAX 1400
  29. #define ALPS_BITMAP_X_BITS 15
  30. #define ALPS_BITMAP_Y_BITS 11
  31. #define ALPS_CMD_NIBBLE_10 0x01f2
  32. static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
  33. { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
  34. { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
  35. { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
  36. { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
  37. { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
  38. { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
  39. { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
  40. { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
  41. { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
  42. { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
  43. { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
  44. { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
  45. { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
  46. { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
  47. { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
  48. { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
  49. };
  50. static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
  51. { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
  52. { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
  53. { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
  54. { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
  55. { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
  56. { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
  57. { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
  58. { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
  59. { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
  60. { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
  61. { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
  62. { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
  63. { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
  64. { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
  65. { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
  66. { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
  67. };
  68. #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
  69. #define ALPS_PASS 0x04 /* device has a pass-through port */
  70. #define ALPS_WHEEL 0x08 /* hardware wheel present */
  71. #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
  72. #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
  73. #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
  74. #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
  75. 6-byte ALPS packet */
  76. static const struct alps_model_info alps_model_data[] = {
  77. { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
  78. { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
  79. { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  80. { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  81. { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
  82. { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  83. { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  84. { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
  85. { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
  86. { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
  87. { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  88. { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
  89. { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
  90. { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
  91. { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
  92. { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
  93. { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
  94. { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
  95. /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
  96. { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
  97. ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
  98. { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
  99. { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
  100. ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
  101. { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
  102. };
  103. static void alps_set_abs_params_st(struct alps_data *priv,
  104. struct input_dev *dev1);
  105. static void alps_set_abs_params_mt(struct alps_data *priv,
  106. struct input_dev *dev1);
  107. /*
  108. * XXX - this entry is suspicious. First byte has zero lower nibble,
  109. * which is what a normal mouse would report. Also, the value 0x0e
  110. * isn't valid per PS/2 spec.
  111. */
  112. /* Packet formats are described in Documentation/input/alps.txt */
  113. static bool alps_is_valid_first_byte(struct alps_data *priv,
  114. unsigned char data)
  115. {
  116. return (data & priv->mask0) == priv->byte0;
  117. }
  118. static void alps_report_buttons(struct psmouse *psmouse,
  119. struct input_dev *dev1, struct input_dev *dev2,
  120. int left, int right, int middle)
  121. {
  122. struct input_dev *dev;
  123. /*
  124. * If shared button has already been reported on the
  125. * other device (dev2) then this event should be also
  126. * sent through that device.
  127. */
  128. dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
  129. input_report_key(dev, BTN_LEFT, left);
  130. dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
  131. input_report_key(dev, BTN_RIGHT, right);
  132. dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
  133. input_report_key(dev, BTN_MIDDLE, middle);
  134. /*
  135. * Sync the _other_ device now, we'll do the first
  136. * device later once we report the rest of the events.
  137. */
  138. input_sync(dev2);
  139. }
  140. static void alps_process_packet_v1_v2(struct psmouse *psmouse)
  141. {
  142. struct alps_data *priv = psmouse->private;
  143. unsigned char *packet = psmouse->packet;
  144. struct input_dev *dev = psmouse->dev;
  145. struct input_dev *dev2 = priv->dev2;
  146. int x, y, z, ges, fin, left, right, middle;
  147. int back = 0, forward = 0;
  148. if (priv->proto_version == ALPS_PROTO_V1) {
  149. left = packet[2] & 0x10;
  150. right = packet[2] & 0x08;
  151. middle = 0;
  152. x = packet[1] | ((packet[0] & 0x07) << 7);
  153. y = packet[4] | ((packet[3] & 0x07) << 7);
  154. z = packet[5];
  155. } else {
  156. left = packet[3] & 1;
  157. right = packet[3] & 2;
  158. middle = packet[3] & 4;
  159. x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
  160. y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
  161. z = packet[5];
  162. }
  163. if (priv->flags & ALPS_FW_BK_1) {
  164. back = packet[0] & 0x10;
  165. forward = packet[2] & 4;
  166. }
  167. if (priv->flags & ALPS_FW_BK_2) {
  168. back = packet[3] & 4;
  169. forward = packet[2] & 4;
  170. if ((middle = forward && back))
  171. forward = back = 0;
  172. }
  173. ges = packet[2] & 1;
  174. fin = packet[2] & 2;
  175. if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
  176. input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
  177. input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
  178. alps_report_buttons(psmouse, dev2, dev, left, right, middle);
  179. input_sync(dev2);
  180. return;
  181. }
  182. alps_report_buttons(psmouse, dev, dev2, left, right, middle);
  183. /* Convert hardware tap to a reasonable Z value */
  184. if (ges && !fin)
  185. z = 40;
  186. /*
  187. * A "tap and drag" operation is reported by the hardware as a transition
  188. * from (!fin && ges) to (fin && ges). This should be translated to the
  189. * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
  190. */
  191. if (ges && fin && !priv->prev_fin) {
  192. input_report_abs(dev, ABS_X, x);
  193. input_report_abs(dev, ABS_Y, y);
  194. input_report_abs(dev, ABS_PRESSURE, 0);
  195. input_report_key(dev, BTN_TOOL_FINGER, 0);
  196. input_sync(dev);
  197. }
  198. priv->prev_fin = fin;
  199. if (z > 30)
  200. input_report_key(dev, BTN_TOUCH, 1);
  201. if (z < 25)
  202. input_report_key(dev, BTN_TOUCH, 0);
  203. if (z > 0) {
  204. input_report_abs(dev, ABS_X, x);
  205. input_report_abs(dev, ABS_Y, y);
  206. }
  207. input_report_abs(dev, ABS_PRESSURE, z);
  208. input_report_key(dev, BTN_TOOL_FINGER, z > 0);
  209. if (priv->flags & ALPS_WHEEL)
  210. input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
  211. if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
  212. input_report_key(dev, BTN_FORWARD, forward);
  213. input_report_key(dev, BTN_BACK, back);
  214. }
  215. if (priv->flags & ALPS_FOUR_BUTTONS) {
  216. input_report_key(dev, BTN_0, packet[2] & 4);
  217. input_report_key(dev, BTN_1, packet[0] & 0x10);
  218. input_report_key(dev, BTN_2, packet[3] & 4);
  219. input_report_key(dev, BTN_3, packet[0] & 0x20);
  220. }
  221. input_sync(dev);
  222. }
  223. /*
  224. * Process bitmap data from v3 and v4 protocols. Returns the number of
  225. * fingers detected. A return value of 0 means at least one of the
  226. * bitmaps was empty.
  227. *
  228. * The bitmaps don't have enough data to track fingers, so this function
  229. * only generates points representing a bounding box of all contacts.
  230. * These points are returned in x1, y1, x2, and y2 when the return value
  231. * is greater than 0.
  232. */
  233. static int alps_process_bitmap(unsigned int x_map, unsigned int y_map,
  234. int *x1, int *y1, int *x2, int *y2)
  235. {
  236. struct alps_bitmap_point {
  237. int start_bit;
  238. int num_bits;
  239. };
  240. int fingers_x = 0, fingers_y = 0, fingers;
  241. int i, bit, prev_bit;
  242. struct alps_bitmap_point x_low = {0,}, x_high = {0,};
  243. struct alps_bitmap_point y_low = {0,}, y_high = {0,};
  244. struct alps_bitmap_point *point;
  245. if (!x_map || !y_map)
  246. return 0;
  247. *x1 = *y1 = *x2 = *y2 = 0;
  248. prev_bit = 0;
  249. point = &x_low;
  250. for (i = 0; x_map != 0; i++, x_map >>= 1) {
  251. bit = x_map & 1;
  252. if (bit) {
  253. if (!prev_bit) {
  254. point->start_bit = i;
  255. fingers_x++;
  256. }
  257. point->num_bits++;
  258. } else {
  259. if (prev_bit)
  260. point = &x_high;
  261. else
  262. point->num_bits = 0;
  263. }
  264. prev_bit = bit;
  265. }
  266. /*
  267. * y bitmap is reversed for what we need (lower positions are in
  268. * higher bits), so we process from the top end.
  269. */
  270. y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS);
  271. prev_bit = 0;
  272. point = &y_low;
  273. for (i = 0; y_map != 0; i++, y_map <<= 1) {
  274. bit = y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1));
  275. if (bit) {
  276. if (!prev_bit) {
  277. point->start_bit = i;
  278. fingers_y++;
  279. }
  280. point->num_bits++;
  281. } else {
  282. if (prev_bit)
  283. point = &y_high;
  284. else
  285. point->num_bits = 0;
  286. }
  287. prev_bit = bit;
  288. }
  289. /*
  290. * Fingers can overlap, so we use the maximum count of fingers
  291. * on either axis as the finger count.
  292. */
  293. fingers = max(fingers_x, fingers_y);
  294. /*
  295. * If total fingers is > 1 but either axis reports only a single
  296. * contact, we have overlapping or adjacent fingers. For the
  297. * purposes of creating a bounding box, divide the single contact
  298. * (roughly) equally between the two points.
  299. */
  300. if (fingers > 1) {
  301. if (fingers_x == 1) {
  302. i = x_low.num_bits / 2;
  303. x_low.num_bits = x_low.num_bits - i;
  304. x_high.start_bit = x_low.start_bit + i;
  305. x_high.num_bits = max(i, 1);
  306. } else if (fingers_y == 1) {
  307. i = y_low.num_bits / 2;
  308. y_low.num_bits = y_low.num_bits - i;
  309. y_high.start_bit = y_low.start_bit + i;
  310. y_high.num_bits = max(i, 1);
  311. }
  312. }
  313. *x1 = (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) /
  314. (2 * (ALPS_BITMAP_X_BITS - 1));
  315. *y1 = (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) /
  316. (2 * (ALPS_BITMAP_Y_BITS - 1));
  317. if (fingers > 1) {
  318. *x2 = (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)) /
  319. (2 * (ALPS_BITMAP_X_BITS - 1));
  320. *y2 = (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)) /
  321. (2 * (ALPS_BITMAP_Y_BITS - 1));
  322. }
  323. return fingers;
  324. }
  325. static void alps_set_slot(struct input_dev *dev, int slot, bool active,
  326. int x, int y)
  327. {
  328. input_mt_slot(dev, slot);
  329. input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
  330. if (active) {
  331. input_report_abs(dev, ABS_MT_POSITION_X, x);
  332. input_report_abs(dev, ABS_MT_POSITION_Y, y);
  333. }
  334. }
  335. static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
  336. int x1, int y1, int x2, int y2)
  337. {
  338. alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
  339. alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
  340. }
  341. static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
  342. {
  343. struct alps_data *priv = psmouse->private;
  344. unsigned char *packet = psmouse->packet;
  345. struct input_dev *dev = priv->dev2;
  346. int x, y, z, left, right, middle;
  347. /* Sanity check packet */
  348. if (!(packet[0] & 0x40)) {
  349. psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
  350. return;
  351. }
  352. /*
  353. * There's a special packet that seems to indicate the end
  354. * of a stream of trackstick data. Filter these out.
  355. */
  356. if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
  357. return;
  358. x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
  359. y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
  360. z = (packet[4] & 0x7c) >> 2;
  361. /*
  362. * The x and y values tend to be quite large, and when used
  363. * alone the trackstick is difficult to use. Scale them down
  364. * to compensate.
  365. */
  366. x /= 8;
  367. y /= 8;
  368. input_report_rel(dev, REL_X, x);
  369. input_report_rel(dev, REL_Y, -y);
  370. /*
  371. * Most ALPS models report the trackstick buttons in the touchpad
  372. * packets, but a few report them here. No reliable way has been
  373. * found to differentiate between the models upfront, so we enable
  374. * the quirk in response to seeing a button press in the trackstick
  375. * packet.
  376. */
  377. left = packet[3] & 0x01;
  378. right = packet[3] & 0x02;
  379. middle = packet[3] & 0x04;
  380. if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
  381. (left || right || middle))
  382. priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
  383. if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
  384. input_report_key(dev, BTN_LEFT, left);
  385. input_report_key(dev, BTN_RIGHT, right);
  386. input_report_key(dev, BTN_MIDDLE, middle);
  387. }
  388. input_sync(dev);
  389. return;
  390. }
  391. static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
  392. {
  393. struct alps_data *priv = psmouse->private;
  394. unsigned char *packet = psmouse->packet;
  395. struct input_dev *dev = psmouse->dev;
  396. struct input_dev *dev2 = priv->dev2;
  397. int x, y, z;
  398. int left, right, middle;
  399. int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  400. int fingers = 0, bmap_fingers;
  401. unsigned int x_bitmap, y_bitmap;
  402. /*
  403. * There's no single feature of touchpad position and bitmap packets
  404. * that can be used to distinguish between them. We rely on the fact
  405. * that a bitmap packet should always follow a position packet with
  406. * bit 6 of packet[4] set.
  407. */
  408. if (priv->multi_packet) {
  409. /*
  410. * Sometimes a position packet will indicate a multi-packet
  411. * sequence, but then what follows is another position
  412. * packet. Check for this, and when it happens process the
  413. * position packet as usual.
  414. */
  415. if (packet[0] & 0x40) {
  416. fingers = (packet[5] & 0x3) + 1;
  417. x_bitmap = ((packet[4] & 0x7e) << 8) |
  418. ((packet[1] & 0x7f) << 2) |
  419. ((packet[0] & 0x30) >> 4);
  420. y_bitmap = ((packet[3] & 0x70) << 4) |
  421. ((packet[2] & 0x7f) << 1) |
  422. (packet[4] & 0x01);
  423. bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap,
  424. &x1, &y1, &x2, &y2);
  425. /*
  426. * We shouldn't report more than one finger if
  427. * we don't have two coordinates.
  428. */
  429. if (fingers > 1 && bmap_fingers < 2)
  430. fingers = bmap_fingers;
  431. /* Now process position packet */
  432. packet = priv->multi_data;
  433. } else {
  434. priv->multi_packet = 0;
  435. }
  436. }
  437. /*
  438. * Bit 6 of byte 0 is not usually set in position packets. The only
  439. * times it seems to be set is in situations where the data is
  440. * suspect anyway, e.g. a palm resting flat on the touchpad. Given
  441. * this combined with the fact that this bit is useful for filtering
  442. * out misidentified bitmap packets, we reject anything with this
  443. * bit set.
  444. */
  445. if (packet[0] & 0x40)
  446. return;
  447. if (!priv->multi_packet && (packet[4] & 0x40)) {
  448. priv->multi_packet = 1;
  449. memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
  450. return;
  451. }
  452. priv->multi_packet = 0;
  453. left = packet[3] & 0x01;
  454. right = packet[3] & 0x02;
  455. middle = packet[3] & 0x04;
  456. x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) |
  457. ((packet[0] & 0x30) >> 4);
  458. y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f);
  459. z = packet[5] & 0x7f;
  460. /*
  461. * Sometimes the hardware sends a single packet with z = 0
  462. * in the middle of a stream. Real releases generate packets
  463. * with x, y, and z all zero, so these seem to be flukes.
  464. * Ignore them.
  465. */
  466. if (x && y && !z)
  467. return;
  468. /*
  469. * If we don't have MT data or the bitmaps were empty, we have
  470. * to rely on ST data.
  471. */
  472. if (!fingers) {
  473. x1 = x;
  474. y1 = y;
  475. fingers = z > 0 ? 1 : 0;
  476. }
  477. if (z >= 64)
  478. input_report_key(dev, BTN_TOUCH, 1);
  479. else
  480. input_report_key(dev, BTN_TOUCH, 0);
  481. alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
  482. input_mt_report_finger_count(dev, fingers);
  483. input_report_key(dev, BTN_LEFT, left);
  484. input_report_key(dev, BTN_RIGHT, right);
  485. input_report_key(dev, BTN_MIDDLE, middle);
  486. if (z > 0) {
  487. input_report_abs(dev, ABS_X, x);
  488. input_report_abs(dev, ABS_Y, y);
  489. }
  490. input_report_abs(dev, ABS_PRESSURE, z);
  491. input_sync(dev);
  492. if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
  493. left = packet[3] & 0x10;
  494. right = packet[3] & 0x20;
  495. middle = packet[3] & 0x40;
  496. input_report_key(dev2, BTN_LEFT, left);
  497. input_report_key(dev2, BTN_RIGHT, right);
  498. input_report_key(dev2, BTN_MIDDLE, middle);
  499. input_sync(dev2);
  500. }
  501. }
  502. static void alps_process_packet_v3(struct psmouse *psmouse)
  503. {
  504. unsigned char *packet = psmouse->packet;
  505. /*
  506. * v3 protocol packets come in three types, two representing
  507. * touchpad data and one representing trackstick data.
  508. * Trackstick packets seem to be distinguished by always
  509. * having 0x3f in the last byte. This value has never been
  510. * observed in the last byte of either of the other types
  511. * of packets.
  512. */
  513. if (packet[5] == 0x3f) {
  514. alps_process_trackstick_packet_v3(psmouse);
  515. return;
  516. }
  517. alps_process_touchpad_packet_v3(psmouse);
  518. }
  519. static void alps_process_packet_v4(struct psmouse *psmouse)
  520. {
  521. struct alps_data *priv = psmouse->private;
  522. unsigned char *packet = psmouse->packet;
  523. struct input_dev *dev = psmouse->dev;
  524. int offset;
  525. int x, y, z;
  526. int left, right;
  527. int x1, y1, x2, y2;
  528. int fingers = 0;
  529. unsigned int x_bitmap, y_bitmap;
  530. /*
  531. * v4 has a 6-byte encoding for bitmap data, but this data is
  532. * broken up between 3 normal packets. Use priv->multi_packet to
  533. * track our position in the bitmap packet.
  534. */
  535. if (packet[6] & 0x40) {
  536. /* sync, reset position */
  537. priv->multi_packet = 0;
  538. }
  539. if (WARN_ON_ONCE(priv->multi_packet > 2))
  540. return;
  541. offset = 2 * priv->multi_packet;
  542. priv->multi_data[offset] = packet[6];
  543. priv->multi_data[offset + 1] = packet[7];
  544. if (++priv->multi_packet > 2) {
  545. priv->multi_packet = 0;
  546. x_bitmap = ((priv->multi_data[2] & 0x1f) << 10) |
  547. ((priv->multi_data[3] & 0x60) << 3) |
  548. ((priv->multi_data[0] & 0x3f) << 2) |
  549. ((priv->multi_data[1] & 0x60) >> 5);
  550. y_bitmap = ((priv->multi_data[5] & 0x01) << 10) |
  551. ((priv->multi_data[3] & 0x1f) << 5) |
  552. (priv->multi_data[1] & 0x1f);
  553. fingers = alps_process_bitmap(x_bitmap, y_bitmap,
  554. &x1, &y1, &x2, &y2);
  555. /* Store MT data.*/
  556. priv->fingers = fingers;
  557. priv->x1 = x1;
  558. priv->x2 = x2;
  559. priv->y1 = y1;
  560. priv->y2 = y2;
  561. }
  562. left = packet[4] & 0x01;
  563. right = packet[4] & 0x02;
  564. x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
  565. ((packet[0] & 0x30) >> 4);
  566. y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
  567. z = packet[5] & 0x7f;
  568. /*
  569. * If there were no contacts in the bitmap, use ST
  570. * points in MT reports.
  571. * If there were two contacts or more, report MT data.
  572. */
  573. if (priv->fingers < 2) {
  574. x1 = x;
  575. y1 = y;
  576. fingers = z > 0 ? 1 : 0;
  577. } else {
  578. fingers = priv->fingers;
  579. x1 = priv->x1;
  580. x2 = priv->x2;
  581. y1 = priv->y1;
  582. y2 = priv->y2;
  583. }
  584. if (z >= 64)
  585. input_report_key(dev, BTN_TOUCH, 1);
  586. else
  587. input_report_key(dev, BTN_TOUCH, 0);
  588. alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
  589. input_mt_report_finger_count(dev, fingers);
  590. input_report_key(dev, BTN_LEFT, left);
  591. input_report_key(dev, BTN_RIGHT, right);
  592. if (z > 0) {
  593. input_report_abs(dev, ABS_X, x);
  594. input_report_abs(dev, ABS_Y, y);
  595. }
  596. input_report_abs(dev, ABS_PRESSURE, z);
  597. input_sync(dev);
  598. }
  599. static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
  600. unsigned char packet[],
  601. bool report_buttons)
  602. {
  603. struct alps_data *priv = psmouse->private;
  604. struct input_dev *dev2 = priv->dev2;
  605. if (report_buttons)
  606. alps_report_buttons(psmouse, dev2, psmouse->dev,
  607. packet[0] & 1, packet[0] & 2, packet[0] & 4);
  608. input_report_rel(dev2, REL_X,
  609. packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
  610. input_report_rel(dev2, REL_Y,
  611. packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
  612. input_sync(dev2);
  613. }
  614. static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
  615. {
  616. struct alps_data *priv = psmouse->private;
  617. if (psmouse->pktcnt < 6)
  618. return PSMOUSE_GOOD_DATA;
  619. if (psmouse->pktcnt == 6) {
  620. /*
  621. * Start a timer to flush the packet if it ends up last
  622. * 6-byte packet in the stream. Timer needs to fire
  623. * psmouse core times out itself. 20 ms should be enough
  624. * to decide if we are getting more data or not.
  625. */
  626. mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
  627. return PSMOUSE_GOOD_DATA;
  628. }
  629. del_timer(&priv->timer);
  630. if (psmouse->packet[6] & 0x80) {
  631. /*
  632. * Highest bit is set - that means we either had
  633. * complete ALPS packet and this is start of the
  634. * next packet or we got garbage.
  635. */
  636. if (((psmouse->packet[3] |
  637. psmouse->packet[4] |
  638. psmouse->packet[5]) & 0x80) ||
  639. (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
  640. psmouse_dbg(psmouse,
  641. "refusing packet %4ph (suspected interleaved ps/2)\n",
  642. psmouse->packet + 3);
  643. return PSMOUSE_BAD_DATA;
  644. }
  645. priv->process_packet(psmouse);
  646. /* Continue with the next packet */
  647. psmouse->packet[0] = psmouse->packet[6];
  648. psmouse->pktcnt = 1;
  649. } else {
  650. /*
  651. * High bit is 0 - that means that we indeed got a PS/2
  652. * packet in the middle of ALPS packet.
  653. *
  654. * There is also possibility that we got 6-byte ALPS
  655. * packet followed by 3-byte packet from trackpoint. We
  656. * can not distinguish between these 2 scenarios but
  657. * because the latter is unlikely to happen in course of
  658. * normal operation (user would need to press all
  659. * buttons on the pad and start moving trackpoint
  660. * without touching the pad surface) we assume former.
  661. * Even if we are wrong the wost thing that would happen
  662. * the cursor would jump but we should not get protocol
  663. * de-synchronization.
  664. */
  665. alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
  666. false);
  667. /*
  668. * Continue with the standard ALPS protocol handling,
  669. * but make sure we won't process it as an interleaved
  670. * packet again, which may happen if all buttons are
  671. * pressed. To avoid this let's reset the 4th bit which
  672. * is normally 1.
  673. */
  674. psmouse->packet[3] = psmouse->packet[6] & 0xf7;
  675. psmouse->pktcnt = 4;
  676. }
  677. return PSMOUSE_GOOD_DATA;
  678. }
  679. static void alps_flush_packet(unsigned long data)
  680. {
  681. struct psmouse *psmouse = (struct psmouse *)data;
  682. struct alps_data *priv = psmouse->private;
  683. serio_pause_rx(psmouse->ps2dev.serio);
  684. if (psmouse->pktcnt == psmouse->pktsize) {
  685. /*
  686. * We did not any more data in reasonable amount of time.
  687. * Validate the last 3 bytes and process as a standard
  688. * ALPS packet.
  689. */
  690. if ((psmouse->packet[3] |
  691. psmouse->packet[4] |
  692. psmouse->packet[5]) & 0x80) {
  693. psmouse_dbg(psmouse,
  694. "refusing packet %3ph (suspected interleaved ps/2)\n",
  695. psmouse->packet + 3);
  696. } else {
  697. priv->process_packet(psmouse);
  698. }
  699. psmouse->pktcnt = 0;
  700. }
  701. serio_continue_rx(psmouse->ps2dev.serio);
  702. }
  703. static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
  704. {
  705. struct alps_data *priv = psmouse->private;
  706. if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
  707. if (psmouse->pktcnt == 3) {
  708. alps_report_bare_ps2_packet(psmouse, psmouse->packet,
  709. true);
  710. return PSMOUSE_FULL_PACKET;
  711. }
  712. return PSMOUSE_GOOD_DATA;
  713. }
  714. /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
  715. if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
  716. psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
  717. return alps_handle_interleaved_ps2(psmouse);
  718. }
  719. if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
  720. psmouse_dbg(psmouse,
  721. "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
  722. psmouse->packet[0], priv->mask0, priv->byte0);
  723. return PSMOUSE_BAD_DATA;
  724. }
  725. /* Bytes 2 - pktsize should have 0 in the highest bit */
  726. if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
  727. (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
  728. psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
  729. psmouse->pktcnt - 1,
  730. psmouse->packet[psmouse->pktcnt - 1]);
  731. return PSMOUSE_BAD_DATA;
  732. }
  733. if (psmouse->pktcnt == psmouse->pktsize) {
  734. priv->process_packet(psmouse);
  735. return PSMOUSE_FULL_PACKET;
  736. }
  737. return PSMOUSE_GOOD_DATA;
  738. }
  739. static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
  740. {
  741. struct ps2dev *ps2dev = &psmouse->ps2dev;
  742. struct alps_data *priv = psmouse->private;
  743. int command;
  744. unsigned char *param;
  745. unsigned char dummy[4];
  746. BUG_ON(nibble > 0xf);
  747. command = priv->nibble_commands[nibble].command;
  748. param = (command & 0x0f00) ?
  749. dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
  750. if (ps2_command(ps2dev, param, command))
  751. return -1;
  752. return 0;
  753. }
  754. static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
  755. {
  756. struct ps2dev *ps2dev = &psmouse->ps2dev;
  757. struct alps_data *priv = psmouse->private;
  758. int i, nibble;
  759. if (ps2_command(ps2dev, NULL, priv->addr_command))
  760. return -1;
  761. for (i = 12; i >= 0; i -= 4) {
  762. nibble = (addr >> i) & 0xf;
  763. if (alps_command_mode_send_nibble(psmouse, nibble))
  764. return -1;
  765. }
  766. return 0;
  767. }
  768. static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
  769. {
  770. struct ps2dev *ps2dev = &psmouse->ps2dev;
  771. unsigned char param[4];
  772. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  773. return -1;
  774. /*
  775. * The address being read is returned in the first two bytes
  776. * of the result. Check that this address matches the expected
  777. * address.
  778. */
  779. if (addr != ((param[0] << 8) | param[1]))
  780. return -1;
  781. return param[2];
  782. }
  783. static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
  784. {
  785. if (alps_command_mode_set_addr(psmouse, addr))
  786. return -1;
  787. return __alps_command_mode_read_reg(psmouse, addr);
  788. }
  789. static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
  790. {
  791. if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
  792. return -1;
  793. if (alps_command_mode_send_nibble(psmouse, value & 0xf))
  794. return -1;
  795. return 0;
  796. }
  797. static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
  798. u8 value)
  799. {
  800. if (alps_command_mode_set_addr(psmouse, addr))
  801. return -1;
  802. return __alps_command_mode_write_reg(psmouse, value);
  803. }
  804. static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
  805. int repeated_command, unsigned char *param)
  806. {
  807. struct ps2dev *ps2dev = &psmouse->ps2dev;
  808. param[0] = 0;
  809. if (init_command && ps2_command(ps2dev, param, init_command))
  810. return -EIO;
  811. if (ps2_command(ps2dev, NULL, repeated_command) ||
  812. ps2_command(ps2dev, NULL, repeated_command) ||
  813. ps2_command(ps2dev, NULL, repeated_command))
  814. return -EIO;
  815. param[0] = param[1] = param[2] = 0xff;
  816. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  817. return -EIO;
  818. psmouse_dbg(psmouse, "%2.2X report: %2.2x %2.2x %2.2x\n",
  819. repeated_command, param[0], param[1], param[2]);
  820. return 0;
  821. }
  822. static int alps_enter_command_mode(struct psmouse *psmouse,
  823. unsigned char *resp)
  824. {
  825. unsigned char param[4];
  826. if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
  827. psmouse_err(psmouse, "failed to enter command mode\n");
  828. return -1;
  829. }
  830. if (param[0] != 0x88 && param[1] != 0x07) {
  831. psmouse_dbg(psmouse,
  832. "unknown response while entering command mode\n");
  833. return -1;
  834. }
  835. if (resp)
  836. *resp = param[2];
  837. return 0;
  838. }
  839. static inline int alps_exit_command_mode(struct psmouse *psmouse)
  840. {
  841. struct ps2dev *ps2dev = &psmouse->ps2dev;
  842. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
  843. return -1;
  844. return 0;
  845. }
  846. /*
  847. * For DualPoint devices select the device that should respond to
  848. * subsequent commands. It looks like glidepad is behind stickpointer,
  849. * I'd thought it would be other way around...
  850. */
  851. static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
  852. {
  853. struct ps2dev *ps2dev = &psmouse->ps2dev;
  854. int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
  855. if (ps2_command(ps2dev, NULL, cmd) ||
  856. ps2_command(ps2dev, NULL, cmd) ||
  857. ps2_command(ps2dev, NULL, cmd) ||
  858. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
  859. return -1;
  860. /* we may get 3 more bytes, just ignore them */
  861. ps2_drain(ps2dev, 3, 100);
  862. return 0;
  863. }
  864. static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
  865. {
  866. struct ps2dev *ps2dev = &psmouse->ps2dev;
  867. /* Try ALPS magic knock - 4 disable before enable */
  868. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  869. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  870. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  871. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  872. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
  873. return -1;
  874. /*
  875. * Switch mouse to poll (remote) mode so motion data will not
  876. * get in our way
  877. */
  878. return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
  879. }
  880. static int alps_get_status(struct psmouse *psmouse, char *param)
  881. {
  882. /* Get status: 0xF5 0xF5 0xF5 0xE9 */
  883. if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
  884. return -1;
  885. return 0;
  886. }
  887. /*
  888. * Turn touchpad tapping on or off. The sequences are:
  889. * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
  890. * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
  891. * My guess that 0xE9 (GetInfo) is here as a sync point.
  892. * For models that also have stickpointer (DualPoints) its tapping
  893. * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
  894. * we don't fiddle with it.
  895. */
  896. static int alps_tap_mode(struct psmouse *psmouse, int enable)
  897. {
  898. struct ps2dev *ps2dev = &psmouse->ps2dev;
  899. int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
  900. unsigned char tap_arg = enable ? 0x0A : 0x00;
  901. unsigned char param[4];
  902. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
  903. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  904. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  905. ps2_command(ps2dev, &tap_arg, cmd))
  906. return -1;
  907. if (alps_get_status(psmouse, param))
  908. return -1;
  909. return 0;
  910. }
  911. /*
  912. * alps_poll() - poll the touchpad for current motion packet.
  913. * Used in resync.
  914. */
  915. static int alps_poll(struct psmouse *psmouse)
  916. {
  917. struct alps_data *priv = psmouse->private;
  918. unsigned char buf[sizeof(psmouse->packet)];
  919. bool poll_failed;
  920. if (priv->flags & ALPS_PASS)
  921. alps_passthrough_mode_v2(psmouse, true);
  922. poll_failed = ps2_command(&psmouse->ps2dev, buf,
  923. PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
  924. if (priv->flags & ALPS_PASS)
  925. alps_passthrough_mode_v2(psmouse, false);
  926. if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
  927. return -1;
  928. if ((psmouse->badbyte & 0xc8) == 0x08) {
  929. /*
  930. * Poll the track stick ...
  931. */
  932. if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
  933. return -1;
  934. }
  935. memcpy(psmouse->packet, buf, sizeof(buf));
  936. return 0;
  937. }
  938. static int alps_hw_init_v1_v2(struct psmouse *psmouse)
  939. {
  940. struct alps_data *priv = psmouse->private;
  941. if ((priv->flags & ALPS_PASS) &&
  942. alps_passthrough_mode_v2(psmouse, true)) {
  943. return -1;
  944. }
  945. if (alps_tap_mode(psmouse, true)) {
  946. psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
  947. return -1;
  948. }
  949. if (alps_absolute_mode_v1_v2(psmouse)) {
  950. psmouse_err(psmouse, "Failed to enable absolute mode\n");
  951. return -1;
  952. }
  953. if ((priv->flags & ALPS_PASS) &&
  954. alps_passthrough_mode_v2(psmouse, false)) {
  955. return -1;
  956. }
  957. /* ALPS needs stream mode, otherwise it won't report any data */
  958. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
  959. psmouse_err(psmouse, "Failed to enable stream mode\n");
  960. return -1;
  961. }
  962. return 0;
  963. }
  964. /*
  965. * Enable or disable passthrough mode to the trackstick. Must be in
  966. * command mode when calling this function.
  967. */
  968. static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
  969. {
  970. int reg_val;
  971. reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
  972. if (reg_val == -1)
  973. return -1;
  974. if (enable)
  975. reg_val |= 0x01;
  976. else
  977. reg_val &= ~0x01;
  978. if (__alps_command_mode_write_reg(psmouse, reg_val))
  979. return -1;
  980. return 0;
  981. }
  982. /* Must be in command mode when calling this function */
  983. static int alps_absolute_mode_v3(struct psmouse *psmouse)
  984. {
  985. int reg_val;
  986. reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
  987. if (reg_val == -1)
  988. return -1;
  989. reg_val |= 0x06;
  990. if (__alps_command_mode_write_reg(psmouse, reg_val))
  991. return -1;
  992. return 0;
  993. }
  994. static int alps_hw_init_v3(struct psmouse *psmouse)
  995. {
  996. struct ps2dev *ps2dev = &psmouse->ps2dev;
  997. int reg_val;
  998. unsigned char param[4];
  999. if (alps_enter_command_mode(psmouse, NULL))
  1000. goto error;
  1001. /* Check for trackstick */
  1002. reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
  1003. if (reg_val == -1)
  1004. goto error;
  1005. if (reg_val & 0x80) {
  1006. if (alps_passthrough_mode_v3(psmouse, true))
  1007. goto error;
  1008. if (alps_exit_command_mode(psmouse))
  1009. goto error;
  1010. /*
  1011. * E7 report for the trackstick
  1012. *
  1013. * There have been reports of failures to seem to trace back
  1014. * to the above trackstick check failing. When these occur
  1015. * this E7 report fails, so when that happens we continue
  1016. * with the assumption that there isn't a trackstick after
  1017. * all.
  1018. */
  1019. param[0] = 0x64;
  1020. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1021. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1022. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1023. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  1024. psmouse_warn(psmouse, "trackstick E7 report failed\n");
  1025. } else {
  1026. psmouse_dbg(psmouse,
  1027. "trackstick E7 report: %2.2x %2.2x %2.2x\n",
  1028. param[0], param[1], param[2]);
  1029. /*
  1030. * Not sure what this does, but it is absolutely
  1031. * essential. Without it, the touchpad does not
  1032. * work at all and the trackstick just emits normal
  1033. * PS/2 packets.
  1034. */
  1035. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1036. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1037. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1038. alps_command_mode_send_nibble(psmouse, 0x9) ||
  1039. alps_command_mode_send_nibble(psmouse, 0x4)) {
  1040. psmouse_err(psmouse,
  1041. "Error sending magic E6 sequence\n");
  1042. goto error_passthrough;
  1043. }
  1044. }
  1045. if (alps_enter_command_mode(psmouse, NULL))
  1046. goto error_passthrough;
  1047. if (alps_passthrough_mode_v3(psmouse, false))
  1048. goto error;
  1049. }
  1050. if (alps_absolute_mode_v3(psmouse)) {
  1051. psmouse_err(psmouse, "Failed to enter absolute mode\n");
  1052. goto error;
  1053. }
  1054. reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
  1055. if (reg_val == -1)
  1056. goto error;
  1057. if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
  1058. goto error;
  1059. reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
  1060. if (reg_val == -1)
  1061. goto error;
  1062. if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
  1063. goto error;
  1064. if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
  1065. goto error;
  1066. if (__alps_command_mode_write_reg(psmouse, 0x04))
  1067. goto error;
  1068. if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
  1069. goto error;
  1070. if (__alps_command_mode_write_reg(psmouse, 0x03))
  1071. goto error;
  1072. if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
  1073. goto error;
  1074. if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
  1075. goto error;
  1076. if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
  1077. goto error;
  1078. if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
  1079. goto error;
  1080. /*
  1081. * This ensures the trackstick packets are in the format
  1082. * supported by this driver. If bit 1 isn't set the packet
  1083. * format is different.
  1084. */
  1085. if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
  1086. goto error;
  1087. alps_exit_command_mode(psmouse);
  1088. /* Set rate and enable data reporting */
  1089. param[0] = 0x64;
  1090. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
  1091. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1092. psmouse_err(psmouse, "Failed to enable data reporting\n");
  1093. return -1;
  1094. }
  1095. return 0;
  1096. error_passthrough:
  1097. /* Something failed while in passthrough mode, so try to get out */
  1098. if (!alps_enter_command_mode(psmouse, NULL))
  1099. alps_passthrough_mode_v3(psmouse, false);
  1100. error:
  1101. /*
  1102. * Leaving the touchpad in command mode will essentially render
  1103. * it unusable until the machine reboots, so exit it here just
  1104. * to be safe
  1105. */
  1106. alps_exit_command_mode(psmouse);
  1107. return -1;
  1108. }
  1109. /* Must be in command mode when calling this function */
  1110. static int alps_absolute_mode_v4(struct psmouse *psmouse)
  1111. {
  1112. int reg_val;
  1113. reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
  1114. if (reg_val == -1)
  1115. return -1;
  1116. reg_val |= 0x02;
  1117. if (__alps_command_mode_write_reg(psmouse, reg_val))
  1118. return -1;
  1119. return 0;
  1120. }
  1121. static int alps_hw_init_v4(struct psmouse *psmouse)
  1122. {
  1123. struct ps2dev *ps2dev = &psmouse->ps2dev;
  1124. unsigned char param[4];
  1125. if (alps_enter_command_mode(psmouse, NULL))
  1126. goto error;
  1127. if (alps_absolute_mode_v4(psmouse)) {
  1128. psmouse_err(psmouse, "Failed to enter absolute mode\n");
  1129. goto error;
  1130. }
  1131. if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
  1132. goto error;
  1133. if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
  1134. goto error;
  1135. if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
  1136. goto error;
  1137. if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
  1138. goto error;
  1139. if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
  1140. goto error;
  1141. if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
  1142. goto error;
  1143. if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
  1144. goto error;
  1145. if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
  1146. goto error;
  1147. alps_exit_command_mode(psmouse);
  1148. /*
  1149. * This sequence changes the output from a 9-byte to an
  1150. * 8-byte format. All the same data seems to be present,
  1151. * just in a more compact format.
  1152. */
  1153. param[0] = 0xc8;
  1154. param[1] = 0x64;
  1155. param[2] = 0x50;
  1156. if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
  1157. ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
  1158. ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
  1159. ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
  1160. return -1;
  1161. /* Set rate and enable data reporting */
  1162. param[0] = 0x64;
  1163. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
  1164. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1165. psmouse_err(psmouse, "Failed to enable data reporting\n");
  1166. return -1;
  1167. }
  1168. return 0;
  1169. error:
  1170. /*
  1171. * Leaving the touchpad in command mode will essentially render
  1172. * it unusable until the machine reboots, so exit it here just
  1173. * to be safe
  1174. */
  1175. alps_exit_command_mode(psmouse);
  1176. return -1;
  1177. }
  1178. static void alps_set_defaults(struct alps_data *priv)
  1179. {
  1180. priv->byte0 = 0x8f;
  1181. priv->mask0 = 0x8f;
  1182. priv->flags = ALPS_DUALPOINT;
  1183. switch (priv->proto_version) {
  1184. case ALPS_PROTO_V1:
  1185. case ALPS_PROTO_V2:
  1186. priv->hw_init = alps_hw_init_v1_v2;
  1187. priv->process_packet = alps_process_packet_v1_v2;
  1188. priv->set_abs_params = alps_set_abs_params_st;
  1189. break;
  1190. case ALPS_PROTO_V3:
  1191. priv->hw_init = alps_hw_init_v3;
  1192. priv->process_packet = alps_process_packet_v3;
  1193. priv->set_abs_params = alps_set_abs_params_mt;
  1194. priv->nibble_commands = alps_v3_nibble_commands;
  1195. priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
  1196. break;
  1197. case ALPS_PROTO_V4:
  1198. priv->hw_init = alps_hw_init_v4;
  1199. priv->process_packet = alps_process_packet_v4;
  1200. priv->set_abs_params = alps_set_abs_params_mt;
  1201. priv->nibble_commands = alps_v4_nibble_commands;
  1202. priv->addr_command = PSMOUSE_CMD_DISABLE;
  1203. break;
  1204. }
  1205. }
  1206. static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv,
  1207. unsigned char *e7, unsigned char *ec)
  1208. {
  1209. const struct alps_model_info *model;
  1210. int i;
  1211. for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
  1212. model = &alps_model_data[i];
  1213. if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
  1214. (!model->command_mode_resp ||
  1215. model->command_mode_resp == ec[2])) {
  1216. priv->proto_version = model->proto_version;
  1217. alps_set_defaults(priv);
  1218. priv->flags = model->flags;
  1219. priv->byte0 = model->byte0;
  1220. priv->mask0 = model->mask0;
  1221. return 0;
  1222. }
  1223. }
  1224. return -EINVAL;
  1225. }
  1226. static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
  1227. {
  1228. unsigned char e6[4], e7[4], ec[4];
  1229. /*
  1230. * First try "E6 report".
  1231. * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
  1232. * The bits 0-2 of the first byte will be 1s if some buttons are
  1233. * pressed.
  1234. */
  1235. if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
  1236. PSMOUSE_CMD_SETSCALE11, e6))
  1237. return -EIO;
  1238. if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
  1239. return -EINVAL;
  1240. /*
  1241. * Now get the "E7" and "EC" reports. These will uniquely identify
  1242. * most ALPS touchpads.
  1243. */
  1244. if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
  1245. PSMOUSE_CMD_SETSCALE21, e7) ||
  1246. alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
  1247. PSMOUSE_CMD_RESET_WRAP, ec) ||
  1248. alps_exit_command_mode(psmouse))
  1249. return -EIO;
  1250. if (alps_match_table(psmouse, priv, e7, ec) == 0) {
  1251. return 0;
  1252. } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
  1253. ec[2] >= 0x90 && ec[2] <= 0x9d) {
  1254. priv->proto_version = ALPS_PROTO_V3;
  1255. alps_set_defaults(priv);
  1256. return 0;
  1257. }
  1258. psmouse_info(psmouse,
  1259. "Unknown ALPS touchpad: E7=%2.2x %2.2x %2.2x, EC=%2.2x %2.2x %2.2x\n",
  1260. e7[0], e7[1], e7[2], ec[0], ec[1], ec[2]);
  1261. return -EINVAL;
  1262. }
  1263. static int alps_reconnect(struct psmouse *psmouse)
  1264. {
  1265. struct alps_data *priv = psmouse->private;
  1266. psmouse_reset(psmouse);
  1267. if (alps_identify(psmouse, priv) < 0)
  1268. return -1;
  1269. return priv->hw_init(psmouse);
  1270. }
  1271. static void alps_disconnect(struct psmouse *psmouse)
  1272. {
  1273. struct alps_data *priv = psmouse->private;
  1274. psmouse_reset(psmouse);
  1275. del_timer_sync(&priv->timer);
  1276. input_unregister_device(priv->dev2);
  1277. kfree(priv);
  1278. }
  1279. static void alps_set_abs_params_st(struct alps_data *priv,
  1280. struct input_dev *dev1)
  1281. {
  1282. input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
  1283. input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
  1284. }
  1285. static void alps_set_abs_params_mt(struct alps_data *priv,
  1286. struct input_dev *dev1)
  1287. {
  1288. set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
  1289. input_mt_init_slots(dev1, 2, 0);
  1290. input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
  1291. input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
  1292. set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
  1293. set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
  1294. set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
  1295. input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
  1296. input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
  1297. }
  1298. int alps_init(struct psmouse *psmouse)
  1299. {
  1300. struct alps_data *priv;
  1301. struct input_dev *dev1 = psmouse->dev, *dev2;
  1302. priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
  1303. dev2 = input_allocate_device();
  1304. if (!priv || !dev2)
  1305. goto init_fail;
  1306. priv->dev2 = dev2;
  1307. setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
  1308. psmouse->private = priv;
  1309. psmouse_reset(psmouse);
  1310. if (alps_identify(psmouse, priv) < 0)
  1311. goto init_fail;
  1312. if (priv->hw_init(psmouse))
  1313. goto init_fail;
  1314. /*
  1315. * Undo part of setup done for us by psmouse core since touchpad
  1316. * is not a relative device.
  1317. */
  1318. __clear_bit(EV_REL, dev1->evbit);
  1319. __clear_bit(REL_X, dev1->relbit);
  1320. __clear_bit(REL_Y, dev1->relbit);
  1321. /*
  1322. * Now set up our capabilities.
  1323. */
  1324. dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
  1325. dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
  1326. dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
  1327. dev1->keybit[BIT_WORD(BTN_LEFT)] |=
  1328. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
  1329. dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
  1330. priv->set_abs_params(priv, dev1);
  1331. input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
  1332. if (priv->flags & ALPS_WHEEL) {
  1333. dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
  1334. dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
  1335. }
  1336. if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
  1337. dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
  1338. dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
  1339. }
  1340. if (priv->flags & ALPS_FOUR_BUTTONS) {
  1341. dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
  1342. dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
  1343. dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
  1344. dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
  1345. } else {
  1346. dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
  1347. }
  1348. snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
  1349. dev2->phys = priv->phys;
  1350. dev2->name = (priv->flags & ALPS_DUALPOINT) ?
  1351. "DualPoint Stick" : "PS/2 Mouse";
  1352. dev2->id.bustype = BUS_I8042;
  1353. dev2->id.vendor = 0x0002;
  1354. dev2->id.product = PSMOUSE_ALPS;
  1355. dev2->id.version = 0x0000;
  1356. dev2->dev.parent = &psmouse->ps2dev.serio->dev;
  1357. dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  1358. dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  1359. dev2->keybit[BIT_WORD(BTN_LEFT)] =
  1360. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  1361. if (input_register_device(priv->dev2))
  1362. goto init_fail;
  1363. psmouse->protocol_handler = alps_process_byte;
  1364. psmouse->poll = alps_poll;
  1365. psmouse->disconnect = alps_disconnect;
  1366. psmouse->reconnect = alps_reconnect;
  1367. psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
  1368. /* We are having trouble resyncing ALPS touchpads so disable it for now */
  1369. psmouse->resync_time = 0;
  1370. return 0;
  1371. init_fail:
  1372. psmouse_reset(psmouse);
  1373. input_free_device(dev2);
  1374. kfree(priv);
  1375. psmouse->private = NULL;
  1376. return -1;
  1377. }
  1378. int alps_detect(struct psmouse *psmouse, bool set_properties)
  1379. {
  1380. struct alps_data dummy;
  1381. if (alps_identify(psmouse, &dummy) < 0)
  1382. return -1;
  1383. if (set_properties) {
  1384. psmouse->vendor = "ALPS";
  1385. psmouse->name = dummy.flags & ALPS_DUALPOINT ?
  1386. "DualPoint TouchPad" : "GlidePoint";
  1387. psmouse->model = dummy.proto_version << 8;
  1388. }
  1389. return 0;
  1390. }