alps.c 46 KB

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