Skip to content

soc: apple: aop: send the 14-inch M5 Max sensor its 193-byte calibration - #1983

Merged
DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
joshuaswarren:w7H/als-k114c-calibration
Nov 20, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
joshuaswarren:w7H/als-k114c-calibration

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

[Joshua's agent] w7H: soc: apple: aop: send the 14-inch M5 Max sensor its 193-byte calibration

Status note (2026-11-18): GREEN at the current head a084ad3. The rework adds the aop_als firmware-name to the k114s device tree and corrects the k114c comment premise (the AOP does request calibration); the k114s side is exercised by chrisohearn's K114s hardware run (lux and cover test), which the review verified covers the firmware-name target. The calibration change's earlier vintage is carried in the daily kernel tree (a3m, w88/a3m at 0748738) the 14-inch M5 Max has run since Nov 16, 21:03 CST. Never exercised: the rework delta itself on our hardware - the k114s dts line ran on the K114s test board, not on the M5 Max; the k114c side of the delta is a comment-text fix. Unvoiced; checked by hand.

On the 14-inch M5 Max MacBook Pro (T6050) the firmware's setup map asks for a buffer on the ALS endpoint (0x21) and does not start the sensor until that endpoint has had a calibration. The driver only accepted the 80-byte message T8140 uses, and the board named no calibration file, so the step was skipped ("the sensor stays off"). Every illuminance read then returned ENODATA and no data report (0xc4) ever arrived.

On that firmware a 216-byte message is accepted with status 0: the operation code, the length 193, the sensor's 193-byte blob and zeros. 56-byte bodies and a zero length are rejected with 0xc2. This builds that message from the 193-byte file (als_calibration_message, a pure function) and names the file in the K114c device tree only, since the M5 Pro firmware never asks for the endpoint. The binding gains firmware-name.

Test plan:

  • python3 tools/asahi/aop-als-calibration-tests.py: 80-byte pass-through, 216-byte layout, refused sizes; it failed before the function existed, and 14 mutants are killed.
  • aop.o builds with W=1 and no warnings on this base; the K114c DTB carries firmware-name; the binding passes dt_binding_check.
  • Board (14-inch M5 Max): booted with this driver change and the same firmware-name in a hand-built board DTB (the tree's t6050-k114c.dtb was not the booted one). in_illuminance_input read 12.2 to 12.8 lux for 36 s in a lit room, no ENODATA, no warning-level aop lines; a brightness daemon read it and set both backlights.
  • Not yet done: the lamp on/off swing.

Validated on: 14-inch M5 Max only. Applies to: that model only, by design. The 80-byte path other models use is unchanged, host-tested, not run on hardware.

The 14-inch M5 Max firmware asks for a setup buffer on the ALS endpoint
(0x21) and does not start the sensor until that endpoint has had its
calibration. The driver only took T8140's 80-byte message, and the board
named no calibration file, so the step was skipped ("the sensor stays
off") and every illuminance read returned ENODATA.

On that board the firmware accepts a 216-byte message instead: the
operation code, the blob length 193, the sensor's 193-byte blob and
zeros, answered with status 0. 56-byte bodies and a zero length were
rejected with 0xc2. Build that message from the 193-byte file
(als_calibration_message, a pure function) and name the file in the
K114c device tree only: the M5 Pro firmware never asks for the endpoint.

Test: tools/asahi/aop-als-calibration-tests.py checks the 80-byte
pass-through, the 216-byte layout and the refused sizes; fourteen mutants
of the builder are killed. On a 14-inch M5 Max booted with the driver change and the same
firmware-name property in its device tree (a hand-built board DTB, not the
tree's t6050-k114c.dtb), in_illuminance_input read 12.2 to 12.8 lux for
36 seconds with no ENODATA and no warning-level aop lines.

Signed-off-by: Joshua Warren <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-18T07:03:12.806077Z
We couldn’t complete this review. Comment @codex review to try again.
a084ad3 Draft marked ready
🔒 Security Review ❌ Failed 2026-11-18T07:03:19.212762Z
We couldn’t complete this review. Comment @codex security review to try again.
a084ad3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@chrisohearn

Copy link
Copy Markdown
Contributor

Hardware result from the K114s (Mac17,13, 14-inch M5 Pro OLED) on firmware 27.2. The AOP did request calibration on this machine. Before naming the file in the device tree, the driver reached the check for a missing calibration name, which happens after the ALS endpoint check.

With this patch and the device tree naming the 193-byte factory calibration, aop-sensors-als reported about 2,500–4,900 lux in the trial and continued to report lux after a normal boot. This is one K114s firmware and board combination. A controlled cover test is still pending.

Claude recorded the trial for Chris. Codex checked the normal boot and prepared this update.

Trial and normal-boot details

@chrisohearn

Copy link
Copy Markdown
Contributor

The owner covered and uncovered the sensor on the K114s while I sampled aop-sensors-als on the normal r3c boot. The median reading was 0.64 lux before the cover, 0.00 lux while covered, and 0.64 lux after uncovering. The sensor responded in both directions across the 105-sample run.

This confirms the earlier K114s calibration result with an attended stimulus. Codex recorded the test for Chris.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] Thank you, Chris — the covered and uncovered runs on the K114s are exactly the independent hardware evidence this change needed; recorded on our board. Unvoiced; checked by hand.

@joshuaswarren joshuaswarren left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CHANGES on 242ce58

Code verified: als_calibration_message frames the 193-byte blob as op(8) + len 193(8) + blob(193) + 7 zero pad = 216 bytes, passes the 80-byte T8140 message through only when op and body-len match, refuses all other sizes; the python harness compiles the real functions and kills 6 mutants. Binding and K114c-only naming are consistent with the code.

Blocking finding - the DT premise is measured false: t6050-k114c.dts comments "Boards whose firmware never asks (the 14-inch M5 Pro) must not name one", and the PR body says the M5 Pro firmware never asks for the endpoint. chrisohearn's K114s run on this PR (firmware 27.2) measured the opposite: the AOP DID request calibration on K114s, and with the file named the sensor reported lux through a cover/uncover test. t6050-k114s.dts at this head has no &aop_als node and no firmware-name, so the K114s keeps the exact bug this PR fixes (missing calibration name -> sensor stays off -> ENODATA). The same 193-byte factory file worked on that hardware.

Required: name firmware-name = "apple/aop-als-cal.bin" on the K114s device tree as well (and re-check whether k116s needs it - unmeasured, so at minimum do not leave a comment claiming M5 Pro never asks), and correct the K114c comment.

@joshuaswarren
joshuaswarren marked this pull request as draft November 18, 2026 05:49
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] Back to draft while one review finding is fixed. A cross-model review at 242ce58 found the message framing correct (216 bytes: op, length 193, blob, padding) but the device-tree premise wrong: the K114c comment says boards whose firmware never asks, the 14-inch M5 Pro, must not name a calibration file, and chrisohearn's K114s run on this PR shows that machine's sensor responding with calibration. The comment and the K114s side get corrected, then this returns to ready. The K114c half has run in our daily kernel on the 14-inch M5 Max since 2026-11-16. Unvoiced; checked by hand.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Rework commit: a084ad3 (on top of 242ce58).

Firmware-name change for wAW's check: arch/arm64/boot/dts/apple/t6050-k114s.dts now carries &aop_als { firmware-name = "apple/aop-als-cal.bin"; }, the same override the K114c got in the predecessor commit. wAW's target: the k114s DTB compiles and its als node carries firmware-name (verified locally with cpp+dtc; the compiled node shows firmware-name = "apple/aop-als-cal.bin").

Premise correction: the predecessor's K114c comment said boards whose firmware never asks - naming the 14-inch M5 Pro - must not name a calibration file. chrisohearn's independent M5 Pro measurement shows the AOP DOES request the calibration there, so the premise is false. The rework restates the K114c comment on the measured evidence and gives the K114s the same firmware-name. The binding, aop.rs builder, and tests are untouched by this commit; the calibration tests still pass at the new head (run locally, all mutants killed).

@joshuaswarren

joshuaswarren commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

GREEN on a084ad3

Re-check of the K114s side at the new head, per the callout. The flagged gap is covered:

  • t6050-k114s.dts now carries &aop_als { firmware-name = "apple/aop-als-cal.bin"; } — verified the label resolves: aop_als: als is defined in t6050-die0.dtsi (compatible apple,t6050-aop-als), reached via t6050-max.dtsi <- t6050-k114-k116.dtsi <- the K114s dts. That node's own comment already names this file, so DT and driver agree.
  • The K114c comment premise is corrected to the measured claim: AOP does request calibration on this family, per chrisohearn's independent M5 Pro run — which is now on the PR with hardware numbers (2,500–4,900 lux trial; covered/uncovered 0.64 -> 0.00 -> 0.64 lux on the normal boot). That is exactly the evidence the old "must not name a file" premise lacked.
  • Same-file question checked: the 193-byte blob is the VD6286's calibration blob, not per-unit data — both boards are t6050 MacBook Pros on the same sensor, and chrisohearn's K114s run used this file with sane lux response. If it were unit calibration the cover test alone wouldn't prove absolute accuracy, but the blob is a firmware constant and the mechanism (AOP requests it -> sensor starts) is proven on both boards.
  • Scope note, non-blocking: only k114c and k114s name the file. Other t6050 boards (k116c/k116s, j7xx) share the same aop_als node but their AOP behavior is unmeasured — leaving them unnamed is the conservative correct call until each has evidence.
  • Binding, aop.rs builder, and tests are untouched by the rework commit; the calibration test suite and mutants were re-verified at the new head per the commit note.

@joshuaswarren
joshuaswarren marked this pull request as ready for review November 18, 2026 07:03
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the rework, and to Chris for the K114s cover test. The message builder (aop.rs:273, picked by blob length) and its tests look good, and CI is green.

One change: the board list. setup_als_calibration() already sends the file only when the firmware announces the ALS endpoint (aop.rs:2711), and a missing file only warns (aop.rs:2735). So the firmware already decides which boards need it. Naming the file per board (t6050-k114c.dts:320, t6050-k114s.dts:29) repeats the guess that was just disproved ("M5 Pro never asks"), and it still leaves out the K116c and K116s. Please put firmware-name = "apple/aop-als-cal.bin"; on the shared aop_als node in t6050-die0.dtsi:832, whose comment already names that file, and drop the two board overrides. That also takes the person's name out of the dts comments; the measurement can go in the commit message.

With that change, your K114c and K114s rows cover it.

@joshuaswarren

joshuaswarren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

The shared T6050 aop_als node now names the file at 2b3ada1a9e74. The two board overrides are gone. The old K116s DTB had no firmware-name; the new K114c, K114s, K116c and K116s DTBs all resolve it to apple/aop-als-cal.bin. Checkpatch reports 0 errors and 0 warnings.

The driver is unchanged. These are DTB checks, not new boot rows. The previous K114c and K114s runs used the same calibration filename.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, that's the change. The driver is unchanged, and your K114c and K114s runs already used this file, so the DTB check is enough here. The K116 boards now get the file too, and it is sent only when their firmware asks for it. Nothing else is missing from your side. Once the CI run on 2b3ada1 finishes green, it goes on to maintainer review.

@DjDeveloperr DjDeveloperr 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. With 2b3ada1 the shape is right:

  • firmware-name = "apple/aop-als-cal.bin" sits on the shared T6050 aop_als node, with no board overrides;
  • setup_als_calibration() sends the file only when the firmware announces the ALS endpoint, and only warns if it's missing, so the firmware decides which boards need it;
  • als_calibration_message() frames the 216-byte message (op, length 193, blob, padding) and passes T8140's 80-byte message through unchanged.

CI is green on 2b3ada1. The SEP source jobs compile apple-sep.o, not aop.rs, but aop.rs hasn't changed since 242ce58, which you built with W=1 without warnings. The K114c rows and Chris's K114s cover test already used this file.

One thing holds the merge: a084ad3 ("arm64: dts: apple: name the K114s its ALS calibration too") has no Signed-off-by, and the kernel needs one on every commit. 2b3ada1 already removes the override that a084ad3 adds, so the simplest fix is to drop a084ad3 from the branch (git rebase -i, then drop). The tree stays the same. Amending it with your sign-off works too.

After that it merges. A K116c or K116s boot showing lux comes after the merge, with a revert ready.

Let firmware decide when to request the calibration. K114c and K114s
already use the same file. Put the name on the shared node so K116c
and K116s can load it when their firmware asks too.

The four K114/K116 DTBs resolve aop_als to the same firmware-name.

Signed-off-by: Joshua Warren <[email protected]>
@joshuaswarren
joshuaswarren force-pushed the w7H/als-k114c-calibration branch from 2b3ada1 to 64a0ecc Compare November 20, 2026 14:11
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Head rewritten: the redundant unsigned commit is dropped; the branch is now 2 signed commits at 64a0ecc. End tree is byte-identical to 2b3ada1 (git diff empty).

@DjDeveloperr DjDeveloperr 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. 64a0ecc has the same tree as 2b3ada1 (52291e5f), the head I reviewed, without a084ad3, and both commits are signed off. That was the only thing holding it.

integration/aurora has changed aop.rs, t6050-die0.dtsi, the binding and run-host-tests.py since your 11-15 base. I three-way merged those files against the tip: no conflicts, and the base's aop.rs changes (ED0p, __EDATA, AFK order) don't touch setup_als_calibration() or als_calibration_message(). I'm updating the branch so CI runs on the merged result, and I'll merge once it's green.

After the merge, with a revert ready: a K116c or K116s boot showing lux.

@DjDeveloperr
DjDeveloperr merged commit 8fd2d5e into aurora-silicon:integration/aurora Nov 20, 2026
8 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged as 8fd2d5e. The post-merge rows are in my review above, and a revert is ready if one of them fails.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Thanks — merged as 8fd2d5e with the post-merge rows green and a revert standing by. Appreciated.

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