Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB7D9C433E0 for ; Tue, 11 Aug 2020 13:39:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9004920771 for ; Tue, 11 Aug 2020 13:39:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jC7OpU13" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728651AbgHKNjq (ORCPT ); Tue, 11 Aug 2020 09:39:46 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49704 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728532AbgHKNjp (ORCPT ); Tue, 11 Aug 2020 09:39:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597153183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHM0Va84olzQtItpi4Mouml7v3hy76P4eZwlXG/YIo4=; b=jC7OpU13DxQLn7VgtAOeWH62JeK1DKzRvvjPV/k7sR/inyU8Pz88atPfwQZju4Gt65gYfz dfvZuDyy/BTMilC/CFsVGhmCbps804Kqi+ymMHg/ntzaXKnywWqYAKjYQp07v8XE0TD07G c+x3OV8uocZp66iV4mjs4ABSlV3bVW4= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-w_55ubjgM72PwOHI0Y6-tw-1; Tue, 11 Aug 2020 09:39:41 -0400 X-MC-Unique: w_55ubjgM72PwOHI0Y6-tw-1 Received: by mail-ej1-f71.google.com with SMTP id i4so5150650ejk.9 for ; Tue, 11 Aug 2020 06:39:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aHM0Va84olzQtItpi4Mouml7v3hy76P4eZwlXG/YIo4=; b=Et2SyTn5iws3OZRouZ0irnJ2FJCnaZm2NN41L/Hary+t0bSZ027EYuInuD5UKNDH6A R9CZ8+PeIOaleT6DOrJuPPre1KZwCToGr1p4s2J5auos/9OluVipTo1JHz9+XwFEVgY0 YO1SbCeNoWa2YdsWveIn8+F1TytSWs5ploY+DBF6q76Whn75S9iES4CCf7XPWyLFvCBS EQq7bh8tklDEOtevh3L9aYvas3SBgRqVi941ImyGrO7DHof47/QXuxo5f8F0o9JwvgUt QIQ1Vpe10jX6CuXaSQ/7GAjdwIaTdkewLMjj3wy7UsulXRnMgknYnHyaLSE2R5ThRU5X uDPw== X-Gm-Message-State: AOAM530eCiJOInV4G3VSyfLKGjJ0ZQaHiab8LbUqJfynEOOEesfwqUqp Mg80Fi6nskNl+X5j1VSENlh1SGv+BRheuQjxE5taFnecBFP0Q8zW/LYJkz4o85nsbvHevz9B2tY zw73Zh7Vd2pgh+xrxwpl77Os= X-Received: by 2002:a17:906:a253:: with SMTP id bi19mr25855242ejb.338.1597153180553; Tue, 11 Aug 2020 06:39:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYhnPHwAvoRQlImmNvp7f7mXCFUm3mKzXz5bM3s2r6WlOuHN9bZbCxRMx1tme6QiERKBahOw== X-Received: by 2002:a17:906:a253:: with SMTP id bi19mr25855225ejb.338.1597153180339; Tue, 11 Aug 2020 06:39:40 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c0c-fe00-d2ea-f29d-118b-24dc.cable.dynamic.v6.ziggo.nl. [2001:1c00:c0c:fe00:d2ea:f29d:118b:24dc]) by smtp.gmail.com with ESMTPSA id s2sm14864654ejh.95.2020.08.11.06.39.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 06:39:39 -0700 (PDT) Subject: Re: [PATCH v2] HID: i2c-hid: Always sleep 1ms after I2C_HID_PWR_ON commands To: Kai-Heng Feng Cc: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, stable@vger.kernel.org, Andrea Borgia References: <20200811125900.338705-1-hdegoede@redhat.com> <141CAECB-B76A-41D0-9D2D-4955DAAEBF77@canonical.com> From: Hans de Goede Message-ID: <47427dd7-1146-11d8-21f4-058f3753a91d@redhat.com> Date: Tue, 11 Aug 2020 15:39:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <141CAECB-B76A-41D0-9D2D-4955DAAEBF77@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Hi, On 8/11/20 3:37 PM, Kai-Heng Feng wrote: > Hi Hans, > >> On Aug 11, 2020, at 20:59, Hans de Goede wrote: >> >> Before this commit i2c_hid_parse() consists of the following steps: >> >> 1. Send power on cmd >> 2. usleep_range(1000, 5000) >> 3. Send reset cmd >> 4. Wait for reset to complete (device interrupt, or msleep(100)) >> 5. Send power on cmd >> 6. Try to read HID descriptor >> >> Notice how there is an usleep_range(1000, 5000) after the first power-on >> command, but not after the second power-on command. >> >> Testing has shown that at least on the BMAX Y13 laptop's i2c-hid touchpad, >> not having a delay after the second power-on command causes the HID >> descriptor to read as all zeros. >> >> In case we hit this on other devices too, the descriptor being all zeros >> can be recognized by the following message being logged many, many times: >> >> hid-generic 0018:0911:5288.0002: unknown main item tag 0x0 >> >> At the same time as the BMAX Y13's touchpad issue was debugged, >> Kai-Heng was working on debugging some issues with Goodix i2c-hid >> touchpads. It turns out that these need a delay after a PWR_ON command >> too, otherwise they stop working after a suspend/resume cycle. >> According to Goodix a delay of minimal 60ms is needed. >> >> Having multiple cases where we need a delay after sending the power-on >> command, seems to indicate that we should always sleep after the power-on >> command. >> >> This commit fixes the mentioned issues by moving the existing 1ms sleep to >> the i2c_hid_set_power() function and changing it to a 60ms sleep. > > Thanks for your patch. > > The subject is still "1ms" instead of "60ms". Oops, v3 with this fixed coming up. Regards, Hans >> Cc: stable@vger.kernel.org >> BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=208247 >> Reported-by: Kai-Heng Feng >> Reported-and-tested-by: Andrea Borgia >> Signed-off-by: Hans de Goede >> --- >> Changes in v2: >> - Add Kai-Heng's case, with Goodix touchpads needing a delay after PWR_ON too, >> to the commit message >> - Add a Reported-by tag for Kai-Heng >> - Increase the delay to 60ms >> --- >> drivers/hid/i2c-hid/i2c-hid-core.c | 22 +++++++++++++--------- >> 1 file changed, 13 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c >> index 294c84e136d7..dbd04492825d 100644 >> --- a/drivers/hid/i2c-hid/i2c-hid-core.c >> +++ b/drivers/hid/i2c-hid/i2c-hid-core.c >> @@ -420,6 +420,19 @@ static int i2c_hid_set_power(struct i2c_client *client, int power_state) >> dev_err(&client->dev, "failed to change power setting.\n"); >> >> set_pwr_exit: >> + >> + /* >> + * The HID over I2C specification states that if a DEVICE needs time >> + * after the PWR_ON request, it should utilise CLOCK stretching. >> + * However, it has been observered that the Windows driver provides a >> + * 1ms sleep between the PWR_ON and RESET requests. >> + * According to Goodix Windows even waits 60 ms after (other?) >> + * PWR_ON requests. Testing has confirmed that several devices >> + * will not work properly without a delay after a PWR_ON request. >> + */ >> + if (!ret && power_state == I2C_HID_PWR_ON) >> + msleep(60); >> + >> return ret; >> } >> >> @@ -441,15 +454,6 @@ static int i2c_hid_hwreset(struct i2c_client *client) >> if (ret) >> goto out_unlock; >> >> - /* >> - * The HID over I2C specification states that if a DEVICE needs time >> - * after the PWR_ON request, it should utilise CLOCK stretching. >> - * However, it has been observered that the Windows driver provides a >> - * 1ms sleep between the PWR_ON and RESET requests and that some devices >> - * rely on this. >> - */ >> - usleep_range(1000, 5000); >> - >> i2c_hid_dbg(ihid, "resetting...\n"); >> >> ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0); >> -- >> 2.28.0 >> >