* [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows
@ 2023-12-02 22:46 Hans de Goede
2023-12-02 22:46 ` [PATCH v3 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset() Hans de Goede
` (7 more replies)
0 siblings, 8 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
Here is v3 of my i2c-hid series reworking how the i2c-hid-core waits
for reset to complete.
Further testing on the laptop for which I2C_HID_QUIRK_NO_IRQ_AFTER_RESET
was first introduced, shows that reading the report descriptor before
waiting for the reset helps with the missing reset IRQ, but it only helps
some of the time. About 50% of the time the reset still does not get
acked properly.
Still I believe that it would be good to move forward with
this series:
1. Reading descriptors before waiting for reset does make the reset ack IRQ
happen some of the time, so it does seem to improve things somewhat and
maybe it does fully fix the issue on some other models
2. This series should reduce the probe time of the i2c-hid driver
Changes in v3:
- Use "else if" to only wait for reset timeout when
the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk is not set
- Use goto abort_reset instead of return on i2c_hid_start_hwreset()
failure, so that the mutex gets properly unlocked
Changes in v2:
- Drop the patch dropping the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirks
- Add a patch changing a missing reset ack from an error into a warning
- Move the mutex_[un]lock(&ihid->reset_lock) calls out of
i2c_hid_start_hwreset() / i2c_hid_finish_hwreset() and into their
callers, as suggested by Douglas Anderson
Regards,
Hans
Hans de Goede (7):
HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset()
HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish()
functions
HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling
HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the
report-descriptor
HID: i2c-hid: Turn missing reset ack into a warning
HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk
HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines
drivers/hid/i2c-hid/i2c-hid-core.c | 137 +++++++++++++++--------------
1 file changed, 70 insertions(+), 67 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset()
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-02 22:46 ` [PATCH v3 2/7] HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish() functions Hans de Goede
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
i2c_hid_hwreset() is the only caller of i2c_hid_execute_reset(),
fold the latter into the former.
This is a preparation patch for removing the need for
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET by making i2c-hid behave
more like Windows.
No functional changes intended.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v3:
- Use "else if" to only wait for reset timeout when
the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk is not set
Changes in v2:
- Move the i2c_hid_dbg(... "%s: waiting...\n" ...) to above the
msleep(100) for the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk
---
drivers/hid/i2c-hid/i2c-hid-core.c | 79 +++++++++++++-----------------
1 file changed, 33 insertions(+), 46 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 2735cd585af0..ca2a4ccb9abf 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -426,49 +426,9 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
return ret;
}
-static int i2c_hid_execute_reset(struct i2c_hid *ihid)
-{
- size_t length = 0;
- int ret;
-
- i2c_hid_dbg(ihid, "resetting...\n");
-
- /* Prepare reset command. Command register goes first. */
- *(__le16 *)ihid->cmdbuf = ihid->hdesc.wCommandRegister;
- length += sizeof(__le16);
- /* Next is RESET command itself */
- length += i2c_hid_encode_command(ihid->cmdbuf + length,
- I2C_HID_OPCODE_RESET, 0, 0);
-
- set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
-
- ret = i2c_hid_xfer(ihid, ihid->cmdbuf, length, NULL, 0);
- if (ret) {
- dev_err(&ihid->client->dev, "failed to reset device.\n");
- goto out;
- }
-
- if (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET) {
- msleep(100);
- goto out;
- }
-
- i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
- if (!wait_event_timeout(ihid->wait,
- !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
- msecs_to_jiffies(5000))) {
- ret = -ENODATA;
- goto out;
- }
- i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
-
-out:
- clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
- return ret;
-}
-
static int i2c_hid_hwreset(struct i2c_hid *ihid)
{
+ size_t length = 0;
int ret;
i2c_hid_dbg(ihid, "%s\n", __func__);
@@ -482,21 +442,48 @@ static int i2c_hid_hwreset(struct i2c_hid *ihid)
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
if (ret)
- goto out_unlock;
+ goto err_unlock;
- ret = i2c_hid_execute_reset(ihid);
+ /* Prepare reset command. Command register goes first. */
+ *(__le16 *)ihid->cmdbuf = ihid->hdesc.wCommandRegister;
+ length += sizeof(__le16);
+ /* Next is RESET command itself */
+ length += i2c_hid_encode_command(ihid->cmdbuf + length,
+ I2C_HID_OPCODE_RESET, 0, 0);
+
+ set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+
+ ret = i2c_hid_xfer(ihid, ihid->cmdbuf, length, NULL, 0);
if (ret) {
dev_err(&ihid->client->dev,
"failed to reset device: %d\n", ret);
- i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
- goto out_unlock;
+ goto err_clear_reset;
}
+ i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
+
+ if (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET) {
+ msleep(100);
+ clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+ } else if (!wait_event_timeout(ihid->wait,
+ !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
+ msecs_to_jiffies(5000))) {
+ ret = -ENODATA;
+ goto err_clear_reset;
+ }
+ i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
+
/* At least some SIS devices need this after reset */
if (!(ihid->quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET))
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
-out_unlock:
+ mutex_unlock(&ihid->reset_lock);
+ return ret;
+
+err_clear_reset:
+ clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+ i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
+err_unlock:
mutex_unlock(&ihid->reset_lock);
return ret;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/7] HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish() functions
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
2023-12-02 22:46 ` [PATCH v3 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset() Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-02 22:46 ` [PATCH v3 3/7] HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling Hans de Goede
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
Split i2c_hid_hwreset() into:
i2c_hid_start_hwreset() which sends the PWR_ON and reset commands; and
i2c_hid_finish_hwreset() which actually waits for the reset to complete.
This is a preparation patch for removing the need for
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET by making i2c-hid behave
more like Windows.
No functional changes intended.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Move the mutex_[un]lock(&ihid->reset_lock) calls from
i2c_hid_start_hwreset() / i2c_hid_finish_hwreset() to the callers
to make the locking more clear
---
drivers/hid/i2c-hid/i2c-hid-core.c | 38 ++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index ca2a4ccb9abf..21d65ca32866 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -426,7 +426,7 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
return ret;
}
-static int i2c_hid_hwreset(struct i2c_hid *ihid)
+static int i2c_hid_start_hwreset(struct i2c_hid *ihid)
{
size_t length = 0;
int ret;
@@ -438,11 +438,11 @@ static int i2c_hid_hwreset(struct i2c_hid *ihid)
* being reset. Otherwise we may lose the reset complete
* interrupt.
*/
- mutex_lock(&ihid->reset_lock);
+ lockdep_assert_held(&ihid->reset_lock);
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
if (ret)
- goto err_unlock;
+ return ret;
/* Prepare reset command. Command register goes first. */
*(__le16 *)ihid->cmdbuf = ihid->hdesc.wCommandRegister;
@@ -460,6 +460,18 @@ static int i2c_hid_hwreset(struct i2c_hid *ihid)
goto err_clear_reset;
}
+ return 0;
+
+err_clear_reset:
+ clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+ i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
+ return ret;
+}
+
+static int i2c_hid_finish_hwreset(struct i2c_hid *ihid)
+{
+ int ret = 0;
+
i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
if (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET) {
@@ -477,14 +489,11 @@ static int i2c_hid_hwreset(struct i2c_hid *ihid)
if (!(ihid->quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET))
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
- mutex_unlock(&ihid->reset_lock);
return ret;
err_clear_reset:
clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
-err_unlock:
- mutex_unlock(&ihid->reset_lock);
return ret;
}
@@ -731,7 +740,11 @@ static int i2c_hid_parse(struct hid_device *hid)
}
do {
- ret = i2c_hid_hwreset(ihid);
+ mutex_lock(&ihid->reset_lock);
+ ret = i2c_hid_start_hwreset(ihid);
+ if (ret == 0)
+ ret = i2c_hid_finish_hwreset(ihid);
+ mutex_unlock(&ihid->reset_lock);
if (ret)
msleep(1000);
} while (tries-- > 0 && ret);
@@ -974,10 +987,15 @@ static int i2c_hid_core_resume(struct i2c_hid *ihid)
* However some ALPS touchpads generate IRQ storm without reset, so
* let's still reset them here.
*/
- if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME)
- ret = i2c_hid_hwreset(ihid);
- else
+ if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME) {
+ mutex_lock(&ihid->reset_lock);
+ ret = i2c_hid_start_hwreset(ihid);
+ if (ret == 0)
+ ret = i2c_hid_finish_hwreset(ihid);
+ mutex_unlock(&ihid->reset_lock);
+ } else {
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
+ }
if (ret)
return ret;
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 3/7] HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
2023-12-02 22:46 ` [PATCH v3 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset() Hans de Goede
2023-12-02 22:46 ` [PATCH v3 2/7] HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish() functions Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-02 22:46 ` [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor Hans de Goede
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
Switch i2c_hid_parse() to goto style error handling.
This is a preparation patch for removing the need for
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET by making i2c-hid behave
more like Windows.
Note this changes the descriptor read error path to propagate
the actual i2c_hid_read_register() error code (which is always
negative) instead of hardcoding a -EIO return.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/hid/i2c-hid/i2c-hid-core.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 21d65ca32866..71d742aeaf35 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -773,23 +773,21 @@ static int i2c_hid_parse(struct hid_device *hid)
rdesc, rsize);
if (ret) {
hid_err(hid, "reading report descriptor failed\n");
- kfree(rdesc);
- return -EIO;
+ goto out;
}
}
i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
ret = hid_parse_report(hid, rdesc, rsize);
+ if (ret)
+ dbg_hid("parsing report descriptor failed\n");
+
+out:
if (!use_override)
kfree(rdesc);
- if (ret) {
- dbg_hid("parsing report descriptor failed\n");
- return ret;
- }
-
- return 0;
+ return ret;
}
static int i2c_hid_start(struct hid_device *hid)
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
` (2 preceding siblings ...)
2023-12-02 22:46 ` [PATCH v3 3/7] HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-04 16:28 ` Doug Anderson
2023-12-02 22:46 ` [PATCH v3 5/7] HID: i2c-hid: Turn missing reset ack into a warning Hans de Goede
` (3 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
A recent bug made me look at Microsoft's i2c-hid docs again
and I noticed the following:
"""
4. Issue a RESET (Host Initiated Reset) to the Device.
5. Retrieve report descriptor from the device.
Note: Steps 4 and 5 may be done in parallel to optimize for time on I²C.
Since report descriptors are (a) static and (b) quite long, Windows 8 may
issue a request for 5 while it is waiting for a response from the device
on 4.
"""
Which made me think that maybe on some touchpads the reset ack is delayed
till after the report descriptor is read ?
Testing a T-BAO Tbook Air 12.5 with a 0911:5288 (SIPODEV SP1064?) touchpad,
for which the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk was first introduced,
shows that reading the report descriptor before waiting for the reset
helps with the missing reset IRQ. Now the reset does get acked properly,
but the ack sometimes still does not happen unfortunately.
Still moving the wait for ack to after reading the report-descriptor,
is probably a good idea, both to make i2c-hid's behavior closer to
Windows as well as to speed up probing i2c-hid devices.
While at it drop the dbg_hid() for a malloc failure, malloc failures
already get logged extensively by malloc itself.
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2247751
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v3:
- Use goto abort_reset instead of return on i2c_hid_start_hwreset()
failure, so that the mutex gets properly unlocked
Changes in v2:
- Adjust commit message to note that moving the wait-for-reset
to after reading thr report-descriptor only partially fixes
the missing reset IRQ problem
- Adjust for the reset_lock now being taken in the callers of
i2c_hid_start_hwreset() / i2c_hid_finish_hwreset()
---
drivers/hid/i2c-hid/i2c-hid-core.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 71d742aeaf35..400c15a180b5 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -725,11 +725,10 @@ static int i2c_hid_parse(struct hid_device *hid)
struct i2c_client *client = hid->driver_data;
struct i2c_hid *ihid = i2c_get_clientdata(client);
struct i2c_hid_desc *hdesc = &ihid->hdesc;
+ char *rdesc = NULL, *use_override = NULL;
unsigned int rsize;
- char *rdesc;
int ret;
int tries = 3;
- char *use_override;
i2c_hid_dbg(ihid, "entering %s\n", __func__);
@@ -739,18 +738,15 @@ static int i2c_hid_parse(struct hid_device *hid)
return -EINVAL;
}
+ mutex_lock(&ihid->reset_lock);
do {
- mutex_lock(&ihid->reset_lock);
ret = i2c_hid_start_hwreset(ihid);
- if (ret == 0)
- ret = i2c_hid_finish_hwreset(ihid);
- mutex_unlock(&ihid->reset_lock);
if (ret)
msleep(1000);
} while (tries-- > 0 && ret);
if (ret)
- return ret;
+ goto abort_reset;
use_override = i2c_hid_get_dmi_hid_report_desc_override(client->name,
&rsize);
@@ -762,8 +758,8 @@ static int i2c_hid_parse(struct hid_device *hid)
rdesc = kzalloc(rsize, GFP_KERNEL);
if (!rdesc) {
- dbg_hid("couldn't allocate rdesc memory\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto abort_reset;
}
i2c_hid_dbg(ihid, "asking HID report descriptor\n");
@@ -773,10 +769,23 @@ static int i2c_hid_parse(struct hid_device *hid)
rdesc, rsize);
if (ret) {
hid_err(hid, "reading report descriptor failed\n");
- goto out;
+ goto abort_reset;
}
}
+ /*
+ * Windows directly reads the report-descriptor after sending reset
+ * and then waits for resets completion afterwards. Some touchpads
+ * actually wait for the report-descriptor to be read before signalling
+ * reset completion.
+ */
+ ret = i2c_hid_finish_hwreset(ihid);
+abort_reset:
+ clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+ mutex_unlock(&ihid->reset_lock);
+ if (ret)
+ goto out;
+
i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
ret = hid_parse_report(hid, rdesc, rsize);
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 5/7] HID: i2c-hid: Turn missing reset ack into a warning
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
` (3 preceding siblings ...)
2023-12-02 22:46 ` [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-02 22:46 ` [PATCH v3 6/7] HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk Hans de Goede
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
On all i2c-hid devices seen sofar the reset-ack either works, or the hw is
somehow buggy and does not (always) ack the reset properly, yet it still
works fine.
Lower the very long reset timeout to 1 second which should be plenty
and change the reset not getting acked from an error into a warning.
This results in a bit cleaner code and avoids the need to add more
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirks in the future.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/hid/i2c-hid/i2c-hid-core.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 400c15a180b5..88a203e920de 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -479,9 +479,9 @@ static int i2c_hid_finish_hwreset(struct i2c_hid *ihid)
clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
} else if (!wait_event_timeout(ihid->wait,
!test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
- msecs_to_jiffies(5000))) {
- ret = -ENODATA;
- goto err_clear_reset;
+ msecs_to_jiffies(1000))) {
+ dev_warn(&ihid->client->dev, "device did not ack reset within 1000 ms\n");
+ clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
}
i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
@@ -490,11 +490,6 @@ static int i2c_hid_finish_hwreset(struct i2c_hid *ihid)
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
return ret;
-
-err_clear_reset:
- clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
- i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
- return ret;
}
static void i2c_hid_get_input(struct i2c_hid *ihid)
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 6/7] HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
` (4 preceding siblings ...)
2023-12-02 22:46 ` [PATCH v3 5/7] HID: i2c-hid: Turn missing reset ack into a warning Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-02 22:46 ` [PATCH v3 7/7] HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines Hans de Goede
2023-12-06 10:50 ` [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Jiri Kosina
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
Re-trying the power-on command on failure on all devices should
not be a problem, drop the I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk
and simply retry power-on on all devices.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/hid/i2c-hid/i2c-hid-core.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 88a203e920de..0c1a7cd84e4c 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -44,7 +44,6 @@
#include "i2c-hid.h"
/* quirks to control the device */
-#define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
#define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
#define I2C_HID_QUIRK_BOGUS_IRQ BIT(4)
#define I2C_HID_QUIRK_RESET_ON_RESUME BIT(5)
@@ -120,8 +119,6 @@ static const struct i2c_hid_quirks {
__u16 idProduct;
__u32 quirks;
} i2c_hid_quirks[] = {
- { USB_VENDOR_ID_WEIDA, HID_ANY_ID,
- I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
{ I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
{ I2C_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15,
@@ -395,8 +392,7 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
* The call will get a return value (EREMOTEIO) but device will be
* triggered and activated. After that, it goes like a normal device.
*/
- if (power_state == I2C_HID_PWR_ON &&
- ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
+ if (power_state == I2C_HID_PWR_ON) {
ret = i2c_hid_set_power_command(ihid, I2C_HID_PWR_ON);
/* Device was already activated */
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 7/7] HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
` (5 preceding siblings ...)
2023-12-02 22:46 ` [PATCH v3 6/7] HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk Hans de Goede
@ 2023-12-02 22:46 ` Hans de Goede
2023-12-06 10:50 ` [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Jiri Kosina
7 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-12-02 22:46 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: Hans de Goede, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
The quirks variable and the I2C_HID_QUIRK_ defines are never used /
exported outside of the i2c-hid code renumber them to start at
BIT(0) again.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/hid/i2c-hid/i2c-hid-core.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 0c1a7cd84e4c..90f316ae9819 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -44,11 +44,11 @@
#include "i2c-hid.h"
/* quirks to control the device */
-#define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
-#define I2C_HID_QUIRK_BOGUS_IRQ BIT(4)
-#define I2C_HID_QUIRK_RESET_ON_RESUME BIT(5)
-#define I2C_HID_QUIRK_BAD_INPUT_SIZE BIT(6)
-#define I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET BIT(7)
+#define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(0)
+#define I2C_HID_QUIRK_BOGUS_IRQ BIT(1)
+#define I2C_HID_QUIRK_RESET_ON_RESUME BIT(2)
+#define I2C_HID_QUIRK_BAD_INPUT_SIZE BIT(3)
+#define I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET BIT(4)
/* Command opcodes */
#define I2C_HID_OPCODE_RESET 0x01
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor
2023-12-02 22:46 ` [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor Hans de Goede
@ 2023-12-04 16:28 ` Doug Anderson
0 siblings, 0 replies; 10+ messages in thread
From: Doug Anderson @ 2023-12-04 16:28 UTC (permalink / raw)
To: Hans de Goede
Cc: Jiri Kosina, Benjamin Tissoires, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
Hi,
On Sat, Dec 2, 2023 at 2:46 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> A recent bug made me look at Microsoft's i2c-hid docs again
> and I noticed the following:
>
> """
> 4. Issue a RESET (Host Initiated Reset) to the Device.
> 5. Retrieve report descriptor from the device.
>
> Note: Steps 4 and 5 may be done in parallel to optimize for time on I²C.
> Since report descriptors are (a) static and (b) quite long, Windows 8 may
> issue a request for 5 while it is waiting for a response from the device
> on 4.
> """
>
> Which made me think that maybe on some touchpads the reset ack is delayed
> till after the report descriptor is read ?
>
> Testing a T-BAO Tbook Air 12.5 with a 0911:5288 (SIPODEV SP1064?) touchpad,
> for which the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk was first introduced,
> shows that reading the report descriptor before waiting for the reset
> helps with the missing reset IRQ. Now the reset does get acked properly,
> but the ack sometimes still does not happen unfortunately.
>
> Still moving the wait for ack to after reading the report-descriptor,
> is probably a good idea, both to make i2c-hid's behavior closer to
> Windows as well as to speed up probing i2c-hid devices.
>
> While at it drop the dbg_hid() for a malloc failure, malloc failures
> already get logged extensively by malloc itself.
>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2247751
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v3:
> - Use goto abort_reset instead of return on i2c_hid_start_hwreset()
> failure, so that the mutex gets properly unlocked
>
> Changes in v2:
> - Adjust commit message to note that moving the wait-for-reset
> to after reading thr report-descriptor only partially fixes
> the missing reset IRQ problem
> - Adjust for the reset_lock now being taken in the callers of
> i2c_hid_start_hwreset() / i2c_hid_finish_hwreset()
> ---
> drivers/hid/i2c-hid/i2c-hid-core.c | 29 +++++++++++++++++++----------
> 1 file changed, 19 insertions(+), 10 deletions(-)
Reviewed-by: Douglas Anderson <dianders@chromium.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
` (6 preceding siblings ...)
2023-12-02 22:46 ` [PATCH v3 7/7] HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines Hans de Goede
@ 2023-12-06 10:50 ` Jiri Kosina
7 siblings, 0 replies; 10+ messages in thread
From: Jiri Kosina @ 2023-12-06 10:50 UTC (permalink / raw)
To: Hans de Goede
Cc: Benjamin Tissoires, Douglas Anderson, Julian Sax, ahormann,
Bruno Jesus, Dietrich, kloxdami, Tim Aldridge, Rene Wagner,
Federico Ricchiuto, linux-input
On Sat, 2 Dec 2023, Hans de Goede wrote:
> Here is v3 of my i2c-hid series reworking how the i2c-hid-core waits
> for reset to complete.
I've agree that it's worth proceeding with this series even despite it not
fixing the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET completely for good.
Now in hid.git#for-6.8/i2c-hid.
Thanks,
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-12-06 10:50 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-02 22:46 [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
2023-12-02 22:46 ` [PATCH v3 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset() Hans de Goede
2023-12-02 22:46 ` [PATCH v3 2/7] HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish() functions Hans de Goede
2023-12-02 22:46 ` [PATCH v3 3/7] HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling Hans de Goede
2023-12-02 22:46 ` [PATCH v3 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor Hans de Goede
2023-12-04 16:28 ` Doug Anderson
2023-12-02 22:46 ` [PATCH v3 5/7] HID: i2c-hid: Turn missing reset ack into a warning Hans de Goede
2023-12-02 22:46 ` [PATCH v3 6/7] HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk Hans de Goede
2023-12-02 22:46 ` [PATCH v3 7/7] HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines Hans de Goede
2023-12-06 10:50 ` [PATCH v3 0/7] HID: i2c-hid: Rework wait for reset to match Windows Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).