Received: by 10.213.65.68 with SMTP id h4csp27871imn; Mon, 12 Mar 2018 16:10:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELsunsXtvJlhIpq/q6DL2NqNZspeGzk1jysxqx6SrxPKh7zeUv/ItDX+UHlLlrPnqUMRAPXL X-Received: by 10.98.237.12 with SMTP id u12mr9488629pfh.72.1520896253618; Mon, 12 Mar 2018 16:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520896253; cv=none; d=google.com; s=arc-20160816; b=P0ZHVV1Cq68d0ta2LGJYnJI55FqLxmvVgjTWxxDbpftUD9JXHniA0qUGd/ikDDaGuQ 55zu6fugx73h8QmD/iPw8wbPHOF59l5knvYZqIm9j+rQFEhJMzL9i9926xaEsX3iUs3F 8LGQKsPB8q6rRRTJ0Xj8fPQyqha8FWU+XSSrsIjz6yV8QhMgoWSwH44qO82WX+kZT1K1 CBvDd5gBgBzin0/lqcB9WZFuhMwTrK9Tk9a1pUrpMeE8LQYBmI+8dL1/u2T+cdFZ8A+F 6xjelP8QM5pSy9YVH78ARv/LZVb8bxsFud9xbjsBxojOKvEwXjkpFbv5GwFHPVugB99F YHYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=40jpRmIO/2xlRogYq6u1/64WRznU2YwIi6bTUyCpPbI=; b=rvN+rp6U1ZgTWN5OKZNhKZi0YdyhQ4iUOulumLTnvJqospY6kyaFGPPCtulnn6IekG e7jwsOwaMTywccgKWwKxA7DfY/I+AtoSr3fXrxfpVOwVsJDFSELsVl8S9Qg7Qyupd/3V tVFecENkIXnbrtNqO4/PEqjfE016NapOgIemwjW2uZX3h6l8DudHdvBGAqH+h85IrZAh OauQ16mklU9senSHcwEL4VPZJOLvmJlimM4b6Ol5HGDepWGUjYvJPsJJDs+qcCzWmZfy 7DERGlxo3dzJ7Qwq/Sz5rfj3eYtax8AIM21g88GcRBq+Ls4M+cmMxpluKenLiKkBSBhX cxFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NO+vycTo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p16-v6si5145562pli.731.2018.03.12.16.10.38; Mon, 12 Mar 2018 16:10:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NO+vycTo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932302AbeCLXJk (ORCPT + 99 others); Mon, 12 Mar 2018 19:09:40 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:46185 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333AbeCLXJi (ORCPT ); Mon, 12 Mar 2018 19:09:38 -0400 Received: by mail-wr0-f196.google.com with SMTP id m12so17396948wrm.13; Mon, 12 Mar 2018 16:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=40jpRmIO/2xlRogYq6u1/64WRznU2YwIi6bTUyCpPbI=; b=NO+vycToo4zGRCiwSRQiaarD5fYvTBB5C0S0flvupjh/9sf7CCtANmRbjlJFu9W2qp BpPwCpAPpexOhYppKaOZ6nEASCtZCM8aRiQ0CpJppTIv/lgPnwCWeNQRMglsmyIybHxz 46Mq3uDX5+KAyF/WeRZNQ+W41Cl9Eh3No+XIZVIApmOz7bTInFkCKcrzVrqOqanRUnzl FbokIKsTINRxW/C1yxwoKQotqDYPszf/uxdJWMmP1TfSo4yMsmnBWobUxKxk5tEOjA/A IyZARW+HLT8sZLIw+IScXsFVqrEmw0QKf+d48ApAu6HsN9W7ftdmg+Sj7wCTTQW917m6 t0CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=40jpRmIO/2xlRogYq6u1/64WRznU2YwIi6bTUyCpPbI=; b=Ric6KMvQtVXS9mB+vBx7XAq4XLBejn7qwx5u8lZlQppehue9+TY2w4kGNrKMfvPs8D GksY2XCOdRZR4SThVtE1Vh8dssERwYYwdZ7oZ32Md9ovoJ7BF1w7FfnvGRsSF0tV+3nW exj/O+tkVaHcbo/FFbEE2MNgj3HeXElOP7Vi9T+WCAFGO+ri3GL7uZzlEHE9Oxn2T+Kt wlUiMvLo7RNHLVzxdhk0C2lZR2PM4CkCSaQjmH3tAqkXN3Ipf/PdqYADCqGTwT42G76+ ii+lZ0v8A6wsJJh16eEsykMHMjsd2/J8TgzzKXXOJ8tknsv+yRpe/oEEW/6wpQDIA3wo REOw== X-Gm-Message-State: AElRT7HN1oo6sXEY107dZgH7t7Bs/qlUybGGrjiob9UKlYPi9TOHkQIA pihJ+dzTsn0D/bmAwbVBX5M= X-Received: by 10.223.200.144 with SMTP id k16mr8157354wrh.282.1520896177069; Mon, 12 Mar 2018 16:09:37 -0700 (PDT) Received: from Pali-Latitude.lan (pali.kolej.mff.cuni.cz. [78.128.193.202]) by smtp.gmail.com with ESMTPSA id f127sm5752054wmg.46.2018.03.12.16.09.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 16:09:35 -0700 (PDT) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Dmitry Torokhov , Masaki Ota Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols Date: Tue, 13 Mar 2018 00:09:15 +0100 Message-Id: <20180312230915.26050-1-pali.rohar@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove cite "Not sure what this does, but it is absolutely essential". Extract initialization of trackstick part when touchpad is in passthrought mode for v3 and v6 protocols into own function. Initialization for v3 is: setscale11, setscale11, setscale11, nibble 0x9, nibble 0x4. Initialization for v6 is: setscale11, setscale11, setscale11, setrate 0xC8, setrate 0x14. Nibbles 0x9 and 0x4 for v3 protocol correspondent to setrate 0xC8 and 0x14, therefore these sequences are same. When touchpad is in passthrought mode, then OS communicates with trackstick and this sequence is some magic vendor PS/2 command to put trackstick into "extended" mode. After that sequence trackstick starts reporting packets in some vendor 4 bytes format (first byte is always 0xE8). Next step after configuring trackstick to be in "extended" mode, is to configure touchpad for v3 protocol to expect that trackstick reports data in "extended" mode. For v3 protocol this is done by setting bit 1 in register 0xC2C8 (offset 0x08 from base address 0xC2C0). When both touchpad and trackstick are not configured for "extended" mode then touchpad reports trackstick packets in different format, which is not supported by psmouse/alps driver (yet). In Cirque documentation GP-AN- 130823 INTERFACING TO GEN4 OVER I2C (PDF) available at http://www.cirque.com/gen4-dev-resources is Logical Address 0xC2C8 named as PS2AuxControl and Bit Number 1 as ProcessAuxExtendedData with description: Auxiliary device data is assumed to be extended data when set. Signed-off-by: Pali Rohár --- drivers/input/mouse/alps.c | 80 ++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index dbe57da8c1a1..010c1bcdb06d 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -2063,14 +2063,11 @@ static int alps_hw_init_v1_v2(struct psmouse *psmouse) return 0; } -static int alps_hw_init_v6(struct psmouse *psmouse) +/* Must be in passthrough mode when calling this function */ +static int alps_trackstick_enter_extended_mode_v3_v6(struct psmouse *psmouse) { unsigned char param[2] = {0xC8, 0x14}; - /* Enter passthrough mode to let trackpoint enter 6byte raw mode */ - if (alps_passthrough_mode_v2(psmouse, true)) - return -1; - if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || @@ -2078,9 +2075,25 @@ static int alps_hw_init_v6(struct psmouse *psmouse) ps2_command(&psmouse->ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) return -1; + return 0; +} + +static int alps_hw_init_v6(struct psmouse *psmouse) +{ + int ret; + + /* Enter passthrough mode to let trackpoint enter 6byte raw mode */ + if (alps_passthrough_mode_v2(psmouse, true)) + return -1; + + ret = alps_trackstick_enter_extended_mode_v3_v6(psmouse); + if (alps_passthrough_mode_v2(psmouse, false)) return -1; + if (ret) + return ret; + if (alps_absolute_mode_v6(psmouse)) { psmouse_err(psmouse, "Failed to enable absolute mode\n"); return -1; @@ -2154,10 +2167,18 @@ static int alps_probe_trackstick_v3_v7(struct psmouse *psmouse, int reg_base) static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base) { - struct ps2dev *ps2dev = &psmouse->ps2dev; int ret = 0; + int reg_val; unsigned char param[4]; + /* + * We need to configure trackstick to report data for touchpad in + * extended format. And also we need to tell touchpad to expect data + * from trackstick in extended format. Without this configuration + * trackstick packets sent from touchpad are in basic format which is + * different from what we expect. + */ + if (alps_passthrough_mode_v3(psmouse, reg_base, true)) return -EIO; @@ -2175,39 +2196,36 @@ static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base) ret = -ENODEV; } else { psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param); - - /* - * 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"); + if (alps_trackstick_enter_extended_mode_v3_v6(psmouse)) { + psmouse_err(psmouse, "Failed to enter into trackstick extended mode\n"); ret = -EIO; - goto error; } + } + + if (alps_passthrough_mode_v3(psmouse, reg_base, false)) + return -EIO; + + if (ret) + return ret; + if (alps_enter_command_mode(psmouse)) + return -EIO; + + reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08); + if (reg_val == -1) { + ret = -EIO; + } else { /* - * This ensures the trackstick packets are in the format - * supported by this driver. If bit 1 isn't set the packet - * format is different. + * Tell touchpad that trackstick is now in extended mode. + * If bit 1 isn't set the packet format is different. */ - if (alps_enter_command_mode(psmouse) || - alps_command_mode_write_reg(psmouse, - reg_base + 0x08, 0x82) || - alps_exit_command_mode(psmouse)) + reg_val |= BIT(1); + if (__alps_command_mode_write_reg(psmouse, reg_val)) ret = -EIO; } -error: - if (alps_passthrough_mode_v3(psmouse, reg_base, false)) - ret = -EIO; + if (alps_exit_command_mode(psmouse)) + return -EIO; return ret; } -- 2.11.0