Skip to content

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

Open
DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
fix/aop-als-rearm-after-sleep
Open

DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
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 <hey@djdev.me>
@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)

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.

2 participants