From e79d051867c103d3a1e9458869beafed63004983 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Tue, 20 Oct 2026 16:13:55 -0300 Subject: [PATCH 1/8] dt-bindings: input: apple,dockchannel-hid: Add apple,afe-smc On the J616s the trackpad analog front end is not powered through an SMC GPIO but through the SMC key gp1c, which the host drives around the multi-touch interface reset. Add apple,afe-smc, a link to the SMC that owns the key, for the boards that need it. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- .../bindings/input/apple,dockchannel-hid.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml b/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml index 0be283d25641f..07a0b8d1173ce 100644 --- a/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml +++ b/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml @@ -92,6 +92,14 @@ properties: description: Reset line of the STM interface, pulsed on the coprocessor's request. + apple,afe-smc: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The SMC whose gp1c key powers the trackpad analog front end. With it + the host drives the key low to power the multi-touch interface on + and high to power it off, between the coprocessor's power transition + notifications. + apple,no-stm: type: boolean description: @@ -198,6 +206,15 @@ required: additionalProperties: false allOf: + - if: + properties: + compatible: + not: + contains: + const: apple,t6041-dockchannel-hid + then: + properties: + apple,afe-smc: false - if: properties: multi-touch: From d8b19e08abaecb8e9401981aba9cef764147ce6c Mon Sep 17 00:00:00 2001 From: Josh Rodd Date: Mon, 21 Sep 2026 07:42:37 -0400 Subject: [PATCH 2/8] HID: dockchannel: receive ring for the M4 MTP firmware The M4 MTP firmware (T8132) delivers reports through a host-allocated 2 MiB DMA ring registered with command 0x91, and announces new data with notify frames on the FIFO. Allocate and register the ring, drain complete frames from it, dispatch FIFO and ring frames through one path, and use the observed T8132 interface reset sequence. Firmware without the ring keeps the FIFO-only path. Josh Rodd's "Add MacBook Air M4 MTP (keyboard, trackpad) support" (GravityLinux, merged as PR #1), as trimmed back to the minimal change over the existing driver by Niklas Sheth's review series (a48a449524c4, d93489134413, ba7b4a7e394d, 2d1c2b55e0fe, 313226188dd1, bd7b318d7b28), merged onto this tree's driver (its PM1 command helper, checksum helper, stop check and wakeup setup kept). Link: https://github.com/GravityLinux/linux/commit/3f56fba5e1c3 Link: https://github.com/GravityLinux/linux/compare/3f56fba5e1c3...0c724f06f5bf Signed-off-by: Josh Rodd Assisted-by: oh-my-pi:gpt-6-astra [jgoyvaerts: trimmed per Niklas Sheth's review series and merged onto this tree's driver, as described above] Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- drivers/hid/dockchannel-hid/dockchannel-hid.c | 268 ++++++++++++++---- 1 file changed, 215 insertions(+), 53 deletions(-) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index a0af190a9b50a..ffabc7bde55f8 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -12,8 +12,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -27,9 +29,12 @@ #define MAX_INTERFACES 16 -/* Data + checksum */ -#define MAX_PKT_SIZE (0xffff + 4) +/* Complete frame, including the largest aligned body and its checksum. */ +#define MAX_PKT_SIZE (8 + 0xfffc + 4) +#define DCHID_RING_SIZE SZ_2M +#define DCHID_RING_HEADER_SIZE 8 +#define DCHID_CHANNEL_NOTIFY 0x00 #define DCHID_CHANNEL_CMD 0x11 #define DCHID_CHANNEL_REPORT 0x12 @@ -76,6 +81,8 @@ struct dchid_init_hdr { #define INIT_TERMINATOR 2 #define INIT_PRODUCT_NAME 7 +#define CMD_RESET_INTERFACE 0x40 +#define CMD_REGISTER_RING 0x91 #define CMD_SEND_FIRMWARE 0x95 #define CMD_ENABLE_INTERFACE 0xb4 #define CMD_ACK_GPIO_CMD 0xa1 @@ -191,6 +198,13 @@ struct dockchannel_hid { /* Held from probe on when the multi-touch interface uses power method 2 */ struct gpio_desc *afe_reset; + struct mutex ring_mutex; + bool use_ring; + bool ring_registered; + int ring_error; + void *ring; + dma_addr_t ring_dma; + u32 ring_read; bool id_ready; struct dchid_stm_id device_id; char serial[64]; @@ -430,9 +444,61 @@ static int dchid_enable_interface(struct dchid_iface *iface) static int dchid_reset_interface(struct dchid_iface *iface, int state) { u8 msg[DCHID_PM1_CMD_SIZE]; + u8 msg2[] = { CMD_RESET_INTERFACE, 2, iface->index, state, 0, 0, 0, 0, 0 }; + int ret; - dchid_pm1_command(iface->index, state, msg); - return dchid_comm_cmd(iface->dchid, msg, sizeof(msg)); + if (!iface->dchid->use_ring) { + dchid_pm1_command(iface->index, state, msg); + return dchid_comm_cmd(iface->dchid, msg, sizeof(msg)); + } + + /* + * T8132 boot capture: state 0 then 2, each with byte 4 equal to 0 + * then 1. This is only the observed provisioning sequence, not a + * contract for suspend, wake, or arbitrary interface power changes. + */ + ret = dchid_comm_cmd(iface->dchid, msg2, sizeof(msg2)); + if (ret < 0) + return ret; + msg2[4] = 1; + return dchid_comm_cmd(iface->dchid, msg2, sizeof(msg2)); +} + +static int dchid_register_ring(struct dockchannel_hid *dchid) +{ + struct { + u8 cmd; + u8 reserved[2]; + u64 addr; + u32 size; + } __packed msg = { + .cmd = CMD_REGISTER_RING, + .addr = dchid->ring_dma, + .size = DCHID_RING_SIZE, + }; + /* Observed in both macOS and standalone T8132 bringup before 0x91. */ + u8 prepare[] = { 0xc1, 0x02 }; + int ret = 0; + + if (!dchid->use_ring) + return 0; + + mutex_lock(&dchid->ring_mutex); + ret = dchid->ring_error; + if (!dchid->ring_registered) { + ret = dchid_comm_cmd(dchid, prepare, sizeof(prepare)); + if (ret < 0) { + mutex_unlock(&dchid->ring_mutex); + return ret; + } + /* The registration ACK itself arrives through the ring. */ + dma_wmb(); + WRITE_ONCE(dchid->ring_registered, true); + ret = dchid_comm_cmd(dchid, &msg, sizeof(msg)); + dchid->ring_error = ret; + } + mutex_unlock(&dchid->ring_mutex); + return ret; } /* @@ -562,6 +628,11 @@ static int dchid_request_gpio(struct dchid_iface *iface) if (iface->firmware_managed_reset) return -EINVAL; + if (iface->dchid->use_ring) { + dev_err_once(iface->dchid->dev, "T8132 SMC reset GPIO operation is not established\n"); + return -EOPNOTSUPP; + } + if (iface->gpio) return 0; @@ -604,14 +675,17 @@ static int dchid_start_interface(struct dchid_iface *iface) dev_dbg(iface->dchid->dev, "Starting interface %s\n", iface->name); iface->starting = true; + ret = dchid_register_ring(iface->dchid); + if (ret < 0) + goto err; /* Look to see if we need firmware */ ret = dchid_get_firmware(iface, &fw, &size); if (ret < 0) goto err; - /* If we need a GPIO, make sure we have it. */ - if (iface->gpio_announced) { + /* T8132 startup does not use the older host GPIO reset. */ + if (!iface->dchid->use_ring && iface->gpio_announced) { ret = dchid_request_gpio(iface); if (ret < 0) goto err; @@ -1002,7 +1076,7 @@ static void dchid_handle_init(struct dockchannel_hid *dchid, void *data, size_t break; } - if (hdr->more_packets) + if (hdr->more_packets || (dchid->use_ring && !iface->hid_desc)) return; /* We need to enable STM first, since it'll give us the device IDs */ @@ -1205,13 +1279,129 @@ static void dchid_handle_ack(struct dchid_iface *iface, struct dchid_hdr *hdr, v complete(&iface->out_complete); } +/* Return the complete frame size, or reject a lost framing boundary. */ +static int dchid_frame_size(const struct dchid_hdr *hdr) +{ + size_t length = hdr->length; + + if (hdr->hdr_len != sizeof(*hdr) || !IS_ALIGNED(length, 4)) + return -EPROTO; + return sizeof(*hdr) + length + sizeof(u32); +} + +/* + * Both receive transports pass complete frames here. Header bytes 6/7 and + * application padding are opaque, checksum-covered data, not required zeroes. + */ +static int dchid_dispatch(struct dockchannel_hid *dchid, struct dchid_hdr *hdr, + void *data, bool fifo) +{ + struct dchid_iface *iface; + struct dchid_work *work; + u32 checksum; + + if (!dchid_verify_checksum(hdr, data, &checksum)) { + dev_err(dchid->dev, "Checksum mismatch (iface %d): 0x%08x != 0xffffffff\n", + hdr->iface, checksum); + return 0; + } + + if (dchid->use_ring && hdr->channel == DCHID_CHANNEL_NOTIFY) { + /* A FIFO notification has no application subheader or report ID. */ + return fifo && !hdr->length && hdr->iface == IFACE_COMM; + } + + if (hdr->iface >= MAX_INTERFACES || hdr->length < sizeof(struct dchid_subhdr)) + return 0; + iface = dchid->ifaces[hdr->iface]; + if (!iface) { + dev_err(dchid->dev, "Received packet for uninitialized iface %d\n", hdr->iface); + return 0; + } + + switch (hdr->channel) { + case DCHID_CHANNEL_CMD: + dchid_handle_ack(iface, hdr, data); + return 0; + case DCHID_CHANNEL_REPORT: + break; + default: + dev_warn(dchid->dev, "Unknown channel 0x%x, treating as report...\n", + hdr->channel); + break; + } + + work = kzalloc(sizeof(*work) + hdr->length, GFP_KERNEL); + if (!work) + return 0; + work->hdr = *hdr; + work->iface = iface; + memcpy(work->data, data, hdr->length); + INIT_WORK(&work->work, dchid_packet_work); + queue_work(iface->wq, &work->work); + return 0; +} + +static void dchid_ring_copy(struct dockchannel_hid *dchid, void *dst, + u32 offset, size_t length) +{ + size_t first = min_t(size_t, length, + DCHID_RING_SIZE - DCHID_RING_HEADER_SIZE - offset); + void *data = dchid->ring + DCHID_RING_HEADER_SIZE; + + memcpy(dst, data + offset, first); + memcpy(dst + first, data, length - first); +} + +static int dchid_drain_ring(struct dockchannel_hid *dchid) +{ + const u32 capacity = DCHID_RING_SIZE - DCHID_RING_HEADER_SIZE; + u32 *indices = dchid->ring; + u32 producer, consumer, available; + int size; + + if (!READ_ONCE(dchid->ring_registered)) + return -EPROTO; + + while (1) { + producer = READ_ONCE(indices[0]); + consumer = READ_ONCE(indices[1]); + if (producer >= capacity || consumer != dchid->ring_read || + !IS_ALIGNED(producer, 4)) + return -EPROTO; + /* Read only the bytes published by this producer snapshot. */ + dma_rmb(); + available = producer >= consumer ? producer - consumer : + capacity - consumer + producer; + if (available < sizeof(struct dchid_hdr)) + return 0; + dchid_ring_copy(dchid, dchid->pkt_buf, consumer, + sizeof(struct dchid_hdr)); + size = dchid_frame_size((void *)dchid->pkt_buf); + if (size < 0) + return size; + if (available < size) + return 0; + dchid_ring_copy(dchid, dchid->pkt_buf, consumer, size); + dchid_dispatch(dchid, (void *)dchid->pkt_buf, + dchid->pkt_buf + sizeof(struct dchid_hdr), false); + consumer += size; + if (consumer >= capacity) + consumer -= capacity; + dchid->ring_read = consumer; + /* All frame reads must complete before the producer can reuse it. */ + mb(); + WRITE_ONCE(indices[1], consumer); + cond_resched(); + } + return 0; +} + static void dchid_handle_packet(void *cookie, size_t avail) { struct dockchannel_hid *dchid = cookie; struct dchid_hdr hdr; - struct dchid_work *work; - struct dchid_iface *iface; - u32 checksum; + int ret; if (READ_ONCE(dchid->stopping)) return; @@ -1220,59 +1410,21 @@ static void dchid_handle_packet(void *cookie, size_t avail) dev_err(dchid->dev, "Read failed (header)\n"); return; } - if (hdr.hdr_len != sizeof(hdr)) { dev_err(dchid->dev, "Bad header length %d\n", hdr.hdr_len); goto done; } - - if (dockchannel_recv(dchid->dc, dchid->pkt_buf, hdr.length + 4) != (hdr.length + 4)) { + if (dockchannel_recv(dchid->dc, dchid->pkt_buf, hdr.length + 4) != hdr.length + 4) { dev_err(dchid->dev, "Read failed (body)\n"); goto done; } - if (!dchid_verify_checksum(&hdr, dchid->pkt_buf, &checksum)) { - dev_err(dchid->dev, "Checksum mismatch (iface %d): 0x%08x != 0xffffffff\n", - hdr.iface, checksum); - goto done; - } - - - if (hdr.iface >= MAX_INTERFACES) { - dev_err(dchid->dev, "Bad iface %d\n", hdr.iface); - goto done; - } - - iface = dchid->ifaces[hdr.iface]; - - if (!iface) { - dev_err(dchid->dev, "Received packet for uninitialized iface %d\n", hdr.iface); - goto done; - } - - switch (hdr.channel) { - case DCHID_CHANNEL_CMD: - dchid_handle_ack(iface, &hdr, dchid->pkt_buf); - goto done; - case DCHID_CHANNEL_REPORT: - break; - default: - dev_warn(dchid->dev, "Unknown channel 0x%x, treating as report...\n", - hdr.channel); - break; + if (dchid_dispatch(dchid, &hdr, dchid->pkt_buf, true)) { + ret = dchid_drain_ring(dchid); + if (ret < 0) + dev_err(dchid->dev, "Receive ring failed: %d\n", ret); } - work = kzalloc(sizeof(*work) + hdr.length, GFP_KERNEL); - if (!work) - goto done; - - work->hdr = hdr; - work->iface = iface; - memcpy(work->data, dchid->pkt_buf, hdr.length); - INIT_WORK(&work->work, dchid_packet_work); - - queue_work(iface->wq, &work->work); - done: if (!READ_ONCE(dchid->stopping)) dockchannel_await(dchid->dc, dchid_handle_packet, dchid, @@ -1302,6 +1454,8 @@ static int dockchannel_hid_probe(struct platform_device *pdev) stm = device_get_named_child_node(dev, "stm"); dchid->id_ready = !stm || !fwnode_device_is_available(stm); fwnode_handle_put(stm); + mutex_init(&dchid->ring_mutex); + dchid->use_ring = of_device_is_compatible(dev->of_node, "apple,t8132-dockchannel-hid"); /* * The STM interface reports the machine's vendor and product IDs, @@ -1417,6 +1571,13 @@ static int dockchannel_hid_probe(struct platform_device *pdev) if (ret) dev_warn(dev, "Failed to set up wakeup: %d\n", ret); + if (dchid->use_ring) { + dchid->ring = dmam_alloc_coherent(dev, DCHID_RING_SIZE, &dchid->ring_dma, + GFP_KERNEL); + if (!dchid->ring) + return -ENOMEM; + memset(dchid->ring, 0, DCHID_RING_SIZE); + } dchid->new_iface_wq = alloc_ordered_workqueue("dchid-new", 0); if (!dchid->new_iface_wq) return -ENOMEM; @@ -1466,6 +1627,7 @@ static void dockchannel_hid_remove(struct platform_device *pdev) } static const struct of_device_id dockchannel_hid_of_match[] = { + { .compatible = "apple,t8132-dockchannel-hid" }, { .compatible = "apple,dockchannel-hid" }, {}, }; From 94a3109ac3616a89bae79c28592c91fee0288725 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Wed, 14 Oct 2026 19:05:55 +0000 Subject: [PATCH 3/8] HID: dockchannel: support the J616s MTP and its trackpad power sequence The MTP of the MacBook Pro 16-inch (M4 Pro, J616s) runs the same firmware transport as T8132, so the apple,t6041-dockchannel-hid compatible selects the receive ring. It is the only compatible that does: apple,t8132-dockchannel-hid is not in the binding and no device tree uses it, while the M4 Air's MTP is adopted from the boot loader on a path the ring setup has never run on, so that compatible goes. The ring's power messages are built with dchid_pm2_command(), the same bytes, instead of a second copy of the command, and the dma_alloc_coherent() ring is not cleared again. On the J616s the trackpad analog front end needs a power sequence around the interface reset: SMC key gp1c high followed by 50 ms when turning it off, low when turning it on, issued between the WillChange and HasChanged messages. It is used on boards whose device tree links the SMC with apple,afe-smc, and is checked against the controller compatible and the key's size and access before anything is written. The reset runs once per boot; if the power-off fails, the power-on is not sent, so a failed sequence leaves the trackpad off instead of repeating a step on an unknown state. The driver needs macsmc for this, so it may not be built in while macsmc is a module. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- drivers/hid/dockchannel-hid/Kconfig | 1 + drivers/hid/dockchannel-hid/dockchannel-hid.c | 97 +++++++++++++++++-- 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/drivers/hid/dockchannel-hid/Kconfig b/drivers/hid/dockchannel-hid/Kconfig index 593cbeb58416a..53ddaaac9057e 100644 --- a/drivers/hid/dockchannel-hid/Kconfig +++ b/drivers/hid/dockchannel-hid/Kconfig @@ -5,6 +5,7 @@ menu "DockChannel HID support" config HID_DOCKCHANNEL tristate "HID over DockChannel transport layer for Apple Silicon SoCs" depends on APPLE_DOCKCHANNEL && APPLE_RTKIT_HELPER && INPUT && OF && HID + depends on MFD_MACSMC || !MFD_MACSMC help Say Y here if you use an M2 or later Apple Silicon based laptop. The keyboard and touchpad are HID based devices connected via the diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index ffabc7bde55f8..03b9d2f7a268b 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -81,7 +82,6 @@ struct dchid_init_hdr { #define INIT_TERMINATOR 2 #define INIT_PRODUCT_NAME 7 -#define CMD_RESET_INTERFACE 0x40 #define CMD_REGISTER_RING 0x91 #define CMD_SEND_FIRMWARE 0x95 #define CMD_ENABLE_INTERFACE 0xb4 @@ -192,6 +192,7 @@ struct dockchannel_hid { struct device *dev; struct dockchannel *dc; struct device_link *helper_link; + struct apple_smc *afe_smc; bool stopping; bool inherited_mtp; @@ -444,7 +445,8 @@ static int dchid_enable_interface(struct dchid_iface *iface) static int dchid_reset_interface(struct dchid_iface *iface, int state) { u8 msg[DCHID_PM1_CMD_SIZE]; - u8 msg2[] = { CMD_RESET_INTERFACE, 2, iface->index, state, 0, 0, 0, 0, 0 }; + u8 msg2[DCHID_PM2_CMD_SIZE]; + bool afe = iface->dchid->afe_smc && iface->index == 1; int ret; if (!iface->dchid->use_ring) { @@ -457,10 +459,33 @@ static int dchid_reset_interface(struct dchid_iface *iface, int state) * then 1. This is only the observed provisioning sequence, not a * contract for suspend, wake, or arbitrary interface power changes. */ + dchid_pm2_command(iface->index, state, false, msg2); ret = dchid_comm_cmd(iface->dchid, msg2, sizeof(msg2)); if (ret < 0) return ret; - msg2[4] = 1; + +#if IS_REACHABLE(CONFIG_MFD_MACSMC) + if (afe) { + /* + * J616s macOS power sequence: gp1c high + 50 ms when turning + * off, low with no added delay when turning on. These are + * pKW4 function payloads, not gpio-macsmc CMD_OUTPUT values. + * The host operation sits between WillChange and HasChanged. + */ + __le32 value = cpu_to_le32(0x00010000 | (state == 0)); + + ret = apple_smc_write(iface->dchid->afe_smc, SMC_KEY(gp1c), + &value, sizeof(value)); + if (ret < 0) { + dev_err(iface->dchid->dev, + "AFE power sequence failed: %d; reboot required\n", ret); + return ret; + } + if (state == 0) + msleep(50); + } +#endif + dchid_pm2_command(iface->index, state, true, msg2); return dchid_comm_cmd(iface->dchid, msg2, sizeof(msg2)); } @@ -727,8 +752,10 @@ static int dchid_start_interface(struct dchid_iface *iface) if (ret < 0) goto err; } else { - dchid_reset_interface(iface, DCHID_POWER_STATE_OFF); - dchid_reset_interface(iface, DCHID_POWER_STATE_ON); + ret = dchid_reset_interface(iface, DCHID_POWER_STATE_OFF); + /* After a failed AFE power-off the trackpad stays off: no retry. */ + if (ret >= 0 || !iface->dchid->afe_smc || iface->index != 1) + dchid_reset_interface(iface, DCHID_POWER_STATE_ON); } } @@ -1431,6 +1458,57 @@ static void dchid_handle_packet(void *cookie, size_t avail) sizeof(struct dchid_hdr)); } +/* AFE power through SMC key gp1c, for boards whose device tree links the SMC. */ +static int dchid_bind_afe_smc(struct dockchannel_hid *dchid) +{ + struct device *dev = dchid->dev; +#if IS_REACHABLE(CONFIG_MFD_MACSMC) + struct device_node *node; + struct platform_device *pdev; + struct device_link *link; + struct apple_smc_key_info info; + int ret; +#endif + + if (!of_find_property(dev->of_node, "apple,afe-smc", NULL)) + return 0; + if (!of_device_is_compatible(dev->of_node, "apple,t6041-dockchannel-hid")) + return -EINVAL; +#if !IS_REACHABLE(CONFIG_MFD_MACSMC) + return -EOPNOTSUPP; +#else + node = of_parse_phandle(dev->of_node, "apple,afe-smc", 0); + if (!node) + return -EINVAL; + /* What macsmc binds to: its driver data is read as an apple_smc below */ + if (!of_device_is_compatible(node, "apple,t8103-smc") && + !of_device_is_compatible(node, "apple,smc")) { + of_node_put(node); + return -EINVAL; + } + pdev = of_find_device_by_node(node); + of_node_put(node); + if (!pdev) + return -EPROBE_DEFER; + link = device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER); + put_device(&pdev->dev); + if (!link) + return -EINVAL; + if (link->supplier->links.status != DL_DEV_DRIVER_BOUND) + return -EPROBE_DEFER; + dchid->afe_smc = dev_get_drvdata(link->supplier); + if (!dchid->afe_smc) + return -EPROBE_DEFER; + ret = apple_smc_get_key_info(dchid->afe_smc, SMC_KEY(gp1c), &info); + if (ret < 0) + return ret; + if (info.size != 4 || !(info.flags & APPLE_SMC_WRITABLE)) + return -EINVAL; + dev_info(dev, "AFE power sequence via SMC gp1c\n"); + return 0; +#endif +} + static int dockchannel_hid_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1455,7 +1533,12 @@ static int dockchannel_hid_probe(struct platform_device *pdev) dchid->id_ready = !stm || !fwnode_device_is_available(stm); fwnode_handle_put(stm); mutex_init(&dchid->ring_mutex); - dchid->use_ring = of_device_is_compatible(dev->of_node, "apple,t8132-dockchannel-hid"); + /* The M4 Pro (J616s) MTP uses the same 26.6.2 firmware transport as T8132. */ + dchid->use_ring = of_device_is_compatible(dev->of_node, "apple,t6041-dockchannel-hid"); + + ret = dchid_bind_afe_smc(dchid); + if (ret) + return dev_err_probe(dev, ret, "AFE power sequence preflight failed\n"); /* * The STM interface reports the machine's vendor and product IDs, @@ -1576,7 +1659,6 @@ static int dockchannel_hid_probe(struct platform_device *pdev) GFP_KERNEL); if (!dchid->ring) return -ENOMEM; - memset(dchid->ring, 0, DCHID_RING_SIZE); } dchid->new_iface_wq = alloc_ordered_workqueue("dchid-new", 0); if (!dchid->new_iface_wq) @@ -1627,7 +1709,6 @@ static void dockchannel_hid_remove(struct platform_device *pdev) } static const struct of_device_id dockchannel_hid_of_match[] = { - { .compatible = "apple,t8132-dockchannel-hid" }, { .compatible = "apple,dockchannel-hid" }, {}, }; From 7a1f8d1322a5bb4499e1aa528f657d94559b6add Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 23 Oct 2026 13:43:53 -0300 Subject: [PATCH 4/8] arm64: dts: apple: t6040-j616s: Link the MTP to the SMC The J616s trackpad analog front end is powered through SMC key gp1c around the multi-touch interface reset. Point the MTP at the SMC with apple,afe-smc so the driver runs that sequence. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index d24ff77472e6c..a683e8da10c78 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -288,6 +288,9 @@ }; &mtp_hid { + /* SMC key gp1c powers the trackpad analog front end. */ + apple,afe-smc = <&smc>; + multi-touch { firmware-name = "apple/tpmtfw-j616s.bin"; }; From bd9d71a4244144c45c64b3733023b427a57330cb Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Tue, 20 Oct 2026 17:24:01 -0300 Subject: [PATCH 5/8] HID: dockchannel: ignore ring notifications before registration The MTP firmware can send a FIFO ring notification while the first interface start is still between the 0xc1 prepare command and dchid_register_ring() marking the ring registered. The ring address has not been sent at that point, so the firmware cannot have written to the ring, and the notification carries no payload. The drain treated this as a protocol error and logged "Receive ring failed: -71" on about half of the J616s boots, always during startup, while the keyboard and trackpad worked normally afterwards. Return 0 for this state, as the earlier ring implementation did. Frames published after registration come with their own notification, and the drain re-reads both ring indices each time, so nothing is lost. Fixes: d8b19e08abae ("HID: dockchannel: receive ring for the M4 MTP firmware") Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- drivers/hid/dockchannel-hid/dockchannel-hid.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index 03b9d2f7a268b..c17b0defa892a 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -1387,8 +1387,11 @@ static int dchid_drain_ring(struct dockchannel_hid *dchid) u32 producer, consumer, available; int size; - if (!READ_ONCE(dchid->ring_registered)) - return -EPROTO; + if (!READ_ONCE(dchid->ring_registered)) { + /* The firmware can notify before it has the ring address: nothing to read. */ + dev_dbg(dchid->dev, "Ring notification before registration\n"); + return 0; + } while (1) { producer = READ_ONCE(indices[0]); From d5ba9ed25aa33bc3863a0493fedceacc44ae821e Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Wed, 21 Oct 2026 14:44:34 -0300 Subject: [PATCH 6/8] HID: dockchannel: wake only on keyboard input and trackpad clicks Any frame from the MTP woke the system from suspend-to-idle, because the FIFO's receive interrupt was the wake interrupt. On the J616s a real s2idle ended 3 ms after it began ("Triggering wakeup from IRQ 74"), most likely on the answer to the LED report the input core sends while it suspends the keyboard. Resting fingers, the trackpad accelerometer and the other interfaces would do the same. Add system sleep PM ops that mark the sleep window. Within it, a received input report wakes the system with pm_wakeup_hard_event() only when it is a keyboard report or a multi-touch report with the firmware's button bit set, so a keypress or a trackpad click still wakes the machine. pm_wakeup_hard_event() does nothing while wakeup is disabled for the device in sysfs. Requests from the HID core fail with -EBUSY in that window instead of waiting up to a second for an answer: the LED report above timed out in suspend-to-idle once the link's interrupt was disabled. The coprocessor itself keeps running. No sleep command for it is known, and neither its RTKit session nor the trackpad AFE power sequence can be restarted, so the keyboard must not be put down. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- drivers/hid/dockchannel-hid/dockchannel-hid.c | 70 +++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index c17b0defa892a..61792a1c3dc4d 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -114,6 +115,10 @@ struct dchid_gpio_ack { u8 cmd[]; } __packed; +/* Multi-touch report 0x75: byte 23 bit 0 is the firmware's button state. */ +#define MT_REPORT_ID 0x75 +#define MT_REPORT_BUTTON 23 + #define STM_REPORT_ID 0x10 #define STM_REPORT_SERIAL 0x11 #define STM_REPORT_KEYBTYPE 0x14 @@ -195,6 +200,8 @@ struct dockchannel_hid { struct apple_smc *afe_smc; bool stopping; bool inherited_mtp; + /* Between the system sleep suspend and resume callbacks */ + bool suspended; /* Held from probe on when the multi-touch interface uses power method 2 */ struct gpio_desc *afe_reset; @@ -843,6 +850,9 @@ static int dchid_raw_request(struct hid_device *hdev, if (READ_ONCE(iface->dchid->stopping)) return -ESHUTDOWN; + /* Fail fast: an answer that arrives in suspend-to-idle is not waited for. */ + if (READ_ONCE(iface->dchid->suspended)) + return -EBUSY; switch (reqtype) { case HID_REQ_GET_REPORT: @@ -1306,6 +1316,25 @@ static void dchid_handle_ack(struct dchid_iface *iface, struct dchid_hdr *hdr, v complete(&iface->out_complete); } +/* + * Whether a report should wake the system: any keyboard report, and a + * multi-touch report only while the trackpad is clicked. Touches, the + * accelerometer and the other interfaces do not wake it. + */ +static bool dchid_wake_report(struct dchid_iface *iface, void *data) +{ + struct dchid_subhdr *shdr = data; + u8 *payload = data + sizeof(*shdr); + + if (FIELD_GET(FLAGS_GROUP, shdr->flags) != HID_INPUT_REPORT) + return false; + if (!strcmp(iface->name, "keyboard")) + return shdr->length > 0; + return !strcmp(iface->name, "multi-touch") && + shdr->length > MT_REPORT_BUTTON && payload[0] == MT_REPORT_ID && + (payload[MT_REPORT_BUTTON] & 1); +} + /* Return the complete frame size, or reject a lost framing boundary. */ static int dchid_frame_size(const struct dchid_hdr *hdr) { @@ -1351,6 +1380,12 @@ static int dchid_dispatch(struct dockchannel_hid *dchid, struct dchid_hdr *hdr, dchid_handle_ack(iface, hdr, data); return 0; case DCHID_CHANNEL_REPORT: + /* pm_wakeup_hard_event() does nothing while wakeup is disabled. */ + if (READ_ONCE(dchid->suspended) && + hdr->length >= sizeof(struct dchid_subhdr) + + ((struct dchid_subhdr *)data)->length && + dchid_wake_report(iface, data)) + pm_wakeup_hard_event(dchid->dev); break; default: dev_warn(dchid->dev, "Unknown channel 0x%x, treating as report...\n", @@ -1648,10 +1683,11 @@ static int dockchannel_hid_probe(struct platform_device *pdev) } /* - * Keyboard and trackpad input wakes the system. The coprocessor keeps - * running across suspend-to-idle and keeps sending reports through - * the FIFO, so its receive interrupt is the wake interrupt. Without - * it the machine still works, it just cannot be woken from here. + * A keypress or a trackpad click wakes the system. The coprocessor + * keeps running across suspend-to-idle and keeps sending through the + * FIFO, so received frames are classified (dchid_wake_report()) and + * other traffic does not wake it. Without a wakeup source the machine + * still works, it just cannot be woken from here. */ ret = dockchannel_init_wakeup(dchid->dc); if (ret) @@ -1711,6 +1747,31 @@ static void dockchannel_hid_remove(struct platform_device *pdev) } } +/* + * The coprocessor keeps running across suspend-to-idle: there is no known + * sleep command for it, and its RTKit session and the trackpad AFE power + * sequence are not restartable. Only mark the sleep window, in which input + * may wake the system and requests from the HID core fail fast. + */ +static int dockchannel_hid_suspend(struct device *dev) +{ + struct dockchannel_hid *dchid = dev_get_drvdata(dev); + + WRITE_ONCE(dchid->suspended, true); + return 0; +} + +static int dockchannel_hid_resume(struct device *dev) +{ + struct dockchannel_hid *dchid = dev_get_drvdata(dev); + + WRITE_ONCE(dchid->suspended, false); + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(dockchannel_hid_pm_ops, dockchannel_hid_suspend, + dockchannel_hid_resume); + static const struct of_device_id dockchannel_hid_of_match[] = { { .compatible = "apple,dockchannel-hid" }, {}, @@ -1724,6 +1785,7 @@ static struct platform_driver dockchannel_hid_driver = { .of_match_table = dockchannel_hid_of_match, /* The coprocessor announces its interfaces only once per boot. */ .suppress_bind_attrs = true, + .pm = pm_sleep_ptr(&dockchannel_hid_pm_ops), }, .probe = dockchannel_hid_probe, .remove = dockchannel_hid_remove, From f98122b072d632a1bd9afec104a7bea2dcb11199 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Wed, 21 Oct 2026 14:44:34 -0300 Subject: [PATCH 7/8] soc: apple: dockchannel: keep receiving through system sleep The receive interrupt was the device's wake interrupt, so the PM core armed it for system sleep and any frame ended a suspend-to-idle, whatever it carried. The client cannot filter what it never gets to read. Request the receive interrupt with IRQF_NO_SUSPEND instead, so that the client keeps receiving in suspend-to-idle and decides itself which data wakes the system, with pm_wakeup_hard_event() on the FIFO's device. dockchannel_init_wakeup() now only makes that device a wakeup source. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- drivers/soc/apple/dockchannel.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/soc/apple/dockchannel.c b/drivers/soc/apple/dockchannel.c index cf9e74bef94e3..77dc01f8b4359 100644 --- a/drivers/soc/apple/dockchannel.c +++ b/drivers/soc/apple/dockchannel.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -255,8 +254,13 @@ struct dockchannel *dockchannel_init(struct platform_device *pdev) if (ret) return ERR_PTR(dev_err_probe(dev, ret, "Failed to request TX IRQ")); + /* + * Received data keeps being handled through system sleep, so that the + * client can tell input that should wake the system from other traffic. + */ ret = devm_request_threaded_irq(dev, dockchannel->rx_irq, dockchannel_rx_irq, - dockchannel_rx_irq_thread, IRQF_NO_AUTOEN, + dockchannel_rx_irq_thread, + IRQF_NO_AUTOEN | IRQF_NO_SUSPEND, "apple-dockchannel-rx", dockchannel); if (ret) return ERR_PTR(dev_err_probe(dev, ret, "Failed to request RX IRQ")); @@ -266,26 +270,21 @@ struct dockchannel *dockchannel_init(struct platform_device *pdev) EXPORT_SYMBOL(dockchannel_init); /** - * dockchannel_init_wakeup() - Let data from the remote side wake the system + * dockchannel_init_wakeup() - Make the FIFO's device a wakeup source * @dockchannel: FIFO returned by dockchannel_init() * - * Make the FIFO's device a wakeup source, enabled by default, with the - * receive interrupt as its wake interrupt. While wakeup is enabled for the - * device, the PM core keeps that interrupt armed across system sleep, and - * data that arrives then wakes the system. The data itself is read after - * resume, as usual. + * Make the FIFO's device a wakeup source, enabled by default. The receive + * interrupt is not a wake interrupt: it stays enabled through system sleep + * and the client keeps receiving data, so that any traffic does not end a + * suspend-to-idle. The client decides which data wakes the system and + * reports it with pm_wakeup_hard_event() on the FIFO's device, which does + * nothing while wakeup is disabled for the device. * * Return: 0 on success, or a negative error code. */ int dockchannel_init_wakeup(struct dockchannel *dockchannel) { - int ret; - - ret = devm_device_init_wakeup(dockchannel->dev); - if (ret) - return ret; - - return devm_pm_set_wake_irq(dockchannel->dev, dockchannel->rx_irq); + return devm_device_init_wakeup(dockchannel->dev); } EXPORT_SYMBOL(dockchannel_init_wakeup); From 6083c89eeb31205a82b59f86c85cb995fc8658c9 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 23 Oct 2026 13:41:42 -0300 Subject: [PATCH 8/8] HID: dockchannel: test the receive ring reader The receive ring is memory the MTP firmware writes, read with wrap-around arithmetic. A frame straddles the end of the 2 MiB ring once every 2 MiB of input, so in normal trackpad use. Add two KUnit cases to the parser test: a checksummed acknowledgment split across the end of the ring must arrive whole and move the consumer index past it, and a header with the wrong length must stop the drain with -EPROTO without consuming anything. Signed-off-by: Jonathan Goyvaerts Assisted-by: LLM --- .../dockchannel-hid-parser-test.c | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c index 56efa764aaec6..64fde481641cd 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c @@ -196,6 +196,66 @@ static void dchid_unaligned_checksum_test(struct kunit *test) } } +/* A ring whose next frame straddles the end of the data area. */ +static void *dchid_test_ring(struct kunit *test, u32 consumer, u32 producer) +{ + struct dockchannel_hid *dchid = ((struct dchid_iface *)test->priv)->dchid; + u32 *indices; + + dchid->ring = kunit_kzalloc(test, DCHID_RING_SIZE, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dchid->ring); + indices = dchid->ring; + indices[0] = producer; + indices[1] = consumer; + dchid->ring_read = consumer; + dchid->ring_registered = true; + dchid->use_ring = true; + return dchid->ring + DCHID_RING_HEADER_SIZE; +} + +static void dchid_ring_wrap_test(struct kunit *test) +{ + struct dchid_iface *iface = test->priv; + const u32 capacity = DCHID_RING_SIZE - DCHID_RING_HEADER_SIZE; + const u32 consumer = capacity - 12; + struct { + struct dchid_hdr hdr; + struct dchid_subhdr sub; + u8 id; + u8 pad[3]; + __le32 checksum; + } __packed frame = { + .hdr = { .hdr_len = sizeof(struct dchid_hdr), .channel = DCHID_CHANNEL_CMD, + .length = sizeof(struct dchid_subhdr) + 4, .seq = 7, .iface = 1 }, + .sub = { .flags = 0x80, .length = 1 }, + .id = 0x10, + }; + u8 *data; + + /* A complete, checksummed acknowledgment of the pending command. */ + frame.checksum = cpu_to_le32(U32_MAX - dchid_checksum(&frame, sizeof(frame) - 4)); + data = dchid_test_ring(test, consumer, sizeof(frame) - 12); + memcpy(data + consumer, &frame, 12); + memcpy(data, (u8 *)&frame + 12, sizeof(frame) - 12); + + KUNIT_EXPECT_EQ(test, dchid_drain_ring(iface->dchid), 0); + /* The frame arrived whole: its acknowledgment matched the pending command. */ + KUNIT_EXPECT_TRUE(test, completion_done(&iface->out_complete)); + KUNIT_EXPECT_EQ(test, iface->dchid->ring_read, sizeof(frame) - 12); + KUNIT_EXPECT_EQ(test, ((u32 *)iface->dchid->ring)[1], sizeof(frame) - 12); +} + +static void dchid_ring_bad_header_test(struct kunit *test) +{ + struct dchid_iface *iface = test->priv; + struct dchid_hdr hdr = { .hdr_len = sizeof(hdr) + 1, .length = 4 }; + u8 *data = dchid_test_ring(test, 0, 16); + + memcpy(data, &hdr, sizeof(hdr)); + KUNIT_EXPECT_EQ(test, dchid_drain_ring(iface->dchid), -EPROTO); + KUNIT_EXPECT_EQ(test, iface->dchid->ring_read, 0U); +} + static struct kunit_case dchid_parser_cases[] = { KUNIT_CASE(dchid_unaligned_checksum_test), KUNIT_CASE(dchid_short_ack_test), @@ -206,6 +266,8 @@ static struct kunit_case dchid_parser_cases[] = { KUNIT_CASE(dchid_short_input_test), KUNIT_CASE(dchid_init_descriptor_test), KUNIT_CASE(dchid_packet_checksum_test), + KUNIT_CASE(dchid_ring_wrap_test), + KUNIT_CASE(dchid_ring_bad_header_test), {} };