From: Hans de Goede <hdegoede@redhat.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
Douglas Anderson <dianders@chromium.org>,
Julian Sax <jsbc@gmx.de>,
ahormann@gmx.net, Bruno Jesus <bruno.fl.jesus@gmail.com>,
Dietrich <enaut.w@googlemail.com>,
kloxdami@yahoo.com, Tim Aldridge <taldridge@mac.com>,
Rene Wagner <redhatbugzilla@callerid.de>,
Federico Ricchiuto <fed.ricchiuto@gmail.com>,
linux-input@vger.kernel.org
Subject: [RFC v2 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor
Date: Mon, 20 Nov 2023 20:33:10 +0100 [thread overview]
Message-ID: <20231120193313.666912-5-hdegoede@redhat.com> (raw)
In-Reply-To: <20231120193313.666912-1-hdegoede@redhat.com>
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 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 | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 5e535480fed7..48582c75a51b 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -741,12 +741,9 @@ 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);
@@ -764,8 +761,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");
@@ -775,10 +772,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
next prev parent reply other threads:[~2023-11-20 19:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 19:33 [RFC v2 0/7] HID: i2c-hid: Rework wait for reset to match Windows Hans de Goede
2023-11-20 19:33 ` [RFC v2 1/7] HID: i2c-hid: Fold i2c_hid_execute_reset() into i2c_hid_hwreset() Hans de Goede
2023-11-20 22:05 ` Doug Anderson
2023-11-20 19:33 ` [RFC v2 2/7] HID: i2c-hid: Split i2c_hid_hwreset() in start() and finish() functions Hans de Goede
2023-11-20 22:05 ` Doug Anderson
2023-11-20 19:33 ` [RFC v2 3/7] HID: i2c-hid: Switch i2c_hid_parse() to goto style error handling Hans de Goede
2023-11-20 19:33 ` Hans de Goede [this message]
2023-11-20 22:07 ` [RFC v2 4/7] HID: i2c-hid: Move i2c_hid_finish_hwreset() to after reading the report-descriptor Doug Anderson
2023-11-21 9:52 ` Hans de Goede
2023-11-21 15:25 ` Doug Anderson
2023-11-21 16:05 ` Hans de Goede
2023-11-20 19:33 ` [RFC v2 5/7] HID: i2c-hid: Turn missing reset ack into a warning Hans de Goede
2023-11-20 22:07 ` Doug Anderson
2023-11-20 19:33 ` [RFC v2 6/7] HID: i2c-hid: Remove I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV quirk Hans de Goede
2023-11-20 19:33 ` [RFC v2 7/7] HID: i2c-hid: Renumber I2C_HID_QUIRK_ defines Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231120193313.666912-5-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=ahormann@gmx.net \
--cc=benjamin.tissoires@redhat.com \
--cc=bruno.fl.jesus@gmail.com \
--cc=dianders@chromium.org \
--cc=enaut.w@googlemail.com \
--cc=fed.ricchiuto@gmail.com \
--cc=jikos@kernel.org \
--cc=jsbc@gmx.de \
--cc=kloxdami@yahoo.com \
--cc=linux-input@vger.kernel.org \
--cc=redhatbugzilla@callerid.de \
--cc=taldridge@mac.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).