diff options
author | Hsin-Yi Wang <hsinyi@chromium.org> | 2024-03-07 23:57:42 +0100 |
---|---|---|
committer | Douglas Anderson <dianders@chromium.org> | 2024-03-14 16:22:57 +0100 |
commit | 6e3fdedcf0bc03c852d9fdbb5443f1e43103195f (patch) | |
tree | c8e64f596612f5cefd9b2a9ca6bf2993d7b1ca9d /drivers/gpu/drm/drm_edid.c | |
parent | drm_edid: Add a function to get EDID base block (diff) | |
download | linux-6e3fdedcf0bc03c852d9fdbb5443f1e43103195f.tar.xz linux-6e3fdedcf0bc03c852d9fdbb5443f1e43103195f.zip |
drm/edid: Add a function to match EDID with identity
Create a type drm_edid_ident as the identity of an EDID. Currently it
contains panel id and monitor name.
Create a function that can match a given EDID and an identity:
1. Reject if the panel id doesn't match.
2. If name is not null in identity, try to match it in the detailed timing
blocks. Note that some panel vendors put the monitor name after
EDID_DETAIL_MONITOR_STRING.
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240307230653.1807557-3-hsinyi@chromium.org
Diffstat (limited to 'drivers/gpu/drm/drm_edid.c')
-rw-r--r-- | drivers/gpu/drm/drm_edid.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index ecd6e9255b67..8fed2131f424 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -102,6 +102,11 @@ struct detailed_mode_closure { int modes; }; +struct drm_edid_match_closure { + const struct drm_edid_ident *ident; + bool matched; +}; + #define LEVEL_DMT 0 #define LEVEL_GTF 1 #define LEVEL_GTF2 2 @@ -5456,6 +5461,66 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db) } static void +match_identity(const struct detailed_timing *timing, void *data) +{ + struct drm_edid_match_closure *closure = data; + unsigned int i; + const char *name = closure->ident->name; + unsigned int name_len = strlen(name); + const char *desc = timing->data.other_data.data.str.str; + unsigned int desc_len = ARRAY_SIZE(timing->data.other_data.data.str.str); + + if (name_len > desc_len || + !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) || + is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING))) + return; + + if (strncmp(name, desc, name_len)) + return; + + for (i = name_len; i < desc_len; i++) { + if (desc[i] == '\n') + break; + /* Allow white space before EDID string terminator. */ + if (!isspace(desc[i])) + return; + } + + closure->matched = true; +} + +/** + * drm_edid_match - match drm_edid with given identity + * @drm_edid: EDID + * @ident: the EDID identity to match with + * + * Check if the EDID matches with the given identity. + * + * Return: True if the given identity matched with EDID, false otherwise. + */ +bool drm_edid_match(const struct drm_edid *drm_edid, + const struct drm_edid_ident *ident) +{ + if (!drm_edid || drm_edid_get_panel_id(drm_edid) != ident->panel_id) + return false; + + /* Match with name only if it's not NULL. */ + if (ident->name) { + struct drm_edid_match_closure closure = { + .ident = ident, + .matched = false, + }; + + drm_for_each_detailed_block(drm_edid, match_identity, &closure); + + return closure.matched; + } + + return true; +} +EXPORT_SYMBOL(drm_edid_match); + +static void monitor_name(const struct detailed_timing *timing, void *data) { const char **res = data; |