From patchwork Sat May 14 06:47:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4PigLByaWMgUGllbA==?= X-Patchwork-Id: 784942 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4EB8E0L025085 for ; Sat, 14 May 2011 11:08:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756076Ab1ENLIN (ORCPT ); Sat, 14 May 2011 07:08:13 -0400 Received: from mailservice.tudelft.nl ([130.161.131.5]:46424 "EHLO mailservice.tudelft.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755081Ab1ENLIM (ORCPT ); Sat, 14 May 2011 07:08:12 -0400 Received: from localhost (localhost [127.0.0.1]) by amavis (Postfix) with ESMTP id 126AF2B8045; Sat, 14 May 2011 12:43:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at tudelft.nl X-Spam-Flag: NO X-Spam-Score: -9.315 X-Spam-Level: X-Spam-Status: No, score=-9.315 tagged_above=-99 required=5 tests=[BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, PROLO_LEO3=0.01, RCVD_IN_PBL=10, RCVD_IN_SORBS_DUL=0.001, RDNS_DYNAMIC=0.982, TUD_REL01=-20] autolearn=ham Received: from mailservice.tudelft.nl ([130.161.131.73]) by localhost (tudelft.nl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id fec0znaPlC1k; Sat, 14 May 2011 12:43:10 +0200 (CEST) Received: from smtp-a.tudelft.nl (smtp-a.tudelft.nl [130.161.180.7]) by mx2.tudelft.nl (Postfix) with ESMTP id 454F72B8047; Sat, 14 May 2011 12:43:10 +0200 (CEST) Received: from [192.168.1.33] (212-123-168-131.ip.telfort.nl [212.123.168.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-a.tudelft.nl (Postfix) with ESMTP id 01B67B3A62; Sat, 14 May 2011 12:43:09 +0200 (CEST) Message-ID: <4DCE2578.9060308@tudelft.nl> Date: Sat, 14 May 2011 08:47:20 +0200 From: =?ISO-8859-1?Q?=C9ric_Piel?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Mandriva/3.1.10-1 (2011.0) Thunderbird/3.1.10 MIME-Version: 1.0 To: Dmitry Torokhov CC: "linux-input@vger.kernel.org" , Henrik Rydberg , Chris Bagwell , Florian Ragwitz Subject: [PATCH 3/6] elantech: implement data check for 6-byte protocol Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 14 May 2011 11:08:14 +0000 (UTC) Based on the protocol description, and the source code of the Dell/Ubuntu driver, the two additional types of data checking for the 6-byte protocol are added. Technically, this is not parity checking, but to avoid too much change, "paritycheck" is kept to talk about the checks. In addition, as in the Dell/Ubuntu driver, instead of dropping all the bytes when an error is detected, just drop the first byte, so that it's possible to re-synchronize quickly. Signed-off-by: Éric Piel --- drivers/input/mouse/elantech.c | 61 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index badb2ea..8f0a1ee 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -348,6 +348,57 @@ static int elantech_check_parity_v1(struct psmouse *psmouse) etd->parity[packet[3]] == p3; } +static int elantech_check_parity_ef113(struct psmouse *psmouse) +{ + unsigned char *packet = psmouse->packet; + + /* Consistency checks as in the Dell/Ubuntu driver */ + return !((((packet[0] & 0x3c) != 0x3c) && ((packet[0] & 0xc0) != 0x80)) || + (((packet[0] & 0x0c) != 0x0c) && ((packet[0] & 0xc0) == 0x80)) || + (((packet[0] & 0xc0) != 0x80) && ((packet[1] & 0xf0) != 0x00)) || + (((packet[3] & 0x3e) != 0x38) && ((packet[0] & 0xc0) != 0x80)) || + (((packet[3] & 0x0e) != 0x08) && ((packet[0] & 0xc0) == 0x80)) || + (((packet[0] & 0xc0) != 0x80) && ((packet[4] & 0xf0) != 0x00))); +} + +static int elantech_check_parity_const(struct psmouse *psmouse) +{ + unsigned char *packet = psmouse->packet; + + /* Some bits which are constant in the 6 packets */ + return (((packet[0] & 0x0c) == 0x04) && ((packet[3] & 0x0f) == 0x02)); +} + +/* + * Returns 0 if an error is detected in the packets. + */ +static int elantech_check_parity(struct psmouse *psmouse) +{ + struct elantech_data *etd = psmouse->private; + + switch (etd->paritycheck) { + case ETP_FULL_PC: + return elantech_check_parity_v1(psmouse); + case ETP_EF113_CHECK: + return elantech_check_parity_ef113(psmouse); + case ETP_CONST_CHECK: + return elantech_check_parity_const(psmouse); + case ETP_NOT_CHECK: + default: + return 1; + } +} + +static void elantech_shift_packets(struct psmouse *psmouse) +{ + unsigned char *packet = psmouse->packet; + int i; + + for (i = 0; i < (psmouse->pktsize - 1); i++) + packet[i] = packet[i + 1]; + psmouse->pktcnt--; +} + /* * Process byte stream from mouse and handle complete packets */ @@ -361,16 +412,18 @@ static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse) if (etd->debug > 1) elantech_packet_dump(psmouse->packet, psmouse->pktsize); + if (!elantech_check_parity(psmouse)) { + /* Try to re-synchronize */ + elantech_shift_packets(psmouse); + return PSMOUSE_GOOD_DATA; + } + switch (etd->hw_version) { case 1: - if (etd->paritycheck && !elantech_check_parity_v1(psmouse)) - return PSMOUSE_BAD_DATA; - elantech_report_absolute_v1(psmouse); break; case 2: - /* We don't know how to check parity in protocol v2 */ elantech_report_absolute_v2(psmouse); break; }