Skip to content

iio: aop_als: arm the CT817 again after system sleep - #2528

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/aop-als-rearm-after-sleep
Nov 26, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/aop-als-rearm-after-sleep

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Problem

On the MacBook Neo (J700, T8140), the ambient light sensor stops at the first system sleep of every boot and never reports again until reboot. After that wake, in_illuminance_input keeps returning the last sample taken before the sleep, usually from the moment the panel went dark. iio-sensor-proxy, and anything that follows ambient light, then sees a constant for the rest of the boot. No error is logged.

Evidence (Neo J700, installed aura 1.0.0b13-g5dcf62d0, no dock)

  • Every boot is affected. This was seen in the Neo deep-sleep soak (work/neo-tip-soak-20261119): 26 boots and 72 deep sleeps.
    • Kernels: integration/aurora 1473d15 (8 boots), the 7.3.0-41 RPM (2 boots) and 1473d15 with every sleep forced onto the deep path (16 boots).
    • After the first wake, every ALS read returned one constant value, identical to 6 decimals, through the later wakes.
    • Example boot. Before the first sleep, five reads over 5 s: 20.55 20.55 20.55 19.36 20.55 lx. After wake 1 and wake 2: 1.453372 ×5 each, with the backlight (402) and the room unchanged.
    • Each boot froze on its own value, between 0.000000 and 6.628011 lx.
  • Why:
    • The firmware stops the sensor's reports for system sleep; aop_las.rs already notes this ("after the light sensor already stopped its reports for sleep").
    • The CT817 starts reporting only on a 0 → non-zero transition of its report interval.
    • enable_als() writes that transition once, at probe, and the driver has no PM handling.

Fix

A PM notifier, built the same way as aop_las's (#2223). At PM_POST_SUSPEND it writes the interval to 0 and then repeats the probe's CT817 arming: verbosity, batch interval, raw interval, interval.

  • Only the CT817 gets the hook (offset == LUX_OFFSET_CT817); VD6286 and CT720 are unchanged.
  • A failure only logs a dev_warn.
  • rustfmt-clean with the tree's .rustfmt.toml. Builds without warnings with LLVM 19 / Rust 1.85.

Tested (Neo J700)

Test kit 7.3.0.nts1473a = 1473d15 + this patch (same diff), Ryzen build, config-neo-41 lineage. One-shot boots on the installed aura, each followed by a byte-exact undo.

  • 2 valid boots × 3 DRAM-kept deep sleeps: the sensor reported again after every wake and followed the light.
    • Boot A: before the sleep 15.26 ×5. After wake 2 18.61 18.61 18.23 18.61 18.61, after wake 3 18.61 ×5, panel on.
    • Boot B: before the sleep 16.46 15.26 15.26 15.26 15.26. After wake 1 18.23 ×5 (panel on). After wake 2, with the lock screen dimming the backlight to 121, 5.17 6.37 5.17 5.17 6.37. After wake 3 5.55 ×5.
  • Sleep, GPU smoke, Wi-Fi, BT, panel and the AOP mics behaved as on the unpatched tip. The patch logged no reports not armed again warning, no AOP crash, no BAD lines.
  • Not counted:
    • A third boot is void: the host's Wi-Fi switched networks mid-row, so no sleep ran.
    • Boot A's first-wake read was taken ~100 s after the wake (slow Wi-Fi reassociation), with the display already turned off by the lock screen.
  • Not run: other CT817 machines (T8142/J815), and machines with the other sensor parts (VD6286, CT720), whose code is unchanged.

Not merging; for review.

🤖 Generated with Claude Code

On the J700 (T8140) the light sensor stops reporting at the first system
sleep of a boot and never starts again. Every read of
in_illuminance_input after that wake returns the last sample from before
the sleep, usually taken as the panel went dark, for the rest of the boot.

Measured 2026-11-19 on integration/aurora 1473d15 and on the
7.3.0-41 RPM alike: 26 boots, 72 deep sleeps, on both the DRAM-kept
and the deep path. Before the first sleep, five reads over 5 s gave
20.55 20.55 20.55 19.36 20.55 lx. After the first and second wakes the
same boot read 1.453372 five times each, with the room and the backlight
unchanged. Each boot froze on its own value, between 0.000000 and
6.628011 lx.

The firmware stops the sensor's reports for system sleep; the lid angle
driver's comment notes the same. The CT817 starts reporting only on a
zero to non-zero transition of its report interval, which enable_als()
writes once, at probe.

Register a PM notifier, as aop_las does. At PM_POST_SUSPEND it writes the
interval to zero and then repeats the probe's CT817 arming: verbosity,
batch and raw interval, then the interval. Only the CT817 gets the hook;
the other parts are unchanged.

Tested on the J700 with 1473d15 plus this patch, built as a test kit:
2 boots, 6 DRAM-kept deep sleeps. After every wake the sensor reported
again and followed the light. It read 18.23-18.61 lx with the panel on,
and fell to 5.17-6.37 lx, still varying from read to read, when the lock
screen dimmed the backlight to 121. The sleeps, GPU, Wi-Fi, BT and the
AOP mics behaved as on the tip, and the patch logged no warning.

Signed-off-by: Diljit Singh <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

No blockers.

I checked the hook's lifetime and teardown. The notifier block is the first field of a pinned PmHook. unbind() unregisters it before the listener goes, and unregister_pm_notifier() waits for a running callback, so pm_event() can't run against a freed hook. On a failed probe, Drop covers it too. The wake sequence (interval 0, then the probe's arming) is the same as at probe, and the hook is only registered for the part whose arming depends on the 0 to non-zero transition. The commit carries a human Signed-off-by and no agent trailers.

  1. Nit: drivers/iio/common/aop_sensors/aop_als.rs:147-265 copies aop_las.rs's notifier scaffolding almost line for line: PmHook, pm_event, pm_register/pm_unregister with both CONFIG_PM_SLEEP variants, Send/Sync, unregister, Drop. Each driver differs only in its callback body. A shared kernel::iio::common::aop_sensors helper that takes a resume closure would keep the unsafe code in one place. This can be a follow-up.
  2. Nit: the PR body ends with the "Generated with Claude Code" footer. Make Assisted-by: LLM (...) its last line instead.

HW row: on J815 (T8142, CT817) with the same kit, 3 deep sleeps; after each wake in_illuminance_input follows a light change. On J616s (VD6286), 3 sleeps on the unchanged path; record whether that part keeps reporting after a wake, or needs the same hook. Both with 0 AVC, 0 failed units, and no new AOP errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

aop_als.rs on integration/aurora (4a17f73) still arms the CT817 only at probe and has no sleep handling; the file has not changed since this branch was cut, so it applies cleanly. Draft #2713 edits the same driver for the same problem from the other side (interval to zero in .suspend, CT817 replay in .resume), and its author has handed it over, so the two should become one change: this one has the J700 proof for the re-arm, #2713 has the suspend-time stop and a VD6286 row. @DjDeveloperr could you say which shape you want to keep, and fold the other in? Rows still asked for: J815 (CT817) three deep sleeps, and J616s (VD6286) to see whether that part keeps reporting after a wake.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf

Verdict at ebc0f1bd6a73

Approve. The PmHook lifetime, pinned #[repr(C)] layout, teardown ordering, and CT817-scoped PM_POST_SUSPEND re-arm sequence are sound.

Blockers

None.

Checked

  • 1 changed file (drivers/iio/common/aop_sensors/aop_als.rs) audited in full.
  • Rust safety & lifecycle: PmHook is #[repr(C)] with nb as its first field inside Pin<KBox<PmHook>>. unregister() uses registered.xchg(false, Relaxed) before calling unregister_pm_notifier() (which synchronizes against any running callback) and is invoked in both unbind() and Drop. Struct field ordering (pm before listener before _iio) ensures the notifier cannot outlive the AOP listener. Both CONFIG_PM_SLEEP and !CONFIG_PM_SLEEP builds are cleanly handled.
  • Hardware scoping: Only CT817 (offset == LUX_OFFSET_CT817) registers the hook and replays ALS_PROP_INTERVAL = 0 followed by arm_ct817() on PM_POST_SUSPEND; other ALS sensors remain unchanged.
  • CI & trailers: host-tests SUCCESS, MERGEABLE; commit has clean Signed-off-by: with zero AI trailers; J700 (T8140) 2 boots / 6 deep sleeps verification is documented in the commit message.
  • Non-blocking note: Coordinate with draft #2713 (suspend-time stop / VD6286) and clean up the PR description footer before merge as previously noted.
  • Untested scope: Static code audit only (userspace-only review environment; no kernel build or boot performed here).
Evidence
  • Audited drivers/iio/common/aop_sensors/aop_als.rs diff (+161/-12) at ebc0f1bd6a73.
  • CI at head ebc0f1bd6a73: host-tests SUCCESS.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at ebc0f1bd: ready to merge

Check Detail
CI at head ok 1 check passed
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok comment at ebc0f1bd
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS
Merge: gh pr merge 2528 --merge (Owners and Core through the bypass: add --admin).

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

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

ebc0f1b Neo (J700, T8140) + J615 (T8122) + J616s (T6040) (batched 0-diff merge onto main) PASS: aop-sensors-als bound cleanly with 0 als errors across 2/2 rtc0 s2idle on Neo (16.07 lx pre/post-sleep, Borealis VK 1.4.363 + GL 4.6 OK) and 2/2 rtc0 s2idle on J615 (live changing lux pre 16.49-16.66 lx & post 14.90-15.05 lx); Enforcing, 0 failed, 0 AVC on Neo/J616s, 0 new kernel errors; fleet defaults restored.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 26, 2026
@RyanTheTide
RyanTheTide merged commit 876fe09 into main Nov 26, 2026
2 checks passed
@RyanTheTide
RyanTheTide deleted the fix/aop-als-rearm-after-sleep branch November 27, 2026 13:21
olivergreg pushed a commit to olivergreg/linux that referenced this pull request Nov 27, 2026
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 aurora-silicon#2713 by Kyle Arrington, who handed
the branch over. Its suspend and resume part is left out: aurora-silicon#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: aurora-silicon#2713
Signed-off-by: Ryan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants