Skip to content

iio: apple: AOP fused motion (devmotion6) and board temperature (als-temp) on the M4 Pro - #1247

Merged
RyanTheTide merged 12 commits into
integration/aurorafrom
surp/aop-services-int-20261109
Nov 8, 2026
Merged

RyanTheTide merged 12 commits into
integration/aurorafrom
surp/aop-services-int-20261109

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #1054 (same commits, surp/aop-services at 7949de52). #1054 conflicted with integration/aurora, so this branch merges integration in (no rebase, no force push):

  • 1f392cd2 merges integration 1fadde6a (the fleet37 base). The only conflict: c5fd88e moved the T6040-only AOP children (accel, gyro) from t604x.dtsi to t6040.dtsi. devmotion6 and als-temp now sit next to them in the t6040.dtsi &aop block, so the J614s and J616s get them and the J616c tree gains nothing.
  • 7918e6ce merges integration 9c607045 (clean).

What

Two AOP sensor services on the M4 Pro (J616s) that Linux left unclaimed:

  • als-temp: a board temperature sensor next to the ambient light sensor, exposed as an IIO temperature channel (in_temp_input, millidegrees Celsius, 1 Hz, buffered with timestamp). Optional calibration comes from bootloader-filled DT properties; without it the sensor runs on its own defaults (debug message only).
  • devmotion6: the always-on processor's six-axis fusion output, exposed as an IIO quaternion (in_rot_quaternion_raw, W/X/Y/Z signed Q30, buffered with timestamp).

devmotion6 does not use fake-HID reports. Its reports arrive in a per-service shared-memory fast path that the host opens:

  1. read property 81 (report size; a 32-bit value on the M4 Pro);
  2. allocate a coherent buffer with a selector word and two report slots, mapped through the AOP's own DART stream;
  3. open the client with EPIC command 25, then set the report interval (property 0);
  4. poll the slot the selector publishes (AOP timestamp, length, raw report).

The firmware stores property 0 but refreshes the slots at the fusion engine's fixed rate (every 5 ms on the M4 Pro) until the client is closed, whatever the interval says. So the host paces itself: sampling_frequency (default 50 Hz, 1 to 200 Hz) sets the poll period, and the client is open only while samples are consumed. Enabling the IIO buffer opens it and disabling it closes it (interval 0, then command 26). A direct read without a buffer opens the client, waits for the first estimate and closes it again. Sleep closes an open client and resume reopens it; unbind closes it for good. If an open or close outcome is unknown, the buffer stays mapped. The AOP core now routes the 0x99/0x9a replies to commands 25/26, which it used to drop. The AOP core claims just these two names; wakehint (one opaque vendor byte) and cma (a command and history transport, not a sensor) stay unclaimed on purpose. T604x AOP child nodes and bindings included.

Testing (J616s, 11-07)

Setup: one-shot trial Stage 2 (the live DTB plus the two child nodes) and a one-shot kernel, 7.3.0-aurora-aop2b = fleet17 source + this branch at 3b980a29, fleet17 config. fleet17 stayed the default; the machine went back to fleet17 and the production Stage 2 afterwards.

  • devmotion6 streams from boot. A buffered capture gave 150 samples with |q|² = 1.000000 and monotonic timestamps. Example report (52-byte type 3, laptop flat, lid at 86°): W +0.99983, X -0.01851, Y +0.00024, Z +0.00000.
  • Suspend/resume: two s2idle cycles (rtcwake -m freeze). The close and reopen are acknowledged, with no AOP or driver messages, and samples resume after each wake. The attitude re-converges to slightly different values each time.
  • als-temp: 21.4 °C, steady, survives s2idle.
  • SELinux enforcing, 0 AVC, 0 failed units. Boot log err/warn: the same 4 lines as fleet17, nothing new. Kernel not tainted.
  • W=1 and Clippy report no warnings in aop_devmotion.rs, aop_temp.rs or aop.rs. rustfmt is clean on those files. Binding checks passed earlier.

The hardware run found three bugs, now fixed on this branch:

  • the 4-byte property 81 reply failed the probe with a silent -EIO;
  • the ring was allocated on the service device, which has no DMA setup (-ENOMEM);
  • the core dropped the command replies, so the open timed out.

A fourth fix was needed after that: the decoder required 60-byte type 3 reports, but the M4 Pro sends 52-byte ones.

Rate and on-demand client (11-07, 091f105d + 5a685b33)

  • Sweep with a debug build: property 0 = 20, 2500, 5000, 10000, 20000, 40000, 100000, 1000000, 20000000 and 0 all read back as written, and every one left consecutive slot timestamps 5008-5009 us apart. Unloading the accel/gyro drivers did not change that either.
  • With 091f105d: no consumer means no poll work at all (it used to be every 5 ms for the whole boot). Direct reads take 8-19 ms. The buffer runs at 47.6 / 166 / 9.6 Hz for 50 / 200 / 10 Hz requested (jiffy rounding; the firmware caps it at 200). Disabling the buffer stops the polling. Three s2idle cycles (rtcwake -d rtc1), with the buffer on and with it off, all resumed cleanly.
  • After a cold AOP the engine publishes the exact identity quaternion for about 140 ms (23 reports) before its first estimate, so a direct read right after boot returned (1, 0, 0, 0). 5a685b33 skips that placeholder and lets a direct read wait up to 500 ms. Retest (12:51-12:58): the first read after boot returns a real estimate in 157 ms and later ones take 7-8 ms. Rates, s2idle and boot log are unchanged from the run above.
  • Enforcing, 0 AVC, 0 failed units, no new boot-log lines from these drivers.

Still open

  • Motion check by hand. Tilt the laptop and move the lid, then confirm the quaternion components move smoothly while the norm stays near 1. At rest the attitude is stable, as measured on 11-07 and 11-09.
  • DT step. The J616s boots the DTB inside Stage 2. These child nodes reach users with the next J616s Stage 2 DTB refresh after this merges (DT lane). A trial of exactly that, live Stage 2 with only the DTB swapped, booted cleanly on 11-09 (receipts in the comments).

🤖 Generated with Claude Code

The J616s AOP announces two sensor services Linux left unclaimed:
devmotion6, the always-on processor's six-axis fusion output, and
als-temp, a board temperature sensor next to the light sensor. Claim
them in the AOP core and expose them through IIO: the fused orientation
as a quaternion (W/X/Y/Z, signed Q30, 50 Hz) and the board temperature
in millidegrees Celsius (1 Hz). Stop both streams across system sleep
and restart them on resume. Optional temperature calibration comes from
bootloader-filled DT properties; without it the sensor runs on its own
defaults. Add the T604x AOP child nodes and their bindings.

The wakehint and cma services stay unclaimed: wakehint is a single
vendor byte with no established meaning, and cma is a CoreMotion
command and history transport rather than a sensor.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Select the AOP firmware's built-in calibration state before enabling the
devmotion6 interval. AppleSPUHIDDriver performs this generic state write
even though the fused service has no calibration blob; an interval alone
is accepted but leaves the service silent. Keep the state across sleep and
restore only the interval on resume, matching the macOS power path.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
On the J616s the devmotion6 service answers the calibration-state write
with the 'unsupported' status the other AOP sensor services use when
they already hold their calibration from an earlier start in the same
AOP session. Treat it the same way instead of failing the probe.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
devmotion6 does not stream over fake-HID reports. Its reports arrive in a
per-service shared-memory fast path that the AP must open before the
report interval does anything.

Read the payload size from property 81, allocate a coherent two-slot
ping-pong buffer, open the client with EPIC command 25, then set the
interval. Poll the published slot for new reports. On sleep and unbind,
clear the interval and close the client with command 26; on resume, open a
new client before restoring the interval. If an open or close outcome is
unknown, keep the DMA mapping, since the firmware may still hold it.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The firmware answers the client-open (25) and client-close (26) commands
with reply subtypes 0x99 and 0x9a: the request subtype with bit 7 set,
like the existing 0x84 and 0x8a replies. The core only matched the older
subtypes, so it dropped these replies and the caller timed out.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The firmware writes the fast-path ring, so the ring has to be mapped
through the AOP core's own DART stream. The service device has no DMA
setup, and the allocation on it failed with -ENOMEM. Allocate on the
parent AOP device instead.

The payload-size property also answers with 32 bits on the M4 Pro, not
64, which failed the probe with a silent -EIO. Accept either width, and
log the reply length when it is too short.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The M4 Pro firmware sends 52-byte type 3 reports, while the decoder only
took type 3 and 4 reports of exactly 60 bytes. It treated every report as
a state report and the device never produced a sample. The length varies
with the firmware, so require only that the quaternion fits.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The interval in property 0 does not pace the fast-path buffer. The
firmware stores whatever is written there, but it refreshes the shared
slots at the fusion engine's own rate, every 5 ms on the M4 Pro, for
every value from 20 us to 20 s and even for zero, until the client is
closed. The driver opened the client at probe and polled the buffer
every 5 ms for the rest of the boot, with or without a reader.

Open the client only while samples are consumed: when the IIO buffer is
enabled, and briefly for a direct read, which waits up to 100 ms for the
first sample and closes the client again. Poll at the requested rate,
exposed as sampling_frequency (default 50 Hz, 1 to 200 Hz), and still
write the matching interval for the firmware's record. Suspend now
closes and resume reopens only a client that was open, and a stopped
client's last sample is never returned to a later reader.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
When the AOP starts the fusion engine, the service publishes the exact
identity quaternion until its filter has a first estimate, about 140 ms
(23 reports) on the M4 Pro. Since the client is now opened on demand, a
direct read right after a cold start returned that placeholder as the
orientation.

Do not report a bit-exact identity quaternion, which a measured attitude
never is, and let a direct read wait up to 500 ms for a real estimate.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Picks up the tools/aurora-sep source-check fix (c60537c) and the
current release branch, so CI runs against today's base.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The T6040-only AOP children moved from t604x.dtsi to t6040.dtsi
(c5fd88e). Put devmotion6 and als-temp next to accel and gyro in
the t6040.dtsi &aop block, so the J614s and J616s keep them and the
J616c tree does not gain unqualified nodes.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware receipts (J616s, 11-09 03:41-03:52)

Setup: one-shot kernel 7.3.0-aurora-aopj6a = fleet37 (integration 1fadde6a, fleet37 config) + this branch at 1f392cd2, plus a one-shot aura-try Stage 2 trial: the live J616s Stage 2 (4f6074f7) with only the DTB swapped. dtc diff of the live DTB against the trial DTB shows only the two new AOP children (als-temp, devmotion6). The trial was never committed: afterwards the Mac went back to fleet37 with the production Stage 2 4f6074f7, no try marker, and the test kernel removed.

  • Binding: aop-sensors-als-temp and aop-sensors-devmotion6 bind next to the existing las, als, accel and gyro devices. snd_soc_apple_aop (AOP audio) still binds, and the AOP reports READY.
  • als-temp: 22.6-22.7 °C, steady. It reads exactly the same as the SMC's own TAOL key at the same instant (22617 vs 22617 m°C). Display temperatures TD0x read 21.6-23.5 °C.
  • devmotion6 direct read: 162.7 ms when cold, then 6-8 ms. |q|² = 1.000000.
  • devmotion6 buffer at 50 Hz: 190 samples in 4 s (47.5 Hz). |q|² stays at 1.000000, timestamps are monotonic and 20.6-22.4 ms apart, and every component spread is 0 at rest.
  • Client open/close, from the workqueue tracepoint and the AOP mailbox IRQ counter:
    • poll work runs 0 times while idle, 143 times per 3 s with the buffer on, and 0 times after disable;
    • the AOP mailbox takes +2 IRQs on enable and +2 on disable;
    • a direct read costs +4, for its open and close.
  • Two s2idle cycles (rtcwake -d rtc1 -m freeze), one with the buffer on and one with it off: both returned rc 0 (suspend_stats 2 success, 0 fail). Reads after resume gave |q|² = 1, als-temp was fine, and there were no AOP or devmotion messages.
  • iio-sensor-proxy behaves the same as on fleet37: active, ALS present, no accelerometer claimed.
  • SELinux enforcing, 0 AVC, kernel not tainted, 0 failed units. Boot-log warning classes compared with fleet37: nothing new from this branch.
  • Buildbox: host tests (run-host-tests.py) 196/196 and apple-dcp selftests 87/0. dt_binding_check on the three bindings passed. W=1 + CLIPPY report 0 warnings in aop_devmotion.rs, aop_temp.rs and aop.rs. CI is green (source, rust-build, kunit, host-tests, dt-checks).

Still not verified: attitude change under real motion. Nobody was at the machine, so this needs a tilt/lid test by hand; at rest the attitude is stable and the norm stays at 1.

DT delivery: the J616s boots the DTB inside Stage 2. These nodes reach users with the next J616s Stage 2 DTB refresh (DT lane), which composes from the integration DTB after this merges. Until then the drivers stay unbound, which is harmless.

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 8, 2026 16:52
@RyanTheTide
RyanTheTide merged commit b6a6631 into integration/aurora Nov 8, 2026
5 checks passed
@RyanTheTide
RyanTheTide deleted the surp/aop-services-int-20261109 branch November 16, 2026 05:12
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.

1 participant