From 2e4d9c8118d06a9a3ff2c6de07bcb45e3fc50985 Mon Sep 17 00:00:00 2001 From: Chris O'Hearn <137103567+chrisohearn@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:03:18 -0700 Subject: [PATCH 1/4] dt-bindings: display: apple,dcp: add apple,min-brightness to the panel 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 <137103567+chrisohearn@users.noreply.github.com> --- Documentation/devicetree/bindings/display/apple,dcp.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 6867256ee228e..5bf6cbcf1008e 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -558,6 +558,12 @@ properties: apple,max-brightness: $ref: /schemas/types.yaml#/definitions/uint32 description: Maximum firmware backlight level. + apple,min-brightness: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + description: + Lowest level at which the panel shows a lit picture, in the unit + of apple,max-brightness. required: - compatible additionalProperties: false From 040c06ca5353698c6b843ccb63f6c4507031072f Mon Sep 17 00:00:00 2001 From: Chris O'Hearn <137103567+chrisohearn@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:03:19 -0700 Subject: [PATCH 2/4] drm/apple: hold brightness requests at the panel's floor 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 <137103567+chrisohearn@users.noreply.github.com> --- drivers/gpu/drm/apple/dcp-internal.h | 2 + drivers/gpu/drm/apple/dcp.c | 3 ++ drivers/gpu/drm/apple/dcp_backlight.c | 13 +++++ drivers/gpu/drm/apple/dcp_backlight.h | 26 ++++++++++ drivers/gpu/drm/apple/dcp_backlight_test.c | 60 ++++++++++++++++++++++ 5 files changed, 104 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 2c3899445803a..3d6c8b6120435 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -193,6 +193,8 @@ struct dcp_fb_reference { struct dcp_brightness { struct backlight_device *bl_dev; u32 maximum; + /* apple,min-brightness: lowest level a request reaches, 0 for none. */ + u32 minimum; u32 dac; int nits; int scale; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 073e51f9781fe..a66b3498ebb4e 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6848,6 +6848,9 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat &dcp->brightness.maximum); if (ret) dev_err(dev, "Missing property 'apple,max-brightness'\n"); + /* Checked and applied where the nits backlight is set up. */ + of_property_read_u32(panel_np, "apple,min-brightness", + &dcp->brightness.minimum); } dcp_panel_read_dimensions(dcp, panel_np); diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index a487e9b770aab..02e7403a1c7ec 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -295,6 +295,7 @@ int dcp_backlight_configure(struct apple_dcp *dcp, u32 maximum, void (*kick)(struct apple_dcp *dcp)) { unsigned long flags; + int floor_ret = 0; int ret; if ((dcp->fw_compat != DCP_FIRMWARE_H17P && dcp->fw_compat != DCP_FIRMWARE_V_27_0 && @@ -310,6 +311,9 @@ int dcp_backlight_configure(struct apple_dcp *dcp, u32 maximum, ret = dcp_bl_init(&dcp->backlight.state, maximum, inherited_valid, inherited, default_valid, default_nits); + if (!ret && dcp->brightness.minimum) + floor_ret = dcp_bl_set_minimum(&dcp->backlight.state, + dcp->brightness.minimum); if (!ret && iomfb_is_m4(dcp)) { /* * The J713 panel jumps to new levels, and its first @@ -324,6 +328,12 @@ int dcp_backlight_configure(struct apple_dcp *dcp, u32 maximum, } spin_unlock_irqrestore(&dcp->backlight.lock, flags); mutex_unlock(&dcp->bl_register_mutex); + if (floor_ret) + dev_warn(dcp->dev, "brightness floor %u ignored for a ceiling of %u\n", + dcp->brightness.minimum, maximum); + else if (!ret && dcp->brightness.minimum) + dev_info(dcp->dev, "brightness requests below %u nits are raised to %u nits\n", + dcp->brightness.minimum, dcp->brightness.minimum); if (!ret) schedule_work(&dcp->bl_register_wq); return ret; @@ -874,6 +884,9 @@ static int dcp_set_brightness(struct backlight_device *bd) old = state->target; ret = dcp_bl_request(state, bd->props.brightness, backlight_is_blank(bd), suspended); + /* Read back the level the panel's floor made of the request. */ + if (!ret) + bd->props.brightness = dcp_bl_floor(state, bd->props.brightness); /* A new level restarts the fade from the level presented last. */ fade = !ret && state->fading && state->target != old; if (fade) diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 0045e995885d7..86e810dbd8ae2 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -17,6 +17,8 @@ */ struct dcp_backlight_state { u32 maximum; + /* Lowest level a request can reach, 0 for none: dcp_bl_set_minimum(). */ + u32 minimum; u32 target; u32 level; u32 fade_from; @@ -99,6 +101,29 @@ static inline int dcp_bl_init(struct dcp_backlight_state *state, u32 maximum, return 0; } +/* + * A panel node may name the lowest level a brightness request can reach + * (apple,min-brightness, in nits). A request below it, zero included, is + * raised to it, so a brightness write alone cannot darken such a panel. + * Blanking, DPMS off and suspend are not requests and still present zero. + * A loader level below the floor stays until the first request. + */ +static inline int dcp_bl_set_minimum(struct dcp_backlight_state *state, u32 minimum) +{ + if (!state->ready) + return -ENODATA; + if (minimum >= state->maximum) + return -ERANGE; + state->minimum = minimum; + return 0; +} + +/* The level a request for @nits reaches on this panel. */ +static inline u32 dcp_bl_floor(const struct dcp_backlight_state *state, u32 nits) +{ + return max(nits, state->minimum); +} + /* * A decoded powerlog sample can seed takeover only before Linux control. * It reports the level the panel shows, so the level is then known. @@ -170,6 +195,7 @@ static inline int dcp_bl_request(struct dcp_backlight_state *state, u32 nits, return -ENODATA; if (nits > state->maximum) return -ERANGE; + nits = dcp_bl_floor(state, nits); /* Save/restore clients may echo the reporting default without a change. */ if (state->preserve_inherited && !state->controlled && !state->level_known && state->target == nits) { diff --git a/drivers/gpu/drm/apple/dcp_backlight_test.c b/drivers/gpu/drm/apple/dcp_backlight_test.c index e31fa370b3b4f..b9f888f44f461 100644 --- a/drivers/gpu/drm/apple/dcp_backlight_test.c +++ b/drivers/gpu/drm/apple/dcp_backlight_test.c @@ -84,6 +84,65 @@ static void backlight_range_test(struct kunit *test) KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 600U); } +static void backlight_floor_test(struct kunit *test) +{ + struct dcp_backlight_state state = {}; + struct dcp_backlight_present present; + + KUNIT_EXPECT_EQ(test, dcp_bl_set_minimum(&state, 10), -ENODATA); + KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 1000, false, 0, true, 500), 0); + KUNIT_EXPECT_EQ(test, dcp_bl_set_minimum(&state, 1000), -ERANGE); + KUNIT_EXPECT_EQ(test, state.minimum, 0U); + /* Without a floor zero is a level like any other. */ + state.controlled = true; + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 0U); + + /* With one, zero and every level below it become the floor. */ + KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 1000, false, 0, true, 500), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_set_minimum(&state, 10), 0); + state.controlled = true; + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 10U); + KUNIT_ASSERT_EQ(test, dcp_bl_prepare(&state, true, &present), 0); + KUNIT_EXPECT_EQ(test, present.nits, 10U); + KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, true)); + KUNIT_EXPECT_EQ(test, state.actual, 10U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 9, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 10U); + KUNIT_EXPECT_EQ(test, dcp_bl_prepare(&state, true, &present), -EALREADY); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 11, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 11U); + KUNIT_EXPECT_EQ(test, dcp_bl_request(&state, 1001, false, false), -ERANGE); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 1000, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 1000U); + + /* Display off is not a request: it presents zero and wakes at the floor. */ + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, false, false), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_dpms(&state, false), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_prepare(&state, true, &present), 0); + KUNIT_EXPECT_EQ(test, present.nits, 0U); + KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, true)); + KUNIT_ASSERT_EQ(test, dcp_bl_dpms(&state, true), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_prepare(&state, true, &present), 0); + KUNIT_EXPECT_EQ(test, present.nits, 10U); + KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, true)); + + /* So is a core blank, whatever level comes with it. */ + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, true, false), 0); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 0U); + KUNIT_EXPECT_EQ(test, state.target, 10U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, false, false), 0); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 10U); + + /* A loader level below the floor stays until the first request. */ + KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 1000, true, 4, false, 0), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_set_minimum(&state, 10), 0); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 4U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 10U); +} + static void backlight_dpms_cycles_test(struct kunit *test) { struct dcp_backlight_state state; @@ -856,6 +915,7 @@ static struct kunit_case backlight_cases[] = { KUNIT_CASE(backlight_millinits_takeover_test), KUNIT_CASE(backlight_takeover_test), KUNIT_CASE(backlight_range_test), + KUNIT_CASE(backlight_floor_test), KUNIT_CASE(backlight_dpms_cycles_test), KUNIT_CASE(backlight_blanked_target_test), KUNIT_CASE(backlight_suspend_test), From 0c42db3168103262999f31676fbd2ef0c46e837f Mon Sep 17 00:00:00 2001 From: Chris O'Hearn <137103567+chrisohearn@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:41:12 -0700 Subject: [PATCH 3/4] drm/apple: keep an inherited level across blank and suspend 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 <137103567+chrisohearn@users.noreply.github.com> --- drivers/gpu/drm/apple/dcp_backlight.c | 4 ++-- drivers/gpu/drm/apple/dcp_backlight.h | 8 ++++++- drivers/gpu/drm/apple/dcp_backlight_test.c | 27 ++++++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index 02e7403a1c7ec..7e59e2cc0ae14 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -884,9 +884,9 @@ static int dcp_set_brightness(struct backlight_device *bd) old = state->target; ret = dcp_bl_request(state, bd->props.brightness, backlight_is_blank(bd), suspended); - /* Read back the level the panel's floor made of the request. */ + /* Keep sysfs in sync with the accepted target. */ if (!ret) - bd->props.brightness = dcp_bl_floor(state, bd->props.brightness); + bd->props.brightness = state->target; /* A new level restarts the fade from the level presented last. */ fade = !ret && state->fading && state->target != old; if (fade) diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 86e810dbd8ae2..86ca1c4d54ddd 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -195,7 +195,13 @@ static inline int dcp_bl_request(struct dcp_backlight_state *state, u32 nits, return -ENODATA; if (nits > state->maximum) return -ERANGE; - 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); /* Save/restore clients may echo the reporting default without a change. */ if (state->preserve_inherited && !state->controlled && !state->level_known && state->target == nits) { diff --git a/drivers/gpu/drm/apple/dcp_backlight_test.c b/drivers/gpu/drm/apple/dcp_backlight_test.c index b9f888f44f461..c743caf7de313 100644 --- a/drivers/gpu/drm/apple/dcp_backlight_test.c +++ b/drivers/gpu/drm/apple/dcp_backlight_test.c @@ -128,19 +128,42 @@ static void backlight_floor_test(struct kunit *test) KUNIT_EXPECT_EQ(test, present.nits, 10U); KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, true)); - /* So is a core blank, whatever level comes with it. */ + /* A new level can be requested while blanking. */ KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, true, false), 0); KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 0U); KUNIT_EXPECT_EQ(test, state.target, 10U); KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 0, false, false), 0); KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 10U); - /* A loader level below the floor stays until the first request. */ + /* A loader level below the floor stays across blank and suspend. */ KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 1000, true, 4, false, 0), 0); KUNIT_ASSERT_EQ(test, dcp_bl_set_minimum(&state, 10), 0); KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 4U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, true, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 4U); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 0U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 4U); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 4U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, false, true), 0); + KUNIT_EXPECT_EQ(test, state.target, 4U); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 0U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, false, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 4U); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 4U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, false, false), 0); KUNIT_EXPECT_EQ(test, state.target, 10U); + + /* A same-level write while already blanked still takes the floor. */ + KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 1000, true, 4, false, 0), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_set_minimum(&state, 10), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, true, false), 0); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 4, true, false), 0); + KUNIT_EXPECT_EQ(test, state.target, 10U); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 0U); + KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 10, false, false), 0); + KUNIT_EXPECT_EQ(test, dcp_bl_effective(&state), 10U); } static void backlight_dpms_cycles_test(struct kunit *test) From 08ea507eb7a296083c43bd8ecc135d41a8e48d2b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 29 Nov 2026 11:41:21 +1100 Subject: [PATCH 4/4] drm/apple: dcp_backlight: open-code the floor clamp 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 --- drivers/gpu/drm/apple/dcp_backlight.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 86ca1c4d54ddd..b6933da7446ee 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -121,7 +121,7 @@ static inline int dcp_bl_set_minimum(struct dcp_backlight_state *state, u32 mini /* The level a request for @nits reaches on this panel. */ 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; } /*