From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com, ardb@kernel.org, ilias.apalodimas@linaro.org,
jani.nikula@linux.intel.com, maarten.lankhorst@linux.intel.com,
mripard@kernel.org, simona@ffwll.ch, airlied@gmail.com
Cc: dri-devel@lists.freedesktop.org, linux-efi@vger.kernel.org,
sashiko-reviews@lists.linux.dev,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 1/3] drm/edid: Add drm_edid_get_preferred_size()
Date: Thu, 27 Aug 2026 16:01:37 +0200 [thread overview]
Message-ID: <20260827140726.420734-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20260827140726.420734-1-tzimmermann@suse.de>
Add drm_edid_get_preferred_size() to extract the panel's preferred
display resolution from a given EDID. Required for DRM's panel
orientation quirks.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/drm_edid.c | 40 ++++++++++++++++++++++++++++++++++++++
include/drm/drm_edid.h | 2 ++
2 files changed, 42 insertions(+)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 07970e5b5f65..02cbf8de1128 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2844,6 +2844,46 @@ u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid)
}
EXPORT_SYMBOL(drm_edid_get_panel_id);
+/**
+ * drm_edid_get_preferred_size - Get a panel's preferred size from EDID
+ * @drm_edid: EDID that contains panel ID.
+ * @width: Returns the panel's width in pixels per scanline, if given
+ * @height: Returns the panel's height in scanlines, if given
+ *
+ * This function detects the preferred size of a panel from the given
+ * EDID. There is no such information stored in the EDID block directly,
+ * but the preferred mode often corresponds to the panel's native geometry.
+ *
+ * Return: Zero on success, or a negative errno code otherwise.
+ */
+int drm_edid_get_preferred_size(const struct drm_edid *drm_edid,
+ unsigned int *width, unsigned int *height)
+{
+ const struct edid *edid = drm_edid->edid;
+ const struct detailed_pixel_timing *pt;
+
+ if (drm_edid->size < EDID_LENGTH)
+ return -EINVAL;
+
+ /*
+ * Use whatever the Preferred Timing Descriptor tells us. For old
+ * and obscure displays, we might need better heuristics.
+ */
+
+ if (edid->revision < 4 && !(edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING))
+ return -EINVAL; /* no Preferred Timing Descriptor */
+
+ pt = &edid->detailed_timings[0].data.pixel_data;
+
+ if (*width)
+ *width = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
+ if (*height)
+ *height = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_edid_get_preferred_size);
+
/**
* drm_edid_read_base_block - Get a panel's EDID base block
* @adapter: I2C adapter to use for DDC
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 04f7a7f1f108..981aeeb6ddf9 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -487,6 +487,8 @@ void drm_edid_get_product_id(const struct drm_edid *drm_edid,
void drm_edid_print_product_id(struct drm_printer *p,
const struct drm_edid_product_id *id, bool raw);
u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid);
+int drm_edid_get_preferred_size(const struct drm_edid *drm_edid,
+ unsigned int *width, unsigned int *height);
bool drm_edid_match(const struct drm_edid *drm_edid,
const struct drm_edid_ident *ident);
bool drm_edid_has_quirk(struct drm_connector *connector, enum drm_edid_quirk quirk);
--
2.55.0
next prev parent reply other threads:[~2026-08-27 14:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 14:01 [PATCH 0/3] sysfb: Fix display output on Lenovo D330 (and others) Thomas Zimmermann
2026-08-27 14:01 ` Thomas Zimmermann [this message]
2026-08-27 14:19 ` [PATCH 1/3] drm/edid: Add drm_edid_get_preferred_size() sashiko-bot
2026-08-27 14:40 ` Thomas Zimmermann
2026-08-27 14:01 ` [PATCH 2/3] drm/sysfb: Use preferred panel size for panel orientation quirks Thomas Zimmermann
2026-08-27 14:21 ` sashiko-bot
2026-08-27 14:44 ` Thomas Zimmermann
2026-08-27 14:01 ` [PATCH 3/3] firmware/sysfb: Remove rotation quirk for Lenovo D330 Thomas Zimmermann
2026-08-27 16:56 ` [PATCH 0/3] sysfb: Fix display output on Lenovo D330 (and others) Ard Biesheuvel
2026-08-31 10:34 ` Thomas Zimmermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260827140726.420734-2-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=ardb@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ilias.apalodimas@linaro.org \
--cc=jani.nikula@linux.intel.com \
--cc=javierm@redhat.com \
--cc=linux-efi@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox