Skip to content

iio: aop_als: Stop the reports for a system sleep and on unbind - #2713

Closed
gig3m wants to merge 1 commit into
aurora-silicon:mainfrom
gig3m:j813/aop-als-sleep-v2
Closed

gig3m wants to merge 1 commit into
aurora-silicon:mainfrom
gig3m:j813/aop-als-sleep-v2

Conversation

@gig3m

@gig3m gig3m commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

The ALS reports on its own at the interval the driver sets at probe (200 ms), and each report is an AOP mailbox interrupt. Nothing set the interval back to zero, so:

  • after an unbind the sensor kept reporting to nobody
  • in suspend-to-idle it woke a CPU five times a second

This sets the interval to zero on unbind and in .suspend. In .resume the CT817 (T8140) gets the probe's whole sequence (verbosity, batch, raw, then the interval), since it arms only on the zero to non-zero transition after its batch and raw properties are written. The other parts need only the interval.

Replaces #1876: adds the CT817 replay from the review, on current integration/aurora, without the commit trailer.

Draft, because I can test one machine and this driver serves several. I have only a J813 (VD6286), so the CT817 path has not run. Feedback wanted on:

  • a real sleep. aop.rs stops the endpoints in suspend_late for a firmware sleep; this runs before that, in .suspend. I could only test s2idle.
  • whether macOS stops the ALS for a sleep the same way. I have no trace of it.

Tested on J813 (Mac17,3, 27.0 stub, VD6286) with #1876's head, integration/aurora 5d112b1 merged with #1532. The J813 row on this head is to follow:

  • awake, AOP mailbox interrupts per 10 s: bound 60, unbound 10 (59 before this change), rebound 60
  • s2idle test suspends, 20 trials: 1.15 to 1.2 interrupts per second in the sleep, 5.9 to 6.0 before
  • the channel reads again after every resume and rebind
  • one lid-close sleep, 181 s on battery: 1.02 interrupts per second in the sleep (it was 3.6 on an earlier kernel), the channel reads again after it, no warning
  • no measurable power change in s2idle here (1.90 W against 1.93 W, 20 s trials): the cores only clock-gate. It should count once T8142 has a real sleep.

Not tested: any other Mac (so not the CT817 replay), a failed write on resume (it warns).

Assisted-by: LLM (Anthropic:Claude Fable 5.2)

The sensor reports on its own at the interval the driver sets at probe,
and each report is an AOP mailbox interrupt. Nothing set the interval back
to zero: the sensor kept reporting after the driver was unbound, and
through suspend-to-idle, where it woke a CPU five times a second.

Set the interval to zero on unbind and on system suspend. On resume the
CT817 gets the probe's whole sequence (verbosity, batch, raw, then the
interval), since it arms only on the zero to non-zero interval
transition after its batch and raw properties are written, and they may
not survive the sleep. The other parts need only the interval.

Signed-off-by: Kyle Arrington <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Looks right to me. The drvdata cast matches what platform::Adapter stores (Pin<KBox<IIOAopAlsDriver>>). The epic_call in .suspend is bounded by the AOP's own timeouts, so a wedged AOP costs one timeout and doesn't hang the sleep. Picking the CT817 replay by the report layout keys it on the sensor part, not the board.

On your firmware-sleep question: .suspend runs before aop.rs stops the endpoints in suspend_late, so the interval write goes out while the service is still up. The open question is the resume. If the AOP comes back from a firmware-driven sleep with its sensor state reset, the non-CT817 parts may also need more than the interval. A T8140 (Neo, CT817) deep-sleep row would settle both: 3 sleeps, then the AOP mailbox IRQ rate in sleep and awake, and in_illuminance changing after each wake.

Small: if set_interval(0) fails in .suspend, the CT817 replay on resume writes the interval non-zero to non-zero, which doesn't re-arm per your comment. That's harmless (it was still reporting), but a dev_dbg on the suspend failure would make it visible.

Assisted-by: LLM (Claude:Opus 5.5)

@gig3m

gig3m commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

I'm stepping back from this one. The branch stays up and maintainer edits are enabled, so take it, rework it, or close it as you see fit. The code is GPL-2.0 under my Signed-off-by; use it however helps.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

aop_als.rs on integration/aurora at daa9e2d still has no sleep handling and never sets the interval back to zero, and ea28a0c applies to that tip without conflicts. #2528 edits the same driver for the same sensor state from the resume side (re-arm the CT817 after a sleep, with J700 proof); this one stops the reports at suspend and on unbind and has a VD6286 row. The author has handed this branch over, so the two should become one change rather than land separately. Whichever shape is kept needs a T8140 deep-sleep row: the AOP mailbox interrupt rate in sleep and awake, and the illuminance changing after each wake.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@gig3m checking open drafts today. To come out of draft, this still needs:

  • A test run at the current head on a Mac with the hardware it touches, then mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The unbind part of this change is now in #3393, rebased on main after #2528 and credited to this PR, with J700 and J413 rows. The suspend part isn't in it: #2528 already re-arms the CT817 after a sleep, and whether reports wake the CPU in suspend-to-idle still needs a measurement. This PR stays open for that part.

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]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Closing as superseded. Every part of this change is now in main:

This PR Landed in
Stop the reports (interval 0) at unbind #3393 (99edb763)
Stop the reports for system suspend #3404 (ad25d59a), every part, PM_SUSPEND_PREPARE
Resume: CT817 gets the whole probe sequence #2528 (wake re-arm), with the zero-first arm from #3393
Resume: other parts get the interval back #3404, after every attempted stop

The landed version uses a PM notifier rather than dev_pm_ops, because #2528 had already added one, and its commits credit this PR. J413 (VD6286) rows: AOP interrupts during a 21 s s2idle went from 84 to 28; the sensor stops at unbind and comes back on rebind. The J700 (CT817) rows cover unbind and rebind, two deep sleeps and one s2idle.

Thanks for the original patch and for handing it over. The branch stays up, so this can be reopened if something here was missed.

AxxzyWasTaken pushed a commit to AxxzyWasTaken/linux that referenced this pull request Nov 27, 2026
The light sensor reports on its own every 200 ms, and each report is an
AOP mailbox interrupt. Nothing stopped them for a system sleep, so in
suspend-to-idle they went on waking a CPU for readings nobody takes.

On a J413 (M2 Air, VD6286, suspend-to-idle by default) the AOP mailbox
took 84 interrupts during a 21 s rtc sleep with the light sensor armed,
and 26 with it stopped: the light sensor was about 2.7 of the 4 wakeups
a second the AOP caused while the Mac slept. The lid angle driver
already stops its reports for the sleep.

Extend the PM notifier that re-arms the CT817 to every part: at
PM_SUSPEND_PREPARE write the interval to zero, and at PM_POST_SUSPEND
start the reports again. The CT817 keeps the whole arming sequence after
every sleep, because its firmware stops the reports for system sleep
even when the host did not. The other parts get their interval back, and
only if it was stopped. A failure to stop is logged and never refuses
the sleep.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants