alps.c 46 KB

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