Bug 289353 - [ig4] touchpad broken on MateBook X Pro 2023 with 15.0-CURRENT
Summary: [ig4] touchpad broken on MateBook X Pro 2023 with 15.0-CURRENT
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Vladimir Kondratyev
URL:
Keywords: regression
Depends on:
Blocks: 15.0-metabug
  Show dependency tree / graph
 
Reported: 2025-09-07 12:30 UTC by huanghwh
Modified: 2025-10-12 03:04 UTC (History)
4 users (show)

See Also:


Attachments
dmesg_good (33.01 KB, text/plain)
2025-09-16 12:53 UTC, huanghwh
no flags Details
dmesg_bad (25.71 KB, text/plain)
2025-09-16 12:53 UTC, huanghwh
no flags Details
Outline patch (1.48 KB, patch)
2025-09-20 16:44 UTC, Poul-Henning Kamp
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description huanghwh 2025-09-07 12:30:06 UTC
I test 15/stable on MateBookPro 2023, touchpad is not work anymore, It is working on 14.3-RELEASE, dmesg show:

iichid0: <GXTP7863:00 27C6:01E0 I2C HID device> at addr 0x15 on iicbus14
iichid0: Using sampling mode
hidbus0: <HID bus> on iichid0
acpi_pwr_switch_consumer: new power state D3cold is not the one requested D0
iichid1: <GXTP738X:00 27C6:0114 I2C HID device> at addr 0x5d on iicbus15
iichid1: Using sampling mode
hidbus1: <HID bus> on iichid1
hmt0: <GXTP7863:00 27C6:01E0 TouchPad> on hidbus0
hconf0: <GXTP7863:00 27C6:01E0 Configuration> on hidbus0
hmt0: Multitouch touchpad with 2 external buttons, click-pad
hmt0: 5 contacts with [C] properties. Report range [0:0] - [3684:2338]
hmt1: <GXTP738X:00 27C6:0114 TouchScreen> on hidbus1
hmt1: Multitouch touchscreen with 0 external buttons
hmt1: 10 contacts with [] properties. Report range [0:0] - [6240:4160]
Security policy loaded: MAC/ntpd (mac_ntpd)
wlan0: link state changed to UP
ig4iic0: Failed to abort transfer. Do the controller reset.
ig4iic0: Failed to abort transfer. Do the controller reset.
ig4iic0: Failed to abort transfer. Do the controller reset.

and a lot of:

ig4iic0: Failed to abort transfer. Do the controller reset.

# uname -a
FreeBSD mbxp.jopens.cn 15.0-ALPHA1 FreeBSD 15.0-ALPHA1 #0 stable/15-n280099-0b3d82579a01-dirty: Sun Sep  7 19:28:24 CST 2025     root@mbxp.jopens.cn:/usr/obj/usr/src/amd64.amd64/sys/MBXP amd64
Comment 1 huanghwh 2025-09-13 16:59:32 UTC
The culprit is "iichid: Stop using split I²C bus transactions" by git bisect:

commit 36027361f9cfb76013153a032286eccda1512359 (HEAD)
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date:   Tue Jul 29 06:17:43 2025 +0000

    iichid: Stop using split I²C bus transactions

    Read IIC-HID reports as a single I²C transaction, instead of reading
    first the two byte length field, holding the bus, and then the rest
    of the report in a separate transaction.

    While technically legal, I²C bus split transactions are not universally
    supported, and in particular the "Snapdragon Elite" ARM CPU does
    not seem to support them.

    It is also not obvious that they are beneficial in this case, given
    the overhead of controller setup, interrupts and tear-down.

    Reviewed by: wulf
    Differential Revision: https://reviews.freebsd.org/D51302
Comment 2 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-15 13:16:33 UTC
Can you try to enable some of the debugging to see what it is actually trying to do at the I²C level ?

In particular look for reports from the touch-pad where the first two bytes indicate a longer length than we expect to receive.
Comment 3 huanghwh 2025-09-16 12:53:06 UTC
Created attachment 263848 [details]
dmesg_good
Comment 4 huanghwh 2025-09-16 12:53:37 UTC
Created attachment 263849 [details]
dmesg_bad
Comment 5 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-19 19:13:43 UTC
I notice the "Using sampling mode", do you happen to know why interrupts could not be set up ?

The only idea I have right now, is that because we are in polling mode, we are getting zero bytes back from the device which are not in fact indications that the RESET finished.

Normally we would get an interrupt, read the zero bytes and be good to go.

But in polling mode we may be reading before the interrupt happens and get zeros from the device as a surprised "you talkin' to me?" non-reply, which we then mistake for the RESET completed message.

You can probably test this theory by sticking a sensibly long delay before:

    /* Wait for RESET response */

and see if that changes things ?

If that theory holds, and by doing so we manage to wedge the device, ig4iic might be justified in not being able to get the bus back into whack, but it could also be that part of the ig4iic code needs to be looked at.  (That will be wulf's department.)
Comment 6 huanghwh 2025-09-20 14:56:18 UTC
(In reply to Poul-Henning Kamp from comment #5)
I test long delay 5 seconds, not work. but I try to modify rdesc->rdsize:
diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c
index fdb4816b8bd9..90990da8afb3 100644
--- a/sys/dev/iicbus/iichid.c
+++ b/sys/dev/iicbus/iichid.c
@@ -820,8 +820,7 @@ iichid_intr_setup(device_t dev, device_t child __unused, hid_intr_t intr,
         * may set it to a wrong length.  Also find the longest input report
         * in report descriptor, and add two for the length field.
         */
-       rdesc->rdsize = 2 +
-           MAX(rdesc->isize, le16toh(sc->desc.wMaxInputLength));
+       rdesc->rdsize = le16toh(sc->desc.wMaxInputLength);
        /* Write and get/set_report sizes are limited by I2C-HID protocol. */
        rdesc->grsize = rdesc->srsize = IICHID_SIZE_MAX;
        rdesc->wrsize = IICHID_SIZE_MAX;

this patch works, from my test:

touchpad:
rdesc->isize = 65
le16toh(sc->desc.wMaxInputLength) = 64
touchpad works if rdsize <= 64

for touchscreen:
rdesc->isize = 65
le16toh(sc->desc.wMaxInputLength) = 34

touchscreen can work even rdsize = 67
Comment 7 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-20 16:09:56 UTC
I would personally not have a problem with that patch, but I do not know why we also walk the descriptors to find individual report lengths, nor if we calculate them correctly.

Wulf@ knows the history better than I do, I just got rid of the split-i2c transactions. (although, the +2 is probably my mistake.)
Comment 8 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-20 16:44:23 UTC
Created attachment 263941 [details]
Outline patch

As mentioned, I am not qualified to say if rdesc->isize is calculated correctly, but if it is, this is the patch I would suggest.

But as far as I can tell, the isize=65 will still break things for you, so this is mostly for reference.
Comment 9 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 07:50:50 UTC
> although, the +2 is probably my mistake.

Just re-read specs. Correct formula is

rdesc->rdsize = MAX(rdesc->isize + 2, le16toh(sc->desc.wMaxInputLength));
Comment 10 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 07:56:26 UTC
> rdesc->rdsize = le16toh(sc->desc.wMaxInputLength);

This will broke some semi-HID devices like ietp(4) as they uses report descriptor overloading for input buffer sizing.

Seems that le16toh(sc->desc.wMaxInputLength) should be used for HID devices and rdesc->isize + 2 for semi-HID
Comment 11 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 08:39:58 UTC
I hope this helps

diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c
index fdb4816b8bd..05d8dcf365e 100644
--- a/sys/dev/iicbus/iichid.c
+++ b/sys/dev/iicbus/iichid.c
@@ -820,8 +820,8 @@ iichid_intr_setup(device_t dev, device_t child __unused, hid_intr_t intr,
 	 * may set it to a wrong length.  Also find the longest input report
 	 * in report descriptor, and add two for the length field.
 	 */
-	rdesc->rdsize = 2 +
-	    MAX(rdesc->isize, le16toh(sc->desc.wMaxInputLength));
+	rdesc->rdsize = rdesc->rdsize == 0 ?
+	    le16toh(sc->desc.wMaxInputLength) : rdesc->isize + 2;
 	/* Write and get/set_report sizes are limited by I2C-HID protocol. */
 	rdesc->grsize = rdesc->srsize = IICHID_SIZE_MAX;
 	rdesc->wrsize = IICHID_SIZE_MAX;
Comment 12 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-21 09:26:10 UTC
That works for the keyboard on my Snapdragon Thinkpad.  (Cannot test touchpad until there's a X for arm64:16)

With evidence that devices croak if we ask about too much data, I think we should truncate maxlen in iichid_read() appropriately ?
Comment 13 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 09:31:41 UTC
(In reply to Poul-Henning Kamp from comment #12)
As I see

maxlen == sc->intr_bufsize == rdesc->rdsize == le16toh(sc->desc.wMaxInputLength)
Comment 14 huanghwh 2025-09-21 09:36:41 UTC
This works for both touchpad and touch screen.
Comment 15 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-21 09:50:59 UTC
In iichid_read() maxlen is a passed in parameter, which is passed (+2) to iichid_cmd_read(). (see line 930-ish)

What I propose is that we trim it to be no larger than the "usual" maxlen.
Comment 16 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 10:00:52 UTC
(In reply to Poul-Henning Kamp from comment #15)

IMO we should trim actlen when we invoke interrupt handler
Comment 17 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 10:12:21 UTC
Both maxlen and actlen includes length header
Comment 18 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 10:22:04 UTC
Here is the patch:

diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c
index 6d95d6d2d4f..c0119358f3f 100644
--- a/sys/dev/iicbus/iichid.c
+++ b/sys/dev/iicbus/iichid.c
@@ -299,11 +299,11 @@ iichid_cmd_read(struct iichid_softc* sc, void *buf, iichid_size_t maxlen,
 		}
 	}
 
-	if (actlen <= 2 || actlen > maxlen) {
-		actlen = 0;
-	}
 	if (actual_len != NULL) {
-		*actual_len = actlen;
+		if (actlen <= 2 || actlen > maxlen)
+			*actual_len = 0;
+		else
+			*actual_len = actlen - 2;
 	}
 
 	return (error);
Comment 19 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 10:27:51 UTC
Ouch. You meant this?

diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c
index 6d95d6d2d4f..5bee2401f3a 100644
--- a/sys/dev/iicbus/iichid.c
+++ b/sys/dev/iicbus/iichid.c
@@ -278,7 +278,7 @@ iichid_cmd_read(struct iichid_softc* sc, void *buf, iichid_size_t maxlen,
 
 	memset(buf, 0xaa, 2);   // In case nothing gets read
 	struct iic_msg msgs[] = {
-	    { sc->addr, IIC_M_RD, maxlen, buf },
+	    { sc->addr, IIC_M_RD, maxlen + 2, buf },
 	};
 	int error;
 
@@ -299,11 +299,11 @@ iichid_cmd_read(struct iichid_softc* sc, void *buf, iichid_size_t maxlen,
 		}
 	}
 
-	if (actlen <= 2 || actlen > maxlen) {
-		actlen = 0;
-	}
 	if (actual_len != NULL) {
-		*actual_len = actlen;
+		if (actlen <= 2 || actlen > maxlen + 2)
+			*actual_len = 0;
+		else
+			*actual_len = actlen - 2;
 	}
 
 	return (error);
@@ -537,7 +537,7 @@ iichid_sampling_task(void *context, int pending)
 	if (!sc->power_on)
 		goto out;
 
-	error = iichid_cmd_read(sc, sc->intr_buf, sc->intr_bufsize, &actual);
+	error = iichid_cmd_read(sc, sc->intr_buf, sc->intr_bufsize - 2, &actual);
 	if (error == 0) {
 		if (actual > 0) {
 			sc->intr_handler(sc->intr_ctx, sc->intr_buf + 2, actual);
@@ -601,7 +601,7 @@ iichid_intr(void *context)
 	 * acknowledge interrupts we fetch only length header and discard it.
 	 */
 	THREAD_SLEEPING_OK();
-	error = iichid_cmd_read(sc, sc->intr_buf, sc->intr_bufsize, &actual);
+	error = iichid_cmd_read(sc, sc->intr_buf, sc->intr_bufsize - 2, &actual);
 	THREAD_NO_SLEEPING();
 	if (error == 0) {
 		if (sc->power_on && sc->open) {
Comment 20 Poul-Henning Kamp freebsd_committer freebsd_triage 2025-09-21 10:29:33 UTC
But that still does not solve the problem I'm talking about:

If the device croaks on IIC transactions longer than it has advertized, we should not attempt such transactions.

That means that we have to cut maxlen down *before* we call iicbus_transfer() in iichid_cmd_read().
Comment 21 Vladimir Kondratyev freebsd_committer freebsd_triage 2025-09-21 10:40:53 UTC
We can't cut maxlen down. It results in non-acknowledged interrupts on some devices.
Comment 22 commit-hook freebsd_committer freebsd_triage 2025-09-22 08:38:43 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f496952e3e6cdd531675a44b84b3f1954532afb

commit 8f496952e3e6cdd531675a44b84b3f1954532afb
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2025-09-22 08:37:19 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2025-09-22 08:37:19 +0000

    iichid(4): Always use wMaxInputLength bytes as input report length

    Lower values may result in non-acknowledged interrupts. E.g. ITE5570 device
    found in ASUS TUF. Greater values may result in read failures. E.g. GXTP7863
    device found on MateBookPro 2023.

    Investigated by:        huanghwh@gmail.com
    PR:             289353
    MFC after:      1 week
    fixes:          36027361f9cf ("iichid: Stop using split I²C bus transactions")

 sys/dev/iicbus/iichid.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Comment 23 commit-hook freebsd_committer freebsd_triage 2025-09-29 21:53:43 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c18032ba3172ec139056d71952b885b35f9fe107

commit c18032ba3172ec139056d71952b885b35f9fe107
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2025-09-22 08:37:19 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2025-09-29 21:50:43 +0000

    iichid(4): Always use wMaxInputLength bytes as input report length

    Lower values may result in non-acknowledged interrupts. E.g. ITE5570 device
    found in ASUS TUF. Greater values may result in read failures. E.g. GXTP7863
    device found on MateBookPro 2023.

    Investigated by:        huanghwh@gmail.com
    PR:             289353
    MFC after:      1 week
    fixes:          36027361f9cf ("iichid: Stop using split I²C bus transactions")

    (cherry picked from commit 8f496952e3e6cdd531675a44b84b3f1954532afb)

 sys/dev/iicbus/iichid.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)