Skip to content

pwm: apple: runtime suspend on zero duty cycle - #3219

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/pwm-apple-zero-duty-rpm
Nov 29, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/pwm-apple-zero-duty-rpm

Conversation

@erikwb

@erikwb erikwb commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Drop the pwm-apple runtime PM output reference when on_cycles == 0 while preserving register state and readback, allowing idle PWM power domains (fpwm1) to power-gate when leds-pwm sets brightness to 0.
Tested: J313 M1 Air @ 42a2c37fd846 (driver unchanged from ad65b1cf3a64, default command line) — fpwm1 drops to off-0 at kbd_backlight=0, wakes to on at brightness=10, returns to off-0 at brightness=0, and stays off-0 across deep S2R; arm64 KUnit pwm-apple 40/40 passed; apple-pwm-pm-tests.py + --negative-control passed; CI host-tests (698/698) and pr-text passed at 42a2c37fd846. J713 (M4 Air, T8132, firmware 27.2) in fleet candidate 90de523e9ed9 (main fcb124279183 plus the unchanged heads fa6ca3bf0e0b (#3085), 42a2c37fd846 (#3219), 3b32d06f7ae5 (#3269), 4654596c5a86 (#3305), d3cf4ca61518 (#3329) and 5dde1e7a4ffb (#3335)), default command line plus panic=10: fpwm1 is off-0 at kbd_backlight=0, on at brightness=10 and off-0 again at brightness=0 (pm_genpd_summary; the keyboard-backlight daemon was stopped for the test and restarted after), 0 failed units, 0 AppArmor denials, no pwm error line. A deep sleep on that candidate (rtcwake -d /dev/rtc1 -m mem -s 15) did not resume: the Mac reset, and the next boot read PMU panic counter 1. It is not yet attributed to a PR in the candidate or to main (the main-only control boot did not complete), so no sleep or resume claim is made for J713.
Risk: two-way door · Apple Silicon Macs using apple,s5l-fpwm (keyboard backlight and PWM consumers).
Not yet: nothing.

Details

leds-pwm keeps state->enabled = true with duty_cycle = 0 when turning an LED off, which previously kept the runtime PM reference on apple_pwm held permanently.

  • Keep writing APPLE_PWM_ON_CYCLES, APPLE_PWM_OFF_CYCLES, and APPLE_PWM_CTRL identically so apple_pwm_get_state() readback is unchanged (and apple_pwm_runtime_suspend()/resume() save and restore all three registers across power-domain loss).
  • Hold the output runtime PM reference only while state->enabled && on_cycles > 0, matching the same check on bootloader-enabled outputs in apple_pwm_probe().
  • Add KUnit coverage verifying reference release and readback across register loss for both explicit zero duty and sub-cycle duties rounding down to zero cycles, and update tools/asahi/apple-pwm-pm-tests.py to match the zero-duty runtime-suspend behavior.
Evidence
  • tools/testing/kunit/kunit.py run --arch=arm64 --make_options=LLVM=1 --kunitconfig=drivers/pwm/pwm-apple.kunitconfig: Testing complete. Ran 40 tests: passed: 40.
  • python3 tools/asahi/apple-pwm-pm-tests.py: 9/9 PASS; python3 tools/asahi/apple-pwm-pm-tests.py --negative-control: PASS negative control: missing output reference was detected.
  • make ARCH=arm64 LLVM=1 W=1 drivers/pwm/pwm-apple.o: 0 warnings.
  • ./scripts/checkpatch.pl --strict --git 2cb2c0034b36f41fcae3e9e47d5239a98e4fb89e..42a2c37fd846: 0 errors, 0 warnings, 0 checks across both commits.
  • CI at 42a2c37fd846: host-tests run 45927630933 passed (698/698 passed, including apple-pwm-pm-tests and apple-pwm-pm-tests --negative-control); pr-text run 45927720704 passed.
  • J313 pm_genpd_summary (ad65b1cf3a64, driver unchanged in 42a2c37fd846): fpwm1 transitions on (kbd_backlight=10) -> off-0 (kbd_backlight=0), remains off-0 after deep S2R.

Consumers such as leds-pwm keep state->enabled = true with
duty_cycle = 0 when turning an LED off, which previously kept the PWM
controller's runtime PM reference (and its PMGR domain, e.g. fpwm1 on
T8103) permanently powered even with the keyboard backlight at 0.

Keep programming the control and cycle registers identically so
get_state() readback is unchanged, and hold the runtime PM output
reference only while the controller actively drives a non-zero duty
cycle (on_cycles > 0). Also preserve the same check at probe time.

Extend pwm-apple KUnit coverage to verify reference release and
hardware readback across register loss for explicit zero duty and
sub-cycle duties rounding to zero cycles (40/40 tests pass).

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team as code owners November 26, 2026 09:39
@erikwb
erikwb requested review from Acelogic and malik-na November 26, 2026 09:39
RyanTheTide
RyanTheTide previously approved these changes Nov 26, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MERGE at ad65b1cf3a64 once CI is green

Blockers: none.

Checked:

  • The output reference now follows on_cycles > 0 instead of state->enabled. Get/put stay balanced on every transition:
    • enabled-nonzero → enabled-zero puts it;
    • enabled-zero → enabled-nonzero gets it;
    • disabled puts it if one was held.
  • Probe takes the boot-left reference only for a running non-zero output.
  • The registers are still written for a zero duty, and readback survives a power-gated resume. The new KUnit case drives both an explicit 0 and a duty that rounds down to 0 cycles.
  • J313 row at this head: fpwm1 goes off-0 at brightness 0, back on at 10, and stays off across deep S2R. pwm-apple KUnit 40/40.

Non-blocking: bool driving = false; sits after a statement in apple_pwm_apply(). Kernel builds use -Wdeclaration-after-statement, so if CI or a W=1 build flags it, moving it to the top of the function fixes it.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 42a2c37f: not ready yet

Check Detail
CI at head no failing: host-tests, pr-text / pr-text, pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 42a2c37f
Conflicts ok none
PR text ok Risk: two-way · Apple Silicon Macs using apple,s5l-fpwm (keyboard backlight and PWM consumers).

Areas: area:gpu

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

@RyanTheTide

Copy link
Copy Markdown
Contributor

MERGETRAIN6: approved and has a row, but host-tests fails at ad65b1cf3a64 on this PR's own test: apple-pwm-pm-tests and its --negative-control both exit 1 (AssertionError; run https://github.com/aurora-silicon/linux/actions/runs/45794081132/job/139820139500). Please fix the test (or the fixture it compiles) and push once. I merge as soon as CI is green.

Update the host runtime-PM model test and its --negative-control hook to
match drivers/pwm/pwm-apple.c suspending on enabled zero-duty outputs
(driving = on_cycles > 0) and resuming cleanly when a non-zero duty is
applied again.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb

erikwb commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Fixed tools/asahi/apple-pwm-pm-tests.py (and its --negative-control hook) in 42a2c37fd846 to match the zero-duty runtime-suspend behavior; drivers/pwm/pwm-apple.c is unchanged from ad65b1cf3a64. Both normal and --negative-control runs pass locally.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@erikwb

erikwb commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide All latest CI checks at 42a2c37fd846 are green: host-tests (run 45927630933, 698/698 including apple-pwm-pm-tests and --negative-control), pr-text (run 45927720704), and readiness.

The ci-failing label and CI at head: no readiness note are from three superseded CANCELLED non-readiness check runs at 02:19Z–02:20Z that pr-readiness counts alongside the passing host-tests, pr-text, and readiness runs without deduplicating by check name.

Regarding the non-blocking -Wdeclaration-after-statement note on bool driving = false; in drivers/pwm/pwm-apple.c: make ARCH=arm64 LLVM=1 W=1 drivers/pwm/pwm-apple.o builds with 0 warnings, and checkpatch.pl --strict reports 0 errors and 0 warnings.

Since 42a2c37fd846 only updated tools/asahi/apple-pwm-pm-tests.py (drivers/pwm/pwm-apple.c is unchanged from ad65b1cf3a64, where the J313 hardware row was recorded), pushing that test-fix commit dismissed the earlier approval on ad65b1cf3a64. The J713 (M4 Air, T8132) fpwm1 keyboard backlight regression boot ran at 42a2c37fd846 in fleet candidate 90de523e9ed9 (main fcb124279183 plus the unchanged heads fa6ca3bf0e0b (#3085), 42a2c37fd846 (#3219), 3b32d06f7ae5 (#3269), 4654596c5a86 (#3305), d3cf4ca61518 (#3329) and 5dde1e7a4ffb (#3335)), default command line plus panic=10: fpwm1 is off-0 at kbd_backlight=0, on at brightness=10 and off-0 again at brightness=0, with 0 failed units and no pwm error line. A deep sleep on that candidate (rtcwake -d /dev/rtc1 -m mem -s 15) did not resume: the Mac reset, and the next boot read PMU panic counter 1. It is not yet attributed to a PR in the candidate or to main (the main-only control boot did not complete), so no sleep or resume claim is made for J713. Fresh approval at 42a2c37fd846 is requested.

@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: MERGE at 42a2c37f

Blockers: none (driver unchanged from previously verified ad65b1cf, host-tests 698/698 + pr-text green, exact-head J313 row PASS; ready to merge).

Checked:

  • drivers/pwm/pwm-apple.c (unchanged from ad65b1cf): runtime PM output reference tracks on_cycles > 0 with balanced get/put transitions across enabled-nonzero, enabled-zero, and disabled states, preserving register state and readback while letting idle fpwm1 power-gate.
  • tools/asahi/apple-pwm-pm-tests.py (42a2c37f): updated assertions and --negative-control hook for zero-duty runtime suspend; 698/698 host-tests pass (run 45927630933).
  • Hardware row & policy: J313 M1 Air exact-head row PASS; MERGEABLE on main; human Signed-off-by; no Apple material, tool attribution, private serials, or board gating.
Evidence
  • Head: 42a2c37fd846 (base: main, mergeable: MERGEABLE, +62/-10 across 3 files).

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping @DjDeveloperr: closeout merge at 42a2c37f. App approved at this head, CI green on the latest runs (the cancelled duplicates are superseded). Rows: J713 at this head, and J313 at ad65b1cf, where the delta to this head is tests only. Merging under the 6-point rule 1 h from now unless you object.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 42a2c37f. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J713@head+J313@ad65b1c(test-only-delta). (5) There's no blocking review. (6) Dj was pinged here 88 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit f54d899 into main Nov 29, 2026
7 of 12 checks passed
@RyanTheTide
RyanTheTide deleted the fix/pwm-apple-zero-duty-rpm branch November 29, 2026 02:23
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merged. Thanks @erikwb!

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) ci-failing A check failed at the PR head (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