From patchwork Tue Apr 23 12:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kenny Levinsen X-Patchwork-Id: 13639943 X-Patchwork-Delegate: jikos@jikos.cz Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 BC6F384FAC for ; Tue, 23 Apr 2024 12:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713875170; cv=none; b=uS4U5XTHpaszVfpg/DsZ3WcHc1KkQ8owNEzi1MJTLU0EqKO+eL7p/Mft+I4UEBABqeevA2cNPbnOUkYdgq7BoqWSx0ABXCoJU/LvSP2ZZavUgIpHQ6VnznBf6DebNcrQ7JVmD3AkMeFc5A/VteZL5oLgcZynfBP+EHH2TQ/EdVE= 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.188 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kl.wtf header.i=@kl.wtf header.b="hoHRGL96" 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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;