From patchwork Fri Oct 13 18:20:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10005629 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 8A44D60230 for ; Fri, 13 Oct 2017 18:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83A2A2912B for ; Fri, 13 Oct 2017 18:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 784492912F; Fri, 13 Oct 2017 18:21:04 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 B375E2912B for ; Fri, 13 Oct 2017 18:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753123AbdJMSVC (ORCPT ); Fri, 13 Oct 2017 14:21:02 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:43317 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752590AbdJMSVA (ORCPT ); Fri, 13 Oct 2017 14:21:00 -0400 Received: by mail-pg0-f65.google.com with SMTP id s75so968017pgs.0 for ; Fri, 13 Oct 2017 11:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1b7gkyUlx3aEbdYlEq1QXV56QStiPdi7NntObRUdiIU=; b=bdwL8NwR/2BUHWnfxc55UDcd3FwGAmKb0G49FEkIg0VlGv7KWQ7g2wPBhmF1Saozzq 8y523vvBrhSgH/GArRQSEPaGgg3IEFNSHCfD3a008C//AVn9KluVcoCHHqsbv+MMxL0L Vi6g3A1Uz+u0P1axXH8MLw+ay1RW1fiTE69BOcYyJxVV/DTR8HtDYLHek88LFsD6Yjl+ tLdBmeaA2El2MQxBOfopWw4BHZN305lWwkaAy5b6hSCYpRQXmJkPDSrINNJy91sHk2pQ wPocFrpzO8InSt5uvdfjN5Q3Cdl6XMBpFVW1bP52jPKfjnhoT9JiWbeSnBMLA27RjiMP zetg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1b7gkyUlx3aEbdYlEq1QXV56QStiPdi7NntObRUdiIU=; b=ZWu9TjkoNvN3ApVyPYi70aIA5FoPGTeXSETFg8kunFarLAAC+lOcsyu5AlwaoNTNft xnxb/x0HAjtl5Pyrx0e1bbYbIxHQCzs8xkiTrFkFT0ZNtypJMIr/WlGwa2cXIl0sTrj5 RP8dRM/4RNVtz5JwqKU+uyOgMyNjZtAtOTKvxE0BBKhvFBlG5FsPkw7klH15T+36x0rY WCdU9kD8AlT7llOgD22/xmddPkifql9prZRo6HluUF9zMqx2vnEAWmVPrJDsxoeaaIeP uZc2BafGs8QFhzN1Am/oj8L9/MwR/IBiMVrH5Kot6iIQRmAqwiaf4YYPe/an2vIySsPO gH2Q== X-Gm-Message-State: AMCzsaVgZMCjLR4v6I0BKEQTkyah7RcRgf4IFuWg9QXt48PRDK3yI35q qirTEHAL9flyjBeEe77oZlI= X-Google-Smtp-Source: AOwi7QBKvj5P0VyOu40cPjcQwRhEiZ3V+l/XpLQNuPy80ljap5KNyuSP7pAJTXU5hhI6nJA64drPUQ== X-Received: by 10.84.160.6 with SMTP id n6mr2108620pla.393.1507918859441; Fri, 13 Oct 2017 11:20:59 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id a25sm3722046pfc.143.2017.10.13.11.20.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Oct 2017 11:20:58 -0700 (PDT) Date: Fri, 13 Oct 2017 11:20:56 -0700 From: Dmitry Torokhov To: Bastien Nocera Cc: Hans de Goede , Benjamin Tissoires , linux-input@vger.kernel.org, Paul Cercueil , russianneuromancer@ya.ru Subject: Re: [PATCH v3] Input: goodix - Poll the 'buffer status' bit before reading data Message-ID: <20171013182056.ktgrsofuwu2powo5@dtor-ws> References: <20171013174139.32125-1-hdegoede@redhat.com> <1507917540.5910.40.camel@hadess.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1507917540.5910.40.camel@hadess.net> User-Agent: NeoMutt/20170609 (1.8.3) 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 On Fri, Oct 13, 2017 at 07:59:00PM +0200, Bastien Nocera wrote: > On Fri, 2017-10-13 at 19:41 +0200, Hans de Goede wrote: > > + const int timeout = 20; > > I meant rather something like: > #define GOODIX_BUFFER_STATUS_TIMEOUT 20 > > Feel free to add my Reviewed-by after this change is made. > How about below? Reviewed-by: Bastien Nocera diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index 84df27326b53..699179a3c297 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -71,6 +71,9 @@ struct goodix_ts_data { #define GOODIX_REG_CONFIG_DATA 0x8047 #define GOODIX_REG_ID 0x8140 +#define GOODIX_BUFFER_STATUS_READY BIT(7) +#define GOODIX_BUFFER_STATUS_TIMEOUT 20 + #define RESOLUTION_LOC 1 #define MAX_CONTACTS_LOC 5 #define TRIGGER_LOC 6 @@ -194,35 +197,53 @@ static int goodix_get_cfg_len(u16 id) static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) { + unsigned long max_timeout; int touch_num; int error; - 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; - } + /* + * The 'buffer status' bit, which indicates that the data is valid, is + * not set as soon as the interrupt is raised, but slightly after. + * This takes around 10 ms to happen, so we poll for 20 ms. + */ + max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT); + 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 (!(data[0] & 0x80)) - return -EAGAIN; + if (data[0] & GOODIX_BUFFER_STATUS_READY) { + touch_num = data[0] & 0x0f; + if (touch_num > ts->max_touch_num) + return -EPROTO; + + if (touch_num > 1) { + data += 1 + GOODIX_CONTACT_SIZE; + error = goodix_i2c_read(ts->client, + GOODIX_READ_COOR_ADDR + + 1 + GOODIX_CONTACT_SIZE, + data, + GOODIX_CONTACT_SIZE * + (touch_num - 1)); + if (error) + return error; + } + + return touch_num; + } - touch_num = data[0] & 0x0f; - if (touch_num > ts->max_touch_num) - return -EPROTO; - - if (touch_num > 1) { - data += 1 + GOODIX_CONTACT_SIZE; - error = goodix_i2c_read(ts->client, - GOODIX_READ_COOR_ADDR + - 1 + GOODIX_CONTACT_SIZE, - data, - GOODIX_CONTACT_SIZE * (touch_num - 1)); - if (error) - return error; - } + usleep_range(1000, 2000); /* Poll every 1 - 2 ms */ + } while (time_before(jiffies, max_timeout)); - return touch_num; + /* + * The Goodix panel will send spurious interrupts after a + * 'finger up' event, which will always cause a timeout. + */ + return 0; } static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)