blob: 49147b2aa288c820dd6f40741ca184bbbeeddab1 [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 },
Dave Airlief453ba02008-11-07 14:05:41 -0800165};
166
Thierry Redinga6b21832012-11-23 15:01:42 +0100167/*
168 * Autogenerated from the DMT spec.
169 * This table is copied from xfree86/modes/xf86EdidModes.c.
170 */
171static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300172 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100173 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
174 736, 832, 0, 350, 382, 385, 445, 0,
175 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300176 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100177 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
178 736, 832, 0, 400, 401, 404, 445, 0,
179 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300180 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100181 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
182 828, 936, 0, 400, 401, 404, 446, 0,
183 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300184 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100185 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300186 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100187 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300188 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100189 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
190 704, 832, 0, 480, 489, 492, 520, 0,
191 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300192 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100193 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
194 720, 840, 0, 480, 481, 484, 500, 0,
195 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300196 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100197 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
198 752, 832, 0, 480, 481, 484, 509, 0,
199 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300200 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100201 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
202 896, 1024, 0, 600, 601, 603, 625, 0,
203 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300204 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100205 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
206 968, 1056, 0, 600, 601, 605, 628, 0,
207 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300208 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100209 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
210 976, 1040, 0, 600, 637, 643, 666, 0,
211 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300212 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100213 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
214 896, 1056, 0, 600, 601, 604, 625, 0,
215 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300216 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100217 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
218 896, 1048, 0, 600, 601, 604, 631, 0,
219 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300220 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100221 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
222 880, 960, 0, 600, 603, 607, 636, 0,
223 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300224 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100225 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
226 976, 1088, 0, 480, 486, 494, 517, 0,
227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300228 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100229 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100230 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100231 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300232 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300233 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100234 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
235 1184, 1344, 0, 768, 771, 777, 806, 0,
236 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300237 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100238 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
239 1184, 1328, 0, 768, 771, 777, 806, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300241 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100242 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
243 1136, 1312, 0, 768, 769, 772, 800, 0,
244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300245 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100246 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
247 1168, 1376, 0, 768, 769, 772, 808, 0,
248 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300249 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100250 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
251 1104, 1184, 0, 768, 771, 775, 813, 0,
252 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300253 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100254 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
255 1344, 1600, 0, 864, 865, 868, 900, 0,
256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300257 /* 0x55 - 1280x720@60Hz */
258 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
259 1430, 1650, 0, 720, 725, 730, 750, 0,
260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300261 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100262 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
263 1360, 1440, 0, 768, 771, 778, 790, 0,
264 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300265 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100266 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
267 1472, 1664, 0, 768, 771, 778, 798, 0,
268 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300269 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100270 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
271 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300272 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300273 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100274 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
275 1496, 1712, 0, 768, 771, 778, 809, 0,
276 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300277 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100278 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
279 1360, 1440, 0, 768, 771, 778, 813, 0,
280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300281 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100282 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
283 1360, 1440, 0, 800, 803, 809, 823, 0,
284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300285 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100286 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
287 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300288 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300289 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100290 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
291 1488, 1696, 0, 800, 803, 809, 838, 0,
292 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300293 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100294 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
295 1496, 1712, 0, 800, 803, 809, 843, 0,
296 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300297 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100298 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
299 1360, 1440, 0, 800, 803, 809, 847, 0,
300 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300301 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100302 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
303 1488, 1800, 0, 960, 961, 964, 1000, 0,
304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300305 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100306 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
307 1504, 1728, 0, 960, 961, 964, 1011, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300309 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100310 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
311 1360, 1440, 0, 960, 963, 967, 1017, 0,
312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300313 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100314 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
315 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
316 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300317 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100318 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
319 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
320 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300321 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100322 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
323 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
324 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300325 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100326 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
327 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
328 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300329 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100330 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
331 1536, 1792, 0, 768, 771, 777, 795, 0,
332 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300333 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100334 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
335 1440, 1520, 0, 768, 771, 776, 813, 0,
336 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300337 /* 0x51 - 1366x768@60Hz */
338 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
339 1579, 1792, 0, 768, 771, 774, 798, 0,
340 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
341 /* 0x56 - 1366x768@60Hz */
342 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
343 1436, 1500, 0, 768, 769, 772, 800, 0,
344 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300345 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100346 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
347 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
348 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300349 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100350 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
351 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
352 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300353 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100354 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
355 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
356 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300357 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100358 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
359 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
360 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300361 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100362 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
363 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300365 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100366 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
367 1520, 1600, 0, 900, 903, 909, 926, 0,
368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300369 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100370 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
371 1672, 1904, 0, 900, 903, 909, 934, 0,
372 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300373 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100374 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
375 1688, 1936, 0, 900, 903, 909, 942, 0,
376 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300377 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100378 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
379 1696, 1952, 0, 900, 903, 909, 948, 0,
380 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300381 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100382 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
383 1520, 1600, 0, 900, 903, 909, 953, 0,
384 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300385 /* 0x53 - 1600x900@60Hz */
386 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
387 1704, 1800, 0, 900, 901, 904, 1000, 0,
388 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300389 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100390 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
391 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300393 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100394 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
395 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
396 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300397 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100398 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
399 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
400 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300401 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100402 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
403 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
404 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300405 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100406 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
407 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
408 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300409 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100410 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
411 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
412 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300413 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100414 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
415 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
416 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300417 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100418 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
419 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
420 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300421 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100422 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
423 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
424 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300425 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100426 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
427 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
428 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300429 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100430 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
431 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
432 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300433 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100434 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
435 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
436 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300437 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100438 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
439 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
440 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300441 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100442 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
443 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
444 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300445 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100446 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
447 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
448 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300449 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100450 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300451 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100452 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300453 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100454 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
455 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
456 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300457 /* 0x52 - 1920x1080@60Hz */
458 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
459 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
460 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300461 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100462 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
463 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
464 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300465 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100466 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
467 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
468 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300469 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100470 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
471 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
472 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300473 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100474 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
475 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
476 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300477 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100478 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
479 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
480 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300481 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100482 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
483 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
484 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300485 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100486 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
487 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
488 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300489 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100490 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
491 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
492 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300493 /* 0x54 - 2048x1152@60Hz */
494 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
495 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
496 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300497 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100498 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
499 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
500 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300501 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100502 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
503 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
504 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300505 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100506 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
507 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
508 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300509 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100510 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
511 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
512 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300513 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100514 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
515 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
516 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300517 /* 0x57 - 4096x2160@60Hz RB */
518 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
519 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
520 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
521 /* 0x58 - 4096x2160@59.94Hz RB */
522 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
523 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
524 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100525};
526
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300527/*
528 * These more or less come from the DMT spec. The 720x400 modes are
529 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
530 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
531 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
532 * mode.
533 *
534 * The DMT modes have been fact-checked; the rest are mild guesses.
535 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100536static const struct drm_display_mode edid_est_modes[] = {
537 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
538 968, 1056, 0, 600, 601, 605, 628, 0,
539 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
540 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
541 896, 1024, 0, 600, 601, 603, 625, 0,
542 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
543 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
544 720, 840, 0, 480, 481, 484, 500, 0,
545 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
546 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100547 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100548 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
549 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
550 768, 864, 0, 480, 483, 486, 525, 0,
551 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100552 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100553 752, 800, 0, 480, 490, 492, 525, 0,
554 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
555 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
556 846, 900, 0, 400, 421, 423, 449, 0,
557 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
558 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
559 846, 900, 0, 400, 412, 414, 449, 0,
560 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
561 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
562 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
563 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100564 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100565 1136, 1312, 0, 768, 769, 772, 800, 0,
566 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
567 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
568 1184, 1328, 0, 768, 771, 777, 806, 0,
569 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
570 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
571 1184, 1344, 0, 768, 771, 777, 806, 0,
572 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
573 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
574 1208, 1264, 0, 768, 768, 776, 817, 0,
575 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
576 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
577 928, 1152, 0, 624, 625, 628, 667, 0,
578 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
579 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
580 896, 1056, 0, 600, 601, 604, 625, 0,
581 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
582 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
583 976, 1040, 0, 600, 637, 643, 666, 0,
584 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
585 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
586 1344, 1600, 0, 864, 865, 868, 900, 0,
587 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
588};
589
590struct minimode {
591 short w;
592 short h;
593 short r;
594 short rb;
595};
596
597static const struct minimode est3_modes[] = {
598 /* byte 6 */
599 { 640, 350, 85, 0 },
600 { 640, 400, 85, 0 },
601 { 720, 400, 85, 0 },
602 { 640, 480, 85, 0 },
603 { 848, 480, 60, 0 },
604 { 800, 600, 85, 0 },
605 { 1024, 768, 85, 0 },
606 { 1152, 864, 75, 0 },
607 /* byte 7 */
608 { 1280, 768, 60, 1 },
609 { 1280, 768, 60, 0 },
610 { 1280, 768, 75, 0 },
611 { 1280, 768, 85, 0 },
612 { 1280, 960, 60, 0 },
613 { 1280, 960, 85, 0 },
614 { 1280, 1024, 60, 0 },
615 { 1280, 1024, 85, 0 },
616 /* byte 8 */
617 { 1360, 768, 60, 0 },
618 { 1440, 900, 60, 1 },
619 { 1440, 900, 60, 0 },
620 { 1440, 900, 75, 0 },
621 { 1440, 900, 85, 0 },
622 { 1400, 1050, 60, 1 },
623 { 1400, 1050, 60, 0 },
624 { 1400, 1050, 75, 0 },
625 /* byte 9 */
626 { 1400, 1050, 85, 0 },
627 { 1680, 1050, 60, 1 },
628 { 1680, 1050, 60, 0 },
629 { 1680, 1050, 75, 0 },
630 { 1680, 1050, 85, 0 },
631 { 1600, 1200, 60, 0 },
632 { 1600, 1200, 65, 0 },
633 { 1600, 1200, 70, 0 },
634 /* byte 10 */
635 { 1600, 1200, 75, 0 },
636 { 1600, 1200, 85, 0 },
637 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300638 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100639 { 1856, 1392, 60, 0 },
640 { 1856, 1392, 75, 0 },
641 { 1920, 1200, 60, 1 },
642 { 1920, 1200, 60, 0 },
643 /* byte 11 */
644 { 1920, 1200, 75, 0 },
645 { 1920, 1200, 85, 0 },
646 { 1920, 1440, 60, 0 },
647 { 1920, 1440, 75, 0 },
648};
649
650static const struct minimode extra_modes[] = {
651 { 1024, 576, 60, 0 },
652 { 1366, 768, 60, 0 },
653 { 1600, 900, 60, 0 },
654 { 1680, 945, 60, 0 },
655 { 1920, 1080, 60, 0 },
656 { 2048, 1152, 60, 0 },
657 { 2048, 1536, 60, 0 },
658};
659
660/*
661 * Probably taken from CEA-861 spec.
662 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200663 *
664 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100665 */
666static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200667 /* 0 - dummy, VICs start at 1 */
668 { },
Thierry Redinga6b21832012-11-23 15:01:42 +0100669 /* 1 - 640x480@60Hz */
670 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
671 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300672 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530673 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100674 /* 2 - 720x480@60Hz */
675 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
676 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300677 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530678 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100679 /* 3 - 720x480@60Hz */
680 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
681 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300682 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530683 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100684 /* 4 - 1280x720@60Hz */
685 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
686 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300687 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530688 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100689 /* 5 - 1920x1080i@60Hz */
690 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
691 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
692 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300693 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530694 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700695 /* 6 - 720(1440)x480i@60Hz */
696 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
697 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100698 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300699 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530700 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700701 /* 7 - 720(1440)x480i@60Hz */
702 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
703 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100704 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300705 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530706 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700707 /* 8 - 720(1440)x240@60Hz */
708 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
709 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100710 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300711 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530712 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700713 /* 9 - 720(1440)x240@60Hz */
714 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
715 801, 858, 0, 240, 244, 247, 262, 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_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530718 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100719 /* 10 - 2880x480i@60Hz */
720 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
721 3204, 3432, 0, 480, 488, 494, 525, 0,
722 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300723 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530724 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100725 /* 11 - 2880x480i@60Hz */
726 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
727 3204, 3432, 0, 480, 488, 494, 525, 0,
728 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300729 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530730 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100731 /* 12 - 2880x240@60Hz */
732 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
733 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300734 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530735 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100736 /* 13 - 2880x240@60Hz */
737 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
738 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300739 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530740 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100741 /* 14 - 1440x480@60Hz */
742 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
743 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300744 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530745 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100746 /* 15 - 1440x480@60Hz */
747 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
748 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300749 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530750 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100751 /* 16 - 1920x1080@60Hz */
752 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
753 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300754 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530755 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100756 /* 17 - 720x576@50Hz */
757 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
758 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300759 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530760 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100761 /* 18 - 720x576@50Hz */
762 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
763 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300764 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530765 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100766 /* 19 - 1280x720@50Hz */
767 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
768 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300769 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530770 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100771 /* 20 - 1920x1080i@50Hz */
772 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
773 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
774 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300775 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530776 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700777 /* 21 - 720(1440)x576i@50Hz */
778 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
779 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100780 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300781 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530782 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700783 /* 22 - 720(1440)x576i@50Hz */
784 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
785 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100786 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300787 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530788 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700789 /* 23 - 720(1440)x288@50Hz */
790 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
791 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100792 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300793 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530794 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700795 /* 24 - 720(1440)x288@50Hz */
796 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
797 795, 864, 0, 288, 290, 293, 312, 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_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530800 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100801 /* 25 - 2880x576i@50Hz */
802 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
803 3180, 3456, 0, 576, 580, 586, 625, 0,
804 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300805 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530806 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100807 /* 26 - 2880x576i@50Hz */
808 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
809 3180, 3456, 0, 576, 580, 586, 625, 0,
810 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300811 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530812 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100813 /* 27 - 2880x288@50Hz */
814 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
815 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300816 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530817 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100818 /* 28 - 2880x288@50Hz */
819 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
820 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300821 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530822 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100823 /* 29 - 1440x576@50Hz */
824 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
825 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300826 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530827 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100828 /* 30 - 1440x576@50Hz */
829 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
830 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300831 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530832 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100833 /* 31 - 1920x1080@50Hz */
834 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
835 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300836 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530837 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100838 /* 32 - 1920x1080@24Hz */
839 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
840 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300841 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530842 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100843 /* 33 - 1920x1080@25Hz */
844 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
845 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300846 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530847 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100848 /* 34 - 1920x1080@30Hz */
849 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
850 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300851 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530852 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100853 /* 35 - 2880x480@60Hz */
854 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
855 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300856 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530857 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100858 /* 36 - 2880x480@60Hz */
859 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
860 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300861 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530862 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100863 /* 37 - 2880x576@50Hz */
864 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
865 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300866 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530867 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100868 /* 38 - 2880x576@50Hz */
869 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
870 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300871 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530872 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100873 /* 39 - 1920x1080i@50Hz */
874 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
875 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
876 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300877 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530878 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100879 /* 40 - 1920x1080i@100Hz */
880 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
881 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
882 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300883 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530884 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100885 /* 41 - 1280x720@100Hz */
886 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
887 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300888 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530889 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100890 /* 42 - 720x576@100Hz */
891 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
892 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300893 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530894 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100895 /* 43 - 720x576@100Hz */
896 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
897 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300898 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530899 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700900 /* 44 - 720(1440)x576i@100Hz */
901 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
902 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100903 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700904 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530905 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700906 /* 45 - 720(1440)x576i@100Hz */
907 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
908 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100909 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700910 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530911 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100912 /* 46 - 1920x1080i@120Hz */
913 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
914 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
915 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300916 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530917 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100918 /* 47 - 1280x720@120Hz */
919 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
920 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300921 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530922 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100923 /* 48 - 720x480@120Hz */
924 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
925 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300926 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530927 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100928 /* 49 - 720x480@120Hz */
929 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
930 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300931 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530932 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700933 /* 50 - 720(1440)x480i@120Hz */
934 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
935 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100936 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300937 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530938 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700939 /* 51 - 720(1440)x480i@120Hz */
940 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
941 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100942 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300943 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530944 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100945 /* 52 - 720x576@200Hz */
946 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
947 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300948 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530949 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100950 /* 53 - 720x576@200Hz */
951 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
952 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300953 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530954 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700955 /* 54 - 720(1440)x576i@200Hz */
956 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
957 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100958 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300959 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530960 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700961 /* 55 - 720(1440)x576i@200Hz */
962 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
963 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100964 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300965 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530966 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100967 /* 56 - 720x480@240Hz */
968 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
969 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300970 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530971 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100972 /* 57 - 720x480@240Hz */
973 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
974 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300975 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530976 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200977 /* 58 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700978 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
979 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100980 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300981 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530982 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200983 /* 59 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700984 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
985 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100986 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300987 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530988 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100989 /* 60 - 1280x720@24Hz */
990 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
991 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300992 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530993 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100994 /* 61 - 1280x720@25Hz */
995 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
996 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300997 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530998 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100999 /* 62 - 1280x720@30Hz */
1000 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1001 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001002 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301003 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001004 /* 63 - 1920x1080@120Hz */
1005 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1006 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001007 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301008 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001009 /* 64 - 1920x1080@100Hz */
1010 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001011 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001012 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301013 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301014 /* 65 - 1280x720@24Hz */
1015 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1016 3080, 3300, 0, 720, 725, 730, 750, 0,
1017 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1018 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1019 /* 66 - 1280x720@25Hz */
1020 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1021 3740, 3960, 0, 720, 725, 730, 750, 0,
1022 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1023 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1024 /* 67 - 1280x720@30Hz */
1025 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1026 3080, 3300, 0, 720, 725, 730, 750, 0,
1027 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1028 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1029 /* 68 - 1280x720@50Hz */
1030 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1031 1760, 1980, 0, 720, 725, 730, 750, 0,
1032 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1033 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1034 /* 69 - 1280x720@60Hz */
1035 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1036 1430, 1650, 0, 720, 725, 730, 750, 0,
1037 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1038 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1039 /* 70 - 1280x720@100Hz */
1040 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1041 1760, 1980, 0, 720, 725, 730, 750, 0,
1042 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1043 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1044 /* 71 - 1280x720@120Hz */
1045 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1046 1430, 1650, 0, 720, 725, 730, 750, 0,
1047 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1048 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1049 /* 72 - 1920x1080@24Hz */
1050 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1051 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1052 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1053 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1054 /* 73 - 1920x1080@25Hz */
1055 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1056 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1057 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1058 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1059 /* 74 - 1920x1080@30Hz */
1060 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1061 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1062 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1063 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1064 /* 75 - 1920x1080@50Hz */
1065 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1066 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1067 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1068 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1069 /* 76 - 1920x1080@60Hz */
1070 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1071 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1072 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1073 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1074 /* 77 - 1920x1080@100Hz */
1075 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1076 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1077 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1078 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1079 /* 78 - 1920x1080@120Hz */
1080 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1081 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1082 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1083 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1084 /* 79 - 1680x720@24Hz */
1085 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1086 3080, 3300, 0, 720, 725, 730, 750, 0,
1087 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1088 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1089 /* 80 - 1680x720@25Hz */
1090 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1091 2948, 3168, 0, 720, 725, 730, 750, 0,
1092 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1093 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1094 /* 81 - 1680x720@30Hz */
1095 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1096 2420, 2640, 0, 720, 725, 730, 750, 0,
1097 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1098 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1099 /* 82 - 1680x720@50Hz */
1100 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1101 1980, 2200, 0, 720, 725, 730, 750, 0,
1102 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1103 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1104 /* 83 - 1680x720@60Hz */
1105 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1106 1980, 2200, 0, 720, 725, 730, 750, 0,
1107 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1108 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1109 /* 84 - 1680x720@100Hz */
1110 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1111 1780, 2000, 0, 720, 725, 730, 825, 0,
1112 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1113 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1114 /* 85 - 1680x720@120Hz */
1115 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1116 1780, 2000, 0, 720, 725, 730, 825, 0,
1117 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1118 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1119 /* 86 - 2560x1080@24Hz */
1120 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1121 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1122 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1123 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1124 /* 87 - 2560x1080@25Hz */
1125 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1126 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1127 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1128 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1129 /* 88 - 2560x1080@30Hz */
1130 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1131 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1132 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1133 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1134 /* 89 - 2560x1080@50Hz */
1135 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1136 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1137 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1138 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1139 /* 90 - 2560x1080@60Hz */
1140 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1141 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1142 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1143 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1144 /* 91 - 2560x1080@100Hz */
1145 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1146 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1147 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1148 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1149 /* 92 - 2560x1080@120Hz */
1150 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1151 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1152 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1153 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1154 /* 93 - 3840x2160p@24Hz 16:9 */
1155 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1156 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1157 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1158 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1159 /* 94 - 3840x2160p@25Hz 16:9 */
1160 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1161 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1162 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1163 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1164 /* 95 - 3840x2160p@30Hz 16:9 */
1165 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1166 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1167 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1168 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1169 /* 96 - 3840x2160p@50Hz 16:9 */
1170 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1171 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1172 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1173 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1174 /* 97 - 3840x2160p@60Hz 16:9 */
1175 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1176 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1177 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1178 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1179 /* 98 - 4096x2160p@24Hz 256:135 */
1180 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1181 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1182 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1183 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1184 /* 99 - 4096x2160p@25Hz 256:135 */
1185 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1186 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1187 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1188 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1189 /* 100 - 4096x2160p@30Hz 256:135 */
1190 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1191 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1192 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1193 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1194 /* 101 - 4096x2160p@50Hz 256:135 */
1195 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1196 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1197 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1198 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1199 /* 102 - 4096x2160p@60Hz 256:135 */
1200 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1201 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1202 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1203 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1204 /* 103 - 3840x2160p@24Hz 64:27 */
1205 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1206 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1207 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1208 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1209 /* 104 - 3840x2160p@25Hz 64:27 */
1210 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1211 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1212 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1213 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1214 /* 105 - 3840x2160p@30Hz 64:27 */
1215 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1216 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1217 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1218 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1219 /* 106 - 3840x2160p@50Hz 64:27 */
1220 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1221 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1222 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1223 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1224 /* 107 - 3840x2160p@60Hz 64:27 */
1225 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1226 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1228 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001229};
1230
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001231/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001232 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001233 */
1234static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001235 /* 0 - dummy, VICs start at 1 */
1236 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001237 /* 1 - 3840x2160@30Hz */
1238 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1239 3840, 4016, 4104, 4400, 0,
1240 2160, 2168, 2178, 2250, 0,
1241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1242 .vrefresh = 30, },
1243 /* 2 - 3840x2160@25Hz */
1244 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1245 3840, 4896, 4984, 5280, 0,
1246 2160, 2168, 2178, 2250, 0,
1247 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1248 .vrefresh = 25, },
1249 /* 3 - 3840x2160@24Hz */
1250 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1251 3840, 5116, 5204, 5500, 0,
1252 2160, 2168, 2178, 2250, 0,
1253 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1254 .vrefresh = 24, },
1255 /* 4 - 4096x2160@24Hz (SMPTE) */
1256 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1257 4096, 5116, 5204, 5500, 0,
1258 2160, 2168, 2178, 2250, 0,
1259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1260 .vrefresh = 24, },
1261};
1262
Adam Jackson61e57a82010-03-29 21:43:18 +00001263/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001264
Adam Jackson083ae052009-09-23 17:30:45 -04001265static const u8 edid_header[] = {
1266 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1267};
Dave Airlief453ba02008-11-07 14:05:41 -08001268
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001269/**
1270 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1271 * @raw_edid: pointer to raw base EDID block
1272 *
1273 * Sanity check the header of the base EDID block.
1274 *
1275 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001276 */
1277int drm_edid_header_is_valid(const u8 *raw_edid)
1278{
1279 int i, score = 0;
1280
1281 for (i = 0; i < sizeof(edid_header); i++)
1282 if (raw_edid[i] == edid_header[i])
1283 score++;
1284
1285 return score;
1286}
1287EXPORT_SYMBOL(drm_edid_header_is_valid);
1288
Adam Jackson47819ba2012-05-30 16:42:39 -04001289static int edid_fixup __read_mostly = 6;
1290module_param_named(edid_fixup, edid_fixup, int, 0400);
1291MODULE_PARM_DESC(edid_fixup,
1292 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001293
Dave Airlie40d9b042014-10-20 16:29:33 +10001294static void drm_get_displayid(struct drm_connector *connector,
1295 struct edid *edid);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001296
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001297static int drm_edid_block_checksum(const u8 *raw_edid)
1298{
1299 int i;
1300 u8 csum = 0;
1301 for (i = 0; i < EDID_LENGTH; i++)
1302 csum += raw_edid[i];
1303
1304 return csum;
1305}
1306
Stefan Brünsd6885d62014-11-30 19:57:41 +01001307static bool drm_edid_is_zero(const u8 *in_edid, int length)
1308{
1309 if (memchr_inv(in_edid, 0, length))
1310 return false;
1311
1312 return true;
1313}
1314
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001315/**
1316 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1317 * @raw_edid: pointer to raw EDID block
1318 * @block: type of block to validate (0 for base, extension otherwise)
1319 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001320 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001321 *
1322 * Validate a base or extension EDID block and optionally dump bad blocks to
1323 * the console.
1324 *
1325 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001326 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001327bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1328 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001329{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001330 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001331 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001332
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001333 if (WARN_ON(!raw_edid))
1334 return false;
1335
Adam Jackson47819ba2012-05-30 16:42:39 -04001336 if (edid_fixup > 8 || edid_fixup < 0)
1337 edid_fixup = 6;
1338
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001339 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001340 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001341 if (score == 8) {
1342 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001343 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001344 } else if (score >= edid_fixup) {
1345 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1346 * The corrupt flag needs to be set here otherwise, the
1347 * fix-up code here will correct the problem, the
1348 * checksum is correct and the test fails
1349 */
1350 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001351 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001352 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1353 memcpy(raw_edid, edid_header, sizeof(edid_header));
1354 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001355 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001356 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001357 goto bad;
1358 }
1359 }
Dave Airlief453ba02008-11-07 14:05:41 -08001360
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001361 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001362 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001363 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001364 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001365
Adam Jackson4a638b42010-05-25 16:33:09 -04001366 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001367 if (raw_edid[0] == CEA_EXT) {
1368 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1369 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1370 } else {
1371 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001372 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001373
Adam Jackson4a638b42010-05-25 16:33:09 -04001374 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001375 }
Dave Airlief453ba02008-11-07 14:05:41 -08001376 }
1377
Adam Jackson61e57a82010-03-29 21:43:18 +00001378 /* per-block-type checks */
1379 switch (raw_edid[0]) {
1380 case 0: /* base */
1381 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001382 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001383 goto bad;
1384 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001385
Adam Jackson61e57a82010-03-29 21:43:18 +00001386 if (edid->revision > 4)
1387 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1388 break;
1389
1390 default:
1391 break;
1392 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001393
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001394 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001395
1396bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001397 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001398 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001399 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001400 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001401 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001402 print_hex_dump(KERN_NOTICE,
1403 " \t", DUMP_PREFIX_NONE, 16, 1,
1404 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001405 }
Dave Airlief453ba02008-11-07 14:05:41 -08001406 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001407 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001408}
Carsten Emdeda0df922012-03-18 22:37:33 +01001409EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001410
1411/**
1412 * drm_edid_is_valid - sanity check EDID data
1413 * @edid: EDID data
1414 *
1415 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001416 *
1417 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001418 */
1419bool drm_edid_is_valid(struct edid *edid)
1420{
1421 int i;
1422 u8 *raw = (u8 *)edid;
1423
1424 if (!edid)
1425 return false;
1426
1427 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001428 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001429 return false;
1430
1431 return true;
1432}
Alex Deucher3c537882010-02-05 04:21:19 -05001433EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001434
Adam Jackson61e57a82010-03-29 21:43:18 +00001435#define DDC_SEGMENT_ADDR 0x30
1436/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001437 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001438 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001439 * @buf: EDID data buffer to be filled
1440 * @block: 128 byte EDID block to start fetching from
1441 * @len: EDID data buffer length to fetch
1442 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001443 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001444 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001445 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001446 */
1447static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001448drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001449{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001450 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001451 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001452 unsigned char segment = block >> 1;
1453 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001454 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001455
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001456 /*
1457 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001458 * adapter reports EAGAIN. However, we find that bit-banging transfers
1459 * are susceptible to errors under a heavily loaded machine and
1460 * generate spurious NAKs and timeouts. Retrying the transfer
1461 * of the individual block a few times seems to overcome this.
1462 */
1463 do {
1464 struct i2c_msg msgs[] = {
1465 {
Shirish Scd004b32012-08-30 07:04:06 +00001466 .addr = DDC_SEGMENT_ADDR,
1467 .flags = 0,
1468 .len = 1,
1469 .buf = &segment,
1470 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001471 .addr = DDC_ADDR,
1472 .flags = 0,
1473 .len = 1,
1474 .buf = &start,
1475 }, {
1476 .addr = DDC_ADDR,
1477 .flags = I2C_M_RD,
1478 .len = len,
1479 .buf = buf,
1480 }
1481 };
Shirish Scd004b32012-08-30 07:04:06 +00001482
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001483 /*
1484 * Avoid sending the segment addr to not upset non-compliant
1485 * DDC monitors.
1486 */
Shirish Scd004b32012-08-30 07:04:06 +00001487 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1488
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001489 if (ret == -ENXIO) {
1490 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1491 adapter->name);
1492 break;
1493 }
Shirish Scd004b32012-08-30 07:04:06 +00001494 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001495
Shirish Scd004b32012-08-30 07:04:06 +00001496 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001497}
1498
Chris Wilson14544d02016-10-24 12:38:21 +01001499static void connector_bad_edid(struct drm_connector *connector,
1500 u8 *edid, int num_blocks)
1501{
1502 int i;
1503
1504 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1505 return;
1506
1507 dev_warn(connector->dev->dev,
1508 "%s: EDID is invalid:\n",
1509 connector->name);
1510 for (i = 0; i < num_blocks; i++) {
1511 u8 *block = edid + i * EDID_LENGTH;
1512 char prefix[20];
1513
1514 if (drm_edid_is_zero(block, EDID_LENGTH))
1515 sprintf(prefix, "\t[%02x] ZERO ", i);
1516 else if (!drm_edid_block_valid(block, i, false, NULL))
1517 sprintf(prefix, "\t[%02x] BAD ", i);
1518 else
1519 sprintf(prefix, "\t[%02x] GOOD ", i);
1520
1521 print_hex_dump(KERN_WARNING,
1522 prefix, DUMP_PREFIX_NONE, 16, 1,
1523 block, EDID_LENGTH, false);
1524 }
1525}
1526
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001527/**
1528 * drm_do_get_edid - get EDID data using a custom EDID block read function
1529 * @connector: connector we're probing
1530 * @get_edid_block: EDID block read function
1531 * @data: private data passed to the block read function
1532 *
1533 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1534 * exposes a different interface to read EDID blocks this function can be used
1535 * to get EDID data using a custom block read function.
1536 *
1537 * As in the general case the DDC bus is accessible by the kernel at the I2C
1538 * level, drivers must make all reasonable efforts to expose it as an I2C
1539 * adapter and use drm_get_edid() instead of abusing this function.
1540 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001541 * The EDID may be overridden using debugfs override_edid or firmare EDID
1542 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1543 * order. Having either of them bypasses actual EDID reads.
1544 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001545 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1546 */
1547struct edid *drm_do_get_edid(struct drm_connector *connector,
1548 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1549 size_t len),
1550 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001551{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001552 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001553 u8 *edid, *new;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001554 struct edid *override = NULL;
1555
1556 if (connector->override_edid)
Ville Syrjälä11b83e32018-02-23 21:25:02 +02001557 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
Jani Nikula53fd40a2017-09-12 11:19:26 +03001558
1559 if (!override)
1560 override = drm_load_edid_firmware(connector);
1561
1562 if (!IS_ERR_OR_NULL(override))
1563 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001564
Chris Wilsonf14f3682016-10-17 09:35:12 +01001565 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001566 return NULL;
1567
1568 /* base block fetch */
1569 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001570 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001571 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001572 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001573 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001574 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001575 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001576 connector->null_edid_counter++;
1577 goto carp;
1578 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001579 }
1580 if (i == 4)
1581 goto carp;
1582
1583 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001584 valid_extensions = edid[0x7e];
1585 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001586 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001587
Chris Wilson14544d02016-10-24 12:38:21 +01001588 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001589 if (!new)
1590 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001591 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001592
Chris Wilsonf14f3682016-10-17 09:35:12 +01001593 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001594 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001595
Adam Jackson61e57a82010-03-29 21:43:18 +00001596 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001597 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001598 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001599 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001600 break;
1601 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001602
Chris Wilson14544d02016-10-24 12:38:21 +01001603 if (i == 4)
1604 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001605 }
1606
Chris Wilsonf14f3682016-10-17 09:35:12 +01001607 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001608 u8 *base;
1609
1610 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1611
Chris Wilsonf14f3682016-10-17 09:35:12 +01001612 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1613 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001614
1615 new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001616 if (!new)
1617 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001618
1619 base = new;
1620 for (i = 0; i <= edid[0x7e]; i++) {
1621 u8 *block = edid + i * EDID_LENGTH;
1622
1623 if (!drm_edid_block_valid(block, i, false, NULL))
1624 continue;
1625
1626 memcpy(base, block, EDID_LENGTH);
1627 base += EDID_LENGTH;
1628 }
1629
1630 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001631 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001632 }
1633
Chris Wilsonf14f3682016-10-17 09:35:12 +01001634 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001635
1636carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001637 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001638out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001639 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001640 return NULL;
1641}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001642EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001643
1644/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001645 * drm_probe_ddc() - probe DDC presence
1646 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001647 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001648 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001649 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001650bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001651drm_probe_ddc(struct i2c_adapter *adapter)
1652{
1653 unsigned char out;
1654
1655 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1656}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001657EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001658
1659/**
1660 * drm_get_edid - get EDID data, if available
1661 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001662 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001663 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001664 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001665 * attach it to the connector.
1666 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001667 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001668 */
1669struct edid *drm_get_edid(struct drm_connector *connector,
1670 struct i2c_adapter *adapter)
1671{
Dave Airlie40d9b042014-10-20 16:29:33 +10001672 struct edid *edid;
1673
Jani Nikula15f080f2017-02-17 17:20:53 +02001674 if (connector->force == DRM_FORCE_OFF)
1675 return NULL;
1676
1677 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001678 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001679
Dave Airlie40d9b042014-10-20 16:29:33 +10001680 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1681 if (edid)
1682 drm_get_displayid(connector, edid);
1683 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001684}
1685EXPORT_SYMBOL(drm_get_edid);
1686
Jani Nikula51f8da52013-09-27 15:08:27 +03001687/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001688 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1689 * @connector: connector we're probing
1690 * @adapter: I2C adapter to use for DDC
1691 *
1692 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1693 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1694 * switch DDC to the GPU which is retrieving EDID.
1695 *
1696 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1697 */
1698struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1699 struct i2c_adapter *adapter)
1700{
1701 struct pci_dev *pdev = connector->dev->pdev;
1702 struct edid *edid;
1703
1704 vga_switcheroo_lock_ddc(pdev);
1705 edid = drm_get_edid(connector, adapter);
1706 vga_switcheroo_unlock_ddc(pdev);
1707
1708 return edid;
1709}
1710EXPORT_SYMBOL(drm_get_edid_switcheroo);
1711
1712/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001713 * drm_edid_duplicate - duplicate an EDID and the extensions
1714 * @edid: EDID to duplicate
1715 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001716 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001717 */
1718struct edid *drm_edid_duplicate(const struct edid *edid)
1719{
1720 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1721}
1722EXPORT_SYMBOL(drm_edid_duplicate);
1723
Adam Jackson61e57a82010-03-29 21:43:18 +00001724/*** EDID parsing ***/
1725
Dave Airlief453ba02008-11-07 14:05:41 -08001726/**
1727 * edid_vendor - match a string against EDID's obfuscated vendor field
1728 * @edid: EDID to match
1729 * @vendor: vendor string
1730 *
1731 * Returns true if @vendor is in @edid, false otherwise
1732 */
Keith Packard170178f2017-12-13 00:44:26 -08001733static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001734{
1735 char edid_vendor[3];
1736
1737 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1738 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1739 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001740 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001741
1742 return !strncmp(edid_vendor, vendor, 3);
1743}
1744
1745/**
1746 * edid_get_quirks - return quirk flags for a given EDID
1747 * @edid: EDID to process
1748 *
1749 * This tells subsequent routines what fixes they need to apply.
1750 */
Keith Packard170178f2017-12-13 00:44:26 -08001751static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001752{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001753 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001754 int i;
1755
1756 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1757 quirk = &edid_quirk_list[i];
1758
1759 if (edid_vendor(edid, quirk->vendor) &&
1760 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1761 return quirk->quirks;
1762 }
1763
1764 return 0;
1765}
1766
1767#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001768#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001769
Dave Airlief453ba02008-11-07 14:05:41 -08001770/**
1771 * edid_fixup_preferred - set preferred modes based on quirk list
1772 * @connector: has mode list to fix up
1773 * @quirks: quirks list
1774 *
1775 * Walk the mode list for @connector, clearing the preferred status
1776 * on existing modes and setting it anew for the right mode ala @quirks.
1777 */
1778static void edid_fixup_preferred(struct drm_connector *connector,
1779 u32 quirks)
1780{
1781 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001782 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001783 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001784
1785 if (list_empty(&connector->probed_modes))
1786 return;
1787
1788 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1789 target_refresh = 60;
1790 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1791 target_refresh = 75;
1792
1793 preferred_mode = list_first_entry(&connector->probed_modes,
1794 struct drm_display_mode, head);
1795
1796 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1797 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1798
1799 if (cur_mode == preferred_mode)
1800 continue;
1801
1802 /* Largest mode is preferred */
1803 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1804 preferred_mode = cur_mode;
1805
Alex Deucher339d2022013-08-15 11:42:14 -04001806 cur_vrefresh = cur_mode->vrefresh ?
1807 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1808 preferred_vrefresh = preferred_mode->vrefresh ?
1809 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001810 /* At a given size, try to get closest to target refresh */
1811 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001812 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1813 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001814 preferred_mode = cur_mode;
1815 }
1816 }
1817
1818 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1819}
1820
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001821static bool
1822mode_is_rb(const struct drm_display_mode *mode)
1823{
1824 return (mode->htotal - mode->hdisplay == 160) &&
1825 (mode->hsync_end - mode->hdisplay == 80) &&
1826 (mode->hsync_end - mode->hsync_start == 32) &&
1827 (mode->vsync_start - mode->vdisplay == 3);
1828}
1829
Adam Jackson33c75312012-04-13 16:33:29 -04001830/*
1831 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1832 * @dev: Device to duplicate against
1833 * @hsize: Mode width
1834 * @vsize: Mode height
1835 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001836 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001837 *
1838 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001839 *
1840 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001841 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001842struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001843 int hsize, int vsize, int fresh,
1844 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001845{
Adam Jackson07a5e632009-12-03 17:44:38 -05001846 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001847
Thierry Redinga6b21832012-11-23 15:01:42 +01001848 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001849 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001850 if (hsize != ptr->hdisplay)
1851 continue;
1852 if (vsize != ptr->vdisplay)
1853 continue;
1854 if (fresh != drm_mode_vrefresh(ptr))
1855 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001856 if (rb != mode_is_rb(ptr))
1857 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001858
1859 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001860 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001861
1862 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001863}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001864EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001865
Adam Jacksond1ff6402010-03-29 21:43:26 +00001866typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1867
1868static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001869cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1870{
1871 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001872 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001873 u8 *det_base = ext + d;
1874
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001875 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001876 for (i = 0; i < n; i++)
1877 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1878}
1879
1880static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001881vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1882{
1883 unsigned int i, n = min((int)ext[0x02], 6);
1884 u8 *det_base = ext + 5;
1885
1886 if (ext[0x01] != 1)
1887 return; /* unknown version */
1888
1889 for (i = 0; i < n; i++)
1890 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1891}
1892
1893static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001894drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1895{
1896 int i;
1897 struct edid *edid = (struct edid *)raw_edid;
1898
1899 if (edid == NULL)
1900 return;
1901
1902 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1903 cb(&(edid->detailed_timings[i]), closure);
1904
Adam Jackson4d76a222010-08-03 14:38:17 -04001905 for (i = 1; i <= raw_edid[0x7e]; i++) {
1906 u8 *ext = raw_edid + (i * EDID_LENGTH);
1907 switch (*ext) {
1908 case CEA_EXT:
1909 cea_for_each_detailed_block(ext, cb, closure);
1910 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001911 case VTB_EXT:
1912 vtb_for_each_detailed_block(ext, cb, closure);
1913 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001914 default:
1915 break;
1916 }
1917 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001918}
1919
1920static void
1921is_rb(struct detailed_timing *t, void *data)
1922{
1923 u8 *r = (u8 *)t;
1924 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1925 if (r[15] & 0x10)
1926 *(bool *)data = true;
1927}
1928
1929/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1930static bool
1931drm_monitor_supports_rb(struct edid *edid)
1932{
1933 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001934 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001935 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1936 return ret;
1937 }
1938
1939 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1940}
1941
Adam Jackson7a374352010-03-29 21:43:30 +00001942static void
1943find_gtf2(struct detailed_timing *t, void *data)
1944{
1945 u8 *r = (u8 *)t;
1946 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1947 *(u8 **)data = r;
1948}
1949
1950/* Secondary GTF curve kicks in above some break frequency */
1951static int
1952drm_gtf2_hbreak(struct edid *edid)
1953{
1954 u8 *r = NULL;
1955 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1956 return r ? (r[12] * 2) : 0;
1957}
1958
1959static int
1960drm_gtf2_2c(struct edid *edid)
1961{
1962 u8 *r = NULL;
1963 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1964 return r ? r[13] : 0;
1965}
1966
1967static int
1968drm_gtf2_m(struct edid *edid)
1969{
1970 u8 *r = NULL;
1971 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1972 return r ? (r[15] << 8) + r[14] : 0;
1973}
1974
1975static int
1976drm_gtf2_k(struct edid *edid)
1977{
1978 u8 *r = NULL;
1979 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1980 return r ? r[16] : 0;
1981}
1982
1983static int
1984drm_gtf2_2j(struct edid *edid)
1985{
1986 u8 *r = NULL;
1987 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1988 return r ? r[17] : 0;
1989}
1990
1991/**
1992 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1993 * @edid: EDID block to scan
1994 */
1995static int standard_timing_level(struct edid *edid)
1996{
1997 if (edid->revision >= 2) {
1998 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1999 return LEVEL_CVT;
2000 if (drm_gtf2_hbreak(edid))
2001 return LEVEL_GTF2;
2002 return LEVEL_GTF;
2003 }
2004 return LEVEL_DMT;
2005}
2006
Adam Jackson23425ca2009-09-23 17:30:58 -04002007/*
2008 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2009 * monitors fill with ascii space (0x20) instead.
2010 */
2011static int
2012bad_std_timing(u8 a, u8 b)
2013{
2014 return (a == 0x00 && b == 0x00) ||
2015 (a == 0x01 && b == 0x01) ||
2016 (a == 0x20 && b == 0x20);
2017}
2018
Dave Airlief453ba02008-11-07 14:05:41 -08002019/**
2020 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002021 * @connector: connector of for the EDID block
2022 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002023 * @t: standard timing params
2024 *
2025 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002026 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002027 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002028static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002029drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002030 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002031{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002032 struct drm_device *dev = connector->dev;
2033 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002034 int hsize, vsize;
2035 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002036 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2037 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002038 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2039 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002040 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002041
Adam Jackson23425ca2009-09-23 17:30:58 -04002042 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2043 return NULL;
2044
Zhao Yakui5c612592009-06-22 13:17:10 +08002045 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2046 hsize = t->hsize * 8 + 248;
2047 /* vrefresh_rate = vfreq + 60 */
2048 vrefresh_rate = vfreq + 60;
2049 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002050 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002051 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002052 vsize = hsize;
2053 else
2054 vsize = (hsize * 10) / 16;
2055 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002056 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002057 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002058 vsize = (hsize * 4) / 5;
2059 else
2060 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002061
2062 /* HDTV hack, part 1 */
2063 if (vrefresh_rate == 60 &&
2064 ((hsize == 1360 && vsize == 765) ||
2065 (hsize == 1368 && vsize == 769))) {
2066 hsize = 1366;
2067 vsize = 768;
2068 }
2069
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002070 /*
2071 * If this connector already has a mode for this size and refresh
2072 * rate (because it came from detailed or CVT info), use that
2073 * instead. This way we don't have to guess at interlace or
2074 * reduced blanking.
2075 */
Adam Jackson522032d2010-04-09 16:52:49 +00002076 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002077 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2078 drm_mode_vrefresh(m) == vrefresh_rate)
2079 return NULL;
2080
Adam Jacksona0910c82010-03-29 21:43:28 +00002081 /* HDTV hack, part 2 */
2082 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2083 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002084 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002085 if (!mode)
2086 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002087 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002088 mode->hsync_start = mode->hsync_start - 1;
2089 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002090 return mode;
2091 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002092
Zhao Yakui559ee212009-09-03 09:33:47 +08002093 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002094 if (drm_monitor_supports_rb(edid)) {
2095 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2096 true);
2097 if (mode)
2098 return mode;
2099 }
2100 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002101 if (mode)
2102 return mode;
2103
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002104 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002105 switch (timing_level) {
2106 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002107 break;
2108 case LEVEL_GTF:
2109 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2110 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002111 case LEVEL_GTF2:
2112 /*
2113 * This is potentially wrong if there's ever a monitor with
2114 * more than one ranges section, each claiming a different
2115 * secondary GTF curve. Please don't do that.
2116 */
2117 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002118 if (!mode)
2119 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002120 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002121 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002122 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2123 vrefresh_rate, 0, 0,
2124 drm_gtf2_m(edid),
2125 drm_gtf2_2c(edid),
2126 drm_gtf2_k(edid),
2127 drm_gtf2_2j(edid));
2128 }
2129 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002130 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002131 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2132 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002133 break;
2134 }
Dave Airlief453ba02008-11-07 14:05:41 -08002135 return mode;
2136}
2137
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002138/*
2139 * EDID is delightfully ambiguous about how interlaced modes are to be
2140 * encoded. Our internal representation is of frame height, but some
2141 * HDTV detailed timings are encoded as field height.
2142 *
2143 * The format list here is from CEA, in frame size. Technically we
2144 * should be checking refresh rate too. Whatever.
2145 */
2146static void
2147drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2148 struct detailed_pixel_timing *pt)
2149{
2150 int i;
2151 static const struct {
2152 int w, h;
2153 } cea_interlaced[] = {
2154 { 1920, 1080 },
2155 { 720, 480 },
2156 { 1440, 480 },
2157 { 2880, 480 },
2158 { 720, 576 },
2159 { 1440, 576 },
2160 { 2880, 576 },
2161 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002162
2163 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2164 return;
2165
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002166 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002167 if ((mode->hdisplay == cea_interlaced[i].w) &&
2168 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2169 mode->vdisplay *= 2;
2170 mode->vsync_start *= 2;
2171 mode->vsync_end *= 2;
2172 mode->vtotal *= 2;
2173 mode->vtotal |= 1;
2174 }
2175 }
2176
2177 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2178}
2179
Dave Airlief453ba02008-11-07 14:05:41 -08002180/**
2181 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2182 * @dev: DRM device (needed to create new mode)
2183 * @edid: EDID block
2184 * @timing: EDID detailed timing info
2185 * @quirks: quirks to apply
2186 *
2187 * An EDID detailed timing block contains enough info for us to create and
2188 * return a new struct drm_display_mode.
2189 */
2190static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2191 struct edid *edid,
2192 struct detailed_timing *timing,
2193 u32 quirks)
2194{
2195 struct drm_display_mode *mode;
2196 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002197 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2198 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2199 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2200 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002201 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2202 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 +01002203 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 +02002204 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 -08002205
Adam Jacksonfc438962009-06-04 10:20:34 +10002206 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002207 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002208 return NULL;
2209
Michel Dänzer0454bea2009-06-15 16:56:07 +02002210 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002211 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002212 return NULL;
2213 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002214 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002215 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002216 }
2217
Zhao Yakuifcb45612009-10-14 09:11:25 +08002218 /* it is incorrect if hsync/vsync width is zero */
2219 if (!hsync_pulse_width || !vsync_pulse_width) {
2220 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2221 "Wrong Hsync/Vsync pulse width\n");
2222 return NULL;
2223 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002224
2225 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2226 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2227 if (!mode)
2228 return NULL;
2229
2230 goto set_size;
2231 }
2232
Dave Airlief453ba02008-11-07 14:05:41 -08002233 mode = drm_mode_create(dev);
2234 if (!mode)
2235 return NULL;
2236
Dave Airlief453ba02008-11-07 14:05:41 -08002237 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002238 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002239
Michel Dänzer0454bea2009-06-15 16:56:07 +02002240 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002241
Michel Dänzer0454bea2009-06-15 16:56:07 +02002242 mode->hdisplay = hactive;
2243 mode->hsync_start = mode->hdisplay + hsync_offset;
2244 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2245 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002246
Michel Dänzer0454bea2009-06-15 16:56:07 +02002247 mode->vdisplay = vactive;
2248 mode->vsync_start = mode->vdisplay + vsync_offset;
2249 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2250 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002251
Jesse Barnes7064fef2009-11-05 10:12:54 -08002252 /* Some EDIDs have bogus h/vtotal values */
2253 if (mode->hsync_end > mode->htotal)
2254 mode->htotal = mode->hsync_end + 1;
2255 if (mode->vsync_end > mode->vtotal)
2256 mode->vtotal = mode->vsync_end + 1;
2257
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002258 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002259
2260 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002261 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002262 }
2263
Michel Dänzer0454bea2009-06-15 16:56:07 +02002264 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2265 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2266 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2267 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002268
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002269set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002270 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2271 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002272
2273 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2274 mode->width_mm *= 10;
2275 mode->height_mm *= 10;
2276 }
2277
2278 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2279 mode->width_mm = edid->width_cm * 10;
2280 mode->height_mm = edid->height_cm * 10;
2281 }
2282
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002283 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002284 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002285 drm_mode_set_name(mode);
2286
Dave Airlief453ba02008-11-07 14:05:41 -08002287 return mode;
2288}
2289
Adam Jackson07a5e632009-12-03 17:44:38 -05002290static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002291mode_in_hsync_range(const struct drm_display_mode *mode,
2292 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002293{
2294 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002295
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002296 hmin = t[7];
2297 if (edid->revision >= 4)
2298 hmin += ((t[4] & 0x04) ? 255 : 0);
2299 hmax = t[8];
2300 if (edid->revision >= 4)
2301 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002302 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002303
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002304 return (hsync <= hmax && hsync >= hmin);
2305}
2306
2307static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002308mode_in_vsync_range(const struct drm_display_mode *mode,
2309 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002310{
2311 int vsync, vmin, vmax;
2312
2313 vmin = t[5];
2314 if (edid->revision >= 4)
2315 vmin += ((t[4] & 0x01) ? 255 : 0);
2316 vmax = t[6];
2317 if (edid->revision >= 4)
2318 vmax += ((t[4] & 0x02) ? 255 : 0);
2319 vsync = drm_mode_vrefresh(mode);
2320
2321 return (vsync <= vmax && vsync >= vmin);
2322}
2323
2324static u32
2325range_pixel_clock(struct edid *edid, u8 *t)
2326{
2327 /* unspecified */
2328 if (t[9] == 0 || t[9] == 255)
2329 return 0;
2330
2331 /* 1.4 with CVT support gives us real precision, yay */
2332 if (edid->revision >= 4 && t[10] == 0x04)
2333 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2334
2335 /* 1.3 is pathetic, so fuzz up a bit */
2336 return t[9] * 10000 + 5001;
2337}
2338
Adam Jackson07a5e632009-12-03 17:44:38 -05002339static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002340mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002341 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002342{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002343 u32 max_clock;
2344 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002345
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002346 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002347 return false;
2348
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002349 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002350 return false;
2351
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002352 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002353 if (mode->clock > max_clock)
2354 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002355
2356 /* 1.4 max horizontal check */
2357 if (edid->revision >= 4 && t[10] == 0x04)
2358 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2359 return false;
2360
2361 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2362 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002363
2364 return true;
2365}
2366
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002367static bool valid_inferred_mode(const struct drm_connector *connector,
2368 const struct drm_display_mode *mode)
2369{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002370 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002371 bool ok = false;
2372
2373 list_for_each_entry(m, &connector->probed_modes, head) {
2374 if (mode->hdisplay == m->hdisplay &&
2375 mode->vdisplay == m->vdisplay &&
2376 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2377 return false; /* duplicated */
2378 if (mode->hdisplay <= m->hdisplay &&
2379 mode->vdisplay <= m->vdisplay)
2380 ok = true;
2381 }
2382 return ok;
2383}
2384
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002385static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002386drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002387 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002388{
2389 int i, modes = 0;
2390 struct drm_display_mode *newmode;
2391 struct drm_device *dev = connector->dev;
2392
Thierry Redinga6b21832012-11-23 15:01:42 +01002393 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002394 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2395 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002396 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2397 if (newmode) {
2398 drm_mode_probed_add(connector, newmode);
2399 modes++;
2400 }
2401 }
2402 }
2403
2404 return modes;
2405}
2406
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002407/* fix up 1366x768 mode from 1368x768;
2408 * GFT/CVT can't express 1366 width which isn't dividable by 8
2409 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002410void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002411{
2412 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2413 mode->hdisplay = 1366;
2414 mode->hsync_start--;
2415 mode->hsync_end--;
2416 drm_mode_set_name(mode);
2417 }
2418}
2419
Adam Jacksonb309bd32012-04-13 16:33:40 -04002420static int
2421drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2422 struct detailed_timing *timing)
2423{
2424 int i, modes = 0;
2425 struct drm_display_mode *newmode;
2426 struct drm_device *dev = connector->dev;
2427
Thierry Redinga6b21832012-11-23 15:01:42 +01002428 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002429 const struct minimode *m = &extra_modes[i];
2430 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002431 if (!newmode)
2432 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002433
Takashi Iwai969218f2017-01-17 17:43:29 +01002434 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002435 if (!mode_in_range(newmode, edid, timing) ||
2436 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002437 drm_mode_destroy(dev, newmode);
2438 continue;
2439 }
2440
2441 drm_mode_probed_add(connector, newmode);
2442 modes++;
2443 }
2444
2445 return modes;
2446}
2447
2448static int
2449drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2450 struct detailed_timing *timing)
2451{
2452 int i, modes = 0;
2453 struct drm_display_mode *newmode;
2454 struct drm_device *dev = connector->dev;
2455 bool rb = drm_monitor_supports_rb(edid);
2456
Thierry Redinga6b21832012-11-23 15:01:42 +01002457 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002458 const struct minimode *m = &extra_modes[i];
2459 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002460 if (!newmode)
2461 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002462
Takashi Iwai969218f2017-01-17 17:43:29 +01002463 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002464 if (!mode_in_range(newmode, edid, timing) ||
2465 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002466 drm_mode_destroy(dev, newmode);
2467 continue;
2468 }
2469
2470 drm_mode_probed_add(connector, newmode);
2471 modes++;
2472 }
2473
2474 return modes;
2475}
2476
Adam Jackson13931572010-08-03 14:38:19 -04002477static void
2478do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002479{
Adam Jackson13931572010-08-03 14:38:19 -04002480 struct detailed_mode_closure *closure = c;
2481 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002482 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002483
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002484 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2485 return;
2486
2487 closure->modes += drm_dmt_modes_for_range(closure->connector,
2488 closure->edid,
2489 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002490
2491 if (!version_greater(closure->edid, 1, 1))
2492 return; /* GTF not defined yet */
2493
2494 switch (range->flags) {
2495 case 0x02: /* secondary gtf, XXX could do more */
2496 case 0x00: /* default gtf */
2497 closure->modes += drm_gtf_modes_for_range(closure->connector,
2498 closure->edid,
2499 timing);
2500 break;
2501 case 0x04: /* cvt, only in 1.4+ */
2502 if (!version_greater(closure->edid, 1, 3))
2503 break;
2504
2505 closure->modes += drm_cvt_modes_for_range(closure->connector,
2506 closure->edid,
2507 timing);
2508 break;
2509 case 0x01: /* just the ranges, no formula */
2510 default:
2511 break;
2512 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002513}
2514
Adam Jackson13931572010-08-03 14:38:19 -04002515static int
2516add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2517{
2518 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002519 .connector = connector,
2520 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002521 };
2522
2523 if (version_greater(edid, 1, 0))
2524 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2525 &closure);
2526
2527 return closure.modes;
2528}
2529
Adam Jackson2255be12010-03-29 21:43:22 +00002530static int
2531drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2532{
2533 int i, j, m, modes = 0;
2534 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002535 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002536
2537 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002538 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002539 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002540 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002541 break;
2542 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002543 mode = drm_mode_find_dmt(connector->dev,
2544 est3_modes[m].w,
2545 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002546 est3_modes[m].r,
2547 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002548 if (mode) {
2549 drm_mode_probed_add(connector, mode);
2550 modes++;
2551 }
2552 }
2553 }
2554 }
2555
2556 return modes;
2557}
2558
Adam Jackson13931572010-08-03 14:38:19 -04002559static void
2560do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002561{
Adam Jackson13931572010-08-03 14:38:19 -04002562 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002563 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002564
2565 if (data->type == EDID_DETAIL_EST_TIMINGS)
2566 closure->modes += drm_est3_modes(closure->connector, timing);
2567}
2568
2569/**
2570 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002571 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002572 * @edid: EDID block to scan
2573 *
2574 * Each EDID block contains a bitmap of the supported "established modes" list
2575 * (defined above). Tease them out and add them to the global modes list.
2576 */
2577static int
2578add_established_modes(struct drm_connector *connector, struct edid *edid)
2579{
Adam Jackson9cf00972009-12-03 17:44:36 -05002580 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002581 unsigned long est_bits = edid->established_timings.t1 |
2582 (edid->established_timings.t2 << 8) |
2583 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2584 int i, modes = 0;
2585 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002586 .connector = connector,
2587 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002588 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002589
Adam Jackson13931572010-08-03 14:38:19 -04002590 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2591 if (est_bits & (1<<i)) {
2592 struct drm_display_mode *newmode;
2593 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2594 if (newmode) {
2595 drm_mode_probed_add(connector, newmode);
2596 modes++;
2597 }
2598 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002599 }
2600
Adam Jackson13931572010-08-03 14:38:19 -04002601 if (version_greater(edid, 1, 0))
2602 drm_for_each_detailed_block((u8 *)edid,
2603 do_established_modes, &closure);
2604
2605 return modes + closure.modes;
2606}
2607
2608static void
2609do_standard_modes(struct detailed_timing *timing, void *c)
2610{
2611 struct detailed_mode_closure *closure = c;
2612 struct detailed_non_pixel *data = &timing->data.other_data;
2613 struct drm_connector *connector = closure->connector;
2614 struct edid *edid = closure->edid;
2615
2616 if (data->type == EDID_DETAIL_STD_MODES) {
2617 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002618 for (i = 0; i < 6; i++) {
2619 struct std_timing *std;
2620 struct drm_display_mode *newmode;
2621
2622 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002623 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002624 if (newmode) {
2625 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002626 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002627 }
2628 }
Adam Jackson13931572010-08-03 14:38:19 -04002629 }
2630}
2631
2632/**
2633 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002634 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002635 * @edid: EDID block to scan
2636 *
2637 * Standard modes can be calculated using the appropriate standard (DMT,
2638 * GTF or CVT. Grab them from @edid and add them to the list.
2639 */
2640static int
2641add_standard_modes(struct drm_connector *connector, struct edid *edid)
2642{
2643 int i, modes = 0;
2644 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002645 .connector = connector,
2646 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002647 };
2648
2649 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2650 struct drm_display_mode *newmode;
2651
2652 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002653 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002654 if (newmode) {
2655 drm_mode_probed_add(connector, newmode);
2656 modes++;
2657 }
2658 }
2659
2660 if (version_greater(edid, 1, 0))
2661 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2662 &closure);
2663
2664 /* XXX should also look for standard codes in VTB blocks */
2665
2666 return modes + closure.modes;
2667}
2668
Dave Airlief453ba02008-11-07 14:05:41 -08002669static int drm_cvt_modes(struct drm_connector *connector,
2670 struct detailed_timing *timing)
2671{
2672 int i, j, modes = 0;
2673 struct drm_display_mode *newmode;
2674 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002675 struct cvt_timing *cvt;
2676 const int rates[] = { 60, 85, 75, 60, 50 };
2677 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002678
2679 for (i = 0; i < 4; i++) {
2680 int uninitialized_var(width), height;
2681 cvt = &(timing->data.other_data.data.cvt[i]);
2682
2683 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002684 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002685
2686 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002687 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002688 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002689 width = height * 4 / 3;
2690 break;
2691 case 0x04:
2692 width = height * 16 / 9;
2693 break;
2694 case 0x08:
2695 width = height * 16 / 10;
2696 break;
2697 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002698 width = height * 15 / 9;
2699 break;
2700 }
2701
2702 for (j = 1; j < 5; j++) {
2703 if (cvt->code[2] & (1 << j)) {
2704 newmode = drm_cvt_mode(dev, width, height,
2705 rates[j], j == 0,
2706 false, false);
2707 if (newmode) {
2708 drm_mode_probed_add(connector, newmode);
2709 modes++;
2710 }
2711 }
2712 }
2713 }
2714
2715 return modes;
2716}
2717
Adam Jackson13931572010-08-03 14:38:19 -04002718static void
2719do_cvt_mode(struct detailed_timing *timing, void *c)
2720{
2721 struct detailed_mode_closure *closure = c;
2722 struct detailed_non_pixel *data = &timing->data.other_data;
2723
2724 if (data->type == EDID_DETAIL_CVT_3BYTE)
2725 closure->modes += drm_cvt_modes(closure->connector, timing);
2726}
Adam Jackson9cf00972009-12-03 17:44:36 -05002727
2728static int
Adam Jackson13931572010-08-03 14:38:19 -04002729add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2730{
2731 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002732 .connector = connector,
2733 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002734 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002735
Adam Jackson13931572010-08-03 14:38:19 -04002736 if (version_greater(edid, 1, 2))
2737 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002738
Adam Jackson13931572010-08-03 14:38:19 -04002739 /* XXX should also look for CVT codes in VTB blocks */
2740
2741 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002742}
2743
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002744static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2745
Adam Jackson13931572010-08-03 14:38:19 -04002746static void
2747do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002748{
Adam Jackson13931572010-08-03 14:38:19 -04002749 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002750 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002751
2752 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002753 newmode = drm_mode_detailed(closure->connector->dev,
2754 closure->edid, timing,
2755 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002756 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002757 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002758
Adam Jackson13931572010-08-03 14:38:19 -04002759 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002760 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2761
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002762 /*
2763 * Detailed modes are limited to 10kHz pixel clock resolution,
2764 * so fix up anything that looks like CEA/HDMI mode, but the clock
2765 * is just slightly off.
2766 */
2767 fixup_detailed_cea_mode_clock(newmode);
2768
Adam Jackson13931572010-08-03 14:38:19 -04002769 drm_mode_probed_add(closure->connector, newmode);
2770 closure->modes++;
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002771 closure->preferred = false;
Zhao Yakui882f0212009-08-26 18:20:49 +08002772 }
Ma Ling167f3a02009-03-20 14:09:48 +08002773}
2774
Adam Jackson13931572010-08-03 14:38:19 -04002775/*
2776 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002777 * @connector: attached connector
2778 * @edid: EDID block to scan
2779 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002780 */
Adam Jackson13931572010-08-03 14:38:19 -04002781static int
2782add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2783 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002784{
Adam Jackson13931572010-08-03 14:38:19 -04002785 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002786 .connector = connector,
2787 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002788 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02002789 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002790 };
Dave Airlief453ba02008-11-07 14:05:41 -08002791
Adam Jackson13931572010-08-03 14:38:19 -04002792 if (closure.preferred && !version_greater(edid, 1, 3))
2793 closure.preferred =
2794 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002795
Adam Jackson13931572010-08-03 14:38:19 -04002796 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002797
Adam Jackson13931572010-08-03 14:38:19 -04002798 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002799}
Dave Airlief453ba02008-11-07 14:05:41 -08002800
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002801#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002802#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002803#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002804#define SPEAKER_BLOCK 0x04
Shashank Sharma87563fc2017-07-13 21:03:10 +05302805#define USE_EXTENDED_TAG 0x07
2806#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302807#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2808#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002809#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002810#define EDID_CEA_YCRCB444 (1 << 5)
2811#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002812#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002813
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002814/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002815 * Search EDID for CEA extension block.
2816 */
Keith Packard170178f2017-12-13 00:44:26 -08002817static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002818{
2819 u8 *edid_ext = NULL;
2820 int i;
2821
2822 /* No EDID or EDID extensions */
2823 if (edid == NULL || edid->extensions == 0)
2824 return NULL;
2825
2826 /* Find CEA extension */
2827 for (i = 0; i < edid->extensions; i++) {
2828 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002829 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002830 break;
2831 }
2832
2833 if (i == edid->extensions)
2834 return NULL;
2835
2836 return edid_ext;
2837}
2838
Keith Packard170178f2017-12-13 00:44:26 -08002839static u8 *drm_find_cea_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002840{
2841 return drm_find_edid_extension(edid, CEA_EXT);
2842}
2843
Keith Packard170178f2017-12-13 00:44:26 -08002844static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002845{
2846 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2847}
2848
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002849/*
2850 * Calculate the alternate clock for the CEA mode
2851 * (60Hz vs. 59.94Hz etc.)
2852 */
2853static unsigned int
2854cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2855{
2856 unsigned int clock = cea_mode->clock;
2857
2858 if (cea_mode->vrefresh % 6 != 0)
2859 return clock;
2860
2861 /*
2862 * edid_cea_modes contains the 59.94Hz
2863 * variant for 240 and 480 line modes,
2864 * and the 60Hz variant otherwise.
2865 */
2866 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002867 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002868 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002869 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002870
2871 return clock;
2872}
2873
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002874static bool
2875cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2876{
2877 /*
2878 * For certain VICs the spec allows the vertical
2879 * front porch to vary by one or two lines.
2880 *
2881 * cea_modes[] stores the variant with the shortest
2882 * vertical front porch. We can adjust the mode to
2883 * get the other variants by simply increasing the
2884 * vertical front porch length.
2885 */
2886 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
2887 edid_cea_modes[9].vtotal != 262 ||
2888 edid_cea_modes[12].vtotal != 262 ||
2889 edid_cea_modes[13].vtotal != 262 ||
2890 edid_cea_modes[23].vtotal != 312 ||
2891 edid_cea_modes[24].vtotal != 312 ||
2892 edid_cea_modes[27].vtotal != 312 ||
2893 edid_cea_modes[28].vtotal != 312);
2894
2895 if (((vic == 8 || vic == 9 ||
2896 vic == 12 || vic == 13) && mode->vtotal < 263) ||
2897 ((vic == 23 || vic == 24 ||
2898 vic == 27 || vic == 28) && mode->vtotal < 314)) {
2899 mode->vsync_start++;
2900 mode->vsync_end++;
2901 mode->vtotal++;
2902
2903 return true;
2904 }
2905
2906 return false;
2907}
2908
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002909static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
2910 unsigned int clock_tolerance)
2911{
Jani Nikulad9278b42016-01-08 13:21:51 +02002912 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002913
2914 if (!to_match->clock)
2915 return 0;
2916
Jani Nikulad9278b42016-01-08 13:21:51 +02002917 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002918 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002919 unsigned int clock1, clock2;
2920
2921 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002922 clock1 = cea_mode.clock;
2923 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002924
2925 if (abs(to_match->clock - clock1) > clock_tolerance &&
2926 abs(to_match->clock - clock2) > clock_tolerance)
2927 continue;
2928
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002929 do {
2930 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2931 return vic;
2932 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002933 }
2934
2935 return 0;
2936}
2937
Thierry Reding18316c82012-12-20 15:41:44 +01002938/**
2939 * drm_match_cea_mode - look for a CEA mode matching given mode
2940 * @to_match: display mode
2941 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002942 * 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 +01002943 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002944 */
Thierry Reding18316c82012-12-20 15:41:44 +01002945u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002946{
Jani Nikulad9278b42016-01-08 13:21:51 +02002947 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00002948
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002949 if (!to_match->clock)
2950 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002951
Jani Nikulad9278b42016-01-08 13:21:51 +02002952 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002953 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002954 unsigned int clock1, clock2;
2955
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002956 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002957 clock1 = cea_mode.clock;
2958 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002959
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002960 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
2961 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
2962 continue;
2963
2964 do {
2965 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2966 return vic;
2967 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00002968 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002969
Stephane Marchesina4799032012-11-09 16:21:05 +00002970 return 0;
2971}
2972EXPORT_SYMBOL(drm_match_cea_mode);
2973
Jani Nikulad9278b42016-01-08 13:21:51 +02002974static bool drm_valid_cea_vic(u8 vic)
2975{
2976 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
2977}
2978
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302979/**
2980 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2981 * the input VIC from the CEA mode list
2982 * @video_code: ID given to each of the CEA modes
2983 *
2984 * Returns picture aspect ratio
2985 */
2986enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2987{
Jani Nikulad9278b42016-01-08 13:21:51 +02002988 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302989}
2990EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2991
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002992/*
2993 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2994 * specific block).
2995 *
2996 * It's almost like cea_mode_alternate_clock(), we just need to add an
2997 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2998 * one.
2999 */
3000static unsigned int
3001hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3002{
3003 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3004 return hdmi_mode->clock;
3005
3006 return cea_mode_alternate_clock(hdmi_mode);
3007}
3008
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003009static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3010 unsigned int clock_tolerance)
3011{
Jani Nikulad9278b42016-01-08 13:21:51 +02003012 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003013
3014 if (!to_match->clock)
3015 return 0;
3016
Jani Nikulad9278b42016-01-08 13:21:51 +02003017 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3018 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003019 unsigned int clock1, clock2;
3020
3021 /* Make sure to also match alternate clocks */
3022 clock1 = hdmi_mode->clock;
3023 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3024
3025 if (abs(to_match->clock - clock1) > clock_tolerance &&
3026 abs(to_match->clock - clock2) > clock_tolerance)
3027 continue;
3028
3029 if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003030 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003031 }
3032
3033 return 0;
3034}
3035
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003036/*
3037 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3038 * @to_match: display mode
3039 *
3040 * An HDMI mode is one defined in the HDMI vendor specific block.
3041 *
3042 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3043 */
3044static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3045{
Jani Nikulad9278b42016-01-08 13:21:51 +02003046 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003047
3048 if (!to_match->clock)
3049 return 0;
3050
Jani Nikulad9278b42016-01-08 13:21:51 +02003051 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3052 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003053 unsigned int clock1, clock2;
3054
3055 /* Make sure to also match alternate clocks */
3056 clock1 = hdmi_mode->clock;
3057 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3058
3059 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3060 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01003061 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003062 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003063 }
3064 return 0;
3065}
3066
Jani Nikulad9278b42016-01-08 13:21:51 +02003067static bool drm_valid_hdmi_vic(u8 vic)
3068{
3069 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3070}
3071
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003072static int
3073add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3074{
3075 struct drm_device *dev = connector->dev;
3076 struct drm_display_mode *mode, *tmp;
3077 LIST_HEAD(list);
3078 int modes = 0;
3079
3080 /* Don't add CEA modes if the CEA extension block is missing */
3081 if (!drm_find_cea_extension(edid))
3082 return 0;
3083
3084 /*
3085 * Go through all probed modes and create a new mode
3086 * with the alternate clock for certain CEA modes.
3087 */
3088 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003089 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003090 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003091 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003092 unsigned int clock1, clock2;
3093
Jani Nikulad9278b42016-01-08 13:21:51 +02003094 if (drm_valid_cea_vic(vic)) {
3095 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003096 clock2 = cea_mode_alternate_clock(cea_mode);
3097 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003098 vic = drm_match_hdmi_mode(mode);
3099 if (drm_valid_hdmi_vic(vic)) {
3100 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003101 clock2 = hdmi_mode_alternate_clock(cea_mode);
3102 }
3103 }
3104
3105 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003106 continue;
3107
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003108 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003109
3110 if (clock1 == clock2)
3111 continue;
3112
3113 if (mode->clock != clock1 && mode->clock != clock2)
3114 continue;
3115
3116 newmode = drm_mode_duplicate(dev, cea_mode);
3117 if (!newmode)
3118 continue;
3119
Damien Lespiau27130212013-09-25 16:45:28 +01003120 /* Carry over the stereo flags */
3121 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3122
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003123 /*
3124 * The current mode could be either variant. Make
3125 * sure to pick the "other" clock for the new mode.
3126 */
3127 if (mode->clock != clock1)
3128 newmode->clock = clock1;
3129 else
3130 newmode->clock = clock2;
3131
3132 list_add_tail(&newmode->head, &list);
3133 }
3134
3135 list_for_each_entry_safe(mode, tmp, &list, head) {
3136 list_del(&mode->head);
3137 drm_mode_probed_add(connector, mode);
3138 modes++;
3139 }
3140
3141 return modes;
3142}
Stephane Marchesina4799032012-11-09 16:21:05 +00003143
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303144static u8 svd_to_vic(u8 svd)
3145{
3146 /* 0-6 bit vic, 7th bit native mode indicator */
3147 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3148 return svd & 127;
3149
3150 return svd;
3151}
3152
Thomas Woodaff04ac2013-11-29 15:33:27 +00003153static struct drm_display_mode *
3154drm_display_mode_from_vic_index(struct drm_connector *connector,
3155 const u8 *video_db, u8 video_len,
3156 u8 video_index)
3157{
3158 struct drm_device *dev = connector->dev;
3159 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003160 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003161
3162 if (video_db == NULL || video_index >= video_len)
3163 return NULL;
3164
3165 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303166 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003167 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003168 return NULL;
3169
Jani Nikulad9278b42016-01-08 13:21:51 +02003170 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003171 if (!newmode)
3172 return NULL;
3173
Thomas Woodaff04ac2013-11-29 15:33:27 +00003174 newmode->vrefresh = 0;
3175
3176 return newmode;
3177}
3178
Shashank Sharma832d4f22017-07-14 16:03:46 +05303179/*
3180 * do_y420vdb_modes - Parse YCBCR 420 only modes
3181 * @connector: connector corresponding to the HDMI sink
3182 * @svds: start of the data block of CEA YCBCR 420 VDB
3183 * @len: length of the CEA YCBCR 420 VDB
3184 *
3185 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3186 * which contains modes which can be supported in YCBCR 420
3187 * output format only.
3188 */
3189static int do_y420vdb_modes(struct drm_connector *connector,
3190 const u8 *svds, u8 svds_len)
3191{
3192 int modes = 0, i;
3193 struct drm_device *dev = connector->dev;
3194 struct drm_display_info *info = &connector->display_info;
3195 struct drm_hdmi_info *hdmi = &info->hdmi;
3196
3197 for (i = 0; i < svds_len; i++) {
3198 u8 vic = svd_to_vic(svds[i]);
3199 struct drm_display_mode *newmode;
3200
3201 if (!drm_valid_cea_vic(vic))
3202 continue;
3203
3204 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3205 if (!newmode)
3206 break;
3207 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3208 drm_mode_probed_add(connector, newmode);
3209 modes++;
3210 }
3211
3212 if (modes > 0)
3213 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3214 return modes;
3215}
3216
3217/*
3218 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3219 * @connector: connector corresponding to the HDMI sink
3220 * @vic: CEA vic for the video mode to be added in the map
3221 *
3222 * Makes an entry for a videomode in the YCBCR 420 bitmap
3223 */
3224static void
3225drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3226{
3227 u8 vic = svd_to_vic(svd);
3228 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3229
3230 if (!drm_valid_cea_vic(vic))
3231 return;
3232
3233 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3234}
3235
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003236static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003237do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003238{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003239 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303240 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003241
Thomas Woodaff04ac2013-11-29 15:33:27 +00003242 for (i = 0; i < len; i++) {
3243 struct drm_display_mode *mode;
3244 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3245 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303246 /*
3247 * YCBCR420 capability block contains a bitmap which
3248 * gives the index of CEA modes from CEA VDB, which
3249 * can support YCBCR 420 sampling output also (apart
3250 * from RGB/YCBCR444 etc).
3251 * For example, if the bit 0 in bitmap is set,
3252 * first mode in VDB can support YCBCR420 output too.
3253 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3254 */
3255 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3256 drm_add_cmdb_modes(connector, db[i]);
3257
Thomas Woodaff04ac2013-11-29 15:33:27 +00003258 drm_mode_probed_add(connector, mode);
3259 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003260 }
3261 }
3262
3263 return modes;
3264}
3265
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003266struct stereo_mandatory_mode {
3267 int width, height, vrefresh;
3268 unsigned int flags;
3269};
3270
3271static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003272 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3273 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003274 { 1920, 1080, 50,
3275 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3276 { 1920, 1080, 60,
3277 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003278 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3279 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3280 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3281 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003282};
3283
3284static bool
3285stereo_match_mandatory(const struct drm_display_mode *mode,
3286 const struct stereo_mandatory_mode *stereo_mode)
3287{
3288 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3289
3290 return mode->hdisplay == stereo_mode->width &&
3291 mode->vdisplay == stereo_mode->height &&
3292 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3293 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3294}
3295
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003296static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3297{
3298 struct drm_device *dev = connector->dev;
3299 const struct drm_display_mode *mode;
3300 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003301 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003302
3303 INIT_LIST_HEAD(&stereo_modes);
3304
3305 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003306 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3307 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003308 struct drm_display_mode *new_mode;
3309
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003310 if (!stereo_match_mandatory(mode,
3311 &stereo_mandatory_modes[i]))
3312 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003313
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003314 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003315 new_mode = drm_mode_duplicate(dev, mode);
3316 if (!new_mode)
3317 continue;
3318
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003319 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003320 list_add_tail(&new_mode->head, &stereo_modes);
3321 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003322 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003323 }
3324
3325 list_splice_tail(&stereo_modes, &connector->probed_modes);
3326
3327 return modes;
3328}
3329
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003330static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3331{
3332 struct drm_device *dev = connector->dev;
3333 struct drm_display_mode *newmode;
3334
Jani Nikulad9278b42016-01-08 13:21:51 +02003335 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003336 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3337 return 0;
3338 }
3339
3340 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3341 if (!newmode)
3342 return 0;
3343
3344 drm_mode_probed_add(connector, newmode);
3345
3346 return 1;
3347}
3348
Thomas Woodfbf46022013-10-16 15:58:50 +01003349static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3350 const u8 *video_db, u8 video_len, u8 video_index)
3351{
Thomas Woodfbf46022013-10-16 15:58:50 +01003352 struct drm_display_mode *newmode;
3353 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003354
3355 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003356 newmode = drm_display_mode_from_vic_index(connector, video_db,
3357 video_len,
3358 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003359 if (newmode) {
3360 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3361 drm_mode_probed_add(connector, newmode);
3362 modes++;
3363 }
3364 }
3365 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003366 newmode = drm_display_mode_from_vic_index(connector, video_db,
3367 video_len,
3368 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003369 if (newmode) {
3370 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3371 drm_mode_probed_add(connector, newmode);
3372 modes++;
3373 }
3374 }
3375 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003376 newmode = drm_display_mode_from_vic_index(connector, video_db,
3377 video_len,
3378 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003379 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003380 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003381 drm_mode_probed_add(connector, newmode);
3382 modes++;
3383 }
3384 }
3385
3386 return modes;
3387}
3388
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003389/*
3390 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3391 * @connector: connector corresponding to the HDMI sink
3392 * @db: start of the CEA vendor specific block
3393 * @len: length of the CEA block payload, ie. one can access up to db[len]
3394 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003395 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3396 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003397 */
3398static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003399do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3400 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003401{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003402 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003403 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003404 u8 vic_len, hdmi_3d_len = 0;
3405 u16 mask;
3406 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003407
3408 if (len < 8)
3409 goto out;
3410
3411 /* no HDMI_Video_Present */
3412 if (!(db[8] & (1 << 5)))
3413 goto out;
3414
3415 /* Latency_Fields_Present */
3416 if (db[8] & (1 << 7))
3417 offset += 2;
3418
3419 /* I_Latency_Fields_Present */
3420 if (db[8] & (1 << 6))
3421 offset += 2;
3422
3423 /* the declared length is not long enough for the 2 first bytes
3424 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003425 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003426 goto out;
3427
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003428 /* 3D_Present */
3429 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003430 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003431 modes += add_hdmi_mandatory_stereo_modes(connector);
3432
Thomas Woodfbf46022013-10-16 15:58:50 +01003433 /* 3D_Multi_present */
3434 multi_present = (db[8 + offset] & 0x60) >> 5;
3435 }
3436
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003437 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003438 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003439 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003440
3441 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003442 u8 vic;
3443
3444 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003445 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003446 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003447 offset += 1 + vic_len;
3448
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003449 if (multi_present == 1)
3450 multi_len = 2;
3451 else if (multi_present == 2)
3452 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003453 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003454 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003455
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003456 if (len < (8 + offset + hdmi_3d_len - 1))
3457 goto out;
3458
3459 if (hdmi_3d_len < multi_len)
3460 goto out;
3461
3462 if (multi_present == 1 || multi_present == 2) {
3463 /* 3D_Structure_ALL */
3464 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3465
3466 /* check if 3D_MASK is present */
3467 if (multi_present == 2)
3468 mask = (db[10 + offset] << 8) | db[11 + offset];
3469 else
3470 mask = 0xffff;
3471
3472 for (i = 0; i < 16; i++) {
3473 if (mask & (1 << i))
3474 modes += add_3d_struct_modes(connector,
3475 structure_all,
3476 video_db,
3477 video_len, i);
3478 }
3479 }
3480
3481 offset += multi_len;
3482
3483 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3484 int vic_index;
3485 struct drm_display_mode *newmode = NULL;
3486 unsigned int newflag = 0;
3487 bool detail_present;
3488
3489 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3490
3491 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3492 break;
3493
3494 /* 2D_VIC_order_X */
3495 vic_index = db[8 + offset + i] >> 4;
3496
3497 /* 3D_Structure_X */
3498 switch (db[8 + offset + i] & 0x0f) {
3499 case 0:
3500 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3501 break;
3502 case 6:
3503 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3504 break;
3505 case 8:
3506 /* 3D_Detail_X */
3507 if ((db[9 + offset + i] >> 4) == 1)
3508 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3509 break;
3510 }
3511
3512 if (newflag != 0) {
3513 newmode = drm_display_mode_from_vic_index(connector,
3514 video_db,
3515 video_len,
3516 vic_index);
3517
3518 if (newmode) {
3519 newmode->flags |= newflag;
3520 drm_mode_probed_add(connector, newmode);
3521 modes++;
3522 }
3523 }
3524
3525 if (detail_present)
3526 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003527 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003528
3529out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003530 if (modes > 0)
3531 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003532 return modes;
3533}
3534
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003535static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003536cea_db_payload_len(const u8 *db)
3537{
3538 return db[0] & 0x1f;
3539}
3540
3541static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303542cea_db_extended_tag(const u8 *db)
3543{
3544 return db[1];
3545}
3546
3547static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003548cea_db_tag(const u8 *db)
3549{
3550 return db[0] >> 5;
3551}
3552
3553static int
3554cea_revision(const u8 *cea)
3555{
3556 return cea[1];
3557}
3558
3559static int
3560cea_db_offsets(const u8 *cea, int *start, int *end)
3561{
3562 /* Data block offset in CEA extension block */
3563 *start = 4;
3564 *end = cea[2];
3565 if (*end == 0)
3566 *end = 127;
3567 if (*end < 4 || *end > 127)
3568 return -ERANGE;
3569 return 0;
3570}
3571
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003572static bool cea_db_is_hdmi_vsdb(const u8 *db)
3573{
3574 int hdmi_id;
3575
3576 if (cea_db_tag(db) != VENDOR_BLOCK)
3577 return false;
3578
3579 if (cea_db_payload_len(db) < 5)
3580 return false;
3581
3582 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3583
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003584 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003585}
3586
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303587static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3588{
3589 unsigned int oui;
3590
3591 if (cea_db_tag(db) != VENDOR_BLOCK)
3592 return false;
3593
3594 if (cea_db_payload_len(db) < 7)
3595 return false;
3596
3597 oui = db[3] << 16 | db[2] << 8 | db[1];
3598
3599 return oui == HDMI_FORUM_IEEE_OUI;
3600}
3601
Shashank Sharma832d4f22017-07-14 16:03:46 +05303602static bool cea_db_is_y420cmdb(const u8 *db)
3603{
3604 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3605 return false;
3606
3607 if (!cea_db_payload_len(db))
3608 return false;
3609
3610 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3611 return false;
3612
3613 return true;
3614}
3615
3616static bool cea_db_is_y420vdb(const u8 *db)
3617{
3618 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3619 return false;
3620
3621 if (!cea_db_payload_len(db))
3622 return false;
3623
3624 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3625 return false;
3626
3627 return true;
3628}
3629
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003630#define for_each_cea_db(cea, i, start, end) \
3631 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3632
Shashank Sharma832d4f22017-07-14 16:03:46 +05303633static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3634 const u8 *db)
3635{
3636 struct drm_display_info *info = &connector->display_info;
3637 struct drm_hdmi_info *hdmi = &info->hdmi;
3638 u8 map_len = cea_db_payload_len(db) - 1;
3639 u8 count;
3640 u64 map = 0;
3641
3642 if (map_len == 0) {
3643 /* All CEA modes support ycbcr420 sampling also.*/
3644 hdmi->y420_cmdb_map = U64_MAX;
3645 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3646 return;
3647 }
3648
3649 /*
3650 * This map indicates which of the existing CEA block modes
3651 * from VDB can support YCBCR420 output too. So if bit=0 is
3652 * set, first mode from VDB can support YCBCR420 output too.
3653 * We will parse and keep this map, before parsing VDB itself
3654 * to avoid going through the same block again and again.
3655 *
3656 * Spec is not clear about max possible size of this block.
3657 * Clamping max bitmap block size at 8 bytes. Every byte can
3658 * address 8 CEA modes, in this way this map can address
3659 * 8*8 = first 64 SVDs.
3660 */
3661 if (WARN_ON_ONCE(map_len > 8))
3662 map_len = 8;
3663
3664 for (count = 0; count < map_len; count++)
3665 map |= (u64)db[2 + count] << (8 * count);
3666
3667 if (map)
3668 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3669
3670 hdmi->y420_cmdb_map = map;
3671}
3672
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003673static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003674add_cea_modes(struct drm_connector *connector, struct edid *edid)
3675{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003676 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003677 const u8 *db, *hdmi = NULL, *video = NULL;
3678 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003679 int modes = 0;
3680
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003681 if (cea && cea_revision(cea) >= 3) {
3682 int i, start, end;
3683
3684 if (cea_db_offsets(cea, &start, &end))
3685 return 0;
3686
3687 for_each_cea_db(cea, i, start, end) {
3688 db = &cea[i];
3689 dbl = cea_db_payload_len(db);
3690
Thomas Woodfbf46022013-10-16 15:58:50 +01003691 if (cea_db_tag(db) == VIDEO_BLOCK) {
3692 video = db + 1;
3693 video_len = dbl;
3694 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303695 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003696 hdmi = db;
3697 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303698 } else if (cea_db_is_y420vdb(db)) {
3699 const u8 *vdb420 = &db[2];
3700
3701 /* Add 4:2:0(only) modes present in EDID */
3702 modes += do_y420vdb_modes(connector,
3703 vdb420,
3704 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003705 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003706 }
3707 }
3708
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003709 /*
3710 * We parse the HDMI VSDB after having added the cea modes as we will
3711 * be patching their flags when the sink supports stereo 3D.
3712 */
3713 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003714 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3715 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003716
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003717 return modes;
3718}
3719
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003720static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3721{
3722 const struct drm_display_mode *cea_mode;
3723 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003724 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003725 const char *type;
3726
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003727 /*
3728 * allow 5kHz clock difference either way to account for
3729 * the 10kHz clock resolution limit of detailed timings.
3730 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003731 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3732 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003733 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003734 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003735 clock1 = cea_mode->clock;
3736 clock2 = cea_mode_alternate_clock(cea_mode);
3737 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003738 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3739 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003740 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003741 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003742 clock1 = cea_mode->clock;
3743 clock2 = hdmi_mode_alternate_clock(cea_mode);
3744 } else {
3745 return;
3746 }
3747 }
3748
3749 /* pick whichever is closest */
3750 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3751 clock = clock1;
3752 else
3753 clock = clock2;
3754
3755 if (mode->clock == clock)
3756 return;
3757
3758 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003759 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003760 mode->clock = clock;
3761}
3762
Wu Fengguang76adaa342011-09-05 14:23:20 +08003763static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003764drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003765{
Ville Syrjälä85040722012-08-16 14:55:05 +00003766 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003767
Jani Nikulaf7da77852017-11-01 16:20:57 +02003768 if (len >= 6 && (db[6] & (1 << 7)))
3769 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00003770 if (len >= 8) {
3771 connector->latency_present[0] = db[8] >> 7;
3772 connector->latency_present[1] = (db[8] >> 6) & 1;
3773 }
3774 if (len >= 9)
3775 connector->video_latency[0] = db[9];
3776 if (len >= 10)
3777 connector->audio_latency[0] = db[10];
3778 if (len >= 11)
3779 connector->video_latency[1] = db[11];
3780 if (len >= 12)
3781 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003782
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003783 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3784 "video latency %d %d, "
3785 "audio latency %d %d\n",
3786 connector->latency_present[0],
3787 connector->latency_present[1],
3788 connector->video_latency[0],
3789 connector->video_latency[1],
3790 connector->audio_latency[0],
3791 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003792}
3793
3794static void
3795monitor_name(struct detailed_timing *t, void *data)
3796{
3797 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3798 *(u8 **)data = t->data.other_data.data.str.str;
3799}
3800
Jim Bride59f7c0f2016-04-14 10:18:35 -07003801static int get_monitor_name(struct edid *edid, char name[13])
3802{
3803 char *edid_name = NULL;
3804 int mnl;
3805
3806 if (!edid || !name)
3807 return 0;
3808
3809 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
3810 for (mnl = 0; edid_name && mnl < 13; mnl++) {
3811 if (edid_name[mnl] == 0x0a)
3812 break;
3813
3814 name[mnl] = edid_name[mnl];
3815 }
3816
3817 return mnl;
3818}
3819
3820/**
3821 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3822 * @edid: monitor EDID information
3823 * @name: pointer to a character array to hold the name of the monitor
3824 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3825 *
3826 */
3827void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
3828{
3829 int name_length;
3830 char buf[13];
3831
3832 if (bufsize <= 0)
3833 return;
3834
3835 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
3836 memcpy(name, buf, name_length);
3837 name[name_length] = '\0';
3838}
3839EXPORT_SYMBOL(drm_edid_get_monitor_name);
3840
Jani Nikula42750d32017-11-01 16:21:00 +02003841static void clear_eld(struct drm_connector *connector)
3842{
3843 memset(connector->eld, 0, sizeof(connector->eld));
3844
3845 connector->latency_present[0] = false;
3846 connector->latency_present[1] = false;
3847 connector->video_latency[0] = 0;
3848 connector->audio_latency[0] = 0;
3849 connector->video_latency[1] = 0;
3850 connector->audio_latency[1] = 0;
3851}
3852
Jani Nikula79436a12017-11-01 16:21:03 +02003853/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08003854 * drm_edid_to_eld - build ELD from EDID
3855 * @connector: connector corresponding to the HDMI/DP sink
3856 * @edid: EDID to parse
3857 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003858 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02003859 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003860 */
Jani Nikula79436a12017-11-01 16:21:03 +02003861static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003862{
3863 uint8_t *eld = connector->eld;
3864 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003865 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02003866 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003867 int mnl;
3868 int dbl;
3869
Jani Nikula42750d32017-11-01 16:21:00 +02003870 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03003871
Jani Nikulae9bd0b82017-02-17 17:20:52 +02003872 if (!edid)
3873 return;
3874
Wu Fengguang76adaa342011-09-05 14:23:20 +08003875 cea = drm_find_cea_extension(edid);
3876 if (!cea) {
3877 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3878 return;
3879 }
3880
Jani Nikulaf7da77852017-11-01 16:20:57 +02003881 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
3882 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07003883
Jani Nikulaf7da77852017-11-01 16:20:57 +02003884 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
3885 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003886
Jani Nikulaf7da77852017-11-01 16:20:57 +02003887 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003888
Jani Nikulaf7da77852017-11-01 16:20:57 +02003889 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
3890 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
3891 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
3892 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003893
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003894 if (cea_revision(cea) >= 3) {
3895 int i, start, end;
3896
3897 if (cea_db_offsets(cea, &start, &end)) {
3898 start = 0;
3899 end = 0;
3900 }
3901
3902 for_each_cea_db(cea, i, start, end) {
3903 db = &cea[i];
3904 dbl = cea_db_payload_len(db);
3905
3906 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02003907 int sad_count;
3908
Christian Schmidta0ab7342011-12-19 20:03:38 +01003909 case AUDIO_BLOCK:
3910 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02003911 sad_count = min(dbl / 3, 15 - total_sad_count);
3912 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003913 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02003914 &db[1], sad_count * 3);
3915 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01003916 break;
3917 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003918 /* Speaker Allocation Data Block */
3919 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02003920 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003921 break;
3922 case VENDOR_BLOCK:
3923 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003924 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003925 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003926 break;
3927 default:
3928 break;
3929 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003930 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003931 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02003932 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003933
Jani Nikula1d1c3662017-11-01 16:20:58 +02003934 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3935 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3936 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
3937 else
3938 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003939
Jani Nikula938fd8a2014-10-28 16:20:48 +02003940 eld[DRM_ELD_BASELINE_ELD_LEN] =
3941 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3942
3943 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02003944 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003945}
Wu Fengguang76adaa342011-09-05 14:23:20 +08003946
3947/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003948 * drm_edid_to_sad - extracts SADs from EDID
3949 * @edid: EDID to parse
3950 * @sads: pointer that will be set to the extracted SADs
3951 *
3952 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003953 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003954 * Note: The returned pointer needs to be freed using kfree().
3955 *
3956 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003957 */
3958int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3959{
3960 int count = 0;
3961 int i, start, end, dbl;
3962 u8 *cea;
3963
3964 cea = drm_find_cea_extension(edid);
3965 if (!cea) {
3966 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3967 return -ENOENT;
3968 }
3969
3970 if (cea_revision(cea) < 3) {
3971 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3972 return -ENOTSUPP;
3973 }
3974
3975 if (cea_db_offsets(cea, &start, &end)) {
3976 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3977 return -EPROTO;
3978 }
3979
3980 for_each_cea_db(cea, i, start, end) {
3981 u8 *db = &cea[i];
3982
3983 if (cea_db_tag(db) == AUDIO_BLOCK) {
3984 int j;
3985 dbl = cea_db_payload_len(db);
3986
3987 count = dbl / 3; /* SAD is 3B */
3988 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3989 if (!*sads)
3990 return -ENOMEM;
3991 for (j = 0; j < count; j++) {
3992 u8 *sad = &db[1 + j * 3];
3993
3994 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3995 (*sads)[j].channels = sad[0] & 0x7;
3996 (*sads)[j].freq = sad[1] & 0x7F;
3997 (*sads)[j].byte2 = sad[2];
3998 }
3999 break;
4000 }
4001 }
4002
4003 return count;
4004}
4005EXPORT_SYMBOL(drm_edid_to_sad);
4006
4007/**
Alex Deucherd105f472013-07-25 15:55:32 -04004008 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4009 * @edid: EDID to parse
4010 * @sadb: pointer to the speaker block
4011 *
4012 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004013 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004014 * Note: The returned pointer needs to be freed using kfree().
4015 *
4016 * Return: The number of found Speaker Allocation Blocks or negative number on
4017 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004018 */
4019int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4020{
4021 int count = 0;
4022 int i, start, end, dbl;
4023 const u8 *cea;
4024
4025 cea = drm_find_cea_extension(edid);
4026 if (!cea) {
4027 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4028 return -ENOENT;
4029 }
4030
4031 if (cea_revision(cea) < 3) {
4032 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4033 return -ENOTSUPP;
4034 }
4035
4036 if (cea_db_offsets(cea, &start, &end)) {
4037 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4038 return -EPROTO;
4039 }
4040
4041 for_each_cea_db(cea, i, start, end) {
4042 const u8 *db = &cea[i];
4043
4044 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4045 dbl = cea_db_payload_len(db);
4046
4047 /* Speaker Allocation Data Block */
4048 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004049 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004050 if (!*sadb)
4051 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004052 count = dbl;
4053 break;
4054 }
4055 }
4056 }
4057
4058 return count;
4059}
4060EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4061
4062/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004063 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004064 * @connector: connector associated with the HDMI/DP sink
4065 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004066 *
4067 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4068 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004069 */
4070int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004071 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004072{
4073 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4074 int a, v;
4075
4076 if (!connector->latency_present[0])
4077 return 0;
4078 if (!connector->latency_present[1])
4079 i = 0;
4080
4081 a = connector->audio_latency[i];
4082 v = connector->video_latency[i];
4083
4084 /*
4085 * HDMI/DP sink doesn't support audio or video?
4086 */
4087 if (a == 255 || v == 255)
4088 return 0;
4089
4090 /*
4091 * Convert raw EDID values to millisecond.
4092 * Treat unknown latency as 0ms.
4093 */
4094 if (a)
4095 a = min(2 * (a - 1), 500);
4096 if (v)
4097 v = min(2 * (v - 1), 500);
4098
4099 return max(v - a, 0);
4100}
4101EXPORT_SYMBOL(drm_av_sync_delay);
4102
4103/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004104 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004105 * @edid: monitor EDID information
4106 *
4107 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004108 *
4109 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004110 */
4111bool drm_detect_hdmi_monitor(struct edid *edid)
4112{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004113 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004114 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004115 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004116
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004117 edid_ext = drm_find_cea_extension(edid);
4118 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004119 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004120
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004121 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004122 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004123
4124 /*
4125 * Because HDMI identifier is in Vendor Specific Block,
4126 * search it from all data blocks of CEA extension.
4127 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004128 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004129 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4130 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004131 }
4132
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004133 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004134}
4135EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4136
Dave Airlief453ba02008-11-07 14:05:41 -08004137/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004138 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004139 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004140 *
4141 * Monitor should have CEA extension block.
4142 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4143 * audio' only. If there is any audio extension block and supported
4144 * audio format, assume at least 'basic audio' support, even if 'basic
4145 * audio' is not defined in EDID.
4146 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004147 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004148 */
4149bool drm_detect_monitor_audio(struct edid *edid)
4150{
4151 u8 *edid_ext;
4152 int i, j;
4153 bool has_audio = false;
4154 int start_offset, end_offset;
4155
4156 edid_ext = drm_find_cea_extension(edid);
4157 if (!edid_ext)
4158 goto end;
4159
4160 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4161
4162 if (has_audio) {
4163 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4164 goto end;
4165 }
4166
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004167 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4168 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004169
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004170 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4171 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004172 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004173 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004174 DRM_DEBUG_KMS("CEA audio format %d\n",
4175 (edid_ext[i + j] >> 3) & 0xf);
4176 goto end;
4177 }
4178 }
4179end:
4180 return has_audio;
4181}
4182EXPORT_SYMBOL(drm_detect_monitor_audio);
4183
4184/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004185 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01004186 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004187 *
4188 * Check whether the monitor reports the RGB quantization range selection
4189 * as supported. The AVI infoframe can then be used to inform the monitor
4190 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004191 *
4192 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004193 */
4194bool drm_rgb_quant_range_selectable(struct edid *edid)
4195{
4196 u8 *edid_ext;
4197 int i, start, end;
4198
4199 edid_ext = drm_find_cea_extension(edid);
4200 if (!edid_ext)
4201 return false;
4202
4203 if (cea_db_offsets(edid_ext, &start, &end))
4204 return false;
4205
4206 for_each_cea_db(edid_ext, i, start, end) {
Shashank Sharma87563fc2017-07-13 21:03:10 +05304207 if (cea_db_tag(&edid_ext[i]) == USE_EXTENDED_TAG &&
4208 cea_db_payload_len(&edid_ext[i]) == 2 &&
4209 cea_db_extended_tag(&edid_ext[i]) ==
4210 EXT_VIDEO_CAPABILITY_BLOCK) {
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004211 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
4212 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
4213 }
4214 }
4215
4216 return false;
4217}
4218EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
4219
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004220/**
4221 * drm_default_rgb_quant_range - default RGB quantization range
4222 * @mode: display mode
4223 *
4224 * Determine the default RGB quantization range for the mode,
4225 * as specified in CEA-861.
4226 *
4227 * Return: The default RGB quantization range for the mode
4228 */
4229enum hdmi_quantization_range
4230drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4231{
4232 /* All CEA modes other than VIC 1 use limited quantization range. */
4233 return drm_match_cea_mode(mode) > 1 ?
4234 HDMI_QUANTIZATION_RANGE_LIMITED :
4235 HDMI_QUANTIZATION_RANGE_FULL;
4236}
4237EXPORT_SYMBOL(drm_default_rgb_quant_range);
4238
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304239static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4240 const u8 *db)
4241{
4242 u8 dc_mask;
4243 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4244
4245 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
4246 hdmi->y420_dc_modes |= dc_mask;
4247}
4248
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304249static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4250 const u8 *hf_vsdb)
4251{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304252 struct drm_display_info *display = &connector->display_info;
4253 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304254
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004255 display->has_hdmi_infoframe = true;
4256
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304257 if (hf_vsdb[6] & 0x80) {
4258 hdmi->scdc.supported = true;
4259 if (hf_vsdb[6] & 0x40)
4260 hdmi->scdc.read_request = true;
4261 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304262
4263 /*
4264 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4265 * And as per the spec, three factors confirm this:
4266 * * Availability of a HF-VSDB block in EDID (check)
4267 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4268 * * SCDC support available (let's check)
4269 * Lets check it out.
4270 */
4271
4272 if (hf_vsdb[5]) {
4273 /* max clock is 5000 KHz times block value */
4274 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4275 struct drm_scdc *scdc = &hdmi->scdc;
4276
4277 if (max_tmds_clock > 340000) {
4278 display->max_tmds_clock = max_tmds_clock;
4279 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4280 display->max_tmds_clock);
4281 }
4282
4283 if (scdc->supported) {
4284 scdc->scrambling.supported = true;
4285
4286 /* Few sinks support scrambling for cloks < 340M */
4287 if ((hf_vsdb[6] & 0x8))
4288 scdc->scrambling.low_rates = true;
4289 }
4290 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304291
4292 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304293}
4294
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004295static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4296 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004297{
Ville Syrjälä18267502016-09-28 16:51:38 +03004298 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004299 unsigned int dc_bpc = 0;
4300
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004301 /* HDMI supports at least 8 bpc */
4302 info->bpc = 8;
4303
4304 if (cea_db_payload_len(hdmi) < 6)
4305 return;
4306
4307 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4308 dc_bpc = 10;
4309 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4310 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4311 connector->name);
4312 }
4313
4314 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4315 dc_bpc = 12;
4316 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4317 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4318 connector->name);
4319 }
4320
4321 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4322 dc_bpc = 16;
4323 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4324 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4325 connector->name);
4326 }
4327
4328 if (dc_bpc == 0) {
4329 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4330 connector->name);
4331 return;
4332 }
4333
4334 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4335 connector->name, dc_bpc);
4336 info->bpc = dc_bpc;
4337
4338 /*
4339 * Deep color support mandates RGB444 support for all video
4340 * modes and forbids YCRCB422 support for all video modes per
4341 * HDMI 1.3 spec.
4342 */
4343 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4344
4345 /* YCRCB444 is optional according to spec. */
4346 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4347 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4348 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4349 connector->name);
4350 }
4351
4352 /*
4353 * Spec says that if any deep color mode is supported at all,
4354 * then deep color 36 bit must be supported.
4355 */
4356 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4357 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4358 connector->name);
4359 }
4360}
4361
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004362static void
4363drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4364{
4365 struct drm_display_info *info = &connector->display_info;
4366 u8 len = cea_db_payload_len(db);
4367
4368 if (len >= 6)
4369 info->dvi_dual = db[6] & 1;
4370 if (len >= 7)
4371 info->max_tmds_clock = db[7] * 5000;
4372
4373 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4374 "max TMDS clock %d kHz\n",
4375 info->dvi_dual,
4376 info->max_tmds_clock);
4377
4378 drm_parse_hdmi_deep_color_info(connector, db);
4379}
4380
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004381static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004382 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004383{
4384 struct drm_display_info *info = &connector->display_info;
4385 const u8 *edid_ext;
4386 int i, start, end;
4387
Mario Kleinerd0c94692014-03-27 19:59:39 +01004388 edid_ext = drm_find_cea_extension(edid);
4389 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004390 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004391
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004392 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004393
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004394 /* The existence of a CEA block should imply RGB support */
4395 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4396 if (edid_ext[3] & EDID_CEA_YCRCB444)
4397 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4398 if (edid_ext[3] & EDID_CEA_YCRCB422)
4399 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004400
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004401 if (cea_db_offsets(edid_ext, &start, &end))
4402 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004403
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004404 for_each_cea_db(edid_ext, i, start, end) {
4405 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004406
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004407 if (cea_db_is_hdmi_vsdb(db))
4408 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304409 if (cea_db_is_hdmi_forum_vsdb(db))
4410 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304411 if (cea_db_is_y420cmdb(db))
4412 drm_parse_y420cmdb_bitmap(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004413 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004414}
4415
Keith Packard170178f2017-12-13 00:44:26 -08004416/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4417 * all of the values which would have been set from EDID
4418 */
4419void
4420drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004421{
Ville Syrjälä18267502016-09-28 16:51:38 +03004422 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004423
Keith Packard170178f2017-12-13 00:44:26 -08004424 info->width_mm = 0;
4425 info->height_mm = 0;
4426
4427 info->bpc = 0;
4428 info->color_formats = 0;
4429 info->cea_rev = 0;
4430 info->max_tmds_clock = 0;
4431 info->dvi_dual = false;
4432 info->has_hdmi_infoframe = false;
4433
4434 info->non_desktop = 0;
4435}
4436EXPORT_SYMBOL_GPL(drm_reset_display_info);
4437
4438u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4439{
4440 struct drm_display_info *info = &connector->display_info;
4441
4442 u32 quirks = edid_get_quirks(edid);
4443
Jesse Barnes3b112282011-04-15 12:49:23 -07004444 info->width_mm = edid->width_cm * 10;
4445 info->height_mm = edid->height_cm * 10;
4446
4447 /* driver figures it out in this case */
4448 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004449 info->color_formats = 0;
Ville Syrjälä011acce2016-09-28 16:51:40 +03004450 info->cea_rev = 0;
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004451 info->max_tmds_clock = 0;
4452 info->dvi_dual = false;
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004453 info->has_hdmi_infoframe = false;
Jesse Barnes3b112282011-04-15 12:49:23 -07004454
Dave Airlie66660d42017-10-16 05:08:09 +01004455 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4456
Keith Packard170178f2017-12-13 00:44:26 -08004457 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4458
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004459 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004460 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004461
4462 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004463 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004464
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004465 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004466
Mario Kleiner210a0212016-07-06 12:05:48 +02004467 /*
4468 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4469 *
4470 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4471 * tells us to assume 8 bpc color depth if the EDID doesn't have
4472 * extensions which tell otherwise.
4473 */
4474 if ((info->bpc == 0) && (edid->revision < 4) &&
4475 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
4476 info->bpc = 8;
4477 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4478 connector->name, info->bpc);
4479 }
4480
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004481 /* Only defined for 1.4 with digital displays */
4482 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004483 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004484
Jesse Barnes3b112282011-04-15 12:49:23 -07004485 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4486 case DRM_EDID_DIGITAL_DEPTH_6:
4487 info->bpc = 6;
4488 break;
4489 case DRM_EDID_DIGITAL_DEPTH_8:
4490 info->bpc = 8;
4491 break;
4492 case DRM_EDID_DIGITAL_DEPTH_10:
4493 info->bpc = 10;
4494 break;
4495 case DRM_EDID_DIGITAL_DEPTH_12:
4496 info->bpc = 12;
4497 break;
4498 case DRM_EDID_DIGITAL_DEPTH_14:
4499 info->bpc = 14;
4500 break;
4501 case DRM_EDID_DIGITAL_DEPTH_16:
4502 info->bpc = 16;
4503 break;
4504 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4505 default:
4506 info->bpc = 0;
4507 break;
4508 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004509
Mario Kleinerd0c94692014-03-27 19:59:39 +01004510 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004511 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004512
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004513 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004514 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4515 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4516 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4517 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004518 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004519}
Keith Packard170178f2017-12-13 00:44:26 -08004520EXPORT_SYMBOL_GPL(drm_add_display_info);
Jesse Barnes3b112282011-04-15 12:49:23 -07004521
Dave Airliec97291772016-05-03 15:38:37 +10004522static int validate_displayid(u8 *displayid, int length, int idx)
4523{
4524 int i;
4525 u8 csum = 0;
4526 struct displayid_hdr *base;
4527
4528 base = (struct displayid_hdr *)&displayid[idx];
4529
4530 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4531 base->rev, base->bytes, base->prod_id, base->ext_count);
4532
4533 if (base->bytes + 5 > length - idx)
4534 return -EINVAL;
4535 for (i = idx; i <= base->bytes + 5; i++) {
4536 csum += displayid[i];
4537 }
4538 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004539 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004540 return -EINVAL;
4541 }
4542 return 0;
4543}
4544
Dave Airliea39ed682016-05-02 08:35:05 +10004545static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4546 struct displayid_detailed_timings_1 *timings)
4547{
4548 struct drm_display_mode *mode;
4549 unsigned pixel_clock = (timings->pixel_clock[0] |
4550 (timings->pixel_clock[1] << 8) |
4551 (timings->pixel_clock[2] << 16));
4552 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4553 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4554 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4555 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4556 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4557 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4558 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4559 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4560 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4561 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4562 mode = drm_mode_create(dev);
4563 if (!mode)
4564 return NULL;
4565
4566 mode->clock = pixel_clock * 10;
4567 mode->hdisplay = hactive;
4568 mode->hsync_start = mode->hdisplay + hsync;
4569 mode->hsync_end = mode->hsync_start + hsync_width;
4570 mode->htotal = mode->hdisplay + hblank;
4571
4572 mode->vdisplay = vactive;
4573 mode->vsync_start = mode->vdisplay + vsync;
4574 mode->vsync_end = mode->vsync_start + vsync_width;
4575 mode->vtotal = mode->vdisplay + vblank;
4576
4577 mode->flags = 0;
4578 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4579 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4580 mode->type = DRM_MODE_TYPE_DRIVER;
4581
4582 if (timings->flags & 0x80)
4583 mode->type |= DRM_MODE_TYPE_PREFERRED;
4584 mode->vrefresh = drm_mode_vrefresh(mode);
4585 drm_mode_set_name(mode);
4586
4587 return mode;
4588}
4589
4590static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4591 struct displayid_block *block)
4592{
4593 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4594 int i;
4595 int num_timings;
4596 struct drm_display_mode *newmode;
4597 int num_modes = 0;
4598 /* blocks must be multiple of 20 bytes length */
4599 if (block->num_bytes % 20)
4600 return 0;
4601
4602 num_timings = block->num_bytes / 20;
4603 for (i = 0; i < num_timings; i++) {
4604 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4605
4606 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4607 if (!newmode)
4608 continue;
4609
4610 drm_mode_probed_add(connector, newmode);
4611 num_modes++;
4612 }
4613 return num_modes;
4614}
4615
4616static int add_displayid_detailed_modes(struct drm_connector *connector,
4617 struct edid *edid)
4618{
4619 u8 *displayid;
4620 int ret;
4621 int idx = 1;
4622 int length = EDID_LENGTH;
4623 struct displayid_block *block;
4624 int num_modes = 0;
4625
4626 displayid = drm_find_displayid_extension(edid);
4627 if (!displayid)
4628 return 0;
4629
4630 ret = validate_displayid(displayid, length, idx);
4631 if (ret)
4632 return 0;
4633
4634 idx += sizeof(struct displayid_hdr);
4635 while (block = (struct displayid_block *)&displayid[idx],
4636 idx + sizeof(struct displayid_block) <= length &&
4637 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4638 block->num_bytes > 0) {
4639 idx += block->num_bytes + sizeof(struct displayid_block);
4640 switch (block->tag) {
4641 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4642 num_modes += add_displayid_detailed_1_modes(connector, block);
4643 break;
4644 }
4645 }
4646 return num_modes;
4647}
4648
Jesse Barnes3b112282011-04-15 12:49:23 -07004649/**
Dave Airlief453ba02008-11-07 14:05:41 -08004650 * drm_add_edid_modes - add modes from EDID data, if available
4651 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004652 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004653 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004654 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004655 * &drm_display_info structure and ELD in @connector with any information which
4656 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004657 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004658 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004659 */
4660int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4661{
4662 int num_modes = 0;
4663 u32 quirks;
4664
4665 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004666 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004667 return 0;
4668 }
Alex Deucher3c537882010-02-05 04:21:19 -05004669 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004670 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004671 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004672 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004673 return 0;
4674 }
4675
Jani Nikulac945b8c2017-11-01 16:21:01 +02004676 drm_edid_to_eld(connector, edid);
4677
Adam Jacksonc867df72010-03-29 21:43:21 +00004678 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304679 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4680 * To avoid multiple parsing of same block, lets parse that map
4681 * from sink info, before parsing CEA modes.
4682 */
Keith Packard170178f2017-12-13 00:44:26 -08004683 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304684
4685 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004686 * EDID spec says modes should be preferred in this order:
4687 * - preferred detailed mode
4688 * - other detailed modes from base block
4689 * - detailed modes from extension blocks
4690 * - CVT 3-byte code modes
4691 * - standard timing codes
4692 * - established timing codes
4693 * - modes inferred from GTF or CVT range information
4694 *
Adam Jackson13931572010-08-03 14:38:19 -04004695 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004696 *
4697 * XXX order for additional mode types in extension blocks?
4698 */
Adam Jackson13931572010-08-03 14:38:19 -04004699 num_modes += add_detailed_modes(connector, edid, quirks);
4700 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004701 num_modes += add_standard_modes(connector, edid);
4702 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004703 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004704 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004705 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004706 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4707 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004708
4709 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4710 edid_fixup_preferred(connector, quirks);
4711
Mario Kleinere10aec62016-07-06 12:05:44 +02004712 if (quirks & EDID_QUIRK_FORCE_6BPC)
4713 connector->display_info.bpc = 6;
4714
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004715 if (quirks & EDID_QUIRK_FORCE_8BPC)
4716 connector->display_info.bpc = 8;
4717
Mario Kleinere345da82017-04-21 17:05:08 +02004718 if (quirks & EDID_QUIRK_FORCE_10BPC)
4719 connector->display_info.bpc = 10;
4720
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004721 if (quirks & EDID_QUIRK_FORCE_12BPC)
4722 connector->display_info.bpc = 12;
4723
Dave Airlief453ba02008-11-07 14:05:41 -08004724 return num_modes;
4725}
4726EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004727
4728/**
4729 * drm_add_modes_noedid - add modes for the connectors without EDID
4730 * @connector: connector we're probing
4731 * @hdisplay: the horizontal display limit
4732 * @vdisplay: the vertical display limit
4733 *
4734 * Add the specified modes to the connector's mode list. Only when the
4735 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4736 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004737 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004738 */
4739int drm_add_modes_noedid(struct drm_connector *connector,
4740 int hdisplay, int vdisplay)
4741{
4742 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004743 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004744 struct drm_device *dev = connector->dev;
4745
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004746 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004747 if (hdisplay < 0)
4748 hdisplay = 0;
4749 if (vdisplay < 0)
4750 vdisplay = 0;
4751
4752 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004753 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004754 if (hdisplay && vdisplay) {
4755 /*
4756 * Only when two are valid, they will be used to check
4757 * whether the mode should be added to the mode list of
4758 * the connector.
4759 */
4760 if (ptr->hdisplay > hdisplay ||
4761 ptr->vdisplay > vdisplay)
4762 continue;
4763 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004764 if (drm_mode_vrefresh(ptr) > 61)
4765 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004766 mode = drm_mode_duplicate(dev, ptr);
4767 if (mode) {
4768 drm_mode_probed_add(connector, mode);
4769 num_modes++;
4770 }
4771 }
4772 return num_modes;
4773}
4774EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004775
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004776/**
4777 * drm_set_preferred_mode - Sets the preferred mode of a connector
4778 * @connector: connector whose mode list should be processed
4779 * @hpref: horizontal resolution of preferred mode
4780 * @vpref: vertical resolution of preferred mode
4781 *
4782 * Marks a mode as preferred if it matches the resolution specified by @hpref
4783 * and @vpref.
4784 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004785void drm_set_preferred_mode(struct drm_connector *connector,
4786 int hpref, int vpref)
4787{
4788 struct drm_display_mode *mode;
4789
4790 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004791 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004792 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004793 mode->type |= DRM_MODE_TYPE_PREFERRED;
4794 }
4795}
4796EXPORT_SYMBOL(drm_set_preferred_mode);
4797
Thierry Reding10a85122012-11-21 15:31:35 +01004798/**
4799 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4800 * data from a DRM display mode
4801 * @frame: HDMI AVI infoframe
4802 * @mode: DRM display mode
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304803 * @is_hdmi2_sink: Sink is HDMI 2.0 compliant
Thierry Reding10a85122012-11-21 15:31:35 +01004804 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004805 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01004806 */
4807int
4808drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304809 const struct drm_display_mode *mode,
4810 bool is_hdmi2_sink)
Thierry Reding10a85122012-11-21 15:31:35 +01004811{
4812 int err;
4813
4814 if (!frame || !mode)
4815 return -EINVAL;
4816
4817 err = hdmi_avi_infoframe_init(frame);
4818 if (err < 0)
4819 return err;
4820
Damien Lespiaubf02db92013-08-06 20:32:22 +01004821 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
4822 frame->pixel_repeat = 1;
4823
Thierry Reding10a85122012-11-21 15:31:35 +01004824 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01004825
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304826 /*
4827 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
4828 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
4829 * have to make sure we dont break HDMI 1.4 sinks.
4830 */
4831 if (!is_hdmi2_sink && frame->video_code > 64)
4832 frame->video_code = 0;
4833
4834 /*
4835 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
4836 * we should send its VIC in vendor infoframes, else send the
4837 * VIC in AVI infoframes. Lets check if this mode is present in
4838 * HDMI 1.4b 4K modes
4839 */
4840 if (frame->video_code) {
4841 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
4842 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
4843
4844 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
4845 frame->video_code = 0;
4846 }
4847
Thierry Reding10a85122012-11-21 15:31:35 +01004848 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304849
Vandana Kannan69ab6d32014-06-05 14:45:29 +05304850 /*
4851 * Populate picture aspect ratio from either
4852 * user input (if specified) or from the CEA mode list.
4853 */
4854 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
4855 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
4856 frame->picture_aspect = mode->picture_aspect_ratio;
4857 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304858 frame->picture_aspect = drm_get_cea_aspect_ratio(
4859 frame->video_code);
4860
Thierry Reding10a85122012-11-21 15:31:35 +01004861 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06004862 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01004863
4864 return 0;
4865}
4866EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004867
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004868/**
4869 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4870 * quantization range information
4871 * @frame: HDMI AVI infoframe
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004872 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004873 * @rgb_quant_range: RGB quantization range (Q)
4874 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
Daniel Vetter7cdeb372017-12-14 21:30:50 +01004875 * @is_hdmi2_sink: HDMI 2.0 sink, which has different default recommendations
4876 *
4877 * Note that @is_hdmi2_sink can be derived by looking at the
4878 * &drm_scdc.supported flag stored in &drm_hdmi_info.scdc,
4879 * &drm_display_info.hdmi, which can be found in &drm_connector.display_info.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004880 */
4881void
4882drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004883 const struct drm_display_mode *mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004884 enum hdmi_quantization_range rgb_quant_range,
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004885 bool rgb_quant_range_selectable,
4886 bool is_hdmi2_sink)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004887{
4888 /*
4889 * CEA-861:
4890 * "A Source shall not send a non-zero Q value that does not correspond
4891 * to the default RGB Quantization Range for the transmitted Picture
4892 * unless the Sink indicates support for the Q bit in a Video
4893 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004894 *
4895 * HDMI 2.0 recommends sending non-zero Q when it does match the
4896 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004897 */
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004898 if (rgb_quant_range_selectable ||
4899 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004900 frame->quantization_range = rgb_quant_range;
4901 else
4902 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004903
4904 /*
4905 * CEA-861-F:
4906 * "When transmitting any RGB colorimetry, the Source should set the
4907 * YQ-field to match the RGB Quantization Range being transmitted
4908 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4909 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004910 *
4911 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
4912 * by non-zero YQ when receiving RGB. There doesn't seem to be any
4913 * good way to tell which version of CEA-861 the sink supports, so
4914 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
4915 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004916 */
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02004917 if (!is_hdmi2_sink ||
4918 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004919 frame->ycc_quantization_range =
4920 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4921 else
4922 frame->ycc_quantization_range =
4923 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004924}
4925EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
4926
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004927static enum hdmi_3d_structure
4928s3d_structure_from_display_mode(const struct drm_display_mode *mode)
4929{
4930 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
4931
4932 switch (layout) {
4933 case DRM_MODE_FLAG_3D_FRAME_PACKING:
4934 return HDMI_3D_STRUCTURE_FRAME_PACKING;
4935 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
4936 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
4937 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
4938 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
4939 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
4940 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
4941 case DRM_MODE_FLAG_3D_L_DEPTH:
4942 return HDMI_3D_STRUCTURE_L_DEPTH;
4943 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
4944 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
4945 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
4946 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
4947 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
4948 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
4949 default:
4950 return HDMI_3D_STRUCTURE_INVALID;
4951 }
4952}
4953
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004954/**
4955 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4956 * data from a DRM display mode
4957 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004958 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004959 * @mode: DRM display mode
4960 *
4961 * Note that there's is a need to send HDMI vendor infoframes only when using a
4962 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4963 * function will return -EINVAL, error that can be safely ignored.
4964 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004965 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004966 */
4967int
4968drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004969 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004970 const struct drm_display_mode *mode)
4971{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004972 /*
4973 * FIXME: sil-sii8620 doesn't have a connector around when
4974 * we need one, so we have to be prepared for a NULL connector.
4975 */
4976 bool has_hdmi_infoframe = connector ?
4977 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004978 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004979 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004980 u8 vic;
4981
4982 if (!frame || !mode)
4983 return -EINVAL;
4984
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004985 if (!has_hdmi_infoframe)
4986 return -EINVAL;
4987
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004988 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004989 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
4990
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004991 /*
4992 * Even if it's not absolutely necessary to send the infoframe
4993 * (ie.vic==0 and s3d_struct==0) we will still send it if we
4994 * know that the sink can handle it. This is based on a
4995 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
4996 * have trouble realizing that they shuld switch from 3D to 2D
4997 * mode if the source simply stops sending the infoframe when
4998 * it wants to switch from 3D to 2D.
4999 */
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005000
5001 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005002 return -EINVAL;
5003
5004 err = hdmi_vendor_infoframe_init(frame);
5005 if (err < 0)
5006 return err;
5007
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005008 frame->vic = vic;
5009 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005010
5011 return 0;
5012}
5013EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005014
Dave Airlie5e546cd2016-05-03 15:31:12 +10005015static int drm_parse_tiled_block(struct drm_connector *connector,
5016 struct displayid_block *block)
5017{
5018 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5019 u16 w, h;
5020 u8 tile_v_loc, tile_h_loc;
5021 u8 num_v_tile, num_h_tile;
5022 struct drm_tile_group *tg;
5023
5024 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5025 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5026
5027 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5028 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5029 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5030 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5031
5032 connector->has_tile = true;
5033 if (tile->tile_cap & 0x80)
5034 connector->tile_is_single_monitor = true;
5035
5036 connector->num_h_tile = num_h_tile + 1;
5037 connector->num_v_tile = num_v_tile + 1;
5038 connector->tile_h_loc = tile_h_loc;
5039 connector->tile_v_loc = tile_v_loc;
5040 connector->tile_h_size = w + 1;
5041 connector->tile_v_size = h + 1;
5042
5043 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5044 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5045 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5046 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5047 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5048
5049 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5050 if (!tg) {
5051 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5052 }
5053 if (!tg)
5054 return -ENOMEM;
5055
5056 if (connector->tile_group != tg) {
5057 /* if we haven't got a pointer,
5058 take the reference, drop ref to old tile group */
5059 if (connector->tile_group) {
5060 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5061 }
5062 connector->tile_group = tg;
5063 } else
5064 /* if same tile group, then release the ref we just took. */
5065 drm_mode_put_tile_group(connector->dev, tg);
5066 return 0;
5067}
5068
Dave Airlie40d9b042014-10-20 16:29:33 +10005069static int drm_parse_display_id(struct drm_connector *connector,
5070 u8 *displayid, int length,
5071 bool is_edid_extension)
5072{
5073 /* if this is an EDID extension the first byte will be 0x70 */
5074 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005075 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005076 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005077
5078 if (is_edid_extension)
5079 idx = 1;
5080
Dave Airliec97291772016-05-03 15:38:37 +10005081 ret = validate_displayid(displayid, length, idx);
5082 if (ret)
5083 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005084
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005085 idx += sizeof(struct displayid_hdr);
5086 while (block = (struct displayid_block *)&displayid[idx],
5087 idx + sizeof(struct displayid_block) <= length &&
5088 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
5089 block->num_bytes > 0) {
5090 idx += block->num_bytes + sizeof(struct displayid_block);
5091 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5092 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005093
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005094 switch (block->tag) {
5095 case DATA_BLOCK_TILED_DISPLAY:
5096 ret = drm_parse_tiled_block(connector, block);
5097 if (ret)
5098 return ret;
5099 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005100 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5101 /* handled in mode gathering code. */
5102 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005103 default:
5104 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5105 break;
5106 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005107 }
5108 return 0;
5109}
5110
5111static void drm_get_displayid(struct drm_connector *connector,
5112 struct edid *edid)
5113{
5114 void *displayid = NULL;
5115 int ret;
5116 connector->has_tile = false;
5117 displayid = drm_find_displayid_extension(edid);
5118 if (!displayid) {
5119 /* drop reference to any tile group we had */
5120 goto out_drop_ref;
5121 }
5122
5123 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5124 if (ret < 0)
5125 goto out_drop_ref;
5126 if (!connector->has_tile)
5127 goto out_drop_ref;
5128 return;
5129out_drop_ref:
5130 if (connector->tile_group) {
5131 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5132 connector->tile_group = NULL;
5133 }
5134 return;
5135}