alps.c 47 KB

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