1
From d3f13e2c3d04ab8b1f702222a82216c0f1ec8bb4 Mon Sep 17 00:00:00 2001
2
From: "Chia-Lin Kao (AceLan)" <acelan.kao@canonical.com>
3
Date: Tue, 8 Nov 2022 08:11:50 +0800
4
Subject: [PATCH] hw/xfree86: re-calculate the clock and refresh rate
6
Content-Type: text/plain; charset=UTF-8
7
Content-Transfer-Encoding: 8bit
9
xserver fails to generate useable resolutions with 90Hz framerate
10
panels(encounter the same issue with 3 different 2.5k resolution
11
panels). All the resolutions shown by xrandr lead to blank screen except
12
the one written in EDID.
13
Ville Syrjälä from Intel provides a method to calculate the preferred
14
clock and refresh rate from the existing resolution table and this
17
v2. xf86ModeVRefresh might return 0, need to check it before use it.
19
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1388
20
Signed-off-by: Chia-Lin Kao (AceLan) <acelan.kao@canonical.com>
22
hw/xfree86/common/xf86Mode.c | 2 ++
23
hw/xfree86/drivers/modesetting/drmmode_display.c | 12 +++++++++++-
24
include/displaymode.h | 1 +
25
3 files changed, 14 insertions(+), 1 deletion(-)
27
diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
28
index 16dd529e3..136cd15d0 100644
29
--- a/hw/xfree86/common/xf86Mode.c
30
+++ b/hw/xfree86/common/xf86Mode.c
31
@@ -230,6 +230,8 @@ xf86ModeStatusToString(ModeStatus status)
32
return "monitor doesn't support reduced blanking";
34
return "mode requires too much memory bandwidth";
35
+ case MODE_DUPLICATE:
36
+ return "the same mode has been added";
38
return "unknown reason";
40
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
41
index 65e8e6335..dc4e0f078 100644
42
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
43
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
44
@@ -2641,7 +2641,7 @@ static DisplayModePtr
45
drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes)
47
xf86MonPtr mon = output->MonInfo;
48
- DisplayModePtr i, m, preferred = NULL;
49
+ DisplayModePtr i, j, m, preferred = NULL;
50
int max_x = 0, max_y = 0;
51
float max_vrefresh = 0.0;
53
@@ -2673,6 +2673,16 @@ drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes)
54
i->VDisplay >= preferred->VDisplay &&
55
xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
56
i->status = MODE_VSYNC;
57
+ if (xf86ModeVRefresh(i) > 0.0)
58
+ i->Clock = i->Clock * xf86ModeVRefresh(preferred) / xf86ModeVRefresh(i);
59
+ i->VRefresh = xf86ModeVRefresh(preferred);
60
+ for (j = m; j != i; j = j->next) {
61
+ if (!strcmp(i->name, j->name) &&
62
+ xf86ModeVRefresh(i) * (1 + SYNC_TOLERANCE) >= xf86ModeVRefresh(j) &&
63
+ xf86ModeVRefresh(i) * (1 - SYNC_TOLERANCE) <= xf86ModeVRefresh(j)) {
64
+ i->status = MODE_DUPLICATE;
69
xf86PruneInvalidModes(output->scrn, &m, FALSE);
70
diff --git a/include/displaymode.h b/include/displaymode.h
71
index ad01b87ec..561087717 100644
72
--- a/include/displaymode.h
73
+++ b/include/displaymode.h
74
@@ -47,6 +47,7 @@ typedef enum {
75
MODE_ONE_SIZE, /* only one resolution is supported */
76
MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
77
MODE_BANDWIDTH, /* mode requires too much memory bandwidth */
78
+ MODE_DUPLICATE, /* mode is duplicated */
79
MODE_BAD = -2, /* unspecified reason */
80
MODE_ERROR = -1 /* error condition */