From patchwork Fri Nov 14 19:38:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 5309271 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 161F5C11AC for ; Fri, 14 Nov 2014 19:40:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E95220176 for ; Fri, 14 Nov 2014 19:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25FF720131 for ; Fri, 14 Nov 2014 19:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161658AbaKNTki (ORCPT ); Fri, 14 Nov 2014 14:40:38 -0500 Received: from mail-wi0-f181.google.com ([209.85.212.181]:57320 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161834AbaKNTjF (ORCPT ); Fri, 14 Nov 2014 14:39:05 -0500 Received: by mail-wi0-f181.google.com with SMTP id n3so3739324wiv.8 for ; Fri, 14 Nov 2014 11:39:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=1pDH4r8SJzolwV9aS4HF1Pl7wgAq3peLVl1Lg1ng8BY=; b=xAFS2QfA+RKqIgzV/vR052+7lGMkiVEcz9+KkXaJQYkaaYVS2x6Kx3DM3Hb9gI9mjU RnJKH46VcwyIA3w4sgREuVZbA/NgifSvr+rjRJwo34mSKPCKSmOLwA7WKGi2Q4baUarn QCl/qzcl8kYem+YSXgW7Ke5jD7fv+/0yScV8+fyNEOkW3NyWCWlhDtHnGkEv3uGO/Oii 2wCzTWDVabBCK95aw5S3snpCHUQwrQgZf+XcGq06cLYLLWrL+CXJNVqoNxcnBbibf24A 0Ffluq6yVVI0jj6T1SSqj1iaXsEk96lsxXBJfjbTPTmB0LdT0bsaZRIWUIVgHdeCuSna lXmw== X-Received: by 10.180.19.164 with SMTP id g4mr10231841wie.51.1415993944092; Fri, 14 Nov 2014 11:39:04 -0800 (PST) Received: from Pali-Latitude.kolej.mff.cuni.cz (pali.kolej.mff.cuni.cz. [78.128.193.202]) by mx.google.com with ESMTPSA id wr9sm40768945wjb.42.2014.11.14.11.39.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 11:39:03 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Dmitry Torokhov , Hans de Goede Cc: Yunkang Tang , Vadim Klishko , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 4/7] input: alps: Use NULL instead dummy argument for alps_identify Date: Fri, 14 Nov 2014 20:38:23 +0100 Message-Id: <1415993906-13307-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1415993906-13307-1-git-send-email-pali.rohar@gmail.com> References: <1415993906-13307-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch change alps_identify() function code so it can be called also without priv parameter which is useful for alps_detect(). Instead passing dummy value now alps_identify() accept also NULL value and skip filling priv data. It is useless for alps_detect() and it will speed up detection of alps devices. Signed-off-by: Pali Rohár --- drivers/input/mouse/alps.c | 114 +++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 43 deletions(-) diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index 5603870..0176425 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -2162,8 +2162,7 @@ static void alps_set_defaults(struct alps_data *priv) } } -static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv, - unsigned char *e7, unsigned char *ec) +static const struct alps_model_info *alps_match_table(unsigned char *e7, unsigned char *ec) { const struct alps_model_info *model; int i; @@ -2174,24 +2173,49 @@ static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv, if (!memcmp(e7, model->signature, sizeof(model->signature)) && (!model->command_mode_resp || model->command_mode_resp == ec[2])) { + return model; + } + } - priv->proto_version = model->proto_version; - alps_set_defaults(priv); + return NULL; +} - priv->flags = model->flags; - priv->byte0 = model->byte0; - priv->mask0 = model->mask0; +static inline bool alps_match_v5(unsigned char *e7, unsigned char *ec) +{ + return (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 && + ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)); +} - return 0; - } - } +static inline bool alps_match_v7(unsigned char *e7, unsigned char *ec) +{ + return (ec[0] == 0x88 && + ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)); +} - return -EINVAL; +static inline bool alps_match_rushmore_v3(unsigned char *e7, unsigned char *ec) +{ + return (ec[0] == 0x88 && ec[1] == 0x08); +} + +static inline bool alps_match_v3(unsigned char *e7, unsigned char *ec) +{ + return (ec[0] == 0x88 && ec[1] == 0x07 && + ec[2] >= 0x90 && ec[2] <= 0x9d); +} + +static inline bool alps_match_any(unsigned char *e7, unsigned char *ec) +{ + return (alps_match_table(e7, ec) || + alps_match_v5(e7, ec) || + alps_match_v7(e7, ec) || + alps_match_rushmore_v3(e7, ec) || + alps_match_v3(e7, ec)); } static int alps_identify(struct psmouse *psmouse, struct alps_data *priv) { unsigned char e6[4], e7[4], ec[4]; + const struct alps_model_info *model; /* * First try "E6 report". @@ -2217,40 +2241,46 @@ static int alps_identify(struct psmouse *psmouse, struct alps_data *priv) alps_exit_command_mode(psmouse)) return -EIO; - /* Save the Firmware version */ - memcpy(priv->fw_ver, ec, 3); + if (priv) { - if (alps_match_table(psmouse, priv, e7, ec) == 0) { - return 0; - } else if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 && - ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) { - priv->proto_version = ALPS_PROTO_V5; - alps_set_defaults(priv); + /* Save the Firmware version */ + memcpy(priv->fw_ver, ec, 3); - return 0; - } else if (ec[0] == 0x88 && - ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)) { - priv->proto_version = ALPS_PROTO_V7; - alps_set_defaults(priv); - - return 0; - } else if (ec[0] == 0x88 && ec[1] == 0x08) { - priv->proto_version = ALPS_PROTO_V3; - alps_set_defaults(priv); + if ((model = alps_match_table(e7, ec))) { + priv->proto_version = model->proto_version; + alps_set_defaults(priv); + priv->flags = model->flags; + priv->byte0 = model->byte0; + priv->mask0 = model->mask0; + return 0; + } else if (alps_match_v5(e7, ec)) { + priv->proto_version = ALPS_PROTO_V5; + alps_set_defaults(priv); + return 0; + } else if (alps_match_v7(e7, ec)) { + priv->proto_version = ALPS_PROTO_V7; + alps_set_defaults(priv); + return 0; + } else if (alps_match_rushmore_v3(e7, ec)) { + priv->proto_version = ALPS_PROTO_V3; + alps_set_defaults(priv); + priv->hw_init = alps_hw_init_rushmore_v3; + priv->decode_fields = alps_decode_rushmore; + priv->x_bits = 16; + priv->y_bits = 12; + priv->flags |= ALPS_IS_RUSHMORE; + return 0; + } else if (alps_match_v3(e7, ec)) { + priv->proto_version = ALPS_PROTO_V3; + alps_set_defaults(priv); + return 0; + } - priv->hw_init = alps_hw_init_rushmore_v3; - priv->decode_fields = alps_decode_rushmore; - priv->x_bits = 16; - priv->y_bits = 12; - priv->flags |= ALPS_IS_RUSHMORE; + } else { - return 0; - } else if (ec[0] == 0x88 && ec[1] == 0x07 && - ec[2] >= 0x90 && ec[2] <= 0x9d) { - priv->proto_version = ALPS_PROTO_V3; - alps_set_defaults(priv); + if (alps_match_any(e7, ec)) + return 0; - return 0; } psmouse_dbg(psmouse, @@ -2427,9 +2457,7 @@ init_fail: int alps_detect(struct psmouse *psmouse, bool set_properties) { - struct alps_data dummy; - - if (alps_identify(psmouse, &dummy) < 0) + if (alps_identify(psmouse, NULL) < 0) return -1; if (set_properties) {