Skip to content

drm/apple: m4: colour matrix (CTM) on the internal panel - #3262

Open
themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:feat/m4-panel-ctm
Open

themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:feat/m4-panel-ctm

Conversation

@themartiano

@themartiano themartiano commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: The M4 panel's CRTC has no CTM, so night light (hyprsunset) does nothing. Attach a CTM, with no gamma table, to the panel's CRTC and send it with set_matrix (A423, location 9) before the frame it belongs to, as the firmware 26.6 path of the J613 (iomfb_v26_6.c) does.
Tested: J713 (13-inch M4 MacBook Air, firmware 26.6.2) at f64bbee8c7b5, 2026-11-26: PASS. The panel's CRTC (38) has a CTM property; a warm matrix (r 1.000, g 0.695, b 0.430) reached it and identity was restored after, in three runs; a person saw the panel turn clearly warm and come back (second run; in the first they were watching the external display, which correctly stayed unchanged). The kernel (7.3.0-0.next2) was main ba29027e1580 merged with all our M4 display and other branches and #2814, #2797, #2807, #2672, not this branch alone. This commit's tree is identical to the one booted (1b3721363d80; only the Signed-off-by was added). Regression on that kernel: 0 failed units, no oops, crash or stall, 10/10 deep sleeps without kernel errors (no SELinux on this image). Host: new m4-panel-ctm case and the apple-dcp host suite 96/96; KUnit 565 run, 563 pass, 1 skip, 1 fail that main has too (apple-dcpaud-no-sio); W=1 build.
Rebased onto main 9177b2d474f8 on 2026-12-02; head now ed91cbc6bfcb. Conflicts with #2814 in iomfb_m4.c (its iomfb_m4_present_at() and this PR's matrix functions at the same place; both kept) and in the host case m4.py (the case now also extracts iomfb_m4_present_at()). The new m4-panel-ctm host case passes. Host checks re-run at the new head: W=1 arm64 build of drivers/gpu/drm/apple/, 0 warnings; checkpatch --strict clean; KUnit dcp-fabric, dcp-topology, dcp-display (the suites CI picks for these files) on arm64 QEMU: no failures (one case skips in each of two suites); apple-dcp host suite, no new failures (14 cases fail to compile with this container's newer compiler on main itself, and the same 14 here). The hardware rows above are from before the rebase.

Risk: two-way door · M4 internal panels on firmware 26.6.2 (J713, J715, J604). Other Macs: the CTM is attached only where iomfb_m4_has_ctm() is true (an M4 26.6 pipe that is not external); every other CRTC keeps the CTM and gamma table it had, and M4 external outputs still refuse a CTM. Today's DTs enable the M4 DCP on J604, J713 and J715. On those, night light starts working; nothing is sent until userspace sets a matrix, so a desktop without one is unchanged.
Not yet: a matrix held across DPMS, the idle cache and a deep sleep at this head (DPMS off and on was seen on an older tree); whether A428 (#3076, T6041) is needed on this firmware: this sends A423 only, as iomfb_v26_6.c does, and the panel visibly changed.

Details
  • A commit without a frame presents the frame on screen again, as a brightness change does. Nothing is sent for an unchanged matrix. With the display off it waits for the frame that powers it up, and it is sent again after each power-down in case the firmware lost it.
  • A refusal by the firmware is warned and the next matrix is tried; there is no latch, counter or module parameter.
  • The m4-panel-ctm host case runs the matrix, present and blank functions against a mock transport.

Credit: Dylan Ironside wrote the same change independently for omarchy-j604 (patch 0533): the same call, location and conversion, from a work item after the swap. Linked in the commit.

Evidence

J713 test runs of 2026-11-26 on 7.3.0-0.next2 (one display run, two repeats):

panel-ctm  property      CRTCs with a CTM property: {38: identity}
panel-ctm  reached-crtc  before {38: identity}; during {38: matrix r1.000 g0.695 b0.430}; after {38: identity}   (3 of 3 runs)
panel-ctm  person        run 1: not seen (watching the external display); run 2: panel clearly orange for ~8 s, then normal

Host, at the old head 1b3721363d80 (same tree): apple-dcp host suite 96/96 (new m4-panel-ctm); KUnit apple* on arm64 QEMU 565 run, 563 pass, 1 skip, 1 fail (apple-dcpaud-no-sio, fails on main too); W=1 build clean; checkpatch --strict only asked for the Signed-off-by (now added).

The M4 panel's CRTC has no CTM property, so a compositor's night light
has nowhere to put its matrix: aquamarine says "crtc doesn't support CTM"
and Hyprland's hyprsunset does nothing. The other 26.x paths have it.

Send it with set_matrix (A423, location 9, nine signed Q32.32
coefficients), as iomfb_v26_6.c does: that firmware has this one's method
numbers and swap record. Attach a CTM, and no gamma table, to the panel's
CRTC, and send the matrix before the swap of the frame it belongs to. A
commit without a frame presents the frame on screen again, as a
brightness change does. Nothing is sent until the CRTC first has a
matrix, nor for an unchanged one. With the display off it waits for the
frame that powers it up, and it is sent again after each power-down in
case the firmware lost it. External outputs stay as they are.

Dylan Ironside wrote the same change independently for omarchy-j604
(patch 0533, "drm/apple: m4: give the internal T8132 panel a colour
matrix"): the same call, location and conversion, from a work item after
the swap.

The m4-panel-ctm host case runs the matrix, present and blank functions
against a mock transport.

Seen on a J713 (26.6.2) with an earlier tree: the firmware accepts the
matrix, hyprsunset at 3500 K turns the panel warm, and it stays so over
DPMS off and on.

Link: https://github.com/IronsideXXVI/omarchy-j604/blob/main/kernel/patches/0533-drm-apple-m4-give-the-internal-T8132-panel-a-colour-.patch
Signed-off-by: Eduardo <git@martiano.me>
@themartiano
themartiano marked this pull request as ready for review December 2, 2026 16:15
@themartiano
themartiano requested review from a team as code owners December 2, 2026 16:15
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at ed91cbc6: not ready yet

Check Detail
CI at head ok 9 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA ed91cbc6, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · M4 internal panels on firmware 26.6.2 (J713, J715, J604). Other Macs: the CTM is attached only where iomfbm4hasctm() is true (an M4 26.6 pipe that is not external); every other CRTC keeps the CTM and gamma table it had, and M4 external outputs still refuse a CTM. Today's DTs enable the M4 DCP on J604, J713 and J715. On those, night light starts working; nothing is sent until userspace sets a matrix, so a desktop without one is unchanged.

Areas: area:display

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

@maralcbr maralcbr 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: FINISH, then merge at ed91cbc6bfcb

Blockers:

  1. Hardware row at head: the 2026-11-26 J713 rows ran at f64bbee8c7b5 / 1b3721363d80, before a rebase that conflicted inside iomfb_m4_present_at() (the function that sends the matrix) and m4.py. Please post a J713 row at ed91cbc6bfcb (or a batched M4 candidate containing it unchanged on current main), ideally also checking that the warm matrix holds over DPMS off/on, idle-cache entry/exit, and one deep sleep. Once posted, this is ready to approve and merge without a full re-review.

Checked: code is clean with no blockers; no Apple material, no new chip/board/firmware gates, no new parameters, DCO matches author; CRTC color-mgmt attachment, atomic_check, off-to-on enable (color_mgmt_changed), framed and frameless commits, dcp->lock serialization, transport failure vs firmware status refusal, A423 request layout vs iomfb_v26_6.c, power-down re-mark, and host selftests (m4-dpms-retirement, m4-panel-ctm built with -Wall -Werror + ASan/UBSan at head and merged with main 6ee70d49) verified; hosted CI (Apple build and KUnit, Host tests, pr-text) is green at ed91cbc6bfcb.

Evidence
  • drivers/gpu/drm/apple/apple_drv.c:1962-1966, iomfb_m4.c:3607-3610, dcp.c:2464-2466: CTM-only property is attached solely where iomfb_m4_has_ctm() is true (v26_6 && !external, both set in iomfb_m4_init() before component_add()); M4 external outputs still refuse CTM and all M4 outputs refuse gamma/degamma; non-M4 CRTCs are unchanged.
  • drivers/gpu/drm/apple/apple_drv.c:694, 1230-1232 & iomfb.c:5041-5046: enables run before planes and set color_mgmt_changed = true, so a CTM set while !new->active is applied on re-enable.
  • drivers/gpu/drm/apple/iomfb_m4.c:3586-3646, 3679-3701: with a frame, iomfb_m4_present_at() sends A423 after power-up and before swap; frameless commits re-present active_frame under dcp->lock and kick idle-cache, matching iomfb_m4_backlight_work(). Unchanged matrices and initial NULL-CTM commits send nothing.
  • drivers/gpu/drm/apple/iomfb_m4.c:2037-2041, 3598-3604: transport failures fail the session inside dcp_m4_runtime_call_stream() with no swap following; firmware status refusal warns ratelimited and lets frames proceed.
  • drivers/gpu/drm/apple/iomfb.h:452-457 vs iomfb_v26_6.c:1590-1596: 80-byte packed iomfb_set_matrix_req (location 9 at 0, nine Q32.32 coefficients via dcp_ctm_to_fw() at 4, null flag 0 at 76) matches iomfb_v26_6.c.
  • drivers/gpu/drm/apple/iomfb_m4.c:3809-3811: dcp_m4_set_power_state(dcp, false) sets ctm_pending = true when ctm_set, covering blank, power-gate, and suspend/resume.
  • Local host tests (-Wall -Werror, ASan/UBSan) at head and merged with main (6ee70d49c228, clean 3-way merge): m4-dpms-retirement PASS (4/4), m4-panel-ctm PASS (5/5).
  • Hosted CI at ed91cbc6bfcb: Apple build and KUnit pass, Host tests pass, pr-text pass.
  • Non-blocking notes:
    • tools/testing/selftests/drivers/gpu/apple-dcp/m4.py:817 mocks dcp_m4_set_power_state(), so removing iomfb_m4.c:3809-3811 still passes m4-panel-ctm (the blank case only re-sends because it changes the matrix); exercising the real power-state re-mark would close that test gap.
    • iomfb_m4.c:3623-3624 returns before saving the matrix when !dcp->runtime (unreachable in practice, but saving first is cheap).

@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 ed91cbc

Checked: The CTM property and atomic admission use the same internal M4 predicate. The conversion reuses the existing DRM CTM path, programs an update before its frame, and sends an identity matrix on removal. CRTC-only updates re-present the live framebuffer. Powered-off panels keep the update pending for the next frame. The current-head build, host tests, and DCP KUnit passed.

@DjDeveloperr DjDeveloperr 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.

Approving at ed91cbc6bfcb. I read the whole diff and found nothing that has to change.

What I checked

  • The CTM property and the atomic check use the same test (iomfb_m4_has_ctm(): a 26.6 M4 pipe that isn't external). Every other CRTC and the M4 external outputs behave as on main.
  • Nothing is sent until the CRTC first has a matrix, and an unchanged one isn't sent again, so a desktop without night light sees no new call.
  • The matrix goes out before the swap that shows it, under dcp->lock. A commit without a frame presents the shown frame again without taking another framebuffer reference. While the display is off it waits for the frame that powers it up, and each power-down marks it to be sent again.
  • A refused matrix is warned about and frames go on. A failed call fails the session before any swap, as for the other runtime calls.
  • It merges cleanly on main dc4d6f065001 together with #3273, #3261, #2070 and #3951, and drivers/gpu/drm/apple/ compiles there (arm64, GCC, W=1, no warning in a line this PR touches).

Row still owed before merge: J713 on 26.6.2 at this head (or in a batch that contains it unchanged): warm matrix set and cleared, still there after DPMS off/on, after idle and after one deep sleep, 0 new kernel errors. The earlier rows were before the rebase that touched iomfb_m4_present_at().

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants