1From b4179e6ec82f1099128008bbf696d2b6fa9b7a99 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 21 Oct 2020 15:27:38 +0800
4Subject: [PATCH 36/93] backend-drm: Support setting interlaced mode
5
6Tested with:
7echo "output:HDMI-A-1:mode=1920x1080i" > /tmp/.weston_drm.conf
8> Output HDMI-A-1 changed to 1920x1080i@60 for mode(1920x1080i)
9
10Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
11---
12 libweston/backend-drm/drm.c   |  4 ++--
13 libweston/backend-drm/modes.c | 25 +++++++++++++++----------
14 2 files changed, 17 insertions(+), 12 deletions(-)
15
16diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
17index 2b3e90b..5528ef6 100644
18--- a/libweston/backend-drm/drm.c
19+++ b/libweston/backend-drm/drm.c
20@@ -3704,9 +3704,9 @@ drm_output_modeset(struct drm_output *output, const char *modeline)
21
22 	mode = to_drm_mode(output->base.current_mode);
23
24-	weston_log("Output %s changed to %dx%d@%d for mode(%s)\n",
25+	weston_log("Output %s changed to %s@%d for mode(%s)\n",
26 		   output->base.name,
27-		   mode->mode_info.hdisplay, mode->mode_info.vdisplay,
28+		   mode->mode_info.name,
29 		   mode->mode_info.vrefresh,
30 		   modeline);
31
32diff --git a/libweston/backend-drm/modes.c b/libweston/backend-drm/modes.c
33index f3d2c00..8bf6be8 100644
34--- a/libweston/backend-drm/modes.c
35+++ b/libweston/backend-drm/modes.c
36@@ -470,9 +470,8 @@ drm_output_print_modes(struct drm_output *output)
37 		dm = to_drm_mode(m);
38
39 		aspect_ratio = aspect_ratio_to_string(m->aspect_ratio);
40-		weston_log_continue(STAMP_SPACE "%dx%d@%.1f%s%s%s, %.1f MHz\n",
41-				    dm->mode_info.hdisplay,
42-				    dm->mode_info.vdisplay,
43+		weston_log_continue(STAMP_SPACE "%s@%.1f%s%s%s, %.1f MHz\n",
44+				    dm->mode_info.name,
45 				    m->refresh / 1000.0,
46 				    aspect_ratio,
47 				    m->flags & WL_OUTPUT_MODE_PREFERRED ?
48@@ -515,11 +514,15 @@ drm_output_choose_mode(struct drm_output *output,
49 	enum weston_mode_aspect_ratio target_aspect = WESTON_MODE_PIC_AR_NONE;
50 	struct drm_device *device;
51
52+#define WESTON_MODE_NAME(mode) \
53+	to_drm_mode(mode)->mode_info.name
54+
55 	device = output->device;
56+
57 	target_aspect = target_mode->aspect_ratio;
58 	src_aspect = output->base.current_mode->aspect_ratio;
59-	if (output->base.current_mode->width == target_mode->width &&
60-	    output->base.current_mode->height == target_mode->height &&
61+	if (!strcmp(WESTON_MODE_NAME(output->base.current_mode),
62+		    WESTON_MODE_NAME(target_mode)) &&
63 	    (output->base.current_mode->refresh == target_mode->refresh ||
64 	     target_mode->refresh == 0)) {
65 		if (!device->aspect_ratio_supported || src_aspect == target_aspect)
66@@ -529,8 +532,8 @@ drm_output_choose_mode(struct drm_output *output,
67 	wl_list_for_each(mode, &output->base.mode_list, base.link) {
68
69 		src_aspect = mode->base.aspect_ratio;
70-		if (mode->mode_info.hdisplay == target_mode->width &&
71-		    mode->mode_info.vdisplay == target_mode->height) {
72+		if (!strcmp(mode->mode_info.name,
73+			    WESTON_MODE_NAME(target_mode))) {
74 			if (mode->base.refresh == target_mode->refresh ||
75 			    target_mode->refresh == 0) {
76 				if (!device->aspect_ratio_supported ||
77@@ -607,6 +610,7 @@ drm_output_choose_initial_mode(struct drm_device *device,
78 	struct drm_mode *best = NULL;
79 	struct drm_mode *drm_mode;
80 	drmModeModeInfo drm_modeline;
81+	char name[16] = {0};
82 	int32_t width = 0;
83 	int32_t height = 0;
84 	uint32_t refresh = 0;
85@@ -616,7 +620,9 @@ drm_output_choose_initial_mode(struct drm_device *device,
86 	int n;
87
88 	if (mode == WESTON_DRM_BACKEND_OUTPUT_PREFERRED && modeline) {
89-		n = sscanf(modeline, "%dx%d@%d %u:%u", &width, &height,
90+		sscanf(modeline, "%12[^@pP]", name);
91+
92+		n = sscanf(modeline, "%dx%d%*[^0-9]%d %u:%u", &width, &height,
93 			   &refresh, &aspect_width, &aspect_height);
94 		if (device->aspect_ratio_supported && n == 5) {
95 			if (aspect_width == 4 && aspect_height == 3)
96@@ -646,8 +652,7 @@ drm_output_choose_initial_mode(struct drm_device *device,
97 	}
98
99 	wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
100-		if (width == drm_mode->mode_info.hdisplay &&
101-		    height == drm_mode->mode_info.vdisplay &&
102+		if (!strcmp(name, drm_mode->mode_info.name) &&
103 		    (refresh == 0 || refresh == drm_mode->mode_info.vrefresh)) {
104 			if (!device->aspect_ratio_supported ||
105 			    aspect_ratio == drm_mode->base.aspect_ratio)
106--
1072.20.1
108
109