Repository navigation
drm/apple: hold brightness requests at the panel's floor - #3105
Conversation
A panel node may name the lowest level at which the panel shows a lit picture, in the unit of apple,max-brightness. The driver change that follows raises requests below it to it. Turning the display off is not a request and is not affected. Signed-off-by: Chris O'Hearn <[email protected]>
The nits backlight (firmware 27) accepts every level from 0 to apple,max-brightness, and a brightness-only present carries the level to the firmware as written. A write of 0 to the backlight device therefore presents 0 nits, the level DPMS off presents. What 0 nits shows on an OLED panel has not been observed, so such a panel may need a lowest level that a request can reach. Read an optional apple,min-brightness from the panel node, in the same nits as apple,max-brightness. A request below it, zero included, is raised to it, and the backlight device reads the raised level back. Blanking and DPMS off are not requests and still present zero. A level the loader reported below the floor stays until the first request. Without the property, or with one that is not below the maximum, nothing changes. The floor is applied, and logged, on the H17P, firmware 27, M4 and 14.7 nits panels; a panel on the DAC path of older firmware and desktop 26.x firmware do not read it. backlight_floor_test covers the floor, the unchanged zero without it, the display-off cases and the loader level. Built as a user-space program with stand-in headers all 29 cases of the file pass, and backlight_floor_test fails with the floor removed; not run under KUnit. On one K114s (firmware 27.2) a build carrying an earlier cut of this change logs "brightness requests below 10 nits are raised to 10 nits" at probe. In three runs, writes stepping from 500, 1000 or 850 nits down to 10 and back read back unchanged; in the first run the panel was seen to dim and recover. No run wrote below the floor, so the floor itself was not exercised on the hardware. Signed-off-by: Chris O'Hearn <[email protected]>
6301e6e to
040c06c
Compare
|
K114s (Mac17,13, T6050) at
This covers the boot, the write below the floor (as a sysfs read-back), |
|
@chrisohearn checking open drafts today. To come out of draft, this still needs:
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. |
|
Thanks for the check. The hardware row at the current head ( The device tree user is #3181, which sets |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 040c06ca53
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return -ENODATA; | ||
| if (nits > state->maximum) | ||
| return -ERANGE; | ||
| nits = dcp_bl_floor(state, nits); |
There was a problem hiding this comment.
Preserve inherited levels across blank-only updates
When a configured floor exceeds the inherited target (for example, loader level 4 with a floor of 10), the backlight core calls this function for BL_CORE_FBBLANK and BL_CORE_SUSPENDED transitions with the unchanged brightness value. Applying the floor before distinguishing those state-only transitions changes state->target to 10, and dcp_set_brightness() also rewrites the sysfs value, so resume or unblank restores 10 even though no brightness request occurred; blank/suspend-only updates need to preserve the inherited target until the first actual brightness write.
Useful? React with 👍 / 👎.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at 040c06ca: fix first (one small change, below). Not a blocker for the approach.
Blockers
- The Codex P2 finding is real. Blank and suspend changes reach
dcp_bl_request()with the level unchanged, and the floor is applied before that case is recognised. So a loader level below the floor (e.g. 4 with a floor of 10) becomes 10 on the first FB blank or suspend, anddcp_set_brightness()writes 10 back to sysfs. No brightness write happened, which breaks the PR's own rule: "a loader level below the floor stays until the first request". Host repro on this head: loader 4, floor 10,request(4, blank)thenrequest(4, unblank)givestarget=10.
Suggested fix (tested on the host, see below). Apply the floor only when the call is a request:
- nits = dcp_bl_floor(state, nits);
+ /*
+ * A blank or suspend change arrives with the level unchanged: it is not
+ * a request, so a loader level below the floor stays.
+ */
+ if (nits != state->target || (state->core_blank == core_blank &&
+ state->suspended == suspended))
+ nits = dcp_bl_floor(state, nits);In dcp_set_brightness(), reading back state->target instead of dcp_bl_floor(state, bd->props.brightness) keeps sysfs equal to the level in every path, including the state-only ones. Please also add the blank-only and suspend-only cases to backlight_floor_test.
Checked
- The binding is optional with
minimum: 1, and no tree sets it, so no Mac changes behaviour today. The value comes from the DT, with no per-panel table and no chip or board gate. dcp_bl_set_minimum()rejects a floor at or above the maximum, with a warning. Only the nits backlight paths use the floor (the DAC path is untouched), and DPMS off, blank and suspend still present 0.- #2844 touches different hunks, as the PR says.
Evidence
A host build of dcp_backlight.h at 040c06ca (gcc, stub kernel headers) runs the asserts of the PR's backlight_floor_test plus two new cases: blank then unblank with loader 4, and suspend with loader 4.
- PR head: the PR's asserts pass; both new cases fail (
target=10, want 4). - With the fix above: 0 failures, the PR's asserts included.
This was not run as kernel KUnit (QEMU) and not on hardware.
Backlight core blank and suspend transitions carry the current brightness. Applying the floor on these transitions raises an inherited level before the first brightness write. RyanTheTide reported that blanking and unblanking raised an inherited level of 4 nits to 10. Keep the target when only the blank or suspend state changes. Apply the floor to level changes and to requests with unchanged state flags. Read the accepted target back through the backlight device. Extend backlight_floor_test to cover blank and suspend cycles below the floor and same-level writes both lit and blanked. Signed-off-by: Chris O'Hearn <[email protected]>
|
Thanks for reproducing this, Ryan. The driver now keeps the inherited level across blank and suspend transitions, and sysfs reads back the accepted target. I extended backlight_floor_test to check that a 4-nit loader level survives blank/unblank and suspend/resume with a 10-nit floor. Same-value brightness writes still raise the target to 10 nits, including while the panel is blanked. All 29 apple-dcp-backlight cases passed in arm64 QEMU at 0c42db3. I still owe the K114s hardware row at that head. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at 0c42db31: approve. Merge once CI is green and the K114s row at this head is posted.
Blockers: none. The blank/suspend finding from the last review is fixed.
Checked
dcp_bl_request()applies the floor only to real requests. A blank or suspend change with the level unchanged keeps a sub-floor loader level, and a same-level write still takes the floor (blanked or not).- sysfs now reads back
state->targeton every path. - The new test cases cover blank/unblank, suspend/resume and a same-level write while blanked.
- The rest is unchanged from my last review: an optional DT property, no tree sets it, no gates.
Evidence
The host build of dcp_backlight.h at 0c42db31 matches the fix I tested earlier (whitespace only). It passes the earlier asserts and the blank-only and suspend-only cases: 0 failures. CI at this head is queued.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c42db3168
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (nits != state->target || (state->core_blank == core_blank && | ||
| state->suspended == suspended)) | ||
| nits = dcp_bl_floor(state, nits); |
There was a problem hiding this comment.
Preserve inherited targets on same-state resume callbacks
On the firmware-27 wake path when no FB blank remains, dcp_backlight_wake_lit() pre-clears core_blank and suspended before the later backlight-core resume update, so an inherited target below the configured floor reaches this condition with unchanged nits and unchanged flags. The same-flags arm added in this revision is fresh evidence that the earlier issue remains: it raises state->target (and dcp_set_brightness() copies it to sysfs) even though the callback is state-only, so resume still changes the loader level without a brightness write; this path needs an actual-request indicator rather than treating every same-state update as a request.
Useful? React with 👍 / 👎.
| if (!ret && dcp->brightness.minimum) | ||
| floor_ret = dcp_bl_set_minimum(&dcp->backlight.state, | ||
| dcp->brightness.minimum); |
There was a problem hiding this comment.
Floor the M4 startup default before its first present
When apple,min-brightness is valid but greater than 120 on an M4 panel, iomfb_m4_configure_backlight() initializes the non-inherited target to 120 and this call only stores the minimum; the immediately following M4 dcp_bl_jump() marks 120 dirty, and iomfb_m4_swap() presents it. The driver therefore drives the panel below its declared lowest lit level before userspace writes brightness, potentially leaving startup black; floor non-inherited defaults before the M4 jump while retaining the below-floor exception only for loader-inherited levels.
Useful? React with 👍 / 👎.
|
The One-line fix (avoids static inline u32 dcp_bl_floor(const struct dcp_backlight_state *state, u32 nits)
{
- return max(nits, state->minimum);
+ return nits < state->minimum ? state->minimum : nits;
}With this on |
The host test harnesses only stub min(), so the max() in dcp_bl_floor() left six apple-dcp units unbuilt. Open-code the clamp; the kernel build is unchanged. Signed-off-by: Ryan Murray <[email protected]>
|
Thanks @chrisohearn. You have been waiting on us for two days, so we pushed the one-line fix from the earlier review ourselves as Next: a K114s floor row at the new head (we run it on our K114s), the review App at this head, then the merge. The two Codex notes (a resume with unchanged flags, and the M4 120-nit default above a floor) are tracked in #3579. Neither can happen until a tree sets |
There was a problem hiding this comment.
Verdict: MERGE at 08ea507 after CI and the K114s row
The ternary preserves the typed brightness clamp and avoids the missing max helper in the host fixture. The binding makes the floor optional, and no board enables it here. Keep the floor-enabled K114s regression and track resume/default interactions in #3579 before enabling the property in production DT.
|
Row (K114s, M5 Pro, T6050) at exact head 08ea507 -> PASS (floor holds across writes and blank/unblank, 0 DCP crashes).
Evidence: traces/kernel/20261130-closeout-k114s-j316s-combo/k114s/. Default kernel 7.3.0-k114sstack8 and default Stage 2 restored and verified (hashes match, aura-try none, next_entry empty). |
|
Merging at |
What: An optional
apple,min-brightnessin a panel node raises any brightness request below it, zero included, to that level on the nits backlight, and the backlight device reads the raised level back. Without the property nothing changes. Blanking and DPMS off still present 0, and suspend behaves as before. Today a write of 0 toapple-panel-blpresents 0 nits, the level DPMS off presents; what 0 nits shows on this OLED has not been observed. Related: #2844 (see Details).Tested: on a K114s (Mac17,13) at this head: one boot of a kernel built from it with a local tree carrying
apple,min-brightness = <10>; the probe logs the floor, writes of 1 and 9 toapple-panel-blread back 10 (sysfs value; luminance not measured), 0 failed units, no new kernel errors; 31apple-dcp-backlightKUnit cases pass in QEMU anddt_binding_checkpasses (hardware row in the comments).Risk: two-way door for the driver; the property is DT binding surface (one-way once released). Applies to the H17P, firmware 27, M4 and 14.7 nits panels; desktop 26.x firmware does not read the property. No tree sets it, so no Mac changes.
Not yet: a write of 0 and the presented luminance below the floor, on hardware. The K114s device tree user is #3181 (below).
Details
apple,min-brightness,minimum: 1, "lowest level at which the panel shows a lit picture, in the unit of apple,max-brightness". The raising is described in the driver commit.dcp.cstores the property next toapple,max-brightness;dcp_backlight_configure()(nits backlight paths only) applies it withdcp_bl_set_minimum(), ignores a value not below the maximum with a warning, and logs the floor. A panel on the DAC path never reaches it, so it neither applies nor logs the floor; desktop 26.x firmware sets up its backlight elsewhere and does not read the property.dcp_bl_request()applies the floor anddcp_set_brightness()reads the raised level back.dcp_set_brightness()andiomfb_template.c, this change is the nits branch.patch --dry-runof drm/apple: switch the panel backlight off at level 0 and count it in millinits #2844's diff on this tree applies cleanly. The concern raised on drm/apple: switch the panel backlight off at level 0 and count it in millinits #2844 (userspace treating 0 as dimmest visible, restore tools writing a saved 0 back) is the case the floor covers for a panel that presents 0 nits as dark.apple,min-brightness = <10>;in its panel node, stacked on arm64: dts: apple: t6050-k114-k116: report the built-in panel as eDP #2009's panel node).mainhas no K114s display or panel node; the property is only meaningful next toapple,max-brightness, which the boot loader fills in. The K114s line would beapple,min-brightness = <10>;in itspanelnode, with the display hand-off. 10 nits is 1 % of the K116s scale and not a measured value.Evidence
drivers/gpu/drm/apple/dcp_backlight_test.c(user-space build with stand-in KUnit headers, the compile line oftests/brightness/run-dcp-backlight-host.sh)29 case(s), 0 failed, includingbacklight_floor_test; with the floor line replaced byreturn nits;the same case fails (dcp_bl_prepare ... == -114).configplusKUNIT=yandDRM_APPLE_KUNIT_TEST=m, clang 23.1.3,W=1dcp.o,dcp_backlight.o,dcp_backlight_test.o: no warningscheckpatch.pl --strictmake dt_binding_checkapple-dcp 48ae00000.dcp: brightness requests below 10 nits are raised to 10 nits(the earlier cut logged it indcp.c; this cut logs it fromdcp_backlight_configure(), not rebooted)apple-panel-bl,max_brightness1000,brightness200,actual_brightness200, typeplatformbrightnessandactual_brightnessequal the written level at every step. The result files record no observation of the panel. I saw the panel dim and recover in the first run, the D5 run of 2026-11-15 (record). No run went below the floor, so the floor itself was not exercised on hardwareLinks: #2844 (backlight off at level 0), K114s boot report #142 (comment).