Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp95576lqa; Fri, 26 Apr 2024 15:58:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSzjxSmjVokrJsQ5lWeruzV7RWPkTo0Rg3rHl5h+vhGvtG0dQO+xKRVF8x6NJYDaDohH9DUX1ij/3TMAxX1oGjNlBvUKJFMrxlL6UBpQ== X-Google-Smtp-Source: AGHT+IEXYcu0VXw0HrABxkK/tpXpalvpGVUypFNIcectX0JGi6DGTKRc4A0Xe8UUGZTFPlvA97nt X-Received: by 2002:a05:6a21:610:b0:1a3:bd97:4cab with SMTP id ll16-20020a056a21061000b001a3bd974cabmr1376466pzb.6.1714172313539; Fri, 26 Apr 2024 15:58:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714172313; cv=pass; d=google.com; s=arc-20160816; b=lsPKJVkCGrqBfExpEaN/m/VTFEEGrCjnVsg0bhSy7eobgOyo/07chbeFMCt7su6CRz bF0r57eb7d0WCqi8O+6K073z1n46U5uBrXAWdgOuUhZw6z3X68QsE3R4wtF9atTCzpMq pHSFeDt7xKfFHllsiOGcft9M46Z122uRK7I3ZVJhTwt/1xh/qz+c4eZJiVCBHongnnNU TO3RDbGYZD0SKERpmA+yDunkolUX3LtEgTGpVBYJpuLnJ5D8iiXx4jyaNP28gywQKqwT qMUpiTMa8W7McgGInaNwMk6Q/143WTW1PoIapWEfRkaWTPVfOlRVPtJPH5hv1EIQR96D 8PPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4KU3jl0WoeassL0fsNyvxyf1+jr7Lzh8USMHCS2SFuk=; fh=Mm8hlFdBHUY0fyqKU/MWlqkizWEw7qYBWD0xRewgNf0=; b=oSfvHREXN0WfHy7oVNm+m2HoHGCa2G9kl1Qxu+3TUF1xWdfoTv4emqVzhJAbMYdUJ2 DrX2Xn4bIsDim3WRWUS1cIDb+Ic6vXOmTMnUske8S4BnCR4MnmS4wm5DenW+Vc8dofzL WiEKObW3bK6zH6NJVQmdxeGIZqb4FoaB93WMaUVnYoav/LMp4oCCJRps3rJbHps2KO/M gVZXjAL//RsxjLwzzBcXjkCIZZRw6QZli4khNdu3TT+BzK1eeyIvpkjcshBazoP8SOdQ jMtTJmTYAHmvVfdGi20u4qy9pO3cAgVH8qf476veo9qrhoB8/2UQr0qm1NbaovGL+fzY V0AA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kl.wtf header.s=key1 header.b=PyMDwgGJ; arc=pass (i=1 spf=pass spfdomain=kl.wtf dkim=pass dkdomain=kl.wtf dmarc=pass fromdomain=kl.wtf); spf=pass (google.com: domain of linux-kernel+bounces-160757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kl.wtf Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o6-20020a637306000000b0060bef6c5008si2956026pgc.56.2024.04.26.15.58.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 15:58:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kl.wtf header.s=key1 header.b=PyMDwgGJ; arc=pass (i=1 spf=pass spfdomain=kl.wtf dkim=pass dkdomain=kl.wtf dmarc=pass fromdomain=kl.wtf); spf=pass (google.com: domain of linux-kernel+bounces-160757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kl.wtf Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 24C89B21A9F for ; Fri, 26 Apr 2024 22:58:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68D203C06B; Fri, 26 Apr 2024 22:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kl.wtf header.i=@kl.wtf header.b="PyMDwgGJ" Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0124F39AC9 for ; Fri, 26 Apr 2024 22:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172279; cv=none; b=XChefkU0twjfK5MSj+26dLhNdKuFGo33doO5J3D+VlrW7bhHGgGDv08/HVQ5SfGPyFMWm2W9m8aaLLKr9A+DOzVtbnVrclNBNW5LNlI+Id7mouh/wx1Dgqj7dGazTGBHGGVEtRZJ6HNsLe+eqW3D4ya/37QlMZQUMxrwy3t+7oU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172279; c=relaxed/simple; bh=jcYLChDAgnIUe4+iN8D3/9NndAF22/1Z60vNxCuSZTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=erWf2uX4+dQw9O0ZBNyJWZAN4klLAzQMfZbLdebeyuAkSWKGU3056Oo0OXe2M1rhS+SzLhNnny5ui/aKsgOpHSpex3eYSlbWOATvmdFAA1IxiJgPlNZcE7zRDAN8u8gEhd/64pqiVtFMz8X17+iqTnNOY9ATu+8ttIqAd1SWmQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=kl.wtf; spf=pass smtp.mailfrom=kl.wtf; dkim=pass (2048-bit key) header.d=kl.wtf header.i=@kl.wtf header.b=PyMDwgGJ; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=kl.wtf Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kl.wtf X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kl.wtf; s=key1; t=1714172276; 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=4KU3jl0WoeassL0fsNyvxyf1+jr7Lzh8USMHCS2SFuk=; b=PyMDwgGJogmpa6f+Up4ClCDkkfbFDqgE0FxFFdokAgFB6B05qFPdsdg1iAe+0lyH8biu2k VuW9RVfhDJc1AMP2A7zp/0R5DLW5yDpYh5s2ootpgOVliKPMlHKVjcLzOIXSlhWGOpn2PS czThUf0Rb/1TRQHS2nhkcQmgcvUAzb7Pcq5XrQ2YjAfZdxhYE8pfR6JkTHOOcWggLboTwS 8VApmOQEq0TVmWlJS1mmV1HolJ54ZzrmhB/FTSvrzCD6MR6Awo3W7bCFZZSNb5UA74pMgZ eDQ/YMbwkzbmggPyzAo+jL3XiNFdCxH9dBBb78sFnUWvVseSmL+yA2tRulYl5A== From: Kenny Levinsen To: Jiri Kosina , Dmitry Torokhov , Benjamin Tissoires , Douglas Anderson , Hans de Goede , Maxime Ripard , Kai-Heng Feng , Johan Hovold , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Radoslaw Biernacki , Lukasz Majczak Cc: Kenny Levinsen Subject: [PATCH v3 2/3] HID: i2c-hid: Retry HID descriptor read to wake up STM devices Date: Sat, 27 Apr 2024 00:47:08 +0200 Message-ID: <20240426225739.2166-3-kl@kl.wtf> In-Reply-To: <20240426225739.2166-1-kl@kl.wtf> References: <20240426225739.2166-1-kl@kl.wtf> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Some STM microcontrollers need 400µs after rising clock edge in order to come out of their deep sleep state. This in turn means that the first command sent to them will fail on a bus error. Retry once on bus error to see if the device came alive, otherwise treat the error as if no device was present like before. Link: https://lore.kernel.org/all/20240405102436.3479210-1-lma@chromium.org/#t Co-developed-by: Radoslaw Biernacki Co-developed-by: Lukasz Majczak Tested-by: Lukasz Majczak Reviewed-by: Lukasz Majczak Signed-off-by: Kenny Levinsen --- drivers/hid/i2c-hid/i2c-hid-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 6ffa43d245b4..6ac1b11fb675 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -991,8 +991,17 @@ static int __i2c_hid_core_probe(struct i2c_hid *ihid) struct hid_device *hid = ihid->hid; int ret; + /* + * Some STM-based devices need 400µs after a rising clock edge to wake + * from deep sleep, which in turn means that our first command will + * fail on a bus error. Retry the command in this case. + */ ret = i2c_hid_fetch_hid_descriptor(ihid); - if (ret < 0) { + if (ret == -ENXIO) { + usleep_range(400, 500); + ret = i2c_hid_fetch_hid_descriptor(ihid); + } + if (ret) { i2c_hid_dbg(ihid, "failed to fetch HID descriptor: %d\n", ret); return ret; } -- 2.44.0