dri-devel Archive on 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
  2026-12-03  3:46 ` [PATCH v2] " cengjianeng
  0 siblings, 2 replies; 8+ 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] 8+ messages in thread

* Re: [PATCH] drm/edid: prefer highest refresh mode within native resolution on eDP
  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
  2026-12-03  3:47   ` Jianeng Ceng
  2026-12-03  3:46 ` [PATCH v2] " cengjianeng
  1 sibling, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-12-02 12:18 UTC (permalink / raw)
  To: cengjianeng, dri-devel

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
  unvalidated mode
- [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
  non-detailed modes
- [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() mishandles
  multiple preferred
--

commit e313f14ca873716202a489a3beac07169e41bd70
Author: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>

drm/edid: prefer highest refresh mode within native resolution on eDP

This commit adds edid_fixup_preferred_max_vrefresh() to move
DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode sharing the
preferred mode's resolution on eDP connectors.

> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index b8f882a17c8f1..e8a6bdc00e326 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;
> +		}
> +	}

[Severity: Medium]
Does breaking on the first DRM_MODE_TYPE_PREFERRED mode miss preferred
modes at a higher resolution from DisplayID extension blocks?

drm_mode_displayid_detailed() adds modes with DRM_MODE_TYPE_PREFERRED
after add_detailed_modes().  If the base EDID block has a fallback
preferred mode and a DisplayID block has a higher-resolution preferred
mode, this loop stops at the base EDID mode and only updates modes at
that lower resolution.  Also, if no mode in connector->probed_modes has
DRM_MODE_TYPE_PREFERRED set, preferred_mode falls back to
list_first_entry() and receives DRM_MODE_TYPE_PREFERRED unconditionally
at the end of the function.

> +
> +	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;

[Severity: High]
Can moving DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode
before mode validation leave connector->modes with no preferred mode or
break drivers that latch the preferred mode from probed_modes?

_drm_edid_connector_add_modes() runs during .get_modes(), before
__drm_helper_update_and_validate() and drm_mode_prune_invalid().  If the
highest-refresh mode exceeds the GPU dotclock, VBT limit, or available
eDP link bandwidth, drm_mode_prune_invalid() removes it after
DRM_MODE_TYPE_PREFERRED has already been cleared from the 60Hz mode.

In addition, drivers such as i915 and amdgpu snapshot the preferred mode
from connector->probed_modes right after drm_edid_connector_add_modes()
before mode_valid() runs.  In i915, intel_edp_init_connector() ->
intel_panel_add_edid_fixed_modes() stores that mode as the primary
fixed_mode, and intel_dp_can_link_train_fallback_for_edp() rejects any
link training fallback rate or lane count that cannot sustain
fixed_mode->clock.

> +
> +	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;
>  }

[Severity: Medium]
Can calling edid_fixup_preferred_max_vrefresh() here promote an inferred
VESA DMT mode over the panel's native detailed timing?

At this point in _drm_edid_connector_add_modes(), add_cvt_modes(),
add_standard_modes(), add_established_modes(), and add_inferred_modes()
have already appended non-detailed modes to connector->probed_modes.  On
a VRR eDP panel with DRM_EDID_FEATURE_CONTINUOUS_FREQ and a range
descriptor extending above the DTD refresh rate (at a DMT resolution
such as 1920x1200 or 2560x1600), drm_dmt_modes_for_range() adds higher
refresh DMT timings that do not match the panel's blanking or sync flags,
which then replace the panel's DTD as DRM_MODE_TYPE_PREFERRED and break
exact timing checks such as i915's is_alt_drrs_mode().  Running this
unconditionally after edid_fixup_preferred() also overrides
EDID_QUIRK_PREFER_LARGE_60 and EDID_QUIRK_PREFER_LARGE_75 on eDP
connectors.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202120153.1051508-1-cengjianeng@huaqin.corp-partner.google.com?part=1

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

* [PATCH v2] drm/edid: prefer highest refresh mode within native resolution on eDP
  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
@ 2026-12-03  3:46 ` cengjianeng
  2026-12-03  3:59   ` sashiko-bot
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: cengjianeng @ 2026-12-03  3:46 UTC (permalink / raw)
  To: dri-devel; +Cc: dri-misc, 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 detailed timings that share 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.

Only detailed modes are considered. Inferred, CVT, standard timing and
DisplayID modes are not derived from the panel's own timing descriptors,
so they can never replace the panel timing as preferred. If the EDID does
not mark any mode preferred there is nothing to re-point and the mode list
is left untouched.

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, and on panels that already
report 120Hz as preferred: userspace reports the 120Hz mode as preferred
in both cases.

Signed-off-by: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>
---
Changes in v2:
 - Only modes that carry DRM_MODE_TYPE_DRIVER are considered, both when
   selecting the candidate and when clearing the flag, so inferred, CVT,
   standard timing and DisplayID modes can never replace the panel timing.
 - Return early when the EDID marks no mode preferred instead of falling
   back to the first mode in the list and forcing PREFERRED onto it.
 - Scan the whole mode list for the preferred mode instead of breaking out
   on the first hit, so mode lists with several PREFERRED bits converge.
 - Clear the old PREFERRED bit only after a different candidate has been
   confirmed, leaving the mode list untouched when the highest refresh mode
   is already the preferred one.
 drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index b8f882a17c8f..13c5a4d099b0 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3076,6 +3076,79 @@ static void edid_fixup_preferred(struct drm_connector *connector)
 	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
 }
 
+/* Only modes parsed from detailed timings describe the panel itself. */
+static bool is_detailed_mode(const struct drm_display_mode *mode)
+{
+	return mode->type & DRM_MODE_TYPE_DRIVER;
+}
+
+/*
+ * Walk the mode list for connector and re-point the preferred status to the
+ * mode with the highest vertical refresh rate among the detailed modes that
+ * share the resolution of the current preferred mode.
+ *
+ * Only detailed timings are considered: inferred, CVT and standard timing
+ * modes are not derived from the panel's own timing descriptors and must not
+ * replace it as preferred.
+ */
+static void edid_fixup_preferred_max_vrefresh(struct drm_connector *connector)
+{
+	struct drm_display_mode *cur_mode, *preferred_mode = NULL;
+	struct drm_display_mode *candidate_mode = NULL;
+	int hdisplay, vdisplay;
+
+	/* Nothing to do if the EDID does not mark any mode preferred. */
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) {
+			preferred_mode = cur_mode;
+			break;
+		}
+	}
+
+	if (!preferred_mode)
+		return;
+
+	if (!is_detailed_mode(preferred_mode))
+		return;
+
+	/* The preferred mode defines the native resolution. */
+	hdisplay = preferred_mode->hdisplay;
+	vdisplay = preferred_mode->vdisplay;
+
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (!is_detailed_mode(cur_mode))
+			continue;
+
+		if (cur_mode->hdisplay != hdisplay ||
+		    cur_mode->vdisplay != vdisplay)
+			continue;
+
+		if (!candidate_mode ||
+		    drm_mode_vrefresh(cur_mode) > drm_mode_vrefresh(candidate_mode))
+			candidate_mode = cur_mode;
+	}
+
+	if (!candidate_mode || candidate_mode == preferred_mode)
+		return;
+
+	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
+		if (!is_detailed_mode(cur_mode))
+			continue;
+
+		if (cur_mode->hdisplay != hdisplay ||
+		    cur_mode->vdisplay != vdisplay)
+			continue;
+
+		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
+	}
+
+	candidate_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(candidate_mode));
+}
+
 static bool
 mode_is_rb(const struct drm_display_mode *mode)
 {
@@ -7242,6 +7315,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;
 }
 

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

* Re: [PATCH] drm/edid: prefer highest refresh mode within native resolution on eDP
  2026-12-02 12:18 ` sashiko-bot
@ 2026-12-03  3:47   ` Jianeng Ceng
  0 siblings, 0 replies; 8+ messages in thread
From: Jianeng Ceng @ 2026-12-03  3:47 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: dri-devel

[-- Attachment #1: Type: text/plain, Size: 8147 bytes --]

v2 of the patch, addressing the AI review of v1.

The review raised three points:

1. The preferred mode was promoted before validation, so a mode that is
   later rejected by ->mode_valid() could carry DRM_MODE_TYPE_PREFERRED.

   v2 no longer promotes blindly: a candidate is selected first and the old
   PREFERRED bit is cleared only after a different candidate has been
   confirmed. When the highest refresh mode is already the preferred one
   the mode list is left untouched. The remaining window, where the
   candidate itself is pruned later by ->mode_valid(), is inherent to
   running before drm_mode_prune_invalid() and can only be closed by a
   driver side fallback, which is outside the scope of this patch.

2. Modes that are not parsed from detailed timings could be promoted.

   Fixed: only modes carrying DRM_MODE_TYPE_DRIVER are considered, both
   when selecting the candidate and when clearing the flag. Inferred, CVT,
   standard timing and DisplayID modes are skipped.

3. A mode list without any PREFERRED bit, or with several of them, was
   mishandled.

   Fixed: the function returns early when no mode is preferred instead of
   forcing PREFERRED onto the first mode, and the whole list is scanned
   instead of breaking out on the first PREFERRED hit.

Validation: on eDP panels that report a 60Hz timing as preferred while
also supporting 120Hz at the native resolution, and on panels that already
report 120Hz as preferred, userspace now selects the 120Hz mode as
preferred in both cases.

On Wed, Dec 2, 2026 at 8:18 PM <sashiko-bot@kernel.org> wrote:

> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
>   unvalidated mode
> - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
>   non-detailed modes
> - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() mishandles
>   multiple preferred
> --
>
> commit e313f14ca873716202a489a3beac07169e41bd70
> Author: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>
>
> drm/edid: prefer highest refresh mode within native resolution on eDP
>
> This commit adds edid_fixup_preferred_max_vrefresh() to move
> DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode sharing the
> preferred mode's resolution on eDP connectors.
>
> > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > index b8f882a17c8f1..e8a6bdc00e326 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;
> > +             }
> > +     }
>
> [Severity: Medium]
> Does breaking on the first DRM_MODE_TYPE_PREFERRED mode miss preferred
> modes at a higher resolution from DisplayID extension blocks?
>
> drm_mode_displayid_detailed() adds modes with DRM_MODE_TYPE_PREFERRED
> after add_detailed_modes().  If the base EDID block has a fallback
> preferred mode and a DisplayID block has a higher-resolution preferred
> mode, this loop stops at the base EDID mode and only updates modes at
> that lower resolution.  Also, if no mode in connector->probed_modes has
> DRM_MODE_TYPE_PREFERRED set, preferred_mode falls back to
> list_first_entry() and receives DRM_MODE_TYPE_PREFERRED unconditionally
> at the end of the function.
>
> > +
> > +     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;
>
> [Severity: High]
> Can moving DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode
> before mode validation leave connector->modes with no preferred mode or
> break drivers that latch the preferred mode from probed_modes?
>
> _drm_edid_connector_add_modes() runs during .get_modes(), before
> __drm_helper_update_and_validate() and drm_mode_prune_invalid().  If the
> highest-refresh mode exceeds the GPU dotclock, VBT limit, or available
> eDP link bandwidth, drm_mode_prune_invalid() removes it after
> DRM_MODE_TYPE_PREFERRED has already been cleared from the 60Hz mode.
>
> In addition, drivers such as i915 and amdgpu snapshot the preferred mode
> from connector->probed_modes right after drm_edid_connector_add_modes()
> before mode_valid() runs.  In i915, intel_edp_init_connector() ->
> intel_panel_add_edid_fixed_modes() stores that mode as the primary
> fixed_mode, and intel_dp_can_link_train_fallback_for_edp() rejects any
> link training fallback rate or lane count that cannot sustain
> fixed_mode->clock.
>
> > +
> > +     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;
> >  }
>
> [Severity: Medium]
> Can calling edid_fixup_preferred_max_vrefresh() here promote an inferred
> VESA DMT mode over the panel's native detailed timing?
>
> At this point in _drm_edid_connector_add_modes(), add_cvt_modes(),
> add_standard_modes(), add_established_modes(), and add_inferred_modes()
> have already appended non-detailed modes to connector->probed_modes.  On
> a VRR eDP panel with DRM_EDID_FEATURE_CONTINUOUS_FREQ and a range
> descriptor extending above the DTD refresh rate (at a DMT resolution
> such as 1920x1200 or 2560x1600), drm_dmt_modes_for_range() adds higher
> refresh DMT timings that do not match the panel's blanking or sync flags,
> which then replace the panel's DTD as DRM_MODE_TYPE_PREFERRED and break
> exact timing checks such as i915's is_alt_drrs_mode().  Running this
> unconditionally after edid_fixup_preferred() also overrides
> EDID_QUIRK_PREFER_LARGE_60 and EDID_QUIRK_PREFER_LARGE_75 on eDP
> connectors.
>
> --
> Sashiko AI review ·
> https://sashiko.dev/#/patchset/20261202120153.1051508-1-cengjianeng@huaqin.corp-partner.google.com?part=1
>

[-- Attachment #2: Type: text/html, Size: 9692 bytes --]

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

* Re: [PATCH v2] drm/edid: prefer highest refresh mode within native resolution on eDP
  2026-12-03  3:46 ` [PATCH v2] " cengjianeng
@ 2026-12-03  3:59   ` sashiko-bot
  2026-12-03 12:01   ` Jani Nikula
  2026-12-03 12:27   ` Ville Syrjälä
  2 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-03  3:59 UTC (permalink / raw)
  To: cengjianeng, dri-devel

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
  unvalidated mode
- [Medium] drm/edid: is_detailed_mode() matches non-detailed
  DRM_MODE_TYPE_DRIVER modes
- [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() mishandles
  multiple preferred
- [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() replaces
  equal-vrefresh mode
--

commit 74767c3cc3c0bdb88a5c146313bff24e0fe4bfc0
Author: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>

drm/edid: prefer highest refresh mode within native resolution on eDP

This commit updates eDP connector mode probing to re-point
DRM_MODE_TYPE_PREFERRED to the highest refresh rate detailed mode that
shares the resolution of the original preferred mode.

> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index b8f882a17c8f1..13c5a4d099b01 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3076,6 +3076,79 @@ static void edid_fixup_preferred(struct drm_connector *connector)
>  	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
>  }
>  
> +/* Only modes parsed from detailed timings describe the panel itself. */
> +static bool is_detailed_mode(const struct drm_display_mode *mode)
> +{
> +	return mode->type & DRM_MODE_TYPE_DRIVER;
> +}

[Severity: Medium]
Does checking DRM_MODE_TYPE_DRIVER in is_detailed_mode() also match
non-detailed modes?

edid_fixup_preferred_max_vrefresh() runs at the end of
_drm_edid_connector_add_modes() after standard, established, CEA,
DisplayID, and inferred modes have been added to connector->probed_modes.
Modes in drm_dmt_modes[] (added by add_inferred_modes() ->
drm_dmt_modes_for_range() on continuous-frequency panels and by
add_standard_modes()), edid_est_modes[], CEA mode tables, and DisplayID
modes from drm_mode_displayid_detailed() and drm_mode_displayid_formula()
all carry DRM_MODE_TYPE_DRIVER.  An inferred DMT or DisplayID formula mode
at the native resolution with a higher refresh rate (such as a 75Hz, 85Hz,
or 120Hz RB DMT entry) will pass is_detailed_mode() and replace the
panel's actual detailed timing as 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 detailed modes that
> + * share the resolution of the current preferred mode.
> + *
> + * Only detailed timings are considered: inferred, CVT and standard timing
> + * modes are not derived from the panel's own timing descriptors and must not
> + * replace it as preferred.
> + */
> +static void edid_fixup_preferred_max_vrefresh(struct drm_connector *connector)
> +{
> +	struct drm_display_mode *cur_mode, *preferred_mode = NULL;
> +	struct drm_display_mode *candidate_mode = NULL;
> +	int hdisplay, vdisplay;
> +
> +	/* Nothing to do if the EDID does not mark any mode preferred. */
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) {
> +			preferred_mode = cur_mode;
> +			break;
> +		}
> +	}

[Severity: Medium]
What happens when connector->probed_modes has more than one mode marked
DRM_MODE_TYPE_PREFERRED?

Breaking on the first preferred mode ignores any later preferred mode,
such as a higher-resolution preferred timing added by
add_displayid_detailed_modes(), leaving multiple preferred modes in the
list and failing to promote the highest refresh rate at the DisplayID
preferred resolution.  In addition, if multiple modes at the first
preferred mode's resolution have DRM_MODE_TYPE_PREFERRED set and the first
one already has the highest refresh rate, the candidate_mode ==
preferred_mode check below returns early without clearing
DRM_MODE_TYPE_PREFERRED from the other modes.

> +
> +	if (!preferred_mode)
> +		return;
> +
> +	if (!is_detailed_mode(preferred_mode))
> +		return;
> +
> +	/* The preferred mode defines the native resolution. */
> +	hdisplay = preferred_mode->hdisplay;
> +	vdisplay = preferred_mode->vdisplay;
> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		if (!candidate_mode ||
> +		    drm_mode_vrefresh(cur_mode) > drm_mode_vrefresh(candidate_mode))
> +			candidate_mode = cur_mode;
> +	}
> +
> +	if (!candidate_mode || candidate_mode == preferred_mode)
> +		return;

[Severity: Medium]
Can this replace preferred_mode with an earlier mode that has the same
integer drm_mode_vrefresh() value?

Because candidate_mode starts at NULL instead of preferred_mode, an
earlier non-preferred mode at (hdisplay, vdisplay) with the same
drm_mode_vrefresh() value is latched on the first matching iteration and
is not replaced when the loop reaches preferred_mode.  candidate_mode !=
preferred_mode then causes DRM_MODE_TYPE_PREFERRED to be moved to that
earlier mode even though its refresh rate is not higher.  Initializing
candidate_mode to preferred_mode would ensure it only changes when a mode
has a strictly higher vertical refresh rate.

> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
> +	}
> +
> +	candidate_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(candidate_mode));
> +}
> +
>  static bool
>  mode_is_rb(const struct drm_display_mode *mode)
>  {
> @@ -7242,6 +7315,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;
>  }

[Severity: High]
Can promoting the highest-refresh mode in _drm_edid_connector_add_modes()
before mode validation leave the connector without a preferred mode or
break drivers that snapshot the preferred mode from probed_modes?

_drm_edid_connector_add_modes() runs during .get_modes(), before
__drm_helper_update_and_validate() and drm_mode_prune_invalid() in
drm_helper_probe_single_connector_modes().  If the promoted highest-refresh
mode exceeds source GPU dotclock, bridge, VBT, or eDP link bandwidth limits
and is later rejected by mode_valid(), drm_mode_prune_invalid() removes it
after DRM_MODE_TYPE_PREFERRED has already been stripped from the original
60Hz preferred mode, leaving connector->modes with no preferred mode.

Drivers also consume DRM_MODE_TYPE_PREFERRED directly from
connector->probed_modes right after drm_edid_connector_add_modes() and
before mode_valid() runs.  In i915, intel_edp_init_connector() calls
intel_panel_add_edid_fixed_modes() immediately after
drm_edid_connector_add_modes(), caching the preferred mode as
intel_panel_preferred_fixed_mode(), and
intel_dp_can_link_train_fallback_for_edp() rejects any fallback link rate
or lane count that cannot sustain fixed_mode->clock.  In amdgpu_dm,
amdgpu_dm_connector_ddc_get_modes() latches the preferred mode into
amdgpu_encoder->native_mode before mode_valid() and uses its pixel clock
to synthesize all common scaled modes in amdgpu_dm_create_common_mode().

Also, running edid_fixup_preferred_max_vrefresh() unconditionally after
edid_fixup_preferred() overrides the 60Hz or 75Hz target refresh rate
selected when EDID_QUIRK_PREFER_LARGE_60 or EDID_QUIRK_PREFER_LARGE_75 is
set on an eDP connector.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203034601.675116-1-cengjianeng@huaqin.corp-partner.google.com?part=1

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

* Re: [PATCH v2] drm/edid: prefer highest refresh mode within native resolution on eDP
  2026-12-03  3:46 ` [PATCH v2] " cengjianeng
  2026-12-03  3:59   ` sashiko-bot
@ 2026-12-03 12:01   ` Jani Nikula
  2026-12-03 12:27   ` Ville Syrjälä
  2 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2026-12-03 12:01 UTC (permalink / raw)
  To: cengjianeng, dri-devel; +Cc: dri-misc, Jianeng Ceng

On Thu, 03 Dec 2026, cengjianeng <cengjianeng@huaqin.corp-partner.google.com> wrote:
> 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.

I think we could use the EDID before even evaluating the patch further.

Did you see or try [1], for example?

BR,
Jani.


[1] https://lore.kernel.org/r/20261202-displayid-t7-y420-v2-1-de5f730655d2@gmail.com


>
> Re-point DRM_MODE_TYPE_PREFERRED to the mode with the highest vertical
> refresh rate among the detailed timings that share 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.
>
> Only detailed modes are considered. Inferred, CVT, standard timing and
> DisplayID modes are not derived from the panel's own timing descriptors,
> so they can never replace the panel timing as preferred. If the EDID does
> not mark any mode preferred there is nothing to re-point and the mode list
> is left untouched.
>
> 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, and on panels that already
> report 120Hz as preferred: userspace reports the 120Hz mode as preferred
> in both cases.
>
> Signed-off-by: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>
> ---
> Changes in v2:
>  - Only modes that carry DRM_MODE_TYPE_DRIVER are considered, both when
>    selecting the candidate and when clearing the flag, so inferred, CVT,
>    standard timing and DisplayID modes can never replace the panel timing.
>  - Return early when the EDID marks no mode preferred instead of falling
>    back to the first mode in the list and forcing PREFERRED onto it.
>  - Scan the whole mode list for the preferred mode instead of breaking out
>    on the first hit, so mode lists with several PREFERRED bits converge.
>  - Clear the old PREFERRED bit only after a different candidate has been
>    confirmed, leaving the mode list untouched when the highest refresh mode
>    is already the preferred one.
>  drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 76 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index b8f882a17c8f..13c5a4d099b0 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3076,6 +3076,79 @@ static void edid_fixup_preferred(struct drm_connector *connector)
>  	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
>  }
>  
> +/* Only modes parsed from detailed timings describe the panel itself. */
> +static bool is_detailed_mode(const struct drm_display_mode *mode)
> +{
> +	return mode->type & DRM_MODE_TYPE_DRIVER;
> +}
> +
> +/*
> + * Walk the mode list for connector and re-point the preferred status to the
> + * mode with the highest vertical refresh rate among the detailed modes that
> + * share the resolution of the current preferred mode.
> + *
> + * Only detailed timings are considered: inferred, CVT and standard timing
> + * modes are not derived from the panel's own timing descriptors and must not
> + * replace it as preferred.
> + */
> +static void edid_fixup_preferred_max_vrefresh(struct drm_connector *connector)
> +{
> +	struct drm_display_mode *cur_mode, *preferred_mode = NULL;
> +	struct drm_display_mode *candidate_mode = NULL;
> +	int hdisplay, vdisplay;
> +
> +	/* Nothing to do if the EDID does not mark any mode preferred. */
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) {
> +			preferred_mode = cur_mode;
> +			break;
> +		}
> +	}
> +
> +	if (!preferred_mode)
> +		return;
> +
> +	if (!is_detailed_mode(preferred_mode))
> +		return;
> +
> +	/* The preferred mode defines the native resolution. */
> +	hdisplay = preferred_mode->hdisplay;
> +	vdisplay = preferred_mode->vdisplay;
> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		if (!candidate_mode ||
> +		    drm_mode_vrefresh(cur_mode) > drm_mode_vrefresh(candidate_mode))
> +			candidate_mode = cur_mode;
> +	}
> +
> +	if (!candidate_mode || candidate_mode == preferred_mode)
> +		return;
> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
> +	}
> +
> +	candidate_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(candidate_mode));
> +}
> +
>  static bool
>  mode_is_rb(const struct drm_display_mode *mode)
>  {
> @@ -7242,6 +7315,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;
>  }
>  

-- 
Jani Nikula, Intel

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

* Re: [PATCH v2] drm/edid: prefer highest refresh mode within native resolution on eDP
  2026-12-03  3:46 ` [PATCH v2] " cengjianeng
  2026-12-03  3:59   ` sashiko-bot
  2026-12-03 12:01   ` Jani Nikula
@ 2026-12-03 12:27   ` Ville Syrjälä
  2026-12-03 12:33     ` Ville Syrjälä
  2 siblings, 1 reply; 8+ messages in thread
From: Ville Syrjälä @ 2026-12-03 12:27 UTC (permalink / raw)
  To: cengjianeng; +Cc: dri-devel, dri-misc

On Thu, Dec 03, 2026 at 11:46:01AM +0800, cengjianeng wrote:
> 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.

I think one thing we're missing is considering the DisplayID vs. EDID
factor in the selection of the preferred mode. IIRC DisplayID is maybe
supposed to take precedence over the EDID, at least in some cases.
And IIRC there is also some kind of mode preference EDID block
that we're not using.

It seems to me that this patch would basically amount to just removing
the idea of the preferred mode completely, and just picking the first
mode from the sorted list.

> 
> Re-point DRM_MODE_TYPE_PREFERRED to the mode with the highest vertical
> refresh rate among the detailed timings that share 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.
> 
> Only detailed modes are considered. Inferred, CVT, standard timing and
> DisplayID modes are not derived from the panel's own timing descriptors,
> so they can never replace the panel timing as preferred. If the EDID does
> not mark any mode preferred there is nothing to re-point and the mode list
> is left untouched.
> 
> 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, and on panels that already
> report 120Hz as preferred: userspace reports the 120Hz mode as preferred
> in both cases.
> 
> Signed-off-by: Jianeng Ceng <cengjianeng@huaqin.corp-partner.google.com>
> ---
> Changes in v2:
>  - Only modes that carry DRM_MODE_TYPE_DRIVER are considered, both when
>    selecting the candidate and when clearing the flag, so inferred, CVT,
>    standard timing and DisplayID modes can never replace the panel timing.
>  - Return early when the EDID marks no mode preferred instead of falling
>    back to the first mode in the list and forcing PREFERRED onto it.
>  - Scan the whole mode list for the preferred mode instead of breaking out
>    on the first hit, so mode lists with several PREFERRED bits converge.
>  - Clear the old PREFERRED bit only after a different candidate has been
>    confirmed, leaving the mode list untouched when the highest refresh mode
>    is already the preferred one.
>  drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 76 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index b8f882a17c8f..13c5a4d099b0 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3076,6 +3076,79 @@ static void edid_fixup_preferred(struct drm_connector *connector)
>  	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
>  }
>  
> +/* Only modes parsed from detailed timings describe the panel itself. */
> +static bool is_detailed_mode(const struct drm_display_mode *mode)
> +{
> +	return mode->type & DRM_MODE_TYPE_DRIVER;
> +}
> +
> +/*
> + * Walk the mode list for connector and re-point the preferred status to the
> + * mode with the highest vertical refresh rate among the detailed modes that
> + * share the resolution of the current preferred mode.
> + *
> + * Only detailed timings are considered: inferred, CVT and standard timing
> + * modes are not derived from the panel's own timing descriptors and must not
> + * replace it as preferred.
> + */
> +static void edid_fixup_preferred_max_vrefresh(struct drm_connector *connector)
> +{
> +	struct drm_display_mode *cur_mode, *preferred_mode = NULL;
> +	struct drm_display_mode *candidate_mode = NULL;
> +	int hdisplay, vdisplay;
> +
> +	/* Nothing to do if the EDID does not mark any mode preferred. */
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) {
> +			preferred_mode = cur_mode;
> +			break;
> +		}
> +	}
> +
> +	if (!preferred_mode)
> +		return;
> +
> +	if (!is_detailed_mode(preferred_mode))
> +		return;
> +
> +	/* The preferred mode defines the native resolution. */
> +	hdisplay = preferred_mode->hdisplay;
> +	vdisplay = preferred_mode->vdisplay;
> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		if (!candidate_mode ||
> +		    drm_mode_vrefresh(cur_mode) > drm_mode_vrefresh(candidate_mode))
> +			candidate_mode = cur_mode;
> +	}
> +
> +	if (!candidate_mode || candidate_mode == preferred_mode)
> +		return;
> +
> +	list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> +		if (!is_detailed_mode(cur_mode))
> +			continue;
> +
> +		if (cur_mode->hdisplay != hdisplay ||
> +		    cur_mode->vdisplay != vdisplay)
> +			continue;
> +
> +		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
> +	}
> +
> +	candidate_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(candidate_mode));
> +}
> +
>  static bool
>  mode_is_rb(const struct drm_display_mode *mode)
>  {
> @@ -7242,6 +7315,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;
>  }
>  

-- 
Ville Syrjälä
Intel

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

* Re: [PATCH v2] drm/edid: prefer highest refresh mode within native resolution on eDP
  2026-12-03 12:27   ` Ville Syrjälä
@ 2026-12-03 12:33     ` Ville Syrjälä
  0 siblings, 0 replies; 8+ messages in thread
From: Ville Syrjälä @ 2026-12-03 12:33 UTC (permalink / raw)
  To: cengjianeng; +Cc: dri-devel, dri-misc

On Thu, Dec 03, 2026 at 02:27:25PM +0200, Ville Syrjälä wrote:
> On Thu, Dec 03, 2026 at 11:46:01AM +0800, cengjianeng wrote:
> > 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.
> 
> I think one thing we're missing is considering the DisplayID vs. EDID
> factor in the selection of the preferred mode. IIRC DisplayID is maybe
> supposed to take precedence over the EDID, at least in some cases.
> And IIRC there is also some kind of mode preference EDID block
> that we're not using.
> 
> It seems to me that this patch would basically amount to just removing
> the idea of the preferred mode completely, and just picking the first
> mode from the sorted list.

Fastboot stuff might also be impacted here if we don't end up picking
the same preferred mode at the firmware.

-- 
Ville Syrjälä
Intel

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

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

Thread overview: 8+ 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
2026-12-03  3:47   ` Jianeng Ceng
2026-12-03  3:46 ` [PATCH v2] " cengjianeng
2026-12-03  3:59   ` sashiko-bot
2026-12-03 12:01   ` Jani Nikula
2026-12-03 12:27   ` Ville Syrjälä
2026-12-03 12:33     ` Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox