From patchwork Thu Mar 30 13:33:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 9654233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F05260113 for ; Thu, 30 Mar 2017 13:35:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 719AA26E39 for ; Thu, 30 Mar 2017 13:35:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6676A27D5E; Thu, 30 Mar 2017 13:35:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0484726E39 for ; Thu, 30 Mar 2017 13:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933943AbdC3Ne4 (ORCPT ); Thu, 30 Mar 2017 09:34:56 -0400 Received: from mail-by2nam01on0081.outbound.protection.outlook.com ([104.47.34.81]:60320 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933062AbdC3Nex (ORCPT ); Thu, 30 Mar 2017 09:34:53 -0400 Received: from BN3PR03CA0097.namprd03.prod.outlook.com (10.174.66.15) by BN1PR03MB187.namprd03.prod.outlook.com (10.255.200.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14; Thu, 30 Mar 2017 13:34:45 +0000 Received: from BY2FFO11FD035.protection.gbl (2a01:111:f400:7c0c::181) by BN3PR03CA0097.outlook.office365.com (2603:10b6:400:4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10 via Frontend Transport; Thu, 30 Mar 2017 13:34:44 +0000 Authentication-Results: spf=fail (sender IP is 137.71.25.57) smtp.mailfrom=crapouillou.net; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=crapouillou.net; Received-SPF: Fail (protection.outlook.com: domain of crapouillou.net does not designate 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by BY2FFO11FD035.mail.protection.outlook.com (10.1.14.220) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.977.7 via Frontend Transport; Thu, 30 Mar 2017 13:34:42 +0000 Received: from NWD2HUBCAS9.ad.analog.com (nwd2hubcas9.ad.analog.com [10.64.69.109]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id v2UI3lRQ001190 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Thu, 30 Mar 2017 14:03:47 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS9.ad.analog.com (10.64.69.109) with Microsoft SMTP Server id 14.3.210.2; Thu, 30 Mar 2017 09:34:41 -0400 Received: from carl.ad.analog.com ([10.43.17.151]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id v2UDYdgs013168; Thu, 30 Mar 2017 09:34:40 -0400 From: Paul Cercueil To: Bastien Nocera , Dmitry Torokhov CC: , , "Paul Cercueil" Subject: [PATCH] input: goodix: Poll the 'buffer status' bit before reading data Date: Thu, 30 Mar 2017 15:33:49 +0200 Message-ID: <20170330133349.19931-1-paul@crapouillou.net> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131353544835387819; (52f37747-95c3-483a-bd05-08d153b03fac); () X-Forefront-Antispam-Report: CIP:137.71.25.57; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39850400002)(39410400002)(39860400002)(39840400002)(39380400002)(39450400003)(39400400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(2906002)(50466002)(8936002)(48376002)(50226002)(8676002)(1076002)(33646002)(305945005)(47776003)(7636002)(50986999)(105606002)(356003)(106466001)(77096006)(54906002)(189998001)(5003940100001)(5660300001)(4326008)(39060400002)(575784001)(85426001)(38730400002)(36756003)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR03MB187; H:nwd2mta2.analog.com; FPR:; SPF:Fail; MLV:ovrnspm; A:1; MX:1; PTR:nwd2mail11.analog.com; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD035; 1:ULCkRoe+YIFrdeX7WvsXqklFW3L9mnqlcS7QFV3wzsIQK3j5ZGDX7NitwtpZMd4lylEY5At44CLEhY6z7K2LLZ+cnmwTbcCaPao+I/hnszmbMqdRezrgHVS8fKg9A1MVzVLurCBwZTVoVWvkfpBYvHEm9oafA6dRR9gSskF/Kr9J/gl81fT95o2861I1FIYlyt8+PCAXJjPQiGvoj45exmPkFr9WzmeiLp3TYdIhbMJWhdz9E72lgmCrgLIHZIrWfucWmBpbJ8q3TbpJQKJVT3Q8FQ1MP6l6+uvZppnqOBeOUSDOTsL/8RPzmATz/YyZU5nTW8c6cKD5hz/U4nScLJvQL/BBFQ5XPmxOlVUmPxxklTRvc11nMJM88dOlLCy6hBRxAIUallB9Fh7Zg91HsxXBdJR4SjbAcX/Ts21Duz+JAUmCNjG4bV0a/89hrIpi8bMdOqUo+FEEvuRUHrm+YW1LNLCJUm6eezvm87VdhHJpgu1v6qnZO6nkfziRsIcxAgYceR9yNX1RhZtQUVNN/nBVyrRKeEWPg9Ylyf09hKTXqbDkli3fM8/6hJb5i6TGpjdcR5TUSEYBOcO2htzJvg== X-MS-Office365-Filtering-Correlation-Id: c811eb1c-1926-4661-704a-08d47771865b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131430075)(201703131517081); SRVR:BN1PR03MB187; X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB187; 3:Hnio2ak2f1cRsMVaT4DZhsL4FKJiColLqgVZXPPe2yri/ATVW1B5uHvxknt7EyLBsI8to/uFihi+KbK/2oAQi7fNpn6stGHnTfv9yoNrF5UgY0EurjLzFVA4rzqjAA6j/SvlUKP8yQLjA0/r0W/or1WY1d/VIX9R34Ct423R5ZlzTO+F9UoG8CTDG/RwCxzQ0uhTmEtncyJrb4JmWUxjK4l3LEXuP5m99bDe2aepPNVGTZQgv6brppZEtubRC8UnPp9EXzWoYgdTUaLLFl6eZlvl3dYUzOgnTDbPBnWulIEiR4KZtu9HQnVS2KB3Fs8jjdKefi23LjrItgzykq2S2uN3qj2pgFkI/v5iYxMuPlen2IOUNv1DJWN9kds3mKUtqC5IEloGI7Ubf5DL2ZnyxkuiSNr49qC2R9/eFiWiBAlmfm3WFXvkpLpW6+8q4AFg; 25:inbDlj5ayqGpcqwMwX4hOVO8XsgnwH3yo7f++WTVbIsIThTmvPNvQr4NlzHkAgL718JALFXuVhtGGFnjKac3RSCGo6UrZBFltX0a6/TBZBYnzbAlUsCR9g7mLQ8yul6ijD/jEv8mD/hVbiIcwcnlQ8UACiccmWLNUAl12Z5bUI3t0RfADGkNsnulcbG86Vu3We/5k95PO7Vy1Q4NyxZ7JtPsil69bnEi4yuqLmV8/lw7w9JmOkmcMATndYzPRZ9e64ARFTyv078ykYN4QVI0fU+38disuR+RaOw44bmTbxfYvhuUPVdTDHsrm9PpdH1/v/dcwpjHEgSPqPL7X05LDL+YvP/SIY8uAHvSUN7OXQxZsSFH0GEqkE6sNL8q9UvUffGesvtHiQFTt+h1uzLjcyI+h5WN8Yv4FHchFFfkrOd06MfobnmmVhnDOX8mzD4vYWYBlBxocsqlIa/bQ+MDiA== X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB187; 31:PzVY3j9+PdSHJSbI/eNwrQdSWU3XfNYAfOH2TxE+QBjpXqb7EgHqsPFAwzTgfaaziVFneiCla3rDeYo+8x1LqRYMTlyQ2+dfF6PBQ6wZsFVPonoG80XNFx50z0T+vcPPSq5eyARJWCDZwM15sPe/s4nTCSWLMpPmzNqiIQabbeqWjQHBnxKO4jlDiDREHGhE4DVRIqYMWMEAVG+OOSmfazmeZ8MM6X4xmJRgj5y+N+Cgu/BvvGZ8UTskdl1Da52DFk4QCKCihNaEC0ayggFefXrEkxUnx19mOy3QGe1nzhs= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(601004)(2401047)(13023025)(8121501046)(5005006)(13017025)(13015025)(13018025)(13024025)(10201501046)(3002001)(6055026)(6096035)(20161123563025)(20161123561025)(20161123565025)(20161123556025)(201703131430075)(201703131448075)(201703131433075)(201703161259075); SRVR:BN1PR03MB187; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR03MB187; X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB187; 4:VpaZgXVuKKSO32J5aTB65oXwECjURfhWWjS8DsI27ajEJeWvIA7AujBhMc3n8sNayEqxoqi3dB0bqg2K4w1N51MeuwhViz80JGpkByqvM5yXRHKF+Kf4OHEj0gVeSYUP0ywg8JMipZ9Jv8p8uMRIg21AD3OK0Qg4aAxIg2LLRB48yXCiVfHmv39NbincRDRuazhy73DyiVhWHtEoCcBFt0l5PR2ptXyKUIGXBY7fxsua8g8dCbspHD35F9/F8C4ZB+2IB3flS69iUQ76r3bD6PtlYTYrp2LFQ6IvmEY/VXqoQVo4lQAmhVzkfo0D1CFi867L9SYIAg3pNUcqsq8DpdgWw6/JlXNn6R/RTL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Ki7p5hkeCO9G1vsXzbjyKmJjuASmiPKHEQY4Bgryy7NwkOl/xpYlNOcc81+1K33mfHncH5/giBxpekN93YJ1vp+fP3uK5se+IB+7WNCLdF14EXOM/UKycAURohntI5xdlUqWeP7BH6gUH0Lpg==; 5:YCvAVseS9MQQPI4XHZaO8RHOQZa31n6WIzRV6Q4UucMkBg2K7hPdCulurGvNMSoKiPTVf6Nw1ernH0pJNQqHuF252dlomRE/MeaaqFaqYk4TFA3wTQOPKYF7leWWOPZFFa6Oho4aFrR7fHQ0pFVdjOYWxOEkglmWXvrkvS3Ef6gQCwOpjQVoZfU/HEnelZ0f; 24:yTRljU1pf69AEG7f6LBStMET9fKaskhyJCvgIaP5CWOXrUGiUV9OxvMQiIBEslX5TUKWiB3j9XY3QCQ30xQTIZ/g5qvZ02/999lhh39YPUs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB187; 7:dhnYHT0wQwetMC5QPlMMz3bWPvknLASjGYrPR98nffqqxY/3NDovuNONFWnBoW7N5Oib6iQ2nGeHsLslHWbWN2WiYuulDqk4k+aQFrKu8SEI9XxyzzKkaqcQEqkOIqlCFZ6dMEMqPqMSxtRmhUueX5BPZJcPXo62gc7EnT1XKD1nwubwVpYXiBhdynRODonT62AkwKU5gi0PWRYdnxa5OH9FpObVkyFckKflAjVS5kB29Q3UIadj0yBOAsG08DIA4yHVhX7ecdIgGKNmiW0FnZVc5s3HSC7/CDujA+Pxzccp3xlp3j8pwzVG3kc6pAPfwk1LJ9jTJdPWYEwnVrewbQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2017 13:34:42.5091 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[137.71.25.57]; Helo=[nwd2mta2.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR03MB187 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Goodix panel triggers an interrupt on touch events. However, its registers will contain the valid values a short time after the interrupt, and not when it's raised. At that moment, the 'buffer status' bit is set. Previously, if the 'buffer status' bit was not set when the registers were read, the data was discarded and no input event was emitted, causing "finger down" or "finger up" events to be missed sometimes. This went unnoticed until v4.9, as the DesignWare I2C driver commonly used with this driver had enough latency for that bug to never trigger. Now, in the IRQ handler we will poll (with a timeout) the 'buffer status' bit and process the data of the panel as soon as this bit gets set. Note that the Goodix panel will send a few spurious interrupts after the 'finger up' event, in which the 'buffer status' bit will never be set. Signed-off-by: Paul Cercueil --- drivers/input/touchscreen/goodix.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index 240b16f3ee97..7a8b89b87c2f 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -195,18 +195,34 @@ static int goodix_get_cfg_len(u16 id) static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) { + unsigned int timeout = 100; int touch_num; int error; - error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, data, + /* The 'buffer status' bit, which indicates that the data is valid, is + * not set as soon as the interrupt is raised, but slightly after. + */ + do { + error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, data, GOODIX_CONTACT_SIZE + 1); - if (error) { - dev_err(&ts->client->dev, "I2C transfer error: %d\n", error); - return error; - } + if (error) { + dev_err(&ts->client->dev, "I2C transfer error: %d\n", + error); + return error; + } - if (!(data[0] & 0x80)) - return -EAGAIN; + if (data[0] & 0x80) + break; + + usleep_range(100, 200); + } while (--timeout); + + if (!timeout) { + /* The Goodix panel will send spurious interrupts after a + * 'finger up' event, which will always cause a timeout. + */ + return 0; + } touch_num = data[0] & 0x0f; if (touch_num > ts->max_touch_num)