--- /dev/null
+From 1cbc1f0d324ba6c4d1b10ac6362b5e0b029f63d5 Mon Sep 17 00:00:00 2001
+From: Jani Nikula <jani.nikula@intel.com>
+Date: Wed, 4 Jan 2023 12:05:16 +0200
+Subject: drm/edid: fix AVI infoframe aspect ratio handling
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Jani Nikula <jani.nikula@intel.com>
+
+commit 1cbc1f0d324ba6c4d1b10ac6362b5e0b029f63d5 upstream.
+
+We try to avoid sending VICs defined in the later specs in AVI
+infoframes to sinks that conform to the earlier specs, to not upset
+them, and use 0 for the VIC instead. However, we do this detection and
+conversion to 0 too early, as we'll need the actual VIC to figure out
+the aspect ratio.
+
+In particular, for a mode with 64:27 aspect ratio, 0 for VIC fails the
+AVI infoframe generation altogether with -EINVAL.
+
+Separate the VIC lookup from the "filtering", and postpone the
+filtering, to use the proper VIC for aspect ratio handling, and the 0
+VIC for the infoframe video code as needed.
+
+Reported-by: William Tseng <william.tseng@intel.com>
+Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/6153
+References: https://lore.kernel.org/r/20220920062316.43162-1-william.tseng@intel.com
+Cc: <stable@vger.kernel.org>
+Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/c3e78cc6d01ed237f71ad0038826b08d83d75eef.1672826282.git.jani.nikula@intel.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/gpu/drm/drm_edid.c | 21 ++++++++++++---------
+ 1 file changed, 12 insertions(+), 9 deletions(-)
+
+--- a/drivers/gpu/drm/drm_edid.c
++++ b/drivers/gpu/drm/drm_edid.c
+@@ -6885,8 +6885,6 @@ static u8 drm_mode_hdmi_vic(const struct
+ static u8 drm_mode_cea_vic(const struct drm_connector *connector,
+ const struct drm_display_mode *mode)
+ {
+- u8 vic;
+-
+ /*
+ * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
+ * we should send its VIC in vendor infoframes, else send the
+@@ -6896,13 +6894,18 @@ static u8 drm_mode_cea_vic(const struct
+ if (drm_mode_hdmi_vic(connector, mode))
+ return 0;
+
+- vic = drm_match_cea_mode(mode);
++ return drm_match_cea_mode(mode);
++}
+
+- /*
+- * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
+- * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
+- * have to make sure we dont break HDMI 1.4 sinks.
+- */
++/*
++ * Avoid sending VICs defined in HDMI 2.0 in AVI infoframes to sinks that
++ * conform to HDMI 1.4.
++ *
++ * HDMI 1.4 (CTA-861-D) VIC range: [1..64]
++ * HDMI 2.0 (CTA-861-F) VIC range: [1..107]
++ */
++static u8 vic_for_avi_infoframe(const struct drm_connector *connector, u8 vic)
++{
+ if (!is_hdmi2_sink(connector) && vic > 64)
+ return 0;
+
+@@ -6978,7 +6981,7 @@ drm_hdmi_avi_infoframe_from_display_mode
+ picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+ }
+
+- frame->video_code = vic;
++ frame->video_code = vic_for_avi_infoframe(connector, vic);
+ frame->picture_aspect = picture_aspect;
+ frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
+ frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
--- /dev/null
+From 72794d16bd535a984e6653a18f5862405b49b5f9 Mon Sep 17 00:00:00 2001
+From: Jani Nikula <jani.nikula@intel.com>
+Date: Wed, 4 Jan 2023 12:05:17 +0200
+Subject: drm/edid: fix parsing of 3D modes from HDMI VSDB
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Jani Nikula <jani.nikula@intel.com>
+
+commit 72794d16bd535a984e6653a18f5862405b49b5f9 upstream.
+
+Commit 537d9ed2f6c1 ("drm/edid: convert add_cea_modes() to use cea db
+iter") inadvertently moved the do_hdmi_vsdb_modes() call within the db
+iteration loop, always passing NULL as the CTA VDB to
+do_hdmi_vsdb_modes(), skipping a lot of stereo modes.
+
+Move the call back outside of the loop.
+
+This does mean only one CTA VDB and HDMI VSDB combination will be
+handled, but it's an unlikely scenario to have more than one of either
+block, and it was not accounted for before the regression either.
+
+Fixes: 537d9ed2f6c1 ("drm/edid: convert add_cea_modes() to use cea db iter")
+Cc: <stable@vger.kernel.org> # v6.0+
+Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/cf159b8816191ed595a3cb954acaf189c4528cc7.1672826282.git.jani.nikula@intel.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/gpu/drm/drm_edid.c | 22 ++++++++++------------
+ 1 file changed, 10 insertions(+), 12 deletions(-)
+
+--- a/drivers/gpu/drm/drm_edid.c
++++ b/drivers/gpu/drm/drm_edid.c
+@@ -5249,13 +5249,12 @@ static int add_cea_modes(struct drm_conn
+ {
+ const struct cea_db *db;
+ struct cea_db_iter iter;
++ const u8 *hdmi = NULL, *video = NULL;
++ u8 hdmi_len = 0, video_len = 0;
+ int modes = 0;
+
+ cea_db_iter_edid_begin(drm_edid, &iter);
+ cea_db_iter_for_each(db, &iter) {
+- const u8 *hdmi = NULL, *video = NULL;
+- u8 hdmi_len = 0, video_len = 0;
+-
+ if (cea_db_tag(db) == CTA_DB_VIDEO) {
+ video = cea_db_data(db);
+ video_len = cea_db_payload_len(db);
+@@ -5271,18 +5270,17 @@ static int add_cea_modes(struct drm_conn
+ modes += do_y420vdb_modes(connector, vdb420,
+ cea_db_payload_len(db) - 1);
+ }
+-
+- /*
+- * We parse the HDMI VSDB after having added the cea modes as we
+- * will be patching their flags when the sink supports stereo
+- * 3D.
+- */
+- if (hdmi)
+- modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len,
+- video, video_len);
+ }
+ cea_db_iter_end(&iter);
+
++ /*
++ * We parse the HDMI VSDB after having added the cea modes as we will be
++ * patching their flags when the sink supports stereo 3D.
++ */
++ if (hdmi)
++ modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len,
++ video, video_len);
++
+ return modes;
+ }
+