From 20e29dd98823a19ec3e38fbdcf86b6983268c657 Mon Sep 17 00:00:00 2001
From: Liu Ying <victor.liu@nxp.com>
Date: Thu, 14 Jun 2018 17:41:58 +0800
Subject: [PATCH] MLK-18507 drm/bridge: it6263: Filter out known bad display
 modes

It turns out the following display modes are not well supported
by the bridge - 1600x900@60, 1280x1024@60, 1280x720@30/25/24
and 1152x864@75.  Fortunately, they are not that widely used.
So, list them as the known bad display modes and filter them out
in ->mode_valid().

Signed-off-by: Liu Ying <victor.liu@nxp.com>
(cherry picked from commit c44ed03cf3b85d7f5bc8325ffeec9fd07f66aa87)
---
 drivers/gpu/drm/bridge/it6263.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/bridge/it6263.c b/drivers/gpu/drm/bridge/it6263.c
index f309380a0be11c..2bed01900a269d 100644
--- a/drivers/gpu/drm/bridge/it6263.c
+++ b/drivers/gpu/drm/bridge/it6263.c
@@ -335,6 +335,21 @@ struct it6263 {
 	bool split_mode;
 };
 
+struct it6263_minimode {
+	int hdisplay;
+	int vdisplay;
+	int vrefresh;
+};
+
+static const struct it6263_minimode it6263_bad_mode_db[] = {
+	{1600, 900,  60},
+	{1280, 1024, 60},
+	{1280, 720,  30},
+	{1280, 720,  25},
+	{1280, 720,  24},
+	{1152, 864,  75},
+};
+
 static inline struct it6263 *bridge_to_it6263(struct drm_bridge *bridge)
 {
 	return container_of(bridge, struct it6263, bridge);
@@ -507,9 +522,20 @@ static int it6263_get_modes(struct drm_connector *connector)
 enum drm_mode_status it6263_mode_valid(struct drm_connector *connector,
 					struct drm_display_mode *mode)
 {
+	const struct it6263_minimode *m;
+	int i, vrefresh = drm_mode_vrefresh(mode);
+
 	if (mode->clock > 150000)
 		return MODE_CLOCK_HIGH;
 
+	for (i = 0; i < ARRAY_SIZE(it6263_bad_mode_db); i++) {
+		m = &it6263_bad_mode_db[i];
+		if ((mode->hdisplay == m->hdisplay) &&
+		    (mode->vdisplay == m->vdisplay) &&
+		    (vrefresh == m->vrefresh))
+			return MODE_BAD;
+	}
+
 	return MODE_OK;
 }
 
-- 
GitLab