Skip to content

iio: aop_als: run ambient light reports on demand with idle stop - #3473

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/aop-als-idle-stop
Nov 28, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/aop-als-idle-stop

Conversation

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

What: Switch aop_als (drivers/iio/common/aop_sensors/aop_als.rs) from continuous 5 Hz fake-HID streaming at probe to on-demand start on read_raw with a 5 s DelayedWork idle-stop window (matching aop_motion, aop_temp, and aop_las), caching apple/aop-als-cal.bin in RAM at probe, preserving RunState::Unknown across firmware sleep, keeping probe stop failures recoverable, and adding aop-als.py host regression tests.

Tested:

  • rustfmt --check clean; host tests run-host-tests.py --only aop-als: 3/3 PASS (aop-als-channel-tests, aop-als-calibration-tests, apple/aop-als); ARM64 cross-compile (ARCH=arm64 LLVM=1): 0 warnings; scripts/checkpatch.pl --strict: 0 errors, 0 warnings.
  • J616C (MacBook Pro 16" M4 Max, T6041, VD6286 Redbird ALS) integrated boot (7.3.0-j616c-parity5+ carrying this commit, aurora-kbd-light.service paused for idle measurement):
    • Idle-stopped AOP mailbox IRQs (510608000.mailbox-recv): 5.75/s -> 1.00/s (5 IRQs in 5 s, eliminating the 5 Hz ALS stream at idle).
    • Cold on-demand read: lux=1.776817, cct=2898.17 K in 214 ms; warm 4 s window 5.75/s (23 IRQs); cleanly re-stopped to 1.00/s (5 IRQs in 5 s) after the 5 s idle timeout.

Risk: two-way · AOP ambient light sensor driver (aop_als.rs) covering VD6286, CT720, and CT817.

Not yet: Standalone exact-head bare-metal boot row on b11717dde674 and CT720 / CT817 hardware rows.

The AOP ambient light sensor driver enables 5 Hz (200 ms) fake-HID reports
at probe and keeps them streaming continuously until system sleep or
unbind, generating 5 AOP mailbox interrupts per second on an idle desktop
even when nothing reads in_illuminance_input or in_colortemp_input.

Follow the on-demand idle-stop pattern used by aop_motion, aop_temp, and
aop_las:

- Load apple/aop-als-cal.bin once at probe into memory for VD6286 and
  CT720 so on-demand wakes and resume never re-request firmware from the
  filesystem. Send calibration once per AOP boot (and conservatively again
  after firmware suspend, hibernation, or restore).
- Verify calibration, arming (including the full 0 -> verbosity ->
  batch_interval -> raw_interval -> interval sequence on CT817), and
  stopping once at probe, then leave reports stopped at idle.
- Start reports on demand on read_raw, invalidate stale cached samples
  before starting from Stopped or Unknown, track in-flight direct_readers,
  hold reports warm for 5 s via DelayedWork, back off for 5 s after a
  failed start, and retry idle stops if an unacknowledged write leaves
  RunState::Unknown.
- Stop active streams on PM_SUSPEND_PREPARE / PM_HIBERNATION_PREPARE /
  PM_RESTORE_PREPARE without waking an idle stopped sensor on resume.
- Free the IIO device via devres and tear down IIO, PM, delayed work
  (disable_delayed_work_sync), reports, and fake-HID listener in both
  unbind and Drop.
- Add a host regression test (aop-als.py) covering the on-demand stream
  state machine and register it in run-host-tests.py.

Signed-off-by: AxxzyWasTaken <[email protected]>
@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 28, 2026 04:32

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at b11717dd

Blockers:

  1. CI has not finished yet (apple-build, host-tests, KUnit suites, pr-text, readiness are queued; CI must be green at b11717dd).
  2. Confirm that the J616C 7.3.0-j616c-parity5+ integrated boot row carries b11717dd byte-identically (or run an exact-head boot), and add a regression row covering at least one other sensor variant (CT720 or CT817) since aop_als.rs changes the probe/sleep/on-demand lifecycle for all three ALS variants.

Checked: no Apple material, no AI attribution, no new chip/board/firmware gates, no cmdline hacks, human Signed-off-by, Stream state machine (Stopped/Running/Unknown, DirectReadGuard, idle-stop retry, backoff), stop_idle_sync Arc accounting (matches aop_motion.rs), probe-failure and unbind teardown order, probe-time aop-als-cal.bin RAM caching (no filesystem access on wake/resume), and PM_SUSPEND_PREPARE/PM_POST_SUSPEND/PM_POST_HIBERNATION transitions.

Evidence
  • Inspected drivers/iio/common/aop_sensors/aop_als.rs against main and compared stop_idle_sync with aop_motion.rs:395.
  • Verified probe error paths: if control.probe_init() fails, pm.unregister(), control.shutdown(), and listener drop cleanly; if drv.iio.register() fails, IIOAopAlsDriver::drop() runs teardown() in reverse order (IIO -> PM -> control.shutdown() -> fake-HID listener).
  • Verified PM_SUSPEND_PREPARE sets parked = true, clears direct_until, stops reports under stream.lock(), and calls stop_idle_sync(false); any concurrent read_now() waiting on FIRST_SAMPLE_MS observes parked and returns EBUSY cleanly.
  • Verified read_now() warm-read fast path (already_seen && sample.seen_report) avoids 1 s stalls when a channel is validly absent on a live report (e.g. dark CCT).
  • J616C integrated boot row (7.3.0-j616c-parity5+) reports AOP mailbox IRQs reduced 5.75/s -> 1.00/s, cold read 214 ms, clean idle-stop back to 1.00/s.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Confirmed against the booted 7.3.0-j616c-parity5+ (3969120aab727) tree: both drivers/iio/common/aop_sensors/aop_als.rs and tools/testing/selftests/drivers/apple/aop-als.py are byte-identical to b11717dde674 (git diff empty; only unrelated test-runner entries differ in Makefile and tools/asahi/run-host-tests.py). Standalone exact-head J616C verification and a second ALS variant (CT720 or CT817) regression row remain queued.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at b11717dd: not ready yet

Check Detail
CI at head running running: KUnit isp, KUnit jpeg, KUnit prores, KUnit scaler, KUnit macsmc, KUnit clpc
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at b11717dd
Conflicts ok none
PR text ok Risk: two-way · AOP ambient light sensor driver (aopals.rs) covering VD6286, CT720, and CT817.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

RyanTheTide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

J700 MacBook Neo, CT817, at the exact #3473 ALS source blob 95027899 from b11717dde674, compiled and loaded on saved fleet89 645f7cd3:

Phase AOP receive IRQs ALS read
Stock idle 30 in 6 s Immediate cached read
Candidate idle 0 in 6 s First direct read 0.23 s
Candidate active window 15 in 3 s Warm read under 10 ms
Candidate stopped again 0 in 6 s Next cold read 0.23 s

The panel was under night conditions; these checks cover sensor availability, sample latency and report stopping. The saved boot, next-entry state, Enforcing, zero failed units and installed ALS module were verified before and after. The unsigned trial modules leave the usual runtime taint until the next saved reboot. This was a live module row; the combined boot/regression and deep-wake rows are still pending.

code-owner ping @aurora-silicon/core @aurora-silicon/omarchy-mac @aurora-silicon/aurora-maintainers Please review this CT817 evidence alongside the author's J616C VD6286 evidence and assess the remaining merge coverage.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The source review and alternate ALS variant request are satisfied at this head. The J616C integrated VD6286 row uses byte-identical driver source. The J700 CT817 live-module row uses the exact ALS blob and shows 30 receive IRQs per six seconds at stock idle falling to zero, a 0.23 s cold read, and a return to zero after stopping. Both rows exercise on-demand reporting. Keep hosted CI and the combined integrated boot and deep-wake regression as landing gates.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Additional J700 CT817 wake row on saved fleet89, same exact ALS source blob 95027899 from b11717dde674. One RTC deep sleep completed in 16 s, the successful suspend count advanced 0→1 and the boot ID stayed the same. After wake, idle AOP receive IRQs were 0 in 6 s, the first direct lux read completed in 0.23 s, and the rate returned to 0 in 6 s after the hold expired. The stock modules and saved boot state were restored, with Enforcing and zero failed units. The same pre-existing DCP PMU read message is recorded in the earlier stock-family wake evidence.

Also checked composition with #3409. The distinct driver blobs compile and run together, but the source PR heads conflict in the host-test runner list and selftest Makefile. Whichever lands second should forward-merge and keep all of the ALS, LAS, motion and temperature entries. No driver source resolution is needed between those two heads.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Independent J316s M1 Pro peer row on saved fleet89. Loaded the exact #3473 ALS blob 95027899 from b11717dde674 in one live batch with the exact #3409 lid and temperature modules. Stock total AOP interrupts were 28/6 s. With the batch they were 6/6 s at idle, 12/3 s while ALS was active, and 6/6 s after the stop. Two cold lux reads took 0.21 s each and the warm read took under 10 ms. CCT returned ENODATA on both stock and candidate under the cover. This row covers lux and idle behaviour in those conditions.

Input and ALSA devices registered, the headless connector baseline was unchanged, Wi-Fi gateway was 3/3, and hardware EGL passed 32/32 on Apple M1 Pro G13S. Saved GRUB boot and stock modules restored in the same boot, Enforcing, 0 failed units. This is a live module regression on a third SoC family alongside the existing J616C integrated and J700 CT817 rows.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Integrated J316s regression, in one guarded Nightly kernel boot based on 94ea195b6eb5. The installed modules used the exact #3473 ALS blob from b11717dde674 and the exact #3409 lid/temperature blobs from cf2c1f844ddb. Each module probed during normal boot, with its installed hash matching the staged overlay. CT817 functionality and deep wake were tested separately on J700.

J316s returned lux, lid angle 107 and board temperature 19.312 °C. SPI keyboard and trackpad and ALSA endpoints registered. DRM stayed in the usual headless state. Gateway ping passed 3/3, hardware EGL passed 32/32, SELinux was Enforcing, and there were zero failed units, kernel errors or AVCs. Restored and byte-compared the saved fleet89 receipt, including the default entry, command line and boot-stage hash. Removed the trial entry, modules and dead-man.

@RyanTheTide

RyanTheTide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Merged under the six-point rule at b11717dd. The review App approved the exact head and hosted CI passed. The J700 CT817 row includes deep RTC wake, and the J316s and J616C normal boots cover the regression check. There was no blocking review, and code-owner notice had reached 60 minutes. The merged ALS driver blob 95027899e52 matches the tested blob. Revert with git revert -m 1 f3bcc901bd23.

@RyanTheTide
RyanTheTide merged commit f3bcc90 into aurora-silicon:main Nov 28, 2026
22 checks passed
DjDeveloperr added a commit to scottjones/linux that referenced this pull request Dec 1, 2026
Main replaced the IIORegistration-based ALS device with its own on-demand AlsIioDev (aurora-silicon#3473), so register the CT720 channels there: AlsIioDev::new() takes a ChannelSpec per channel (type, modifier, info mask), the four colour counts answer IIO_CHAN_INFO_RAW as whole counts, lux and colour temperature stay processed, and a CT720 report that carries lux but not a colour channel withdraws that channel, as channel_withdrawn() says. MAX_CHANNELS grows to the six CT720 channels; VD6286, CT817 and the other parts keep the channels they had.

Signed-off-by: DjDeveloperr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants