Skip to content

iio: aop_als: stop the reports at unbind, arm the CT817 from zero - #3393

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/aop-als-stop-on-unbind
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/aop-als-stop-on-unbind

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

What: iio_aop_als now writes the report interval to zero at unbind, so the light sensor stops sending AOP mailbox interrupts to a driver that is gone. On the CT817 (T8140) the arming sequence now always starts from interval zero, so a probe still arms the sensor if a previous driver instance or a kexec left it running. This takes over the unbind part of #2713, which its author handed over.

Tested: at 7f1220a1 (aop_als.rs blob 401f4f2b), built as a module against the fleet89 tree (645f7cd3, same config and toolchain, identical symbol table) and loaded on the running fleet89 kernel. No reboot.

  • J700 (MacBook Neo, CT817): after unbind, reports go from 50 to 0 per 10 s; the stock driver stays at 50. Rebind, reload and probe over a running sensor all re-arm (51/10 s). Two 15 s rtc deep sleeps re-arm through the iio: aop_als: arm the CT817 again after system sleep #2528 wake path (51/10 s).
  • J413 (M2 Air, VD6286): after unbind, the ALS's 26 reports per 10 s stop (shared AOP mailbox goes from 46 to 20); the stock driver stays at 46. Rebind and reload re-arm (46/10 s).
  • Both Macs were left on the stock module with the driver bound: saved fleet89, empty next entry, Enforcing, 0 failed units.

Risk: two-way · Macs with an AOP light sensor (T8140 CT817, VD6286/CT720 parts). Non-CT817 parts change only at unbind.

Not yet: both lab rooms were dark at night, so lux read 0.000 throughout and these rows don't show readings following light changes. The new CT817 sequence (zero, then verbosity/batch/raw, then interval) is byte-for-byte the wake sequence that #2528 already verified with lux following light. No row yet on a cold boot of a kernel built from this head, or on a CT720 Mac.

Details
  • Stopping the sensor at unbind follows aop_motion, which already shuts its sensor down at unbind. A failed write is logged and unbind continues; the AOP transport refuses calls with ENODEV once it is closing, and EPIC calls are bounded by its timeouts.
  • arm_ct817() now writes interval 0 first. Before this change only the wake path did; now probe and wake share one sequence, and the wake path's behaviour is unchanged.
  • Left out from iio: aop_als: Stop the reports for a system sleep and on unbind #2713: stopping reports for suspend. iio: aop_als: arm the CT817 again after system sleep #2528 (merged) re-arms the CT817 after a sleep. Whether reports still wake the CPU in suspend-to-idle on the s2idle Macs needs its own measurement before any change.
  • No per-chip or per-board gate is added. The CT817 sequence is selected by the part the AOP reports, as before.
Evidence
  • Method: the rate is the delta of the AOP mailbox receive IRQ over 10 s (J700 310608000.mailbox-recv, J413 24a408000.mbox-recv). On J413 that mailbox also carries the other AOP sensors.
  • Module build: fleet89 source 645f7cd3589d (tree 0394077990b0), kit config byte-identical after olddefconfig, clang/LLD 22.1.6, rustc 1.97.1, bindgen 0.73.2. The kernel symbol set matches the shipped System.map except two linker erratum veneers. The test module's undefined symbols are the stock module's plus register_pm_notifier/unregister_pm_notifier and two atomic helpers, all exported by fleet89. The test .ko was unsigned (taint E until next boot on both Macs).
  • rustfmt --check clean; checkpatch.pl 0 errors / 0 warnings.

J700 row:

A stock bound: reports 50/10s
B stock unloaded (stock unbind leaves the sensor running): reports 50/10s
C new probe over a running sensor: reports 51/10s
D new unbind: reports 0/10s
E new rebind (arm from zero): reports 51/10s
F new unloaded: reports 0/10s
G new reload: reports 51/10s
  sleep 1 rtcwake rc=0 suspend_stats success 0 -> 1   (PM: suspend entry (deep))
H1 after deep sleep 1: reports 51/10s
  sleep 2 rtcwake rc=0 suspend_stats success 1 -> 2
H2 after deep sleep 2: reports 51/10s
Z stock restored: reports 51/10s

J413 row:

A stock bound: reports 46/10s
B stock unloaded (stock unbind leaves the sensor running): reports 47/10s
C new probe over a running sensor: reports 46/10s
D new unbind: reports 20/10s
E new rebind (arm from zero): reports 46/10s
F new unloaded: reports 20/10s
G new reload: reports 46/10s
Z stock restored: reports 46/10s

No new kernel warnings in either run (apart from the unsigned-module taint line).

Revert: git revert of the merge commit; the driver goes back to leaving the sensor running at unbind.

The light sensor reports on its own every 200 ms, and every report is an
AOP mailbox interrupt. unbind() only dropped the listener, so the sensor
went on reporting to nobody: on the J700 (T8140, CT817) the AOP mailbox
kept taking 5 interrupts a second after the driver was unbound, the same
rate as with the driver bound.

Write the interval to zero at unbind, before the listener goes, as the
motion driver already stops its sensor at unbind. A failure is logged
and unbind goes on; the AOP transport refuses calls once it is closing.

The CT817 arms only on a zero to non-zero transition of its interval.
Probe assumed the interval was zero, which holds at a cold boot but not
after a previous instance of the driver (or a kexec) left the sensor
running. Make the zero write the first step of arm_ct817(), so probe
and the wake path share one sequence; the wake path already wrote zero
first, so its behaviour does not change.

This takes over the unbind part of #2713 by Kyle Arrington, who handed
the branch over. Its suspend and resume part is left out: #2528 now arms
the CT817 again after a sleep, and whether reports still wake the CPU
in suspend-to-idle needs its own measurement.

Link: #2713
Signed-off-by: Ryan Murray <[email protected]>

@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.

Code approved. The patch unregisters the CT817 PM callback before the stop write and keeps the listener in place until after that write. CT817 probe and resume share the same zero-to-active sequencing. The author handoff on #2713 scopes this to unbind. Reported J700 and J413 runs cover stop, rebind and restore. Keep hosted CI and a CT720 check for the shared stop path before merge.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Build check at 7f1220a1: aop_als.o compiles against main 2d96d922 (fleet config, clang/LLD 22.1.6, rustc 1.97.1, bindgen 0.73.2) with no errors or warnings. The hosted CI doesn't build this arm64 Rust module. Also rustfmt --check is clean, and checkpatch reports 0 errors and 0 warnings.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

On the CT720 check for the shared stop path:

  • None of our lab Macs has a CT720. Every AOP light sensor we have other than the J700's CT817 exposes in_colortemp_input, which this driver creates only for the VD6286: J413 (M2 Air), J316s (M1 Pro), J616s (M4 Pro), J615 (M3 Air) and J713 (M4 Air).
  • The CT720 and the VD6286 take the same path through this change. At unbind both get the same single ALS_PROP_INTERVAL = 0 write. At probe both get the unchanged non-CT817 branch of enable_als() (calibration if present, then the interval). The only difference between the two parts in this driver is the lux offset in the report, which this PR doesn't touch.
  • So the J413 VD6286 row (the ALS's 26 reports per 10 s stop at unbind and come back at rebind and reload) is our closest equivalent for the CT720 path.

@DjDeveloperr, if any Mac you can reach has a FireFish2/CT720 (a light channel but no colortemp channel), a one-line unbind/bind check would close this out. Otherwise we'll go with the VD6286 row as stated.

@RyanTheTide
RyanTheTide merged commit 99edb76 into main Nov 27, 2026
3 of 4 checks passed
@RyanTheTide
RyanTheTide deleted the fix/aop-als-stop-on-unbind branch November 27, 2026 15:07
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged as 99edb763 at head 7f1220a1. Basis: host-tests and pr-text passed, J700 and J413 rows at this head, and an approval from a non-author review lane. Its CT720 condition is answered above: no lab Mac has that part, and the VD6286 row covers the same code path. The failed readiness run stopped after 27 minutes and left no log; it is a report, not a test. To revert: git revert -m 1 99edb763. The suspend part of #2713 follows in its own PR.

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