Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2904082lqt; Tue, 23 Apr 2024 05:27:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBb/9b5zBKvXLvTQT5Wm9Gnz1ZvTTIAJY/CrfBz2Cmt+eOVwFBy5RDDYjLt/eR9QIDUTlJxltRuLYnCKCA3GE1pLy3q23Qa6kfMY/j3g== X-Google-Smtp-Source: AGHT+IFgXkS2XNDTPQnWCkclCyoGxHgC6fuc2Rlu1qmv0NcBwLr1KXP8UqKDqgkn6iQIto44tYUI X-Received: by 2002:a05:6a20:dd9a:b0:1aa:674a:5e8a with SMTP id kw26-20020a056a20dd9a00b001aa674a5e8amr2813882pzb.25.1713875238162; Tue, 23 Apr 2024 05:27:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713875238; cv=pass; d=google.com; s=arc-20160816; b=GnEZ7cxnS1NyHcj4+HwVUoxhQNLjdCQ+lAZG4G1VpErFuESH4hc2rPpuLJdsfOjQWB 4ox/DTf5Lvcgq5bhVxvaAjCs3iDlQmkpFU8eizIuIKCnPPJdR90a6Js5Eqet5d2P+dYV OJ/hQDHgPr9OKt3cGlEf20lDhRGJMLxARGvR7rCAjNtdSKLlLdDD928sC0wZgTsRemT9 41oMzuM8v70EwmObHhG/XgypAgyc1DnNyw0IuJ5ykmVmf6fBC+r3ya8Ws0W+ZTVLJILX ah3OnpGhnSLTDY5EGVqss1o7w+Z6d39/2k2NvKA9xoXc4xmBze2YE8OD6HzXV3gN4Va9 8vDw== 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=oa97cXZFvKrCM3jeo6QEdrj3udb4p0ze6uH1S8/3A2k=; fh=Mm8hlFdBHUY0fyqKU/MWlqkizWEw7qYBWD0xRewgNf0=; b=tHQ0iuVmP4YIvOzdLZrD1+cIjc5kiLgwgejCHNVWfwJ96K0ONSw/jUab1gBuJZw/+x LJXDvgnU//IZSr0w6Ce6occh/uErkw8TFzVoUOD2XUhWqniaJvxf+QbG4/z3Dqw2GVbA XZ5yuhYt9rciEmXo4ljJ1bCEgaiN0ggSZZvBXwlLQntM/qhyOiEcUK9SdShZD9Z/Y+C2 L/zE0k/aGb9sgBxVe2mGeg2v01Su4t7b4PEyJk/tbLX4dhFyaXtLxn8X7f3vtFhSQWka OliM9evPUfNnNu+mfkeHw4zrpYN/DwDUbzDCT4wCg1IYZnpKAuP7PBMGd3W88NO6JcL1 VueQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kl.wtf header.s=key1 header.b=hoHRGL96; 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-155158-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kl.wtf Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o3-20020a63e343000000b005b8ebaa2937si9540354pgj.47.2024.04.23.05.27.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 05:27:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155158-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kl.wtf header.s=key1 header.b=hoHRGL96; 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-155158-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155158-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 95CC6283A23 for ; Tue, 23 Apr 2024 12:26:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BBF886252; Tue, 23 Apr 2024 12:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kl.wtf header.i=@kl.wtf header.b="hoHRGL96" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 C357284FC5 for ; Tue, 23 Apr 2024 12:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713875170; cv=none; b=O5M9zF+izjSLU2ONl+jHGB3H0O96oLQyLqjQl9Dn2vUMiI6vg3+o3tJIoKXsCzGq53Zv0prcmD1Bs005wpMVbnYj96OOIWp8B7Urv/oM250e2/PxLgyc6z7pCrORLxLM3bC/WYfvZh1mxlDdxTFp413oanb6Aicb6Kx5BJhYUuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713875170; c=relaxed/simple; bh=zynGQTuIFxXRQEi59otUwDM4ji/FKEmTQC80pJpa32Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bH4iG34TidAV9cRZvZF7/t1CJzQCiYq9aNicILkWMocLPX/Hgyo3FeofD9plhoaw1FZp+goAg+exdO1qXLiCsmOZ2PYuM+1A1SnyLh8Yk2xwHFrKtbs8kV3mZSpOdWEqD1ywskvbPgs3m9SonS3rBZm5JyxXZHBD2qF/udTNYVw= 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=hoHRGL96; arc=none smtp.client-ip=95.215.58.185 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=1713875167; 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=oa97cXZFvKrCM3jeo6QEdrj3udb4p0ze6uH1S8/3A2k=; b=hoHRGL96OWQJJq1pbBIWueMeA5VH/1BT0MNoXLQN/iPZumyGudECGU6rnxeC2Bh/gWSgR+ k84Uby8Y/K1JL/woO7RcPFmA7DDQbHZe8rb924rqWW6Kzz9CTQ7Ef6w4ebV4kuAF1Ju/Pw 8F8kF354s/C30TSvxKo6CthuXlBng0wAtF6ws89znzqZVtsbGsCBHs4UovFQzKi2Y+jC19 24egTTWSL665g8mUNcHkYe+JBsdCby6BFjBkiquremAoN2AahRfTVT6axfnZUIylaQNhZb nMb3NI8O+fCrCJ0z4u8H0Zoq0luqVQlBarD8gttxy+J3z76FswI3VCuYhgJNgg== 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 v2 2/3] HID: i2c-hid: Retry HID descriptor read to wake up STM devices Date: Tue, 23 Apr 2024 14:07:54 +0200 Message-ID: <20240423122518.34811-3-kl@kl.wtf> In-Reply-To: <20240423122518.34811-1-kl@kl.wtf> References: <20240423122518.34811-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 send to them timeout and fail with EREMOTEIO. Retry once on EREMOTEIO 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 Signed-off-by: Kenny Levinsen --- drivers/hid/i2c-hid/i2c-hid-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 515a80dbf6c7..252ccb3b71d1 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -1010,7 +1010,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 EREMOTEIO. Retry the command in this case. + */ ret = i2c_hid_fetch_hid_descriptor(ihid); + if (ret == -EREMOTEIO) { + usleep_range(400, 500); + ret = i2c_hid_fetch_hid_descriptor(ihid); + } + if (ret == -EREMOTEIO) { i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); return -ENXIO; -- 2.44.0