From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Riyll-00051U-GP for garchives@archives.gentoo.org; Fri, 06 Jan 2012 01:39:00 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AD46121C020; Fri, 6 Jan 2012 01:38:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 407B521C020 for ; Fri, 6 Jan 2012 01:38:48 +0000 (UTC) Received: from flycatcher.gentoo.org (flycatcher.gentoo.org [81.93.255.6]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6E1A91B40A5 for ; Fri, 6 Jan 2012 01:38:47 +0000 (UTC) Received: by flycatcher.gentoo.org (Postfix, from userid 2195) id 416452004B; Fri, 6 Jan 2012 01:38:45 +0000 (UTC) To: gentoo-commits@lists.gentoo.org From: "Mike Pagano (mpagano)" Subject: [gentoo-commits] linux-patches r2047 - genpatches-2.6/trunk/3.2 X-VCS-Repository: linux-patches X-VCS-Revision: 2047 X-VCS-Files: genpatches-2.6/trunk/3.2/2600_Input-ALPS-synaptics-touchpad.patch genpatches-2.6/trunk/3.2/0000_README X-VCS-Directories: genpatches-2.6/trunk/3.2 X-VCS-Committer: mpagano X-VCS-Committer-Name: Mike Pagano Content-Type: text/plain; charset=UTF-8 Message-Id: <20120106013845.416452004B@flycatcher.gentoo.org> Date: Fri, 6 Jan 2012 01:38:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 7bce951d-1aa4-42f9-a1c5-63457e38179e X-Archives-Hash: f2eb54aaaa067acf18833137ff6048fc Author: mpagano Date: 2012-01-06 01:38:44 +0000 (Fri, 06 Jan 2012) New Revision: 2047 Added: genpatches-2.6/trunk/3.2/2600_Input-ALPS-synaptics-touchpad.patch Modified: genpatches-2.6/trunk/3.2/0000_README Log: Adding ALPS patch. Thanks to iamben. Modified: genpatches-2.6/trunk/3.2/0000_README =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- genpatches-2.6/trunk/3.2/0000_README 2012-01-05 01:15:48 UTC (rev 204= 6) +++ genpatches-2.6/trunk/3.2/0000_README 2012-01-06 01:38:44 UTC (rev 204= 7) @@ -39,6 +39,10 @@ Individual Patch Descriptions: ------------------------------------------------------------------------= -- =20 +Patch: 2600_Input-ALPS-synaptics-touchpad.patch +From: http://bugs.gentoo.org/show_bug.cgi?id=3D318567 +Desc: ALPS Touchpad Patchset + Patch: 4200_fbcondecor-0.9.6.patch From: http://dev.gentoo.org/~spock Desc: Bootsplash successor by Michal Januszewski ported by Alexxy Added: genpatches-2.6/trunk/3.2/2600_Input-ALPS-synaptics-touchpad.patch =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- genpatches-2.6/trunk/3.2/2600_Input-ALPS-synaptics-touchpad.patch = (rev 0) +++ genpatches-2.6/trunk/3.2/2600_Input-ALPS-synaptics-touchpad.patch 201= 2-01-06 01:38:44 UTC (rev 2047) @@ -0,0 +1,1267 @@ +Only in linux-3.2/Documentation/input: alps.txt +diff -ur linux-3.2.old/drivers/input/mouse/alps.c linux-3.2/drivers/inpu= t/mouse/alps.c +--- linux-3.2.old/drivers/input/mouse/alps.c 2012-01-04 17:55:44.0000000= 00 -0600 ++++ linux-3.2/drivers/input/mouse/alps.c 2012-01-05 18:53:42.231275880 -= 0600 +@@ -17,13 +17,63 @@ +=20 + #include + #include ++#include + #include + #include +=20 + #include "psmouse.h" + #include "alps.h" +=20 +-#define ALPS_OLDPROTO 0x01 /* old style input */ ++/* ++ * Definitions for ALPS version 3 and 4 command mode protocol ++ */ ++#define ALPS_V3_X_MAX 2000 ++#define ALPS_V3_Y_MAX 1400 ++ ++#define ALPS_BITMAP_X_BITS 15 ++#define ALPS_BITMAP_Y_BITS 11 ++ ++#define ALPS_CMD_NIBBLE_10 0x01f2 ++ ++static const struct alps_nibble_commands alps_v3_nibble_commands[] =3D = { ++ { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */ ++ { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ ++ { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ ++ { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ ++ { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ ++ { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ ++ { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ ++ { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ ++ { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ ++ { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ ++ { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ ++ { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ ++ { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ ++ { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ ++ { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ ++ { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ ++}; ++ ++static const struct alps_nibble_commands alps_v4_nibble_commands[] =3D = { ++ { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */ ++ { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ ++ { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ ++ { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ ++ { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ ++ { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ ++ { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ ++ { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ ++ { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ ++ { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ ++ { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ ++ { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ ++ { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ ++ { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ ++ { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ ++ { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ ++}; ++ ++ + #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ + #define ALPS_PASS 0x04 /* device has a pass-through port */ +=20 +@@ -35,30 +85,33 @@ + 6-byte ALPS packet */ +=20 + static const struct alps_model_info alps_model_data[] =3D { +- { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* T= oshiba Salellite Pro M10 */ +- { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T *= / +- { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, +- { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, +- { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ +- { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, +- { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, +- { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siem= ens S6010 */ +- { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satell= ite S2400-103 */ +- { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L3= 20 */ +- { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, +- { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* D= ell Latitude D800 */ +- { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R= 61 8918-5QG */ +- { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, +- { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop= */ +- { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* X= XX */ +- { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, +- { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* D= ell Latitude D600 */ ++ { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | A= LPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ ++ { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UM= AX-530T */ ++ { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP= ze1115 */ ++ { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 = }, /* Fujitsu Siemens S6010 */ ++ { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL },= /* Toshiba Satellite S2400-103 */ ++ { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 = }, /* NEC Versa L320 */ ++ { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | A= LPS_DUALPOINT }, /* Dell Latitude D800 */ ++ { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOIN= T }, /* ThinkPad R61 8918-5QG */ ++ { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, ++ { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 = }, /* Ahtec Laptop */ ++ { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | A= LPS_DUALPOINT }, /* XXX */ ++ { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | A= LPS_DUALPOINT }, ++ { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | A= LPS_DUALPOINT }, /* Dell Latitude D600 */ + /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ +- { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, ++ { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, + ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, +- { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vos= tro 1400 */ +- { { 0x52, 0x01, 0x14 }, 0xff, 0xff, +- ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tec= ra A11-11L */ ++ { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUT= TONS }, /* Dell Vostro 1400 */ ++ { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ++ ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Te= cra A11-11L */ ++ { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOIN= T }, ++ { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOIN= T }, ++ { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 }, + }; +=20 + /* +@@ -67,42 +120,7 @@ + * isn't valid per PS/2 spec. + */ +=20 +-/* +- * PS/2 packet format +- * +- * byte 0: 0 0 YSGN XSGN 1 M R L +- * byte 1: X7 X6 X5 X4 X3 X2 X1 X0 +- * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 +- * +- * Note that the device never signals overflow condition. +- * +- * ALPS absolute Mode - new format +- * +- * byte 0: 1 ? ? ? 1 ? ? ? +- * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 +- * byte 2: 0 x10 x9 x8 x7 ? fin ges +- * byte 3: 0 y9 y8 y7 1 M R L +- * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 +- * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 +- * +- * Dualpoint device -- interleaved packet format +- * +- * byte 0: 1 1 0 0 1 1 1 1 +- * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 +- * byte 2: 0 x10 x9 x8 x7 0 fin ges +- * byte 3: 0 0 YSGN XSGN 1 1 1 1 +- * byte 4: X7 X6 X5 X4 X3 X2 X1 X0 +- * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 +- * byte 6: 0 y9 y8 y7 1 m r l +- * byte 7: 0 y6 y5 y4 y3 y2 y1 y0 +- * byte 8: 0 z6 z5 z4 z3 z2 z1 z0 +- * +- * CAPITALS =3D stick, miniscules =3D touchpad +- * +- * ?'s can have different meanings on different models, +- * such as wheel rotation, extra buttons, stick buttons +- * on a dualpoint, etc. +- */ ++/* Packet formats are described in Documentation/input/alps.txt */ +=20 + static bool alps_is_valid_first_byte(const struct alps_model_info *mode= l, + unsigned char data) +@@ -137,7 +155,7 @@ + input_sync(dev2); + } +=20 +-static void alps_process_packet(struct psmouse *psmouse) ++static void alps_process_packet_v1_v2(struct psmouse *psmouse) + { + struct alps_data *priv =3D psmouse->private; + const struct alps_model_info *model =3D priv->i; +@@ -147,7 +165,7 @@ + int x, y, z, ges, fin, left, right, middle; + int back =3D 0, forward =3D 0; +=20 +- if (model->flags & ALPS_OLDPROTO) { ++ if (model->proto_version =3D=3D ALPS_PROTO_V1) { + left =3D packet[2] & 0x10; + right =3D packet[2] & 0x08; + middle =3D 0; +@@ -239,6 +257,403 @@ + input_sync(dev); + } +=20 ++/* ++ * Process bitmap data from v3 and v4 protocols. Returns the number of ++ * fingers detected. A return value of 0 means at least one of the ++ * bitmaps was empty. ++ * ++ * The bitmaps don't have enough data to track fingers, so this functio= n ++ * only generates points representing a bounding box of all contacts. ++ * These points are returned in x1, y1, x2, and y2 when the return valu= e ++ * is greater than 0. ++ */ ++static int alps_process_bitmap(unsigned int x_map, unsigned int y_map, ++ int *x1, int *y1, int *x2, int *y2) ++{ ++ struct alps_bitmap_point { ++ int start_bit; ++ int num_bits; ++ }; ++ ++ int fingers_x =3D 0, fingers_y =3D 0, fingers; ++ int i, bit, prev_bit; ++ struct alps_bitmap_point x_low =3D {0,}, x_high =3D {0,}; ++ struct alps_bitmap_point y_low =3D {0,}, y_high =3D {0,}; ++ struct alps_bitmap_point *point; ++ ++ if (!x_map || !y_map) ++ return 0; ++ ++ *x1 =3D *y1 =3D *x2 =3D *y2 =3D 0; ++ ++ prev_bit =3D 0; ++ point =3D &x_low; ++ for (i =3D 0; x_map !=3D 0; i++, x_map >>=3D 1) { ++ bit =3D x_map & 1; ++ if (bit) { ++ if (!prev_bit) { ++ point->start_bit =3D i; ++ fingers_x++; ++ } ++ point->num_bits++; ++ } else { ++ if (prev_bit) ++ point =3D &x_high; ++ else ++ point->num_bits =3D 0; ++ } ++ prev_bit =3D bit; ++ } ++ ++ /* ++ * y bitmap is reversed for what we need (lower positions are in ++ * higher bits), so we process from the top end. ++ */ ++ y_map =3D y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS= ); ++ prev_bit =3D 0; ++ point =3D &y_low; ++ for (i =3D 0; y_map !=3D 0; i++, y_map <<=3D 1) { ++ bit =3D y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1)); ++ if (bit) { ++ if (!prev_bit) { ++ point->start_bit =3D i; ++ fingers_y++; ++ } ++ point->num_bits++; ++ } else { ++ if (prev_bit) ++ point =3D &y_high; ++ else ++ point->num_bits =3D 0; ++ } ++ prev_bit =3D bit; ++ } ++ ++ /* ++ * Fingers can overlap, so we use the maximum count of fingers ++ * on either axis as the finger count. ++ */ ++ fingers =3D max(fingers_x, fingers_y); ++ ++ /* ++ * If total fingers is > 1 but either axis reports only a single ++ * contact, we have overlapping or adjacent fingers. For the ++ * purposes of creating a bounding box, divide the single contact ++ * (roughly) equally between the two points. ++ */ ++ if (fingers > 1) { ++ if (fingers_x =3D=3D 1) { ++ i =3D x_low.num_bits / 2; ++ x_low.num_bits =3D x_low.num_bits - i; ++ x_high.start_bit =3D x_low.start_bit + i; ++ x_high.num_bits =3D max(i, 1); ++ } else if (fingers_y =3D=3D 1) { ++ i =3D y_low.num_bits / 2; ++ y_low.num_bits =3D y_low.num_bits - i; ++ y_high.start_bit =3D y_low.start_bit + i; ++ y_high.num_bits =3D max(i, 1); ++ } ++ } ++ ++ *x1 =3D (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) / ++ (2 * (ALPS_BITMAP_X_BITS - 1)); ++ *y1 =3D (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) / ++ (2 * (ALPS_BITMAP_Y_BITS - 1)); ++ ++ if (fingers > 1) { ++ *x2 =3D (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)= ) / ++ (2 * (ALPS_BITMAP_X_BITS - 1)); ++ *y2 =3D (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)= ) / ++ (2 * (ALPS_BITMAP_Y_BITS - 1)); ++ } ++ ++ return fingers; ++} ++ ++static void alps_set_slot(struct input_dev *dev, int slot, bool active, ++ int x, int y) ++{ ++ input_mt_slot(dev, slot); ++ input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); ++ if (active) { ++ input_report_abs(dev, ABS_MT_POSITION_X, x); ++ input_report_abs(dev, ABS_MT_POSITION_Y, y); ++ } ++} ++ ++static void alps_report_semi_mt_data(struct input_dev *dev, int num_fin= gers, ++ int x1, int y1, int x2, int y2) ++{ ++ alps_set_slot(dev, 0, num_fingers !=3D 0, x1, y1); ++ alps_set_slot(dev, 1, num_fingers =3D=3D 2, x2, y2); ++} ++ ++static void alps_process_trackstick_packet_v3(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ unsigned char *packet =3D psmouse->packet; ++ struct input_dev *dev =3D priv->dev2; ++ int x, y, z, left, right, middle; ++ ++ /* Sanity check packet */ ++ if (!(packet[0] & 0x40)) { ++ psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n"); ++ return; ++ } ++ ++ /* ++ * There's a special packet that seems to indicate the end ++ * of a stream of trackstick data. Filter these out. ++ */ ++ if (packet[1] =3D=3D 0x7f && packet[2] =3D=3D 0x7f && packet[4] =3D=3D= 0x7f) ++ return; ++ ++ x =3D (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f)); ++ y =3D (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f)); ++ z =3D (packet[4] & 0x7c) >> 2; ++ ++ /* ++ * The x and y values tend to be quite large, and when used ++ * alone the trackstick is difficult to use. Scale them down ++ * to compensate. ++ */ ++ x /=3D 8; ++ y /=3D 8; ++ ++ input_report_rel(dev, REL_X, x); ++ input_report_rel(dev, REL_Y, -y); ++ ++ /* ++ * Most ALPS models report the trackstick buttons in the touchpad ++ * packets, but a few report them here. No reliable way has been ++ * found to differentiate between the models upfront, so we enable ++ * the quirk in response to seeing a button press in the trackstick ++ * packet. ++ */ ++ left =3D packet[3] & 0x01; ++ right =3D packet[3] & 0x02; ++ middle =3D packet[3] & 0x04; ++ ++ if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) && ++ (left || right || middle)) ++ priv->quirks |=3D ALPS_QUIRK_TRACKSTICK_BUTTONS; ++ ++ if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) { ++ input_report_key(dev, BTN_LEFT, left); ++ input_report_key(dev, BTN_RIGHT, right); ++ input_report_key(dev, BTN_MIDDLE, middle); ++ } ++ ++ input_sync(dev); ++ return; ++} ++ ++static void alps_process_touchpad_packet_v3(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ unsigned char *packet =3D psmouse->packet; ++ struct input_dev *dev =3D psmouse->dev; ++ struct input_dev *dev2 =3D priv->dev2; ++ int x, y, z; ++ int left, right, middle; ++ int x1 =3D 0, y1 =3D 0, x2 =3D 0, y2 =3D 0; ++ int fingers =3D 0, bmap_fingers; ++ unsigned int x_bitmap, y_bitmap; ++ ++ /* ++ * There's no single feature of touchpad position and bitmap packets ++ * that can be used to distinguish between them. We rely on the fact ++ * that a bitmap packet should always follow a position packet with ++ * bit 6 of packet[4] set. ++ */ ++ if (priv->multi_packet) { ++ /* ++ * Sometimes a position packet will indicate a multi-packet ++ * sequence, but then what follows is another position ++ * packet. Check for this, and when it happens process the ++ * position packet as usual. ++ */ ++ if (packet[0] & 0x40) { ++ fingers =3D (packet[5] & 0x3) + 1; ++ x_bitmap =3D ((packet[4] & 0x7e) << 8) | ++ ((packet[1] & 0x7f) << 2) | ++ ((packet[0] & 0x30) >> 4); ++ y_bitmap =3D ((packet[3] & 0x70) << 4) | ++ ((packet[2] & 0x7f) << 1) | ++ (packet[4] & 0x01); ++ ++ bmap_fingers =3D alps_process_bitmap(x_bitmap, y_bitmap, ++ &x1, &y1, &x2, &y2); ++ ++ /* ++ * We shouldn't report more than one finger if ++ * we don't have two coordinates. ++ */ ++ if (fingers > 1 && bmap_fingers < 2) ++ fingers =3D bmap_fingers; ++ ++ /* Now process position packet */ ++ packet =3D priv->multi_data; ++ } else { ++ priv->multi_packet =3D 0; ++ } ++ } ++ ++ /* ++ * Bit 6 of byte 0 is not usually set in position packets. The only ++ * times it seems to be set is in situations where the data is ++ * suspect anyway, e.g. a palm resting flat on the touchpad. Given ++ * this combined with the fact that this bit is useful for filtering ++ * out misidentified bitmap packets, we reject anything with this ++ * bit set. ++ */ ++ if (packet[0] & 0x40) ++ return; ++ ++ if (!priv->multi_packet && (packet[4] & 0x40)) { ++ priv->multi_packet =3D 1; ++ memcpy(priv->multi_data, packet, sizeof(priv->multi_data)); ++ return; ++ } ++ ++ priv->multi_packet =3D 0; ++ ++ left =3D packet[3] & 0x01; ++ right =3D packet[3] & 0x02; ++ middle =3D packet[3] & 0x04; ++ ++ x =3D ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) | ++ ((packet[0] & 0x30) >> 4); ++ y =3D ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f); ++ z =3D packet[5] & 0x7f; ++ ++ /* ++ * Sometimes the hardware sends a single packet with z =3D 0 ++ * in the middle of a stream. Real releases generate packets ++ * with x, y, and z all zero, so these seem to be flukes. ++ * Ignore them. ++ */ ++ if (x && y && !z) ++ return; ++ ++ /* ++ * If we don't have MT data or the bitmaps were empty, we have ++ * to rely on ST data. ++ */ ++ if (!fingers) { ++ x1 =3D x; ++ y1 =3D y; ++ fingers =3D z > 0 ? 1 : 0; ++ } ++ ++ if (z >=3D 64) ++ input_report_key(dev, BTN_TOUCH, 1); ++ else ++ input_report_key(dev, BTN_TOUCH, 0); ++ ++ alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2); ++ ++ input_report_key(dev, BTN_TOOL_FINGER, fingers =3D=3D 1); ++ input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers =3D=3D 2); ++ input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers =3D=3D 3); ++ input_report_key(dev, BTN_TOOL_QUADTAP, fingers =3D=3D 4); ++ ++ input_report_key(dev, BTN_LEFT, left); ++ input_report_key(dev, BTN_RIGHT, right); ++ input_report_key(dev, BTN_MIDDLE, middle); ++ ++ if (z > 0) { ++ input_report_abs(dev, ABS_X, x); ++ input_report_abs(dev, ABS_Y, y); ++ } ++ input_report_abs(dev, ABS_PRESSURE, z); ++ ++ input_sync(dev); ++ ++ if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) { ++ left =3D packet[3] & 0x10; ++ right =3D packet[3] & 0x20; ++ middle =3D packet[3] & 0x40; ++ ++ input_report_key(dev2, BTN_LEFT, left); ++ input_report_key(dev2, BTN_RIGHT, right); ++ input_report_key(dev2, BTN_MIDDLE, middle); ++ input_sync(dev2); ++ } ++} ++ ++static void alps_process_packet_v3(struct psmouse *psmouse) ++{ ++ unsigned char *packet =3D psmouse->packet; ++ ++ /* ++ * v3 protocol packets come in three types, two representing ++ * touchpad data and one representing trackstick data. ++ * Trackstick packets seem to be distinguished by always ++ * having 0x3f in the last byte. This value has never been ++ * observed in the last byte of either of the other types ++ * of packets. ++ */ ++ if (packet[5] =3D=3D 0x3f) { ++ alps_process_trackstick_packet_v3(psmouse); ++ return; ++ } ++ ++ alps_process_touchpad_packet_v3(psmouse); ++} ++ ++static void alps_process_packet_v4(struct psmouse *psmouse) ++{ ++ unsigned char *packet =3D psmouse->packet; ++ struct input_dev *dev =3D psmouse->dev; ++ int x, y, z; ++ int left, right; ++ ++ left =3D packet[4] & 0x01; ++ right =3D packet[4] & 0x02; ++ ++ x =3D ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) | ++ ((packet[0] & 0x30) >> 4); ++ y =3D ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f); ++ z =3D packet[5] & 0x7f; ++ ++ if (z >=3D 64) ++ input_report_key(dev, BTN_TOUCH, 1); ++ else ++ input_report_key(dev, BTN_TOUCH, 0); ++ ++ if (z > 0) { ++ input_report_abs(dev, ABS_X, x); ++ input_report_abs(dev, ABS_Y, y); ++ } ++ input_report_abs(dev, ABS_PRESSURE, z); ++ ++ input_report_key(dev, BTN_TOOL_FINGER, z > 0); ++ input_report_key(dev, BTN_LEFT, left); ++ input_report_key(dev, BTN_RIGHT, right); ++ ++ input_sync(dev); ++} ++ ++static void alps_process_packet(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ const struct alps_model_info *model =3D priv->i; ++ ++ switch (model->proto_version) { ++ case ALPS_PROTO_V1: ++ case ALPS_PROTO_V2: ++ alps_process_packet_v1_v2(psmouse); ++ break; ++ case ALPS_PROTO_V3: ++ alps_process_packet_v3(psmouse); ++ break; ++ case ALPS_PROTO_V4: ++ alps_process_packet_v4(psmouse); ++ break; ++ } ++} ++ + static void alps_report_bare_ps2_packet(struct psmouse *psmouse, + unsigned char packet[], + bool report_buttons) +@@ -344,7 +759,7 @@ +=20 + serio_pause_rx(psmouse->ps2dev.serio); +=20 +- if (psmouse->pktcnt =3D=3D 6) { ++ if (psmouse->pktcnt =3D=3D psmouse->pktsize) { +=20 + /* + * We did not any more data in reasonable amount of time. +@@ -395,8 +810,8 @@ + return PSMOUSE_BAD_DATA; + } +=20 +- /* Bytes 2 - 6 should have 0 in the highest bit */ +- if (psmouse->pktcnt >=3D 2 && psmouse->pktcnt <=3D 6 && ++ /* Bytes 2 - pktsize should have 0 in the highest bit */ ++ if (psmouse->pktcnt >=3D 2 && psmouse->pktcnt <=3D psmouse->pktsize && + (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { + psmouse_dbg(psmouse, "refusing packet[%i] =3D %x\n", + psmouse->pktcnt - 1, +@@ -404,7 +819,7 @@ + return PSMOUSE_BAD_DATA; + } +=20 +- if (psmouse->pktcnt =3D=3D 6) { ++ if (psmouse->pktcnt =3D=3D psmouse->pktsize) { + alps_process_packet(psmouse); + return PSMOUSE_FULL_PACKET; + } +@@ -412,11 +827,127 @@ + return PSMOUSE_GOOD_DATA; + } +=20 ++static int alps_command_mode_send_nibble(struct psmouse *psmouse, int n= ibble) ++{ ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ struct alps_data *priv =3D psmouse->private; ++ int command; ++ unsigned char *param; ++ unsigned char dummy[4]; ++ ++ BUG_ON(nibble > 0xf); ++ ++ command =3D priv->nibble_commands[nibble].command; ++ param =3D (command & 0x0f00) ? ++ dummy : (unsigned char *)&priv->nibble_commands[nibble].data; ++ ++ if (ps2_command(ps2dev, param, command)) ++ return -1; ++ ++ return 0; ++} ++ ++static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr= ) ++{ ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ struct alps_data *priv =3D psmouse->private; ++ int i, nibble; ++ ++ if (ps2_command(ps2dev, NULL, priv->addr_command)) ++ return -1; ++ ++ for (i =3D 12; i >=3D 0; i -=3D 4) { ++ nibble =3D (addr >> i) & 0xf; ++ if (alps_command_mode_send_nibble(psmouse, nibble)) ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int __alps_command_mode_read_reg(struct psmouse *psmouse, int ad= dr) ++{ ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ unsigned char param[4]; ++ ++ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) ++ return -1; ++ ++ /* ++ * The address being read is returned in the first two bytes ++ * of the result. Check that this address matches the expected ++ * address. ++ */ ++ if (addr !=3D ((param[0] << 8) | param[1])) ++ return -1; ++ ++ return param[2]; ++} ++ ++static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr= ) ++{ ++ if (alps_command_mode_set_addr(psmouse, addr)) ++ return -1; ++ return __alps_command_mode_read_reg(psmouse, addr); ++} ++ ++static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 va= lue) ++{ ++ if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf)) ++ return -1; ++ if (alps_command_mode_send_nibble(psmouse, value & 0xf)) ++ return -1; ++ return 0; ++} ++ ++static int alps_command_mode_write_reg(struct psmouse *psmouse, int add= r, ++ u8 value) ++{ ++ if (alps_command_mode_set_addr(psmouse, addr)) ++ return -1; ++ return __alps_command_mode_write_reg(psmouse, value); ++} ++ ++static int alps_enter_command_mode(struct psmouse *psmouse, ++ unsigned char *resp) ++{ ++ unsigned char param[4]; ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ ++ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || ++ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) { ++ psmouse_err(psmouse, "failed to enter command mode\n"); ++ return -1; ++ } ++ ++ if (param[0] !=3D 0x88 && param[1] !=3D 0x07) { ++ psmouse_dbg(psmouse, ++ "unknown response while entering command mode: %2.2x %2.2x %2.2x= \n", ++ param[0], param[1], param[2]); ++ return -1; ++ } ++ ++ if (resp) ++ *resp =3D param[2]; ++ return 0; ++} ++ ++static inline int alps_exit_command_mode(struct psmouse *psmouse) ++{ ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) ++ return -1; ++ return 0; ++} ++ + static const struct alps_model_info *alps_get_model(struct psmouse *psm= ouse, int *version) + { + struct ps2dev *ps2dev =3D &psmouse->ps2dev; + static const unsigned char rates[] =3D { 0, 10, 20, 40, 60, 80, 100, 2= 00 }; + unsigned char param[4]; ++ const struct alps_model_info *model =3D NULL; + int i; +=20 + /* +@@ -464,12 +995,41 @@ + *version =3D (param[0] << 8) | (param[1] << 4) | i; + } +=20 +- for (i =3D 0; i < ARRAY_SIZE(alps_model_data); i++) ++ for (i =3D 0; i < ARRAY_SIZE(alps_model_data); i++) { + if (!memcmp(param, alps_model_data[i].signature, +- sizeof(alps_model_data[i].signature))) +- return alps_model_data + i; ++ sizeof(alps_model_data[i].signature))) { ++ model =3D alps_model_data + i; ++ break; ++ } ++ } ++ ++ if (model && model->proto_version > ALPS_PROTO_V2) { ++ /* ++ * Need to check command mode response to identify ++ * model ++ */ ++ model =3D NULL; ++ if (alps_enter_command_mode(psmouse, param)) { ++ psmouse_warn(psmouse, ++ "touchpad failed to enter command mode\n"); ++ } else { ++ for (i =3D 0; i < ARRAY_SIZE(alps_model_data); i++) { ++ if (alps_model_data[i].proto_version > ALPS_PROTO_V2 && ++ alps_model_data[i].command_mode_resp =3D=3D param[0]) { ++ model =3D alps_model_data + i; ++ break; ++ } ++ } ++ alps_exit_command_mode(psmouse); ++ ++ if (!model) ++ psmouse_dbg(psmouse, ++ "Unknown command mode response %2.2x\n", ++ param[0]); ++ } ++ } +=20 +- return NULL; ++ return model; + } +=20 + /* +@@ -477,7 +1037,7 @@ + * subsequent commands. It looks like glidepad is behind stickpointer, + * I'd thought it would be other way around... + */ +-static int alps_passthrough_mode(struct psmouse *psmouse, bool enable) ++static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enabl= e) + { + struct ps2dev *ps2dev =3D &psmouse->ps2dev; + int cmd =3D enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; +@@ -494,7 +1054,7 @@ + return 0; + } +=20 +-static int alps_absolute_mode(struct psmouse *psmouse) ++static int alps_absolute_mode_v1_v2(struct psmouse *psmouse) + { + struct ps2dev *ps2dev =3D &psmouse->ps2dev; +=20 +@@ -565,17 +1125,17 @@ + static int alps_poll(struct psmouse *psmouse) + { + struct alps_data *priv =3D psmouse->private; +- unsigned char buf[6]; ++ unsigned char buf[sizeof(psmouse->packet)]; + bool poll_failed; +=20 + if (priv->i->flags & ALPS_PASS) +- alps_passthrough_mode(psmouse, true); ++ alps_passthrough_mode_v2(psmouse, true); +=20 + poll_failed =3D ps2_command(&psmouse->ps2dev, buf, + PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; +=20 + if (priv->i->flags & ALPS_PASS) +- alps_passthrough_mode(psmouse, false); ++ alps_passthrough_mode_v2(psmouse, false); +=20 + if (poll_failed || (buf[0] & priv->i->mask0) !=3D priv->i->byte0) + return -1; +@@ -592,13 +1152,13 @@ + return 0; + } +=20 +-static int alps_hw_init(struct psmouse *psmouse) ++static int alps_hw_init_v1_v2(struct psmouse *psmouse) + { + struct alps_data *priv =3D psmouse->private; + const struct alps_model_info *model =3D priv->i; +=20 + if ((model->flags & ALPS_PASS) && +- alps_passthrough_mode(psmouse, true)) { ++ alps_passthrough_mode_v2(psmouse, true)) { + return -1; + } +=20 +@@ -607,13 +1167,13 @@ + return -1; + } +=20 +- if (alps_absolute_mode(psmouse)) { ++ if (alps_absolute_mode_v1_v2(psmouse)) { + psmouse_err(psmouse, "Failed to enable absolute mode\n"); + return -1; + } +=20 + if ((model->flags & ALPS_PASS) && +- alps_passthrough_mode(psmouse, false)) { ++ alps_passthrough_mode_v2(psmouse, false)) { + return -1; + } +=20 +@@ -626,6 +1186,297 @@ + return 0; + } +=20 ++/* ++ * Enable or disable passthrough mode to the trackstick. Must be in ++ * command mode when calling this function. ++ */ ++static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enabl= e) ++{ ++ int reg_val; ++ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0008); ++ if (reg_val =3D=3D -1) ++ return -1; ++ ++ if (enable) ++ reg_val |=3D 0x01; ++ else ++ reg_val &=3D ~0x01; ++ ++ if (__alps_command_mode_write_reg(psmouse, reg_val)) ++ return -1; ++ ++ return 0; ++} ++ ++/* Must be in command mode when calling this function */ ++static int alps_absolute_mode_v3(struct psmouse *psmouse) ++{ ++ int reg_val; ++ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0004); ++ if (reg_val =3D=3D -1) ++ return -1; ++ ++ reg_val |=3D 0x06; ++ if (__alps_command_mode_write_reg(psmouse, reg_val)) ++ return -1; ++ ++ return 0; ++} ++ ++static int alps_hw_init_v3(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ int reg_val; ++ unsigned char param[4]; ++ ++ priv->nibble_commands =3D alps_v3_nibble_commands; ++ priv->addr_command =3D PSMOUSE_CMD_RESET_WRAP; ++ ++ if (alps_enter_command_mode(psmouse, NULL)) ++ goto error; ++ ++ /* Check for trackstick */ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0008); ++ if (reg_val =3D=3D -1) ++ goto error; ++ if (reg_val & 0x80) { ++ if (alps_passthrough_mode_v3(psmouse, true)) ++ goto error; ++ if (alps_exit_command_mode(psmouse)) ++ goto error; ++ ++ /* ++ * E7 report for the trackstick ++ * ++ * There have been reports of failures to seem to trace back ++ * to the above trackstick check failing. When these occur ++ * this E7 report fails, so when that happens we continue ++ * with the assumption that there isn't a trackstick after ++ * all. ++ */ ++ param[0] =3D 0x64; ++ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || ++ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) { ++ psmouse_warn(psmouse, "trackstick E7 report failed\n"); ++ } else { ++ psmouse_dbg(psmouse, ++ "trackstick E7 report: %2.2x %2.2x %2.2x\n", ++ param[0], param[1], param[2]); ++ ++ /* ++ * Not sure what this does, but it is absolutely ++ * essential. Without it, the touchpad does not ++ * work at all and the trackstick just emits normal ++ * PS/2 packets. ++ */ ++ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || ++ alps_command_mode_send_nibble(psmouse, 0x9) || ++ alps_command_mode_send_nibble(psmouse, 0x4)) { ++ psmouse_err(psmouse, ++ "Error sending magic E6 sequence\n"); ++ goto error_passthrough; ++ } ++ } ++ ++ if (alps_enter_command_mode(psmouse, NULL)) ++ goto error_passthrough; ++ if (alps_passthrough_mode_v3(psmouse, false)) ++ goto error; ++ } ++ ++ if (alps_absolute_mode_v3(psmouse)) { ++ psmouse_err(psmouse, "Failed to enter absolute mode\n"); ++ goto error; ++ } ++ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0006); ++ if (reg_val =3D=3D -1) ++ goto error; ++ if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) ++ goto error; ++ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0007); ++ if (reg_val =3D=3D -1) ++ goto error; ++ if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) ++ goto error; ++ ++ if (alps_command_mode_read_reg(psmouse, 0x0144) =3D=3D -1) ++ goto error; ++ if (__alps_command_mode_write_reg(psmouse, 0x04)) ++ goto error; ++ ++ if (alps_command_mode_read_reg(psmouse, 0x0159) =3D=3D -1) ++ goto error; ++ if (__alps_command_mode_write_reg(psmouse, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_read_reg(psmouse, 0x0163) =3D=3D -1) ++ goto error; ++ if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_read_reg(psmouse, 0x0162) =3D=3D -1) ++ goto error; ++ if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04)) ++ goto error; ++ ++ /* ++ * This ensures the trackstick packets are in the format ++ * supported by this driver. If bit 1 isn't set the packet ++ * format is different. ++ */ ++ if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82)) ++ goto error; ++ ++ alps_exit_command_mode(psmouse); ++ ++ /* Set rate and enable data reporting */ ++ param[0] =3D 0x64; ++ if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { ++ psmouse_err(psmouse, "Failed to enable data reporting\n"); ++ return -1; ++ } ++ ++ return 0; ++ ++error_passthrough: ++ /* Something failed while in passthrough mode, so try to get out */ ++ if (!alps_enter_command_mode(psmouse, NULL)) ++ alps_passthrough_mode_v3(psmouse, false); ++error: ++ /* ++ * Leaving the touchpad in command mode will essentially render ++ * it unusable until the machine reboots, so exit it here just ++ * to be safe ++ */ ++ alps_exit_command_mode(psmouse); ++ return -1; ++} ++ ++/* Must be in command mode when calling this function */ ++static int alps_absolute_mode_v4(struct psmouse *psmouse) ++{ ++ int reg_val; ++ ++ reg_val =3D alps_command_mode_read_reg(psmouse, 0x0004); ++ if (reg_val =3D=3D -1) ++ return -1; ++ ++ reg_val |=3D 0x02; ++ if (__alps_command_mode_write_reg(psmouse, reg_val)) ++ return -1; ++ ++ return 0; ++} ++ ++static int alps_hw_init_v4(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ struct ps2dev *ps2dev =3D &psmouse->ps2dev; ++ unsigned char param[4]; ++ ++ priv->nibble_commands =3D alps_v4_nibble_commands; ++ priv->addr_command =3D PSMOUSE_CMD_DISABLE; ++ ++ if (alps_enter_command_mode(psmouse, NULL)) ++ goto error; ++ ++ if (alps_absolute_mode_v4(psmouse)) { ++ psmouse_err(psmouse, "Failed to enter absolute mode\n"); ++ goto error; ++ } ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03)) ++ goto error; ++ ++ if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03)) ++ goto error; ++ ++ alps_exit_command_mode(psmouse); ++ ++ /* ++ * This sequence changes the output from a 9-byte to an ++ * 8-byte format. All the same data seems to be present, ++ * just in a more compact format. ++ */ ++ param[0] =3D 0xc8; ++ param[1] =3D 0x64; ++ param[2] =3D 0x50; ++ if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || ++ ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) || ++ ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) || ++ ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) ++ return -1; ++ ++ /* Set rate and enable data reporting */ ++ param[0] =3D 0x64; ++ if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || ++ ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { ++ psmouse_err(psmouse, "Failed to enable data reporting\n"); ++ return -1; ++ } ++ ++ return 0; ++ ++error: ++ /* ++ * Leaving the touchpad in command mode will essentially render ++ * it unusable until the machine reboots, so exit it here just ++ * to be safe ++ */ ++ alps_exit_command_mode(psmouse); ++ return -1; ++} ++ ++static int alps_hw_init(struct psmouse *psmouse) ++{ ++ struct alps_data *priv =3D psmouse->private; ++ const struct alps_model_info *model =3D priv->i; ++ int ret =3D -1; ++ ++ switch (model->proto_version) { ++ case ALPS_PROTO_V1: ++ case ALPS_PROTO_V2: ++ ret =3D alps_hw_init_v1_v2(psmouse); ++ break; ++ case ALPS_PROTO_V3: ++ ret =3D alps_hw_init_v3(psmouse); ++ break; ++ case ALPS_PROTO_V4: ++ ret =3D alps_hw_init_v4(psmouse); ++ break; ++ } ++ ++ return ret; ++} ++ + static int alps_reconnect(struct psmouse *psmouse) + { + const struct alps_model_info *model; +@@ -666,6 +1517,8 @@ +=20 + psmouse->private =3D priv; +=20 ++ psmouse_reset(psmouse); ++ + model =3D alps_get_model(psmouse, &version); + if (!model) + goto init_fail; +@@ -693,8 +1546,29 @@ + BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); +=20 + dev1->evbit[BIT_WORD(EV_ABS)] |=3D BIT_MASK(EV_ABS); +- input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); +- input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); ++ ++ switch (model->proto_version) { ++ case ALPS_PROTO_V1: ++ case ALPS_PROTO_V2: ++ input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); ++ input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); ++ break; ++ case ALPS_PROTO_V3: ++ set_bit(INPUT_PROP_SEMI_MT, dev1->propbit); ++ input_mt_init_slots(dev1, 2); ++ input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0)= ; ++ input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0)= ; ++ ++ set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit); ++ set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit); ++ set_bit(BTN_TOOL_QUADTAP, dev1->keybit); ++ /* fall through */ ++ case ALPS_PROTO_V4: ++ input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0); ++ input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0); ++ break; ++ } ++ + input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); +=20 + if (model->flags & ALPS_WHEEL) { +@@ -737,7 +1611,7 @@ + psmouse->poll =3D alps_poll; + psmouse->disconnect =3D alps_disconnect; + psmouse->reconnect =3D alps_reconnect; +- psmouse->pktsize =3D 6; ++ psmouse->pktsize =3D model->proto_version =3D=3D ALPS_PROTO_V4 ? 8 : 6= ; +=20 + /* We are having trouble resyncing ALPS touchpads so disable it for no= w */ + psmouse->resync_time =3D 0; +diff -ur linux-3.2.old/drivers/input/mouse/alps.h linux-3.2/drivers/inpu= t/mouse/alps.h +--- linux-3.2.old/drivers/input/mouse/alps.h 2012-01-04 17:55:44.0000000= 00 -0600 ++++ linux-3.2/drivers/input/mouse/alps.h 2012-01-05 18:53:42.235275879 -= 0600 +@@ -12,20 +12,39 @@ + #ifndef _ALPS_H + #define _ALPS_H +=20 ++#define ALPS_PROTO_V1 0 ++#define ALPS_PROTO_V2 1 ++#define ALPS_PROTO_V3 2 ++#define ALPS_PROTO_V4 3 ++ + struct alps_model_info { + unsigned char signature[3]; ++ unsigned char command_mode_resp; /* v3/v4 only */ ++ unsigned char proto_version; + unsigned char byte0, mask0; + unsigned char flags; + }; +=20 ++struct alps_nibble_commands { ++ int command; ++ unsigned char data; ++}; ++ + struct alps_data { + struct input_dev *dev2; /* Relative device */ + char phys[32]; /* Phys */ + const struct alps_model_info *i;/* Info */ ++ const struct alps_nibble_commands *nibble_commands; ++ int addr_command; /* Command to set register address */ + int prev_fin; /* Finger bit from previous packet */ ++ int multi_packet; /* Multi-packet data in progress */ ++ unsigned char multi_data[6]; /* Saved multi-packet data */ ++ u8 quirks; + struct timer_list timer; + }; +=20 ++#define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in tracks= tick packet */ ++ + #ifdef CONFIG_MOUSE_PS2_ALPS + int alps_detect(struct psmouse *psmouse, bool set_properties); + int alps_init(struct psmouse *psmouse); +diff -ur linux-3.2.old/drivers/input/mouse/psmouse.h linux-3.2/drivers/i= nput/mouse/psmouse.h +--- linux-3.2.old/drivers/input/mouse/psmouse.h 2012-01-04 17:55:44.0000= 00000 -0600 ++++ linux-3.2/drivers/input/mouse/psmouse.h 2012-01-05 18:53:42.23127588= 0 -0600 +@@ -8,6 +8,7 @@ + #define PSMOUSE_CMD_SETSTREAM 0x00ea + #define PSMOUSE_CMD_SETPOLL 0x00f0 + #define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to recei= ve */ ++#define PSMOUSE_CMD_RESET_WRAP 0x00ec + #define PSMOUSE_CMD_GETID 0x02f2 + #define PSMOUSE_CMD_SETRATE 0x10f3 + #define PSMOUSE_CMD_ENABLE 0x00f4