From nobody Sun May 19 13:34:26 2024 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 68C1D3987D for ; Fri, 26 Apr 2024 22:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172279; cv=none; b=kVVqSzfSBrdpQi2tCOZCdiVl6L+sZCA716r6kFKBr5gTIXC3e6pDC+0rfTAmRf+djy0s1mhmig026ZpNrjlW4CW5K4jAEDZJH6kM2UKGSVhsFmViYTgSwwfM5Ud/fbl4qJwz90ah43UQ8Vv83Wg0enYjcnudxVcvus9Vupz9Q6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172279; c=relaxed/simple; bh=bmGxBMb81JYd9eJGESmHcK3CwPvy/AwmJGpMgmU9o2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OTJmkEydr7r37qQAjuv5xgv5KKreECVjV9K1ZqM/juZ198kdkBrrDzPmLFzfQU4CWXMXJfW8lsRBnhP6iI5Y02sXmiCeG6P8aHiNMYfuiWCMmAk1lNMaZ7ug4N9AV3E+17T2Ud2hPZTPOM47Z/OzISRmRvmDUZinkfl495Mn0V0= 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=RYZd9Zxo; arc=none smtp.client-ip=91.218.175.179 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="RYZd9Zxo" 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=1714172275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7SXRaVoQrN/XQKemgL4uLkkyAHkvGBUXAQSxAzF5ceM=; b=RYZd9ZxoUP/vsNRSnoVMy0oEicyeddd/AkpJaaufnVB6kHdY6p1HJu/+AViwPfVDSWe2OS qTys5Nsel+rb7n9QeVjXfPsCtOatVvY7aGzf3BpHs7wdBwDMgwihn9O7Gef4D7FgdVOqwr wqfwLbGQOjS5W2TRZLvvzUJaCS/Nm5kGcShoLULJV8ahkebSFZBClnPX6w+Tiu3iiotpVW k7V2N93qk6659A0WXxyOk/gqzdp8PRBjUfzEp3roOpfSN0vxxxYWcfVEbfm+/7HU0gbVcQ CZ1MRvJSbuLqNQvFyAjVcowytTBsFXoUhwaCH2s+LROJS8L08WRrwMTqa3VGzw== 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 1/3] HID: i2c-hid: Rely on HID descriptor fetch to probe Date: Sat, 27 Apr 2024 00:47:07 +0200 Message-ID: <20240426225739.2166-2-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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" To avoid error messages when a device is not present, b3a81b6c4fc6 added an initial bus probe using a dummy i2c_smbus_read_byte() call. Without this probe, i2c_hid_fetch_hid_descriptor() will fail internally on a bus error and log. Treat the bus error as a missing device and remove the error log so we can do away with the probe. Tested-by: Lukasz Majczak Reviewed-by: Lukasz Majczak Signed-off-by: Kenny Levinsen --- drivers/hid/i2c-hid/i2c-hid-core.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-h= id-core.c index d965382196c6..6ffa43d245b4 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -872,12 +872,11 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hi= d *ihid) ihid->wHIDDescRegister, &ihid->hdesc, sizeof(ihid->hdesc)); - if (error) { - dev_err(&ihid->client->dev, - "failed to fetch HID descriptor: %d\n", - error); - return -ENODEV; - } + + /* The i2c drivers are a bit inconsistent with their error + * codes, so treat everything as -ENXIO for now. */ + if (error) + return -ENXIO; } =20 /* Validate the length of HID descriptor, the 4 first bytes: @@ -992,17 +991,9 @@ static int __i2c_hid_core_probe(struct i2c_hid *ihid) struct hid_device *hid =3D ihid->hid; int ret; =20 - /* Make sure there is something at this address */ - ret =3D i2c_smbus_read_byte(client); - if (ret < 0) { - i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); - return -ENXIO; - } - ret =3D i2c_hid_fetch_hid_descriptor(ihid); if (ret < 0) { - dev_err(&client->dev, - "Failed to fetch the HID Descriptor\n"); + i2c_hid_dbg(ihid, "failed to fetch HID descriptor: %d\n", ret); return ret; } =20 --=20 2.44.0 From nobody Sun May 19 13:34:26 2024 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kl.wtf header.i=@kl.wtf header.b="PyMDwgGJ" 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: quoted-printable X-Migadu-Flow: FLOW_OUT Some STM microcontrollers need 400=C2=B5s 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-h= id-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 =3D ihid->hid; int ret; =20 + /* + * Some STM-based devices need 400=C2=B5s after a rising clock edge to wa= ke + * from deep sleep, which in turn means that our first command will + * fail on a bus error. Retry the command in this case. + */ ret =3D i2c_hid_fetch_hid_descriptor(ihid); - if (ret < 0) { + if (ret =3D=3D -ENXIO) { + usleep_range(400, 500); + ret =3D i2c_hid_fetch_hid_descriptor(ihid); + } + if (ret) { i2c_hid_dbg(ihid, "failed to fetch HID descriptor: %d\n", ret); return ret; } --=20 2.44.0 From nobody Sun May 19 13:34:26 2024 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.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 9556D3A1B0 for ; Fri, 26 Apr 2024 22:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172280; cv=none; b=h3qb9csYyPYc9C2Ud7hqPmI2plUu3APXod15/ZESD7ilSIoaADx0wuf31XcJEiqTZjB3Ud7TVlVmucF3q6sovKDl2VOt14RKlATQKnUXToNJhpW1yMn+8XgEIe9l0RNkOvfwcqphtrJIUupn+2i41J1f2nMorR3Vj7W2dA7FbYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714172280; c=relaxed/simple; bh=BXBOryCRmdGU3MpjZtj/f9m+SVkcFk68TeUd1IaFwL0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fp3aqUAqlak7wQOwBGHZHHagOja+qRoouFYei1bf0jh+ObwGD/1Xd6Fn4MGuOYpbDIZzQjmgnH7LNQfVuKhMQFx7nhCjmExomjVmpLpmBaYkMOmTAtzXFbwvI6QIDAsSpieBN1fjUPLhh731YPrJ3xhP0RDyooZxYjShaXYZPXU= 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=FzJjArNr; arc=none smtp.client-ip=91.218.175.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="FzJjArNr" 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=SqC2//5SbqmO7sl0eIyTlpelQ5K5dhBqbZvBw6LmbcE=; b=FzJjArNrn0fjQZ78lse7C+m9UIX+MxlPLZVwrQyH/p8SIbdpp0/6cXQ422lnrlWKnO9/jZ f0YIgQvTicvUvb/q9pPK4zsfb5/lqIHhOoVF2SkWz7MV0zuxtAsEUB3jLwINdu0BpjyCv3 mmsNj65FqDdirRB8dOutGxacL4tC1OWggiz9Ad1I04PKsDIgtNEO+oifxTZF5+rV/aLbWi BXQYI0Y7v02OAOHDHTlA0aFsRUEg1FkvWk/tENbaUPDUUofiRsYAXovaes7k32rPKJasQK WjKjNNipzuKHM7WvnNvB8P/G28YDRPPyT2fNuLZYSRjG7sIVUlbdHtVSycuM9A== 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 3/3] HID: i2c-hid: Align i2c_hid_set_power() retry with HID descriptor read Date: Sat, 27 Apr 2024 00:47:09 +0200 Message-ID: <20240426225739.2166-4-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: quoted-printable X-Migadu-Flow: FLOW_OUT The retry for HID descriptor and for power commands deals with the same device quirk, so align the two. Tested-by: Lukasz Majczak Reviewed-by: Lukasz Majczak Signed-off-by: Kenny Levinsen --- drivers/hid/i2c-hid/i2c-hid-core.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-h= id-core.c index 6ac1b11fb675..4ec12c083714 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -385,25 +385,21 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, in= t power_state) i2c_hid_dbg(ihid, "%s\n", __func__); =20 /* - * Some devices require to send a command to wakeup before power on. - * The call will get a return value (EREMOTEIO) but device will be - * triggered and activated. After that, it goes like a normal device. + * Some STM-based devices need 400=C2=B5s after a rising clock edge to wa= ke + * from deep sleep, which in turn means that our first command will + * fail on a bus error. Certain Weida Tech devices also need this + * wake-up. Retry the command in this case. */ - if (power_state =3D=3D I2C_HID_PWR_ON) { + ret =3D i2c_hid_set_power_command(ihid, power_state); + if (ret && power_state =3D=3D I2C_HID_PWR_ON) { + usleep_range(400, 500); ret =3D i2c_hid_set_power_command(ihid, I2C_HID_PWR_ON); - - /* Device was already activated */ - if (!ret) - goto set_pwr_exit; } =20 - ret =3D i2c_hid_set_power_command(ihid, power_state); if (ret) dev_err(&ihid->client->dev, "failed to change power setting.\n"); =20 -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. --=20 2.44.0