Skip to content

HID: dockchannel: J616s (MacBook Pro M4 Pro) keyboard and trackpad - #409

Merged
RyanTheTide merged 8 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/dockchannel-j616s
Oct 24, 2026
Merged

RyanTheTide merged 8 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/dockchannel-j616s

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

The keyboard and trackpad of the MacBook Pro 16" M4 Pro (J616s). Its MTP runs the M4 MTP firmware transport (the T8132's receive ring), and its trackpad's analog front end needs a power sequence through an SMC key. Plus two sleep fixes that apply to every DockChannel HID machine.

  • dt-bindings: apple,afe-smc. A link to the SMC whose gp1c key powers the trackpad analog front end on boards that need it.
  • Josh Rodd's receive ring for the M4 MTP firmware (from GravityLinux, carried with his sign-off): the firmware delivers reports through a host-allocated 2 MiB DMA ring registered with command 0x91 and announces new data with notify frames on the FIFO. Firmware without the ring keeps the FIFO-only path. As trimmed by Niklas Sheth's review series and merged onto this tree's driver (its PM1 command helper, checksum helper, stop check and wakeup setup kept).
  • J616s MTP support. apple,t6041-dockchannel-hid selects the receive ring, and is the only compatible that does: the carried commit's apple,t8132-dockchannel-hid is not in the binding and no DT uses it, and the M4 Air's MTP, adopted from the boot loader (arm64: apple: T8132/J713 (M4 MacBook Air) support and native graphics (replaces #366, #367) #400), has never run the ring setup, so it goes. The trackpad front end is powered around the interface reset: gp1c high, then 50 ms, when turning it off; low when turning it on; issued between the WillChange and HasChanged messages. It is used only with apple,afe-smc, after checking the controller compatible, that the SMC is one macsmc binds (apple,t8103-smc or apple,smc), and the key's size and access. 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 ring's power messages are built with dchid_pm2_command(). Kconfig: the driver may not be built in while macsmc is a module.
  • arm64: dts: t6040-j616s: link the MTP to the SMC (apple,afe-smc = <&smc>).
  • Ignore ring notifications before registration. A notification that arrives between the 0xc1 prepare command and the ring's registration carries nothing (the ring address has not been sent yet). It was treated as a protocol error ("Receive ring failed: -71" on about half of our boots, with the keyboard and trackpad working afterwards).
  • Wake only on keyboard input and trackpad clicks (every machine). Any MTP frame woke the system from suspend-to-idle: on the J616s a real s2idle ended 3 ms after it began, most likely on the answer to the LED report the input core sends while it suspends the keyboard. Within the sleep window a report now wakes the system (pm_wakeup_hard_event()) only when it is a keyboard report or a multi-touch report with the button bit set. The sysfs wakeup setting still applies.
  • soc: apple: dockchannel: keep receiving through system sleep (every machine). For that, the FIFO's receive interrupt is requested with IRQF_NO_SUSPEND instead of being the wake interrupt, so the client keeps receiving in s2idle and decides itself which data wakes the system. dockchannel_init_wakeup() only makes the device a wakeup source.
  • KUnit: the receive ring reader. A checksummed frame split across the end of the ring must arrive whole and move the consumer index past it; a header with the wrong length must stop the drain with -EPROTO.

Hardware tested on: Apple MacBook Pro (16-inch, M4 Pro, 2024), J616s / T6040, macOS 26.6.2 firmware, booted by our own loader.

How tested: our daily kernels drive this keyboard and trackpad; 7.3.0-m4.9 to m4.11 (on integration/aurora up to 6af6603bf85) carry this series as it was before review, with the same apple,afe-smc link in our board include. Daily s2idle suspend by lid and menu since 2026-10-22: the machine stays asleep instead of waking within milliseconds, and the keyboard and trackpad work after resume. The review changes (the T8132 compatible removed, the power messages from the shared helper, which are the same bytes, the AFE retry guard reduced to "no power-on after a failed power-off", the Kconfig dependency, the DT commit in place of our include, and the test) were built, not booted yet.

Not tested / limits: the two sleep changes apply to every DockChannel HID machine but were only run on the J616s; on the M4 Air (#400) they were checked by reading. The KUnit cases were built, not run (no QEMU here; the driver is built in on our machine). The battery cost of receiving through s2idle (frames that do not wake still run the interrupt thread) was not measured over a long sleep. The J616s DT also carries mtp/tp-accel child nodes the binding does not describe yet (dtbs_check reports them, as before this series).

Base: integration/aurora (1aa2857509d). Built at every commit with W=1 and KUnit (CONFIG_HID_DOCKCHANNEL=y, CONFIG_APPLE_DOCKCHANNEL=y, CONFIG_HID_DOCKCHANNEL_KUNIT_TEST=y): no warnings; with CONFIG_MFD_MACSMC=m the driver becomes a module. dt_binding_check (dtschema 2026.9) is clean for apple,dockchannel-hid.yaml, and dtbs_check for t6040-j616s accepts apple,afe-smc. checkpatch --strict: one CHECK (a mutex without a comment) in the carried commit, left as carried.

🤖 Generated with Claude Code

jgoyvaerts and others added 8 commits October 23, 2026 13:47
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 <[email protected]>
Assisted-by: LLM
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 aurora-silicon#1), as trimmed back to the minimal change over
the existing driver by Niklas Sheth's review series (a48a449,
d934891, ba7b4a7, 2d1c2b5, 3132261, bd7b318),
merged onto this tree's driver (its PM1 command helper, checksum helper,
stop check and wakeup setup kept).

Link: GravityLinux/linux@3f56fba5e1c3
Link: GravityLinux/linux@3f56fba...0c724f0

Signed-off-by: Josh Rodd <[email protected]>
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 <[email protected]>
Assisted-by: LLM
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 <[email protected]>
Assisted-by: LLM
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 <[email protected]>
Assisted-by: LLM
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: d8b19e0 ("HID: dockchannel: receive ring for the M4 MTP firmware")
Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
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 <[email protected]>
Assisted-by: LLM
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 <[email protected]>
Assisted-by: LLM
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 <[email protected]>
Assisted-by: LLM
@fbalazsy

Copy link
Copy Markdown
Contributor

Ran the KUnit tests of this PR at 6083c89ee under QEMU 11.1.2 (kunit.py run --arch arm64, -M virt -cpu max, TCG; GCC 16.1.1, rustc 1.99.0).

Result: Ran 17 tests: passed: 17. Both new cases pass: dockchannel-hid-parser 11/11 (dchid_ring_wrap_test, dchid_ring_bad_header_test) and dockchannel-hid-protocol 4/4. No oops or WARN.

kunitconfig
CONFIG_KUNIT=y
CONFIG_ARCH_APPLE=y
CONFIG_PM=y
CONFIG_OF=y
CONFIG_INPUT=y
CONFIG_HID_SUPPORT=y
CONFIG_HID=y
CONFIG_APPLE_MAILBOX=y
CONFIG_APPLE_RTKIT=y
CONFIG_APPLE_RTKIT_HELPER=y
CONFIG_APPLE_DOCKCHANNEL=y
CONFIG_HID_DOCKCHANNEL=y
CONFIG_HID_DOCKCHANNEL_KUNIT_TEST=y
CONFIG_HID_DOCKCHANNEL_PARSER_KUNIT_TEST=y

The ring tests are in the parser suite, so they need CONFIG_HID_DOCKCHANNEL_PARSER_KUNIT_TEST in addition to CONFIG_HID_DOCKCHANNEL_KUNIT_TEST.

A minor one: with MFD_MACSMC unset (as in this minimal config), dockchannel-hid.c:456 warns unused variable 'afe' in dchid_reset_interface(), because its only use is inside #if IS_REACHABLE(CONFIG_MFD_MACSMC). It doesn't show with the m4 config, but a CONFIG_WERROR build without macsmc would fail on it.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Tested with our universal config (7.3.0-aurora-73s):

  • J616s: keyboard, actuator, tp-accel and mtp interfaces come up over the receive ring, the gp1c AFE sequence logs no error, and there's no "Receive ring failed". Our machine doesn't have apple/tpmtfw-j616s.bin yet, so the trackpad itself couldn't be opened there; that's on our side. No RTC wake on this machine, so s2idle wasn't run on it.
  • Neo (A18 Pro, FIFO path): no regressions, keyboard and trackpad ready, and a 30 s s2idle slept the full 31 s and came back with both devices.
  • KUnit: dockchannel-hid-parser 11/11 (both ring cases) and dockchannel-hid-protocol 4/4.

Josh Rodd's commit keeps his authorship and sign-off, with the Gravity links, which is what we want. fbalazsy's unused afe warning without MFD_MACSMC gets a small follow-up commit from us (ryan/j616s-dockchannel-409). Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants