alps.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
  482. input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
  483. input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
  484. input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
  485. input_report_key(dev, BTN_LEFT, left);
  486. input_report_key(dev, BTN_RIGHT, right);
  487. input_report_key(dev, BTN_MIDDLE, middle);
  488. if (z > 0) {
  489. input_report_abs(dev, ABS_X, x);
  490. input_report_abs(dev, ABS_Y, y);
  491. }
  492. input_report_abs(dev, ABS_PRESSURE, z);
  493. input_sync(dev);
  494. if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
  495. left = packet[3] & 0x10;
  496. right = packet[3] & 0x20;
  497. middle = packet[3] & 0x40;
  498. input_report_key(dev2, BTN_LEFT, left);
  499. input_report_key(dev2, BTN_RIGHT, right);
  500. input_report_key(dev2, BTN_MIDDLE, middle);
  501. input_sync(dev2);
  502. }
  503. }
  504. static void alps_process_packet_v3(struct psmouse *psmouse)
  505. {
  506. unsigned char *packet = psmouse->packet;
  507. /*
  508. * v3 protocol packets come in three types, two representing
  509. * touchpad data and one representing trackstick data.
  510. * Trackstick packets seem to be distinguished by always
  511. * having 0x3f in the last byte. This value has never been
  512. * observed in the last byte of either of the other types
  513. * of packets.
  514. */
  515. if (packet[5] == 0x3f) {
  516. alps_process_trackstick_packet_v3(psmouse);
  517. return;
  518. }
  519. alps_process_touchpad_packet_v3(psmouse);
  520. }
  521. static void alps_process_packet_v4(struct psmouse *psmouse)
  522. {
  523. unsigned char *packet = psmouse->packet;
  524. struct input_dev *dev = psmouse->dev;
  525. int x, y, z;
  526. int left, right;
  527. left = packet[4] & 0x01;
  528. right = packet[4] & 0x02;
  529. x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
  530. ((packet[0] & 0x30) >> 4);
  531. y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
  532. z = packet[5] & 0x7f;
  533. if (z >= 64)
  534. input_report_key(dev, BTN_TOUCH, 1);
  535. else
  536. input_report_key(dev, BTN_TOUCH, 0);
  537. if (z > 0) {
  538. input_report_abs(dev, ABS_X, x);
  539. input_report_abs(dev, ABS_Y, y);
  540. }
  541. input_report_abs(dev, ABS_PRESSURE, z);
  542. input_report_key(dev, BTN_TOOL_FINGER, z > 0);
  543. input_report_key(dev, BTN_LEFT, left);
  544. input_report_key(dev, BTN_RIGHT, right);
  545. input_sync(dev);
  546. }
  547. static void alps_process_packet(struct psmouse *psmouse)
  548. {
  549. struct alps_data *priv = psmouse->private;
  550. const struct alps_model_info *model = priv->i;
  551. switch (model->proto_version) {
  552. case ALPS_PROTO_V1:
  553. case ALPS_PROTO_V2:
  554. alps_process_packet_v1_v2(psmouse);
  555. break;
  556. case ALPS_PROTO_V3:
  557. alps_process_packet_v3(psmouse);
  558. break;
  559. case ALPS_PROTO_V4:
  560. alps_process_packet_v4(psmouse);
  561. break;
  562. }
  563. }
  564. static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
  565. unsigned char packet[],
  566. bool report_buttons)
  567. {
  568. struct alps_data *priv = psmouse->private;
  569. struct input_dev *dev2 = priv->dev2;
  570. if (report_buttons)
  571. alps_report_buttons(psmouse, dev2, psmouse->dev,
  572. packet[0] & 1, packet[0] & 2, packet[0] & 4);
  573. input_report_rel(dev2, REL_X,
  574. packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
  575. input_report_rel(dev2, REL_Y,
  576. packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
  577. input_sync(dev2);
  578. }
  579. static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
  580. {
  581. struct alps_data *priv = psmouse->private;
  582. if (psmouse->pktcnt < 6)
  583. return PSMOUSE_GOOD_DATA;
  584. if (psmouse->pktcnt == 6) {
  585. /*
  586. * Start a timer to flush the packet if it ends up last
  587. * 6-byte packet in the stream. Timer needs to fire
  588. * psmouse core times out itself. 20 ms should be enough
  589. * to decide if we are getting more data or not.
  590. */
  591. mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
  592. return PSMOUSE_GOOD_DATA;
  593. }
  594. del_timer(&priv->timer);
  595. if (psmouse->packet[6] & 0x80) {
  596. /*
  597. * Highest bit is set - that means we either had
  598. * complete ALPS packet and this is start of the
  599. * next packet or we got garbage.
  600. */
  601. if (((psmouse->packet[3] |
  602. psmouse->packet[4] |
  603. psmouse->packet[5]) & 0x80) ||
  604. (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
  605. psmouse_dbg(psmouse,
  606. "refusing packet %x %x %x %x (suspected interleaved ps/2)\n",
  607. psmouse->packet[3], psmouse->packet[4],
  608. psmouse->packet[5], psmouse->packet[6]);
  609. return PSMOUSE_BAD_DATA;
  610. }
  611. alps_process_packet(psmouse);
  612. /* Continue with the next packet */
  613. psmouse->packet[0] = psmouse->packet[6];
  614. psmouse->pktcnt = 1;
  615. } else {
  616. /*
  617. * High bit is 0 - that means that we indeed got a PS/2
  618. * packet in the middle of ALPS packet.
  619. *
  620. * There is also possibility that we got 6-byte ALPS
  621. * packet followed by 3-byte packet from trackpoint. We
  622. * can not distinguish between these 2 scenarios but
  623. * because the latter is unlikely to happen in course of
  624. * normal operation (user would need to press all
  625. * buttons on the pad and start moving trackpoint
  626. * without touching the pad surface) we assume former.
  627. * Even if we are wrong the wost thing that would happen
  628. * the cursor would jump but we should not get protocol
  629. * de-synchronization.
  630. */
  631. alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
  632. false);
  633. /*
  634. * Continue with the standard ALPS protocol handling,
  635. * but make sure we won't process it as an interleaved
  636. * packet again, which may happen if all buttons are
  637. * pressed. To avoid this let's reset the 4th bit which
  638. * is normally 1.
  639. */
  640. psmouse->packet[3] = psmouse->packet[6] & 0xf7;
  641. psmouse->pktcnt = 4;
  642. }
  643. return PSMOUSE_GOOD_DATA;
  644. }
  645. static void alps_flush_packet(unsigned long data)
  646. {
  647. struct psmouse *psmouse = (struct psmouse *)data;
  648. serio_pause_rx(psmouse->ps2dev.serio);
  649. if (psmouse->pktcnt == psmouse->pktsize) {
  650. /*
  651. * We did not any more data in reasonable amount of time.
  652. * Validate the last 3 bytes and process as a standard
  653. * ALPS packet.
  654. */
  655. if ((psmouse->packet[3] |
  656. psmouse->packet[4] |
  657. psmouse->packet[5]) & 0x80) {
  658. psmouse_dbg(psmouse,
  659. "refusing packet %x %x %x (suspected interleaved ps/2)\n",
  660. psmouse->packet[3], psmouse->packet[4],
  661. psmouse->packet[5]);
  662. } else {
  663. alps_process_packet(psmouse);
  664. }
  665. psmouse->pktcnt = 0;
  666. }
  667. serio_continue_rx(psmouse->ps2dev.serio);
  668. }
  669. static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
  670. {
  671. struct alps_data *priv = psmouse->private;
  672. const struct alps_model_info *model = priv->i;
  673. /*
  674. * Check if we are dealing with a bare PS/2 packet, presumably from
  675. * a device connected to the external PS/2 port. Because bare PS/2
  676. * protocol does not have enough constant bits to self-synchronize
  677. * properly we only do this if the device is fully synchronized.
  678. */
  679. if (!psmouse->out_of_sync_cnt && (psmouse->packet[0] & 0xc8) == 0x08) {
  680. if (psmouse->pktcnt == 3) {
  681. alps_report_bare_ps2_packet(psmouse, psmouse->packet,
  682. true);
  683. return PSMOUSE_FULL_PACKET;
  684. }
  685. return PSMOUSE_GOOD_DATA;
  686. }
  687. /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
  688. if ((model->flags & ALPS_PS2_INTERLEAVED) &&
  689. psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
  690. return alps_handle_interleaved_ps2(psmouse);
  691. }
  692. if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
  693. psmouse_dbg(psmouse,
  694. "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
  695. psmouse->packet[0], model->mask0, model->byte0);
  696. return PSMOUSE_BAD_DATA;
  697. }
  698. /* Bytes 2 - pktsize should have 0 in the highest bit */
  699. if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
  700. (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
  701. psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
  702. psmouse->pktcnt - 1,
  703. psmouse->packet[psmouse->pktcnt - 1]);
  704. return PSMOUSE_BAD_DATA;
  705. }
  706. if (psmouse->pktcnt == psmouse->pktsize) {
  707. alps_process_packet(psmouse);
  708. return PSMOUSE_FULL_PACKET;
  709. }
  710. return PSMOUSE_GOOD_DATA;
  711. }
  712. static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
  713. {
  714. struct ps2dev *ps2dev = &psmouse->ps2dev;
  715. struct alps_data *priv = psmouse->private;
  716. int command;
  717. unsigned char *param;
  718. unsigned char dummy[4];
  719. BUG_ON(nibble > 0xf);
  720. command = priv->nibble_commands[nibble].command;
  721. param = (command & 0x0f00) ?
  722. dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
  723. if (ps2_command(ps2dev, param, command))
  724. return -1;
  725. return 0;
  726. }
  727. static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
  728. {
  729. struct ps2dev *ps2dev = &psmouse->ps2dev;
  730. struct alps_data *priv = psmouse->private;
  731. int i, nibble;
  732. if (ps2_command(ps2dev, NULL, priv->addr_command))
  733. return -1;
  734. for (i = 12; i >= 0; i -= 4) {
  735. nibble = (addr >> i) & 0xf;
  736. if (alps_command_mode_send_nibble(psmouse, nibble))
  737. return -1;
  738. }
  739. return 0;
  740. }
  741. static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
  742. {
  743. struct ps2dev *ps2dev = &psmouse->ps2dev;
  744. unsigned char param[4];
  745. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  746. return -1;
  747. /*
  748. * The address being read is returned in the first two bytes
  749. * of the result. Check that this address matches the expected
  750. * address.
  751. */
  752. if (addr != ((param[0] << 8) | param[1]))
  753. return -1;
  754. return param[2];
  755. }
  756. static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
  757. {
  758. if (alps_command_mode_set_addr(psmouse, addr))
  759. return -1;
  760. return __alps_command_mode_read_reg(psmouse, addr);
  761. }
  762. static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
  763. {
  764. if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
  765. return -1;
  766. if (alps_command_mode_send_nibble(psmouse, value & 0xf))
  767. return -1;
  768. return 0;
  769. }
  770. static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
  771. u8 value)
  772. {
  773. if (alps_command_mode_set_addr(psmouse, addr))
  774. return -1;
  775. return __alps_command_mode_write_reg(psmouse, value);
  776. }
  777. static int alps_enter_command_mode(struct psmouse *psmouse,
  778. unsigned char *resp)
  779. {
  780. unsigned char param[4];
  781. struct ps2dev *ps2dev = &psmouse->ps2dev;
  782. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
  783. ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
  784. ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
  785. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  786. psmouse_err(psmouse, "failed to enter command mode\n");
  787. return -1;
  788. }
  789. if (param[0] != 0x88 && param[1] != 0x07) {
  790. psmouse_dbg(psmouse,
  791. "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
  792. param[0], param[1], param[2]);
  793. return -1;
  794. }
  795. if (resp)
  796. *resp = param[2];
  797. return 0;
  798. }
  799. static inline int alps_exit_command_mode(struct psmouse *psmouse)
  800. {
  801. struct ps2dev *ps2dev = &psmouse->ps2dev;
  802. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
  803. return -1;
  804. return 0;
  805. }
  806. static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
  807. {
  808. struct ps2dev *ps2dev = &psmouse->ps2dev;
  809. static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
  810. unsigned char param[4];
  811. const struct alps_model_info *model = NULL;
  812. int i;
  813. /*
  814. * First try "E6 report".
  815. * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
  816. * The bits 0-2 of the first byte will be 1s if some buttons are
  817. * pressed.
  818. */
  819. param[0] = 0;
  820. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
  821. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  822. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  823. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
  824. return NULL;
  825. param[0] = param[1] = param[2] = 0xff;
  826. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  827. return NULL;
  828. psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x",
  829. param[0], param[1], param[2]);
  830. if ((param[0] & 0xf8) != 0 || param[1] != 0 ||
  831. (param[2] != 10 && param[2] != 100))
  832. return NULL;
  833. /*
  834. * Now try "E7 report". Allowed responses are in
  835. * alps_model_data[].signature
  836. */
  837. param[0] = 0;
  838. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
  839. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  840. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  841. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
  842. return NULL;
  843. param[0] = param[1] = param[2] = 0xff;
  844. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  845. return NULL;
  846. psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x",
  847. param[0], param[1], param[2]);
  848. if (version) {
  849. for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
  850. /* empty */;
  851. *version = (param[0] << 8) | (param[1] << 4) | i;
  852. }
  853. for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
  854. if (!memcmp(param, alps_model_data[i].signature,
  855. sizeof(alps_model_data[i].signature))) {
  856. model = alps_model_data + i;
  857. break;
  858. }
  859. }
  860. if (model && model->proto_version > ALPS_PROTO_V2) {
  861. /*
  862. * Need to check command mode response to identify
  863. * model
  864. */
  865. model = NULL;
  866. if (alps_enter_command_mode(psmouse, param)) {
  867. psmouse_warn(psmouse,
  868. "touchpad failed to enter command mode\n");
  869. } else {
  870. for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
  871. if (alps_model_data[i].proto_version > ALPS_PROTO_V2 &&
  872. alps_model_data[i].command_mode_resp == param[0]) {
  873. model = alps_model_data + i;
  874. break;
  875. }
  876. }
  877. alps_exit_command_mode(psmouse);
  878. if (!model)
  879. psmouse_dbg(psmouse,
  880. "Unknown command mode response %2.2x\n",
  881. param[0]);
  882. }
  883. }
  884. return model;
  885. }
  886. /*
  887. * For DualPoint devices select the device that should respond to
  888. * subsequent commands. It looks like glidepad is behind stickpointer,
  889. * I'd thought it would be other way around...
  890. */
  891. static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
  892. {
  893. struct ps2dev *ps2dev = &psmouse->ps2dev;
  894. int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
  895. if (ps2_command(ps2dev, NULL, cmd) ||
  896. ps2_command(ps2dev, NULL, cmd) ||
  897. ps2_command(ps2dev, NULL, cmd) ||
  898. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
  899. return -1;
  900. /* we may get 3 more bytes, just ignore them */
  901. ps2_drain(ps2dev, 3, 100);
  902. return 0;
  903. }
  904. static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
  905. {
  906. struct ps2dev *ps2dev = &psmouse->ps2dev;
  907. /* Try ALPS magic knock - 4 disable before enable */
  908. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  909. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  910. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  911. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  912. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
  913. return -1;
  914. /*
  915. * Switch mouse to poll (remote) mode so motion data will not
  916. * get in our way
  917. */
  918. return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
  919. }
  920. static int alps_get_status(struct psmouse *psmouse, char *param)
  921. {
  922. struct ps2dev *ps2dev = &psmouse->ps2dev;
  923. /* Get status: 0xF5 0xF5 0xF5 0xE9 */
  924. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  925. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  926. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  927. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
  928. return -1;
  929. psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x",
  930. param[0], param[1], param[2]);
  931. return 0;
  932. }
  933. /*
  934. * Turn touchpad tapping on or off. The sequences are:
  935. * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
  936. * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
  937. * My guess that 0xE9 (GetInfo) is here as a sync point.
  938. * For models that also have stickpointer (DualPoints) its tapping
  939. * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
  940. * we don't fiddle with it.
  941. */
  942. static int alps_tap_mode(struct psmouse *psmouse, int enable)
  943. {
  944. struct ps2dev *ps2dev = &psmouse->ps2dev;
  945. int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
  946. unsigned char tap_arg = enable ? 0x0A : 0x00;
  947. unsigned char param[4];
  948. if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
  949. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  950. ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
  951. ps2_command(ps2dev, &tap_arg, cmd))
  952. return -1;
  953. if (alps_get_status(psmouse, param))
  954. return -1;
  955. return 0;
  956. }
  957. /*
  958. * alps_poll() - poll the touchpad for current motion packet.
  959. * Used in resync.
  960. */
  961. static int alps_poll(struct psmouse *psmouse)
  962. {
  963. struct alps_data *priv = psmouse->private;
  964. unsigned char buf[sizeof(psmouse->packet)];
  965. bool poll_failed;
  966. if (priv->i->flags & ALPS_PASS)
  967. alps_passthrough_mode_v2(psmouse, true);
  968. poll_failed = ps2_command(&psmouse->ps2dev, buf,
  969. PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
  970. if (priv->i->flags & ALPS_PASS)
  971. alps_passthrough_mode_v2(psmouse, false);
  972. if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
  973. return -1;
  974. if ((psmouse->badbyte & 0xc8) == 0x08) {
  975. /*
  976. * Poll the track stick ...
  977. */
  978. if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
  979. return -1;
  980. }
  981. memcpy(psmouse->packet, buf, sizeof(buf));
  982. return 0;
  983. }
  984. static int alps_hw_init_v1_v2(struct psmouse *psmouse)
  985. {
  986. struct alps_data *priv = psmouse->private;
  987. const struct alps_model_info *model = priv->i;
  988. if ((model->flags & ALPS_PASS) &&
  989. alps_passthrough_mode_v2(psmouse, true)) {
  990. return -1;
  991. }
  992. if (alps_tap_mode(psmouse, true)) {
  993. psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
  994. return -1;
  995. }
  996. if (alps_absolute_mode_v1_v2(psmouse)) {
  997. psmouse_err(psmouse, "Failed to enable absolute mode\n");
  998. return -1;
  999. }
  1000. if ((model->flags & ALPS_PASS) &&
  1001. alps_passthrough_mode_v2(psmouse, false)) {
  1002. return -1;
  1003. }
  1004. /* ALPS needs stream mode, otherwise it won't report any data */
  1005. if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
  1006. psmouse_err(psmouse, "Failed to enable stream mode\n");
  1007. return -1;
  1008. }
  1009. return 0;
  1010. }
  1011. /*
  1012. * Enable or disable passthrough mode to the trackstick. Must be in
  1013. * command mode when calling this function.
  1014. */
  1015. static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
  1016. {
  1017. int reg_val;
  1018. reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
  1019. if (reg_val == -1)
  1020. return -1;
  1021. if (enable)
  1022. reg_val |= 0x01;
  1023. else
  1024. reg_val &= ~0x01;
  1025. if (__alps_command_mode_write_reg(psmouse, reg_val))
  1026. return -1;
  1027. return 0;
  1028. }
  1029. /* Must be in command mode when calling this function */
  1030. static int alps_absolute_mode_v3(struct psmouse *psmouse)
  1031. {
  1032. int reg_val;
  1033. reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
  1034. if (reg_val == -1)
  1035. return -1;
  1036. reg_val |= 0x06;
  1037. if (__alps_command_mode_write_reg(psmouse, reg_val))
  1038. return -1;
  1039. return 0;
  1040. }
  1041. static int alps_hw_init_v3(struct psmouse *psmouse)
  1042. {
  1043. struct alps_data *priv = psmouse->private;
  1044. struct ps2dev *ps2dev = &psmouse->ps2dev;
  1045. int reg_val;
  1046. unsigned char param[4];
  1047. priv->nibble_commands = alps_v3_nibble_commands;
  1048. priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
  1049. if (alps_enter_command_mode(psmouse, NULL))
  1050. goto error;
  1051. /* Check for trackstick */
  1052. reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
  1053. if (reg_val == -1)
  1054. goto error;
  1055. if (reg_val & 0x80) {
  1056. if (alps_passthrough_mode_v3(psmouse, true))
  1057. goto error;
  1058. if (alps_exit_command_mode(psmouse))
  1059. goto error;
  1060. /*
  1061. * E7 report for the trackstick
  1062. *
  1063. * There have been reports of failures to seem to trace back
  1064. * to the above trackstick check failing. When these occur
  1065. * this E7 report fails, so when that happens we continue
  1066. * with the assumption that there isn't a trackstick after
  1067. * all.
  1068. */
  1069. param[0] = 0x64;
  1070. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1071. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1072. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
  1073. ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
  1074. psmouse_warn(psmouse, "trackstick E7 report failed\n");
  1075. } else {
  1076. psmouse_dbg(psmouse,
  1077. "trackstick E7 report: %2.2x %2.2x %2.2x\n",
  1078. param[0], param[1], param[2]);
  1079. /*
  1080. * Not sure what this does, but it is absolutely
  1081. * essential. Without it, the touchpad does not
  1082. * work at all and the trackstick just emits normal
  1083. * PS/2 packets.
  1084. */
  1085. if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1086. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1087. ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
  1088. alps_command_mode_send_nibble(psmouse, 0x9) ||
  1089. alps_command_mode_send_nibble(psmouse, 0x4)) {
  1090. psmouse_err(psmouse,
  1091. "Error sending magic E6 sequence\n");
  1092. goto error_passthrough;
  1093. }
  1094. }
  1095. if (alps_enter_command_mode(psmouse, NULL))
  1096. goto error_passthrough;
  1097. if (alps_passthrough_mode_v3(psmouse, false))
  1098. goto error;
  1099. }
  1100. if (alps_absolute_mode_v3(psmouse)) {
  1101. psmouse_err(psmouse, "Failed to enter absolute mode\n");
  1102. goto error;
  1103. }
  1104. reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
  1105. if (reg_val == -1)
  1106. goto error;
  1107. if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
  1108. goto error;
  1109. reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
  1110. if (reg_val == -1)
  1111. goto error;
  1112. if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
  1113. goto error;
  1114. if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
  1115. goto error;
  1116. if (__alps_command_mode_write_reg(psmouse, 0x04))
  1117. goto error;
  1118. if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
  1119. goto error;
  1120. if (__alps_command_mode_write_reg(psmouse, 0x03))
  1121. goto error;
  1122. if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
  1123. goto error;
  1124. if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
  1125. goto error;
  1126. if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
  1127. goto error;
  1128. if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
  1129. goto error;
  1130. /*
  1131. * This ensures the trackstick packets are in the format
  1132. * supported by this driver. If bit 1 isn't set the packet
  1133. * format is different.
  1134. */
  1135. if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
  1136. goto error;
  1137. alps_exit_command_mode(psmouse);
  1138. /* Set rate and enable data reporting */
  1139. param[0] = 0x64;
  1140. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
  1141. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1142. psmouse_err(psmouse, "Failed to enable data reporting\n");
  1143. return -1;
  1144. }
  1145. return 0;
  1146. error_passthrough:
  1147. /* Something failed while in passthrough mode, so try to get out */
  1148. if (!alps_enter_command_mode(psmouse, NULL))
  1149. alps_passthrough_mode_v3(psmouse, false);
  1150. error:
  1151. /*
  1152. * Leaving the touchpad in command mode will essentially render
  1153. * it unusable until the machine reboots, so exit it here just
  1154. * to be safe
  1155. */
  1156. alps_exit_command_mode(psmouse);
  1157. return -1;
  1158. }
  1159. /* Must be in command mode when calling this function */
  1160. static int alps_absolute_mode_v4(struct psmouse *psmouse)
  1161. {
  1162. int reg_val;
  1163. reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
  1164. if (reg_val == -1)
  1165. return -1;
  1166. reg_val |= 0x02;
  1167. if (__alps_command_mode_write_reg(psmouse, reg_val))
  1168. return -1;
  1169. return 0;
  1170. }
  1171. static int alps_hw_init_v4(struct psmouse *psmouse)
  1172. {
  1173. struct alps_data *priv = psmouse->private;
  1174. struct ps2dev *ps2dev = &psmouse->ps2dev;
  1175. unsigned char param[4];
  1176. priv->nibble_commands = alps_v4_nibble_commands;
  1177. priv->addr_command = PSMOUSE_CMD_DISABLE;
  1178. if (alps_enter_command_mode(psmouse, NULL))
  1179. goto error;
  1180. if (alps_absolute_mode_v4(psmouse)) {
  1181. psmouse_err(psmouse, "Failed to enter absolute mode\n");
  1182. goto error;
  1183. }
  1184. if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
  1185. goto error;
  1186. if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
  1187. goto error;
  1188. if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
  1189. goto error;
  1190. if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
  1191. goto error;
  1192. if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
  1193. goto error;
  1194. if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
  1195. goto error;
  1196. if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
  1197. goto error;
  1198. if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
  1199. goto error;
  1200. alps_exit_command_mode(psmouse);
  1201. /*
  1202. * This sequence changes the output from a 9-byte to an
  1203. * 8-byte format. All the same data seems to be present,
  1204. * just in a more compact format.
  1205. */
  1206. param[0] = 0xc8;
  1207. param[1] = 0x64;
  1208. param[2] = 0x50;
  1209. if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
  1210. ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
  1211. ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
  1212. ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
  1213. return -1;
  1214. /* Set rate and enable data reporting */
  1215. param[0] = 0x64;
  1216. if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
  1217. ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
  1218. psmouse_err(psmouse, "Failed to enable data reporting\n");
  1219. return -1;
  1220. }
  1221. return 0;
  1222. error:
  1223. /*
  1224. * Leaving the touchpad in command mode will essentially render
  1225. * it unusable until the machine reboots, so exit it here just
  1226. * to be safe
  1227. */
  1228. alps_exit_command_mode(psmouse);
  1229. return -1;
  1230. }
  1231. static int alps_hw_init(struct psmouse *psmouse)
  1232. {
  1233. struct alps_data *priv = psmouse->private;
  1234. const struct alps_model_info *model = priv->i;
  1235. int ret = -1;
  1236. switch (model->proto_version) {
  1237. case ALPS_PROTO_V1:
  1238. case ALPS_PROTO_V2:
  1239. ret = alps_hw_init_v1_v2(psmouse);
  1240. break;
  1241. case ALPS_PROTO_V3:
  1242. ret = alps_hw_init_v3(psmouse);
  1243. break;
  1244. case ALPS_PROTO_V4:
  1245. ret = alps_hw_init_v4(psmouse);
  1246. break;
  1247. }
  1248. return ret;
  1249. }
  1250. static int alps_reconnect(struct psmouse *psmouse)
  1251. {
  1252. const struct alps_model_info *model;
  1253. psmouse_reset(psmouse);
  1254. model = alps_get_model(psmouse, NULL);
  1255. if (!model)
  1256. return -1;
  1257. return alps_hw_init(psmouse);
  1258. }
  1259. static void alps_disconnect(struct psmouse *psmouse)
  1260. {
  1261. struct alps_data *priv = psmouse->private;
  1262. psmouse_reset(psmouse);
  1263. del_timer_sync(&priv->timer);
  1264. input_unregister_device(priv->dev2);
  1265. kfree(priv);
  1266. }
  1267. int alps_init(struct psmouse *psmouse)
  1268. {
  1269. struct alps_data *priv;
  1270. const struct alps_model_info *model;
  1271. struct input_dev *dev1 = psmouse->dev, *dev2;
  1272. int version;
  1273. priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
  1274. dev2 = input_allocate_device();
  1275. if (!priv || !dev2)
  1276. goto init_fail;
  1277. priv->dev2 = dev2;
  1278. setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
  1279. psmouse->private = priv;
  1280. psmouse_reset(psmouse);
  1281. model = alps_get_model(psmouse, &version);
  1282. if (!model)
  1283. goto init_fail;
  1284. priv->i = model;
  1285. if (alps_hw_init(psmouse))
  1286. goto init_fail;
  1287. /*
  1288. * Undo part of setup done for us by psmouse core since touchpad
  1289. * is not a relative device.
  1290. */
  1291. __clear_bit(EV_REL, dev1->evbit);
  1292. __clear_bit(REL_X, dev1->relbit);
  1293. __clear_bit(REL_Y, dev1->relbit);
  1294. /*
  1295. * Now set up our capabilities.
  1296. */
  1297. dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
  1298. dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
  1299. dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
  1300. dev1->keybit[BIT_WORD(BTN_LEFT)] |=
  1301. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
  1302. dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
  1303. switch (model->proto_version) {
  1304. case ALPS_PROTO_V1:
  1305. case ALPS_PROTO_V2:
  1306. input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
  1307. input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
  1308. break;
  1309. case ALPS_PROTO_V3:
  1310. set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
  1311. input_mt_init_slots(dev1, 2);
  1312. input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
  1313. input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
  1314. set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
  1315. set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
  1316. set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
  1317. /* fall through */
  1318. case ALPS_PROTO_V4:
  1319. input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
  1320. input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
  1321. break;
  1322. }
  1323. input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
  1324. if (model->flags & ALPS_WHEEL) {
  1325. dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
  1326. dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
  1327. }
  1328. if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
  1329. dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
  1330. dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
  1331. }
  1332. if (model->flags & ALPS_FOUR_BUTTONS) {
  1333. dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
  1334. dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
  1335. dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
  1336. dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
  1337. } else {
  1338. dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
  1339. }
  1340. snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
  1341. dev2->phys = priv->phys;
  1342. dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
  1343. dev2->id.bustype = BUS_I8042;
  1344. dev2->id.vendor = 0x0002;
  1345. dev2->id.product = PSMOUSE_ALPS;
  1346. dev2->id.version = 0x0000;
  1347. dev2->dev.parent = &psmouse->ps2dev.serio->dev;
  1348. dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  1349. dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  1350. dev2->keybit[BIT_WORD(BTN_LEFT)] =
  1351. BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  1352. if (input_register_device(priv->dev2))
  1353. goto init_fail;
  1354. psmouse->protocol_handler = alps_process_byte;
  1355. psmouse->poll = alps_poll;
  1356. psmouse->disconnect = alps_disconnect;
  1357. psmouse->reconnect = alps_reconnect;
  1358. psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6;
  1359. /* We are having trouble resyncing ALPS touchpads so disable it for now */
  1360. psmouse->resync_time = 0;
  1361. /* Allow 2 invalid packets without resetting device */
  1362. psmouse->resetafter = psmouse->pktsize * 2;
  1363. return 0;
  1364. init_fail:
  1365. psmouse_reset(psmouse);
  1366. input_free_device(dev2);
  1367. kfree(priv);
  1368. psmouse->private = NULL;
  1369. return -1;
  1370. }
  1371. int alps_detect(struct psmouse *psmouse, bool set_properties)
  1372. {
  1373. int version;
  1374. const struct alps_model_info *model;
  1375. model = alps_get_model(psmouse, &version);
  1376. if (!model)
  1377. return -1;
  1378. if (set_properties) {
  1379. psmouse->vendor = "ALPS";
  1380. psmouse->name = model->flags & ALPS_DUALPOINT ?
  1381. "DualPoint TouchPad" : "GlidePoint";
  1382. psmouse->model = version;
  1383. }
  1384. return 0;
  1385. }