blob: bfd89b47b1629330a7bddd4247d93d0d64d21edb [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
Adam Jackson61e57a82010-03-29 21:43:18 +00005 * Copyright 2010 Red Hat, Inc.
Dave Airlief453ba02008-11-07 14:05:41 -08006 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.
9 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sub license,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
20 * of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 */
30#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Thierry Reding10a85122012-11-21 15:31:35 +010032#include <linux/hdmi.h>
Dave Airlief453ba02008-11-07 14:05:41 -080033#include <linux/i2c.h>
Adam Jackson47819ba2012-05-30 16:42:39 -040034#include <linux/module.h>
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +010035#include <linux/vga_switcheroo.h>
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/drmP.h>
37#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020038#include <drm/drm_encoder.h>
Dave Airlie40d9b042014-10-20 16:29:33 +100039#include <drm/drm_displayid.h>
Shashank Sharma62c58af2017-03-13 16:54:02 +053040#include <drm/drm_scdc_helper.h>
Dave Airlief453ba02008-11-07 14:05:41 -080041
Takashi Iwai969218f2017-01-17 17:43:29 +010042#include "drm_crtc_internal.h"
43
Adam Jackson13931572010-08-03 14:38:19 -040044#define version_greater(edid, maj, min) \
45 (((edid)->version > (maj)) || \
46 ((edid)->version == (maj) && (edid)->revision > (min)))
Dave Airlief453ba02008-11-07 14:05:41 -080047
Adam Jacksond1ff6402010-03-29 21:43:26 +000048#define EDID_EST_TIMINGS 16
49#define EDID_STD_TIMINGS 8
50#define EDID_DETAILED_TIMINGS 4
Dave Airlief453ba02008-11-07 14:05:41 -080051
52/*
53 * EDID blocks out in the wild have a variety of bugs, try to collect
54 * them here (note that userspace may work around broken monitors first,
55 * but fixes should make their way here so that the kernel "just works"
56 * on as many displays as possible).
57 */
58
59/* First detailed mode wrong, use largest 60Hz mode */
60#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
61/* Reported 135MHz pixel clock is too high, needs adjustment */
62#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
63/* Prefer the largest mode at 75 Hz */
64#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
65/* Detail timing is in cm not mm */
66#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
67/* Detailed timing descriptors have bogus size values, so just take the
68 * maximum size and use that.
69 */
70#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
71/* Monitor forgot to set the first detailed is preferred bit. */
72#define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
73/* use +hsync +vsync for detailed mode */
74#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
Adam Jacksonbc42aab2012-05-23 16:26:54 -040075/* Force reduced-blanking timings for detailed modes */
76#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
Rafał Miłecki49d45a312013-12-07 13:22:42 +010077/* Force 8bpc */
78#define EDID_QUIRK_FORCE_8BPC (1 << 8)
Mario Kleinerbc5b9642014-05-23 21:40:55 +020079/* Force 12bpc */
80#define EDID_QUIRK_FORCE_12BPC (1 << 9)
Mario Kleinere10aec62016-07-06 12:05:44 +020081/* Force 6bpc */
82#define EDID_QUIRK_FORCE_6BPC (1 << 10)
Mario Kleinere345da82017-04-21 17:05:08 +020083/* Force 10bpc */
84#define EDID_QUIRK_FORCE_10BPC (1 << 11)
Dave Airlie66660d42017-10-16 05:08:09 +010085/* Non desktop display (i.e. HMD) */
86#define EDID_QUIRK_NON_DESKTOP (1 << 12)
Alex Deucher3c537882010-02-05 04:21:19 -050087
Adam Jackson13931572010-08-03 14:38:19 -040088struct detailed_mode_closure {
89 struct drm_connector *connector;
90 struct edid *edid;
91 bool preferred;
92 u32 quirks;
93 int modes;
94};
Dave Airlief453ba02008-11-07 14:05:41 -080095
Zhao Yakui5c612592009-06-22 13:17:10 +080096#define LEVEL_DMT 0
97#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000098#define LEVEL_GTF2 2
99#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +0800100
Jani Nikula23c4cfb2016-12-28 13:06:26 +0200101static const struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -0500102 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800103 int product_id;
104 u32 quirks;
105} edid_quirk_list[] = {
106 /* Acer AL1706 */
107 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
108 /* Acer F51 */
109 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
110 /* Unknown Acer */
111 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
112
Mario Kleinere10aec62016-07-06 12:05:44 +0200113 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
114 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
115
Dave Airlief453ba02008-11-07 14:05:41 -0800116 /* Belinea 10 15 55 */
117 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
118 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
119
120 /* Envision Peripherals, Inc. EN-7100e */
121 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000122 /* Envision EN2028 */
123 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800124
125 /* Funai Electronics PM36B */
126 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
127 EDID_QUIRK_DETAILED_IN_CM },
128
Mario Kleinere345da82017-04-21 17:05:08 +0200129 /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
130 { "LGD", 764, EDID_QUIRK_FORCE_10BPC },
131
Dave Airlief453ba02008-11-07 14:05:41 -0800132 /* LG Philips LCD LP154W01-A5 */
133 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
134 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
135
136 /* Philips 107p5 CRT */
137 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
138
139 /* Proview AY765C */
140 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
141
142 /* Samsung SyncMaster 205BW. Note: irony */
143 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
144 /* Samsung SyncMaster 22[5-6]BW */
145 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
146 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400147
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200148 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
149 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
150
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400151 /* ViewSonic VA2026w */
152 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400153
154 /* Medion MD 30217 PG */
155 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100156
157 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
158 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Tomeu Vizoso36fc5792017-02-20 16:25:45 +0100159
160 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
161 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100162
163 /* HTC Vive VR Headset */
164 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
Philipp Zabelb3b12ea2018-02-19 18:59:36 +0100165
166 /* Oculus Rift DK1, DK2, and CV1 VR Headsets */
167 { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
168 { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
169 { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
Philipp Zabel90eda8f2018-02-19 18:59:37 +0100170
171 /* Windows Mixed Reality Headsets */
172 { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
173 { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
174 { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
175 { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
176 { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
177 { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
178 { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
179 { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
Dave Airlief453ba02008-11-07 14:05:41 -0800180};
181
Thierry Redinga6b21832012-11-23 15:01:42 +0100182/*
183 * Autogenerated from the DMT spec.
184 * This table is copied from xfree86/modes/xf86EdidModes.c.
185 */
186static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300187 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100188 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
189 736, 832, 0, 350, 382, 385, 445, 0,
190 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300191 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100192 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
193 736, 832, 0, 400, 401, 404, 445, 0,
194 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300195 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100196 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
197 828, 936, 0, 400, 401, 404, 446, 0,
198 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300199 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100200 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300201 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100202 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300203 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100204 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
205 704, 832, 0, 480, 489, 492, 520, 0,
206 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300207 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100208 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
209 720, 840, 0, 480, 481, 484, 500, 0,
210 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300211 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100212 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
213 752, 832, 0, 480, 481, 484, 509, 0,
214 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300215 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100216 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
217 896, 1024, 0, 600, 601, 603, 625, 0,
218 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300219 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100220 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
221 968, 1056, 0, 600, 601, 605, 628, 0,
222 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300223 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100224 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
225 976, 1040, 0, 600, 637, 643, 666, 0,
226 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300227 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100228 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
229 896, 1056, 0, 600, 601, 604, 625, 0,
230 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300231 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100232 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
233 896, 1048, 0, 600, 601, 604, 631, 0,
234 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300235 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100236 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
237 880, 960, 0, 600, 603, 607, 636, 0,
238 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300239 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100240 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
241 976, 1088, 0, 480, 486, 494, 517, 0,
242 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300243 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100244 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100245 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100246 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300247 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300248 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100249 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
250 1184, 1344, 0, 768, 771, 777, 806, 0,
251 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300252 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100253 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
254 1184, 1328, 0, 768, 771, 777, 806, 0,
255 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300256 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100257 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
258 1136, 1312, 0, 768, 769, 772, 800, 0,
259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300260 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100261 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
262 1168, 1376, 0, 768, 769, 772, 808, 0,
263 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300264 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100265 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
266 1104, 1184, 0, 768, 771, 775, 813, 0,
267 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300268 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100269 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
270 1344, 1600, 0, 864, 865, 868, 900, 0,
271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300272 /* 0x55 - 1280x720@60Hz */
273 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
274 1430, 1650, 0, 720, 725, 730, 750, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300276 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100277 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
278 1360, 1440, 0, 768, 771, 778, 790, 0,
279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300280 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100281 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
282 1472, 1664, 0, 768, 771, 778, 798, 0,
283 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300284 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100285 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
286 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300287 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300288 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100289 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
290 1496, 1712, 0, 768, 771, 778, 809, 0,
291 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300292 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100293 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
294 1360, 1440, 0, 768, 771, 778, 813, 0,
295 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300296 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100297 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
298 1360, 1440, 0, 800, 803, 809, 823, 0,
299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300300 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100301 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
302 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300303 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300304 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100305 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
306 1488, 1696, 0, 800, 803, 809, 838, 0,
307 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300308 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100309 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
310 1496, 1712, 0, 800, 803, 809, 843, 0,
311 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300312 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100313 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
314 1360, 1440, 0, 800, 803, 809, 847, 0,
315 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300316 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100317 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
318 1488, 1800, 0, 960, 961, 964, 1000, 0,
319 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300320 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100321 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
322 1504, 1728, 0, 960, 961, 964, 1011, 0,
323 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300324 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100325 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
326 1360, 1440, 0, 960, 963, 967, 1017, 0,
327 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300328 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100329 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
330 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
331 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300332 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100333 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
334 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
335 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300336 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100337 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
338 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
339 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300340 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100341 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
342 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
343 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300344 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100345 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
346 1536, 1792, 0, 768, 771, 777, 795, 0,
347 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300348 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100349 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
350 1440, 1520, 0, 768, 771, 776, 813, 0,
351 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300352 /* 0x51 - 1366x768@60Hz */
353 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
354 1579, 1792, 0, 768, 771, 774, 798, 0,
355 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
356 /* 0x56 - 1366x768@60Hz */
357 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
358 1436, 1500, 0, 768, 769, 772, 800, 0,
359 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300360 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100361 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
362 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
363 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300364 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100365 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
366 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
367 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300368 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100369 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
370 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
371 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300372 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100373 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
374 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
375 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300376 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100377 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
378 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
379 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300380 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100381 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
382 1520, 1600, 0, 900, 903, 909, 926, 0,
383 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300384 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100385 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
386 1672, 1904, 0, 900, 903, 909, 934, 0,
387 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300388 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100389 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
390 1688, 1936, 0, 900, 903, 909, 942, 0,
391 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300392 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100393 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
394 1696, 1952, 0, 900, 903, 909, 948, 0,
395 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300396 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100397 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
398 1520, 1600, 0, 900, 903, 909, 953, 0,
399 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300400 /* 0x53 - 1600x900@60Hz */
401 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
402 1704, 1800, 0, 900, 901, 904, 1000, 0,
403 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300404 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100405 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
406 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
407 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300408 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100409 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
410 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
411 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300412 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100413 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
414 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
415 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300416 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100417 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
418 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
419 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300420 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100421 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
422 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
423 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300424 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100425 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
426 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
427 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300428 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100429 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
430 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
431 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300432 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100433 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
434 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
435 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300436 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100437 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
438 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
439 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300440 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100441 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
442 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
443 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300444 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100445 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
446 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
447 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300448 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100449 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
450 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
451 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300452 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100453 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
454 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
455 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300456 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100457 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
458 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
459 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300460 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100461 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
462 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
463 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300464 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100465 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300466 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100467 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300468 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100469 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
470 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
471 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300472 /* 0x52 - 1920x1080@60Hz */
473 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
474 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
475 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300476 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100477 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
478 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
479 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300480 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100481 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
482 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
483 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300484 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100485 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
486 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
487 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300488 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100489 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
490 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
491 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300492 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100493 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
494 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
495 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300496 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100497 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
498 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
499 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300500 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100501 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
502 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
503 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300504 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100505 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
506 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300508 /* 0x54 - 2048x1152@60Hz */
509 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
510 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
511 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300512 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100513 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
514 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
515 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300516 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100517 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
518 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
519 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300520 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100521 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
522 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
523 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300524 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100525 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
526 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
527 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300528 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100529 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
530 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
531 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300532 /* 0x57 - 4096x2160@60Hz RB */
533 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
534 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
535 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
536 /* 0x58 - 4096x2160@59.94Hz RB */
537 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
538 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
539 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100540};
541
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300542/*
543 * These more or less come from the DMT spec. The 720x400 modes are
544 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
545 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
546 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
547 * mode.
548 *
549 * The DMT modes have been fact-checked; the rest are mild guesses.
550 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100551static const struct drm_display_mode edid_est_modes[] = {
552 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
553 968, 1056, 0, 600, 601, 605, 628, 0,
554 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
555 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
556 896, 1024, 0, 600, 601, 603, 625, 0,
557 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
558 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
559 720, 840, 0, 480, 481, 484, 500, 0,
560 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
561 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100562 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100563 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
564 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
565 768, 864, 0, 480, 483, 486, 525, 0,
566 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100567 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100568 752, 800, 0, 480, 490, 492, 525, 0,
569 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
570 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
571 846, 900, 0, 400, 421, 423, 449, 0,
572 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
573 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
574 846, 900, 0, 400, 412, 414, 449, 0,
575 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
576 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
577 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
578 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100579 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100580 1136, 1312, 0, 768, 769, 772, 800, 0,
581 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
582 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
583 1184, 1328, 0, 768, 771, 777, 806, 0,
584 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
585 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
586 1184, 1344, 0, 768, 771, 777, 806, 0,
587 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
588 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
589 1208, 1264, 0, 768, 768, 776, 817, 0,
590 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
591 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
592 928, 1152, 0, 624, 625, 628, 667, 0,
593 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
594 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
595 896, 1056, 0, 600, 601, 604, 625, 0,
596 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
597 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
598 976, 1040, 0, 600, 637, 643, 666, 0,
599 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
600 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
601 1344, 1600, 0, 864, 865, 868, 900, 0,
602 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
603};
604
605struct minimode {
606 short w;
607 short h;
608 short r;
609 short rb;
610};
611
612static const struct minimode est3_modes[] = {
613 /* byte 6 */
614 { 640, 350, 85, 0 },
615 { 640, 400, 85, 0 },
616 { 720, 400, 85, 0 },
617 { 640, 480, 85, 0 },
618 { 848, 480, 60, 0 },
619 { 800, 600, 85, 0 },
620 { 1024, 768, 85, 0 },
621 { 1152, 864, 75, 0 },
622 /* byte 7 */
623 { 1280, 768, 60, 1 },
624 { 1280, 768, 60, 0 },
625 { 1280, 768, 75, 0 },
626 { 1280, 768, 85, 0 },
627 { 1280, 960, 60, 0 },
628 { 1280, 960, 85, 0 },
629 { 1280, 1024, 60, 0 },
630 { 1280, 1024, 85, 0 },
631 /* byte 8 */
632 { 1360, 768, 60, 0 },
633 { 1440, 900, 60, 1 },
634 { 1440, 900, 60, 0 },
635 { 1440, 900, 75, 0 },
636 { 1440, 900, 85, 0 },
637 { 1400, 1050, 60, 1 },
638 { 1400, 1050, 60, 0 },
639 { 1400, 1050, 75, 0 },
640 /* byte 9 */
641 { 1400, 1050, 85, 0 },
642 { 1680, 1050, 60, 1 },
643 { 1680, 1050, 60, 0 },
644 { 1680, 1050, 75, 0 },
645 { 1680, 1050, 85, 0 },
646 { 1600, 1200, 60, 0 },
647 { 1600, 1200, 65, 0 },
648 { 1600, 1200, 70, 0 },
649 /* byte 10 */
650 { 1600, 1200, 75, 0 },
651 { 1600, 1200, 85, 0 },
652 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300653 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100654 { 1856, 1392, 60, 0 },
655 { 1856, 1392, 75, 0 },
656 { 1920, 1200, 60, 1 },
657 { 1920, 1200, 60, 0 },
658 /* byte 11 */
659 { 1920, 1200, 75, 0 },
660 { 1920, 1200, 85, 0 },
661 { 1920, 1440, 60, 0 },
662 { 1920, 1440, 75, 0 },
663};
664
665static const struct minimode extra_modes[] = {
666 { 1024, 576, 60, 0 },
667 { 1366, 768, 60, 0 },
668 { 1600, 900, 60, 0 },
669 { 1680, 945, 60, 0 },
670 { 1920, 1080, 60, 0 },
671 { 2048, 1152, 60, 0 },
672 { 2048, 1536, 60, 0 },
673};
674
675/*
676 * Probably taken from CEA-861 spec.
677 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200678 *
679 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100680 */
681static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200682 /* 0 - dummy, VICs start at 1 */
683 { },
Thierry Redinga6b21832012-11-23 15:01:42 +0100684 /* 1 - 640x480@60Hz */
685 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
686 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300687 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530688 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100689 /* 2 - 720x480@60Hz */
690 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
691 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300692 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530693 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100694 /* 3 - 720x480@60Hz */
695 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
696 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300697 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530698 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100699 /* 4 - 1280x720@60Hz */
700 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
701 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300702 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530703 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100704 /* 5 - 1920x1080i@60Hz */
705 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
706 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
707 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300708 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530709 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700710 /* 6 - 720(1440)x480i@60Hz */
711 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
712 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100713 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300714 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530715 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700716 /* 7 - 720(1440)x480i@60Hz */
717 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
718 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100719 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300720 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530721 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700722 /* 8 - 720(1440)x240@60Hz */
723 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
724 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100725 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300726 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530727 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700728 /* 9 - 720(1440)x240@60Hz */
729 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
730 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100731 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300732 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530733 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100734 /* 10 - 2880x480i@60Hz */
735 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
736 3204, 3432, 0, 480, 488, 494, 525, 0,
737 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300738 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530739 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100740 /* 11 - 2880x480i@60Hz */
741 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
742 3204, 3432, 0, 480, 488, 494, 525, 0,
743 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300744 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530745 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100746 /* 12 - 2880x240@60Hz */
747 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
748 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300749 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530750 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100751 /* 13 - 2880x240@60Hz */
752 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
753 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300754 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530755 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100756 /* 14 - 1440x480@60Hz */
757 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
758 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300759 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530760 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100761 /* 15 - 1440x480@60Hz */
762 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
763 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300764 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530765 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100766 /* 16 - 1920x1080@60Hz */
767 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
768 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300769 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530770 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100771 /* 17 - 720x576@50Hz */
772 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
773 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300774 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530775 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100776 /* 18 - 720x576@50Hz */
777 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
778 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300779 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530780 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100781 /* 19 - 1280x720@50Hz */
782 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
783 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300784 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530785 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100786 /* 20 - 1920x1080i@50Hz */
787 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
788 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
789 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300790 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530791 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700792 /* 21 - 720(1440)x576i@50Hz */
793 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
794 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100795 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300796 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530797 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700798 /* 22 - 720(1440)x576i@50Hz */
799 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
800 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300802 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530803 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700804 /* 23 - 720(1440)x288@50Hz */
805 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
806 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100807 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300808 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530809 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700810 /* 24 - 720(1440)x288@50Hz */
811 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
812 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100813 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300814 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530815 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100816 /* 25 - 2880x576i@50Hz */
817 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
818 3180, 3456, 0, 576, 580, 586, 625, 0,
819 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300820 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530821 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100822 /* 26 - 2880x576i@50Hz */
823 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
824 3180, 3456, 0, 576, 580, 586, 625, 0,
825 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300826 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530827 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100828 /* 27 - 2880x288@50Hz */
829 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
830 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300831 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530832 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100833 /* 28 - 2880x288@50Hz */
834 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
835 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300836 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530837 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100838 /* 29 - 1440x576@50Hz */
839 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
840 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300841 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530842 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100843 /* 30 - 1440x576@50Hz */
844 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
845 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300846 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530847 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100848 /* 31 - 1920x1080@50Hz */
849 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
850 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300851 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530852 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100853 /* 32 - 1920x1080@24Hz */
854 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
855 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300856 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530857 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100858 /* 33 - 1920x1080@25Hz */
859 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
860 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300861 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530862 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100863 /* 34 - 1920x1080@30Hz */
864 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
865 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300866 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530867 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100868 /* 35 - 2880x480@60Hz */
869 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
870 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300871 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530872 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100873 /* 36 - 2880x480@60Hz */
874 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
875 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300876 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530877 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100878 /* 37 - 2880x576@50Hz */
879 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
880 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300881 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530882 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100883 /* 38 - 2880x576@50Hz */
884 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
885 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300886 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530887 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100888 /* 39 - 1920x1080i@50Hz */
889 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
890 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
891 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300892 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530893 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100894 /* 40 - 1920x1080i@100Hz */
895 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
896 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
897 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300898 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530899 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100900 /* 41 - 1280x720@100Hz */
901 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
902 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300903 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530904 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100905 /* 42 - 720x576@100Hz */
906 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
907 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300908 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530909 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100910 /* 43 - 720x576@100Hz */
911 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
912 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300913 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530914 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700915 /* 44 - 720(1440)x576i@100Hz */
916 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
917 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100918 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700919 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530920 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700921 /* 45 - 720(1440)x576i@100Hz */
922 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
923 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100924 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700925 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530926 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100927 /* 46 - 1920x1080i@120Hz */
928 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
929 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
930 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300931 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530932 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100933 /* 47 - 1280x720@120Hz */
934 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
935 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300936 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530937 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100938 /* 48 - 720x480@120Hz */
939 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
940 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300941 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530942 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100943 /* 49 - 720x480@120Hz */
944 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
945 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300946 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530947 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700948 /* 50 - 720(1440)x480i@120Hz */
949 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
950 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100951 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300952 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530953 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700954 /* 51 - 720(1440)x480i@120Hz */
955 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
956 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100957 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300958 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530959 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100960 /* 52 - 720x576@200Hz */
961 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
962 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300963 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530964 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100965 /* 53 - 720x576@200Hz */
966 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
967 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300968 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530969 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700970 /* 54 - 720(1440)x576i@200Hz */
971 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
972 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100973 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300974 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530975 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700976 /* 55 - 720(1440)x576i@200Hz */
977 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
978 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100979 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300980 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530981 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100982 /* 56 - 720x480@240Hz */
983 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
984 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300985 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530986 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100987 /* 57 - 720x480@240Hz */
988 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
989 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300990 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530991 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200992 /* 58 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700993 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
994 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100995 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300996 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530997 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200998 /* 59 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700999 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1000 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001001 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001002 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301003 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001004 /* 60 - 1280x720@24Hz */
1005 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1006 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001007 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301008 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001009 /* 61 - 1280x720@25Hz */
1010 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1011 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001012 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301013 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001014 /* 62 - 1280x720@30Hz */
1015 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1016 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001017 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301018 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001019 /* 63 - 1920x1080@120Hz */
1020 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1021 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001022 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301023 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001024 /* 64 - 1920x1080@100Hz */
1025 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001026 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001027 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301028 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301029 /* 65 - 1280x720@24Hz */
1030 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1031 3080, 3300, 0, 720, 725, 730, 750, 0,
1032 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1033 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1034 /* 66 - 1280x720@25Hz */
1035 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1036 3740, 3960, 0, 720, 725, 730, 750, 0,
1037 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1038 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1039 /* 67 - 1280x720@30Hz */
1040 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1041 3080, 3300, 0, 720, 725, 730, 750, 0,
1042 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1043 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1044 /* 68 - 1280x720@50Hz */
1045 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1046 1760, 1980, 0, 720, 725, 730, 750, 0,
1047 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1048 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1049 /* 69 - 1280x720@60Hz */
1050 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1051 1430, 1650, 0, 720, 725, 730, 750, 0,
1052 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1053 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1054 /* 70 - 1280x720@100Hz */
1055 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1056 1760, 1980, 0, 720, 725, 730, 750, 0,
1057 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1058 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1059 /* 71 - 1280x720@120Hz */
1060 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1061 1430, 1650, 0, 720, 725, 730, 750, 0,
1062 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1063 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1064 /* 72 - 1920x1080@24Hz */
1065 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1066 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1067 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1068 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1069 /* 73 - 1920x1080@25Hz */
1070 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1071 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1072 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1073 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1074 /* 74 - 1920x1080@30Hz */
1075 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1076 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1077 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1078 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1079 /* 75 - 1920x1080@50Hz */
1080 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1081 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1082 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1083 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1084 /* 76 - 1920x1080@60Hz */
1085 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1086 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1087 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1088 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1089 /* 77 - 1920x1080@100Hz */
1090 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1091 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1092 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1093 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1094 /* 78 - 1920x1080@120Hz */
1095 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1096 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1097 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1098 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1099 /* 79 - 1680x720@24Hz */
1100 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1101 3080, 3300, 0, 720, 725, 730, 750, 0,
1102 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1103 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1104 /* 80 - 1680x720@25Hz */
1105 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1106 2948, 3168, 0, 720, 725, 730, 750, 0,
1107 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1108 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1109 /* 81 - 1680x720@30Hz */
1110 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1111 2420, 2640, 0, 720, 725, 730, 750, 0,
1112 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1113 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1114 /* 82 - 1680x720@50Hz */
1115 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1116 1980, 2200, 0, 720, 725, 730, 750, 0,
1117 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1118 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1119 /* 83 - 1680x720@60Hz */
1120 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1121 1980, 2200, 0, 720, 725, 730, 750, 0,
1122 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1123 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1124 /* 84 - 1680x720@100Hz */
1125 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1126 1780, 2000, 0, 720, 725, 730, 825, 0,
1127 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1128 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1129 /* 85 - 1680x720@120Hz */
1130 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1131 1780, 2000, 0, 720, 725, 730, 825, 0,
1132 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1133 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1134 /* 86 - 2560x1080@24Hz */
1135 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1136 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1137 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1138 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1139 /* 87 - 2560x1080@25Hz */
1140 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1141 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1142 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1143 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1144 /* 88 - 2560x1080@30Hz */
1145 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1146 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1147 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1148 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1149 /* 89 - 2560x1080@50Hz */
1150 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1151 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1152 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1153 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1154 /* 90 - 2560x1080@60Hz */
1155 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1156 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1157 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1158 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1159 /* 91 - 2560x1080@100Hz */
1160 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1161 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1162 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1163 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1164 /* 92 - 2560x1080@120Hz */
1165 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1166 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1167 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1168 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1169 /* 93 - 3840x2160p@24Hz 16:9 */
1170 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1171 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1172 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1173 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1174 /* 94 - 3840x2160p@25Hz 16:9 */
1175 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1176 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1177 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1178 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1179 /* 95 - 3840x2160p@30Hz 16:9 */
1180 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1181 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1182 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1183 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1184 /* 96 - 3840x2160p@50Hz 16:9 */
1185 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1186 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1187 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1188 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1189 /* 97 - 3840x2160p@60Hz 16:9 */
1190 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1191 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1192 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1193 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1194 /* 98 - 4096x2160p@24Hz 256:135 */
1195 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1196 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1197 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1198 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1199 /* 99 - 4096x2160p@25Hz 256:135 */
1200 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1201 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1202 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1203 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1204 /* 100 - 4096x2160p@30Hz 256:135 */
1205 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1206 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1207 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1208 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1209 /* 101 - 4096x2160p@50Hz 256:135 */
1210 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1211 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1212 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1213 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1214 /* 102 - 4096x2160p@60Hz 256:135 */
1215 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1216 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1217 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1218 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1219 /* 103 - 3840x2160p@24Hz 64:27 */
1220 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1221 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1222 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1223 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1224 /* 104 - 3840x2160p@25Hz 64:27 */
1225 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1226 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1228 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1229 /* 105 - 3840x2160p@30Hz 64:27 */
1230 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1231 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1232 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1233 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1234 /* 106 - 3840x2160p@50Hz 64:27 */
1235 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1236 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1237 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1238 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1239 /* 107 - 3840x2160p@60Hz 64:27 */
1240 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1241 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1242 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1243 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001244};
1245
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001246/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001247 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001248 */
1249static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001250 /* 0 - dummy, VICs start at 1 */
1251 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001252 /* 1 - 3840x2160@30Hz */
1253 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1254 3840, 4016, 4104, 4400, 0,
1255 2160, 2168, 2178, 2250, 0,
1256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1257 .vrefresh = 30, },
1258 /* 2 - 3840x2160@25Hz */
1259 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1260 3840, 4896, 4984, 5280, 0,
1261 2160, 2168, 2178, 2250, 0,
1262 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1263 .vrefresh = 25, },
1264 /* 3 - 3840x2160@24Hz */
1265 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1266 3840, 5116, 5204, 5500, 0,
1267 2160, 2168, 2178, 2250, 0,
1268 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1269 .vrefresh = 24, },
1270 /* 4 - 4096x2160@24Hz (SMPTE) */
1271 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1272 4096, 5116, 5204, 5500, 0,
1273 2160, 2168, 2178, 2250, 0,
1274 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1275 .vrefresh = 24, },
1276};
1277
Adam Jackson61e57a82010-03-29 21:43:18 +00001278/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001279
Adam Jackson083ae052009-09-23 17:30:45 -04001280static const u8 edid_header[] = {
1281 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1282};
Dave Airlief453ba02008-11-07 14:05:41 -08001283
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001284/**
1285 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1286 * @raw_edid: pointer to raw base EDID block
1287 *
1288 * Sanity check the header of the base EDID block.
1289 *
1290 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001291 */
1292int drm_edid_header_is_valid(const u8 *raw_edid)
1293{
1294 int i, score = 0;
1295
1296 for (i = 0; i < sizeof(edid_header); i++)
1297 if (raw_edid[i] == edid_header[i])
1298 score++;
1299
1300 return score;
1301}
1302EXPORT_SYMBOL(drm_edid_header_is_valid);
1303
Adam Jackson47819ba2012-05-30 16:42:39 -04001304static int edid_fixup __read_mostly = 6;
1305module_param_named(edid_fixup, edid_fixup, int, 0400);
1306MODULE_PARM_DESC(edid_fixup,
1307 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001308
Dave Airlie40d9b042014-10-20 16:29:33 +10001309static void drm_get_displayid(struct drm_connector *connector,
1310 struct edid *edid);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001311
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001312static int drm_edid_block_checksum(const u8 *raw_edid)
1313{
1314 int i;
1315 u8 csum = 0;
1316 for (i = 0; i < EDID_LENGTH; i++)
1317 csum += raw_edid[i];
1318
1319 return csum;
1320}
1321
Stefan Brünsd6885d62014-11-30 19:57:41 +01001322static bool drm_edid_is_zero(const u8 *in_edid, int length)
1323{
1324 if (memchr_inv(in_edid, 0, length))
1325 return false;
1326
1327 return true;
1328}
1329
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001330/**
1331 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1332 * @raw_edid: pointer to raw EDID block
1333 * @block: type of block to validate (0 for base, extension otherwise)
1334 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001335 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001336 *
1337 * Validate a base or extension EDID block and optionally dump bad blocks to
1338 * the console.
1339 *
1340 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001341 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001342bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1343 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001344{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001345 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001346 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001347
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001348 if (WARN_ON(!raw_edid))
1349 return false;
1350
Adam Jackson47819ba2012-05-30 16:42:39 -04001351 if (edid_fixup > 8 || edid_fixup < 0)
1352 edid_fixup = 6;
1353
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001354 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001355 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001356 if (score == 8) {
1357 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001358 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001359 } else if (score >= edid_fixup) {
1360 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1361 * The corrupt flag needs to be set here otherwise, the
1362 * fix-up code here will correct the problem, the
1363 * checksum is correct and the test fails
1364 */
1365 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001366 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001367 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1368 memcpy(raw_edid, edid_header, sizeof(edid_header));
1369 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001370 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001371 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001372 goto bad;
1373 }
1374 }
Dave Airlief453ba02008-11-07 14:05:41 -08001375
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001376 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001377 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001378 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001379 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001380
Adam Jackson4a638b42010-05-25 16:33:09 -04001381 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001382 if (raw_edid[0] == CEA_EXT) {
1383 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1384 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1385 } else {
1386 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001387 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001388
Adam Jackson4a638b42010-05-25 16:33:09 -04001389 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001390 }
Dave Airlief453ba02008-11-07 14:05:41 -08001391 }
1392
Adam Jackson61e57a82010-03-29 21:43:18 +00001393 /* per-block-type checks */
1394 switch (raw_edid[0]) {
1395 case 0: /* base */
1396 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001397 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001398 goto bad;
1399 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001400
Adam Jackson61e57a82010-03-29 21:43:18 +00001401 if (edid->revision > 4)
1402 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1403 break;
1404
1405 default:
1406 break;
1407 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001408
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001409 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001410
1411bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001412 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001413 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001414 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001415 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001416 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001417 print_hex_dump(KERN_NOTICE,
1418 " \t", DUMP_PREFIX_NONE, 16, 1,
1419 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001420 }
Dave Airlief453ba02008-11-07 14:05:41 -08001421 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001422 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001423}
Carsten Emdeda0df922012-03-18 22:37:33 +01001424EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001425
1426/**
1427 * drm_edid_is_valid - sanity check EDID data
1428 * @edid: EDID data
1429 *
1430 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001431 *
1432 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001433 */
1434bool drm_edid_is_valid(struct edid *edid)
1435{
1436 int i;
1437 u8 *raw = (u8 *)edid;
1438
1439 if (!edid)
1440 return false;
1441
1442 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001443 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001444 return false;
1445
1446 return true;
1447}
Alex Deucher3c537882010-02-05 04:21:19 -05001448EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001449
Adam Jackson61e57a82010-03-29 21:43:18 +00001450#define DDC_SEGMENT_ADDR 0x30
1451/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001452 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001453 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001454 * @buf: EDID data buffer to be filled
1455 * @block: 128 byte EDID block to start fetching from
1456 * @len: EDID data buffer length to fetch
1457 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001458 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001459 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001460 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001461 */
1462static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001463drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001464{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001465 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001466 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001467 unsigned char segment = block >> 1;
1468 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001469 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001470
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001471 /*
1472 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001473 * adapter reports EAGAIN. However, we find that bit-banging transfers
1474 * are susceptible to errors under a heavily loaded machine and
1475 * generate spurious NAKs and timeouts. Retrying the transfer
1476 * of the individual block a few times seems to overcome this.
1477 */
1478 do {
1479 struct i2c_msg msgs[] = {
1480 {
Shirish Scd004b32012-08-30 07:04:06 +00001481 .addr = DDC_SEGMENT_ADDR,
1482 .flags = 0,
1483 .len = 1,
1484 .buf = &segment,
1485 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001486 .addr = DDC_ADDR,
1487 .flags = 0,
1488 .len = 1,
1489 .buf = &start,
1490 }, {
1491 .addr = DDC_ADDR,
1492 .flags = I2C_M_RD,
1493 .len = len,
1494 .buf = buf,
1495 }
1496 };
Shirish Scd004b32012-08-30 07:04:06 +00001497
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001498 /*
1499 * Avoid sending the segment addr to not upset non-compliant
1500 * DDC monitors.
1501 */
Shirish Scd004b32012-08-30 07:04:06 +00001502 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1503
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001504 if (ret == -ENXIO) {
1505 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1506 adapter->name);
1507 break;
1508 }
Shirish Scd004b32012-08-30 07:04:06 +00001509 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001510
Shirish Scd004b32012-08-30 07:04:06 +00001511 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001512}
1513
Chris Wilson14544d02016-10-24 12:38:21 +01001514static void connector_bad_edid(struct drm_connector *connector,
1515 u8 *edid, int num_blocks)
1516{
1517 int i;
1518
1519 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1520 return;
1521
1522 dev_warn(connector->dev->dev,
1523 "%s: EDID is invalid:\n",
1524 connector->name);
1525 for (i = 0; i < num_blocks; i++) {
1526 u8 *block = edid + i * EDID_LENGTH;
1527 char prefix[20];
1528
1529 if (drm_edid_is_zero(block, EDID_LENGTH))
1530 sprintf(prefix, "\t[%02x] ZERO ", i);
1531 else if (!drm_edid_block_valid(block, i, false, NULL))
1532 sprintf(prefix, "\t[%02x] BAD ", i);
1533 else
1534 sprintf(prefix, "\t[%02x] GOOD ", i);
1535
1536 print_hex_dump(KERN_WARNING,
1537 prefix, DUMP_PREFIX_NONE, 16, 1,
1538 block, EDID_LENGTH, false);
1539 }
1540}
1541
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001542/**
1543 * drm_do_get_edid - get EDID data using a custom EDID block read function
1544 * @connector: connector we're probing
1545 * @get_edid_block: EDID block read function
1546 * @data: private data passed to the block read function
1547 *
1548 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1549 * exposes a different interface to read EDID blocks this function can be used
1550 * to get EDID data using a custom block read function.
1551 *
1552 * As in the general case the DDC bus is accessible by the kernel at the I2C
1553 * level, drivers must make all reasonable efforts to expose it as an I2C
1554 * adapter and use drm_get_edid() instead of abusing this function.
1555 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001556 * The EDID may be overridden using debugfs override_edid or firmare EDID
1557 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1558 * order. Having either of them bypasses actual EDID reads.
1559 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001560 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1561 */
1562struct edid *drm_do_get_edid(struct drm_connector *connector,
1563 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1564 size_t len),
1565 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001566{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001567 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001568 u8 *edid, *new;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001569 struct edid *override = NULL;
1570
1571 if (connector->override_edid)
1572 override = drm_edid_duplicate((const struct edid *)
1573 connector->edid_blob_ptr->data);
1574
1575 if (!override)
1576 override = drm_load_edid_firmware(connector);
1577
1578 if (!IS_ERR_OR_NULL(override))
1579 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001580
Chris Wilsonf14f3682016-10-17 09:35:12 +01001581 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001582 return NULL;
1583
1584 /* base block fetch */
1585 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001586 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001587 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001588 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001589 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001590 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001591 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001592 connector->null_edid_counter++;
1593 goto carp;
1594 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001595 }
1596 if (i == 4)
1597 goto carp;
1598
1599 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001600 valid_extensions = edid[0x7e];
1601 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001602 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001603
Chris Wilson14544d02016-10-24 12:38:21 +01001604 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001605 if (!new)
1606 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001607 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001608
Chris Wilsonf14f3682016-10-17 09:35:12 +01001609 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001610 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001611
Adam Jackson61e57a82010-03-29 21:43:18 +00001612 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001613 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001614 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001615 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001616 break;
1617 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001618
Chris Wilson14544d02016-10-24 12:38:21 +01001619 if (i == 4)
1620 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001621 }
1622
Chris Wilsonf14f3682016-10-17 09:35:12 +01001623 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001624 u8 *base;
1625
1626 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1627
Chris Wilsonf14f3682016-10-17 09:35:12 +01001628 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1629 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001630
1631 new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001632 if (!new)
1633 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001634
1635 base = new;
1636 for (i = 0; i <= edid[0x7e]; i++) {
1637 u8 *block = edid + i * EDID_LENGTH;
1638
1639 if (!drm_edid_block_valid(block, i, false, NULL))
1640 continue;
1641
1642 memcpy(base, block, EDID_LENGTH);
1643 base += EDID_LENGTH;
1644 }
1645
1646 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001647 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001648 }
1649
Chris Wilsonf14f3682016-10-17 09:35:12 +01001650 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001651
1652carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001653 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001654out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001655 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001656 return NULL;
1657}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001658EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001659
1660/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001661 * drm_probe_ddc() - probe DDC presence
1662 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001663 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001664 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001665 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001666bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001667drm_probe_ddc(struct i2c_adapter *adapter)
1668{
1669 unsigned char out;
1670
1671 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1672}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001673EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001674
1675/**
1676 * drm_get_edid - get EDID data, if available
1677 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001678 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001679 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001680 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001681 * attach it to the connector.
1682 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001683 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001684 */
1685struct edid *drm_get_edid(struct drm_connector *connector,
1686 struct i2c_adapter *adapter)
1687{
Dave Airlie40d9b042014-10-20 16:29:33 +10001688 struct edid *edid;
1689
Jani Nikula15f080f2017-02-17 17:20:53 +02001690 if (connector->force == DRM_FORCE_OFF)
1691 return NULL;
1692
1693 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001694 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001695
Dave Airlie40d9b042014-10-20 16:29:33 +10001696 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1697 if (edid)
1698 drm_get_displayid(connector, edid);
1699 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001700}
1701EXPORT_SYMBOL(drm_get_edid);
1702
Jani Nikula51f8da52013-09-27 15:08:27 +03001703/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001704 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1705 * @connector: connector we're probing
1706 * @adapter: I2C adapter to use for DDC
1707 *
1708 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1709 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1710 * switch DDC to the GPU which is retrieving EDID.
1711 *
1712 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1713 */
1714struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1715 struct i2c_adapter *adapter)
1716{
1717 struct pci_dev *pdev = connector->dev->pdev;
1718 struct edid *edid;
1719
1720 vga_switcheroo_lock_ddc(pdev);
1721 edid = drm_get_edid(connector, adapter);
1722 vga_switcheroo_unlock_ddc(pdev);
1723
1724 return edid;
1725}
1726EXPORT_SYMBOL(drm_get_edid_switcheroo);
1727
1728/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001729 * drm_edid_duplicate - duplicate an EDID and the extensions
1730 * @edid: EDID to duplicate
1731 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001732 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001733 */
1734struct edid *drm_edid_duplicate(const struct edid *edid)
1735{
1736 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1737}
1738EXPORT_SYMBOL(drm_edid_duplicate);
1739
Adam Jackson61e57a82010-03-29 21:43:18 +00001740/*** EDID parsing ***/
1741
Dave Airlief453ba02008-11-07 14:05:41 -08001742/**
1743 * edid_vendor - match a string against EDID's obfuscated vendor field
1744 * @edid: EDID to match
1745 * @vendor: vendor string
1746 *
1747 * Returns true if @vendor is in @edid, false otherwise
1748 */
Keith Packard170178f2017-12-13 00:44:26 -08001749static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001750{
1751 char edid_vendor[3];
1752
1753 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1754 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1755 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001756 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001757
1758 return !strncmp(edid_vendor, vendor, 3);
1759}
1760
1761/**
1762 * edid_get_quirks - return quirk flags for a given EDID
1763 * @edid: EDID to process
1764 *
1765 * This tells subsequent routines what fixes they need to apply.
1766 */
Keith Packard170178f2017-12-13 00:44:26 -08001767static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001768{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001769 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001770 int i;
1771
1772 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1773 quirk = &edid_quirk_list[i];
1774
1775 if (edid_vendor(edid, quirk->vendor) &&
1776 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1777 return quirk->quirks;
1778 }
1779
1780 return 0;
1781}
1782
1783#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001784#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001785
Dave Airlief453ba02008-11-07 14:05:41 -08001786/**
1787 * edid_fixup_preferred - set preferred modes based on quirk list
1788 * @connector: has mode list to fix up
1789 * @quirks: quirks list
1790 *
1791 * Walk the mode list for @connector, clearing the preferred status
1792 * on existing modes and setting it anew for the right mode ala @quirks.
1793 */
1794static void edid_fixup_preferred(struct drm_connector *connector,
1795 u32 quirks)
1796{
1797 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001798 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001799 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001800
1801 if (list_empty(&connector->probed_modes))
1802 return;
1803
1804 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1805 target_refresh = 60;
1806 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1807 target_refresh = 75;
1808
1809 preferred_mode = list_first_entry(&connector->probed_modes,
1810 struct drm_display_mode, head);
1811
1812 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1813 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1814
1815 if (cur_mode == preferred_mode)
1816 continue;
1817
1818 /* Largest mode is preferred */
1819 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1820 preferred_mode = cur_mode;
1821
Alex Deucher339d2022013-08-15 11:42:14 -04001822 cur_vrefresh = cur_mode->vrefresh ?
1823 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1824 preferred_vrefresh = preferred_mode->vrefresh ?
1825 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001826 /* At a given size, try to get closest to target refresh */
1827 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001828 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1829 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001830 preferred_mode = cur_mode;
1831 }
1832 }
1833
1834 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1835}
1836
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001837static bool
1838mode_is_rb(const struct drm_display_mode *mode)
1839{
1840 return (mode->htotal - mode->hdisplay == 160) &&
1841 (mode->hsync_end - mode->hdisplay == 80) &&
1842 (mode->hsync_end - mode->hsync_start == 32) &&
1843 (mode->vsync_start - mode->vdisplay == 3);
1844}
1845
Adam Jackson33c75312012-04-13 16:33:29 -04001846/*
1847 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1848 * @dev: Device to duplicate against
1849 * @hsize: Mode width
1850 * @vsize: Mode height
1851 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001852 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001853 *
1854 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001855 *
1856 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001857 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001858struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001859 int hsize, int vsize, int fresh,
1860 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001861{
Adam Jackson07a5e632009-12-03 17:44:38 -05001862 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001863
Thierry Redinga6b21832012-11-23 15:01:42 +01001864 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001865 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001866 if (hsize != ptr->hdisplay)
1867 continue;
1868 if (vsize != ptr->vdisplay)
1869 continue;
1870 if (fresh != drm_mode_vrefresh(ptr))
1871 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001872 if (rb != mode_is_rb(ptr))
1873 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001874
1875 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001876 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001877
1878 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001879}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001880EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001881
Adam Jacksond1ff6402010-03-29 21:43:26 +00001882typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1883
1884static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001885cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1886{
1887 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001888 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001889 u8 *det_base = ext + d;
1890
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001891 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001892 for (i = 0; i < n; i++)
1893 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1894}
1895
1896static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001897vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1898{
1899 unsigned int i, n = min((int)ext[0x02], 6);
1900 u8 *det_base = ext + 5;
1901
1902 if (ext[0x01] != 1)
1903 return; /* unknown version */
1904
1905 for (i = 0; i < n; i++)
1906 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1907}
1908
1909static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001910drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1911{
1912 int i;
1913 struct edid *edid = (struct edid *)raw_edid;
1914
1915 if (edid == NULL)
1916 return;
1917
1918 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1919 cb(&(edid->detailed_timings[i]), closure);
1920
Adam Jackson4d76a222010-08-03 14:38:17 -04001921 for (i = 1; i <= raw_edid[0x7e]; i++) {
1922 u8 *ext = raw_edid + (i * EDID_LENGTH);
1923 switch (*ext) {
1924 case CEA_EXT:
1925 cea_for_each_detailed_block(ext, cb, closure);
1926 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001927 case VTB_EXT:
1928 vtb_for_each_detailed_block(ext, cb, closure);
1929 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001930 default:
1931 break;
1932 }
1933 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001934}
1935
1936static void
1937is_rb(struct detailed_timing *t, void *data)
1938{
1939 u8 *r = (u8 *)t;
1940 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1941 if (r[15] & 0x10)
1942 *(bool *)data = true;
1943}
1944
1945/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1946static bool
1947drm_monitor_supports_rb(struct edid *edid)
1948{
1949 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001950 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001951 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1952 return ret;
1953 }
1954
1955 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1956}
1957
Adam Jackson7a374352010-03-29 21:43:30 +00001958static void
1959find_gtf2(struct detailed_timing *t, void *data)
1960{
1961 u8 *r = (u8 *)t;
1962 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1963 *(u8 **)data = r;
1964}
1965
1966/* Secondary GTF curve kicks in above some break frequency */
1967static int
1968drm_gtf2_hbreak(struct edid *edid)
1969{
1970 u8 *r = NULL;
1971 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1972 return r ? (r[12] * 2) : 0;
1973}
1974
1975static int
1976drm_gtf2_2c(struct edid *edid)
1977{
1978 u8 *r = NULL;
1979 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1980 return r ? r[13] : 0;
1981}
1982
1983static int
1984drm_gtf2_m(struct edid *edid)
1985{
1986 u8 *r = NULL;
1987 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1988 return r ? (r[15] << 8) + r[14] : 0;
1989}
1990
1991static int
1992drm_gtf2_k(struct edid *edid)
1993{
1994 u8 *r = NULL;
1995 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1996 return r ? r[16] : 0;
1997}
1998
1999static int
2000drm_gtf2_2j(struct edid *edid)
2001{
2002 u8 *r = NULL;
2003 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2004 return r ? r[17] : 0;
2005}
2006
2007/**
2008 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2009 * @edid: EDID block to scan
2010 */
2011static int standard_timing_level(struct edid *edid)
2012{
2013 if (edid->revision >= 2) {
2014 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2015 return LEVEL_CVT;
2016 if (drm_gtf2_hbreak(edid))
2017 return LEVEL_GTF2;
2018 return LEVEL_GTF;
2019 }
2020 return LEVEL_DMT;
2021}
2022
Adam Jackson23425ca2009-09-23 17:30:58 -04002023/*
2024 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2025 * monitors fill with ascii space (0x20) instead.
2026 */
2027static int
2028bad_std_timing(u8 a, u8 b)
2029{
2030 return (a == 0x00 && b == 0x00) ||
2031 (a == 0x01 && b == 0x01) ||
2032 (a == 0x20 && b == 0x20);
2033}
2034
Dave Airlief453ba02008-11-07 14:05:41 -08002035/**
2036 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002037 * @connector: connector of for the EDID block
2038 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002039 * @t: standard timing params
2040 *
2041 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002042 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002043 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002044static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002045drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002046 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002047{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002048 struct drm_device *dev = connector->dev;
2049 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002050 int hsize, vsize;
2051 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002052 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2053 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002054 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2055 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002056 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002057
Adam Jackson23425ca2009-09-23 17:30:58 -04002058 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2059 return NULL;
2060
Zhao Yakui5c612592009-06-22 13:17:10 +08002061 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2062 hsize = t->hsize * 8 + 248;
2063 /* vrefresh_rate = vfreq + 60 */
2064 vrefresh_rate = vfreq + 60;
2065 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002066 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002067 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002068 vsize = hsize;
2069 else
2070 vsize = (hsize * 10) / 16;
2071 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002072 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002073 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002074 vsize = (hsize * 4) / 5;
2075 else
2076 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002077
2078 /* HDTV hack, part 1 */
2079 if (vrefresh_rate == 60 &&
2080 ((hsize == 1360 && vsize == 765) ||
2081 (hsize == 1368 && vsize == 769))) {
2082 hsize = 1366;
2083 vsize = 768;
2084 }
2085
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002086 /*
2087 * If this connector already has a mode for this size and refresh
2088 * rate (because it came from detailed or CVT info), use that
2089 * instead. This way we don't have to guess at interlace or
2090 * reduced blanking.
2091 */
Adam Jackson522032d2010-04-09 16:52:49 +00002092 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002093 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2094 drm_mode_vrefresh(m) == vrefresh_rate)
2095 return NULL;
2096
Adam Jacksona0910c82010-03-29 21:43:28 +00002097 /* HDTV hack, part 2 */
2098 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2099 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002100 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002101 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002102 mode->hsync_start = mode->hsync_start - 1;
2103 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002104 return mode;
2105 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002106
Zhao Yakui559ee212009-09-03 09:33:47 +08002107 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002108 if (drm_monitor_supports_rb(edid)) {
2109 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2110 true);
2111 if (mode)
2112 return mode;
2113 }
2114 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002115 if (mode)
2116 return mode;
2117
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002118 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002119 switch (timing_level) {
2120 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002121 break;
2122 case LEVEL_GTF:
2123 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2124 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002125 case LEVEL_GTF2:
2126 /*
2127 * This is potentially wrong if there's ever a monitor with
2128 * more than one ranges section, each claiming a different
2129 * secondary GTF curve. Please don't do that.
2130 */
2131 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002132 if (!mode)
2133 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002134 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002135 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002136 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2137 vrefresh_rate, 0, 0,
2138 drm_gtf2_m(edid),
2139 drm_gtf2_2c(edid),
2140 drm_gtf2_k(edid),
2141 drm_gtf2_2j(edid));
2142 }
2143 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002144 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002145 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2146 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002147 break;
2148 }
Dave Airlief453ba02008-11-07 14:05:41 -08002149 return mode;
2150}
2151
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002152/*
2153 * EDID is delightfully ambiguous about how interlaced modes are to be
2154 * encoded. Our internal representation is of frame height, but some
2155 * HDTV detailed timings are encoded as field height.
2156 *
2157 * The format list here is from CEA, in frame size. Technically we
2158 * should be checking refresh rate too. Whatever.
2159 */
2160static void
2161drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2162 struct detailed_pixel_timing *pt)
2163{
2164 int i;
2165 static const struct {
2166 int w, h;
2167 } cea_interlaced[] = {
2168 { 1920, 1080 },
2169 { 720, 480 },
2170 { 1440, 480 },
2171 { 2880, 480 },
2172 { 720, 576 },
2173 { 1440, 576 },
2174 { 2880, 576 },
2175 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002176
2177 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2178 return;
2179
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002180 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002181 if ((mode->hdisplay == cea_interlaced[i].w) &&
2182 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2183 mode->vdisplay *= 2;
2184 mode->vsync_start *= 2;
2185 mode->vsync_end *= 2;
2186 mode->vtotal *= 2;
2187 mode->vtotal |= 1;
2188 }
2189 }
2190
2191 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2192}
2193
Dave Airlief453ba02008-11-07 14:05:41 -08002194/**
2195 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2196 * @dev: DRM device (needed to create new mode)
2197 * @edid: EDID block
2198 * @timing: EDID detailed timing info
2199 * @quirks: quirks to apply
2200 *
2201 * An EDID detailed timing block contains enough info for us to create and
2202 * return a new struct drm_display_mode.
2203 */
2204static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2205 struct edid *edid,
2206 struct detailed_timing *timing,
2207 u32 quirks)
2208{
2209 struct drm_display_mode *mode;
2210 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002211 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2212 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2213 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2214 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002215 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2216 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
Torsten Duwe16dad1d2013-03-23 15:38:22 +01002217 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002218 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
Dave Airlief453ba02008-11-07 14:05:41 -08002219
Adam Jacksonfc438962009-06-04 10:20:34 +10002220 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002221 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002222 return NULL;
2223
Michel Dänzer0454bea2009-06-15 16:56:07 +02002224 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002225 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002226 return NULL;
2227 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002228 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002229 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002230 }
2231
Zhao Yakuifcb45612009-10-14 09:11:25 +08002232 /* it is incorrect if hsync/vsync width is zero */
2233 if (!hsync_pulse_width || !vsync_pulse_width) {
2234 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2235 "Wrong Hsync/Vsync pulse width\n");
2236 return NULL;
2237 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002238
2239 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2240 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2241 if (!mode)
2242 return NULL;
2243
2244 goto set_size;
2245 }
2246
Dave Airlief453ba02008-11-07 14:05:41 -08002247 mode = drm_mode_create(dev);
2248 if (!mode)
2249 return NULL;
2250
Dave Airlief453ba02008-11-07 14:05:41 -08002251 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002252 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002253
Michel Dänzer0454bea2009-06-15 16:56:07 +02002254 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002255
Michel Dänzer0454bea2009-06-15 16:56:07 +02002256 mode->hdisplay = hactive;
2257 mode->hsync_start = mode->hdisplay + hsync_offset;
2258 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2259 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002260
Michel Dänzer0454bea2009-06-15 16:56:07 +02002261 mode->vdisplay = vactive;
2262 mode->vsync_start = mode->vdisplay + vsync_offset;
2263 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2264 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002265
Jesse Barnes7064fef2009-11-05 10:12:54 -08002266 /* Some EDIDs have bogus h/vtotal values */
2267 if (mode->hsync_end > mode->htotal)
2268 mode->htotal = mode->hsync_end + 1;
2269 if (mode->vsync_end > mode->vtotal)
2270 mode->vtotal = mode->vsync_end + 1;
2271
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002272 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002273
2274 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002275 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002276 }
2277
Michel Dänzer0454bea2009-06-15 16:56:07 +02002278 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2279 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2280 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2281 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002282
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002283set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002284 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2285 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002286
2287 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2288 mode->width_mm *= 10;
2289 mode->height_mm *= 10;
2290 }
2291
2292 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2293 mode->width_mm = edid->width_cm * 10;
2294 mode->height_mm = edid->height_cm * 10;
2295 }
2296
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002297 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002298 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002299 drm_mode_set_name(mode);
2300
Dave Airlief453ba02008-11-07 14:05:41 -08002301 return mode;
2302}
2303
Adam Jackson07a5e632009-12-03 17:44:38 -05002304static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002305mode_in_hsync_range(const struct drm_display_mode *mode,
2306 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002307{
2308 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002309
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002310 hmin = t[7];
2311 if (edid->revision >= 4)
2312 hmin += ((t[4] & 0x04) ? 255 : 0);
2313 hmax = t[8];
2314 if (edid->revision >= 4)
2315 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002316 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002317
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002318 return (hsync <= hmax && hsync >= hmin);
2319}
2320
2321static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002322mode_in_vsync_range(const struct drm_display_mode *mode,
2323 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002324{
2325 int vsync, vmin, vmax;
2326
2327 vmin = t[5];
2328 if (edid->revision >= 4)
2329 vmin += ((t[4] & 0x01) ? 255 : 0);
2330 vmax = t[6];
2331 if (edid->revision >= 4)
2332 vmax += ((t[4] & 0x02) ? 255 : 0);
2333 vsync = drm_mode_vrefresh(mode);
2334
2335 return (vsync <= vmax && vsync >= vmin);
2336}
2337
2338static u32
2339range_pixel_clock(struct edid *edid, u8 *t)
2340{
2341 /* unspecified */
2342 if (t[9] == 0 || t[9] == 255)
2343 return 0;
2344
2345 /* 1.4 with CVT support gives us real precision, yay */
2346 if (edid->revision >= 4 && t[10] == 0x04)
2347 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2348
2349 /* 1.3 is pathetic, so fuzz up a bit */
2350 return t[9] * 10000 + 5001;
2351}
2352
Adam Jackson07a5e632009-12-03 17:44:38 -05002353static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002354mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002355 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002356{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002357 u32 max_clock;
2358 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002359
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002360 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002361 return false;
2362
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002363 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002364 return false;
2365
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002366 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002367 if (mode->clock > max_clock)
2368 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002369
2370 /* 1.4 max horizontal check */
2371 if (edid->revision >= 4 && t[10] == 0x04)
2372 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2373 return false;
2374
2375 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2376 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002377
2378 return true;
2379}
2380
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002381static bool valid_inferred_mode(const struct drm_connector *connector,
2382 const struct drm_display_mode *mode)
2383{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002384 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002385 bool ok = false;
2386
2387 list_for_each_entry(m, &connector->probed_modes, head) {
2388 if (mode->hdisplay == m->hdisplay &&
2389 mode->vdisplay == m->vdisplay &&
2390 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2391 return false; /* duplicated */
2392 if (mode->hdisplay <= m->hdisplay &&
2393 mode->vdisplay <= m->vdisplay)
2394 ok = true;
2395 }
2396 return ok;
2397}
2398
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002399static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002400drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002401 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002402{
2403 int i, modes = 0;
2404 struct drm_display_mode *newmode;
2405 struct drm_device *dev = connector->dev;
2406
Thierry Redinga6b21832012-11-23 15:01:42 +01002407 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002408 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2409 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002410 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2411 if (newmode) {
2412 drm_mode_probed_add(connector, newmode);
2413 modes++;
2414 }
2415 }
2416 }
2417
2418 return modes;
2419}
2420
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002421/* fix up 1366x768 mode from 1368x768;
2422 * GFT/CVT can't express 1366 width which isn't dividable by 8
2423 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002424void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002425{
2426 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2427 mode->hdisplay = 1366;
2428 mode->hsync_start--;
2429 mode->hsync_end--;
2430 drm_mode_set_name(mode);
2431 }
2432}
2433
Adam Jacksonb309bd32012-04-13 16:33:40 -04002434static int
2435drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2436 struct detailed_timing *timing)
2437{
2438 int i, modes = 0;
2439 struct drm_display_mode *newmode;
2440 struct drm_device *dev = connector->dev;
2441
Thierry Redinga6b21832012-11-23 15:01:42 +01002442 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002443 const struct minimode *m = &extra_modes[i];
2444 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002445 if (!newmode)
2446 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002447
Takashi Iwai969218f2017-01-17 17:43:29 +01002448 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002449 if (!mode_in_range(newmode, edid, timing) ||
2450 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002451 drm_mode_destroy(dev, newmode);
2452 continue;
2453 }
2454
2455 drm_mode_probed_add(connector, newmode);
2456 modes++;
2457 }
2458
2459 return modes;
2460}
2461
2462static int
2463drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2464 struct detailed_timing *timing)
2465{
2466 int i, modes = 0;
2467 struct drm_display_mode *newmode;
2468 struct drm_device *dev = connector->dev;
2469 bool rb = drm_monitor_supports_rb(edid);
2470
Thierry Redinga6b21832012-11-23 15:01:42 +01002471 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002472 const struct minimode *m = &extra_modes[i];
2473 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002474 if (!newmode)
2475 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002476
Takashi Iwai969218f2017-01-17 17:43:29 +01002477 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002478 if (!mode_in_range(newmode, edid, timing) ||
2479 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002480 drm_mode_destroy(dev, newmode);
2481 continue;
2482 }
2483
2484 drm_mode_probed_add(connector, newmode);
2485 modes++;
2486 }
2487
2488 return modes;
2489}
2490
Adam Jackson13931572010-08-03 14:38:19 -04002491static void
2492do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002493{
Adam Jackson13931572010-08-03 14:38:19 -04002494 struct detailed_mode_closure *closure = c;
2495 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002496 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002497
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002498 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2499 return;
2500
2501 closure->modes += drm_dmt_modes_for_range(closure->connector,
2502 closure->edid,
2503 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002504
2505 if (!version_greater(closure->edid, 1, 1))
2506 return; /* GTF not defined yet */
2507
2508 switch (range->flags) {
2509 case 0x02: /* secondary gtf, XXX could do more */
2510 case 0x00: /* default gtf */
2511 closure->modes += drm_gtf_modes_for_range(closure->connector,
2512 closure->edid,
2513 timing);
2514 break;
2515 case 0x04: /* cvt, only in 1.4+ */
2516 if (!version_greater(closure->edid, 1, 3))
2517 break;
2518
2519 closure->modes += drm_cvt_modes_for_range(closure->connector,
2520 closure->edid,
2521 timing);
2522 break;
2523 case 0x01: /* just the ranges, no formula */
2524 default:
2525 break;
2526 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002527}
2528
Adam Jackson13931572010-08-03 14:38:19 -04002529static int
2530add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2531{
2532 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002533 .connector = connector,
2534 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002535 };
2536
2537 if (version_greater(edid, 1, 0))
2538 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2539 &closure);
2540
2541 return closure.modes;
2542}
2543
Adam Jackson2255be12010-03-29 21:43:22 +00002544static int
2545drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2546{
2547 int i, j, m, modes = 0;
2548 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002549 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002550
2551 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002552 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002553 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002554 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002555 break;
2556 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002557 mode = drm_mode_find_dmt(connector->dev,
2558 est3_modes[m].w,
2559 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002560 est3_modes[m].r,
2561 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002562 if (mode) {
2563 drm_mode_probed_add(connector, mode);
2564 modes++;
2565 }
2566 }
2567 }
2568 }
2569
2570 return modes;
2571}
2572
Adam Jackson13931572010-08-03 14:38:19 -04002573static void
2574do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002575{
Adam Jackson13931572010-08-03 14:38:19 -04002576 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002577 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002578
2579 if (data->type == EDID_DETAIL_EST_TIMINGS)
2580 closure->modes += drm_est3_modes(closure->connector, timing);
2581}
2582
2583/**
2584 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002585 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002586 * @edid: EDID block to scan
2587 *
2588 * Each EDID block contains a bitmap of the supported "established modes" list
2589 * (defined above). Tease them out and add them to the global modes list.
2590 */
2591static int
2592add_established_modes(struct drm_connector *connector, struct edid *edid)
2593{
Adam Jackson9cf00972009-12-03 17:44:36 -05002594 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002595 unsigned long est_bits = edid->established_timings.t1 |
2596 (edid->established_timings.t2 << 8) |
2597 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2598 int i, modes = 0;
2599 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002600 .connector = connector,
2601 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002602 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002603
Adam Jackson13931572010-08-03 14:38:19 -04002604 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2605 if (est_bits & (1<<i)) {
2606 struct drm_display_mode *newmode;
2607 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2608 if (newmode) {
2609 drm_mode_probed_add(connector, newmode);
2610 modes++;
2611 }
2612 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002613 }
2614
Adam Jackson13931572010-08-03 14:38:19 -04002615 if (version_greater(edid, 1, 0))
2616 drm_for_each_detailed_block((u8 *)edid,
2617 do_established_modes, &closure);
2618
2619 return modes + closure.modes;
2620}
2621
2622static void
2623do_standard_modes(struct detailed_timing *timing, void *c)
2624{
2625 struct detailed_mode_closure *closure = c;
2626 struct detailed_non_pixel *data = &timing->data.other_data;
2627 struct drm_connector *connector = closure->connector;
2628 struct edid *edid = closure->edid;
2629
2630 if (data->type == EDID_DETAIL_STD_MODES) {
2631 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002632 for (i = 0; i < 6; i++) {
2633 struct std_timing *std;
2634 struct drm_display_mode *newmode;
2635
2636 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002637 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002638 if (newmode) {
2639 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002640 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002641 }
2642 }
Adam Jackson13931572010-08-03 14:38:19 -04002643 }
2644}
2645
2646/**
2647 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002648 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002649 * @edid: EDID block to scan
2650 *
2651 * Standard modes can be calculated using the appropriate standard (DMT,
2652 * GTF or CVT. Grab them from @edid and add them to the list.
2653 */
2654static int
2655add_standard_modes(struct drm_connector *connector, struct edid *edid)
2656{
2657 int i, modes = 0;
2658 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002659 .connector = connector,
2660 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002661 };
2662
2663 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2664 struct drm_display_mode *newmode;
2665
2666 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002667 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002668 if (newmode) {
2669 drm_mode_probed_add(connector, newmode);
2670 modes++;
2671 }
2672 }
2673
2674 if (version_greater(edid, 1, 0))
2675 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2676 &closure);
2677
2678 /* XXX should also look for standard codes in VTB blocks */
2679
2680 return modes + closure.modes;
2681}
2682
Dave Airlief453ba02008-11-07 14:05:41 -08002683static int drm_cvt_modes(struct drm_connector *connector,
2684 struct detailed_timing *timing)
2685{
2686 int i, j, modes = 0;
2687 struct drm_display_mode *newmode;
2688 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002689 struct cvt_timing *cvt;
2690 const int rates[] = { 60, 85, 75, 60, 50 };
2691 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002692
2693 for (i = 0; i < 4; i++) {
2694 int uninitialized_var(width), height;
2695 cvt = &(timing->data.other_data.data.cvt[i]);
2696
2697 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002698 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002699
2700 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002701 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002702 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002703 width = height * 4 / 3;
2704 break;
2705 case 0x04:
2706 width = height * 16 / 9;
2707 break;
2708 case 0x08:
2709 width = height * 16 / 10;
2710 break;
2711 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002712 width = height * 15 / 9;
2713 break;
2714 }
2715
2716 for (j = 1; j < 5; j++) {
2717 if (cvt->code[2] & (1 << j)) {
2718 newmode = drm_cvt_mode(dev, width, height,
2719 rates[j], j == 0,
2720 false, false);
2721 if (newmode) {
2722 drm_mode_probed_add(connector, newmode);
2723 modes++;
2724 }
2725 }
2726 }
2727 }
2728
2729 return modes;
2730}
2731
Adam Jackson13931572010-08-03 14:38:19 -04002732static void
2733do_cvt_mode(struct detailed_timing *timing, void *c)
2734{
2735 struct detailed_mode_closure *closure = c;
2736 struct detailed_non_pixel *data = &timing->data.other_data;
2737
2738 if (data->type == EDID_DETAIL_CVT_3BYTE)
2739 closure->modes += drm_cvt_modes(closure->connector, timing);
2740}
Adam Jackson9cf00972009-12-03 17:44:36 -05002741
2742static int
Adam Jackson13931572010-08-03 14:38:19 -04002743add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2744{
2745 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002746 .connector = connector,
2747 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002748 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002749
Adam Jackson13931572010-08-03 14:38:19 -04002750 if (version_greater(edid, 1, 2))
2751 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002752
Adam Jackson13931572010-08-03 14:38:19 -04002753 /* XXX should also look for CVT codes in VTB blocks */
2754
2755 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002756}
2757
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002758static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2759
Adam Jackson13931572010-08-03 14:38:19 -04002760static void
2761do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002762{
Adam Jackson13931572010-08-03 14:38:19 -04002763 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002764 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002765
2766 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002767 newmode = drm_mode_detailed(closure->connector->dev,
2768 closure->edid, timing,
2769 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002770 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002771 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002772
Adam Jackson13931572010-08-03 14:38:19 -04002773 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002774 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2775
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002776 /*
2777 * Detailed modes are limited to 10kHz pixel clock resolution,
2778 * so fix up anything that looks like CEA/HDMI mode, but the clock
2779 * is just slightly off.
2780 */
2781 fixup_detailed_cea_mode_clock(newmode);
2782
Adam Jackson13931572010-08-03 14:38:19 -04002783 drm_mode_probed_add(closure->connector, newmode);
2784 closure->modes++;
2785 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002786 }
Ma Ling167f3a02009-03-20 14:09:48 +08002787}
2788
Adam Jackson13931572010-08-03 14:38:19 -04002789/*
2790 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002791 * @connector: attached connector
2792 * @edid: EDID block to scan
2793 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002794 */
Adam Jackson13931572010-08-03 14:38:19 -04002795static int
2796add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2797 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002798{
Adam Jackson13931572010-08-03 14:38:19 -04002799 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002800 .connector = connector,
2801 .edid = edid,
2802 .preferred = 1,
2803 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002804 };
Dave Airlief453ba02008-11-07 14:05:41 -08002805
Adam Jackson13931572010-08-03 14:38:19 -04002806 if (closure.preferred && !version_greater(edid, 1, 3))
2807 closure.preferred =
2808 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002809
Adam Jackson13931572010-08-03 14:38:19 -04002810 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002811
Adam Jackson13931572010-08-03 14:38:19 -04002812 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002813}
Dave Airlief453ba02008-11-07 14:05:41 -08002814
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002815#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002816#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002817#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002818#define SPEAKER_BLOCK 0x04
Shashank Sharma87563fc2017-07-13 21:03:10 +05302819#define USE_EXTENDED_TAG 0x07
2820#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302821#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2822#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002823#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002824#define EDID_CEA_YCRCB444 (1 << 5)
2825#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002826#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002827
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002828/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002829 * Search EDID for CEA extension block.
2830 */
Keith Packard170178f2017-12-13 00:44:26 -08002831static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002832{
2833 u8 *edid_ext = NULL;
2834 int i;
2835
2836 /* No EDID or EDID extensions */
2837 if (edid == NULL || edid->extensions == 0)
2838 return NULL;
2839
2840 /* Find CEA extension */
2841 for (i = 0; i < edid->extensions; i++) {
2842 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002843 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002844 break;
2845 }
2846
2847 if (i == edid->extensions)
2848 return NULL;
2849
2850 return edid_ext;
2851}
2852
Keith Packard170178f2017-12-13 00:44:26 -08002853static u8 *drm_find_cea_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002854{
2855 return drm_find_edid_extension(edid, CEA_EXT);
2856}
2857
Keith Packard170178f2017-12-13 00:44:26 -08002858static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002859{
2860 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2861}
2862
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002863/*
2864 * Calculate the alternate clock for the CEA mode
2865 * (60Hz vs. 59.94Hz etc.)
2866 */
2867static unsigned int
2868cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2869{
2870 unsigned int clock = cea_mode->clock;
2871
2872 if (cea_mode->vrefresh % 6 != 0)
2873 return clock;
2874
2875 /*
2876 * edid_cea_modes contains the 59.94Hz
2877 * variant for 240 and 480 line modes,
2878 * and the 60Hz variant otherwise.
2879 */
2880 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002881 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002882 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002883 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002884
2885 return clock;
2886}
2887
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002888static bool
2889cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2890{
2891 /*
2892 * For certain VICs the spec allows the vertical
2893 * front porch to vary by one or two lines.
2894 *
2895 * cea_modes[] stores the variant with the shortest
2896 * vertical front porch. We can adjust the mode to
2897 * get the other variants by simply increasing the
2898 * vertical front porch length.
2899 */
2900 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
2901 edid_cea_modes[9].vtotal != 262 ||
2902 edid_cea_modes[12].vtotal != 262 ||
2903 edid_cea_modes[13].vtotal != 262 ||
2904 edid_cea_modes[23].vtotal != 312 ||
2905 edid_cea_modes[24].vtotal != 312 ||
2906 edid_cea_modes[27].vtotal != 312 ||
2907 edid_cea_modes[28].vtotal != 312);
2908
2909 if (((vic == 8 || vic == 9 ||
2910 vic == 12 || vic == 13) && mode->vtotal < 263) ||
2911 ((vic == 23 || vic == 24 ||
2912 vic == 27 || vic == 28) && mode->vtotal < 314)) {
2913 mode->vsync_start++;
2914 mode->vsync_end++;
2915 mode->vtotal++;
2916
2917 return true;
2918 }
2919
2920 return false;
2921}
2922
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002923static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
2924 unsigned int clock_tolerance)
2925{
Jani Nikulad9278b42016-01-08 13:21:51 +02002926 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002927
2928 if (!to_match->clock)
2929 return 0;
2930
Jani Nikulad9278b42016-01-08 13:21:51 +02002931 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002932 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002933 unsigned int clock1, clock2;
2934
2935 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002936 clock1 = cea_mode.clock;
2937 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002938
2939 if (abs(to_match->clock - clock1) > clock_tolerance &&
2940 abs(to_match->clock - clock2) > clock_tolerance)
2941 continue;
2942
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002943 do {
2944 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2945 return vic;
2946 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002947 }
2948
2949 return 0;
2950}
2951
Thierry Reding18316c82012-12-20 15:41:44 +01002952/**
2953 * drm_match_cea_mode - look for a CEA mode matching given mode
2954 * @to_match: display mode
2955 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002956 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
Thierry Reding18316c82012-12-20 15:41:44 +01002957 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002958 */
Thierry Reding18316c82012-12-20 15:41:44 +01002959u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002960{
Jani Nikulad9278b42016-01-08 13:21:51 +02002961 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00002962
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002963 if (!to_match->clock)
2964 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002965
Jani Nikulad9278b42016-01-08 13:21:51 +02002966 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002967 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002968 unsigned int clock1, clock2;
2969
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002970 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002971 clock1 = cea_mode.clock;
2972 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002973
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002974 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
2975 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
2976 continue;
2977
2978 do {
2979 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2980 return vic;
2981 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00002982 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002983
Stephane Marchesina4799032012-11-09 16:21:05 +00002984 return 0;
2985}
2986EXPORT_SYMBOL(drm_match_cea_mode);
2987
Jani Nikulad9278b42016-01-08 13:21:51 +02002988static bool drm_valid_cea_vic(u8 vic)
2989{
2990 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
2991}
2992
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302993/**
2994 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2995 * the input VIC from the CEA mode list
2996 * @video_code: ID given to each of the CEA modes
2997 *
2998 * Returns picture aspect ratio
2999 */
3000enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
3001{
Jani Nikulad9278b42016-01-08 13:21:51 +02003002 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303003}
3004EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
3005
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003006/*
3007 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3008 * specific block).
3009 *
3010 * It's almost like cea_mode_alternate_clock(), we just need to add an
3011 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3012 * one.
3013 */
3014static unsigned int
3015hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3016{
3017 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3018 return hdmi_mode->clock;
3019
3020 return cea_mode_alternate_clock(hdmi_mode);
3021}
3022
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003023static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3024 unsigned int clock_tolerance)
3025{
Jani Nikulad9278b42016-01-08 13:21:51 +02003026 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003027
3028 if (!to_match->clock)
3029 return 0;
3030
Jani Nikulad9278b42016-01-08 13:21:51 +02003031 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3032 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003033 unsigned int clock1, clock2;
3034
3035 /* Make sure to also match alternate clocks */
3036 clock1 = hdmi_mode->clock;
3037 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3038
3039 if (abs(to_match->clock - clock1) > clock_tolerance &&
3040 abs(to_match->clock - clock2) > clock_tolerance)
3041 continue;
3042
3043 if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003044 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003045 }
3046
3047 return 0;
3048}
3049
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003050/*
3051 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3052 * @to_match: display mode
3053 *
3054 * An HDMI mode is one defined in the HDMI vendor specific block.
3055 *
3056 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3057 */
3058static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3059{
Jani Nikulad9278b42016-01-08 13:21:51 +02003060 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003061
3062 if (!to_match->clock)
3063 return 0;
3064
Jani Nikulad9278b42016-01-08 13:21:51 +02003065 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3066 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003067 unsigned int clock1, clock2;
3068
3069 /* Make sure to also match alternate clocks */
3070 clock1 = hdmi_mode->clock;
3071 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3072
3073 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3074 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01003075 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003076 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003077 }
3078 return 0;
3079}
3080
Jani Nikulad9278b42016-01-08 13:21:51 +02003081static bool drm_valid_hdmi_vic(u8 vic)
3082{
3083 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3084}
3085
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003086static int
3087add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3088{
3089 struct drm_device *dev = connector->dev;
3090 struct drm_display_mode *mode, *tmp;
3091 LIST_HEAD(list);
3092 int modes = 0;
3093
3094 /* Don't add CEA modes if the CEA extension block is missing */
3095 if (!drm_find_cea_extension(edid))
3096 return 0;
3097
3098 /*
3099 * Go through all probed modes and create a new mode
3100 * with the alternate clock for certain CEA modes.
3101 */
3102 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003103 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003104 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003105 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003106 unsigned int clock1, clock2;
3107
Jani Nikulad9278b42016-01-08 13:21:51 +02003108 if (drm_valid_cea_vic(vic)) {
3109 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003110 clock2 = cea_mode_alternate_clock(cea_mode);
3111 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003112 vic = drm_match_hdmi_mode(mode);
3113 if (drm_valid_hdmi_vic(vic)) {
3114 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003115 clock2 = hdmi_mode_alternate_clock(cea_mode);
3116 }
3117 }
3118
3119 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003120 continue;
3121
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003122 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003123
3124 if (clock1 == clock2)
3125 continue;
3126
3127 if (mode->clock != clock1 && mode->clock != clock2)
3128 continue;
3129
3130 newmode = drm_mode_duplicate(dev, cea_mode);
3131 if (!newmode)
3132 continue;
3133
Damien Lespiau27130212013-09-25 16:45:28 +01003134 /* Carry over the stereo flags */
3135 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3136
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003137 /*
3138 * The current mode could be either variant. Make
3139 * sure to pick the "other" clock for the new mode.
3140 */
3141 if (mode->clock != clock1)
3142 newmode->clock = clock1;
3143 else
3144 newmode->clock = clock2;
3145
3146 list_add_tail(&newmode->head, &list);
3147 }
3148
3149 list_for_each_entry_safe(mode, tmp, &list, head) {
3150 list_del(&mode->head);
3151 drm_mode_probed_add(connector, mode);
3152 modes++;
3153 }
3154
3155 return modes;
3156}
Stephane Marchesina4799032012-11-09 16:21:05 +00003157
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303158static u8 svd_to_vic(u8 svd)
3159{
3160 /* 0-6 bit vic, 7th bit native mode indicator */
3161 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3162 return svd & 127;
3163
3164 return svd;
3165}
3166
Thomas Woodaff04ac2013-11-29 15:33:27 +00003167static struct drm_display_mode *
3168drm_display_mode_from_vic_index(struct drm_connector *connector,
3169 const u8 *video_db, u8 video_len,
3170 u8 video_index)
3171{
3172 struct drm_device *dev = connector->dev;
3173 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003174 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003175
3176 if (video_db == NULL || video_index >= video_len)
3177 return NULL;
3178
3179 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303180 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003181 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003182 return NULL;
3183
Jani Nikulad9278b42016-01-08 13:21:51 +02003184 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003185 if (!newmode)
3186 return NULL;
3187
Thomas Woodaff04ac2013-11-29 15:33:27 +00003188 newmode->vrefresh = 0;
3189
3190 return newmode;
3191}
3192
Shashank Sharma832d4f22017-07-14 16:03:46 +05303193/*
3194 * do_y420vdb_modes - Parse YCBCR 420 only modes
3195 * @connector: connector corresponding to the HDMI sink
3196 * @svds: start of the data block of CEA YCBCR 420 VDB
3197 * @len: length of the CEA YCBCR 420 VDB
3198 *
3199 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3200 * which contains modes which can be supported in YCBCR 420
3201 * output format only.
3202 */
3203static int do_y420vdb_modes(struct drm_connector *connector,
3204 const u8 *svds, u8 svds_len)
3205{
3206 int modes = 0, i;
3207 struct drm_device *dev = connector->dev;
3208 struct drm_display_info *info = &connector->display_info;
3209 struct drm_hdmi_info *hdmi = &info->hdmi;
3210
3211 for (i = 0; i < svds_len; i++) {
3212 u8 vic = svd_to_vic(svds[i]);
3213 struct drm_display_mode *newmode;
3214
3215 if (!drm_valid_cea_vic(vic))
3216 continue;
3217
3218 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3219 if (!newmode)
3220 break;
3221 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3222 drm_mode_probed_add(connector, newmode);
3223 modes++;
3224 }
3225
3226 if (modes > 0)
3227 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3228 return modes;
3229}
3230
3231/*
3232 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3233 * @connector: connector corresponding to the HDMI sink
3234 * @vic: CEA vic for the video mode to be added in the map
3235 *
3236 * Makes an entry for a videomode in the YCBCR 420 bitmap
3237 */
3238static void
3239drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3240{
3241 u8 vic = svd_to_vic(svd);
3242 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3243
3244 if (!drm_valid_cea_vic(vic))
3245 return;
3246
3247 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3248}
3249
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003250static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003251do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003252{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003253 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303254 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003255
Thomas Woodaff04ac2013-11-29 15:33:27 +00003256 for (i = 0; i < len; i++) {
3257 struct drm_display_mode *mode;
3258 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3259 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303260 /*
3261 * YCBCR420 capability block contains a bitmap which
3262 * gives the index of CEA modes from CEA VDB, which
3263 * can support YCBCR 420 sampling output also (apart
3264 * from RGB/YCBCR444 etc).
3265 * For example, if the bit 0 in bitmap is set,
3266 * first mode in VDB can support YCBCR420 output too.
3267 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3268 */
3269 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3270 drm_add_cmdb_modes(connector, db[i]);
3271
Thomas Woodaff04ac2013-11-29 15:33:27 +00003272 drm_mode_probed_add(connector, mode);
3273 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003274 }
3275 }
3276
3277 return modes;
3278}
3279
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003280struct stereo_mandatory_mode {
3281 int width, height, vrefresh;
3282 unsigned int flags;
3283};
3284
3285static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003286 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3287 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003288 { 1920, 1080, 50,
3289 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3290 { 1920, 1080, 60,
3291 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003292 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3293 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3294 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3295 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003296};
3297
3298static bool
3299stereo_match_mandatory(const struct drm_display_mode *mode,
3300 const struct stereo_mandatory_mode *stereo_mode)
3301{
3302 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3303
3304 return mode->hdisplay == stereo_mode->width &&
3305 mode->vdisplay == stereo_mode->height &&
3306 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3307 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3308}
3309
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003310static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3311{
3312 struct drm_device *dev = connector->dev;
3313 const struct drm_display_mode *mode;
3314 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003315 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003316
3317 INIT_LIST_HEAD(&stereo_modes);
3318
3319 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003320 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3321 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003322 struct drm_display_mode *new_mode;
3323
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003324 if (!stereo_match_mandatory(mode,
3325 &stereo_mandatory_modes[i]))
3326 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003327
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003328 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003329 new_mode = drm_mode_duplicate(dev, mode);
3330 if (!new_mode)
3331 continue;
3332
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003333 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003334 list_add_tail(&new_mode->head, &stereo_modes);
3335 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003336 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003337 }
3338
3339 list_splice_tail(&stereo_modes, &connector->probed_modes);
3340
3341 return modes;
3342}
3343
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003344static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3345{
3346 struct drm_device *dev = connector->dev;
3347 struct drm_display_mode *newmode;
3348
Jani Nikulad9278b42016-01-08 13:21:51 +02003349 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003350 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3351 return 0;
3352 }
3353
3354 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3355 if (!newmode)
3356 return 0;
3357
3358 drm_mode_probed_add(connector, newmode);
3359
3360 return 1;
3361}
3362
Thomas Woodfbf46022013-10-16 15:58:50 +01003363static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3364 const u8 *video_db, u8 video_len, u8 video_index)
3365{
Thomas Woodfbf46022013-10-16 15:58:50 +01003366 struct drm_display_mode *newmode;
3367 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003368
3369 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003370 newmode = drm_display_mode_from_vic_index(connector, video_db,
3371 video_len,
3372 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003373 if (newmode) {
3374 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3375 drm_mode_probed_add(connector, newmode);
3376 modes++;
3377 }
3378 }
3379 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003380 newmode = drm_display_mode_from_vic_index(connector, video_db,
3381 video_len,
3382 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003383 if (newmode) {
3384 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3385 drm_mode_probed_add(connector, newmode);
3386 modes++;
3387 }
3388 }
3389 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003390 newmode = drm_display_mode_from_vic_index(connector, video_db,
3391 video_len,
3392 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003393 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003394 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003395 drm_mode_probed_add(connector, newmode);
3396 modes++;
3397 }
3398 }
3399
3400 return modes;
3401}
3402
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003403/*
3404 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3405 * @connector: connector corresponding to the HDMI sink
3406 * @db: start of the CEA vendor specific block
3407 * @len: length of the CEA block payload, ie. one can access up to db[len]
3408 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003409 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3410 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003411 */
3412static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003413do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3414 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003415{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003416 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003417 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003418 u8 vic_len, hdmi_3d_len = 0;
3419 u16 mask;
3420 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003421
3422 if (len < 8)
3423 goto out;
3424
3425 /* no HDMI_Video_Present */
3426 if (!(db[8] & (1 << 5)))
3427 goto out;
3428
3429 /* Latency_Fields_Present */
3430 if (db[8] & (1 << 7))
3431 offset += 2;
3432
3433 /* I_Latency_Fields_Present */
3434 if (db[8] & (1 << 6))
3435 offset += 2;
3436
3437 /* the declared length is not long enough for the 2 first bytes
3438 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003439 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003440 goto out;
3441
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003442 /* 3D_Present */
3443 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003444 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003445 modes += add_hdmi_mandatory_stereo_modes(connector);
3446
Thomas Woodfbf46022013-10-16 15:58:50 +01003447 /* 3D_Multi_present */
3448 multi_present = (db[8 + offset] & 0x60) >> 5;
3449 }
3450
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003451 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003452 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003453 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003454
3455 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003456 u8 vic;
3457
3458 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003459 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003460 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003461 offset += 1 + vic_len;
3462
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003463 if (multi_present == 1)
3464 multi_len = 2;
3465 else if (multi_present == 2)
3466 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003467 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003468 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003469
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003470 if (len < (8 + offset + hdmi_3d_len - 1))
3471 goto out;
3472
3473 if (hdmi_3d_len < multi_len)
3474 goto out;
3475
3476 if (multi_present == 1 || multi_present == 2) {
3477 /* 3D_Structure_ALL */
3478 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3479
3480 /* check if 3D_MASK is present */
3481 if (multi_present == 2)
3482 mask = (db[10 + offset] << 8) | db[11 + offset];
3483 else
3484 mask = 0xffff;
3485
3486 for (i = 0; i < 16; i++) {
3487 if (mask & (1 << i))
3488 modes += add_3d_struct_modes(connector,
3489 structure_all,
3490 video_db,
3491 video_len, i);
3492 }
3493 }
3494
3495 offset += multi_len;
3496
3497 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3498 int vic_index;
3499 struct drm_display_mode *newmode = NULL;
3500 unsigned int newflag = 0;
3501 bool detail_present;
3502
3503 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3504
3505 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3506 break;
3507
3508 /* 2D_VIC_order_X */
3509 vic_index = db[8 + offset + i] >> 4;
3510
3511 /* 3D_Structure_X */
3512 switch (db[8 + offset + i] & 0x0f) {
3513 case 0:
3514 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3515 break;
3516 case 6:
3517 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3518 break;
3519 case 8:
3520 /* 3D_Detail_X */
3521 if ((db[9 + offset + i] >> 4) == 1)
3522 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3523 break;
3524 }
3525
3526 if (newflag != 0) {
3527 newmode = drm_display_mode_from_vic_index(connector,
3528 video_db,
3529 video_len,
3530 vic_index);
3531
3532 if (newmode) {
3533 newmode->flags |= newflag;
3534 drm_mode_probed_add(connector, newmode);
3535 modes++;
3536 }
3537 }
3538
3539 if (detail_present)
3540 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003541 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003542
3543out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003544 if (modes > 0)
3545 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003546 return modes;
3547}
3548
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003549static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003550cea_db_payload_len(const u8 *db)
3551{
3552 return db[0] & 0x1f;
3553}
3554
3555static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303556cea_db_extended_tag(const u8 *db)
3557{
3558 return db[1];
3559}
3560
3561static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003562cea_db_tag(const u8 *db)
3563{
3564 return db[0] >> 5;
3565}
3566
3567static int
3568cea_revision(const u8 *cea)
3569{
3570 return cea[1];
3571}
3572
3573static int
3574cea_db_offsets(const u8 *cea, int *start, int *end)
3575{
3576 /* Data block offset in CEA extension block */
3577 *start = 4;
3578 *end = cea[2];
3579 if (*end == 0)
3580 *end = 127;
3581 if (*end < 4 || *end > 127)
3582 return -ERANGE;
3583 return 0;
3584}
3585
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003586static bool cea_db_is_hdmi_vsdb(const u8 *db)
3587{
3588 int hdmi_id;
3589
3590 if (cea_db_tag(db) != VENDOR_BLOCK)
3591 return false;
3592
3593 if (cea_db_payload_len(db) < 5)
3594 return false;
3595
3596 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3597
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003598 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003599}
3600
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303601static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3602{
3603 unsigned int oui;
3604
3605 if (cea_db_tag(db) != VENDOR_BLOCK)
3606 return false;
3607
3608 if (cea_db_payload_len(db) < 7)
3609 return false;
3610
3611 oui = db[3] << 16 | db[2] << 8 | db[1];
3612
3613 return oui == HDMI_FORUM_IEEE_OUI;
3614}
3615
Shashank Sharma832d4f22017-07-14 16:03:46 +05303616static bool cea_db_is_y420cmdb(const u8 *db)
3617{
3618 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3619 return false;
3620
3621 if (!cea_db_payload_len(db))
3622 return false;
3623
3624 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3625 return false;
3626
3627 return true;
3628}
3629
3630static bool cea_db_is_y420vdb(const u8 *db)
3631{
3632 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3633 return false;
3634
3635 if (!cea_db_payload_len(db))
3636 return false;
3637
3638 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3639 return false;
3640
3641 return true;
3642}
3643
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003644#define for_each_cea_db(cea, i, start, end) \
3645 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3646
Shashank Sharma832d4f22017-07-14 16:03:46 +05303647static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3648 const u8 *db)
3649{
3650 struct drm_display_info *info = &connector->display_info;
3651 struct drm_hdmi_info *hdmi = &info->hdmi;
3652 u8 map_len = cea_db_payload_len(db) - 1;
3653 u8 count;
3654 u64 map = 0;
3655
3656 if (map_len == 0) {
3657 /* All CEA modes support ycbcr420 sampling also.*/
3658 hdmi->y420_cmdb_map = U64_MAX;
3659 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3660 return;
3661 }
3662
3663 /*
3664 * This map indicates which of the existing CEA block modes
3665 * from VDB can support YCBCR420 output too. So if bit=0 is
3666 * set, first mode from VDB can support YCBCR420 output too.
3667 * We will parse and keep this map, before parsing VDB itself
3668 * to avoid going through the same block again and again.
3669 *
3670 * Spec is not clear about max possible size of this block.
3671 * Clamping max bitmap block size at 8 bytes. Every byte can
3672 * address 8 CEA modes, in this way this map can address
3673 * 8*8 = first 64 SVDs.
3674 */
3675 if (WARN_ON_ONCE(map_len > 8))
3676 map_len = 8;
3677
3678 for (count = 0; count < map_len; count++)
3679 map |= (u64)db[2 + count] << (8 * count);
3680
3681 if (map)
3682 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3683
3684 hdmi->y420_cmdb_map = map;
3685}
3686
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003687static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003688add_cea_modes(struct drm_connector *connector, struct edid *edid)
3689{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003690 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003691 const u8 *db, *hdmi = NULL, *video = NULL;
3692 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003693 int modes = 0;
3694
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003695 if (cea && cea_revision(cea) >= 3) {
3696 int i, start, end;
3697
3698 if (cea_db_offsets(cea, &start, &end))
3699 return 0;
3700
3701 for_each_cea_db(cea, i, start, end) {
3702 db = &cea[i];
3703 dbl = cea_db_payload_len(db);
3704
Thomas Woodfbf46022013-10-16 15:58:50 +01003705 if (cea_db_tag(db) == VIDEO_BLOCK) {
3706 video = db + 1;
3707 video_len = dbl;
3708 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303709 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003710 hdmi = db;
3711 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303712 } else if (cea_db_is_y420vdb(db)) {
3713 const u8 *vdb420 = &db[2];
3714
3715 /* Add 4:2:0(only) modes present in EDID */
3716 modes += do_y420vdb_modes(connector,
3717 vdb420,
3718 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003719 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003720 }
3721 }
3722
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003723 /*
3724 * We parse the HDMI VSDB after having added the cea modes as we will
3725 * be patching their flags when the sink supports stereo 3D.
3726 */
3727 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003728 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3729 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003730
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003731 return modes;
3732}
3733
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003734static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3735{
3736 const struct drm_display_mode *cea_mode;
3737 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003738 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003739 const char *type;
3740
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003741 /*
3742 * allow 5kHz clock difference either way to account for
3743 * the 10kHz clock resolution limit of detailed timings.
3744 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003745 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3746 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003747 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003748 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003749 clock1 = cea_mode->clock;
3750 clock2 = cea_mode_alternate_clock(cea_mode);
3751 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003752 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3753 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003754 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003755 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003756 clock1 = cea_mode->clock;
3757 clock2 = hdmi_mode_alternate_clock(cea_mode);
3758 } else {
3759 return;
3760 }
3761 }
3762
3763 /* pick whichever is closest */
3764 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3765 clock = clock1;
3766 else
3767 clock = clock2;
3768
3769 if (mode->clock == clock)
3770 return;
3771
3772 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003773 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003774 mode->clock = clock;
3775}
3776
Wu Fengguang76adaa342011-09-05 14:23:20 +08003777static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003778drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003779{
Ville Syrjälä85040722012-08-16 14:55:05 +00003780 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003781
Jani Nikulaf7da77852017-11-01 16:20:57 +02003782 if (len >= 6 && (db[6] & (1 << 7)))
3783 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00003784 if (len >= 8) {
3785 connector->latency_present[0] = db[8] >> 7;
3786 connector->latency_present[1] = (db[8] >> 6) & 1;
3787 }
3788 if (len >= 9)
3789 connector->video_latency[0] = db[9];
3790 if (len >= 10)
3791 connector->audio_latency[0] = db[10];
3792 if (len >= 11)
3793 connector->video_latency[1] = db[11];
3794 if (len >= 12)
3795 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003796
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003797 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3798 "video latency %d %d, "
3799 "audio latency %d %d\n",
3800 connector->latency_present[0],
3801 connector->latency_present[1],
3802 connector->video_latency[0],
3803 connector->video_latency[1],
3804 connector->audio_latency[0],
3805 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003806}
3807
3808static void
3809monitor_name(struct detailed_timing *t, void *data)
3810{
3811 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3812 *(u8 **)data = t->data.other_data.data.str.str;
3813}
3814
Jim Bride59f7c0f2016-04-14 10:18:35 -07003815static int get_monitor_name(struct edid *edid, char name[13])
3816{
3817 char *edid_name = NULL;
3818 int mnl;
3819
3820 if (!edid || !name)
3821 return 0;
3822
3823 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
3824 for (mnl = 0; edid_name && mnl < 13; mnl++) {
3825 if (edid_name[mnl] == 0x0a)
3826 break;
3827
3828 name[mnl] = edid_name[mnl];
3829 }
3830
3831 return mnl;
3832}
3833
3834/**
3835 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3836 * @edid: monitor EDID information
3837 * @name: pointer to a character array to hold the name of the monitor
3838 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3839 *
3840 */
3841void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
3842{
3843 int name_length;
3844 char buf[13];
3845
3846 if (bufsize <= 0)
3847 return;
3848
3849 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
3850 memcpy(name, buf, name_length);
3851 name[name_length] = '\0';
3852}
3853EXPORT_SYMBOL(drm_edid_get_monitor_name);
3854
Jani Nikula42750d32017-11-01 16:21:00 +02003855static void clear_eld(struct drm_connector *connector)
3856{
3857 memset(connector->eld, 0, sizeof(connector->eld));
3858
3859 connector->latency_present[0] = false;
3860 connector->latency_present[1] = false;
3861 connector->video_latency[0] = 0;
3862 connector->audio_latency[0] = 0;
3863 connector->video_latency[1] = 0;
3864 connector->audio_latency[1] = 0;
3865}
3866
Jani Nikula79436a12017-11-01 16:21:03 +02003867/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08003868 * drm_edid_to_eld - build ELD from EDID
3869 * @connector: connector corresponding to the HDMI/DP sink
3870 * @edid: EDID to parse
3871 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003872 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02003873 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003874 */
Jani Nikula79436a12017-11-01 16:21:03 +02003875static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003876{
3877 uint8_t *eld = connector->eld;
3878 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003879 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02003880 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003881 int mnl;
3882 int dbl;
3883
Jani Nikula42750d32017-11-01 16:21:00 +02003884 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03003885
Jani Nikulae9bd0b82017-02-17 17:20:52 +02003886 if (!edid)
3887 return;
3888
Wu Fengguang76adaa342011-09-05 14:23:20 +08003889 cea = drm_find_cea_extension(edid);
3890 if (!cea) {
3891 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3892 return;
3893 }
3894
Jani Nikulaf7da77852017-11-01 16:20:57 +02003895 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
3896 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07003897
Jani Nikulaf7da77852017-11-01 16:20:57 +02003898 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
3899 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003900
Jani Nikulaf7da77852017-11-01 16:20:57 +02003901 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003902
Jani Nikulaf7da77852017-11-01 16:20:57 +02003903 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
3904 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
3905 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
3906 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003907
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003908 if (cea_revision(cea) >= 3) {
3909 int i, start, end;
3910
3911 if (cea_db_offsets(cea, &start, &end)) {
3912 start = 0;
3913 end = 0;
3914 }
3915
3916 for_each_cea_db(cea, i, start, end) {
3917 db = &cea[i];
3918 dbl = cea_db_payload_len(db);
3919
3920 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02003921 int sad_count;
3922
Christian Schmidta0ab7342011-12-19 20:03:38 +01003923 case AUDIO_BLOCK:
3924 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02003925 sad_count = min(dbl / 3, 15 - total_sad_count);
3926 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003927 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02003928 &db[1], sad_count * 3);
3929 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01003930 break;
3931 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003932 /* Speaker Allocation Data Block */
3933 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003934 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003935 break;
3936 case VENDOR_BLOCK:
3937 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003938 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003939 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003940 break;
3941 default:
3942 break;
3943 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003944 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003945 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02003946 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003947
Jani Nikula1d1c3662017-11-01 16:20:58 +02003948 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3949 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3950 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
3951 else
3952 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003953
Jani Nikula938fd8a2014-10-28 16:20:48 +02003954 eld[DRM_ELD_BASELINE_ELD_LEN] =
3955 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3956
3957 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02003958 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003959}
Wu Fengguang76adaa342011-09-05 14:23:20 +08003960
3961/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003962 * drm_edid_to_sad - extracts SADs from EDID
3963 * @edid: EDID to parse
3964 * @sads: pointer that will be set to the extracted SADs
3965 *
3966 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003967 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003968 * Note: The returned pointer needs to be freed using kfree().
3969 *
3970 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003971 */
3972int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3973{
3974 int count = 0;
3975 int i, start, end, dbl;
3976 u8 *cea;
3977
3978 cea = drm_find_cea_extension(edid);
3979 if (!cea) {
3980 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3981 return -ENOENT;
3982 }
3983
3984 if (cea_revision(cea) < 3) {
3985 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3986 return -ENOTSUPP;
3987 }
3988
3989 if (cea_db_offsets(cea, &start, &end)) {
3990 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3991 return -EPROTO;
3992 }
3993
3994 for_each_cea_db(cea, i, start, end) {
3995 u8 *db = &cea[i];
3996
3997 if (cea_db_tag(db) == AUDIO_BLOCK) {
3998 int j;
3999 dbl = cea_db_payload_len(db);
4000
4001 count = dbl / 3; /* SAD is 3B */
4002 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4003 if (!*sads)
4004 return -ENOMEM;
4005 for (j = 0; j < count; j++) {
4006 u8 *sad = &db[1 + j * 3];
4007
4008 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4009 (*sads)[j].channels = sad[0] & 0x7;
4010 (*sads)[j].freq = sad[1] & 0x7F;
4011 (*sads)[j].byte2 = sad[2];
4012 }
4013 break;
4014 }
4015 }
4016
4017 return count;
4018}
4019EXPORT_SYMBOL(drm_edid_to_sad);
4020
4021/**
Alex Deucherd105f472013-07-25 15:55:32 -04004022 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4023 * @edid: EDID to parse
4024 * @sadb: pointer to the speaker block
4025 *
4026 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004027 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004028 * Note: The returned pointer needs to be freed using kfree().
4029 *
4030 * Return: The number of found Speaker Allocation Blocks or negative number on
4031 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004032 */
4033int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4034{
4035 int count = 0;
4036 int i, start, end, dbl;
4037 const u8 *cea;
4038
4039 cea = drm_find_cea_extension(edid);
4040 if (!cea) {
4041 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4042 return -ENOENT;
4043 }
4044
4045 if (cea_revision(cea) < 3) {
4046 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4047 return -ENOTSUPP;
4048 }
4049
4050 if (cea_db_offsets(cea, &start, &end)) {
4051 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4052 return -EPROTO;
4053 }
4054
4055 for_each_cea_db(cea, i, start, end) {
4056 const u8 *db = &cea[i];
4057
4058 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4059 dbl = cea_db_payload_len(db);
4060
4061 /* Speaker Allocation Data Block */
4062 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004063 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004064 if (!*sadb)
4065 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004066 count = dbl;
4067 break;
4068 }
4069 }
4070 }
4071
4072 return count;
4073}
4074EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4075
4076/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004077 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004078 * @connector: connector associated with the HDMI/DP sink
4079 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004080 *
4081 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4082 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004083 */
4084int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004085 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004086{
4087 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4088 int a, v;
4089
4090 if (!connector->latency_present[0])
4091 return 0;
4092 if (!connector->latency_present[1])
4093 i = 0;
4094
4095 a = connector->audio_latency[i];
4096 v = connector->video_latency[i];
4097
4098 /*
4099 * HDMI/DP sink doesn't support audio or video?
4100 */
4101 if (a == 255 || v == 255)
4102 return 0;
4103
4104 /*
4105 * Convert raw EDID values to millisecond.
4106 * Treat unknown latency as 0ms.
4107 */
4108 if (a)
4109 a = min(2 * (a - 1), 500);
4110 if (v)
4111 v = min(2 * (v - 1), 500);
4112
4113 return max(v - a, 0);
4114}
4115EXPORT_SYMBOL(drm_av_sync_delay);
4116
4117/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004118 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004119 * @edid: monitor EDID information
4120 *
4121 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004122 *
4123 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004124 */
4125bool drm_detect_hdmi_monitor(struct edid *edid)
4126{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004127 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004128 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004129 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004130
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004131 edid_ext = drm_find_cea_extension(edid);
4132 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004133 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004134
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004135 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004136 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004137
4138 /*
4139 * Because HDMI identifier is in Vendor Specific Block,
4140 * search it from all data blocks of CEA extension.
4141 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004142 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004143 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4144 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004145 }
4146
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004147 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004148}
4149EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4150
Dave Airlief453ba02008-11-07 14:05:41 -08004151/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004152 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004153 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004154 *
4155 * Monitor should have CEA extension block.
4156 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4157 * audio' only. If there is any audio extension block and supported
4158 * audio format, assume at least 'basic audio' support, even if 'basic
4159 * audio' is not defined in EDID.
4160 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004161 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004162 */
4163bool drm_detect_monitor_audio(struct edid *edid)
4164{
4165 u8 *edid_ext;
4166 int i, j;
4167 bool has_audio = false;
4168 int start_offset, end_offset;
4169
4170 edid_ext = drm_find_cea_extension(edid);
4171 if (!edid_ext)
4172 goto end;
4173
4174 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4175
4176 if (has_audio) {
4177 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4178 goto end;
4179 }
4180
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004181 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4182 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004183
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004184 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4185 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004186 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004187 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004188 DRM_DEBUG_KMS("CEA audio format %d\n",
4189 (edid_ext[i + j] >> 3) & 0xf);
4190 goto end;
4191 }
4192 }
4193end:
4194 return has_audio;
4195}
4196EXPORT_SYMBOL(drm_detect_monitor_audio);
4197
4198/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004199 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01004200 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004201 *
4202 * Check whether the monitor reports the RGB quantization range selection
4203 * as supported. The AVI infoframe can then be used to inform the monitor
4204 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004205 *
4206 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004207 */
4208bool drm_rgb_quant_range_selectable(struct edid *edid)
4209{
4210 u8 *edid_ext;
4211 int i, start, end;
4212
4213 edid_ext = drm_find_cea_extension(edid);
4214 if (!edid_ext)
4215 return false;
4216
4217 if (cea_db_offsets(edid_ext, &start, &end))
4218 return false;
4219
4220 for_each_cea_db(edid_ext, i, start, end) {
Shashank Sharma87563fc2017-07-13 21:03:10 +05304221 if (cea_db_tag(&edid_ext[i]) == USE_EXTENDED_TAG &&
4222 cea_db_payload_len(&edid_ext[i]) == 2 &&
4223 cea_db_extended_tag(&edid_ext[i]) ==
4224 EXT_VIDEO_CAPABILITY_BLOCK) {
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004225 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
4226 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
4227 }
4228 }
4229
4230 return false;
4231}
4232EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
4233
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004234/**
4235 * drm_default_rgb_quant_range - default RGB quantization range
4236 * @mode: display mode
4237 *
4238 * Determine the default RGB quantization range for the mode,
4239 * as specified in CEA-861.
4240 *
4241 * Return: The default RGB quantization range for the mode
4242 */
4243enum hdmi_quantization_range
4244drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4245{
4246 /* All CEA modes other than VIC 1 use limited quantization range. */
4247 return drm_match_cea_mode(mode) > 1 ?
4248 HDMI_QUANTIZATION_RANGE_LIMITED :
4249 HDMI_QUANTIZATION_RANGE_FULL;
4250}
4251EXPORT_SYMBOL(drm_default_rgb_quant_range);
4252
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304253static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4254 const u8 *db)
4255{
4256 u8 dc_mask;
4257 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4258
4259 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
4260 hdmi->y420_dc_modes |= dc_mask;
4261}
4262
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304263static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4264 const u8 *hf_vsdb)
4265{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304266 struct drm_display_info *display = &connector->display_info;
4267 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304268
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004269 display->has_hdmi_infoframe = true;
4270
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304271 if (hf_vsdb[6] & 0x80) {
4272 hdmi->scdc.supported = true;
4273 if (hf_vsdb[6] & 0x40)
4274 hdmi->scdc.read_request = true;
4275 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304276
4277 /*
4278 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4279 * And as per the spec, three factors confirm this:
4280 * * Availability of a HF-VSDB block in EDID (check)
4281 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4282 * * SCDC support available (let's check)
4283 * Lets check it out.
4284 */
4285
4286 if (hf_vsdb[5]) {
4287 /* max clock is 5000 KHz times block value */
4288 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4289 struct drm_scdc *scdc = &hdmi->scdc;
4290
4291 if (max_tmds_clock > 340000) {
4292 display->max_tmds_clock = max_tmds_clock;
4293 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4294 display->max_tmds_clock);
4295 }
4296
4297 if (scdc->supported) {
4298 scdc->scrambling.supported = true;
4299
4300 /* Few sinks support scrambling for cloks < 340M */
4301 if ((hf_vsdb[6] & 0x8))
4302 scdc->scrambling.low_rates = true;
4303 }
4304 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304305
4306 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304307}
4308
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004309static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4310 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004311{
Ville Syrjälä18267502016-09-28 16:51:38 +03004312 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004313 unsigned int dc_bpc = 0;
4314
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004315 /* HDMI supports at least 8 bpc */
4316 info->bpc = 8;
4317
4318 if (cea_db_payload_len(hdmi) < 6)
4319 return;
4320
4321 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4322 dc_bpc = 10;
4323 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4324 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4325 connector->name);
4326 }
4327
4328 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4329 dc_bpc = 12;
4330 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4331 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4332 connector->name);
4333 }
4334
4335 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4336 dc_bpc = 16;
4337 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4338 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4339 connector->name);
4340 }
4341
4342 if (dc_bpc == 0) {
4343 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4344 connector->name);
4345 return;
4346 }
4347
4348 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4349 connector->name, dc_bpc);
4350 info->bpc = dc_bpc;
4351
4352 /*
4353 * Deep color support mandates RGB444 support for all video
4354 * modes and forbids YCRCB422 support for all video modes per
4355 * HDMI 1.3 spec.
4356 */
4357 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4358
4359 /* YCRCB444 is optional according to spec. */
4360 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4361 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4362 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4363 connector->name);
4364 }
4365
4366 /*
4367 * Spec says that if any deep color mode is supported at all,
4368 * then deep color 36 bit must be supported.
4369 */
4370 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4371 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4372 connector->name);
4373 }
4374}
4375
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004376static void
4377drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4378{
4379 struct drm_display_info *info = &connector->display_info;
4380 u8 len = cea_db_payload_len(db);
4381
4382 if (len >= 6)
4383 info->dvi_dual = db[6] & 1;
4384 if (len >= 7)
4385 info->max_tmds_clock = db[7] * 5000;
4386
4387 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4388 "max TMDS clock %d kHz\n",
4389 info->dvi_dual,
4390 info->max_tmds_clock);
4391
4392 drm_parse_hdmi_deep_color_info(connector, db);
4393}
4394
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004395static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004396 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004397{
4398 struct drm_display_info *info = &connector->display_info;
4399 const u8 *edid_ext;
4400 int i, start, end;
4401
Mario Kleinerd0c94692014-03-27 19:59:39 +01004402 edid_ext = drm_find_cea_extension(edid);
4403 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004404 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004405
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004406 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004407
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004408 /* The existence of a CEA block should imply RGB support */
4409 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4410 if (edid_ext[3] & EDID_CEA_YCRCB444)
4411 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4412 if (edid_ext[3] & EDID_CEA_YCRCB422)
4413 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004414
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004415 if (cea_db_offsets(edid_ext, &start, &end))
4416 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004417
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004418 for_each_cea_db(edid_ext, i, start, end) {
4419 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004420
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004421 if (cea_db_is_hdmi_vsdb(db))
4422 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304423 if (cea_db_is_hdmi_forum_vsdb(db))
4424 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304425 if (cea_db_is_y420cmdb(db))
4426 drm_parse_y420cmdb_bitmap(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004427 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004428}
4429
Keith Packard170178f2017-12-13 00:44:26 -08004430/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4431 * all of the values which would have been set from EDID
4432 */
4433void
4434drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004435{
Ville Syrjälä18267502016-09-28 16:51:38 +03004436 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004437
Keith Packard170178f2017-12-13 00:44:26 -08004438 info->width_mm = 0;
4439 info->height_mm = 0;
4440
4441 info->bpc = 0;
4442 info->color_formats = 0;
4443 info->cea_rev = 0;
4444 info->max_tmds_clock = 0;
4445 info->dvi_dual = false;
4446 info->has_hdmi_infoframe = false;
4447
4448 info->non_desktop = 0;
4449}
4450EXPORT_SYMBOL_GPL(drm_reset_display_info);
4451
4452u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4453{
4454 struct drm_display_info *info = &connector->display_info;
4455
4456 u32 quirks = edid_get_quirks(edid);
4457
Jesse Barnes3b112282011-04-15 12:49:23 -07004458 info->width_mm = edid->width_cm * 10;
4459 info->height_mm = edid->height_cm * 10;
4460
4461 /* driver figures it out in this case */
4462 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004463 info->color_formats = 0;
Ville Syrjälä011acce2016-09-28 16:51:40 +03004464 info->cea_rev = 0;
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004465 info->max_tmds_clock = 0;
4466 info->dvi_dual = false;
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004467 info->has_hdmi_infoframe = false;
Jesse Barnes3b112282011-04-15 12:49:23 -07004468
Dave Airlie66660d42017-10-16 05:08:09 +01004469 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4470
Keith Packard170178f2017-12-13 00:44:26 -08004471 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4472
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004473 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004474 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004475
4476 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004477 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004478
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004479 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004480
Mario Kleiner210a0212016-07-06 12:05:48 +02004481 /*
4482 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4483 *
4484 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4485 * tells us to assume 8 bpc color depth if the EDID doesn't have
4486 * extensions which tell otherwise.
4487 */
4488 if ((info->bpc == 0) && (edid->revision < 4) &&
4489 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
4490 info->bpc = 8;
4491 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4492 connector->name, info->bpc);
4493 }
4494
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004495 /* Only defined for 1.4 with digital displays */
4496 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004497 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004498
Jesse Barnes3b112282011-04-15 12:49:23 -07004499 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4500 case DRM_EDID_DIGITAL_DEPTH_6:
4501 info->bpc = 6;
4502 break;
4503 case DRM_EDID_DIGITAL_DEPTH_8:
4504 info->bpc = 8;
4505 break;
4506 case DRM_EDID_DIGITAL_DEPTH_10:
4507 info->bpc = 10;
4508 break;
4509 case DRM_EDID_DIGITAL_DEPTH_12:
4510 info->bpc = 12;
4511 break;
4512 case DRM_EDID_DIGITAL_DEPTH_14:
4513 info->bpc = 14;
4514 break;
4515 case DRM_EDID_DIGITAL_DEPTH_16:
4516 info->bpc = 16;
4517 break;
4518 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4519 default:
4520 info->bpc = 0;
4521 break;
4522 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004523
Mario Kleinerd0c94692014-03-27 19:59:39 +01004524 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004525 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004526
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004527 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004528 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4529 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4530 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4531 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004532 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004533}
Keith Packard170178f2017-12-13 00:44:26 -08004534EXPORT_SYMBOL_GPL(drm_add_display_info);
Jesse Barnes3b112282011-04-15 12:49:23 -07004535
Dave Airliec97291772016-05-03 15:38:37 +10004536static int validate_displayid(u8 *displayid, int length, int idx)
4537{
4538 int i;
4539 u8 csum = 0;
4540 struct displayid_hdr *base;
4541
4542 base = (struct displayid_hdr *)&displayid[idx];
4543
4544 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4545 base->rev, base->bytes, base->prod_id, base->ext_count);
4546
4547 if (base->bytes + 5 > length - idx)
4548 return -EINVAL;
4549 for (i = idx; i <= base->bytes + 5; i++) {
4550 csum += displayid[i];
4551 }
4552 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004553 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004554 return -EINVAL;
4555 }
4556 return 0;
4557}
4558
Dave Airliea39ed682016-05-02 08:35:05 +10004559static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4560 struct displayid_detailed_timings_1 *timings)
4561{
4562 struct drm_display_mode *mode;
4563 unsigned pixel_clock = (timings->pixel_clock[0] |
4564 (timings->pixel_clock[1] << 8) |
4565 (timings->pixel_clock[2] << 16));
4566 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4567 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4568 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4569 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4570 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4571 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4572 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4573 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4574 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4575 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4576 mode = drm_mode_create(dev);
4577 if (!mode)
4578 return NULL;
4579
4580 mode->clock = pixel_clock * 10;
4581 mode->hdisplay = hactive;
4582 mode->hsync_start = mode->hdisplay + hsync;
4583 mode->hsync_end = mode->hsync_start + hsync_width;
4584 mode->htotal = mode->hdisplay + hblank;
4585
4586 mode->vdisplay = vactive;
4587 mode->vsync_start = mode->vdisplay + vsync;
4588 mode->vsync_end = mode->vsync_start + vsync_width;
4589 mode->vtotal = mode->vdisplay + vblank;
4590
4591 mode->flags = 0;
4592 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4593 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4594 mode->type = DRM_MODE_TYPE_DRIVER;
4595
4596 if (timings->flags & 0x80)
4597 mode->type |= DRM_MODE_TYPE_PREFERRED;
4598 mode->vrefresh = drm_mode_vrefresh(mode);
4599 drm_mode_set_name(mode);
4600
4601 return mode;
4602}
4603
4604static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4605 struct displayid_block *block)
4606{
4607 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4608 int i;
4609 int num_timings;
4610 struct drm_display_mode *newmode;
4611 int num_modes = 0;
4612 /* blocks must be multiple of 20 bytes length */
4613 if (block->num_bytes % 20)
4614 return 0;
4615
4616 num_timings = block->num_bytes / 20;
4617 for (i = 0; i < num_timings; i++) {
4618 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4619
4620 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4621 if (!newmode)
4622 continue;
4623
4624 drm_mode_probed_add(connector, newmode);
4625 num_modes++;
4626 }
4627 return num_modes;
4628}
4629
4630static int add_displayid_detailed_modes(struct drm_connector *connector,
4631 struct edid *edid)
4632{
4633 u8 *displayid;
4634 int ret;
4635 int idx = 1;
4636 int length = EDID_LENGTH;
4637 struct displayid_block *block;
4638 int num_modes = 0;
4639
4640 displayid = drm_find_displayid_extension(edid);
4641 if (!displayid)
4642 return 0;
4643
4644 ret = validate_displayid(displayid, length, idx);
4645 if (ret)
4646 return 0;
4647
4648 idx += sizeof(struct displayid_hdr);
4649 while (block = (struct displayid_block *)&displayid[idx],
4650 idx + sizeof(struct displayid_block) <= length &&
4651 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4652 block->num_bytes > 0) {
4653 idx += block->num_bytes + sizeof(struct displayid_block);
4654 switch (block->tag) {
4655 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4656 num_modes += add_displayid_detailed_1_modes(connector, block);
4657 break;
4658 }
4659 }
4660 return num_modes;
4661}
4662
Jesse Barnes3b112282011-04-15 12:49:23 -07004663/**
Dave Airlief453ba02008-11-07 14:05:41 -08004664 * drm_add_edid_modes - add modes from EDID data, if available
4665 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004666 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004667 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004668 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004669 * &drm_display_info structure and ELD in @connector with any information which
4670 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004671 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004672 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004673 */
4674int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4675{
4676 int num_modes = 0;
4677 u32 quirks;
4678
4679 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004680 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004681 return 0;
4682 }
Alex Deucher3c537882010-02-05 04:21:19 -05004683 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004684 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004685 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004686 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004687 return 0;
4688 }
4689
Jani Nikulac945b8c2017-11-01 16:21:01 +02004690 drm_edid_to_eld(connector, edid);
4691
Adam Jacksonc867df72010-03-29 21:43:21 +00004692 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304693 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4694 * To avoid multiple parsing of same block, lets parse that map
4695 * from sink info, before parsing CEA modes.
4696 */
Keith Packard170178f2017-12-13 00:44:26 -08004697 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304698
4699 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004700 * EDID spec says modes should be preferred in this order:
4701 * - preferred detailed mode
4702 * - other detailed modes from base block
4703 * - detailed modes from extension blocks
4704 * - CVT 3-byte code modes
4705 * - standard timing codes
4706 * - established timing codes
4707 * - modes inferred from GTF or CVT range information
4708 *
Adam Jackson13931572010-08-03 14:38:19 -04004709 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004710 *
4711 * XXX order for additional mode types in extension blocks?
4712 */
Adam Jackson13931572010-08-03 14:38:19 -04004713 num_modes += add_detailed_modes(connector, edid, quirks);
4714 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004715 num_modes += add_standard_modes(connector, edid);
4716 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004717 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004718 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004719 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004720 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4721 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004722
4723 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4724 edid_fixup_preferred(connector, quirks);
4725
Mario Kleinere10aec62016-07-06 12:05:44 +02004726 if (quirks & EDID_QUIRK_FORCE_6BPC)
4727 connector->display_info.bpc = 6;
4728
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004729 if (quirks & EDID_QUIRK_FORCE_8BPC)
4730 connector->display_info.bpc = 8;
4731
Mario Kleinere345da82017-04-21 17:05:08 +02004732 if (quirks & EDID_QUIRK_FORCE_10BPC)
4733 connector->display_info.bpc = 10;
4734
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004735 if (quirks & EDID_QUIRK_FORCE_12BPC)
4736 connector->display_info.bpc = 12;
4737
Dave Airlief453ba02008-11-07 14:05:41 -08004738 return num_modes;
4739}
4740EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004741
4742/**
4743 * drm_add_modes_noedid - add modes for the connectors without EDID
4744 * @connector: connector we're probing
4745 * @hdisplay: the horizontal display limit
4746 * @vdisplay: the vertical display limit
4747 *
4748 * Add the specified modes to the connector's mode list. Only when the
4749 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4750 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004751 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004752 */
4753int drm_add_modes_noedid(struct drm_connector *connector,
4754 int hdisplay, int vdisplay)
4755{
4756 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004757 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004758 struct drm_device *dev = connector->dev;
4759
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004760 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004761 if (hdisplay < 0)
4762 hdisplay = 0;
4763 if (vdisplay < 0)
4764 vdisplay = 0;
4765
4766 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004767 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004768 if (hdisplay && vdisplay) {
4769 /*
4770 * Only when two are valid, they will be used to check
4771 * whether the mode should be added to the mode list of
4772 * the connector.
4773 */
4774 if (ptr->hdisplay > hdisplay ||
4775 ptr->vdisplay > vdisplay)
4776 continue;
4777 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004778 if (drm_mode_vrefresh(ptr) > 61)
4779 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004780 mode = drm_mode_duplicate(dev, ptr);
4781 if (mode) {
4782 drm_mode_probed_add(connector, mode);
4783 num_modes++;
4784 }
4785 }
4786 return num_modes;
4787}
4788EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004789
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004790/**
4791 * drm_set_preferred_mode - Sets the preferred mode of a connector
4792 * @connector: connector whose mode list should be processed
4793 * @hpref: horizontal resolution of preferred mode
4794 * @vpref: vertical resolution of preferred mode
4795 *
4796 * Marks a mode as preferred if it matches the resolution specified by @hpref
4797 * and @vpref.
4798 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004799void drm_set_preferred_mode(struct drm_connector *connector,
4800 int hpref, int vpref)
4801{
4802 struct drm_display_mode *mode;
4803
4804 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004805 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004806 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004807 mode->type |= DRM_MODE_TYPE_PREFERRED;
4808 }
4809}
4810EXPORT_SYMBOL(drm_set_preferred_mode);
4811
Thierry Reding10a85122012-11-21 15:31:35 +01004812/**
4813 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4814 * data from a DRM display mode
4815 * @frame: HDMI AVI infoframe
4816 * @mode: DRM display mode
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304817 * @is_hdmi2_sink: Sink is HDMI 2.0 compliant
Thierry Reding10a85122012-11-21 15:31:35 +01004818 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004819 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01004820 */
4821int
4822drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304823 const struct drm_display_mode *mode,
4824 bool is_hdmi2_sink)
Thierry Reding10a85122012-11-21 15:31:35 +01004825{
4826 int err;
4827
4828 if (!frame || !mode)
4829 return -EINVAL;
4830
4831 err = hdmi_avi_infoframe_init(frame);
4832 if (err < 0)
4833 return err;
4834
Damien Lespiaubf02db92013-08-06 20:32:22 +01004835 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
4836 frame->pixel_repeat = 1;
4837
Thierry Reding10a85122012-11-21 15:31:35 +01004838 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01004839
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304840 /*
4841 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
4842 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
4843 * have to make sure we dont break HDMI 1.4 sinks.
4844 */
4845 if (!is_hdmi2_sink && frame->video_code > 64)
4846 frame->video_code = 0;
4847
4848 /*
4849 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
4850 * we should send its VIC in vendor infoframes, else send the
4851 * VIC in AVI infoframes. Lets check if this mode is present in
4852 * HDMI 1.4b 4K modes
4853 */
4854 if (frame->video_code) {
4855 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
4856 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
4857
4858 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
4859 frame->video_code = 0;
4860 }
4861
Thierry Reding10a85122012-11-21 15:31:35 +01004862 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304863
Vandana Kannan69ab6d32014-06-05 14:45:29 +05304864 /*
4865 * Populate picture aspect ratio from either
4866 * user input (if specified) or from the CEA mode list.
4867 */
4868 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
4869 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
4870 frame->picture_aspect = mode->picture_aspect_ratio;
4871 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304872 frame->picture_aspect = drm_get_cea_aspect_ratio(
4873 frame->video_code);
4874
Thierry Reding10a85122012-11-21 15:31:35 +01004875 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06004876 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01004877
4878 return 0;
4879}
4880EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004881
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004882/**
4883 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4884 * quantization range information
4885 * @frame: HDMI AVI infoframe
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004886 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004887 * @rgb_quant_range: RGB quantization range (Q)
4888 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
Daniel Vetter7cdeb372017-12-14 21:30:50 +01004889 * @is_hdmi2_sink: HDMI 2.0 sink, which has different default recommendations
4890 *
4891 * Note that @is_hdmi2_sink can be derived by looking at the
4892 * &drm_scdc.supported flag stored in &drm_hdmi_info.scdc,
4893 * &drm_display_info.hdmi, which can be found in &drm_connector.display_info.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004894 */
4895void
4896drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004897 const struct drm_display_mode *mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004898 enum hdmi_quantization_range rgb_quant_range,
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004899 bool rgb_quant_range_selectable,
4900 bool is_hdmi2_sink)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004901{
4902 /*
4903 * CEA-861:
4904 * "A Source shall not send a non-zero Q value that does not correspond
4905 * to the default RGB Quantization Range for the transmitted Picture
4906 * unless the Sink indicates support for the Q bit in a Video
4907 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004908 *
4909 * HDMI 2.0 recommends sending non-zero Q when it does match the
4910 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004911 */
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004912 if (rgb_quant_range_selectable ||
4913 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004914 frame->quantization_range = rgb_quant_range;
4915 else
4916 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004917
4918 /*
4919 * CEA-861-F:
4920 * "When transmitting any RGB colorimetry, the Source should set the
4921 * YQ-field to match the RGB Quantization Range being transmitted
4922 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4923 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004924 *
4925 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
4926 * by non-zero YQ when receiving RGB. There doesn't seem to be any
4927 * good way to tell which version of CEA-861 the sink supports, so
4928 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
4929 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004930 */
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004931 if (!is_hdmi2_sink ||
4932 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004933 frame->ycc_quantization_range =
4934 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4935 else
4936 frame->ycc_quantization_range =
4937 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004938}
4939EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
4940
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004941static enum hdmi_3d_structure
4942s3d_structure_from_display_mode(const struct drm_display_mode *mode)
4943{
4944 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
4945
4946 switch (layout) {
4947 case DRM_MODE_FLAG_3D_FRAME_PACKING:
4948 return HDMI_3D_STRUCTURE_FRAME_PACKING;
4949 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
4950 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
4951 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
4952 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
4953 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
4954 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
4955 case DRM_MODE_FLAG_3D_L_DEPTH:
4956 return HDMI_3D_STRUCTURE_L_DEPTH;
4957 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
4958 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
4959 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
4960 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
4961 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
4962 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
4963 default:
4964 return HDMI_3D_STRUCTURE_INVALID;
4965 }
4966}
4967
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004968/**
4969 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4970 * data from a DRM display mode
4971 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004972 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004973 * @mode: DRM display mode
4974 *
4975 * Note that there's is a need to send HDMI vendor infoframes only when using a
4976 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4977 * function will return -EINVAL, error that can be safely ignored.
4978 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004979 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004980 */
4981int
4982drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004983 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004984 const struct drm_display_mode *mode)
4985{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004986 /*
4987 * FIXME: sil-sii8620 doesn't have a connector around when
4988 * we need one, so we have to be prepared for a NULL connector.
4989 */
4990 bool has_hdmi_infoframe = connector ?
4991 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004992 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004993 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004994 u8 vic;
4995
4996 if (!frame || !mode)
4997 return -EINVAL;
4998
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004999 if (!has_hdmi_infoframe)
5000 return -EINVAL;
5001
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005002 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005003 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
5004
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005005 /*
5006 * Even if it's not absolutely necessary to send the infoframe
5007 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5008 * know that the sink can handle it. This is based on a
5009 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5010 * have trouble realizing that they shuld switch from 3D to 2D
5011 * mode if the source simply stops sending the infoframe when
5012 * it wants to switch from 3D to 2D.
5013 */
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005014
5015 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005016 return -EINVAL;
5017
5018 err = hdmi_vendor_infoframe_init(frame);
5019 if (err < 0)
5020 return err;
5021
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005022 frame->vic = vic;
5023 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005024
5025 return 0;
5026}
5027EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005028
Dave Airlie5e546cd2016-05-03 15:31:12 +10005029static int drm_parse_tiled_block(struct drm_connector *connector,
5030 struct displayid_block *block)
5031{
5032 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5033 u16 w, h;
5034 u8 tile_v_loc, tile_h_loc;
5035 u8 num_v_tile, num_h_tile;
5036 struct drm_tile_group *tg;
5037
5038 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5039 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5040
5041 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5042 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5043 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5044 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5045
5046 connector->has_tile = true;
5047 if (tile->tile_cap & 0x80)
5048 connector->tile_is_single_monitor = true;
5049
5050 connector->num_h_tile = num_h_tile + 1;
5051 connector->num_v_tile = num_v_tile + 1;
5052 connector->tile_h_loc = tile_h_loc;
5053 connector->tile_v_loc = tile_v_loc;
5054 connector->tile_h_size = w + 1;
5055 connector->tile_v_size = h + 1;
5056
5057 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5058 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5059 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5060 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5061 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5062
5063 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5064 if (!tg) {
5065 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5066 }
5067 if (!tg)
5068 return -ENOMEM;
5069
5070 if (connector->tile_group != tg) {
5071 /* if we haven't got a pointer,
5072 take the reference, drop ref to old tile group */
5073 if (connector->tile_group) {
5074 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5075 }
5076 connector->tile_group = tg;
5077 } else
5078 /* if same tile group, then release the ref we just took. */
5079 drm_mode_put_tile_group(connector->dev, tg);
5080 return 0;
5081}
5082
Dave Airlie40d9b042014-10-20 16:29:33 +10005083static int drm_parse_display_id(struct drm_connector *connector,
5084 u8 *displayid, int length,
5085 bool is_edid_extension)
5086{
5087 /* if this is an EDID extension the first byte will be 0x70 */
5088 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005089 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005090 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005091
5092 if (is_edid_extension)
5093 idx = 1;
5094
Dave Airliec97291772016-05-03 15:38:37 +10005095 ret = validate_displayid(displayid, length, idx);
5096 if (ret)
5097 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005098
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005099 idx += sizeof(struct displayid_hdr);
5100 while (block = (struct displayid_block *)&displayid[idx],
5101 idx + sizeof(struct displayid_block) <= length &&
5102 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
5103 block->num_bytes > 0) {
5104 idx += block->num_bytes + sizeof(struct displayid_block);
5105 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5106 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005107
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005108 switch (block->tag) {
5109 case DATA_BLOCK_TILED_DISPLAY:
5110 ret = drm_parse_tiled_block(connector, block);
5111 if (ret)
5112 return ret;
5113 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005114 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5115 /* handled in mode gathering code. */
5116 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005117 default:
5118 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5119 break;
5120 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005121 }
5122 return 0;
5123}
5124
5125static void drm_get_displayid(struct drm_connector *connector,
5126 struct edid *edid)
5127{
5128 void *displayid = NULL;
5129 int ret;
5130 connector->has_tile = false;
5131 displayid = drm_find_displayid_extension(edid);
5132 if (!displayid) {
5133 /* drop reference to any tile group we had */
5134 goto out_drop_ref;
5135 }
5136
5137 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5138 if (ret < 0)
5139 goto out_drop_ref;
5140 if (!connector->has_tile)
5141 goto out_drop_ref;
5142 return;
5143out_drop_ref:
5144 if (connector->tile_group) {
5145 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5146 connector->tile_group = NULL;
5147 }
5148 return;
5149}