From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Maxim Medvedev <redrathnure@gmail.com>
Date: Mon, 1 Jan 2024 21:50:10 +0000
Subject: HDMI EDID records for 800x480 resolution (a MKS IPS50 screen and
 similar)

---
 drivers/gpu/drm/drm_edid.c                    | 12 +++++++++-
 drivers/phy/rockchip/phy-rockchip-inno-hdmi.c |  1 +
 drivers/video/hdmi.c                          |  2 ++
 include/linux/hdmi.h                          |  1 +
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 111111111111..222222222222 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -1550,6 +1550,16 @@ static const struct drm_display_mode edid_cea_modes_193[] = {
 		   4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
+	/* 220 - 800x480@60Hz 5:3 */
+	{ DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER, 30240, 800, 850,
+		   920, 960, 0, 480, 510, 513, 525, 0,
+		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
+	  .picture_aspect_ratio = HDMI_PICTURE_ASPECT_5_3, },
+	/* 221 - 800x480@60Hz 5:3, MKS IPS50 */
+	{ DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER, 30240, 800, 850,
+		   950, 960, 0, 480, 510, 513, 525, 0,
+		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
+	  .picture_aspect_ratio = HDMI_PICTURE_ASPECT_5_3, },
 };
 
 /*
@@ -4215,7 +4225,7 @@ static bool drm_edid_has_cta_extension(const struct drm_edid *drm_edid)
 static __always_inline const struct drm_display_mode *cea_mode_for_vic(u8 vic)
 {
 	BUILD_BUG_ON(1 + ARRAY_SIZE(edid_cea_modes_1) - 1 != 127);
-	BUILD_BUG_ON(193 + ARRAY_SIZE(edid_cea_modes_193) - 1 != 219);
+	BUILD_BUG_ON(193 + ARRAY_SIZE(edid_cea_modes_193) - 1 != 221);
 
 	if (vic >= 1 && vic < 1 + ARRAY_SIZE(edid_cea_modes_1))
 		return &edid_cea_modes_1[vic - 1];
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c b/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c
index 111111111111..222222222222 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c
@@ -295,6 +295,7 @@ static const struct pre_pll_config pre_pll_cfg_table[] = {
 	{ 25175000,  31468750,  1,   41, 0, 3, 3,  1, 3, 3,  4, 0, 0xf5554f},
 	{ 27000000,  27000000,  1,   36, 0, 3, 3,  1, 2, 3,  4, 0,      0x0},
 	{ 27000000,  33750000,  1,   45, 0, 3, 3,  1, 3, 3,  4, 0,      0x0},
+	{ 30240000,  30240000,  5,  504, 3, 2, 2, 20, 4, 2,  2, 0,      0x0}, // Non standard screens like MKS IPS50
 	{ 31500000,  31500000,  1,   42, 0, 3, 3,  1, 2, 3,  4, 0,      0x0},
 	{ 31500000,  39375000,  1,  105, 1, 3, 3, 10, 0, 3,  4, 0,      0x0},
 	{ 33750000,  33750000,  1,   45, 0, 3, 3,  1, 2, 3,  4, 0,      0x0},
diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 111111111111..222222222222 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -1087,6 +1087,8 @@ hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect)
 		return "64:27";
 	case HDMI_PICTURE_ASPECT_256_135:
 		return "256:135";
+	case HDMI_PICTURE_ASPECT_5_3:
+		return "5:3";
 	case HDMI_PICTURE_ASPECT_RESERVED:
 		return "Reserved";
 	}
diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h
index 111111111111..222222222222 100644
--- a/include/linux/hdmi.h
+++ b/include/linux/hdmi.h
@@ -108,6 +108,7 @@ enum hdmi_picture_aspect {
 	HDMI_PICTURE_ASPECT_16_9,
 	HDMI_PICTURE_ASPECT_64_27,
 	HDMI_PICTURE_ASPECT_256_135,
+	HDMI_PICTURE_ASPECT_5_3,
 	HDMI_PICTURE_ASPECT_RESERVED,
 };
 
-- 
Armbian

