Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Documentation/devicetree/bindings/display/apple,dcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions drivers/gpu/drm/apple/dcp_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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);
Comment on lines +314 to +316

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

if (!ret && iomfb_is_m4(dcp)) {
/*
* The J713 panel jumps to new levels, and its first
Expand All @@ -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;
Expand Down Expand Up @@ -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);
/* Keep sysfs in sync with the accepted target. */
if (!ret)
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)
Expand Down
32 changes: 32 additions & 0 deletions drivers/gpu/drm/apple/dcp_backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 nits < state->minimum ? state->minimum : nits;
}

/*
* A decoded powerlog sample can seed takeover only before Linux control.
* It reports the level the panel shows, so the level is then known.
Expand Down Expand Up @@ -170,6 +195,13 @@ static inline int dcp_bl_request(struct dcp_backlight_state *state, u32 nits,
return -ENODATA;
if (nits > state->maximum)
return -ERANGE;
/*
* 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);
Comment on lines +202 to +204

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

/* Save/restore clients may echo the reporting default without a change. */
if (state->preserve_inherited && !state->controlled && !state->level_known &&
state->target == nits) {
Expand Down
83 changes: 83 additions & 0 deletions drivers/gpu/drm/apple/dcp_backlight_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,88 @@ 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));

/* 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 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)
{
struct dcp_backlight_state state;
Expand Down Expand Up @@ -856,6 +938,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),
Expand Down
Loading