Skip to content

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

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

RyanTheTide merged 10 commits into
integration/aurorafrom
surp/aop-services

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 (why this stays a draft)

  • Motion check not done. With nobody at the machine, the lid and chassis never moved. At rest the fused attitude stays bit-identical between reports. Someone needs to tilt the laptop and move the lid, and confirm that at least two components move smoothly and the norm stays near 1.
  • DT step. The J616s boots the DTB embedded in Stage 2. A Stage 2 refresh carrying the integration DTB (these child nodes plus the other merged J616s DT changes) trial-booted cleanly on 11-07 (3 DCPs, eDP + external display, 0 AVC). It goes live together with the next fleet kernel after this PR merges.

🤖 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
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