All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/edid: prefer highest refresh mode within native resolution on eDP
@ 2026-12-02 12:01 cengjianeng
  2026-12-02 12:18 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: cengjianeng @ 2026-12-02 12:01 UTC (permalink / raw)
  To: dri-devel
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	linux-kernel, Jianeng Ceng

From: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>

Some eDP panels advertise the same native resolution at multiple refresh
rates, but mark the lowest refresh rate (typically 60Hz) as the preferred
mode in their EDID. The panel is capable of multi-refresh-rate operation
and is meant to be driven at its highest refresh rate by default, so the
kernel hands userspace a preferred mode below the panel capability. The
compositor then picks a non-preferred mode, or keeps the panel at its
lowest refresh rate until userspace makes an explicit choice.

Re-point DRM_MODE_TYPE_PREFERRED to the mode with the highest vertical
refresh rate among the modes sharing the resolution of the original
preferred mode, for eDP connectors. This keeps the native resolution
selected by the EDID untouched, and only resolves which refresh rate
within that resolution is reported as preferred. The mode ordering and
the panel fixed-mode anchor userspace sees then match the panel's
capability.

This mirrors what vendors ship as an EDID override for such panels, but
handles it generically in the kernel so panels cannot regress on a
factory EDID update.

Tested on eDP panels that report a 60Hz preferred timing while also
supporting 120Hz at the same native resolution: userspace now reports
the 120Hz mode as preferred.

Signed-off-by: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>
---
 drivers/gpu/drm/drm_edid.c | 50 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index b8f882a17c8f..e8a6bdc00e32 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3076,6 +3076,53 @@ static void edid_fixup_preferred(struct drm_connector *connector)
 	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
 }
 
+/*
+ * Walk the mode list for connector and re-point the preferred status to the
+ * mode with the highest vertical refresh rate among the modes that share the
+ * resolution of the current preferred mode.
+ */
+static void edid_fixup_preferred_max_vrefresh(struct drm_connector *connector)
+{
+	struct drm_display_mode *cur_mode, *preferred_mode;
+	int hdisplay, vdisplay;
+
+	if (list_empty(&connector->probed_modes))
+		return;
+
+	preferred_mode = list_first_entry(&connector->probed_modes,
+					  struct drm_display_mode, head);
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) {
+			preferred_mode = cur_mode;
+			break;
+		}
+	}
+
+	hdisplay = preferred_mode->hdisplay;
+	vdisplay = preferred_mode->vdisplay;
+
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (cur_mode->hdisplay != hdisplay || cur_mode->vdisplay != vdisplay)
+			continue;
+
+		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
+	}
+
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (cur_mode->hdisplay != hdisplay || cur_mode->vdisplay != vdisplay)
+			continue;
+
+		if (drm_mode_vrefresh(cur_mode) > drm_mode_vrefresh(preferred_mode))
+			preferred_mode = cur_mode;
+	}
+
+	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
+
+	drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] preferred mode: "
+		    DRM_MODE_FMT "\n", connector->base.id, connector->name,
+		    DRM_MODE_ARG(preferred_mode));
+}
+
 static bool
 mode_is_rb(const struct drm_display_mode *mode)
 {
@@ -7242,6 +7289,9 @@ static int _drm_edid_connector_add_modes(struct drm_connector *connector,
 	    drm_edid_has_internal_quirk(connector, EDID_QUIRK_PREFER_LARGE_75))
 		edid_fixup_preferred(connector);
 
+	if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
+		edid_fixup_preferred_max_vrefresh(connector);
+
 	return num_modes;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 12:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:01 [PATCH] drm/edid: prefer highest refresh mode within native resolution on eDP cengjianeng
2026-12-02 12:18 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.