alps.c 48 KB

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