From patchwork Mon Jun 21 21:04:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?w4PigLByaWMgUGllbA==?= X-Patchwork-Id: 107254 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5LL80UJ017344 for ; Mon, 21 Jun 2010 21:08:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758425Ab0FUVIG (ORCPT ); Mon, 21 Jun 2010 17:08:06 -0400 Received: from mailservice.tudelft.nl ([130.161.131.5]:49768 "EHLO mailservice.tudelft.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758347Ab0FUVIE (ORCPT ); Mon, 21 Jun 2010 17:08:04 -0400 Received: from localhost (localhost [127.0.0.1]) by amavis (Postfix) with ESMTP id 9F27D7F800E; Mon, 21 Jun 2010 23:08:03 +0200 (CEST) X-Virus-Scanned: amavisd-new at tudelft.nl X-Spam-Flag: NO X-Spam-Score: -22.589 X-Spam-Level: X-Spam-Status: No, score=-22.589 tagged_above=-99 required=5 tests=[BAYES_00=-2.599, PROLO_LEO3=0.01, TUD_REL01=-20] autolearn=ham Received: from mailservice.tudelft.nl ([130.161.131.69]) by localhost (tudelft.nl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TWLQLeL1o8ak; Mon, 21 Jun 2010 23:08:02 +0200 (CEST) Received: from smtp-a.tudelft.nl (smtp-a.tudelft.nl [130.161.180.7]) by mx1.tudelft.nl (Postfix) with ESMTP id BFE307F8011; Mon, 21 Jun 2010 23:08:02 +0200 (CEST) Received: from [172.19.3.21] (63-103-dsl.ipact.nl [84.35.103.63]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-a.tudelft.nl (Postfix) with ESMTP id 301B0B3A62; Mon, 21 Jun 2010 23:08:02 +0200 (CEST) Message-ID: <4C1FD3C2.1010201@tudelft.nl> Date: Mon, 21 Jun 2010 23:04:02 +0200 From: =?UTF-8?B?w4lyaWMgUGllbA==?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100614 Mandriva/3.0.4-11mdv2010.1 (2010.1) Thunderbird/3.0.4 MIME-Version: 1.0 To: Dmitry Torokhov , "linux-input@vger.kernel.org" CC: Florian Ragwitz Subject: [PATCH 4/7] elantech: implement data check for 6-byte protocol References: <4C1FD2B0.1080504@tudelft.nl> In-Reply-To: <4C1FD2B0.1080504@tudelft.nl> X-Enigmail-Version: 1.0.1 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.3 (demeter.kernel.org [140.211.167.41]); Mon, 21 Jun 2010 21:08:07 +0000 (UTC) diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index f32ffda..b09b458 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -339,6 +339,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 */ @@ -352,16 +403,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; }