blob: 9796c29dc004ce961ac65c1576ca34b1c1155cd9 [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 },
Philipp Zabelccffc9e2018-02-19 18:59:38 +0100180
181 /* Sony PlayStation VR Headset */
182 { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
Dave Airlief453ba02008-11-07 14:05:41 -0800183};
184
Thierry Redinga6b21832012-11-23 15:01:42 +0100185/*
186 * Autogenerated from the DMT spec.
187 * This table is copied from xfree86/modes/xf86EdidModes.c.
188 */
189static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300190 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100191 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
192 736, 832, 0, 350, 382, 385, 445, 0,
193 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300194 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100195 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
196 736, 832, 0, 400, 401, 404, 445, 0,
197 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300198 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100199 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
200 828, 936, 0, 400, 401, 404, 446, 0,
201 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300202 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100203 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300204 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100205 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300206 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100207 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
208 704, 832, 0, 480, 489, 492, 520, 0,
209 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300210 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100211 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
212 720, 840, 0, 480, 481, 484, 500, 0,
213 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300214 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100215 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
216 752, 832, 0, 480, 481, 484, 509, 0,
217 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300218 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100219 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
220 896, 1024, 0, 600, 601, 603, 625, 0,
221 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300222 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100223 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
224 968, 1056, 0, 600, 601, 605, 628, 0,
225 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300226 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100227 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
228 976, 1040, 0, 600, 637, 643, 666, 0,
229 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300230 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100231 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
232 896, 1056, 0, 600, 601, 604, 625, 0,
233 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300234 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100235 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
236 896, 1048, 0, 600, 601, 604, 631, 0,
237 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300238 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100239 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
240 880, 960, 0, 600, 603, 607, 636, 0,
241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300242 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100243 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
244 976, 1088, 0, 480, 486, 494, 517, 0,
245 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300246 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100247 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100248 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100249 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300250 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300251 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100252 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
253 1184, 1344, 0, 768, 771, 777, 806, 0,
254 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300255 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100256 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
257 1184, 1328, 0, 768, 771, 777, 806, 0,
258 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300259 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100260 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
261 1136, 1312, 0, 768, 769, 772, 800, 0,
262 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300263 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100264 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
265 1168, 1376, 0, 768, 769, 772, 808, 0,
266 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300267 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100268 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
269 1104, 1184, 0, 768, 771, 775, 813, 0,
270 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300271 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100272 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
273 1344, 1600, 0, 864, 865, 868, 900, 0,
274 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300275 /* 0x55 - 1280x720@60Hz */
276 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
277 1430, 1650, 0, 720, 725, 730, 750, 0,
278 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300279 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100280 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
281 1360, 1440, 0, 768, 771, 778, 790, 0,
282 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300283 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100284 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
285 1472, 1664, 0, 768, 771, 778, 798, 0,
286 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300287 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100288 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
289 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300290 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300291 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100292 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
293 1496, 1712, 0, 768, 771, 778, 809, 0,
294 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300295 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100296 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
297 1360, 1440, 0, 768, 771, 778, 813, 0,
298 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300299 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100300 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
301 1360, 1440, 0, 800, 803, 809, 823, 0,
302 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300303 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100304 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
305 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300306 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300307 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100308 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
309 1488, 1696, 0, 800, 803, 809, 838, 0,
310 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300311 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100312 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
313 1496, 1712, 0, 800, 803, 809, 843, 0,
314 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300315 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100316 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
317 1360, 1440, 0, 800, 803, 809, 847, 0,
318 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300319 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100320 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
321 1488, 1800, 0, 960, 961, 964, 1000, 0,
322 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300323 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100324 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
325 1504, 1728, 0, 960, 961, 964, 1011, 0,
326 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300327 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100328 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
329 1360, 1440, 0, 960, 963, 967, 1017, 0,
330 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300331 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100332 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
333 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
334 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300335 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100336 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
337 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
338 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300339 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100340 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
341 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
342 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300343 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100344 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
345 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
346 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300347 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100348 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
349 1536, 1792, 0, 768, 771, 777, 795, 0,
350 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300351 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100352 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
353 1440, 1520, 0, 768, 771, 776, 813, 0,
354 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300355 /* 0x51 - 1366x768@60Hz */
356 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
357 1579, 1792, 0, 768, 771, 774, 798, 0,
358 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
359 /* 0x56 - 1366x768@60Hz */
360 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
361 1436, 1500, 0, 768, 769, 772, 800, 0,
362 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300363 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100364 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
365 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
366 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300367 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100368 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
369 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
370 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300371 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100372 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
373 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
374 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300375 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100376 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
377 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
378 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300379 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100380 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
381 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
382 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300383 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100384 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
385 1520, 1600, 0, 900, 903, 909, 926, 0,
386 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300387 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100388 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
389 1672, 1904, 0, 900, 903, 909, 934, 0,
390 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300391 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100392 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
393 1688, 1936, 0, 900, 903, 909, 942, 0,
394 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300395 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100396 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
397 1696, 1952, 0, 900, 903, 909, 948, 0,
398 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300399 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100400 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
401 1520, 1600, 0, 900, 903, 909, 953, 0,
402 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300403 /* 0x53 - 1600x900@60Hz */
404 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
405 1704, 1800, 0, 900, 901, 904, 1000, 0,
406 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300407 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100408 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
409 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
410 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300411 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100412 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
413 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
414 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300415 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100416 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
417 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
418 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300419 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100420 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
421 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
422 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300423 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100424 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
425 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
426 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300427 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100428 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
429 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
430 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300431 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100432 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
433 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
434 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300435 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100436 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
437 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
438 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300439 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100440 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
441 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
442 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300443 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100444 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
445 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
446 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300447 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100448 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
449 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
450 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300451 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100452 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
453 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
454 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300455 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100456 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
457 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
458 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300459 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100460 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
461 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
462 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300463 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100464 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
465 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
466 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300467 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100468 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300469 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100470 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300471 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100472 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
473 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
474 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300475 /* 0x52 - 1920x1080@60Hz */
476 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
477 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
478 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300479 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100480 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
481 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
482 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300483 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100484 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
485 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
486 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300487 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100488 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
489 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
490 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300491 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100492 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
493 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
494 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300495 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100496 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
497 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
498 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300499 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100500 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
501 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
502 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300503 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100504 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
505 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
506 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300507 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100508 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
509 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
510 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300511 /* 0x54 - 2048x1152@60Hz */
512 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
513 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
514 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300515 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100516 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
517 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
518 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300519 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100520 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
521 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
522 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300523 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100524 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
525 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
526 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300527 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100528 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
529 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
530 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300531 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100532 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
533 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
534 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300535 /* 0x57 - 4096x2160@60Hz RB */
536 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
537 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
538 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
539 /* 0x58 - 4096x2160@59.94Hz RB */
540 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
541 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
542 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100543};
544
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300545/*
546 * These more or less come from the DMT spec. The 720x400 modes are
547 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
548 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
549 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
550 * mode.
551 *
552 * The DMT modes have been fact-checked; the rest are mild guesses.
553 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100554static const struct drm_display_mode edid_est_modes[] = {
555 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
556 968, 1056, 0, 600, 601, 605, 628, 0,
557 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
558 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
559 896, 1024, 0, 600, 601, 603, 625, 0,
560 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
561 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
562 720, 840, 0, 480, 481, 484, 500, 0,
563 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
564 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100565 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100566 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
567 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
568 768, 864, 0, 480, 483, 486, 525, 0,
569 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100570 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100571 752, 800, 0, 480, 490, 492, 525, 0,
572 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
573 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
574 846, 900, 0, 400, 421, 423, 449, 0,
575 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
576 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
577 846, 900, 0, 400, 412, 414, 449, 0,
578 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
579 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
580 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
581 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100582 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100583 1136, 1312, 0, 768, 769, 772, 800, 0,
584 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
585 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
586 1184, 1328, 0, 768, 771, 777, 806, 0,
587 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
588 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
589 1184, 1344, 0, 768, 771, 777, 806, 0,
590 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
591 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
592 1208, 1264, 0, 768, 768, 776, 817, 0,
593 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
594 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
595 928, 1152, 0, 624, 625, 628, 667, 0,
596 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
597 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
598 896, 1056, 0, 600, 601, 604, 625, 0,
599 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
600 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
601 976, 1040, 0, 600, 637, 643, 666, 0,
602 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
603 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
604 1344, 1600, 0, 864, 865, 868, 900, 0,
605 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
606};
607
608struct minimode {
609 short w;
610 short h;
611 short r;
612 short rb;
613};
614
615static const struct minimode est3_modes[] = {
616 /* byte 6 */
617 { 640, 350, 85, 0 },
618 { 640, 400, 85, 0 },
619 { 720, 400, 85, 0 },
620 { 640, 480, 85, 0 },
621 { 848, 480, 60, 0 },
622 { 800, 600, 85, 0 },
623 { 1024, 768, 85, 0 },
624 { 1152, 864, 75, 0 },
625 /* byte 7 */
626 { 1280, 768, 60, 1 },
627 { 1280, 768, 60, 0 },
628 { 1280, 768, 75, 0 },
629 { 1280, 768, 85, 0 },
630 { 1280, 960, 60, 0 },
631 { 1280, 960, 85, 0 },
632 { 1280, 1024, 60, 0 },
633 { 1280, 1024, 85, 0 },
634 /* byte 8 */
635 { 1360, 768, 60, 0 },
636 { 1440, 900, 60, 1 },
637 { 1440, 900, 60, 0 },
638 { 1440, 900, 75, 0 },
639 { 1440, 900, 85, 0 },
640 { 1400, 1050, 60, 1 },
641 { 1400, 1050, 60, 0 },
642 { 1400, 1050, 75, 0 },
643 /* byte 9 */
644 { 1400, 1050, 85, 0 },
645 { 1680, 1050, 60, 1 },
646 { 1680, 1050, 60, 0 },
647 { 1680, 1050, 75, 0 },
648 { 1680, 1050, 85, 0 },
649 { 1600, 1200, 60, 0 },
650 { 1600, 1200, 65, 0 },
651 { 1600, 1200, 70, 0 },
652 /* byte 10 */
653 { 1600, 1200, 75, 0 },
654 { 1600, 1200, 85, 0 },
655 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300656 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100657 { 1856, 1392, 60, 0 },
658 { 1856, 1392, 75, 0 },
659 { 1920, 1200, 60, 1 },
660 { 1920, 1200, 60, 0 },
661 /* byte 11 */
662 { 1920, 1200, 75, 0 },
663 { 1920, 1200, 85, 0 },
664 { 1920, 1440, 60, 0 },
665 { 1920, 1440, 75, 0 },
666};
667
668static const struct minimode extra_modes[] = {
669 { 1024, 576, 60, 0 },
670 { 1366, 768, 60, 0 },
671 { 1600, 900, 60, 0 },
672 { 1680, 945, 60, 0 },
673 { 1920, 1080, 60, 0 },
674 { 2048, 1152, 60, 0 },
675 { 2048, 1536, 60, 0 },
676};
677
678/*
679 * Probably taken from CEA-861 spec.
680 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200681 *
682 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100683 */
684static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200685 /* 0 - dummy, VICs start at 1 */
686 { },
Thierry Redinga6b21832012-11-23 15:01:42 +0100687 /* 1 - 640x480@60Hz */
688 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
689 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300690 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530691 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100692 /* 2 - 720x480@60Hz */
693 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
694 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300695 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530696 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100697 /* 3 - 720x480@60Hz */
698 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
699 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300700 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530701 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100702 /* 4 - 1280x720@60Hz */
703 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
704 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300705 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530706 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100707 /* 5 - 1920x1080i@60Hz */
708 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
709 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
710 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300711 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530712 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700713 /* 6 - 720(1440)x480i@60Hz */
714 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
715 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100716 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300717 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530718 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700719 /* 7 - 720(1440)x480i@60Hz */
720 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
721 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100722 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300723 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530724 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700725 /* 8 - 720(1440)x240@60Hz */
726 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
727 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100728 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300729 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530730 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700731 /* 9 - 720(1440)x240@60Hz */
732 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
733 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100734 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300735 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530736 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100737 /* 10 - 2880x480i@60Hz */
738 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
739 3204, 3432, 0, 480, 488, 494, 525, 0,
740 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300741 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530742 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100743 /* 11 - 2880x480i@60Hz */
744 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
745 3204, 3432, 0, 480, 488, 494, 525, 0,
746 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300747 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530748 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100749 /* 12 - 2880x240@60Hz */
750 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
751 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300752 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530753 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100754 /* 13 - 2880x240@60Hz */
755 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
756 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300757 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530758 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100759 /* 14 - 1440x480@60Hz */
760 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
761 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300762 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530763 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100764 /* 15 - 1440x480@60Hz */
765 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
766 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300767 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530768 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100769 /* 16 - 1920x1080@60Hz */
770 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
771 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300772 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530773 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100774 /* 17 - 720x576@50Hz */
775 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
776 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300777 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530778 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100779 /* 18 - 720x576@50Hz */
780 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
781 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300782 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530783 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100784 /* 19 - 1280x720@50Hz */
785 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
786 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300787 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530788 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100789 /* 20 - 1920x1080i@50Hz */
790 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
791 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
792 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300793 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530794 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700795 /* 21 - 720(1440)x576i@50Hz */
796 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
797 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100798 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300799 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530800 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700801 /* 22 - 720(1440)x576i@50Hz */
802 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
803 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100804 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300805 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530806 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700807 /* 23 - 720(1440)x288@50Hz */
808 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
809 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100810 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300811 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530812 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700813 /* 24 - 720(1440)x288@50Hz */
814 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
815 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100816 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300817 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530818 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100819 /* 25 - 2880x576i@50Hz */
820 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
821 3180, 3456, 0, 576, 580, 586, 625, 0,
822 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300823 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530824 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100825 /* 26 - 2880x576i@50Hz */
826 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
827 3180, 3456, 0, 576, 580, 586, 625, 0,
828 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300829 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530830 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100831 /* 27 - 2880x288@50Hz */
832 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
833 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300834 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530835 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100836 /* 28 - 2880x288@50Hz */
837 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
838 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300839 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530840 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100841 /* 29 - 1440x576@50Hz */
842 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
843 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300844 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530845 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100846 /* 30 - 1440x576@50Hz */
847 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
848 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300849 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530850 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100851 /* 31 - 1920x1080@50Hz */
852 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
853 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300854 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530855 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100856 /* 32 - 1920x1080@24Hz */
857 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
858 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300859 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530860 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100861 /* 33 - 1920x1080@25Hz */
862 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
863 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300864 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530865 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100866 /* 34 - 1920x1080@30Hz */
867 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
868 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300869 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530870 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100871 /* 35 - 2880x480@60Hz */
872 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
873 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300874 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530875 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100876 /* 36 - 2880x480@60Hz */
877 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
878 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300879 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530880 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100881 /* 37 - 2880x576@50Hz */
882 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
883 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300884 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530885 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100886 /* 38 - 2880x576@50Hz */
887 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
888 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300889 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530890 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100891 /* 39 - 1920x1080i@50Hz */
892 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
893 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
894 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300895 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530896 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100897 /* 40 - 1920x1080i@100Hz */
898 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
899 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
900 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300901 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530902 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100903 /* 41 - 1280x720@100Hz */
904 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
905 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300906 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530907 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100908 /* 42 - 720x576@100Hz */
909 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
910 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300911 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530912 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100913 /* 43 - 720x576@100Hz */
914 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
915 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300916 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530917 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700918 /* 44 - 720(1440)x576i@100Hz */
919 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
920 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100921 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700922 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530923 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700924 /* 45 - 720(1440)x576i@100Hz */
925 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
926 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100927 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700928 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530929 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100930 /* 46 - 1920x1080i@120Hz */
931 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
932 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
933 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300934 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530935 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100936 /* 47 - 1280x720@120Hz */
937 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
938 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300939 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530940 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100941 /* 48 - 720x480@120Hz */
942 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
943 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300944 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530945 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100946 /* 49 - 720x480@120Hz */
947 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
948 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300949 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530950 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700951 /* 50 - 720(1440)x480i@120Hz */
952 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
953 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100954 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300955 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530956 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700957 /* 51 - 720(1440)x480i@120Hz */
958 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
959 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100960 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300961 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530962 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100963 /* 52 - 720x576@200Hz */
964 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
965 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300966 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530967 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100968 /* 53 - 720x576@200Hz */
969 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
970 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300971 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530972 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700973 /* 54 - 720(1440)x576i@200Hz */
974 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
975 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100976 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300977 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530978 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700979 /* 55 - 720(1440)x576i@200Hz */
980 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
981 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100982 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300983 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530984 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100985 /* 56 - 720x480@240Hz */
986 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
987 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300988 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530989 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100990 /* 57 - 720x480@240Hz */
991 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
992 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300993 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530994 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200995 /* 58 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700996 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
997 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100998 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300999 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301000 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjäläe5878032016-11-03 14:53:28 +02001001 /* 59 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -07001002 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1003 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001004 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001005 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301006 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001007 /* 60 - 1280x720@24Hz */
1008 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1009 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001010 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301011 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001012 /* 61 - 1280x720@25Hz */
1013 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1014 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001015 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301016 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001017 /* 62 - 1280x720@30Hz */
1018 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1019 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001020 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301021 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001022 /* 63 - 1920x1080@120Hz */
1023 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1024 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001025 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301026 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001027 /* 64 - 1920x1080@100Hz */
1028 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001029 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001030 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301031 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301032 /* 65 - 1280x720@24Hz */
1033 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1034 3080, 3300, 0, 720, 725, 730, 750, 0,
1035 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1036 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1037 /* 66 - 1280x720@25Hz */
1038 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1039 3740, 3960, 0, 720, 725, 730, 750, 0,
1040 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1041 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1042 /* 67 - 1280x720@30Hz */
1043 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1044 3080, 3300, 0, 720, 725, 730, 750, 0,
1045 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1046 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1047 /* 68 - 1280x720@50Hz */
1048 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1049 1760, 1980, 0, 720, 725, 730, 750, 0,
1050 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1051 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1052 /* 69 - 1280x720@60Hz */
1053 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1054 1430, 1650, 0, 720, 725, 730, 750, 0,
1055 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1056 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1057 /* 70 - 1280x720@100Hz */
1058 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1059 1760, 1980, 0, 720, 725, 730, 750, 0,
1060 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1061 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1062 /* 71 - 1280x720@120Hz */
1063 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1064 1430, 1650, 0, 720, 725, 730, 750, 0,
1065 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1066 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1067 /* 72 - 1920x1080@24Hz */
1068 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1069 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1070 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1071 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1072 /* 73 - 1920x1080@25Hz */
1073 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1074 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1075 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1076 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1077 /* 74 - 1920x1080@30Hz */
1078 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1079 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1080 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1081 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1082 /* 75 - 1920x1080@50Hz */
1083 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1084 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1085 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1086 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1087 /* 76 - 1920x1080@60Hz */
1088 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1089 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1090 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1091 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1092 /* 77 - 1920x1080@100Hz */
1093 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1094 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1095 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1096 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1097 /* 78 - 1920x1080@120Hz */
1098 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1099 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1100 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1101 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1102 /* 79 - 1680x720@24Hz */
1103 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1104 3080, 3300, 0, 720, 725, 730, 750, 0,
1105 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1106 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1107 /* 80 - 1680x720@25Hz */
1108 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1109 2948, 3168, 0, 720, 725, 730, 750, 0,
1110 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1111 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1112 /* 81 - 1680x720@30Hz */
1113 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1114 2420, 2640, 0, 720, 725, 730, 750, 0,
1115 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1116 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1117 /* 82 - 1680x720@50Hz */
1118 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1119 1980, 2200, 0, 720, 725, 730, 750, 0,
1120 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1121 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1122 /* 83 - 1680x720@60Hz */
1123 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1124 1980, 2200, 0, 720, 725, 730, 750, 0,
1125 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1126 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1127 /* 84 - 1680x720@100Hz */
1128 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1129 1780, 2000, 0, 720, 725, 730, 825, 0,
1130 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1131 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1132 /* 85 - 1680x720@120Hz */
1133 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1134 1780, 2000, 0, 720, 725, 730, 825, 0,
1135 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1136 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1137 /* 86 - 2560x1080@24Hz */
1138 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1139 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1140 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1141 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1142 /* 87 - 2560x1080@25Hz */
1143 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1144 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1145 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1146 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1147 /* 88 - 2560x1080@30Hz */
1148 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1149 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1150 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1151 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1152 /* 89 - 2560x1080@50Hz */
1153 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1154 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1155 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1156 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1157 /* 90 - 2560x1080@60Hz */
1158 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1159 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1160 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1161 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1162 /* 91 - 2560x1080@100Hz */
1163 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1164 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1165 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1166 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1167 /* 92 - 2560x1080@120Hz */
1168 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1169 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1170 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1171 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1172 /* 93 - 3840x2160p@24Hz 16:9 */
1173 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1174 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1175 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1176 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1177 /* 94 - 3840x2160p@25Hz 16:9 */
1178 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1179 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1180 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1181 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1182 /* 95 - 3840x2160p@30Hz 16:9 */
1183 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1184 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1185 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1186 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1187 /* 96 - 3840x2160p@50Hz 16:9 */
1188 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1189 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1190 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1191 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1192 /* 97 - 3840x2160p@60Hz 16:9 */
1193 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1194 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1195 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1196 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1197 /* 98 - 4096x2160p@24Hz 256:135 */
1198 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1199 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1201 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1202 /* 99 - 4096x2160p@25Hz 256:135 */
1203 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1204 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1205 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1206 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1207 /* 100 - 4096x2160p@30Hz 256:135 */
1208 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1209 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1210 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1211 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1212 /* 101 - 4096x2160p@50Hz 256:135 */
1213 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1214 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1215 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1216 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1217 /* 102 - 4096x2160p@60Hz 256:135 */
1218 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1219 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1221 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1222 /* 103 - 3840x2160p@24Hz 64:27 */
1223 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1224 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1225 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1226 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1227 /* 104 - 3840x2160p@25Hz 64:27 */
1228 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1229 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1230 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1231 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1232 /* 105 - 3840x2160p@30Hz 64:27 */
1233 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1234 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1236 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1237 /* 106 - 3840x2160p@50Hz 64:27 */
1238 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1239 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1240 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1241 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1242 /* 107 - 3840x2160p@60Hz 64:27 */
1243 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1244 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1245 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1246 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001247};
1248
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001249/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001250 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001251 */
1252static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001253 /* 0 - dummy, VICs start at 1 */
1254 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001255 /* 1 - 3840x2160@30Hz */
1256 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1257 3840, 4016, 4104, 4400, 0,
1258 2160, 2168, 2178, 2250, 0,
1259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1260 .vrefresh = 30, },
1261 /* 2 - 3840x2160@25Hz */
1262 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1263 3840, 4896, 4984, 5280, 0,
1264 2160, 2168, 2178, 2250, 0,
1265 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1266 .vrefresh = 25, },
1267 /* 3 - 3840x2160@24Hz */
1268 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1269 3840, 5116, 5204, 5500, 0,
1270 2160, 2168, 2178, 2250, 0,
1271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1272 .vrefresh = 24, },
1273 /* 4 - 4096x2160@24Hz (SMPTE) */
1274 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1275 4096, 5116, 5204, 5500, 0,
1276 2160, 2168, 2178, 2250, 0,
1277 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1278 .vrefresh = 24, },
1279};
1280
Adam Jackson61e57a82010-03-29 21:43:18 +00001281/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001282
Adam Jackson083ae052009-09-23 17:30:45 -04001283static const u8 edid_header[] = {
1284 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1285};
Dave Airlief453ba02008-11-07 14:05:41 -08001286
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001287/**
1288 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1289 * @raw_edid: pointer to raw base EDID block
1290 *
1291 * Sanity check the header of the base EDID block.
1292 *
1293 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001294 */
1295int drm_edid_header_is_valid(const u8 *raw_edid)
1296{
1297 int i, score = 0;
1298
1299 for (i = 0; i < sizeof(edid_header); i++)
1300 if (raw_edid[i] == edid_header[i])
1301 score++;
1302
1303 return score;
1304}
1305EXPORT_SYMBOL(drm_edid_header_is_valid);
1306
Adam Jackson47819ba2012-05-30 16:42:39 -04001307static int edid_fixup __read_mostly = 6;
1308module_param_named(edid_fixup, edid_fixup, int, 0400);
1309MODULE_PARM_DESC(edid_fixup,
1310 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001311
Dave Airlie40d9b042014-10-20 16:29:33 +10001312static void drm_get_displayid(struct drm_connector *connector,
1313 struct edid *edid);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001314
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001315static int drm_edid_block_checksum(const u8 *raw_edid)
1316{
1317 int i;
1318 u8 csum = 0;
1319 for (i = 0; i < EDID_LENGTH; i++)
1320 csum += raw_edid[i];
1321
1322 return csum;
1323}
1324
Stefan Brünsd6885d62014-11-30 19:57:41 +01001325static bool drm_edid_is_zero(const u8 *in_edid, int length)
1326{
1327 if (memchr_inv(in_edid, 0, length))
1328 return false;
1329
1330 return true;
1331}
1332
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001333/**
1334 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1335 * @raw_edid: pointer to raw EDID block
1336 * @block: type of block to validate (0 for base, extension otherwise)
1337 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001338 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001339 *
1340 * Validate a base or extension EDID block and optionally dump bad blocks to
1341 * the console.
1342 *
1343 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001344 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001345bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1346 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001347{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001348 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001349 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001350
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001351 if (WARN_ON(!raw_edid))
1352 return false;
1353
Adam Jackson47819ba2012-05-30 16:42:39 -04001354 if (edid_fixup > 8 || edid_fixup < 0)
1355 edid_fixup = 6;
1356
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001357 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001358 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001359 if (score == 8) {
1360 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001361 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001362 } else if (score >= edid_fixup) {
1363 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1364 * The corrupt flag needs to be set here otherwise, the
1365 * fix-up code here will correct the problem, the
1366 * checksum is correct and the test fails
1367 */
1368 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001369 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001370 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1371 memcpy(raw_edid, edid_header, sizeof(edid_header));
1372 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001373 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001374 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001375 goto bad;
1376 }
1377 }
Dave Airlief453ba02008-11-07 14:05:41 -08001378
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001379 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001380 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001381 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001382 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001383
Adam Jackson4a638b42010-05-25 16:33:09 -04001384 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001385 if (raw_edid[0] == CEA_EXT) {
1386 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1387 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1388 } else {
1389 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001390 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001391
Adam Jackson4a638b42010-05-25 16:33:09 -04001392 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001393 }
Dave Airlief453ba02008-11-07 14:05:41 -08001394 }
1395
Adam Jackson61e57a82010-03-29 21:43:18 +00001396 /* per-block-type checks */
1397 switch (raw_edid[0]) {
1398 case 0: /* base */
1399 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001400 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001401 goto bad;
1402 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001403
Adam Jackson61e57a82010-03-29 21:43:18 +00001404 if (edid->revision > 4)
1405 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1406 break;
1407
1408 default:
1409 break;
1410 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001411
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001412 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001413
1414bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001415 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001416 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001417 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001418 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001419 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001420 print_hex_dump(KERN_NOTICE,
1421 " \t", DUMP_PREFIX_NONE, 16, 1,
1422 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001423 }
Dave Airlief453ba02008-11-07 14:05:41 -08001424 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001425 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001426}
Carsten Emdeda0df922012-03-18 22:37:33 +01001427EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001428
1429/**
1430 * drm_edid_is_valid - sanity check EDID data
1431 * @edid: EDID data
1432 *
1433 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001434 *
1435 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001436 */
1437bool drm_edid_is_valid(struct edid *edid)
1438{
1439 int i;
1440 u8 *raw = (u8 *)edid;
1441
1442 if (!edid)
1443 return false;
1444
1445 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001446 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001447 return false;
1448
1449 return true;
1450}
Alex Deucher3c537882010-02-05 04:21:19 -05001451EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001452
Adam Jackson61e57a82010-03-29 21:43:18 +00001453#define DDC_SEGMENT_ADDR 0x30
1454/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001455 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001456 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001457 * @buf: EDID data buffer to be filled
1458 * @block: 128 byte EDID block to start fetching from
1459 * @len: EDID data buffer length to fetch
1460 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001461 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001462 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001463 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001464 */
1465static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001466drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001467{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001468 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001469 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001470 unsigned char segment = block >> 1;
1471 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001472 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001473
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001474 /*
1475 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001476 * adapter reports EAGAIN. However, we find that bit-banging transfers
1477 * are susceptible to errors under a heavily loaded machine and
1478 * generate spurious NAKs and timeouts. Retrying the transfer
1479 * of the individual block a few times seems to overcome this.
1480 */
1481 do {
1482 struct i2c_msg msgs[] = {
1483 {
Shirish Scd004b32012-08-30 07:04:06 +00001484 .addr = DDC_SEGMENT_ADDR,
1485 .flags = 0,
1486 .len = 1,
1487 .buf = &segment,
1488 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001489 .addr = DDC_ADDR,
1490 .flags = 0,
1491 .len = 1,
1492 .buf = &start,
1493 }, {
1494 .addr = DDC_ADDR,
1495 .flags = I2C_M_RD,
1496 .len = len,
1497 .buf = buf,
1498 }
1499 };
Shirish Scd004b32012-08-30 07:04:06 +00001500
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001501 /*
1502 * Avoid sending the segment addr to not upset non-compliant
1503 * DDC monitors.
1504 */
Shirish Scd004b32012-08-30 07:04:06 +00001505 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1506
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001507 if (ret == -ENXIO) {
1508 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1509 adapter->name);
1510 break;
1511 }
Shirish Scd004b32012-08-30 07:04:06 +00001512 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001513
Shirish Scd004b32012-08-30 07:04:06 +00001514 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001515}
1516
Chris Wilson14544d02016-10-24 12:38:21 +01001517static void connector_bad_edid(struct drm_connector *connector,
1518 u8 *edid, int num_blocks)
1519{
1520 int i;
1521
1522 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1523 return;
1524
1525 dev_warn(connector->dev->dev,
1526 "%s: EDID is invalid:\n",
1527 connector->name);
1528 for (i = 0; i < num_blocks; i++) {
1529 u8 *block = edid + i * EDID_LENGTH;
1530 char prefix[20];
1531
1532 if (drm_edid_is_zero(block, EDID_LENGTH))
1533 sprintf(prefix, "\t[%02x] ZERO ", i);
1534 else if (!drm_edid_block_valid(block, i, false, NULL))
1535 sprintf(prefix, "\t[%02x] BAD ", i);
1536 else
1537 sprintf(prefix, "\t[%02x] GOOD ", i);
1538
1539 print_hex_dump(KERN_WARNING,
1540 prefix, DUMP_PREFIX_NONE, 16, 1,
1541 block, EDID_LENGTH, false);
1542 }
1543}
1544
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001545/**
1546 * drm_do_get_edid - get EDID data using a custom EDID block read function
1547 * @connector: connector we're probing
1548 * @get_edid_block: EDID block read function
1549 * @data: private data passed to the block read function
1550 *
1551 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1552 * exposes a different interface to read EDID blocks this function can be used
1553 * to get EDID data using a custom block read function.
1554 *
1555 * As in the general case the DDC bus is accessible by the kernel at the I2C
1556 * level, drivers must make all reasonable efforts to expose it as an I2C
1557 * adapter and use drm_get_edid() instead of abusing this function.
1558 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001559 * The EDID may be overridden using debugfs override_edid or firmare EDID
1560 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1561 * order. Having either of them bypasses actual EDID reads.
1562 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001563 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1564 */
1565struct edid *drm_do_get_edid(struct drm_connector *connector,
1566 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1567 size_t len),
1568 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001569{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001570 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001571 u8 *edid, *new;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001572 struct edid *override = NULL;
1573
1574 if (connector->override_edid)
1575 override = drm_edid_duplicate((const struct edid *)
1576 connector->edid_blob_ptr->data);
1577
1578 if (!override)
1579 override = drm_load_edid_firmware(connector);
1580
1581 if (!IS_ERR_OR_NULL(override))
1582 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001583
Chris Wilsonf14f3682016-10-17 09:35:12 +01001584 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001585 return NULL;
1586
1587 /* base block fetch */
1588 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001589 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001590 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001591 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001592 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001593 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001594 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001595 connector->null_edid_counter++;
1596 goto carp;
1597 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001598 }
1599 if (i == 4)
1600 goto carp;
1601
1602 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001603 valid_extensions = edid[0x7e];
1604 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001605 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001606
Chris Wilson14544d02016-10-24 12:38:21 +01001607 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001608 if (!new)
1609 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001610 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001611
Chris Wilsonf14f3682016-10-17 09:35:12 +01001612 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001613 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001614
Adam Jackson61e57a82010-03-29 21:43:18 +00001615 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001616 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001617 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001618 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001619 break;
1620 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001621
Chris Wilson14544d02016-10-24 12:38:21 +01001622 if (i == 4)
1623 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001624 }
1625
Chris Wilsonf14f3682016-10-17 09:35:12 +01001626 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001627 u8 *base;
1628
1629 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1630
Chris Wilsonf14f3682016-10-17 09:35:12 +01001631 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1632 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001633
1634 new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001635 if (!new)
1636 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001637
1638 base = new;
1639 for (i = 0; i <= edid[0x7e]; i++) {
1640 u8 *block = edid + i * EDID_LENGTH;
1641
1642 if (!drm_edid_block_valid(block, i, false, NULL))
1643 continue;
1644
1645 memcpy(base, block, EDID_LENGTH);
1646 base += EDID_LENGTH;
1647 }
1648
1649 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001650 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001651 }
1652
Chris Wilsonf14f3682016-10-17 09:35:12 +01001653 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001654
1655carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001656 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001657out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001658 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001659 return NULL;
1660}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001661EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001662
1663/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001664 * drm_probe_ddc() - probe DDC presence
1665 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001666 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001667 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001668 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001669bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001670drm_probe_ddc(struct i2c_adapter *adapter)
1671{
1672 unsigned char out;
1673
1674 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1675}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001676EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001677
1678/**
1679 * drm_get_edid - get EDID data, if available
1680 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001681 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001682 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001683 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001684 * attach it to the connector.
1685 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001686 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001687 */
1688struct edid *drm_get_edid(struct drm_connector *connector,
1689 struct i2c_adapter *adapter)
1690{
Dave Airlie40d9b042014-10-20 16:29:33 +10001691 struct edid *edid;
1692
Jani Nikula15f080f2017-02-17 17:20:53 +02001693 if (connector->force == DRM_FORCE_OFF)
1694 return NULL;
1695
1696 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001697 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001698
Dave Airlie40d9b042014-10-20 16:29:33 +10001699 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1700 if (edid)
1701 drm_get_displayid(connector, edid);
1702 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001703}
1704EXPORT_SYMBOL(drm_get_edid);
1705
Jani Nikula51f8da52013-09-27 15:08:27 +03001706/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001707 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1708 * @connector: connector we're probing
1709 * @adapter: I2C adapter to use for DDC
1710 *
1711 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1712 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1713 * switch DDC to the GPU which is retrieving EDID.
1714 *
1715 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1716 */
1717struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1718 struct i2c_adapter *adapter)
1719{
1720 struct pci_dev *pdev = connector->dev->pdev;
1721 struct edid *edid;
1722
1723 vga_switcheroo_lock_ddc(pdev);
1724 edid = drm_get_edid(connector, adapter);
1725 vga_switcheroo_unlock_ddc(pdev);
1726
1727 return edid;
1728}
1729EXPORT_SYMBOL(drm_get_edid_switcheroo);
1730
1731/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001732 * drm_edid_duplicate - duplicate an EDID and the extensions
1733 * @edid: EDID to duplicate
1734 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001735 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001736 */
1737struct edid *drm_edid_duplicate(const struct edid *edid)
1738{
1739 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1740}
1741EXPORT_SYMBOL(drm_edid_duplicate);
1742
Adam Jackson61e57a82010-03-29 21:43:18 +00001743/*** EDID parsing ***/
1744
Dave Airlief453ba02008-11-07 14:05:41 -08001745/**
1746 * edid_vendor - match a string against EDID's obfuscated vendor field
1747 * @edid: EDID to match
1748 * @vendor: vendor string
1749 *
1750 * Returns true if @vendor is in @edid, false otherwise
1751 */
Keith Packard170178f2017-12-13 00:44:26 -08001752static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001753{
1754 char edid_vendor[3];
1755
1756 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1757 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1758 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001759 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001760
1761 return !strncmp(edid_vendor, vendor, 3);
1762}
1763
1764/**
1765 * edid_get_quirks - return quirk flags for a given EDID
1766 * @edid: EDID to process
1767 *
1768 * This tells subsequent routines what fixes they need to apply.
1769 */
Keith Packard170178f2017-12-13 00:44:26 -08001770static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001771{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001772 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001773 int i;
1774
1775 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1776 quirk = &edid_quirk_list[i];
1777
1778 if (edid_vendor(edid, quirk->vendor) &&
1779 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1780 return quirk->quirks;
1781 }
1782
1783 return 0;
1784}
1785
1786#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001787#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001788
Dave Airlief453ba02008-11-07 14:05:41 -08001789/**
1790 * edid_fixup_preferred - set preferred modes based on quirk list
1791 * @connector: has mode list to fix up
1792 * @quirks: quirks list
1793 *
1794 * Walk the mode list for @connector, clearing the preferred status
1795 * on existing modes and setting it anew for the right mode ala @quirks.
1796 */
1797static void edid_fixup_preferred(struct drm_connector *connector,
1798 u32 quirks)
1799{
1800 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001801 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001802 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001803
1804 if (list_empty(&connector->probed_modes))
1805 return;
1806
1807 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1808 target_refresh = 60;
1809 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1810 target_refresh = 75;
1811
1812 preferred_mode = list_first_entry(&connector->probed_modes,
1813 struct drm_display_mode, head);
1814
1815 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1816 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1817
1818 if (cur_mode == preferred_mode)
1819 continue;
1820
1821 /* Largest mode is preferred */
1822 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1823 preferred_mode = cur_mode;
1824
Alex Deucher339d2022013-08-15 11:42:14 -04001825 cur_vrefresh = cur_mode->vrefresh ?
1826 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1827 preferred_vrefresh = preferred_mode->vrefresh ?
1828 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001829 /* At a given size, try to get closest to target refresh */
1830 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001831 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1832 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001833 preferred_mode = cur_mode;
1834 }
1835 }
1836
1837 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1838}
1839
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001840static bool
1841mode_is_rb(const struct drm_display_mode *mode)
1842{
1843 return (mode->htotal - mode->hdisplay == 160) &&
1844 (mode->hsync_end - mode->hdisplay == 80) &&
1845 (mode->hsync_end - mode->hsync_start == 32) &&
1846 (mode->vsync_start - mode->vdisplay == 3);
1847}
1848
Adam Jackson33c75312012-04-13 16:33:29 -04001849/*
1850 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1851 * @dev: Device to duplicate against
1852 * @hsize: Mode width
1853 * @vsize: Mode height
1854 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001855 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001856 *
1857 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001858 *
1859 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001860 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001861struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001862 int hsize, int vsize, int fresh,
1863 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001864{
Adam Jackson07a5e632009-12-03 17:44:38 -05001865 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001866
Thierry Redinga6b21832012-11-23 15:01:42 +01001867 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001868 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001869 if (hsize != ptr->hdisplay)
1870 continue;
1871 if (vsize != ptr->vdisplay)
1872 continue;
1873 if (fresh != drm_mode_vrefresh(ptr))
1874 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001875 if (rb != mode_is_rb(ptr))
1876 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001877
1878 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001879 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001880
1881 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001882}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001883EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001884
Adam Jacksond1ff6402010-03-29 21:43:26 +00001885typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1886
1887static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001888cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1889{
1890 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001891 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001892 u8 *det_base = ext + d;
1893
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001894 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001895 for (i = 0; i < n; i++)
1896 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1897}
1898
1899static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001900vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1901{
1902 unsigned int i, n = min((int)ext[0x02], 6);
1903 u8 *det_base = ext + 5;
1904
1905 if (ext[0x01] != 1)
1906 return; /* unknown version */
1907
1908 for (i = 0; i < n; i++)
1909 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1910}
1911
1912static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001913drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1914{
1915 int i;
1916 struct edid *edid = (struct edid *)raw_edid;
1917
1918 if (edid == NULL)
1919 return;
1920
1921 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1922 cb(&(edid->detailed_timings[i]), closure);
1923
Adam Jackson4d76a222010-08-03 14:38:17 -04001924 for (i = 1; i <= raw_edid[0x7e]; i++) {
1925 u8 *ext = raw_edid + (i * EDID_LENGTH);
1926 switch (*ext) {
1927 case CEA_EXT:
1928 cea_for_each_detailed_block(ext, cb, closure);
1929 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001930 case VTB_EXT:
1931 vtb_for_each_detailed_block(ext, cb, closure);
1932 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001933 default:
1934 break;
1935 }
1936 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001937}
1938
1939static void
1940is_rb(struct detailed_timing *t, void *data)
1941{
1942 u8 *r = (u8 *)t;
1943 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1944 if (r[15] & 0x10)
1945 *(bool *)data = true;
1946}
1947
1948/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1949static bool
1950drm_monitor_supports_rb(struct edid *edid)
1951{
1952 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001953 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001954 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1955 return ret;
1956 }
1957
1958 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1959}
1960
Adam Jackson7a374352010-03-29 21:43:30 +00001961static void
1962find_gtf2(struct detailed_timing *t, void *data)
1963{
1964 u8 *r = (u8 *)t;
1965 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1966 *(u8 **)data = r;
1967}
1968
1969/* Secondary GTF curve kicks in above some break frequency */
1970static int
1971drm_gtf2_hbreak(struct edid *edid)
1972{
1973 u8 *r = NULL;
1974 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1975 return r ? (r[12] * 2) : 0;
1976}
1977
1978static int
1979drm_gtf2_2c(struct edid *edid)
1980{
1981 u8 *r = NULL;
1982 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1983 return r ? r[13] : 0;
1984}
1985
1986static int
1987drm_gtf2_m(struct edid *edid)
1988{
1989 u8 *r = NULL;
1990 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1991 return r ? (r[15] << 8) + r[14] : 0;
1992}
1993
1994static int
1995drm_gtf2_k(struct edid *edid)
1996{
1997 u8 *r = NULL;
1998 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1999 return r ? r[16] : 0;
2000}
2001
2002static int
2003drm_gtf2_2j(struct edid *edid)
2004{
2005 u8 *r = NULL;
2006 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2007 return r ? r[17] : 0;
2008}
2009
2010/**
2011 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2012 * @edid: EDID block to scan
2013 */
2014static int standard_timing_level(struct edid *edid)
2015{
2016 if (edid->revision >= 2) {
2017 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2018 return LEVEL_CVT;
2019 if (drm_gtf2_hbreak(edid))
2020 return LEVEL_GTF2;
2021 return LEVEL_GTF;
2022 }
2023 return LEVEL_DMT;
2024}
2025
Adam Jackson23425ca2009-09-23 17:30:58 -04002026/*
2027 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2028 * monitors fill with ascii space (0x20) instead.
2029 */
2030static int
2031bad_std_timing(u8 a, u8 b)
2032{
2033 return (a == 0x00 && b == 0x00) ||
2034 (a == 0x01 && b == 0x01) ||
2035 (a == 0x20 && b == 0x20);
2036}
2037
Dave Airlief453ba02008-11-07 14:05:41 -08002038/**
2039 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002040 * @connector: connector of for the EDID block
2041 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002042 * @t: standard timing params
2043 *
2044 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002045 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002046 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002047static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002048drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002049 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002050{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002051 struct drm_device *dev = connector->dev;
2052 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002053 int hsize, vsize;
2054 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002055 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2056 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002057 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2058 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002059 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002060
Adam Jackson23425ca2009-09-23 17:30:58 -04002061 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2062 return NULL;
2063
Zhao Yakui5c612592009-06-22 13:17:10 +08002064 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2065 hsize = t->hsize * 8 + 248;
2066 /* vrefresh_rate = vfreq + 60 */
2067 vrefresh_rate = vfreq + 60;
2068 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002069 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002070 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002071 vsize = hsize;
2072 else
2073 vsize = (hsize * 10) / 16;
2074 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002075 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002076 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002077 vsize = (hsize * 4) / 5;
2078 else
2079 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002080
2081 /* HDTV hack, part 1 */
2082 if (vrefresh_rate == 60 &&
2083 ((hsize == 1360 && vsize == 765) ||
2084 (hsize == 1368 && vsize == 769))) {
2085 hsize = 1366;
2086 vsize = 768;
2087 }
2088
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002089 /*
2090 * If this connector already has a mode for this size and refresh
2091 * rate (because it came from detailed or CVT info), use that
2092 * instead. This way we don't have to guess at interlace or
2093 * reduced blanking.
2094 */
Adam Jackson522032d2010-04-09 16:52:49 +00002095 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002096 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2097 drm_mode_vrefresh(m) == vrefresh_rate)
2098 return NULL;
2099
Adam Jacksona0910c82010-03-29 21:43:28 +00002100 /* HDTV hack, part 2 */
2101 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2102 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002103 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002104 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002105 mode->hsync_start = mode->hsync_start - 1;
2106 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002107 return mode;
2108 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002109
Zhao Yakui559ee212009-09-03 09:33:47 +08002110 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002111 if (drm_monitor_supports_rb(edid)) {
2112 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2113 true);
2114 if (mode)
2115 return mode;
2116 }
2117 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002118 if (mode)
2119 return mode;
2120
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002121 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002122 switch (timing_level) {
2123 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002124 break;
2125 case LEVEL_GTF:
2126 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2127 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002128 case LEVEL_GTF2:
2129 /*
2130 * This is potentially wrong if there's ever a monitor with
2131 * more than one ranges section, each claiming a different
2132 * secondary GTF curve. Please don't do that.
2133 */
2134 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002135 if (!mode)
2136 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002137 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002138 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002139 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2140 vrefresh_rate, 0, 0,
2141 drm_gtf2_m(edid),
2142 drm_gtf2_2c(edid),
2143 drm_gtf2_k(edid),
2144 drm_gtf2_2j(edid));
2145 }
2146 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002147 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002148 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2149 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002150 break;
2151 }
Dave Airlief453ba02008-11-07 14:05:41 -08002152 return mode;
2153}
2154
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002155/*
2156 * EDID is delightfully ambiguous about how interlaced modes are to be
2157 * encoded. Our internal representation is of frame height, but some
2158 * HDTV detailed timings are encoded as field height.
2159 *
2160 * The format list here is from CEA, in frame size. Technically we
2161 * should be checking refresh rate too. Whatever.
2162 */
2163static void
2164drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2165 struct detailed_pixel_timing *pt)
2166{
2167 int i;
2168 static const struct {
2169 int w, h;
2170 } cea_interlaced[] = {
2171 { 1920, 1080 },
2172 { 720, 480 },
2173 { 1440, 480 },
2174 { 2880, 480 },
2175 { 720, 576 },
2176 { 1440, 576 },
2177 { 2880, 576 },
2178 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002179
2180 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2181 return;
2182
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002183 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002184 if ((mode->hdisplay == cea_interlaced[i].w) &&
2185 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2186 mode->vdisplay *= 2;
2187 mode->vsync_start *= 2;
2188 mode->vsync_end *= 2;
2189 mode->vtotal *= 2;
2190 mode->vtotal |= 1;
2191 }
2192 }
2193
2194 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2195}
2196
Dave Airlief453ba02008-11-07 14:05:41 -08002197/**
2198 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2199 * @dev: DRM device (needed to create new mode)
2200 * @edid: EDID block
2201 * @timing: EDID detailed timing info
2202 * @quirks: quirks to apply
2203 *
2204 * An EDID detailed timing block contains enough info for us to create and
2205 * return a new struct drm_display_mode.
2206 */
2207static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2208 struct edid *edid,
2209 struct detailed_timing *timing,
2210 u32 quirks)
2211{
2212 struct drm_display_mode *mode;
2213 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002214 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2215 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2216 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2217 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002218 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2219 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 +01002220 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 +02002221 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 -08002222
Adam Jacksonfc438962009-06-04 10:20:34 +10002223 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002224 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002225 return NULL;
2226
Michel Dänzer0454bea2009-06-15 16:56:07 +02002227 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002228 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002229 return NULL;
2230 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002231 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002232 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002233 }
2234
Zhao Yakuifcb45612009-10-14 09:11:25 +08002235 /* it is incorrect if hsync/vsync width is zero */
2236 if (!hsync_pulse_width || !vsync_pulse_width) {
2237 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2238 "Wrong Hsync/Vsync pulse width\n");
2239 return NULL;
2240 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002241
2242 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2243 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2244 if (!mode)
2245 return NULL;
2246
2247 goto set_size;
2248 }
2249
Dave Airlief453ba02008-11-07 14:05:41 -08002250 mode = drm_mode_create(dev);
2251 if (!mode)
2252 return NULL;
2253
Dave Airlief453ba02008-11-07 14:05:41 -08002254 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002255 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002256
Michel Dänzer0454bea2009-06-15 16:56:07 +02002257 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002258
Michel Dänzer0454bea2009-06-15 16:56:07 +02002259 mode->hdisplay = hactive;
2260 mode->hsync_start = mode->hdisplay + hsync_offset;
2261 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2262 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002263
Michel Dänzer0454bea2009-06-15 16:56:07 +02002264 mode->vdisplay = vactive;
2265 mode->vsync_start = mode->vdisplay + vsync_offset;
2266 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2267 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002268
Jesse Barnes7064fef2009-11-05 10:12:54 -08002269 /* Some EDIDs have bogus h/vtotal values */
2270 if (mode->hsync_end > mode->htotal)
2271 mode->htotal = mode->hsync_end + 1;
2272 if (mode->vsync_end > mode->vtotal)
2273 mode->vtotal = mode->vsync_end + 1;
2274
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002275 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002276
2277 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002278 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002279 }
2280
Michel Dänzer0454bea2009-06-15 16:56:07 +02002281 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2282 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2283 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2284 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002285
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002286set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002287 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2288 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002289
2290 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2291 mode->width_mm *= 10;
2292 mode->height_mm *= 10;
2293 }
2294
2295 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2296 mode->width_mm = edid->width_cm * 10;
2297 mode->height_mm = edid->height_cm * 10;
2298 }
2299
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002300 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002301 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002302 drm_mode_set_name(mode);
2303
Dave Airlief453ba02008-11-07 14:05:41 -08002304 return mode;
2305}
2306
Adam Jackson07a5e632009-12-03 17:44:38 -05002307static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002308mode_in_hsync_range(const struct drm_display_mode *mode,
2309 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002310{
2311 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002312
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002313 hmin = t[7];
2314 if (edid->revision >= 4)
2315 hmin += ((t[4] & 0x04) ? 255 : 0);
2316 hmax = t[8];
2317 if (edid->revision >= 4)
2318 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002319 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002320
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002321 return (hsync <= hmax && hsync >= hmin);
2322}
2323
2324static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002325mode_in_vsync_range(const struct drm_display_mode *mode,
2326 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002327{
2328 int vsync, vmin, vmax;
2329
2330 vmin = t[5];
2331 if (edid->revision >= 4)
2332 vmin += ((t[4] & 0x01) ? 255 : 0);
2333 vmax = t[6];
2334 if (edid->revision >= 4)
2335 vmax += ((t[4] & 0x02) ? 255 : 0);
2336 vsync = drm_mode_vrefresh(mode);
2337
2338 return (vsync <= vmax && vsync >= vmin);
2339}
2340
2341static u32
2342range_pixel_clock(struct edid *edid, u8 *t)
2343{
2344 /* unspecified */
2345 if (t[9] == 0 || t[9] == 255)
2346 return 0;
2347
2348 /* 1.4 with CVT support gives us real precision, yay */
2349 if (edid->revision >= 4 && t[10] == 0x04)
2350 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2351
2352 /* 1.3 is pathetic, so fuzz up a bit */
2353 return t[9] * 10000 + 5001;
2354}
2355
Adam Jackson07a5e632009-12-03 17:44:38 -05002356static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002357mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002358 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002359{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002360 u32 max_clock;
2361 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002362
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002363 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002364 return false;
2365
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002366 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002367 return false;
2368
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002369 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002370 if (mode->clock > max_clock)
2371 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002372
2373 /* 1.4 max horizontal check */
2374 if (edid->revision >= 4 && t[10] == 0x04)
2375 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2376 return false;
2377
2378 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2379 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002380
2381 return true;
2382}
2383
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002384static bool valid_inferred_mode(const struct drm_connector *connector,
2385 const struct drm_display_mode *mode)
2386{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002387 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002388 bool ok = false;
2389
2390 list_for_each_entry(m, &connector->probed_modes, head) {
2391 if (mode->hdisplay == m->hdisplay &&
2392 mode->vdisplay == m->vdisplay &&
2393 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2394 return false; /* duplicated */
2395 if (mode->hdisplay <= m->hdisplay &&
2396 mode->vdisplay <= m->vdisplay)
2397 ok = true;
2398 }
2399 return ok;
2400}
2401
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002402static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002403drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002404 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002405{
2406 int i, modes = 0;
2407 struct drm_display_mode *newmode;
2408 struct drm_device *dev = connector->dev;
2409
Thierry Redinga6b21832012-11-23 15:01:42 +01002410 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002411 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2412 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002413 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2414 if (newmode) {
2415 drm_mode_probed_add(connector, newmode);
2416 modes++;
2417 }
2418 }
2419 }
2420
2421 return modes;
2422}
2423
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002424/* fix up 1366x768 mode from 1368x768;
2425 * GFT/CVT can't express 1366 width which isn't dividable by 8
2426 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002427void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002428{
2429 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2430 mode->hdisplay = 1366;
2431 mode->hsync_start--;
2432 mode->hsync_end--;
2433 drm_mode_set_name(mode);
2434 }
2435}
2436
Adam Jacksonb309bd32012-04-13 16:33:40 -04002437static int
2438drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2439 struct detailed_timing *timing)
2440{
2441 int i, modes = 0;
2442 struct drm_display_mode *newmode;
2443 struct drm_device *dev = connector->dev;
2444
Thierry Redinga6b21832012-11-23 15:01:42 +01002445 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002446 const struct minimode *m = &extra_modes[i];
2447 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002448 if (!newmode)
2449 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002450
Takashi Iwai969218f2017-01-17 17:43:29 +01002451 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002452 if (!mode_in_range(newmode, edid, timing) ||
2453 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002454 drm_mode_destroy(dev, newmode);
2455 continue;
2456 }
2457
2458 drm_mode_probed_add(connector, newmode);
2459 modes++;
2460 }
2461
2462 return modes;
2463}
2464
2465static int
2466drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2467 struct detailed_timing *timing)
2468{
2469 int i, modes = 0;
2470 struct drm_display_mode *newmode;
2471 struct drm_device *dev = connector->dev;
2472 bool rb = drm_monitor_supports_rb(edid);
2473
Thierry Redinga6b21832012-11-23 15:01:42 +01002474 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002475 const struct minimode *m = &extra_modes[i];
2476 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002477 if (!newmode)
2478 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002479
Takashi Iwai969218f2017-01-17 17:43:29 +01002480 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002481 if (!mode_in_range(newmode, edid, timing) ||
2482 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002483 drm_mode_destroy(dev, newmode);
2484 continue;
2485 }
2486
2487 drm_mode_probed_add(connector, newmode);
2488 modes++;
2489 }
2490
2491 return modes;
2492}
2493
Adam Jackson13931572010-08-03 14:38:19 -04002494static void
2495do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002496{
Adam Jackson13931572010-08-03 14:38:19 -04002497 struct detailed_mode_closure *closure = c;
2498 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002499 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002500
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002501 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2502 return;
2503
2504 closure->modes += drm_dmt_modes_for_range(closure->connector,
2505 closure->edid,
2506 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002507
2508 if (!version_greater(closure->edid, 1, 1))
2509 return; /* GTF not defined yet */
2510
2511 switch (range->flags) {
2512 case 0x02: /* secondary gtf, XXX could do more */
2513 case 0x00: /* default gtf */
2514 closure->modes += drm_gtf_modes_for_range(closure->connector,
2515 closure->edid,
2516 timing);
2517 break;
2518 case 0x04: /* cvt, only in 1.4+ */
2519 if (!version_greater(closure->edid, 1, 3))
2520 break;
2521
2522 closure->modes += drm_cvt_modes_for_range(closure->connector,
2523 closure->edid,
2524 timing);
2525 break;
2526 case 0x01: /* just the ranges, no formula */
2527 default:
2528 break;
2529 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002530}
2531
Adam Jackson13931572010-08-03 14:38:19 -04002532static int
2533add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2534{
2535 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002536 .connector = connector,
2537 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002538 };
2539
2540 if (version_greater(edid, 1, 0))
2541 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2542 &closure);
2543
2544 return closure.modes;
2545}
2546
Adam Jackson2255be12010-03-29 21:43:22 +00002547static int
2548drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2549{
2550 int i, j, m, modes = 0;
2551 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002552 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002553
2554 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002555 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002556 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002557 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002558 break;
2559 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002560 mode = drm_mode_find_dmt(connector->dev,
2561 est3_modes[m].w,
2562 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002563 est3_modes[m].r,
2564 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002565 if (mode) {
2566 drm_mode_probed_add(connector, mode);
2567 modes++;
2568 }
2569 }
2570 }
2571 }
2572
2573 return modes;
2574}
2575
Adam Jackson13931572010-08-03 14:38:19 -04002576static void
2577do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002578{
Adam Jackson13931572010-08-03 14:38:19 -04002579 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002580 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002581
2582 if (data->type == EDID_DETAIL_EST_TIMINGS)
2583 closure->modes += drm_est3_modes(closure->connector, timing);
2584}
2585
2586/**
2587 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002588 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002589 * @edid: EDID block to scan
2590 *
2591 * Each EDID block contains a bitmap of the supported "established modes" list
2592 * (defined above). Tease them out and add them to the global modes list.
2593 */
2594static int
2595add_established_modes(struct drm_connector *connector, struct edid *edid)
2596{
Adam Jackson9cf00972009-12-03 17:44:36 -05002597 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002598 unsigned long est_bits = edid->established_timings.t1 |
2599 (edid->established_timings.t2 << 8) |
2600 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2601 int i, modes = 0;
2602 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002603 .connector = connector,
2604 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002605 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002606
Adam Jackson13931572010-08-03 14:38:19 -04002607 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2608 if (est_bits & (1<<i)) {
2609 struct drm_display_mode *newmode;
2610 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2611 if (newmode) {
2612 drm_mode_probed_add(connector, newmode);
2613 modes++;
2614 }
2615 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002616 }
2617
Adam Jackson13931572010-08-03 14:38:19 -04002618 if (version_greater(edid, 1, 0))
2619 drm_for_each_detailed_block((u8 *)edid,
2620 do_established_modes, &closure);
2621
2622 return modes + closure.modes;
2623}
2624
2625static void
2626do_standard_modes(struct detailed_timing *timing, void *c)
2627{
2628 struct detailed_mode_closure *closure = c;
2629 struct detailed_non_pixel *data = &timing->data.other_data;
2630 struct drm_connector *connector = closure->connector;
2631 struct edid *edid = closure->edid;
2632
2633 if (data->type == EDID_DETAIL_STD_MODES) {
2634 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002635 for (i = 0; i < 6; i++) {
2636 struct std_timing *std;
2637 struct drm_display_mode *newmode;
2638
2639 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002640 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002641 if (newmode) {
2642 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002643 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002644 }
2645 }
Adam Jackson13931572010-08-03 14:38:19 -04002646 }
2647}
2648
2649/**
2650 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002651 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002652 * @edid: EDID block to scan
2653 *
2654 * Standard modes can be calculated using the appropriate standard (DMT,
2655 * GTF or CVT. Grab them from @edid and add them to the list.
2656 */
2657static int
2658add_standard_modes(struct drm_connector *connector, struct edid *edid)
2659{
2660 int i, modes = 0;
2661 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002662 .connector = connector,
2663 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002664 };
2665
2666 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2667 struct drm_display_mode *newmode;
2668
2669 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002670 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002671 if (newmode) {
2672 drm_mode_probed_add(connector, newmode);
2673 modes++;
2674 }
2675 }
2676
2677 if (version_greater(edid, 1, 0))
2678 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2679 &closure);
2680
2681 /* XXX should also look for standard codes in VTB blocks */
2682
2683 return modes + closure.modes;
2684}
2685
Dave Airlief453ba02008-11-07 14:05:41 -08002686static int drm_cvt_modes(struct drm_connector *connector,
2687 struct detailed_timing *timing)
2688{
2689 int i, j, modes = 0;
2690 struct drm_display_mode *newmode;
2691 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002692 struct cvt_timing *cvt;
2693 const int rates[] = { 60, 85, 75, 60, 50 };
2694 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002695
2696 for (i = 0; i < 4; i++) {
2697 int uninitialized_var(width), height;
2698 cvt = &(timing->data.other_data.data.cvt[i]);
2699
2700 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002701 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002702
2703 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002704 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002705 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002706 width = height * 4 / 3;
2707 break;
2708 case 0x04:
2709 width = height * 16 / 9;
2710 break;
2711 case 0x08:
2712 width = height * 16 / 10;
2713 break;
2714 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002715 width = height * 15 / 9;
2716 break;
2717 }
2718
2719 for (j = 1; j < 5; j++) {
2720 if (cvt->code[2] & (1 << j)) {
2721 newmode = drm_cvt_mode(dev, width, height,
2722 rates[j], j == 0,
2723 false, false);
2724 if (newmode) {
2725 drm_mode_probed_add(connector, newmode);
2726 modes++;
2727 }
2728 }
2729 }
2730 }
2731
2732 return modes;
2733}
2734
Adam Jackson13931572010-08-03 14:38:19 -04002735static void
2736do_cvt_mode(struct detailed_timing *timing, void *c)
2737{
2738 struct detailed_mode_closure *closure = c;
2739 struct detailed_non_pixel *data = &timing->data.other_data;
2740
2741 if (data->type == EDID_DETAIL_CVT_3BYTE)
2742 closure->modes += drm_cvt_modes(closure->connector, timing);
2743}
Adam Jackson9cf00972009-12-03 17:44:36 -05002744
2745static int
Adam Jackson13931572010-08-03 14:38:19 -04002746add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2747{
2748 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002749 .connector = connector,
2750 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002751 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002752
Adam Jackson13931572010-08-03 14:38:19 -04002753 if (version_greater(edid, 1, 2))
2754 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002755
Adam Jackson13931572010-08-03 14:38:19 -04002756 /* XXX should also look for CVT codes in VTB blocks */
2757
2758 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002759}
2760
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002761static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2762
Adam Jackson13931572010-08-03 14:38:19 -04002763static void
2764do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002765{
Adam Jackson13931572010-08-03 14:38:19 -04002766 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002767 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002768
2769 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002770 newmode = drm_mode_detailed(closure->connector->dev,
2771 closure->edid, timing,
2772 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002773 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002774 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002775
Adam Jackson13931572010-08-03 14:38:19 -04002776 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002777 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2778
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002779 /*
2780 * Detailed modes are limited to 10kHz pixel clock resolution,
2781 * so fix up anything that looks like CEA/HDMI mode, but the clock
2782 * is just slightly off.
2783 */
2784 fixup_detailed_cea_mode_clock(newmode);
2785
Adam Jackson13931572010-08-03 14:38:19 -04002786 drm_mode_probed_add(closure->connector, newmode);
2787 closure->modes++;
2788 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002789 }
Ma Ling167f3a02009-03-20 14:09:48 +08002790}
2791
Adam Jackson13931572010-08-03 14:38:19 -04002792/*
2793 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002794 * @connector: attached connector
2795 * @edid: EDID block to scan
2796 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002797 */
Adam Jackson13931572010-08-03 14:38:19 -04002798static int
2799add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2800 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002801{
Adam Jackson13931572010-08-03 14:38:19 -04002802 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002803 .connector = connector,
2804 .edid = edid,
2805 .preferred = 1,
2806 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002807 };
Dave Airlief453ba02008-11-07 14:05:41 -08002808
Adam Jackson13931572010-08-03 14:38:19 -04002809 if (closure.preferred && !version_greater(edid, 1, 3))
2810 closure.preferred =
2811 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002812
Adam Jackson13931572010-08-03 14:38:19 -04002813 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002814
Adam Jackson13931572010-08-03 14:38:19 -04002815 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002816}
Dave Airlief453ba02008-11-07 14:05:41 -08002817
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002818#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002819#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002820#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002821#define SPEAKER_BLOCK 0x04
Shashank Sharma87563fc2017-07-13 21:03:10 +05302822#define USE_EXTENDED_TAG 0x07
2823#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302824#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2825#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002826#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002827#define EDID_CEA_YCRCB444 (1 << 5)
2828#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002829#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002830
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002831/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002832 * Search EDID for CEA extension block.
2833 */
Keith Packard170178f2017-12-13 00:44:26 -08002834static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002835{
2836 u8 *edid_ext = NULL;
2837 int i;
2838
2839 /* No EDID or EDID extensions */
2840 if (edid == NULL || edid->extensions == 0)
2841 return NULL;
2842
2843 /* Find CEA extension */
2844 for (i = 0; i < edid->extensions; i++) {
2845 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002846 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002847 break;
2848 }
2849
2850 if (i == edid->extensions)
2851 return NULL;
2852
2853 return edid_ext;
2854}
2855
Keith Packard170178f2017-12-13 00:44:26 -08002856static u8 *drm_find_cea_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002857{
2858 return drm_find_edid_extension(edid, CEA_EXT);
2859}
2860
Keith Packard170178f2017-12-13 00:44:26 -08002861static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002862{
2863 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2864}
2865
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002866/*
2867 * Calculate the alternate clock for the CEA mode
2868 * (60Hz vs. 59.94Hz etc.)
2869 */
2870static unsigned int
2871cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2872{
2873 unsigned int clock = cea_mode->clock;
2874
2875 if (cea_mode->vrefresh % 6 != 0)
2876 return clock;
2877
2878 /*
2879 * edid_cea_modes contains the 59.94Hz
2880 * variant for 240 and 480 line modes,
2881 * and the 60Hz variant otherwise.
2882 */
2883 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002884 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002885 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002886 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002887
2888 return clock;
2889}
2890
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002891static bool
2892cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2893{
2894 /*
2895 * For certain VICs the spec allows the vertical
2896 * front porch to vary by one or two lines.
2897 *
2898 * cea_modes[] stores the variant with the shortest
2899 * vertical front porch. We can adjust the mode to
2900 * get the other variants by simply increasing the
2901 * vertical front porch length.
2902 */
2903 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
2904 edid_cea_modes[9].vtotal != 262 ||
2905 edid_cea_modes[12].vtotal != 262 ||
2906 edid_cea_modes[13].vtotal != 262 ||
2907 edid_cea_modes[23].vtotal != 312 ||
2908 edid_cea_modes[24].vtotal != 312 ||
2909 edid_cea_modes[27].vtotal != 312 ||
2910 edid_cea_modes[28].vtotal != 312);
2911
2912 if (((vic == 8 || vic == 9 ||
2913 vic == 12 || vic == 13) && mode->vtotal < 263) ||
2914 ((vic == 23 || vic == 24 ||
2915 vic == 27 || vic == 28) && mode->vtotal < 314)) {
2916 mode->vsync_start++;
2917 mode->vsync_end++;
2918 mode->vtotal++;
2919
2920 return true;
2921 }
2922
2923 return false;
2924}
2925
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002926static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
2927 unsigned int clock_tolerance)
2928{
Jani Nikulad9278b42016-01-08 13:21:51 +02002929 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002930
2931 if (!to_match->clock)
2932 return 0;
2933
Jani Nikulad9278b42016-01-08 13:21:51 +02002934 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002935 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002936 unsigned int clock1, clock2;
2937
2938 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002939 clock1 = cea_mode.clock;
2940 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002941
2942 if (abs(to_match->clock - clock1) > clock_tolerance &&
2943 abs(to_match->clock - clock2) > clock_tolerance)
2944 continue;
2945
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002946 do {
2947 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2948 return vic;
2949 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002950 }
2951
2952 return 0;
2953}
2954
Thierry Reding18316c82012-12-20 15:41:44 +01002955/**
2956 * drm_match_cea_mode - look for a CEA mode matching given mode
2957 * @to_match: display mode
2958 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002959 * 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 +01002960 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002961 */
Thierry Reding18316c82012-12-20 15:41:44 +01002962u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002963{
Jani Nikulad9278b42016-01-08 13:21:51 +02002964 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00002965
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002966 if (!to_match->clock)
2967 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002968
Jani Nikulad9278b42016-01-08 13:21:51 +02002969 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002970 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002971 unsigned int clock1, clock2;
2972
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002973 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002974 clock1 = cea_mode.clock;
2975 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002976
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002977 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
2978 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
2979 continue;
2980
2981 do {
2982 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2983 return vic;
2984 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00002985 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002986
Stephane Marchesina4799032012-11-09 16:21:05 +00002987 return 0;
2988}
2989EXPORT_SYMBOL(drm_match_cea_mode);
2990
Jani Nikulad9278b42016-01-08 13:21:51 +02002991static bool drm_valid_cea_vic(u8 vic)
2992{
2993 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
2994}
2995
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302996/**
2997 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2998 * the input VIC from the CEA mode list
2999 * @video_code: ID given to each of the CEA modes
3000 *
3001 * Returns picture aspect ratio
3002 */
3003enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
3004{
Jani Nikulad9278b42016-01-08 13:21:51 +02003005 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303006}
3007EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
3008
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003009/*
3010 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3011 * specific block).
3012 *
3013 * It's almost like cea_mode_alternate_clock(), we just need to add an
3014 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3015 * one.
3016 */
3017static unsigned int
3018hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3019{
3020 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3021 return hdmi_mode->clock;
3022
3023 return cea_mode_alternate_clock(hdmi_mode);
3024}
3025
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003026static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3027 unsigned int clock_tolerance)
3028{
Jani Nikulad9278b42016-01-08 13:21:51 +02003029 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003030
3031 if (!to_match->clock)
3032 return 0;
3033
Jani Nikulad9278b42016-01-08 13:21:51 +02003034 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3035 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003036 unsigned int clock1, clock2;
3037
3038 /* Make sure to also match alternate clocks */
3039 clock1 = hdmi_mode->clock;
3040 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3041
3042 if (abs(to_match->clock - clock1) > clock_tolerance &&
3043 abs(to_match->clock - clock2) > clock_tolerance)
3044 continue;
3045
3046 if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003047 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003048 }
3049
3050 return 0;
3051}
3052
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003053/*
3054 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3055 * @to_match: display mode
3056 *
3057 * An HDMI mode is one defined in the HDMI vendor specific block.
3058 *
3059 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3060 */
3061static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3062{
Jani Nikulad9278b42016-01-08 13:21:51 +02003063 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003064
3065 if (!to_match->clock)
3066 return 0;
3067
Jani Nikulad9278b42016-01-08 13:21:51 +02003068 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3069 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003070 unsigned int clock1, clock2;
3071
3072 /* Make sure to also match alternate clocks */
3073 clock1 = hdmi_mode->clock;
3074 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3075
3076 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3077 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01003078 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003079 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003080 }
3081 return 0;
3082}
3083
Jani Nikulad9278b42016-01-08 13:21:51 +02003084static bool drm_valid_hdmi_vic(u8 vic)
3085{
3086 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3087}
3088
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003089static int
3090add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3091{
3092 struct drm_device *dev = connector->dev;
3093 struct drm_display_mode *mode, *tmp;
3094 LIST_HEAD(list);
3095 int modes = 0;
3096
3097 /* Don't add CEA modes if the CEA extension block is missing */
3098 if (!drm_find_cea_extension(edid))
3099 return 0;
3100
3101 /*
3102 * Go through all probed modes and create a new mode
3103 * with the alternate clock for certain CEA modes.
3104 */
3105 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003106 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003107 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003108 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003109 unsigned int clock1, clock2;
3110
Jani Nikulad9278b42016-01-08 13:21:51 +02003111 if (drm_valid_cea_vic(vic)) {
3112 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003113 clock2 = cea_mode_alternate_clock(cea_mode);
3114 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003115 vic = drm_match_hdmi_mode(mode);
3116 if (drm_valid_hdmi_vic(vic)) {
3117 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003118 clock2 = hdmi_mode_alternate_clock(cea_mode);
3119 }
3120 }
3121
3122 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003123 continue;
3124
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003125 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003126
3127 if (clock1 == clock2)
3128 continue;
3129
3130 if (mode->clock != clock1 && mode->clock != clock2)
3131 continue;
3132
3133 newmode = drm_mode_duplicate(dev, cea_mode);
3134 if (!newmode)
3135 continue;
3136
Damien Lespiau27130212013-09-25 16:45:28 +01003137 /* Carry over the stereo flags */
3138 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3139
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003140 /*
3141 * The current mode could be either variant. Make
3142 * sure to pick the "other" clock for the new mode.
3143 */
3144 if (mode->clock != clock1)
3145 newmode->clock = clock1;
3146 else
3147 newmode->clock = clock2;
3148
3149 list_add_tail(&newmode->head, &list);
3150 }
3151
3152 list_for_each_entry_safe(mode, tmp, &list, head) {
3153 list_del(&mode->head);
3154 drm_mode_probed_add(connector, mode);
3155 modes++;
3156 }
3157
3158 return modes;
3159}
Stephane Marchesina4799032012-11-09 16:21:05 +00003160
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303161static u8 svd_to_vic(u8 svd)
3162{
3163 /* 0-6 bit vic, 7th bit native mode indicator */
3164 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3165 return svd & 127;
3166
3167 return svd;
3168}
3169
Thomas Woodaff04ac2013-11-29 15:33:27 +00003170static struct drm_display_mode *
3171drm_display_mode_from_vic_index(struct drm_connector *connector,
3172 const u8 *video_db, u8 video_len,
3173 u8 video_index)
3174{
3175 struct drm_device *dev = connector->dev;
3176 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003177 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003178
3179 if (video_db == NULL || video_index >= video_len)
3180 return NULL;
3181
3182 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303183 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003184 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003185 return NULL;
3186
Jani Nikulad9278b42016-01-08 13:21:51 +02003187 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003188 if (!newmode)
3189 return NULL;
3190
Thomas Woodaff04ac2013-11-29 15:33:27 +00003191 newmode->vrefresh = 0;
3192
3193 return newmode;
3194}
3195
Shashank Sharma832d4f22017-07-14 16:03:46 +05303196/*
3197 * do_y420vdb_modes - Parse YCBCR 420 only modes
3198 * @connector: connector corresponding to the HDMI sink
3199 * @svds: start of the data block of CEA YCBCR 420 VDB
3200 * @len: length of the CEA YCBCR 420 VDB
3201 *
3202 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3203 * which contains modes which can be supported in YCBCR 420
3204 * output format only.
3205 */
3206static int do_y420vdb_modes(struct drm_connector *connector,
3207 const u8 *svds, u8 svds_len)
3208{
3209 int modes = 0, i;
3210 struct drm_device *dev = connector->dev;
3211 struct drm_display_info *info = &connector->display_info;
3212 struct drm_hdmi_info *hdmi = &info->hdmi;
3213
3214 for (i = 0; i < svds_len; i++) {
3215 u8 vic = svd_to_vic(svds[i]);
3216 struct drm_display_mode *newmode;
3217
3218 if (!drm_valid_cea_vic(vic))
3219 continue;
3220
3221 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3222 if (!newmode)
3223 break;
3224 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3225 drm_mode_probed_add(connector, newmode);
3226 modes++;
3227 }
3228
3229 if (modes > 0)
3230 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3231 return modes;
3232}
3233
3234/*
3235 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3236 * @connector: connector corresponding to the HDMI sink
3237 * @vic: CEA vic for the video mode to be added in the map
3238 *
3239 * Makes an entry for a videomode in the YCBCR 420 bitmap
3240 */
3241static void
3242drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3243{
3244 u8 vic = svd_to_vic(svd);
3245 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3246
3247 if (!drm_valid_cea_vic(vic))
3248 return;
3249
3250 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3251}
3252
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003253static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003254do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003255{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003256 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303257 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003258
Thomas Woodaff04ac2013-11-29 15:33:27 +00003259 for (i = 0; i < len; i++) {
3260 struct drm_display_mode *mode;
3261 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3262 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303263 /*
3264 * YCBCR420 capability block contains a bitmap which
3265 * gives the index of CEA modes from CEA VDB, which
3266 * can support YCBCR 420 sampling output also (apart
3267 * from RGB/YCBCR444 etc).
3268 * For example, if the bit 0 in bitmap is set,
3269 * first mode in VDB can support YCBCR420 output too.
3270 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3271 */
3272 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3273 drm_add_cmdb_modes(connector, db[i]);
3274
Thomas Woodaff04ac2013-11-29 15:33:27 +00003275 drm_mode_probed_add(connector, mode);
3276 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003277 }
3278 }
3279
3280 return modes;
3281}
3282
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003283struct stereo_mandatory_mode {
3284 int width, height, vrefresh;
3285 unsigned int flags;
3286};
3287
3288static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003289 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3290 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003291 { 1920, 1080, 50,
3292 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3293 { 1920, 1080, 60,
3294 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003295 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3296 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3297 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3298 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003299};
3300
3301static bool
3302stereo_match_mandatory(const struct drm_display_mode *mode,
3303 const struct stereo_mandatory_mode *stereo_mode)
3304{
3305 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3306
3307 return mode->hdisplay == stereo_mode->width &&
3308 mode->vdisplay == stereo_mode->height &&
3309 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3310 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3311}
3312
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003313static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3314{
3315 struct drm_device *dev = connector->dev;
3316 const struct drm_display_mode *mode;
3317 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003318 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003319
3320 INIT_LIST_HEAD(&stereo_modes);
3321
3322 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003323 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3324 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003325 struct drm_display_mode *new_mode;
3326
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003327 if (!stereo_match_mandatory(mode,
3328 &stereo_mandatory_modes[i]))
3329 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003330
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003331 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003332 new_mode = drm_mode_duplicate(dev, mode);
3333 if (!new_mode)
3334 continue;
3335
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003336 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003337 list_add_tail(&new_mode->head, &stereo_modes);
3338 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003339 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003340 }
3341
3342 list_splice_tail(&stereo_modes, &connector->probed_modes);
3343
3344 return modes;
3345}
3346
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003347static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3348{
3349 struct drm_device *dev = connector->dev;
3350 struct drm_display_mode *newmode;
3351
Jani Nikulad9278b42016-01-08 13:21:51 +02003352 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003353 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3354 return 0;
3355 }
3356
3357 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3358 if (!newmode)
3359 return 0;
3360
3361 drm_mode_probed_add(connector, newmode);
3362
3363 return 1;
3364}
3365
Thomas Woodfbf46022013-10-16 15:58:50 +01003366static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3367 const u8 *video_db, u8 video_len, u8 video_index)
3368{
Thomas Woodfbf46022013-10-16 15:58:50 +01003369 struct drm_display_mode *newmode;
3370 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003371
3372 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003373 newmode = drm_display_mode_from_vic_index(connector, video_db,
3374 video_len,
3375 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003376 if (newmode) {
3377 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3378 drm_mode_probed_add(connector, newmode);
3379 modes++;
3380 }
3381 }
3382 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003383 newmode = drm_display_mode_from_vic_index(connector, video_db,
3384 video_len,
3385 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003386 if (newmode) {
3387 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3388 drm_mode_probed_add(connector, newmode);
3389 modes++;
3390 }
3391 }
3392 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003393 newmode = drm_display_mode_from_vic_index(connector, video_db,
3394 video_len,
3395 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003396 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003397 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003398 drm_mode_probed_add(connector, newmode);
3399 modes++;
3400 }
3401 }
3402
3403 return modes;
3404}
3405
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003406/*
3407 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3408 * @connector: connector corresponding to the HDMI sink
3409 * @db: start of the CEA vendor specific block
3410 * @len: length of the CEA block payload, ie. one can access up to db[len]
3411 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003412 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3413 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003414 */
3415static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003416do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3417 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003418{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003419 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003420 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003421 u8 vic_len, hdmi_3d_len = 0;
3422 u16 mask;
3423 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003424
3425 if (len < 8)
3426 goto out;
3427
3428 /* no HDMI_Video_Present */
3429 if (!(db[8] & (1 << 5)))
3430 goto out;
3431
3432 /* Latency_Fields_Present */
3433 if (db[8] & (1 << 7))
3434 offset += 2;
3435
3436 /* I_Latency_Fields_Present */
3437 if (db[8] & (1 << 6))
3438 offset += 2;
3439
3440 /* the declared length is not long enough for the 2 first bytes
3441 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003442 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003443 goto out;
3444
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003445 /* 3D_Present */
3446 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003447 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003448 modes += add_hdmi_mandatory_stereo_modes(connector);
3449
Thomas Woodfbf46022013-10-16 15:58:50 +01003450 /* 3D_Multi_present */
3451 multi_present = (db[8 + offset] & 0x60) >> 5;
3452 }
3453
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003454 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003455 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003456 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003457
3458 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003459 u8 vic;
3460
3461 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003462 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003463 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003464 offset += 1 + vic_len;
3465
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003466 if (multi_present == 1)
3467 multi_len = 2;
3468 else if (multi_present == 2)
3469 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003470 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003471 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003472
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003473 if (len < (8 + offset + hdmi_3d_len - 1))
3474 goto out;
3475
3476 if (hdmi_3d_len < multi_len)
3477 goto out;
3478
3479 if (multi_present == 1 || multi_present == 2) {
3480 /* 3D_Structure_ALL */
3481 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3482
3483 /* check if 3D_MASK is present */
3484 if (multi_present == 2)
3485 mask = (db[10 + offset] << 8) | db[11 + offset];
3486 else
3487 mask = 0xffff;
3488
3489 for (i = 0; i < 16; i++) {
3490 if (mask & (1 << i))
3491 modes += add_3d_struct_modes(connector,
3492 structure_all,
3493 video_db,
3494 video_len, i);
3495 }
3496 }
3497
3498 offset += multi_len;
3499
3500 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3501 int vic_index;
3502 struct drm_display_mode *newmode = NULL;
3503 unsigned int newflag = 0;
3504 bool detail_present;
3505
3506 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3507
3508 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3509 break;
3510
3511 /* 2D_VIC_order_X */
3512 vic_index = db[8 + offset + i] >> 4;
3513
3514 /* 3D_Structure_X */
3515 switch (db[8 + offset + i] & 0x0f) {
3516 case 0:
3517 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3518 break;
3519 case 6:
3520 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3521 break;
3522 case 8:
3523 /* 3D_Detail_X */
3524 if ((db[9 + offset + i] >> 4) == 1)
3525 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3526 break;
3527 }
3528
3529 if (newflag != 0) {
3530 newmode = drm_display_mode_from_vic_index(connector,
3531 video_db,
3532 video_len,
3533 vic_index);
3534
3535 if (newmode) {
3536 newmode->flags |= newflag;
3537 drm_mode_probed_add(connector, newmode);
3538 modes++;
3539 }
3540 }
3541
3542 if (detail_present)
3543 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003544 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003545
3546out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003547 if (modes > 0)
3548 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003549 return modes;
3550}
3551
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003552static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003553cea_db_payload_len(const u8 *db)
3554{
3555 return db[0] & 0x1f;
3556}
3557
3558static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303559cea_db_extended_tag(const u8 *db)
3560{
3561 return db[1];
3562}
3563
3564static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003565cea_db_tag(const u8 *db)
3566{
3567 return db[0] >> 5;
3568}
3569
3570static int
3571cea_revision(const u8 *cea)
3572{
3573 return cea[1];
3574}
3575
3576static int
3577cea_db_offsets(const u8 *cea, int *start, int *end)
3578{
3579 /* Data block offset in CEA extension block */
3580 *start = 4;
3581 *end = cea[2];
3582 if (*end == 0)
3583 *end = 127;
3584 if (*end < 4 || *end > 127)
3585 return -ERANGE;
3586 return 0;
3587}
3588
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003589static bool cea_db_is_hdmi_vsdb(const u8 *db)
3590{
3591 int hdmi_id;
3592
3593 if (cea_db_tag(db) != VENDOR_BLOCK)
3594 return false;
3595
3596 if (cea_db_payload_len(db) < 5)
3597 return false;
3598
3599 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3600
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003601 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003602}
3603
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303604static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3605{
3606 unsigned int oui;
3607
3608 if (cea_db_tag(db) != VENDOR_BLOCK)
3609 return false;
3610
3611 if (cea_db_payload_len(db) < 7)
3612 return false;
3613
3614 oui = db[3] << 16 | db[2] << 8 | db[1];
3615
3616 return oui == HDMI_FORUM_IEEE_OUI;
3617}
3618
Shashank Sharma832d4f22017-07-14 16:03:46 +05303619static bool cea_db_is_y420cmdb(const u8 *db)
3620{
3621 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3622 return false;
3623
3624 if (!cea_db_payload_len(db))
3625 return false;
3626
3627 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3628 return false;
3629
3630 return true;
3631}
3632
3633static bool cea_db_is_y420vdb(const u8 *db)
3634{
3635 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3636 return false;
3637
3638 if (!cea_db_payload_len(db))
3639 return false;
3640
3641 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3642 return false;
3643
3644 return true;
3645}
3646
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003647#define for_each_cea_db(cea, i, start, end) \
3648 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3649
Shashank Sharma832d4f22017-07-14 16:03:46 +05303650static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3651 const u8 *db)
3652{
3653 struct drm_display_info *info = &connector->display_info;
3654 struct drm_hdmi_info *hdmi = &info->hdmi;
3655 u8 map_len = cea_db_payload_len(db) - 1;
3656 u8 count;
3657 u64 map = 0;
3658
3659 if (map_len == 0) {
3660 /* All CEA modes support ycbcr420 sampling also.*/
3661 hdmi->y420_cmdb_map = U64_MAX;
3662 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3663 return;
3664 }
3665
3666 /*
3667 * This map indicates which of the existing CEA block modes
3668 * from VDB can support YCBCR420 output too. So if bit=0 is
3669 * set, first mode from VDB can support YCBCR420 output too.
3670 * We will parse and keep this map, before parsing VDB itself
3671 * to avoid going through the same block again and again.
3672 *
3673 * Spec is not clear about max possible size of this block.
3674 * Clamping max bitmap block size at 8 bytes. Every byte can
3675 * address 8 CEA modes, in this way this map can address
3676 * 8*8 = first 64 SVDs.
3677 */
3678 if (WARN_ON_ONCE(map_len > 8))
3679 map_len = 8;
3680
3681 for (count = 0; count < map_len; count++)
3682 map |= (u64)db[2 + count] << (8 * count);
3683
3684 if (map)
3685 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3686
3687 hdmi->y420_cmdb_map = map;
3688}
3689
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003690static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003691add_cea_modes(struct drm_connector *connector, struct edid *edid)
3692{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003693 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003694 const u8 *db, *hdmi = NULL, *video = NULL;
3695 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003696 int modes = 0;
3697
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003698 if (cea && cea_revision(cea) >= 3) {
3699 int i, start, end;
3700
3701 if (cea_db_offsets(cea, &start, &end))
3702 return 0;
3703
3704 for_each_cea_db(cea, i, start, end) {
3705 db = &cea[i];
3706 dbl = cea_db_payload_len(db);
3707
Thomas Woodfbf46022013-10-16 15:58:50 +01003708 if (cea_db_tag(db) == VIDEO_BLOCK) {
3709 video = db + 1;
3710 video_len = dbl;
3711 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303712 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003713 hdmi = db;
3714 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303715 } else if (cea_db_is_y420vdb(db)) {
3716 const u8 *vdb420 = &db[2];
3717
3718 /* Add 4:2:0(only) modes present in EDID */
3719 modes += do_y420vdb_modes(connector,
3720 vdb420,
3721 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003722 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003723 }
3724 }
3725
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003726 /*
3727 * We parse the HDMI VSDB after having added the cea modes as we will
3728 * be patching their flags when the sink supports stereo 3D.
3729 */
3730 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003731 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3732 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003733
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003734 return modes;
3735}
3736
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003737static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3738{
3739 const struct drm_display_mode *cea_mode;
3740 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003741 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003742 const char *type;
3743
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003744 /*
3745 * allow 5kHz clock difference either way to account for
3746 * the 10kHz clock resolution limit of detailed timings.
3747 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003748 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3749 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003750 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003751 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003752 clock1 = cea_mode->clock;
3753 clock2 = cea_mode_alternate_clock(cea_mode);
3754 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003755 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3756 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003757 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003758 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003759 clock1 = cea_mode->clock;
3760 clock2 = hdmi_mode_alternate_clock(cea_mode);
3761 } else {
3762 return;
3763 }
3764 }
3765
3766 /* pick whichever is closest */
3767 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3768 clock = clock1;
3769 else
3770 clock = clock2;
3771
3772 if (mode->clock == clock)
3773 return;
3774
3775 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003776 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003777 mode->clock = clock;
3778}
3779
Wu Fengguang76adaa342011-09-05 14:23:20 +08003780static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003781drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003782{
Ville Syrjälä85040722012-08-16 14:55:05 +00003783 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003784
Jani Nikulaf7da77852017-11-01 16:20:57 +02003785 if (len >= 6 && (db[6] & (1 << 7)))
3786 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00003787 if (len >= 8) {
3788 connector->latency_present[0] = db[8] >> 7;
3789 connector->latency_present[1] = (db[8] >> 6) & 1;
3790 }
3791 if (len >= 9)
3792 connector->video_latency[0] = db[9];
3793 if (len >= 10)
3794 connector->audio_latency[0] = db[10];
3795 if (len >= 11)
3796 connector->video_latency[1] = db[11];
3797 if (len >= 12)
3798 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003799
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003800 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3801 "video latency %d %d, "
3802 "audio latency %d %d\n",
3803 connector->latency_present[0],
3804 connector->latency_present[1],
3805 connector->video_latency[0],
3806 connector->video_latency[1],
3807 connector->audio_latency[0],
3808 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003809}
3810
3811static void
3812monitor_name(struct detailed_timing *t, void *data)
3813{
3814 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3815 *(u8 **)data = t->data.other_data.data.str.str;
3816}
3817
Jim Bride59f7c0f2016-04-14 10:18:35 -07003818static int get_monitor_name(struct edid *edid, char name[13])
3819{
3820 char *edid_name = NULL;
3821 int mnl;
3822
3823 if (!edid || !name)
3824 return 0;
3825
3826 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
3827 for (mnl = 0; edid_name && mnl < 13; mnl++) {
3828 if (edid_name[mnl] == 0x0a)
3829 break;
3830
3831 name[mnl] = edid_name[mnl];
3832 }
3833
3834 return mnl;
3835}
3836
3837/**
3838 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3839 * @edid: monitor EDID information
3840 * @name: pointer to a character array to hold the name of the monitor
3841 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3842 *
3843 */
3844void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
3845{
3846 int name_length;
3847 char buf[13];
3848
3849 if (bufsize <= 0)
3850 return;
3851
3852 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
3853 memcpy(name, buf, name_length);
3854 name[name_length] = '\0';
3855}
3856EXPORT_SYMBOL(drm_edid_get_monitor_name);
3857
Jani Nikula42750d32017-11-01 16:21:00 +02003858static void clear_eld(struct drm_connector *connector)
3859{
3860 memset(connector->eld, 0, sizeof(connector->eld));
3861
3862 connector->latency_present[0] = false;
3863 connector->latency_present[1] = false;
3864 connector->video_latency[0] = 0;
3865 connector->audio_latency[0] = 0;
3866 connector->video_latency[1] = 0;
3867 connector->audio_latency[1] = 0;
3868}
3869
Jani Nikula79436a12017-11-01 16:21:03 +02003870/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08003871 * drm_edid_to_eld - build ELD from EDID
3872 * @connector: connector corresponding to the HDMI/DP sink
3873 * @edid: EDID to parse
3874 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003875 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02003876 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003877 */
Jani Nikula79436a12017-11-01 16:21:03 +02003878static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003879{
3880 uint8_t *eld = connector->eld;
3881 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003882 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02003883 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003884 int mnl;
3885 int dbl;
3886
Jani Nikula42750d32017-11-01 16:21:00 +02003887 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03003888
Jani Nikulae9bd0b82017-02-17 17:20:52 +02003889 if (!edid)
3890 return;
3891
Wu Fengguang76adaa342011-09-05 14:23:20 +08003892 cea = drm_find_cea_extension(edid);
3893 if (!cea) {
3894 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3895 return;
3896 }
3897
Jani Nikulaf7da77852017-11-01 16:20:57 +02003898 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
3899 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07003900
Jani Nikulaf7da77852017-11-01 16:20:57 +02003901 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
3902 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003903
Jani Nikulaf7da77852017-11-01 16:20:57 +02003904 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003905
Jani Nikulaf7da77852017-11-01 16:20:57 +02003906 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
3907 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
3908 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
3909 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003910
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003911 if (cea_revision(cea) >= 3) {
3912 int i, start, end;
3913
3914 if (cea_db_offsets(cea, &start, &end)) {
3915 start = 0;
3916 end = 0;
3917 }
3918
3919 for_each_cea_db(cea, i, start, end) {
3920 db = &cea[i];
3921 dbl = cea_db_payload_len(db);
3922
3923 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02003924 int sad_count;
3925
Christian Schmidta0ab7342011-12-19 20:03:38 +01003926 case AUDIO_BLOCK:
3927 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02003928 sad_count = min(dbl / 3, 15 - total_sad_count);
3929 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003930 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02003931 &db[1], sad_count * 3);
3932 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01003933 break;
3934 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003935 /* Speaker Allocation Data Block */
3936 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003937 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003938 break;
3939 case VENDOR_BLOCK:
3940 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003941 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003942 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003943 break;
3944 default:
3945 break;
3946 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003947 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003948 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02003949 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003950
Jani Nikula1d1c3662017-11-01 16:20:58 +02003951 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3952 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3953 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
3954 else
3955 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003956
Jani Nikula938fd8a2014-10-28 16:20:48 +02003957 eld[DRM_ELD_BASELINE_ELD_LEN] =
3958 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3959
3960 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02003961 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003962}
Wu Fengguang76adaa342011-09-05 14:23:20 +08003963
3964/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003965 * drm_edid_to_sad - extracts SADs from EDID
3966 * @edid: EDID to parse
3967 * @sads: pointer that will be set to the extracted SADs
3968 *
3969 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003970 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003971 * Note: The returned pointer needs to be freed using kfree().
3972 *
3973 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003974 */
3975int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3976{
3977 int count = 0;
3978 int i, start, end, dbl;
3979 u8 *cea;
3980
3981 cea = drm_find_cea_extension(edid);
3982 if (!cea) {
3983 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3984 return -ENOENT;
3985 }
3986
3987 if (cea_revision(cea) < 3) {
3988 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3989 return -ENOTSUPP;
3990 }
3991
3992 if (cea_db_offsets(cea, &start, &end)) {
3993 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3994 return -EPROTO;
3995 }
3996
3997 for_each_cea_db(cea, i, start, end) {
3998 u8 *db = &cea[i];
3999
4000 if (cea_db_tag(db) == AUDIO_BLOCK) {
4001 int j;
4002 dbl = cea_db_payload_len(db);
4003
4004 count = dbl / 3; /* SAD is 3B */
4005 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4006 if (!*sads)
4007 return -ENOMEM;
4008 for (j = 0; j < count; j++) {
4009 u8 *sad = &db[1 + j * 3];
4010
4011 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4012 (*sads)[j].channels = sad[0] & 0x7;
4013 (*sads)[j].freq = sad[1] & 0x7F;
4014 (*sads)[j].byte2 = sad[2];
4015 }
4016 break;
4017 }
4018 }
4019
4020 return count;
4021}
4022EXPORT_SYMBOL(drm_edid_to_sad);
4023
4024/**
Alex Deucherd105f472013-07-25 15:55:32 -04004025 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4026 * @edid: EDID to parse
4027 * @sadb: pointer to the speaker block
4028 *
4029 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004030 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004031 * Note: The returned pointer needs to be freed using kfree().
4032 *
4033 * Return: The number of found Speaker Allocation Blocks or negative number on
4034 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004035 */
4036int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4037{
4038 int count = 0;
4039 int i, start, end, dbl;
4040 const u8 *cea;
4041
4042 cea = drm_find_cea_extension(edid);
4043 if (!cea) {
4044 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4045 return -ENOENT;
4046 }
4047
4048 if (cea_revision(cea) < 3) {
4049 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4050 return -ENOTSUPP;
4051 }
4052
4053 if (cea_db_offsets(cea, &start, &end)) {
4054 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4055 return -EPROTO;
4056 }
4057
4058 for_each_cea_db(cea, i, start, end) {
4059 const u8 *db = &cea[i];
4060
4061 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4062 dbl = cea_db_payload_len(db);
4063
4064 /* Speaker Allocation Data Block */
4065 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004066 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004067 if (!*sadb)
4068 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004069 count = dbl;
4070 break;
4071 }
4072 }
4073 }
4074
4075 return count;
4076}
4077EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4078
4079/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004080 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004081 * @connector: connector associated with the HDMI/DP sink
4082 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004083 *
4084 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4085 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004086 */
4087int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004088 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004089{
4090 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4091 int a, v;
4092
4093 if (!connector->latency_present[0])
4094 return 0;
4095 if (!connector->latency_present[1])
4096 i = 0;
4097
4098 a = connector->audio_latency[i];
4099 v = connector->video_latency[i];
4100
4101 /*
4102 * HDMI/DP sink doesn't support audio or video?
4103 */
4104 if (a == 255 || v == 255)
4105 return 0;
4106
4107 /*
4108 * Convert raw EDID values to millisecond.
4109 * Treat unknown latency as 0ms.
4110 */
4111 if (a)
4112 a = min(2 * (a - 1), 500);
4113 if (v)
4114 v = min(2 * (v - 1), 500);
4115
4116 return max(v - a, 0);
4117}
4118EXPORT_SYMBOL(drm_av_sync_delay);
4119
4120/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004121 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004122 * @edid: monitor EDID information
4123 *
4124 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004125 *
4126 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004127 */
4128bool drm_detect_hdmi_monitor(struct edid *edid)
4129{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004130 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004131 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004132 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004133
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004134 edid_ext = drm_find_cea_extension(edid);
4135 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004136 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004137
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004138 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004139 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004140
4141 /*
4142 * Because HDMI identifier is in Vendor Specific Block,
4143 * search it from all data blocks of CEA extension.
4144 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004145 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004146 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4147 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004148 }
4149
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004150 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004151}
4152EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4153
Dave Airlief453ba02008-11-07 14:05:41 -08004154/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004155 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004156 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004157 *
4158 * Monitor should have CEA extension block.
4159 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4160 * audio' only. If there is any audio extension block and supported
4161 * audio format, assume at least 'basic audio' support, even if 'basic
4162 * audio' is not defined in EDID.
4163 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004164 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004165 */
4166bool drm_detect_monitor_audio(struct edid *edid)
4167{
4168 u8 *edid_ext;
4169 int i, j;
4170 bool has_audio = false;
4171 int start_offset, end_offset;
4172
4173 edid_ext = drm_find_cea_extension(edid);
4174 if (!edid_ext)
4175 goto end;
4176
4177 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4178
4179 if (has_audio) {
4180 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4181 goto end;
4182 }
4183
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004184 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4185 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004186
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004187 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4188 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004189 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004190 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004191 DRM_DEBUG_KMS("CEA audio format %d\n",
4192 (edid_ext[i + j] >> 3) & 0xf);
4193 goto end;
4194 }
4195 }
4196end:
4197 return has_audio;
4198}
4199EXPORT_SYMBOL(drm_detect_monitor_audio);
4200
4201/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004202 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01004203 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004204 *
4205 * Check whether the monitor reports the RGB quantization range selection
4206 * as supported. The AVI infoframe can then be used to inform the monitor
4207 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004208 *
4209 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004210 */
4211bool drm_rgb_quant_range_selectable(struct edid *edid)
4212{
4213 u8 *edid_ext;
4214 int i, start, end;
4215
4216 edid_ext = drm_find_cea_extension(edid);
4217 if (!edid_ext)
4218 return false;
4219
4220 if (cea_db_offsets(edid_ext, &start, &end))
4221 return false;
4222
4223 for_each_cea_db(edid_ext, i, start, end) {
Shashank Sharma87563fc2017-07-13 21:03:10 +05304224 if (cea_db_tag(&edid_ext[i]) == USE_EXTENDED_TAG &&
4225 cea_db_payload_len(&edid_ext[i]) == 2 &&
4226 cea_db_extended_tag(&edid_ext[i]) ==
4227 EXT_VIDEO_CAPABILITY_BLOCK) {
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004228 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
4229 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
4230 }
4231 }
4232
4233 return false;
4234}
4235EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
4236
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004237/**
4238 * drm_default_rgb_quant_range - default RGB quantization range
4239 * @mode: display mode
4240 *
4241 * Determine the default RGB quantization range for the mode,
4242 * as specified in CEA-861.
4243 *
4244 * Return: The default RGB quantization range for the mode
4245 */
4246enum hdmi_quantization_range
4247drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4248{
4249 /* All CEA modes other than VIC 1 use limited quantization range. */
4250 return drm_match_cea_mode(mode) > 1 ?
4251 HDMI_QUANTIZATION_RANGE_LIMITED :
4252 HDMI_QUANTIZATION_RANGE_FULL;
4253}
4254EXPORT_SYMBOL(drm_default_rgb_quant_range);
4255
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304256static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4257 const u8 *db)
4258{
4259 u8 dc_mask;
4260 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4261
4262 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
4263 hdmi->y420_dc_modes |= dc_mask;
4264}
4265
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304266static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4267 const u8 *hf_vsdb)
4268{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304269 struct drm_display_info *display = &connector->display_info;
4270 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304271
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004272 display->has_hdmi_infoframe = true;
4273
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304274 if (hf_vsdb[6] & 0x80) {
4275 hdmi->scdc.supported = true;
4276 if (hf_vsdb[6] & 0x40)
4277 hdmi->scdc.read_request = true;
4278 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304279
4280 /*
4281 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4282 * And as per the spec, three factors confirm this:
4283 * * Availability of a HF-VSDB block in EDID (check)
4284 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4285 * * SCDC support available (let's check)
4286 * Lets check it out.
4287 */
4288
4289 if (hf_vsdb[5]) {
4290 /* max clock is 5000 KHz times block value */
4291 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4292 struct drm_scdc *scdc = &hdmi->scdc;
4293
4294 if (max_tmds_clock > 340000) {
4295 display->max_tmds_clock = max_tmds_clock;
4296 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4297 display->max_tmds_clock);
4298 }
4299
4300 if (scdc->supported) {
4301 scdc->scrambling.supported = true;
4302
4303 /* Few sinks support scrambling for cloks < 340M */
4304 if ((hf_vsdb[6] & 0x8))
4305 scdc->scrambling.low_rates = true;
4306 }
4307 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304308
4309 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304310}
4311
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004312static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4313 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004314{
Ville Syrjälä18267502016-09-28 16:51:38 +03004315 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004316 unsigned int dc_bpc = 0;
4317
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004318 /* HDMI supports at least 8 bpc */
4319 info->bpc = 8;
4320
4321 if (cea_db_payload_len(hdmi) < 6)
4322 return;
4323
4324 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4325 dc_bpc = 10;
4326 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4327 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4328 connector->name);
4329 }
4330
4331 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4332 dc_bpc = 12;
4333 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4334 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4335 connector->name);
4336 }
4337
4338 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4339 dc_bpc = 16;
4340 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4341 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4342 connector->name);
4343 }
4344
4345 if (dc_bpc == 0) {
4346 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4347 connector->name);
4348 return;
4349 }
4350
4351 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4352 connector->name, dc_bpc);
4353 info->bpc = dc_bpc;
4354
4355 /*
4356 * Deep color support mandates RGB444 support for all video
4357 * modes and forbids YCRCB422 support for all video modes per
4358 * HDMI 1.3 spec.
4359 */
4360 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4361
4362 /* YCRCB444 is optional according to spec. */
4363 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4364 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4365 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4366 connector->name);
4367 }
4368
4369 /*
4370 * Spec says that if any deep color mode is supported at all,
4371 * then deep color 36 bit must be supported.
4372 */
4373 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4374 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4375 connector->name);
4376 }
4377}
4378
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004379static void
4380drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4381{
4382 struct drm_display_info *info = &connector->display_info;
4383 u8 len = cea_db_payload_len(db);
4384
4385 if (len >= 6)
4386 info->dvi_dual = db[6] & 1;
4387 if (len >= 7)
4388 info->max_tmds_clock = db[7] * 5000;
4389
4390 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4391 "max TMDS clock %d kHz\n",
4392 info->dvi_dual,
4393 info->max_tmds_clock);
4394
4395 drm_parse_hdmi_deep_color_info(connector, db);
4396}
4397
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004398static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004399 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004400{
4401 struct drm_display_info *info = &connector->display_info;
4402 const u8 *edid_ext;
4403 int i, start, end;
4404
Mario Kleinerd0c94692014-03-27 19:59:39 +01004405 edid_ext = drm_find_cea_extension(edid);
4406 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004407 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004408
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004409 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004410
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004411 /* The existence of a CEA block should imply RGB support */
4412 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4413 if (edid_ext[3] & EDID_CEA_YCRCB444)
4414 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4415 if (edid_ext[3] & EDID_CEA_YCRCB422)
4416 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004417
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004418 if (cea_db_offsets(edid_ext, &start, &end))
4419 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004420
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004421 for_each_cea_db(edid_ext, i, start, end) {
4422 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004423
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004424 if (cea_db_is_hdmi_vsdb(db))
4425 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304426 if (cea_db_is_hdmi_forum_vsdb(db))
4427 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304428 if (cea_db_is_y420cmdb(db))
4429 drm_parse_y420cmdb_bitmap(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004430 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004431}
4432
Keith Packard170178f2017-12-13 00:44:26 -08004433/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4434 * all of the values which would have been set from EDID
4435 */
4436void
4437drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004438{
Ville Syrjälä18267502016-09-28 16:51:38 +03004439 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004440
Keith Packard170178f2017-12-13 00:44:26 -08004441 info->width_mm = 0;
4442 info->height_mm = 0;
4443
4444 info->bpc = 0;
4445 info->color_formats = 0;
4446 info->cea_rev = 0;
4447 info->max_tmds_clock = 0;
4448 info->dvi_dual = false;
4449 info->has_hdmi_infoframe = false;
4450
4451 info->non_desktop = 0;
4452}
4453EXPORT_SYMBOL_GPL(drm_reset_display_info);
4454
4455u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4456{
4457 struct drm_display_info *info = &connector->display_info;
4458
4459 u32 quirks = edid_get_quirks(edid);
4460
Jesse Barnes3b112282011-04-15 12:49:23 -07004461 info->width_mm = edid->width_cm * 10;
4462 info->height_mm = edid->height_cm * 10;
4463
4464 /* driver figures it out in this case */
4465 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004466 info->color_formats = 0;
Ville Syrjälä011acce2016-09-28 16:51:40 +03004467 info->cea_rev = 0;
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004468 info->max_tmds_clock = 0;
4469 info->dvi_dual = false;
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004470 info->has_hdmi_infoframe = false;
Jesse Barnes3b112282011-04-15 12:49:23 -07004471
Dave Airlie66660d42017-10-16 05:08:09 +01004472 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4473
Keith Packard170178f2017-12-13 00:44:26 -08004474 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4475
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004476 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004477 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004478
4479 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004480 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004481
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004482 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004483
Mario Kleiner210a0212016-07-06 12:05:48 +02004484 /*
4485 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4486 *
4487 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4488 * tells us to assume 8 bpc color depth if the EDID doesn't have
4489 * extensions which tell otherwise.
4490 */
4491 if ((info->bpc == 0) && (edid->revision < 4) &&
4492 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
4493 info->bpc = 8;
4494 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4495 connector->name, info->bpc);
4496 }
4497
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004498 /* Only defined for 1.4 with digital displays */
4499 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004500 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004501
Jesse Barnes3b112282011-04-15 12:49:23 -07004502 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4503 case DRM_EDID_DIGITAL_DEPTH_6:
4504 info->bpc = 6;
4505 break;
4506 case DRM_EDID_DIGITAL_DEPTH_8:
4507 info->bpc = 8;
4508 break;
4509 case DRM_EDID_DIGITAL_DEPTH_10:
4510 info->bpc = 10;
4511 break;
4512 case DRM_EDID_DIGITAL_DEPTH_12:
4513 info->bpc = 12;
4514 break;
4515 case DRM_EDID_DIGITAL_DEPTH_14:
4516 info->bpc = 14;
4517 break;
4518 case DRM_EDID_DIGITAL_DEPTH_16:
4519 info->bpc = 16;
4520 break;
4521 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4522 default:
4523 info->bpc = 0;
4524 break;
4525 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004526
Mario Kleinerd0c94692014-03-27 19:59:39 +01004527 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004528 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004529
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004530 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004531 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4532 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4533 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4534 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004535 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004536}
Keith Packard170178f2017-12-13 00:44:26 -08004537EXPORT_SYMBOL_GPL(drm_add_display_info);
Jesse Barnes3b112282011-04-15 12:49:23 -07004538
Dave Airliec97291772016-05-03 15:38:37 +10004539static int validate_displayid(u8 *displayid, int length, int idx)
4540{
4541 int i;
4542 u8 csum = 0;
4543 struct displayid_hdr *base;
4544
4545 base = (struct displayid_hdr *)&displayid[idx];
4546
4547 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4548 base->rev, base->bytes, base->prod_id, base->ext_count);
4549
4550 if (base->bytes + 5 > length - idx)
4551 return -EINVAL;
4552 for (i = idx; i <= base->bytes + 5; i++) {
4553 csum += displayid[i];
4554 }
4555 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004556 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004557 return -EINVAL;
4558 }
4559 return 0;
4560}
4561
Dave Airliea39ed682016-05-02 08:35:05 +10004562static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4563 struct displayid_detailed_timings_1 *timings)
4564{
4565 struct drm_display_mode *mode;
4566 unsigned pixel_clock = (timings->pixel_clock[0] |
4567 (timings->pixel_clock[1] << 8) |
4568 (timings->pixel_clock[2] << 16));
4569 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4570 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4571 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4572 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4573 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4574 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4575 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4576 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4577 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4578 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4579 mode = drm_mode_create(dev);
4580 if (!mode)
4581 return NULL;
4582
4583 mode->clock = pixel_clock * 10;
4584 mode->hdisplay = hactive;
4585 mode->hsync_start = mode->hdisplay + hsync;
4586 mode->hsync_end = mode->hsync_start + hsync_width;
4587 mode->htotal = mode->hdisplay + hblank;
4588
4589 mode->vdisplay = vactive;
4590 mode->vsync_start = mode->vdisplay + vsync;
4591 mode->vsync_end = mode->vsync_start + vsync_width;
4592 mode->vtotal = mode->vdisplay + vblank;
4593
4594 mode->flags = 0;
4595 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4596 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4597 mode->type = DRM_MODE_TYPE_DRIVER;
4598
4599 if (timings->flags & 0x80)
4600 mode->type |= DRM_MODE_TYPE_PREFERRED;
4601 mode->vrefresh = drm_mode_vrefresh(mode);
4602 drm_mode_set_name(mode);
4603
4604 return mode;
4605}
4606
4607static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4608 struct displayid_block *block)
4609{
4610 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4611 int i;
4612 int num_timings;
4613 struct drm_display_mode *newmode;
4614 int num_modes = 0;
4615 /* blocks must be multiple of 20 bytes length */
4616 if (block->num_bytes % 20)
4617 return 0;
4618
4619 num_timings = block->num_bytes / 20;
4620 for (i = 0; i < num_timings; i++) {
4621 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4622
4623 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4624 if (!newmode)
4625 continue;
4626
4627 drm_mode_probed_add(connector, newmode);
4628 num_modes++;
4629 }
4630 return num_modes;
4631}
4632
4633static int add_displayid_detailed_modes(struct drm_connector *connector,
4634 struct edid *edid)
4635{
4636 u8 *displayid;
4637 int ret;
4638 int idx = 1;
4639 int length = EDID_LENGTH;
4640 struct displayid_block *block;
4641 int num_modes = 0;
4642
4643 displayid = drm_find_displayid_extension(edid);
4644 if (!displayid)
4645 return 0;
4646
4647 ret = validate_displayid(displayid, length, idx);
4648 if (ret)
4649 return 0;
4650
4651 idx += sizeof(struct displayid_hdr);
4652 while (block = (struct displayid_block *)&displayid[idx],
4653 idx + sizeof(struct displayid_block) <= length &&
4654 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4655 block->num_bytes > 0) {
4656 idx += block->num_bytes + sizeof(struct displayid_block);
4657 switch (block->tag) {
4658 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4659 num_modes += add_displayid_detailed_1_modes(connector, block);
4660 break;
4661 }
4662 }
4663 return num_modes;
4664}
4665
Jesse Barnes3b112282011-04-15 12:49:23 -07004666/**
Dave Airlief453ba02008-11-07 14:05:41 -08004667 * drm_add_edid_modes - add modes from EDID data, if available
4668 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004669 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004670 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004671 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004672 * &drm_display_info structure and ELD in @connector with any information which
4673 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004674 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004675 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004676 */
4677int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4678{
4679 int num_modes = 0;
4680 u32 quirks;
4681
4682 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004683 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004684 return 0;
4685 }
Alex Deucher3c537882010-02-05 04:21:19 -05004686 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004687 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004688 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004689 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004690 return 0;
4691 }
4692
Jani Nikulac945b8c2017-11-01 16:21:01 +02004693 drm_edid_to_eld(connector, edid);
4694
Adam Jacksonc867df72010-03-29 21:43:21 +00004695 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304696 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4697 * To avoid multiple parsing of same block, lets parse that map
4698 * from sink info, before parsing CEA modes.
4699 */
Keith Packard170178f2017-12-13 00:44:26 -08004700 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304701
4702 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004703 * EDID spec says modes should be preferred in this order:
4704 * - preferred detailed mode
4705 * - other detailed modes from base block
4706 * - detailed modes from extension blocks
4707 * - CVT 3-byte code modes
4708 * - standard timing codes
4709 * - established timing codes
4710 * - modes inferred from GTF or CVT range information
4711 *
Adam Jackson13931572010-08-03 14:38:19 -04004712 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004713 *
4714 * XXX order for additional mode types in extension blocks?
4715 */
Adam Jackson13931572010-08-03 14:38:19 -04004716 num_modes += add_detailed_modes(connector, edid, quirks);
4717 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004718 num_modes += add_standard_modes(connector, edid);
4719 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004720 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004721 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004722 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004723 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4724 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004725
4726 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4727 edid_fixup_preferred(connector, quirks);
4728
Mario Kleinere10aec62016-07-06 12:05:44 +02004729 if (quirks & EDID_QUIRK_FORCE_6BPC)
4730 connector->display_info.bpc = 6;
4731
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004732 if (quirks & EDID_QUIRK_FORCE_8BPC)
4733 connector->display_info.bpc = 8;
4734
Mario Kleinere345da82017-04-21 17:05:08 +02004735 if (quirks & EDID_QUIRK_FORCE_10BPC)
4736 connector->display_info.bpc = 10;
4737
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004738 if (quirks & EDID_QUIRK_FORCE_12BPC)
4739 connector->display_info.bpc = 12;
4740
Dave Airlief453ba02008-11-07 14:05:41 -08004741 return num_modes;
4742}
4743EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004744
4745/**
4746 * drm_add_modes_noedid - add modes for the connectors without EDID
4747 * @connector: connector we're probing
4748 * @hdisplay: the horizontal display limit
4749 * @vdisplay: the vertical display limit
4750 *
4751 * Add the specified modes to the connector's mode list. Only when the
4752 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4753 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004754 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004755 */
4756int drm_add_modes_noedid(struct drm_connector *connector,
4757 int hdisplay, int vdisplay)
4758{
4759 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004760 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004761 struct drm_device *dev = connector->dev;
4762
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004763 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004764 if (hdisplay < 0)
4765 hdisplay = 0;
4766 if (vdisplay < 0)
4767 vdisplay = 0;
4768
4769 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004770 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004771 if (hdisplay && vdisplay) {
4772 /*
4773 * Only when two are valid, they will be used to check
4774 * whether the mode should be added to the mode list of
4775 * the connector.
4776 */
4777 if (ptr->hdisplay > hdisplay ||
4778 ptr->vdisplay > vdisplay)
4779 continue;
4780 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004781 if (drm_mode_vrefresh(ptr) > 61)
4782 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004783 mode = drm_mode_duplicate(dev, ptr);
4784 if (mode) {
4785 drm_mode_probed_add(connector, mode);
4786 num_modes++;
4787 }
4788 }
4789 return num_modes;
4790}
4791EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004792
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004793/**
4794 * drm_set_preferred_mode - Sets the preferred mode of a connector
4795 * @connector: connector whose mode list should be processed
4796 * @hpref: horizontal resolution of preferred mode
4797 * @vpref: vertical resolution of preferred mode
4798 *
4799 * Marks a mode as preferred if it matches the resolution specified by @hpref
4800 * and @vpref.
4801 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004802void drm_set_preferred_mode(struct drm_connector *connector,
4803 int hpref, int vpref)
4804{
4805 struct drm_display_mode *mode;
4806
4807 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004808 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004809 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004810 mode->type |= DRM_MODE_TYPE_PREFERRED;
4811 }
4812}
4813EXPORT_SYMBOL(drm_set_preferred_mode);
4814
Thierry Reding10a85122012-11-21 15:31:35 +01004815/**
4816 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4817 * data from a DRM display mode
4818 * @frame: HDMI AVI infoframe
4819 * @mode: DRM display mode
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304820 * @is_hdmi2_sink: Sink is HDMI 2.0 compliant
Thierry Reding10a85122012-11-21 15:31:35 +01004821 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004822 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01004823 */
4824int
4825drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304826 const struct drm_display_mode *mode,
4827 bool is_hdmi2_sink)
Thierry Reding10a85122012-11-21 15:31:35 +01004828{
4829 int err;
4830
4831 if (!frame || !mode)
4832 return -EINVAL;
4833
4834 err = hdmi_avi_infoframe_init(frame);
4835 if (err < 0)
4836 return err;
4837
Damien Lespiaubf02db92013-08-06 20:32:22 +01004838 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
4839 frame->pixel_repeat = 1;
4840
Thierry Reding10a85122012-11-21 15:31:35 +01004841 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01004842
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304843 /*
4844 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
4845 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
4846 * have to make sure we dont break HDMI 1.4 sinks.
4847 */
4848 if (!is_hdmi2_sink && frame->video_code > 64)
4849 frame->video_code = 0;
4850
4851 /*
4852 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
4853 * we should send its VIC in vendor infoframes, else send the
4854 * VIC in AVI infoframes. Lets check if this mode is present in
4855 * HDMI 1.4b 4K modes
4856 */
4857 if (frame->video_code) {
4858 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
4859 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
4860
4861 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
4862 frame->video_code = 0;
4863 }
4864
Thierry Reding10a85122012-11-21 15:31:35 +01004865 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304866
Vandana Kannan69ab6d32014-06-05 14:45:29 +05304867 /*
4868 * Populate picture aspect ratio from either
4869 * user input (if specified) or from the CEA mode list.
4870 */
4871 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
4872 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
4873 frame->picture_aspect = mode->picture_aspect_ratio;
4874 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304875 frame->picture_aspect = drm_get_cea_aspect_ratio(
4876 frame->video_code);
4877
Thierry Reding10a85122012-11-21 15:31:35 +01004878 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06004879 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01004880
4881 return 0;
4882}
4883EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004884
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004885/**
4886 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4887 * quantization range information
4888 * @frame: HDMI AVI infoframe
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004889 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004890 * @rgb_quant_range: RGB quantization range (Q)
4891 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
Daniel Vetter7cdeb372017-12-14 21:30:50 +01004892 * @is_hdmi2_sink: HDMI 2.0 sink, which has different default recommendations
4893 *
4894 * Note that @is_hdmi2_sink can be derived by looking at the
4895 * &drm_scdc.supported flag stored in &drm_hdmi_info.scdc,
4896 * &drm_display_info.hdmi, which can be found in &drm_connector.display_info.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004897 */
4898void
4899drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004900 const struct drm_display_mode *mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004901 enum hdmi_quantization_range rgb_quant_range,
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004902 bool rgb_quant_range_selectable,
4903 bool is_hdmi2_sink)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004904{
4905 /*
4906 * CEA-861:
4907 * "A Source shall not send a non-zero Q value that does not correspond
4908 * to the default RGB Quantization Range for the transmitted Picture
4909 * unless the Sink indicates support for the Q bit in a Video
4910 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004911 *
4912 * HDMI 2.0 recommends sending non-zero Q when it does match the
4913 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004914 */
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004915 if (rgb_quant_range_selectable ||
4916 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004917 frame->quantization_range = rgb_quant_range;
4918 else
4919 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004920
4921 /*
4922 * CEA-861-F:
4923 * "When transmitting any RGB colorimetry, the Source should set the
4924 * YQ-field to match the RGB Quantization Range being transmitted
4925 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4926 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004927 *
4928 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
4929 * by non-zero YQ when receiving RGB. There doesn't seem to be any
4930 * good way to tell which version of CEA-861 the sink supports, so
4931 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
4932 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004933 */
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004934 if (!is_hdmi2_sink ||
4935 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004936 frame->ycc_quantization_range =
4937 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4938 else
4939 frame->ycc_quantization_range =
4940 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004941}
4942EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
4943
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004944static enum hdmi_3d_structure
4945s3d_structure_from_display_mode(const struct drm_display_mode *mode)
4946{
4947 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
4948
4949 switch (layout) {
4950 case DRM_MODE_FLAG_3D_FRAME_PACKING:
4951 return HDMI_3D_STRUCTURE_FRAME_PACKING;
4952 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
4953 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
4954 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
4955 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
4956 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
4957 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
4958 case DRM_MODE_FLAG_3D_L_DEPTH:
4959 return HDMI_3D_STRUCTURE_L_DEPTH;
4960 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
4961 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
4962 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
4963 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
4964 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
4965 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
4966 default:
4967 return HDMI_3D_STRUCTURE_INVALID;
4968 }
4969}
4970
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004971/**
4972 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4973 * data from a DRM display mode
4974 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004975 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004976 * @mode: DRM display mode
4977 *
4978 * Note that there's is a need to send HDMI vendor infoframes only when using a
4979 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4980 * function will return -EINVAL, error that can be safely ignored.
4981 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004982 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004983 */
4984int
4985drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004986 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004987 const struct drm_display_mode *mode)
4988{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004989 /*
4990 * FIXME: sil-sii8620 doesn't have a connector around when
4991 * we need one, so we have to be prepared for a NULL connector.
4992 */
4993 bool has_hdmi_infoframe = connector ?
4994 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004995 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004996 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004997 u8 vic;
4998
4999 if (!frame || !mode)
5000 return -EINVAL;
5001
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005002 if (!has_hdmi_infoframe)
5003 return -EINVAL;
5004
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005005 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005006 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
5007
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005008 /*
5009 * Even if it's not absolutely necessary to send the infoframe
5010 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5011 * know that the sink can handle it. This is based on a
5012 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5013 * have trouble realizing that they shuld switch from 3D to 2D
5014 * mode if the source simply stops sending the infoframe when
5015 * it wants to switch from 3D to 2D.
5016 */
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005017
5018 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005019 return -EINVAL;
5020
5021 err = hdmi_vendor_infoframe_init(frame);
5022 if (err < 0)
5023 return err;
5024
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005025 frame->vic = vic;
5026 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005027
5028 return 0;
5029}
5030EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005031
Dave Airlie5e546cd2016-05-03 15:31:12 +10005032static int drm_parse_tiled_block(struct drm_connector *connector,
5033 struct displayid_block *block)
5034{
5035 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5036 u16 w, h;
5037 u8 tile_v_loc, tile_h_loc;
5038 u8 num_v_tile, num_h_tile;
5039 struct drm_tile_group *tg;
5040
5041 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5042 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5043
5044 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5045 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5046 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5047 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5048
5049 connector->has_tile = true;
5050 if (tile->tile_cap & 0x80)
5051 connector->tile_is_single_monitor = true;
5052
5053 connector->num_h_tile = num_h_tile + 1;
5054 connector->num_v_tile = num_v_tile + 1;
5055 connector->tile_h_loc = tile_h_loc;
5056 connector->tile_v_loc = tile_v_loc;
5057 connector->tile_h_size = w + 1;
5058 connector->tile_v_size = h + 1;
5059
5060 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5061 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5062 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5063 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5064 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5065
5066 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5067 if (!tg) {
5068 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5069 }
5070 if (!tg)
5071 return -ENOMEM;
5072
5073 if (connector->tile_group != tg) {
5074 /* if we haven't got a pointer,
5075 take the reference, drop ref to old tile group */
5076 if (connector->tile_group) {
5077 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5078 }
5079 connector->tile_group = tg;
5080 } else
5081 /* if same tile group, then release the ref we just took. */
5082 drm_mode_put_tile_group(connector->dev, tg);
5083 return 0;
5084}
5085
Dave Airlie40d9b042014-10-20 16:29:33 +10005086static int drm_parse_display_id(struct drm_connector *connector,
5087 u8 *displayid, int length,
5088 bool is_edid_extension)
5089{
5090 /* if this is an EDID extension the first byte will be 0x70 */
5091 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005092 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005093 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005094
5095 if (is_edid_extension)
5096 idx = 1;
5097
Dave Airliec97291772016-05-03 15:38:37 +10005098 ret = validate_displayid(displayid, length, idx);
5099 if (ret)
5100 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005101
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005102 idx += sizeof(struct displayid_hdr);
5103 while (block = (struct displayid_block *)&displayid[idx],
5104 idx + sizeof(struct displayid_block) <= length &&
5105 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
5106 block->num_bytes > 0) {
5107 idx += block->num_bytes + sizeof(struct displayid_block);
5108 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5109 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005110
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005111 switch (block->tag) {
5112 case DATA_BLOCK_TILED_DISPLAY:
5113 ret = drm_parse_tiled_block(connector, block);
5114 if (ret)
5115 return ret;
5116 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005117 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5118 /* handled in mode gathering code. */
5119 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005120 default:
5121 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5122 break;
5123 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005124 }
5125 return 0;
5126}
5127
5128static void drm_get_displayid(struct drm_connector *connector,
5129 struct edid *edid)
5130{
5131 void *displayid = NULL;
5132 int ret;
5133 connector->has_tile = false;
5134 displayid = drm_find_displayid_extension(edid);
5135 if (!displayid) {
5136 /* drop reference to any tile group we had */
5137 goto out_drop_ref;
5138 }
5139
5140 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5141 if (ret < 0)
5142 goto out_drop_ref;
5143 if (!connector->has_tile)
5144 goto out_drop_ref;
5145 return;
5146out_drop_ref:
5147 if (connector->tile_group) {
5148 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5149 connector->tile_group = NULL;
5150 }
5151 return;
5152}