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
35 changes: 32 additions & 3 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,21 @@ static int dcp_ext_wait_pmp(struct apple_dcp *dcp)
return 0;
}

/*
* J313 BrightnessLCD::nitsToDBV rejects 395 nits and above. iDAC 1956 is
* accepted and 1957 is not, so 394 is the brightest level that applies.
* apple,max-brightness on this panel is 420; 100% must land on 394.
*/
#define DCP_J313_MAX_NITS 394U

static bool dcp_panel_is_j313(const struct dcp_panel_id *id,
const char *compatible)
{
if (compatible && !strcmp(compatible, "apple,panel-j313"))
return true;
return id && !strcmp(id->name, "J313");
}

static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *data)
{
struct device_node *panel_np;
Expand Down Expand Up @@ -3769,7 +3784,7 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat

if (panel_np) {
const char height_prop[2][16] = { "adj-height-mm", "height-mm" };
const char *compatible;
const char *compatible = NULL;

if (of_device_is_available(panel_np)) {
ret = of_property_read_u32(panel_np, "apple,max-brightness",
Expand All @@ -3782,11 +3797,25 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat
/* use adjusted height as long as the notch is hidden */
of_property_read_u32(panel_np, height_prop[!dcp->notch_height],
&dcp->panel.height_mm);
if (of_property_read_string_index(panel_np, "compatible", 0,
&compatible))
compatible = NULL;
/* The most specific compatible names the panel for its EDID. */
if (iomfb_v14_7_base_edid(dcp) &&
!of_property_read_string_index(panel_np, "compatible", 0, &compatible) &&
if (iomfb_v14_7_base_edid(dcp) && compatible &&
dcp_panel_id_from_compatible(&dcp->panel.id, compatible))
dev_dbg(dev, "no EDID make and product in '%s'\n", compatible);
/*
* Only this panel. The backlight device's maximum is this
* value, so 100% asks the firmware for DCP_J313_MAX_NITS.
*/
if (dcp_panel_is_j313(&dcp->panel.id, compatible) &&
dcp->brightness.maximum > DCP_J313_MAX_NITS) {
dcp->brightness.maximum = DCP_J313_MAX_NITS;
if (dcp->brightness.nits > (int)DCP_J313_MAX_NITS)
dcp->brightness.nits = DCP_J313_MAX_NITS;
dev_info(dev, "capping panel backlight at %u nits\n",
DCP_J313_MAX_NITS);
}

of_node_put(panel_np);
dcp->fixed_connector_type = DRM_MODE_CONNECTOR_eDP;
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/apple/dcp_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ static int dcp_get_brightness(struct backlight_device *bd)
return ret;
}

if (dcp->brightness.nits < 0)
return 0;
if (bd->props.max_brightness > 0 &&
dcp->brightness.nits > bd->props.max_brightness)
return bd->props.max_brightness;
return dcp->brightness.nits;
}

Expand Down
22 changes: 12 additions & 10 deletions drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,12 @@ static void iomfb_cb_pr_publish(struct apple_dcp *dcp, struct iomfb_property *pr
break;
#endif
if (dcp_has_panel(dcp)) {
dcp->brightness.nits = prop->value / dcp->brightness.scale;
u32 nits = prop->value / dcp->brightness.scale;

/* Firmware can report the old 420-nit scale above the cap. */
if (dcp->brightness.maximum && nits > dcp->brightness.maximum)
nits = dcp->brightness.maximum;
dcp->brightness.nits = nits;
/* notify backlight device of the initial brightness */
if (!dcp->brightness.bl_dev && dcp->brightness.maximum > 0)
schedule_work(&dcp->bl_register_wq);
Expand Down Expand Up @@ -2090,19 +2095,16 @@ dcpep_cb_get_tiling_state(struct apple_dcp *dcp,

static u8 dcpep_cb_create_backlight_service(struct apple_dcp *dcp)
{
#if DCP_FW_VER >= DCP_FW_VERSION(26, 0, 0)
/*
* H17P asks during start_ios_gated, before any mode is known, but
* dcp_has_panel() only becomes true once the panel dimensions have been
* parsed. An internal panel always has a backlight, so answer for the
* connector; answering false makes the firmware report that it could
* not find the backlight service.
* Firmware asks during start_ios_gated. On J313 the panel node is
* read first, so width_mm is already set and dcp_has_panel() is
* already true. Answering eDP as well does not change this return
* value. DCP 13.5 still logs that it could not find the backlight
* service, and writes still apply only after a modeset.
* External displays are not eDP.
*/
return dcp_has_panel(dcp) ||
dcp->connector_type == DRM_MODE_CONNECTOR_eDP;
#else
return dcp_has_panel(dcp);
#endif
}

TRAMPOLINE_VOID(trampoline_nop, dcpep_cb_nop);
Expand Down
7 changes: 6 additions & 1 deletion drivers/gpu/drm/apple/systemep.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static int powerlog_report(struct apple_epic_service *service, enum epic_subtype
struct dcp_parse_ctx parse_ctx;
struct apple_dcp *dcp = service->ep->dcp;
int ret;
u32 nits;

/* Later reports must not overwrite a latched hint or Linux's target. */
if (dcp_backlight_active(dcp))
Expand Down Expand Up @@ -110,7 +111,11 @@ static int powerlog_report(struct apple_epic_service *service, enum epic_subtype
return 0;
}

dcp->brightness.nits = mnits.millinits / 1000;
nits = mnits.millinits / 1000;
/* Firmware can report the old 420-nit scale above the cap. */
if (dcp->brightness.maximum && nits > dcp->brightness.maximum)
nits = dcp->brightness.maximum;
dcp->brightness.nits = nits;

return 0;
}
Expand Down
Loading