blob: d0ef372a7481b4c7149d0b810ea68a9fa775a66c [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 */
Jani Nikula9c79ede2019-05-06 12:52:48 +030030
Thierry Reding10a85122012-11-21 15:31:35 +010031#include <linux/hdmi.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/i2c.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030033#include <linux/kernel.h>
Adam Jackson47819ba2012-05-30 16:42:39 -040034#include <linux/module.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030035#include <linux/slab.h>
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +010036#include <linux/vga_switcheroo.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030037
38#include <drm/drm_displayid.h>
39#include <drm/drm_drv.h>
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020041#include <drm/drm_encoder.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030042#include <drm/drm_print.h>
Shashank Sharma62c58af2017-03-13 16:54:02 +053043#include <drm/drm_scdc_helper.h>
Dave Airlief453ba02008-11-07 14:05:41 -080044
Takashi Iwai969218f2017-01-17 17:43:29 +010045#include "drm_crtc_internal.h"
46
Adam Jackson13931572010-08-03 14:38:19 -040047#define version_greater(edid, maj, min) \
48 (((edid)->version > (maj)) || \
49 ((edid)->version == (maj) && (edid)->revision > (min)))
Dave Airlief453ba02008-11-07 14:05:41 -080050
Adam Jacksond1ff6402010-03-29 21:43:26 +000051#define EDID_EST_TIMINGS 16
52#define EDID_STD_TIMINGS 8
53#define EDID_DETAILED_TIMINGS 4
Dave Airlief453ba02008-11-07 14:05:41 -080054
55/*
56 * EDID blocks out in the wild have a variety of bugs, try to collect
57 * them here (note that userspace may work around broken monitors first,
58 * but fixes should make their way here so that the kernel "just works"
59 * on as many displays as possible).
60 */
61
62/* First detailed mode wrong, use largest 60Hz mode */
63#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
64/* Reported 135MHz pixel clock is too high, needs adjustment */
65#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
66/* Prefer the largest mode at 75 Hz */
67#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
68/* Detail timing is in cm not mm */
69#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
70/* Detailed timing descriptors have bogus size values, so just take the
71 * maximum size and use that.
72 */
73#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
Dave Airlief453ba02008-11-07 14:05:41 -080074/* use +hsync +vsync for detailed mode */
75#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
Adam Jacksonbc42aab2012-05-23 16:26:54 -040076/* Force reduced-blanking timings for detailed modes */
77#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
Rafał Miłecki49d45a312013-12-07 13:22:42 +010078/* Force 8bpc */
79#define EDID_QUIRK_FORCE_8BPC (1 << 8)
Mario Kleinerbc5b9642014-05-23 21:40:55 +020080/* Force 12bpc */
81#define EDID_QUIRK_FORCE_12BPC (1 << 9)
Mario Kleinere10aec62016-07-06 12:05:44 +020082/* Force 6bpc */
83#define EDID_QUIRK_FORCE_6BPC (1 << 10)
Mario Kleinere345da82017-04-21 17:05:08 +020084/* Force 10bpc */
85#define EDID_QUIRK_FORCE_10BPC (1 << 11)
Dave Airlie66660d42017-10-16 05:08:09 +010086/* Non desktop display (i.e. HMD) */
87#define EDID_QUIRK_NON_DESKTOP (1 << 12)
Alex Deucher3c537882010-02-05 04:21:19 -050088
Adam Jackson13931572010-08-03 14:38:19 -040089struct detailed_mode_closure {
90 struct drm_connector *connector;
91 struct edid *edid;
92 bool preferred;
93 u32 quirks;
94 int modes;
95};
Dave Airlief453ba02008-11-07 14:05:41 -080096
Zhao Yakui5c612592009-06-22 13:17:10 +080097#define LEVEL_DMT 0
98#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000099#define LEVEL_GTF2 2
100#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +0800101
Jani Nikula23c4cfb2016-12-28 13:06:26 +0200102static const struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -0500103 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800104 int product_id;
105 u32 quirks;
106} edid_quirk_list[] = {
107 /* Acer AL1706 */
108 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
109 /* Acer F51 */
110 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800111
Mario Kleinere10aec62016-07-06 12:05:44 +0200112 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
113 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
114
Kai-Heng Feng0711a432018-10-02 23:29:11 +0800115 /* BOE model on HP Pavilion 15-n233sl reports 8 bpc, but is a 6 bpc panel */
116 { "BOE", 0x78b, EDID_QUIRK_FORCE_6BPC },
117
Kai-Heng Feng06998a752018-02-18 16:53:59 +0800118 /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
119 { "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC },
120
Kai-Heng Feng25da7502018-08-23 05:53:32 +0000121 /* SDC panel of Lenovo B50-80 reports 8 bpc, but is a 6 bpc panel */
122 { "SDC", 0x3652, EDID_QUIRK_FORCE_6BPC },
123
Lee, Shawn C922dcef2018-10-28 22:49:33 -0700124 /* BOE model 0x0771 reports 8 bpc, but is a 6 bpc panel */
125 { "BOE", 0x0771, EDID_QUIRK_FORCE_6BPC },
126
Dave Airlief453ba02008-11-07 14:05:41 -0800127 /* Belinea 10 15 55 */
128 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
129 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
130
131 /* Envision Peripherals, Inc. EN-7100e */
132 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000133 /* Envision EN2028 */
134 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800135
136 /* Funai Electronics PM36B */
137 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
138 EDID_QUIRK_DETAILED_IN_CM },
139
Mario Kleinere345da82017-04-21 17:05:08 +0200140 /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
141 { "LGD", 764, EDID_QUIRK_FORCE_10BPC },
142
Dave Airlief453ba02008-11-07 14:05:41 -0800143 /* LG Philips LCD LP154W01-A5 */
144 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
145 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
146
Dave Airlief453ba02008-11-07 14:05:41 -0800147 /* Samsung SyncMaster 205BW. Note: irony */
148 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
149 /* Samsung SyncMaster 22[5-6]BW */
150 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
151 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400152
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200153 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
154 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
155
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400156 /* ViewSonic VA2026w */
157 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400158
159 /* Medion MD 30217 PG */
160 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100161
Kai-Heng Feng11bcf5f2019-04-02 11:30:37 +0800162 /* Lenovo G50 */
163 { "SDC", 18514, EDID_QUIRK_FORCE_6BPC },
164
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100165 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
166 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Tomeu Vizoso36fc5792017-02-20 16:25:45 +0100167
168 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
169 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100170
Andres Rodriguez30d62d42019-05-02 15:31:57 -0400171 /* Valve Index Headset */
172 { "VLV", 0x91a8, EDID_QUIRK_NON_DESKTOP },
173 { "VLV", 0x91b0, EDID_QUIRK_NON_DESKTOP },
174 { "VLV", 0x91b1, EDID_QUIRK_NON_DESKTOP },
175 { "VLV", 0x91b2, EDID_QUIRK_NON_DESKTOP },
176 { "VLV", 0x91b3, EDID_QUIRK_NON_DESKTOP },
177 { "VLV", 0x91b4, EDID_QUIRK_NON_DESKTOP },
178 { "VLV", 0x91b5, EDID_QUIRK_NON_DESKTOP },
179 { "VLV", 0x91b6, EDID_QUIRK_NON_DESKTOP },
180 { "VLV", 0x91b7, EDID_QUIRK_NON_DESKTOP },
181 { "VLV", 0x91b8, EDID_QUIRK_NON_DESKTOP },
182 { "VLV", 0x91b9, EDID_QUIRK_NON_DESKTOP },
183 { "VLV", 0x91ba, EDID_QUIRK_NON_DESKTOP },
184 { "VLV", 0x91bb, EDID_QUIRK_NON_DESKTOP },
185 { "VLV", 0x91bc, EDID_QUIRK_NON_DESKTOP },
186 { "VLV", 0x91bd, EDID_QUIRK_NON_DESKTOP },
187 { "VLV", 0x91be, EDID_QUIRK_NON_DESKTOP },
188 { "VLV", 0x91bf, EDID_QUIRK_NON_DESKTOP },
189
Lubosz Sarnecki69313172018-05-29 13:52:15 +0200190 /* HTC Vive and Vive Pro VR Headsets */
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100191 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
Lubosz Sarnecki69313172018-05-29 13:52:15 +0200192 { "HVR", 0xaa02, EDID_QUIRK_NON_DESKTOP },
Philipp Zabelb3b12ea2018-02-19 18:59:36 +0100193
194 /* Oculus Rift DK1, DK2, and CV1 VR Headsets */
195 { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
196 { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
197 { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
Philipp Zabel90eda8f2018-02-19 18:59:37 +0100198
199 /* Windows Mixed Reality Headsets */
200 { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
201 { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
202 { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
203 { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
204 { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
205 { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
206 { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
207 { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
Philipp Zabelccffc9e2018-02-19 18:59:38 +0100208
209 /* Sony PlayStation VR Headset */
210 { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
Ryan Pavlik29054232018-12-03 10:46:44 -0600211
212 /* Sensics VR Headsets */
213 { "SEN", 0x1019, EDID_QUIRK_NON_DESKTOP },
214
215 /* OSVR HDK and HDK2 VR Headsets */
216 { "SVR", 0x1019, EDID_QUIRK_NON_DESKTOP },
Dave Airlief453ba02008-11-07 14:05:41 -0800217};
218
Thierry Redinga6b21832012-11-23 15:01:42 +0100219/*
220 * Autogenerated from the DMT spec.
221 * This table is copied from xfree86/modes/xf86EdidModes.c.
222 */
223static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300224 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100225 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
226 736, 832, 0, 350, 382, 385, 445, 0,
227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300228 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100229 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
230 736, 832, 0, 400, 401, 404, 445, 0,
231 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300232 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100233 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
234 828, 936, 0, 400, 401, 404, 446, 0,
235 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300236 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100237 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300238 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100239 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300240 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100241 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
242 704, 832, 0, 480, 489, 492, 520, 0,
243 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300244 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100245 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
246 720, 840, 0, 480, 481, 484, 500, 0,
247 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300248 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100249 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
250 752, 832, 0, 480, 481, 484, 509, 0,
251 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300252 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100253 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
254 896, 1024, 0, 600, 601, 603, 625, 0,
255 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300256 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100257 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
258 968, 1056, 0, 600, 601, 605, 628, 0,
259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300260 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100261 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
262 976, 1040, 0, 600, 637, 643, 666, 0,
263 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300264 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100265 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
266 896, 1056, 0, 600, 601, 604, 625, 0,
267 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300268 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100269 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
270 896, 1048, 0, 600, 601, 604, 631, 0,
271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300272 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100273 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
274 880, 960, 0, 600, 603, 607, 636, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300276 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100277 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
278 976, 1088, 0, 480, 486, 494, 517, 0,
279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300280 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100281 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100282 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100283 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300284 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300285 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100286 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
287 1184, 1344, 0, 768, 771, 777, 806, 0,
288 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300289 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100290 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
291 1184, 1328, 0, 768, 771, 777, 806, 0,
292 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300293 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100294 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
295 1136, 1312, 0, 768, 769, 772, 800, 0,
296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300297 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100298 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
299 1168, 1376, 0, 768, 769, 772, 808, 0,
300 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300301 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100302 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
303 1104, 1184, 0, 768, 771, 775, 813, 0,
304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300305 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100306 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
307 1344, 1600, 0, 864, 865, 868, 900, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300309 /* 0x55 - 1280x720@60Hz */
310 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
311 1430, 1650, 0, 720, 725, 730, 750, 0,
312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300313 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100314 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
315 1360, 1440, 0, 768, 771, 778, 790, 0,
316 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300317 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100318 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
319 1472, 1664, 0, 768, 771, 778, 798, 0,
320 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300321 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100322 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
323 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300324 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300325 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100326 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
327 1496, 1712, 0, 768, 771, 778, 809, 0,
328 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300329 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100330 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
331 1360, 1440, 0, 768, 771, 778, 813, 0,
332 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300333 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100334 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
335 1360, 1440, 0, 800, 803, 809, 823, 0,
336 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300337 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100338 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
339 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300340 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300341 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100342 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
343 1488, 1696, 0, 800, 803, 809, 838, 0,
344 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300345 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100346 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
347 1496, 1712, 0, 800, 803, 809, 843, 0,
348 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300349 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100350 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
351 1360, 1440, 0, 800, 803, 809, 847, 0,
352 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300353 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100354 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
355 1488, 1800, 0, 960, 961, 964, 1000, 0,
356 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300357 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100358 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
359 1504, 1728, 0, 960, 961, 964, 1011, 0,
360 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300361 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100362 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
363 1360, 1440, 0, 960, 963, 967, 1017, 0,
364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300365 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100366 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
367 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300369 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100370 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
371 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
372 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300373 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100374 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
375 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
376 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300377 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100378 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
379 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
380 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300381 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100382 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
383 1536, 1792, 0, 768, 771, 777, 795, 0,
384 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300385 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100386 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
387 1440, 1520, 0, 768, 771, 776, 813, 0,
388 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300389 /* 0x51 - 1366x768@60Hz */
390 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
391 1579, 1792, 0, 768, 771, 774, 798, 0,
392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
393 /* 0x56 - 1366x768@60Hz */
394 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
395 1436, 1500, 0, 768, 769, 772, 800, 0,
396 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300397 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100398 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
399 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
400 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300401 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100402 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
403 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
404 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300405 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100406 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
407 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
408 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300409 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100410 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
411 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
412 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300413 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100414 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
415 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
416 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300417 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100418 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
419 1520, 1600, 0, 900, 903, 909, 926, 0,
420 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300421 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100422 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
423 1672, 1904, 0, 900, 903, 909, 934, 0,
424 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300425 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100426 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
427 1688, 1936, 0, 900, 903, 909, 942, 0,
428 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300429 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100430 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
431 1696, 1952, 0, 900, 903, 909, 948, 0,
432 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300433 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100434 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
435 1520, 1600, 0, 900, 903, 909, 953, 0,
436 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300437 /* 0x53 - 1600x900@60Hz */
438 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
439 1704, 1800, 0, 900, 901, 904, 1000, 0,
440 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300441 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100442 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
443 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
444 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300445 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100446 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
447 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
448 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300449 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100450 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
451 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
452 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300453 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100454 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
455 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
456 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300457 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100458 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
459 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
460 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300461 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100462 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
463 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
464 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300465 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100466 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
467 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
468 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300469 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100470 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
471 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
472 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300473 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100474 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
475 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
476 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300477 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100478 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
479 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
480 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300481 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100482 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
483 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
484 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300485 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100486 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
487 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
488 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300489 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100490 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
491 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
492 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300493 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100494 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
495 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
496 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300497 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100498 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
499 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
500 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300501 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100502 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300503 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100504 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300505 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100506 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
507 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
508 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300509 /* 0x52 - 1920x1080@60Hz */
510 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
511 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
512 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300513 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100514 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
515 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
516 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300517 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100518 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
519 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
520 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300521 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100522 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
523 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
524 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300525 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100526 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
527 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
528 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300529 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100530 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
531 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
532 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300533 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100534 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
535 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
536 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300537 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100538 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
539 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
540 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300541 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100542 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
543 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
544 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300545 /* 0x54 - 2048x1152@60Hz */
546 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
547 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
548 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300549 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100550 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
551 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
552 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300553 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100554 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
555 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
556 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300557 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100558 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
559 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
560 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300561 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100562 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
563 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
564 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300565 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100566 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
567 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
568 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300569 /* 0x57 - 4096x2160@60Hz RB */
570 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
571 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
572 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
573 /* 0x58 - 4096x2160@59.94Hz RB */
574 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
575 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
576 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100577};
578
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300579/*
580 * These more or less come from the DMT spec. The 720x400 modes are
581 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
582 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
583 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
584 * mode.
585 *
586 * The DMT modes have been fact-checked; the rest are mild guesses.
587 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100588static const struct drm_display_mode edid_est_modes[] = {
589 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
590 968, 1056, 0, 600, 601, 605, 628, 0,
591 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
592 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
593 896, 1024, 0, 600, 601, 603, 625, 0,
594 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
595 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
596 720, 840, 0, 480, 481, 484, 500, 0,
597 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
598 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100599 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100600 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
601 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
602 768, 864, 0, 480, 483, 486, 525, 0,
603 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100604 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100605 752, 800, 0, 480, 490, 492, 525, 0,
606 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
607 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
608 846, 900, 0, 400, 421, 423, 449, 0,
609 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
610 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
611 846, 900, 0, 400, 412, 414, 449, 0,
612 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
613 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
614 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
615 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100616 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100617 1136, 1312, 0, 768, 769, 772, 800, 0,
618 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
619 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
620 1184, 1328, 0, 768, 771, 777, 806, 0,
621 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
622 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
623 1184, 1344, 0, 768, 771, 777, 806, 0,
624 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
625 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
626 1208, 1264, 0, 768, 768, 776, 817, 0,
627 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
628 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
629 928, 1152, 0, 624, 625, 628, 667, 0,
630 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
631 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
632 896, 1056, 0, 600, 601, 604, 625, 0,
633 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
634 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
635 976, 1040, 0, 600, 637, 643, 666, 0,
636 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
637 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
638 1344, 1600, 0, 864, 865, 868, 900, 0,
639 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
640};
641
642struct minimode {
643 short w;
644 short h;
645 short r;
646 short rb;
647};
648
649static const struct minimode est3_modes[] = {
650 /* byte 6 */
651 { 640, 350, 85, 0 },
652 { 640, 400, 85, 0 },
653 { 720, 400, 85, 0 },
654 { 640, 480, 85, 0 },
655 { 848, 480, 60, 0 },
656 { 800, 600, 85, 0 },
657 { 1024, 768, 85, 0 },
658 { 1152, 864, 75, 0 },
659 /* byte 7 */
660 { 1280, 768, 60, 1 },
661 { 1280, 768, 60, 0 },
662 { 1280, 768, 75, 0 },
663 { 1280, 768, 85, 0 },
664 { 1280, 960, 60, 0 },
665 { 1280, 960, 85, 0 },
666 { 1280, 1024, 60, 0 },
667 { 1280, 1024, 85, 0 },
668 /* byte 8 */
669 { 1360, 768, 60, 0 },
670 { 1440, 900, 60, 1 },
671 { 1440, 900, 60, 0 },
672 { 1440, 900, 75, 0 },
673 { 1440, 900, 85, 0 },
674 { 1400, 1050, 60, 1 },
675 { 1400, 1050, 60, 0 },
676 { 1400, 1050, 75, 0 },
677 /* byte 9 */
678 { 1400, 1050, 85, 0 },
679 { 1680, 1050, 60, 1 },
680 { 1680, 1050, 60, 0 },
681 { 1680, 1050, 75, 0 },
682 { 1680, 1050, 85, 0 },
683 { 1600, 1200, 60, 0 },
684 { 1600, 1200, 65, 0 },
685 { 1600, 1200, 70, 0 },
686 /* byte 10 */
687 { 1600, 1200, 75, 0 },
688 { 1600, 1200, 85, 0 },
689 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300690 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100691 { 1856, 1392, 60, 0 },
692 { 1856, 1392, 75, 0 },
693 { 1920, 1200, 60, 1 },
694 { 1920, 1200, 60, 0 },
695 /* byte 11 */
696 { 1920, 1200, 75, 0 },
697 { 1920, 1200, 85, 0 },
698 { 1920, 1440, 60, 0 },
699 { 1920, 1440, 75, 0 },
700};
701
702static const struct minimode extra_modes[] = {
703 { 1024, 576, 60, 0 },
704 { 1366, 768, 60, 0 },
705 { 1600, 900, 60, 0 },
706 { 1680, 945, 60, 0 },
707 { 1920, 1080, 60, 0 },
708 { 2048, 1152, 60, 0 },
709 { 2048, 1536, 60, 0 },
710};
711
712/*
713 * Probably taken from CEA-861 spec.
714 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200715 *
716 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100717 */
718static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200719 /* 0 - dummy, VICs start at 1 */
720 { },
Ville Syrjälä78691962018-05-24 22:20:35 +0300721 /* 1 - 640x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100722 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
723 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300724 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530725 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300726 /* 2 - 720x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100727 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
728 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300729 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530730 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300731 /* 3 - 720x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100732 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
733 798, 858, 0, 480, 489, 495, 525, 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_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300736 /* 4 - 1280x720@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100737 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
738 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300739 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530740 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300741 /* 5 - 1920x1080i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100742 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
743 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
744 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300745 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530746 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300747 /* 6 - 720(1440)x480i@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700748 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
749 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100750 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300751 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530752 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300753 /* 7 - 720(1440)x480i@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700754 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
755 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100756 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300757 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530758 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300759 /* 8 - 720(1440)x240@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700760 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
761 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100762 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300763 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530764 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300765 /* 9 - 720(1440)x240@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700766 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
767 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100768 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300769 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530770 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300771 /* 10 - 2880x480i@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100772 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
773 3204, 3432, 0, 480, 488, 494, 525, 0,
774 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300775 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530776 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300777 /* 11 - 2880x480i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100778 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
779 3204, 3432, 0, 480, 488, 494, 525, 0,
780 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300781 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530782 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300783 /* 12 - 2880x240@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100784 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
785 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300786 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530787 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300788 /* 13 - 2880x240@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100789 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
790 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300791 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530792 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300793 /* 14 - 1440x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100794 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
795 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300796 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530797 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300798 /* 15 - 1440x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100799 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
800 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530802 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300803 /* 16 - 1920x1080@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100804 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
805 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300806 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530807 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300808 /* 17 - 720x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100809 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
810 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300811 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530812 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300813 /* 18 - 720x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100814 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
815 796, 864, 0, 576, 581, 586, 625, 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_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300818 /* 19 - 1280x720@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100819 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
820 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300821 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530822 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300823 /* 20 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100824 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
825 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
826 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300827 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530828 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300829 /* 21 - 720(1440)x576i@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700830 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
831 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100832 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300833 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530834 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300835 /* 22 - 720(1440)x576i@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700836 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
837 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100838 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300839 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530840 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300841 /* 23 - 720(1440)x288@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700842 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
843 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100844 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300845 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530846 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300847 /* 24 - 720(1440)x288@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700848 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
849 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100850 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300851 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530852 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300853 /* 25 - 2880x576i@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100854 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
855 3180, 3456, 0, 576, 580, 586, 625, 0,
856 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300857 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530858 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300859 /* 26 - 2880x576i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100860 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
861 3180, 3456, 0, 576, 580, 586, 625, 0,
862 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300863 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530864 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300865 /* 27 - 2880x288@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100866 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
867 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300868 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530869 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300870 /* 28 - 2880x288@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100871 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
872 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300873 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530874 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300875 /* 29 - 1440x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100876 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
877 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300878 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530879 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300880 /* 30 - 1440x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100881 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
882 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300883 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530884 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300885 /* 31 - 1920x1080@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100886 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
887 2492, 2640, 0, 1080, 1084, 1089, 1125, 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 = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300890 /* 32 - 1920x1080@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100891 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
892 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300893 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530894 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300895 /* 33 - 1920x1080@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100896 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
897 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300898 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530899 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300900 /* 34 - 1920x1080@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100901 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
902 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300903 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530904 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300905 /* 35 - 2880x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100906 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
907 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300908 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530909 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300910 /* 36 - 2880x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100911 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
912 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300913 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530914 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300915 /* 37 - 2880x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100916 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
917 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300918 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530919 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300920 /* 38 - 2880x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100921 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
922 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300923 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530924 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300925 /* 39 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100926 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
927 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
928 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300929 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530930 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300931 /* 40 - 1920x1080i@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100932 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
933 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
934 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300935 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530936 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300937 /* 41 - 1280x720@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100938 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
939 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300940 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530941 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300942 /* 42 - 720x576@100Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100943 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
944 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300945 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530946 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300947 /* 43 - 720x576@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100948 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
949 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300950 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530951 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300952 /* 44 - 720(1440)x576i@100Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700953 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
954 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100955 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300956 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530957 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300958 /* 45 - 720(1440)x576i@100Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700959 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
960 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100961 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300962 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530963 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300964 /* 46 - 1920x1080i@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100965 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
966 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
967 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300968 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530969 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300970 /* 47 - 1280x720@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100971 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
972 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300973 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530974 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300975 /* 48 - 720x480@120Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100976 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
977 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300978 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530979 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300980 /* 49 - 720x480@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100981 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
982 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300983 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530984 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300985 /* 50 - 720(1440)x480i@120Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700986 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
987 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100988 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300989 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530990 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300991 /* 51 - 720(1440)x480i@120Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700992 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
993 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100994 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300995 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530996 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300997 /* 52 - 720x576@200Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100998 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
999 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001000 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301001 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001002 /* 53 - 720x576@200Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001003 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1004 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001005 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301006 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001007 /* 54 - 720(1440)x576i@200Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001008 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1009 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001010 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001011 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301012 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001013 /* 55 - 720(1440)x576i@200Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001014 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1015 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001016 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001017 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301018 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001019 /* 56 - 720x480@240Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001020 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1021 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001022 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301023 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001024 /* 57 - 720x480@240Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001025 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1026 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001027 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301028 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001029 /* 58 - 720(1440)x480i@240Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001030 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1031 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001032 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001033 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301034 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001035 /* 59 - 720(1440)x480i@240Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001036 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1037 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001038 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001039 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301040 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001041 /* 60 - 1280x720@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001042 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1043 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001044 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301045 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001046 /* 61 - 1280x720@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001047 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1048 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001049 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301050 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001051 /* 62 - 1280x720@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001052 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1053 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001054 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301055 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001056 /* 63 - 1920x1080@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001057 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1058 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001060 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1061 /* 64 - 1920x1080@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001062 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001063 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001064 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001065 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1066 /* 65 - 1280x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301067 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1068 3080, 3300, 0, 720, 725, 730, 750, 0,
1069 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1070 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001071 /* 66 - 1280x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301072 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1073 3740, 3960, 0, 720, 725, 730, 750, 0,
1074 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1075 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001076 /* 67 - 1280x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301077 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1078 3080, 3300, 0, 720, 725, 730, 750, 0,
1079 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1080 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001081 /* 68 - 1280x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301082 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1083 1760, 1980, 0, 720, 725, 730, 750, 0,
1084 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1085 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001086 /* 69 - 1280x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301087 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1088 1430, 1650, 0, 720, 725, 730, 750, 0,
1089 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1090 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001091 /* 70 - 1280x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301092 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1093 1760, 1980, 0, 720, 725, 730, 750, 0,
1094 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1095 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001096 /* 71 - 1280x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301097 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1098 1430, 1650, 0, 720, 725, 730, 750, 0,
1099 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1100 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001101 /* 72 - 1920x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301102 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1103 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1105 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001106 /* 73 - 1920x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301107 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1108 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1109 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1110 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001111 /* 74 - 1920x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301112 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1113 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1114 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1115 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001116 /* 75 - 1920x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301117 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1118 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1119 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1120 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001121 /* 76 - 1920x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301122 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1123 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1124 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1125 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001126 /* 77 - 1920x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301127 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1128 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1129 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1130 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001131 /* 78 - 1920x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301132 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1133 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1134 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1135 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001136 /* 79 - 1680x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301137 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1138 3080, 3300, 0, 720, 725, 730, 750, 0,
1139 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1140 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001141 /* 80 - 1680x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301142 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1143 2948, 3168, 0, 720, 725, 730, 750, 0,
1144 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1145 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001146 /* 81 - 1680x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301147 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1148 2420, 2640, 0, 720, 725, 730, 750, 0,
1149 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1150 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001151 /* 82 - 1680x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301152 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1153 1980, 2200, 0, 720, 725, 730, 750, 0,
1154 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1155 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001156 /* 83 - 1680x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301157 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1158 1980, 2200, 0, 720, 725, 730, 750, 0,
1159 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1160 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001161 /* 84 - 1680x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301162 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1163 1780, 2000, 0, 720, 725, 730, 825, 0,
1164 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1165 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001166 /* 85 - 1680x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301167 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1168 1780, 2000, 0, 720, 725, 730, 825, 0,
1169 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1170 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001171 /* 86 - 2560x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301172 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1173 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1174 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1175 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001176 /* 87 - 2560x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301177 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1178 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1180 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001181 /* 88 - 2560x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301182 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1183 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1184 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1185 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001186 /* 89 - 2560x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301187 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1188 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1189 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1190 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001191 /* 90 - 2560x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301192 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1193 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1195 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001196 /* 91 - 2560x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301197 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1198 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1199 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1200 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001201 /* 92 - 2560x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301202 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1203 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1205 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001206 /* 93 - 3840x2160@24Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301207 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1208 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1209 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1210 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001211 /* 94 - 3840x2160@25Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301212 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1213 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1215 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001216 /* 95 - 3840x2160@30Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301217 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1218 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1219 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1220 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001221 /* 96 - 3840x2160@50Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301222 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1223 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1225 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001226 /* 97 - 3840x2160@60Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301227 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1228 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1229 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1230 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001231 /* 98 - 4096x2160@24Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301232 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1233 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1234 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1235 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001236 /* 99 - 4096x2160@25Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301237 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1238 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1239 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1240 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001241 /* 100 - 4096x2160@30Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301242 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1243 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1245 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001246 /* 101 - 4096x2160@50Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301247 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1248 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1249 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1250 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001251 /* 102 - 4096x2160@60Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301252 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1253 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1254 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1255 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001256 /* 103 - 3840x2160@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301257 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1258 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1260 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001261 /* 104 - 3840x2160@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301262 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1263 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1264 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1265 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001266 /* 105 - 3840x2160@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301267 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1268 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1269 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1270 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001271 /* 106 - 3840x2160@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301272 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1273 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1274 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1275 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001276 /* 107 - 3840x2160@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301277 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1278 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1280 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001281 /* 108 - 1280x720@48Hz 16:9 */
1282 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1283 2280, 2500, 0, 720, 725, 730, 750, 0,
1284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1285 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1286 /* 109 - 1280x720@48Hz 64:27 */
1287 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1288 2280, 2500, 0, 720, 725, 730, 750, 0,
1289 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1290 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1291 /* 110 - 1680x720@48Hz 64:27 */
1292 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 2490,
1293 2530, 2750, 0, 720, 725, 730, 750, 0,
1294 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1295 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1296 /* 111 - 1920x1080@48Hz 16:9 */
1297 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1298 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1300 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1301 /* 112 - 1920x1080@48Hz 64:27 */
1302 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1303 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1305 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1306 /* 113 - 2560x1080@48Hz 64:27 */
1307 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 3558,
1308 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1309 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1310 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1311 /* 114 - 3840x2160@48Hz 16:9 */
1312 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1313 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1314 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1315 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1316 /* 115 - 4096x2160@48Hz 256:135 */
1317 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5116,
1318 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1319 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1320 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1321 /* 116 - 3840x2160@48Hz 64:27 */
1322 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1323 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1324 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1325 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1326 /* 117 - 3840x2160@100Hz 16:9 */
1327 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1328 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1329 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1330 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1331 /* 118 - 3840x2160@120Hz 16:9 */
1332 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1333 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1334 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1335 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1336 /* 119 - 3840x2160@100Hz 64:27 */
1337 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1338 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1339 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1340 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1341 /* 120 - 3840x2160@120Hz 64:27 */
1342 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1343 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1344 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1345 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1346 /* 121 - 5120x2160@24Hz 64:27 */
1347 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 7116,
1348 7204, 7500, 0, 2160, 2168, 2178, 2200, 0,
1349 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1350 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1351 /* 122 - 5120x2160@25Hz 64:27 */
1352 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 6816,
1353 6904, 7200, 0, 2160, 2168, 2178, 2200, 0,
1354 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1355 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1356 /* 123 - 5120x2160@30Hz 64:27 */
1357 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 5784,
1358 5872, 6000, 0, 2160, 2168, 2178, 2200, 0,
1359 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1360 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1361 /* 124 - 5120x2160@48Hz 64:27 */
1362 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5866,
1363 5954, 6250, 0, 2160, 2168, 2178, 2475, 0,
1364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1365 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1366 /* 125 - 5120x2160@50Hz 64:27 */
1367 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 6216,
1368 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1369 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1370 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1371 /* 126 - 5120x2160@60Hz 64:27 */
1372 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5284,
1373 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
1374 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1375 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1376 /* 127 - 5120x2160@100Hz 64:27 */
1377 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 6216,
1378 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1379 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1380 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001381};
1382
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001383/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001384 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001385 */
1386static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001387 /* 0 - dummy, VICs start at 1 */
1388 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001389 /* 1 - 3840x2160@30Hz */
1390 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1391 3840, 4016, 4104, 4400, 0,
1392 2160, 2168, 2178, 2250, 0,
1393 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001394 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001395 /* 2 - 3840x2160@25Hz */
1396 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1397 3840, 4896, 4984, 5280, 0,
1398 2160, 2168, 2178, 2250, 0,
1399 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001400 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001401 /* 3 - 3840x2160@24Hz */
1402 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1403 3840, 5116, 5204, 5500, 0,
1404 2160, 2168, 2178, 2250, 0,
1405 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001406 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001407 /* 4 - 4096x2160@24Hz (SMPTE) */
1408 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1409 4096, 5116, 5204, 5500, 0,
1410 2160, 2168, 2178, 2250, 0,
1411 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001412 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001413};
1414
Adam Jackson61e57a82010-03-29 21:43:18 +00001415/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001416
Adam Jackson083ae052009-09-23 17:30:45 -04001417static const u8 edid_header[] = {
1418 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1419};
Dave Airlief453ba02008-11-07 14:05:41 -08001420
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001421/**
1422 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1423 * @raw_edid: pointer to raw base EDID block
1424 *
1425 * Sanity check the header of the base EDID block.
1426 *
1427 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001428 */
1429int drm_edid_header_is_valid(const u8 *raw_edid)
1430{
1431 int i, score = 0;
1432
1433 for (i = 0; i < sizeof(edid_header); i++)
1434 if (raw_edid[i] == edid_header[i])
1435 score++;
1436
1437 return score;
1438}
1439EXPORT_SYMBOL(drm_edid_header_is_valid);
1440
Adam Jackson47819ba2012-05-30 16:42:39 -04001441static int edid_fixup __read_mostly = 6;
1442module_param_named(edid_fixup, edid_fixup, int, 0400);
1443MODULE_PARM_DESC(edid_fixup,
1444 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001445
Dave Airlie40d9b042014-10-20 16:29:33 +10001446static void drm_get_displayid(struct drm_connector *connector,
1447 struct edid *edid);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04001448static int validate_displayid(u8 *displayid, int length, int idx);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001449
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001450static int drm_edid_block_checksum(const u8 *raw_edid)
1451{
1452 int i;
1453 u8 csum = 0;
1454 for (i = 0; i < EDID_LENGTH; i++)
1455 csum += raw_edid[i];
1456
1457 return csum;
1458}
1459
Stefan Brünsd6885d62014-11-30 19:57:41 +01001460static bool drm_edid_is_zero(const u8 *in_edid, int length)
1461{
1462 if (memchr_inv(in_edid, 0, length))
1463 return false;
1464
1465 return true;
1466}
1467
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001468/**
1469 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1470 * @raw_edid: pointer to raw EDID block
1471 * @block: type of block to validate (0 for base, extension otherwise)
1472 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001473 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001474 *
1475 * Validate a base or extension EDID block and optionally dump bad blocks to
1476 * the console.
1477 *
1478 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001479 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001480bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1481 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001482{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001483 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001484 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001485
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001486 if (WARN_ON(!raw_edid))
1487 return false;
1488
Adam Jackson47819ba2012-05-30 16:42:39 -04001489 if (edid_fixup > 8 || edid_fixup < 0)
1490 edid_fixup = 6;
1491
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001492 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001493 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001494 if (score == 8) {
1495 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001496 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001497 } else if (score >= edid_fixup) {
1498 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1499 * The corrupt flag needs to be set here otherwise, the
1500 * fix-up code here will correct the problem, the
1501 * checksum is correct and the test fails
1502 */
1503 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001504 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001505 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1506 memcpy(raw_edid, edid_header, sizeof(edid_header));
1507 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001508 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001509 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001510 goto bad;
1511 }
1512 }
Dave Airlief453ba02008-11-07 14:05:41 -08001513
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001514 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001515 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001516 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001517 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001518
Adam Jackson4a638b42010-05-25 16:33:09 -04001519 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001520 if (raw_edid[0] == CEA_EXT) {
1521 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1522 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1523 } else {
1524 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001525 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001526
Adam Jackson4a638b42010-05-25 16:33:09 -04001527 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001528 }
Dave Airlief453ba02008-11-07 14:05:41 -08001529 }
1530
Adam Jackson61e57a82010-03-29 21:43:18 +00001531 /* per-block-type checks */
1532 switch (raw_edid[0]) {
1533 case 0: /* base */
1534 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001535 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001536 goto bad;
1537 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001538
Adam Jackson61e57a82010-03-29 21:43:18 +00001539 if (edid->revision > 4)
1540 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1541 break;
1542
1543 default:
1544 break;
1545 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001546
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001547 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001548
1549bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001550 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001551 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001552 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001553 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001554 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001555 print_hex_dump(KERN_NOTICE,
1556 " \t", DUMP_PREFIX_NONE, 16, 1,
1557 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001558 }
Dave Airlief453ba02008-11-07 14:05:41 -08001559 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001560 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001561}
Carsten Emdeda0df922012-03-18 22:37:33 +01001562EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001563
1564/**
1565 * drm_edid_is_valid - sanity check EDID data
1566 * @edid: EDID data
1567 *
1568 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001569 *
1570 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001571 */
1572bool drm_edid_is_valid(struct edid *edid)
1573{
1574 int i;
1575 u8 *raw = (u8 *)edid;
1576
1577 if (!edid)
1578 return false;
1579
1580 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001581 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001582 return false;
1583
1584 return true;
1585}
Alex Deucher3c537882010-02-05 04:21:19 -05001586EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001587
Adam Jackson61e57a82010-03-29 21:43:18 +00001588#define DDC_SEGMENT_ADDR 0x30
1589/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001590 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001591 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001592 * @buf: EDID data buffer to be filled
1593 * @block: 128 byte EDID block to start fetching from
1594 * @len: EDID data buffer length to fetch
1595 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001596 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001597 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001598 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001599 */
1600static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001601drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001602{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001603 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001604 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001605 unsigned char segment = block >> 1;
1606 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001607 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001608
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001609 /*
1610 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001611 * adapter reports EAGAIN. However, we find that bit-banging transfers
1612 * are susceptible to errors under a heavily loaded machine and
1613 * generate spurious NAKs and timeouts. Retrying the transfer
1614 * of the individual block a few times seems to overcome this.
1615 */
1616 do {
1617 struct i2c_msg msgs[] = {
1618 {
Shirish Scd004b32012-08-30 07:04:06 +00001619 .addr = DDC_SEGMENT_ADDR,
1620 .flags = 0,
1621 .len = 1,
1622 .buf = &segment,
1623 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001624 .addr = DDC_ADDR,
1625 .flags = 0,
1626 .len = 1,
1627 .buf = &start,
1628 }, {
1629 .addr = DDC_ADDR,
1630 .flags = I2C_M_RD,
1631 .len = len,
1632 .buf = buf,
1633 }
1634 };
Shirish Scd004b32012-08-30 07:04:06 +00001635
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001636 /*
1637 * Avoid sending the segment addr to not upset non-compliant
1638 * DDC monitors.
1639 */
Shirish Scd004b32012-08-30 07:04:06 +00001640 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1641
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001642 if (ret == -ENXIO) {
1643 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1644 adapter->name);
1645 break;
1646 }
Shirish Scd004b32012-08-30 07:04:06 +00001647 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001648
Shirish Scd004b32012-08-30 07:04:06 +00001649 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001650}
1651
Chris Wilson14544d02016-10-24 12:38:21 +01001652static void connector_bad_edid(struct drm_connector *connector,
1653 u8 *edid, int num_blocks)
1654{
1655 int i;
1656
Jani Nikulaf0a8f532019-10-01 17:06:14 +03001657 if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
Chris Wilson14544d02016-10-24 12:38:21 +01001658 return;
1659
1660 dev_warn(connector->dev->dev,
1661 "%s: EDID is invalid:\n",
1662 connector->name);
1663 for (i = 0; i < num_blocks; i++) {
1664 u8 *block = edid + i * EDID_LENGTH;
1665 char prefix[20];
1666
1667 if (drm_edid_is_zero(block, EDID_LENGTH))
1668 sprintf(prefix, "\t[%02x] ZERO ", i);
1669 else if (!drm_edid_block_valid(block, i, false, NULL))
1670 sprintf(prefix, "\t[%02x] BAD ", i);
1671 else
1672 sprintf(prefix, "\t[%02x] GOOD ", i);
1673
1674 print_hex_dump(KERN_WARNING,
1675 prefix, DUMP_PREFIX_NONE, 16, 1,
1676 block, EDID_LENGTH, false);
1677 }
1678}
1679
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001680/* Get override or firmware EDID */
1681static struct edid *drm_get_override_edid(struct drm_connector *connector)
1682{
1683 struct edid *override = NULL;
1684
1685 if (connector->override_edid)
1686 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1687
1688 if (!override)
1689 override = drm_load_edid_firmware(connector);
1690
1691 return IS_ERR(override) ? NULL : override;
1692}
1693
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001694/**
Jani Nikula48eaeb72019-06-10 12:30:54 +03001695 * drm_add_override_edid_modes - add modes from override/firmware EDID
1696 * @connector: connector we're probing
1697 *
1698 * Add modes from the override/firmware EDID, if available. Only to be used from
1699 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1700 * failed during drm_get_edid() and caused the override/firmware EDID to be
1701 * skipped.
1702 *
1703 * Return: The number of modes added or 0 if we couldn't find any.
1704 */
1705int drm_add_override_edid_modes(struct drm_connector *connector)
1706{
1707 struct edid *override;
1708 int num_modes = 0;
1709
1710 override = drm_get_override_edid(connector);
1711 if (override) {
1712 drm_connector_update_edid_property(connector, override);
1713 num_modes = drm_add_edid_modes(connector, override);
1714 kfree(override);
1715
1716 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1717 connector->base.id, connector->name, num_modes);
1718 }
1719
1720 return num_modes;
1721}
1722EXPORT_SYMBOL(drm_add_override_edid_modes);
1723
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001724/**
1725 * drm_do_get_edid - get EDID data using a custom EDID block read function
1726 * @connector: connector we're probing
1727 * @get_edid_block: EDID block read function
1728 * @data: private data passed to the block read function
1729 *
1730 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1731 * exposes a different interface to read EDID blocks this function can be used
1732 * to get EDID data using a custom block read function.
1733 *
1734 * As in the general case the DDC bus is accessible by the kernel at the I2C
1735 * level, drivers must make all reasonable efforts to expose it as an I2C
1736 * adapter and use drm_get_edid() instead of abusing this function.
1737 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001738 * The EDID may be overridden using debugfs override_edid or firmare EDID
1739 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1740 * order. Having either of them bypasses actual EDID reads.
1741 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001742 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1743 */
1744struct edid *drm_do_get_edid(struct drm_connector *connector,
1745 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1746 size_t len),
1747 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001748{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001749 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001750 u8 *edid, *new;
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001751 struct edid *override;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001752
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001753 override = drm_get_override_edid(connector);
1754 if (override)
Jani Nikula53fd40a2017-09-12 11:19:26 +03001755 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001756
Chris Wilsonf14f3682016-10-17 09:35:12 +01001757 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001758 return NULL;
1759
1760 /* base block fetch */
1761 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001762 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001763 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001764 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001765 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001766 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001767 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001768 connector->null_edid_counter++;
1769 goto carp;
1770 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001771 }
1772 if (i == 4)
1773 goto carp;
1774
1775 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001776 valid_extensions = edid[0x7e];
1777 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001778 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001779
Chris Wilson14544d02016-10-24 12:38:21 +01001780 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001781 if (!new)
1782 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001783 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001784
Chris Wilsonf14f3682016-10-17 09:35:12 +01001785 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001786 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001787
Adam Jackson61e57a82010-03-29 21:43:18 +00001788 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001789 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001790 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001791 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001792 break;
1793 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001794
Chris Wilson14544d02016-10-24 12:38:21 +01001795 if (i == 4)
1796 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001797 }
1798
Chris Wilsonf14f3682016-10-17 09:35:12 +01001799 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001800 u8 *base;
1801
1802 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1803
Chris Wilsonf14f3682016-10-17 09:35:12 +01001804 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1805 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001806
Kees Cook6da2ec52018-06-12 13:55:00 -07001807 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
1808 GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001809 if (!new)
1810 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001811
1812 base = new;
1813 for (i = 0; i <= edid[0x7e]; i++) {
1814 u8 *block = edid + i * EDID_LENGTH;
1815
1816 if (!drm_edid_block_valid(block, i, false, NULL))
1817 continue;
1818
1819 memcpy(base, block, EDID_LENGTH);
1820 base += EDID_LENGTH;
1821 }
1822
1823 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001824 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001825 }
1826
Chris Wilsonf14f3682016-10-17 09:35:12 +01001827 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001828
1829carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001830 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001831out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001832 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001833 return NULL;
1834}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001835EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001836
1837/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001838 * drm_probe_ddc() - probe DDC presence
1839 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001840 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001841 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001842 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001843bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001844drm_probe_ddc(struct i2c_adapter *adapter)
1845{
1846 unsigned char out;
1847
1848 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1849}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001850EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001851
1852/**
1853 * drm_get_edid - get EDID data, if available
1854 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001855 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001856 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001857 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001858 * attach it to the connector.
1859 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001860 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001861 */
1862struct edid *drm_get_edid(struct drm_connector *connector,
1863 struct i2c_adapter *adapter)
1864{
Dave Airlie40d9b042014-10-20 16:29:33 +10001865 struct edid *edid;
1866
Jani Nikula15f080f2017-02-17 17:20:53 +02001867 if (connector->force == DRM_FORCE_OFF)
1868 return NULL;
1869
1870 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001871 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001872
Dave Airlie40d9b042014-10-20 16:29:33 +10001873 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1874 if (edid)
1875 drm_get_displayid(connector, edid);
1876 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001877}
1878EXPORT_SYMBOL(drm_get_edid);
1879
Jani Nikula51f8da52013-09-27 15:08:27 +03001880/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001881 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1882 * @connector: connector we're probing
1883 * @adapter: I2C adapter to use for DDC
1884 *
1885 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1886 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1887 * switch DDC to the GPU which is retrieving EDID.
1888 *
1889 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1890 */
1891struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1892 struct i2c_adapter *adapter)
1893{
1894 struct pci_dev *pdev = connector->dev->pdev;
1895 struct edid *edid;
1896
1897 vga_switcheroo_lock_ddc(pdev);
1898 edid = drm_get_edid(connector, adapter);
1899 vga_switcheroo_unlock_ddc(pdev);
1900
1901 return edid;
1902}
1903EXPORT_SYMBOL(drm_get_edid_switcheroo);
1904
1905/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001906 * drm_edid_duplicate - duplicate an EDID and the extensions
1907 * @edid: EDID to duplicate
1908 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001909 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001910 */
1911struct edid *drm_edid_duplicate(const struct edid *edid)
1912{
1913 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1914}
1915EXPORT_SYMBOL(drm_edid_duplicate);
1916
Adam Jackson61e57a82010-03-29 21:43:18 +00001917/*** EDID parsing ***/
1918
Dave Airlief453ba02008-11-07 14:05:41 -08001919/**
1920 * edid_vendor - match a string against EDID's obfuscated vendor field
1921 * @edid: EDID to match
1922 * @vendor: vendor string
1923 *
1924 * Returns true if @vendor is in @edid, false otherwise
1925 */
Keith Packard170178f2017-12-13 00:44:26 -08001926static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001927{
1928 char edid_vendor[3];
1929
1930 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1931 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1932 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001933 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001934
1935 return !strncmp(edid_vendor, vendor, 3);
1936}
1937
1938/**
1939 * edid_get_quirks - return quirk flags for a given EDID
1940 * @edid: EDID to process
1941 *
1942 * This tells subsequent routines what fixes they need to apply.
1943 */
Keith Packard170178f2017-12-13 00:44:26 -08001944static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001945{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001946 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001947 int i;
1948
1949 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1950 quirk = &edid_quirk_list[i];
1951
1952 if (edid_vendor(edid, quirk->vendor) &&
1953 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1954 return quirk->quirks;
1955 }
1956
1957 return 0;
1958}
1959
1960#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001961#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001962
Dave Airlief453ba02008-11-07 14:05:41 -08001963/**
1964 * edid_fixup_preferred - set preferred modes based on quirk list
1965 * @connector: has mode list to fix up
1966 * @quirks: quirks list
1967 *
1968 * Walk the mode list for @connector, clearing the preferred status
1969 * on existing modes and setting it anew for the right mode ala @quirks.
1970 */
1971static void edid_fixup_preferred(struct drm_connector *connector,
1972 u32 quirks)
1973{
1974 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001975 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001976 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001977
1978 if (list_empty(&connector->probed_modes))
1979 return;
1980
1981 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1982 target_refresh = 60;
1983 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1984 target_refresh = 75;
1985
1986 preferred_mode = list_first_entry(&connector->probed_modes,
1987 struct drm_display_mode, head);
1988
1989 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1990 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1991
1992 if (cur_mode == preferred_mode)
1993 continue;
1994
1995 /* Largest mode is preferred */
1996 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1997 preferred_mode = cur_mode;
1998
Alex Deucher339d2022013-08-15 11:42:14 -04001999 cur_vrefresh = cur_mode->vrefresh ?
2000 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
2001 preferred_vrefresh = preferred_mode->vrefresh ?
2002 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002003 /* At a given size, try to get closest to target refresh */
2004 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04002005 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
2006 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08002007 preferred_mode = cur_mode;
2008 }
2009 }
2010
2011 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
2012}
2013
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002014static bool
2015mode_is_rb(const struct drm_display_mode *mode)
2016{
2017 return (mode->htotal - mode->hdisplay == 160) &&
2018 (mode->hsync_end - mode->hdisplay == 80) &&
2019 (mode->hsync_end - mode->hsync_start == 32) &&
2020 (mode->vsync_start - mode->vdisplay == 3);
2021}
2022
Adam Jackson33c75312012-04-13 16:33:29 -04002023/*
2024 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
2025 * @dev: Device to duplicate against
2026 * @hsize: Mode width
2027 * @vsize: Mode height
2028 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002029 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04002030 *
2031 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002032 *
2033 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04002034 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002035struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002036 int hsize, int vsize, int fresh,
2037 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08002038{
Adam Jackson07a5e632009-12-03 17:44:38 -05002039 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08002040
Thierry Redinga6b21832012-11-23 15:01:42 +01002041 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002042 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002043 if (hsize != ptr->hdisplay)
2044 continue;
2045 if (vsize != ptr->vdisplay)
2046 continue;
2047 if (fresh != drm_mode_vrefresh(ptr))
2048 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002049 if (rb != mode_is_rb(ptr))
2050 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002051
2052 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08002053 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002054
2055 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002056}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002057EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04002058
Adam Jacksond1ff6402010-03-29 21:43:26 +00002059typedef void detailed_cb(struct detailed_timing *timing, void *closure);
2060
2061static void
Adam Jackson4d76a222010-08-03 14:38:17 -04002062cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2063{
2064 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002065 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04002066 u8 *det_base = ext + d;
2067
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002068 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04002069 for (i = 0; i < n; i++)
2070 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2071}
2072
2073static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002074vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2075{
2076 unsigned int i, n = min((int)ext[0x02], 6);
2077 u8 *det_base = ext + 5;
2078
2079 if (ext[0x01] != 1)
2080 return; /* unknown version */
2081
2082 for (i = 0; i < n; i++)
2083 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2084}
2085
2086static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00002087drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
2088{
2089 int i;
2090 struct edid *edid = (struct edid *)raw_edid;
2091
2092 if (edid == NULL)
2093 return;
2094
2095 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
2096 cb(&(edid->detailed_timings[i]), closure);
2097
Adam Jackson4d76a222010-08-03 14:38:17 -04002098 for (i = 1; i <= raw_edid[0x7e]; i++) {
2099 u8 *ext = raw_edid + (i * EDID_LENGTH);
2100 switch (*ext) {
2101 case CEA_EXT:
2102 cea_for_each_detailed_block(ext, cb, closure);
2103 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002104 case VTB_EXT:
2105 vtb_for_each_detailed_block(ext, cb, closure);
2106 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04002107 default:
2108 break;
2109 }
2110 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00002111}
2112
2113static void
2114is_rb(struct detailed_timing *t, void *data)
2115{
2116 u8 *r = (u8 *)t;
2117 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
2118 if (r[15] & 0x10)
2119 *(bool *)data = true;
2120}
2121
2122/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2123static bool
2124drm_monitor_supports_rb(struct edid *edid)
2125{
2126 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02002127 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00002128 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2129 return ret;
2130 }
2131
2132 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2133}
2134
Adam Jackson7a374352010-03-29 21:43:30 +00002135static void
2136find_gtf2(struct detailed_timing *t, void *data)
2137{
2138 u8 *r = (u8 *)t;
2139 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
2140 *(u8 **)data = r;
2141}
2142
2143/* Secondary GTF curve kicks in above some break frequency */
2144static int
2145drm_gtf2_hbreak(struct edid *edid)
2146{
2147 u8 *r = NULL;
2148 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2149 return r ? (r[12] * 2) : 0;
2150}
2151
2152static int
2153drm_gtf2_2c(struct edid *edid)
2154{
2155 u8 *r = NULL;
2156 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2157 return r ? r[13] : 0;
2158}
2159
2160static int
2161drm_gtf2_m(struct edid *edid)
2162{
2163 u8 *r = NULL;
2164 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2165 return r ? (r[15] << 8) + r[14] : 0;
2166}
2167
2168static int
2169drm_gtf2_k(struct edid *edid)
2170{
2171 u8 *r = NULL;
2172 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2173 return r ? r[16] : 0;
2174}
2175
2176static int
2177drm_gtf2_2j(struct edid *edid)
2178{
2179 u8 *r = NULL;
2180 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2181 return r ? r[17] : 0;
2182}
2183
2184/**
2185 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2186 * @edid: EDID block to scan
2187 */
2188static int standard_timing_level(struct edid *edid)
2189{
2190 if (edid->revision >= 2) {
2191 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2192 return LEVEL_CVT;
2193 if (drm_gtf2_hbreak(edid))
2194 return LEVEL_GTF2;
Lee Shawn Cbfef04a2019-10-07 21:51:27 +08002195 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
2196 return LEVEL_GTF;
Adam Jackson7a374352010-03-29 21:43:30 +00002197 }
2198 return LEVEL_DMT;
2199}
2200
Adam Jackson23425ca2009-09-23 17:30:58 -04002201/*
2202 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2203 * monitors fill with ascii space (0x20) instead.
2204 */
2205static int
2206bad_std_timing(u8 a, u8 b)
2207{
2208 return (a == 0x00 && b == 0x00) ||
2209 (a == 0x01 && b == 0x01) ||
2210 (a == 0x20 && b == 0x20);
2211}
2212
Dave Airlief453ba02008-11-07 14:05:41 -08002213/**
2214 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002215 * @connector: connector of for the EDID block
2216 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002217 * @t: standard timing params
2218 *
2219 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002220 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002221 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002222static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002223drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002224 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002225{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002226 struct drm_device *dev = connector->dev;
2227 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002228 int hsize, vsize;
2229 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002230 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2231 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002232 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2233 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002234 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002235
Adam Jackson23425ca2009-09-23 17:30:58 -04002236 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2237 return NULL;
2238
Zhao Yakui5c612592009-06-22 13:17:10 +08002239 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2240 hsize = t->hsize * 8 + 248;
2241 /* vrefresh_rate = vfreq + 60 */
2242 vrefresh_rate = vfreq + 60;
2243 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002244 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002245 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002246 vsize = hsize;
2247 else
2248 vsize = (hsize * 10) / 16;
2249 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002250 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002251 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002252 vsize = (hsize * 4) / 5;
2253 else
2254 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002255
2256 /* HDTV hack, part 1 */
2257 if (vrefresh_rate == 60 &&
2258 ((hsize == 1360 && vsize == 765) ||
2259 (hsize == 1368 && vsize == 769))) {
2260 hsize = 1366;
2261 vsize = 768;
2262 }
2263
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002264 /*
2265 * If this connector already has a mode for this size and refresh
2266 * rate (because it came from detailed or CVT info), use that
2267 * instead. This way we don't have to guess at interlace or
2268 * reduced blanking.
2269 */
Adam Jackson522032d2010-04-09 16:52:49 +00002270 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002271 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2272 drm_mode_vrefresh(m) == vrefresh_rate)
2273 return NULL;
2274
Adam Jacksona0910c82010-03-29 21:43:28 +00002275 /* HDTV hack, part 2 */
2276 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2277 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002278 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002279 if (!mode)
2280 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002281 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002282 mode->hsync_start = mode->hsync_start - 1;
2283 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002284 return mode;
2285 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002286
Zhao Yakui559ee212009-09-03 09:33:47 +08002287 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002288 if (drm_monitor_supports_rb(edid)) {
2289 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2290 true);
2291 if (mode)
2292 return mode;
2293 }
2294 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002295 if (mode)
2296 return mode;
2297
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002298 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002299 switch (timing_level) {
2300 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002301 break;
2302 case LEVEL_GTF:
2303 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2304 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002305 case LEVEL_GTF2:
2306 /*
2307 * This is potentially wrong if there's ever a monitor with
2308 * more than one ranges section, each claiming a different
2309 * secondary GTF curve. Please don't do that.
2310 */
2311 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002312 if (!mode)
2313 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002314 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002315 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002316 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2317 vrefresh_rate, 0, 0,
2318 drm_gtf2_m(edid),
2319 drm_gtf2_2c(edid),
2320 drm_gtf2_k(edid),
2321 drm_gtf2_2j(edid));
2322 }
2323 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002324 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002325 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2326 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002327 break;
2328 }
Dave Airlief453ba02008-11-07 14:05:41 -08002329 return mode;
2330}
2331
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002332/*
2333 * EDID is delightfully ambiguous about how interlaced modes are to be
2334 * encoded. Our internal representation is of frame height, but some
2335 * HDTV detailed timings are encoded as field height.
2336 *
2337 * The format list here is from CEA, in frame size. Technically we
2338 * should be checking refresh rate too. Whatever.
2339 */
2340static void
2341drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2342 struct detailed_pixel_timing *pt)
2343{
2344 int i;
2345 static const struct {
2346 int w, h;
2347 } cea_interlaced[] = {
2348 { 1920, 1080 },
2349 { 720, 480 },
2350 { 1440, 480 },
2351 { 2880, 480 },
2352 { 720, 576 },
2353 { 1440, 576 },
2354 { 2880, 576 },
2355 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002356
2357 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2358 return;
2359
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002360 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002361 if ((mode->hdisplay == cea_interlaced[i].w) &&
2362 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2363 mode->vdisplay *= 2;
2364 mode->vsync_start *= 2;
2365 mode->vsync_end *= 2;
2366 mode->vtotal *= 2;
2367 mode->vtotal |= 1;
2368 }
2369 }
2370
2371 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2372}
2373
Dave Airlief453ba02008-11-07 14:05:41 -08002374/**
2375 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2376 * @dev: DRM device (needed to create new mode)
2377 * @edid: EDID block
2378 * @timing: EDID detailed timing info
2379 * @quirks: quirks to apply
2380 *
2381 * An EDID detailed timing block contains enough info for us to create and
2382 * return a new struct drm_display_mode.
2383 */
2384static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2385 struct edid *edid,
2386 struct detailed_timing *timing,
2387 u32 quirks)
2388{
2389 struct drm_display_mode *mode;
2390 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002391 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2392 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2393 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2394 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002395 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2396 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 +01002397 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 +02002398 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 -08002399
Adam Jacksonfc438962009-06-04 10:20:34 +10002400 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002401 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002402 return NULL;
2403
Michel Dänzer0454bea2009-06-15 16:56:07 +02002404 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002405 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002406 return NULL;
2407 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002408 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002409 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002410 }
2411
Zhao Yakuifcb45612009-10-14 09:11:25 +08002412 /* it is incorrect if hsync/vsync width is zero */
2413 if (!hsync_pulse_width || !vsync_pulse_width) {
2414 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2415 "Wrong Hsync/Vsync pulse width\n");
2416 return NULL;
2417 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002418
2419 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2420 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2421 if (!mode)
2422 return NULL;
2423
2424 goto set_size;
2425 }
2426
Dave Airlief453ba02008-11-07 14:05:41 -08002427 mode = drm_mode_create(dev);
2428 if (!mode)
2429 return NULL;
2430
Dave Airlief453ba02008-11-07 14:05:41 -08002431 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002432 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002433
Michel Dänzer0454bea2009-06-15 16:56:07 +02002434 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002435
Michel Dänzer0454bea2009-06-15 16:56:07 +02002436 mode->hdisplay = hactive;
2437 mode->hsync_start = mode->hdisplay + hsync_offset;
2438 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2439 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002440
Michel Dänzer0454bea2009-06-15 16:56:07 +02002441 mode->vdisplay = vactive;
2442 mode->vsync_start = mode->vdisplay + vsync_offset;
2443 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2444 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002445
Jesse Barnes7064fef2009-11-05 10:12:54 -08002446 /* Some EDIDs have bogus h/vtotal values */
2447 if (mode->hsync_end > mode->htotal)
2448 mode->htotal = mode->hsync_end + 1;
2449 if (mode->vsync_end > mode->vtotal)
2450 mode->vtotal = mode->vsync_end + 1;
2451
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002452 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002453
2454 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002455 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002456 }
2457
Michel Dänzer0454bea2009-06-15 16:56:07 +02002458 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2459 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2460 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2461 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002462
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002463set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002464 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2465 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002466
2467 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2468 mode->width_mm *= 10;
2469 mode->height_mm *= 10;
2470 }
2471
2472 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2473 mode->width_mm = edid->width_cm * 10;
2474 mode->height_mm = edid->height_cm * 10;
2475 }
2476
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002477 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002478 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002479 drm_mode_set_name(mode);
2480
Dave Airlief453ba02008-11-07 14:05:41 -08002481 return mode;
2482}
2483
Adam Jackson07a5e632009-12-03 17:44:38 -05002484static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002485mode_in_hsync_range(const struct drm_display_mode *mode,
2486 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002487{
2488 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002489
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002490 hmin = t[7];
2491 if (edid->revision >= 4)
2492 hmin += ((t[4] & 0x04) ? 255 : 0);
2493 hmax = t[8];
2494 if (edid->revision >= 4)
2495 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002496 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002497
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002498 return (hsync <= hmax && hsync >= hmin);
2499}
2500
2501static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002502mode_in_vsync_range(const struct drm_display_mode *mode,
2503 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002504{
2505 int vsync, vmin, vmax;
2506
2507 vmin = t[5];
2508 if (edid->revision >= 4)
2509 vmin += ((t[4] & 0x01) ? 255 : 0);
2510 vmax = t[6];
2511 if (edid->revision >= 4)
2512 vmax += ((t[4] & 0x02) ? 255 : 0);
2513 vsync = drm_mode_vrefresh(mode);
2514
2515 return (vsync <= vmax && vsync >= vmin);
2516}
2517
2518static u32
2519range_pixel_clock(struct edid *edid, u8 *t)
2520{
2521 /* unspecified */
2522 if (t[9] == 0 || t[9] == 255)
2523 return 0;
2524
2525 /* 1.4 with CVT support gives us real precision, yay */
2526 if (edid->revision >= 4 && t[10] == 0x04)
2527 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2528
2529 /* 1.3 is pathetic, so fuzz up a bit */
2530 return t[9] * 10000 + 5001;
2531}
2532
Adam Jackson07a5e632009-12-03 17:44:38 -05002533static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002534mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002535 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002536{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002537 u32 max_clock;
2538 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002539
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002540 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002541 return false;
2542
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002543 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002544 return false;
2545
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002546 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002547 if (mode->clock > max_clock)
2548 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002549
2550 /* 1.4 max horizontal check */
2551 if (edid->revision >= 4 && t[10] == 0x04)
2552 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2553 return false;
2554
2555 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2556 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002557
2558 return true;
2559}
2560
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002561static bool valid_inferred_mode(const struct drm_connector *connector,
2562 const struct drm_display_mode *mode)
2563{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002564 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002565 bool ok = false;
2566
2567 list_for_each_entry(m, &connector->probed_modes, head) {
2568 if (mode->hdisplay == m->hdisplay &&
2569 mode->vdisplay == m->vdisplay &&
2570 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2571 return false; /* duplicated */
2572 if (mode->hdisplay <= m->hdisplay &&
2573 mode->vdisplay <= m->vdisplay)
2574 ok = true;
2575 }
2576 return ok;
2577}
2578
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002579static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002580drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002581 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002582{
2583 int i, modes = 0;
2584 struct drm_display_mode *newmode;
2585 struct drm_device *dev = connector->dev;
2586
Thierry Redinga6b21832012-11-23 15:01:42 +01002587 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002588 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2589 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002590 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2591 if (newmode) {
2592 drm_mode_probed_add(connector, newmode);
2593 modes++;
2594 }
2595 }
2596 }
2597
2598 return modes;
2599}
2600
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002601/* fix up 1366x768 mode from 1368x768;
2602 * GFT/CVT can't express 1366 width which isn't dividable by 8
2603 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002604void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002605{
2606 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2607 mode->hdisplay = 1366;
2608 mode->hsync_start--;
2609 mode->hsync_end--;
2610 drm_mode_set_name(mode);
2611 }
2612}
2613
Adam Jacksonb309bd32012-04-13 16:33:40 -04002614static int
2615drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2616 struct detailed_timing *timing)
2617{
2618 int i, modes = 0;
2619 struct drm_display_mode *newmode;
2620 struct drm_device *dev = connector->dev;
2621
Thierry Redinga6b21832012-11-23 15:01:42 +01002622 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002623 const struct minimode *m = &extra_modes[i];
2624 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002625 if (!newmode)
2626 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002627
Takashi Iwai969218f2017-01-17 17:43:29 +01002628 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002629 if (!mode_in_range(newmode, edid, timing) ||
2630 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002631 drm_mode_destroy(dev, newmode);
2632 continue;
2633 }
2634
2635 drm_mode_probed_add(connector, newmode);
2636 modes++;
2637 }
2638
2639 return modes;
2640}
2641
2642static int
2643drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2644 struct detailed_timing *timing)
2645{
2646 int i, modes = 0;
2647 struct drm_display_mode *newmode;
2648 struct drm_device *dev = connector->dev;
2649 bool rb = drm_monitor_supports_rb(edid);
2650
Thierry Redinga6b21832012-11-23 15:01:42 +01002651 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002652 const struct minimode *m = &extra_modes[i];
2653 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002654 if (!newmode)
2655 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002656
Takashi Iwai969218f2017-01-17 17:43:29 +01002657 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002658 if (!mode_in_range(newmode, edid, timing) ||
2659 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002660 drm_mode_destroy(dev, newmode);
2661 continue;
2662 }
2663
2664 drm_mode_probed_add(connector, newmode);
2665 modes++;
2666 }
2667
2668 return modes;
2669}
2670
Adam Jackson13931572010-08-03 14:38:19 -04002671static void
2672do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002673{
Adam Jackson13931572010-08-03 14:38:19 -04002674 struct detailed_mode_closure *closure = c;
2675 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002676 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002677
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002678 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2679 return;
2680
2681 closure->modes += drm_dmt_modes_for_range(closure->connector,
2682 closure->edid,
2683 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002684
2685 if (!version_greater(closure->edid, 1, 1))
2686 return; /* GTF not defined yet */
2687
2688 switch (range->flags) {
2689 case 0x02: /* secondary gtf, XXX could do more */
2690 case 0x00: /* default gtf */
2691 closure->modes += drm_gtf_modes_for_range(closure->connector,
2692 closure->edid,
2693 timing);
2694 break;
2695 case 0x04: /* cvt, only in 1.4+ */
2696 if (!version_greater(closure->edid, 1, 3))
2697 break;
2698
2699 closure->modes += drm_cvt_modes_for_range(closure->connector,
2700 closure->edid,
2701 timing);
2702 break;
2703 case 0x01: /* just the ranges, no formula */
2704 default:
2705 break;
2706 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002707}
2708
Adam Jackson13931572010-08-03 14:38:19 -04002709static int
2710add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2711{
2712 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002713 .connector = connector,
2714 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002715 };
2716
2717 if (version_greater(edid, 1, 0))
2718 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2719 &closure);
2720
2721 return closure.modes;
2722}
2723
Adam Jackson2255be12010-03-29 21:43:22 +00002724static int
2725drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2726{
2727 int i, j, m, modes = 0;
2728 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002729 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002730
2731 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002732 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002733 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002734 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002735 break;
2736 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002737 mode = drm_mode_find_dmt(connector->dev,
2738 est3_modes[m].w,
2739 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002740 est3_modes[m].r,
2741 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002742 if (mode) {
2743 drm_mode_probed_add(connector, mode);
2744 modes++;
2745 }
2746 }
2747 }
2748 }
2749
2750 return modes;
2751}
2752
Adam Jackson13931572010-08-03 14:38:19 -04002753static void
2754do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002755{
Adam Jackson13931572010-08-03 14:38:19 -04002756 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002757 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002758
2759 if (data->type == EDID_DETAIL_EST_TIMINGS)
2760 closure->modes += drm_est3_modes(closure->connector, timing);
2761}
2762
2763/**
2764 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002765 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002766 * @edid: EDID block to scan
2767 *
2768 * Each EDID block contains a bitmap of the supported "established modes" list
2769 * (defined above). Tease them out and add them to the global modes list.
2770 */
2771static int
2772add_established_modes(struct drm_connector *connector, struct edid *edid)
2773{
Adam Jackson9cf00972009-12-03 17:44:36 -05002774 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002775 unsigned long est_bits = edid->established_timings.t1 |
2776 (edid->established_timings.t2 << 8) |
2777 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2778 int i, modes = 0;
2779 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002780 .connector = connector,
2781 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002782 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002783
Adam Jackson13931572010-08-03 14:38:19 -04002784 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2785 if (est_bits & (1<<i)) {
2786 struct drm_display_mode *newmode;
2787 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2788 if (newmode) {
2789 drm_mode_probed_add(connector, newmode);
2790 modes++;
2791 }
2792 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002793 }
2794
Adam Jackson13931572010-08-03 14:38:19 -04002795 if (version_greater(edid, 1, 0))
2796 drm_for_each_detailed_block((u8 *)edid,
2797 do_established_modes, &closure);
2798
2799 return modes + closure.modes;
2800}
2801
2802static void
2803do_standard_modes(struct detailed_timing *timing, void *c)
2804{
2805 struct detailed_mode_closure *closure = c;
2806 struct detailed_non_pixel *data = &timing->data.other_data;
2807 struct drm_connector *connector = closure->connector;
2808 struct edid *edid = closure->edid;
2809
2810 if (data->type == EDID_DETAIL_STD_MODES) {
2811 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002812 for (i = 0; i < 6; i++) {
2813 struct std_timing *std;
2814 struct drm_display_mode *newmode;
2815
2816 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002817 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002818 if (newmode) {
2819 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002820 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002821 }
2822 }
Adam Jackson13931572010-08-03 14:38:19 -04002823 }
2824}
2825
2826/**
2827 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002828 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002829 * @edid: EDID block to scan
2830 *
2831 * Standard modes can be calculated using the appropriate standard (DMT,
2832 * GTF or CVT. Grab them from @edid and add them to the list.
2833 */
2834static int
2835add_standard_modes(struct drm_connector *connector, struct edid *edid)
2836{
2837 int i, modes = 0;
2838 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002839 .connector = connector,
2840 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002841 };
2842
2843 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2844 struct drm_display_mode *newmode;
2845
2846 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002847 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002848 if (newmode) {
2849 drm_mode_probed_add(connector, newmode);
2850 modes++;
2851 }
2852 }
2853
2854 if (version_greater(edid, 1, 0))
2855 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2856 &closure);
2857
2858 /* XXX should also look for standard codes in VTB blocks */
2859
2860 return modes + closure.modes;
2861}
2862
Dave Airlief453ba02008-11-07 14:05:41 -08002863static int drm_cvt_modes(struct drm_connector *connector,
2864 struct detailed_timing *timing)
2865{
2866 int i, j, modes = 0;
2867 struct drm_display_mode *newmode;
2868 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002869 struct cvt_timing *cvt;
2870 const int rates[] = { 60, 85, 75, 60, 50 };
2871 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002872
2873 for (i = 0; i < 4; i++) {
2874 int uninitialized_var(width), height;
2875 cvt = &(timing->data.other_data.data.cvt[i]);
2876
2877 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002878 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002879
2880 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002881 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002882 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002883 width = height * 4 / 3;
2884 break;
2885 case 0x04:
2886 width = height * 16 / 9;
2887 break;
2888 case 0x08:
2889 width = height * 16 / 10;
2890 break;
2891 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002892 width = height * 15 / 9;
2893 break;
2894 }
2895
2896 for (j = 1; j < 5; j++) {
2897 if (cvt->code[2] & (1 << j)) {
2898 newmode = drm_cvt_mode(dev, width, height,
2899 rates[j], j == 0,
2900 false, false);
2901 if (newmode) {
2902 drm_mode_probed_add(connector, newmode);
2903 modes++;
2904 }
2905 }
2906 }
2907 }
2908
2909 return modes;
2910}
2911
Adam Jackson13931572010-08-03 14:38:19 -04002912static void
2913do_cvt_mode(struct detailed_timing *timing, void *c)
2914{
2915 struct detailed_mode_closure *closure = c;
2916 struct detailed_non_pixel *data = &timing->data.other_data;
2917
2918 if (data->type == EDID_DETAIL_CVT_3BYTE)
2919 closure->modes += drm_cvt_modes(closure->connector, timing);
2920}
Adam Jackson9cf00972009-12-03 17:44:36 -05002921
2922static int
Adam Jackson13931572010-08-03 14:38:19 -04002923add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2924{
2925 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002926 .connector = connector,
2927 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002928 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002929
Adam Jackson13931572010-08-03 14:38:19 -04002930 if (version_greater(edid, 1, 2))
2931 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002932
Adam Jackson13931572010-08-03 14:38:19 -04002933 /* XXX should also look for CVT codes in VTB blocks */
2934
2935 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002936}
2937
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002938static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2939
Adam Jackson13931572010-08-03 14:38:19 -04002940static void
2941do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002942{
Adam Jackson13931572010-08-03 14:38:19 -04002943 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002944 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002945
2946 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002947 newmode = drm_mode_detailed(closure->connector->dev,
2948 closure->edid, timing,
2949 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002950 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002951 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002952
Adam Jackson13931572010-08-03 14:38:19 -04002953 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002954 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2955
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002956 /*
2957 * Detailed modes are limited to 10kHz pixel clock resolution,
2958 * so fix up anything that looks like CEA/HDMI mode, but the clock
2959 * is just slightly off.
2960 */
2961 fixup_detailed_cea_mode_clock(newmode);
2962
Adam Jackson13931572010-08-03 14:38:19 -04002963 drm_mode_probed_add(closure->connector, newmode);
2964 closure->modes++;
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002965 closure->preferred = false;
Zhao Yakui882f0212009-08-26 18:20:49 +08002966 }
Ma Ling167f3a02009-03-20 14:09:48 +08002967}
2968
Adam Jackson13931572010-08-03 14:38:19 -04002969/*
2970 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002971 * @connector: attached connector
2972 * @edid: EDID block to scan
2973 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002974 */
Adam Jackson13931572010-08-03 14:38:19 -04002975static int
2976add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2977 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002978{
Adam Jackson13931572010-08-03 14:38:19 -04002979 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002980 .connector = connector,
2981 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002982 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02002983 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002984 };
Dave Airlief453ba02008-11-07 14:05:41 -08002985
Adam Jackson13931572010-08-03 14:38:19 -04002986 if (closure.preferred && !version_greater(edid, 1, 3))
2987 closure.preferred =
2988 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002989
Adam Jackson13931572010-08-03 14:38:19 -04002990 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002991
Adam Jackson13931572010-08-03 14:38:19 -04002992 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002993}
Dave Airlief453ba02008-11-07 14:05:41 -08002994
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002995#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002996#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002997#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002998#define SPEAKER_BLOCK 0x04
Uma Shankare85959d2019-05-16 19:40:08 +05302999#define HDR_STATIC_METADATA_BLOCK 0x6
Shashank Sharma87563fc2017-07-13 21:03:10 +05303000#define USE_EXTENDED_TAG 0x07
3001#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05303002#define EXT_VIDEO_DATA_BLOCK_420 0x0E
3003#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003004#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003005#define EDID_CEA_YCRCB444 (1 << 5)
3006#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003007#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003008
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01003009/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003010 * Search EDID for CEA extension block.
3011 */
Keith Packard170178f2017-12-13 00:44:26 -08003012static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003013{
3014 u8 *edid_ext = NULL;
3015 int i;
3016
3017 /* No EDID or EDID extensions */
3018 if (edid == NULL || edid->extensions == 0)
3019 return NULL;
3020
3021 /* Find CEA extension */
3022 for (i = 0; i < edid->extensions; i++) {
3023 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10003024 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003025 break;
3026 }
3027
3028 if (i == edid->extensions)
3029 return NULL;
3030
3031 return edid_ext;
3032}
3033
Dave Airlie40d9b042014-10-20 16:29:33 +10003034
Keith Packard170178f2017-12-13 00:44:26 -08003035static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10003036{
3037 return drm_find_edid_extension(edid, DISPLAYID_EXT);
3038}
3039
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003040static u8 *drm_find_cea_extension(const struct edid *edid)
3041{
3042 int ret;
3043 int idx = 1;
3044 int length = EDID_LENGTH;
3045 struct displayid_block *block;
3046 u8 *cea;
3047 u8 *displayid;
3048
3049 /* Look for a top level CEA extension block */
3050 cea = drm_find_edid_extension(edid, CEA_EXT);
3051 if (cea)
3052 return cea;
3053
3054 /* CEA blocks can also be found embedded in a DisplayID block */
3055 displayid = drm_find_displayid_extension(edid);
3056 if (!displayid)
3057 return NULL;
3058
3059 ret = validate_displayid(displayid, length, idx);
3060 if (ret)
3061 return NULL;
3062
3063 idx += sizeof(struct displayid_hdr);
3064 for_each_displayid_db(displayid, block, idx, length) {
3065 if (block->tag == DATA_BLOCK_CTA) {
3066 cea = (u8 *)block;
3067 break;
3068 }
3069 }
3070
3071 return cea;
3072}
3073
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003074/*
3075 * Calculate the alternate clock for the CEA mode
3076 * (60Hz vs. 59.94Hz etc.)
3077 */
3078static unsigned int
3079cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
3080{
3081 unsigned int clock = cea_mode->clock;
3082
3083 if (cea_mode->vrefresh % 6 != 0)
3084 return clock;
3085
3086 /*
3087 * edid_cea_modes contains the 59.94Hz
3088 * variant for 240 and 480 line modes,
3089 * and the 60Hz variant otherwise.
3090 */
3091 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003092 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003093 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003094 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003095
3096 return clock;
3097}
3098
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003099static bool
3100cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
3101{
3102 /*
3103 * For certain VICs the spec allows the vertical
3104 * front porch to vary by one or two lines.
3105 *
3106 * cea_modes[] stores the variant with the shortest
3107 * vertical front porch. We can adjust the mode to
3108 * get the other variants by simply increasing the
3109 * vertical front porch length.
3110 */
3111 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
3112 edid_cea_modes[9].vtotal != 262 ||
3113 edid_cea_modes[12].vtotal != 262 ||
3114 edid_cea_modes[13].vtotal != 262 ||
3115 edid_cea_modes[23].vtotal != 312 ||
3116 edid_cea_modes[24].vtotal != 312 ||
3117 edid_cea_modes[27].vtotal != 312 ||
3118 edid_cea_modes[28].vtotal != 312);
3119
3120 if (((vic == 8 || vic == 9 ||
3121 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3122 ((vic == 23 || vic == 24 ||
3123 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3124 mode->vsync_start++;
3125 mode->vsync_end++;
3126 mode->vtotal++;
3127
3128 return true;
3129 }
3130
3131 return false;
3132}
3133
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003134static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3135 unsigned int clock_tolerance)
3136{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303137 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003138 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003139
3140 if (!to_match->clock)
3141 return 0;
3142
Ville Syrjälä357768c2018-05-08 16:39:38 +05303143 if (to_match->picture_aspect_ratio)
3144 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3145
Jani Nikulad9278b42016-01-08 13:21:51 +02003146 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003147 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003148 unsigned int clock1, clock2;
3149
3150 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003151 clock1 = cea_mode.clock;
3152 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003153
3154 if (abs(to_match->clock - clock1) > clock_tolerance &&
3155 abs(to_match->clock - clock2) > clock_tolerance)
3156 continue;
3157
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003158 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303159 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003160 return vic;
3161 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003162 }
3163
3164 return 0;
3165}
3166
Thierry Reding18316c82012-12-20 15:41:44 +01003167/**
3168 * drm_match_cea_mode - look for a CEA mode matching given mode
3169 * @to_match: display mode
3170 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003171 * 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 +01003172 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00003173 */
Thierry Reding18316c82012-12-20 15:41:44 +01003174u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00003175{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303176 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003177 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00003178
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003179 if (!to_match->clock)
3180 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00003181
Ville Syrjälä357768c2018-05-08 16:39:38 +05303182 if (to_match->picture_aspect_ratio)
3183 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3184
Jani Nikulad9278b42016-01-08 13:21:51 +02003185 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003186 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003187 unsigned int clock1, clock2;
3188
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003189 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003190 clock1 = cea_mode.clock;
3191 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003192
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003193 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3194 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3195 continue;
3196
3197 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303198 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003199 return vic;
3200 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00003201 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003202
Stephane Marchesina4799032012-11-09 16:21:05 +00003203 return 0;
3204}
3205EXPORT_SYMBOL(drm_match_cea_mode);
3206
Jani Nikulad9278b42016-01-08 13:21:51 +02003207static bool drm_valid_cea_vic(u8 vic)
3208{
3209 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
3210}
3211
Ville Syrjälä28c03a442019-10-04 17:19:11 +03003212static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303213{
Jani Nikulad9278b42016-01-08 13:21:51 +02003214 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303215}
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303216
Wayne Lind2b43472019-11-18 18:18:31 +08003217static enum hdmi_picture_aspect drm_get_hdmi_aspect_ratio(const u8 video_code)
3218{
3219 return edid_4k_modes[video_code].picture_aspect_ratio;
3220}
3221
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003222/*
3223 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3224 * specific block).
3225 *
3226 * It's almost like cea_mode_alternate_clock(), we just need to add an
3227 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3228 * one.
3229 */
3230static unsigned int
3231hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3232{
3233 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3234 return hdmi_mode->clock;
3235
3236 return cea_mode_alternate_clock(hdmi_mode);
3237}
3238
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003239static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3240 unsigned int clock_tolerance)
3241{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303242 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003243 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003244
3245 if (!to_match->clock)
3246 return 0;
3247
Wayne Lind2b43472019-11-18 18:18:31 +08003248 if (to_match->picture_aspect_ratio)
3249 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3250
Jani Nikulad9278b42016-01-08 13:21:51 +02003251 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3252 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003253 unsigned int clock1, clock2;
3254
3255 /* Make sure to also match alternate clocks */
3256 clock1 = hdmi_mode->clock;
3257 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3258
3259 if (abs(to_match->clock - clock1) > clock_tolerance &&
3260 abs(to_match->clock - clock2) > clock_tolerance)
3261 continue;
3262
Ville Syrjälä357768c2018-05-08 16:39:38 +05303263 if (drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003264 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003265 }
3266
3267 return 0;
3268}
3269
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003270/*
3271 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3272 * @to_match: display mode
3273 *
3274 * An HDMI mode is one defined in the HDMI vendor specific block.
3275 *
3276 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3277 */
3278static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3279{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303280 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003281 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003282
3283 if (!to_match->clock)
3284 return 0;
3285
Wayne Lind2b43472019-11-18 18:18:31 +08003286 if (to_match->picture_aspect_ratio)
3287 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3288
Jani Nikulad9278b42016-01-08 13:21:51 +02003289 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3290 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003291 unsigned int clock1, clock2;
3292
3293 /* Make sure to also match alternate clocks */
3294 clock1 = hdmi_mode->clock;
3295 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3296
3297 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3298 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Ville Syrjälä357768c2018-05-08 16:39:38 +05303299 drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003300 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003301 }
3302 return 0;
3303}
3304
Jani Nikulad9278b42016-01-08 13:21:51 +02003305static bool drm_valid_hdmi_vic(u8 vic)
3306{
3307 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3308}
3309
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003310static int
3311add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3312{
3313 struct drm_device *dev = connector->dev;
3314 struct drm_display_mode *mode, *tmp;
3315 LIST_HEAD(list);
3316 int modes = 0;
3317
3318 /* Don't add CEA modes if the CEA extension block is missing */
3319 if (!drm_find_cea_extension(edid))
3320 return 0;
3321
3322 /*
3323 * Go through all probed modes and create a new mode
3324 * with the alternate clock for certain CEA modes.
3325 */
3326 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003327 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003328 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003329 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003330 unsigned int clock1, clock2;
3331
Jani Nikulad9278b42016-01-08 13:21:51 +02003332 if (drm_valid_cea_vic(vic)) {
3333 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003334 clock2 = cea_mode_alternate_clock(cea_mode);
3335 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003336 vic = drm_match_hdmi_mode(mode);
3337 if (drm_valid_hdmi_vic(vic)) {
3338 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003339 clock2 = hdmi_mode_alternate_clock(cea_mode);
3340 }
3341 }
3342
3343 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003344 continue;
3345
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003346 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003347
3348 if (clock1 == clock2)
3349 continue;
3350
3351 if (mode->clock != clock1 && mode->clock != clock2)
3352 continue;
3353
3354 newmode = drm_mode_duplicate(dev, cea_mode);
3355 if (!newmode)
3356 continue;
3357
Damien Lespiau27130212013-09-25 16:45:28 +01003358 /* Carry over the stereo flags */
3359 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3360
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003361 /*
3362 * The current mode could be either variant. Make
3363 * sure to pick the "other" clock for the new mode.
3364 */
3365 if (mode->clock != clock1)
3366 newmode->clock = clock1;
3367 else
3368 newmode->clock = clock2;
3369
3370 list_add_tail(&newmode->head, &list);
3371 }
3372
3373 list_for_each_entry_safe(mode, tmp, &list, head) {
3374 list_del(&mode->head);
3375 drm_mode_probed_add(connector, mode);
3376 modes++;
3377 }
3378
3379 return modes;
3380}
Stephane Marchesina4799032012-11-09 16:21:05 +00003381
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303382static u8 svd_to_vic(u8 svd)
3383{
3384 /* 0-6 bit vic, 7th bit native mode indicator */
3385 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3386 return svd & 127;
3387
3388 return svd;
3389}
3390
Thomas Woodaff04ac2013-11-29 15:33:27 +00003391static struct drm_display_mode *
3392drm_display_mode_from_vic_index(struct drm_connector *connector,
3393 const u8 *video_db, u8 video_len,
3394 u8 video_index)
3395{
3396 struct drm_device *dev = connector->dev;
3397 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003398 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003399
3400 if (video_db == NULL || video_index >= video_len)
3401 return NULL;
3402
3403 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303404 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003405 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003406 return NULL;
3407
Jani Nikulad9278b42016-01-08 13:21:51 +02003408 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003409 if (!newmode)
3410 return NULL;
3411
Thomas Woodaff04ac2013-11-29 15:33:27 +00003412 newmode->vrefresh = 0;
3413
3414 return newmode;
3415}
3416
Shashank Sharma832d4f22017-07-14 16:03:46 +05303417/*
3418 * do_y420vdb_modes - Parse YCBCR 420 only modes
3419 * @connector: connector corresponding to the HDMI sink
3420 * @svds: start of the data block of CEA YCBCR 420 VDB
3421 * @len: length of the CEA YCBCR 420 VDB
3422 *
3423 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3424 * which contains modes which can be supported in YCBCR 420
3425 * output format only.
3426 */
3427static int do_y420vdb_modes(struct drm_connector *connector,
3428 const u8 *svds, u8 svds_len)
3429{
3430 int modes = 0, i;
3431 struct drm_device *dev = connector->dev;
3432 struct drm_display_info *info = &connector->display_info;
3433 struct drm_hdmi_info *hdmi = &info->hdmi;
3434
3435 for (i = 0; i < svds_len; i++) {
3436 u8 vic = svd_to_vic(svds[i]);
3437 struct drm_display_mode *newmode;
3438
3439 if (!drm_valid_cea_vic(vic))
3440 continue;
3441
3442 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3443 if (!newmode)
3444 break;
3445 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3446 drm_mode_probed_add(connector, newmode);
3447 modes++;
3448 }
3449
3450 if (modes > 0)
3451 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3452 return modes;
3453}
3454
3455/*
3456 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3457 * @connector: connector corresponding to the HDMI sink
3458 * @vic: CEA vic for the video mode to be added in the map
3459 *
3460 * Makes an entry for a videomode in the YCBCR 420 bitmap
3461 */
3462static void
3463drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3464{
3465 u8 vic = svd_to_vic(svd);
3466 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3467
3468 if (!drm_valid_cea_vic(vic))
3469 return;
3470
3471 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3472}
3473
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003474static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003475do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003476{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003477 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303478 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003479
Thomas Woodaff04ac2013-11-29 15:33:27 +00003480 for (i = 0; i < len; i++) {
3481 struct drm_display_mode *mode;
3482 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3483 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303484 /*
3485 * YCBCR420 capability block contains a bitmap which
3486 * gives the index of CEA modes from CEA VDB, which
3487 * can support YCBCR 420 sampling output also (apart
3488 * from RGB/YCBCR444 etc).
3489 * For example, if the bit 0 in bitmap is set,
3490 * first mode in VDB can support YCBCR420 output too.
3491 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3492 */
3493 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3494 drm_add_cmdb_modes(connector, db[i]);
3495
Thomas Woodaff04ac2013-11-29 15:33:27 +00003496 drm_mode_probed_add(connector, mode);
3497 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003498 }
3499 }
3500
3501 return modes;
3502}
3503
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003504struct stereo_mandatory_mode {
3505 int width, height, vrefresh;
3506 unsigned int flags;
3507};
3508
3509static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003510 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3511 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003512 { 1920, 1080, 50,
3513 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3514 { 1920, 1080, 60,
3515 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003516 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3517 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3518 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3519 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003520};
3521
3522static bool
3523stereo_match_mandatory(const struct drm_display_mode *mode,
3524 const struct stereo_mandatory_mode *stereo_mode)
3525{
3526 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3527
3528 return mode->hdisplay == stereo_mode->width &&
3529 mode->vdisplay == stereo_mode->height &&
3530 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3531 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3532}
3533
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003534static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3535{
3536 struct drm_device *dev = connector->dev;
3537 const struct drm_display_mode *mode;
3538 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003539 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003540
3541 INIT_LIST_HEAD(&stereo_modes);
3542
3543 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003544 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3545 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003546 struct drm_display_mode *new_mode;
3547
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003548 if (!stereo_match_mandatory(mode,
3549 &stereo_mandatory_modes[i]))
3550 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003551
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003552 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003553 new_mode = drm_mode_duplicate(dev, mode);
3554 if (!new_mode)
3555 continue;
3556
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003557 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003558 list_add_tail(&new_mode->head, &stereo_modes);
3559 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003560 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003561 }
3562
3563 list_splice_tail(&stereo_modes, &connector->probed_modes);
3564
3565 return modes;
3566}
3567
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003568static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3569{
3570 struct drm_device *dev = connector->dev;
3571 struct drm_display_mode *newmode;
3572
Jani Nikulad9278b42016-01-08 13:21:51 +02003573 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003574 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3575 return 0;
3576 }
3577
3578 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3579 if (!newmode)
3580 return 0;
3581
3582 drm_mode_probed_add(connector, newmode);
3583
3584 return 1;
3585}
3586
Thomas Woodfbf46022013-10-16 15:58:50 +01003587static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3588 const u8 *video_db, u8 video_len, u8 video_index)
3589{
Thomas Woodfbf46022013-10-16 15:58:50 +01003590 struct drm_display_mode *newmode;
3591 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003592
3593 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003594 newmode = drm_display_mode_from_vic_index(connector, video_db,
3595 video_len,
3596 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003597 if (newmode) {
3598 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3599 drm_mode_probed_add(connector, newmode);
3600 modes++;
3601 }
3602 }
3603 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003604 newmode = drm_display_mode_from_vic_index(connector, video_db,
3605 video_len,
3606 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003607 if (newmode) {
3608 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3609 drm_mode_probed_add(connector, newmode);
3610 modes++;
3611 }
3612 }
3613 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003614 newmode = drm_display_mode_from_vic_index(connector, video_db,
3615 video_len,
3616 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003617 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003618 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003619 drm_mode_probed_add(connector, newmode);
3620 modes++;
3621 }
3622 }
3623
3624 return modes;
3625}
3626
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003627/*
3628 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3629 * @connector: connector corresponding to the HDMI sink
3630 * @db: start of the CEA vendor specific block
3631 * @len: length of the CEA block payload, ie. one can access up to db[len]
3632 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003633 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3634 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003635 */
3636static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003637do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3638 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003639{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003640 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003641 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003642 u8 vic_len, hdmi_3d_len = 0;
3643 u16 mask;
3644 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003645
3646 if (len < 8)
3647 goto out;
3648
3649 /* no HDMI_Video_Present */
3650 if (!(db[8] & (1 << 5)))
3651 goto out;
3652
3653 /* Latency_Fields_Present */
3654 if (db[8] & (1 << 7))
3655 offset += 2;
3656
3657 /* I_Latency_Fields_Present */
3658 if (db[8] & (1 << 6))
3659 offset += 2;
3660
3661 /* the declared length is not long enough for the 2 first bytes
3662 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003663 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003664 goto out;
3665
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003666 /* 3D_Present */
3667 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003668 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003669 modes += add_hdmi_mandatory_stereo_modes(connector);
3670
Thomas Woodfbf46022013-10-16 15:58:50 +01003671 /* 3D_Multi_present */
3672 multi_present = (db[8 + offset] & 0x60) >> 5;
3673 }
3674
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003675 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003676 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003677 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003678
3679 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003680 u8 vic;
3681
3682 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003683 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003684 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003685 offset += 1 + vic_len;
3686
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003687 if (multi_present == 1)
3688 multi_len = 2;
3689 else if (multi_present == 2)
3690 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003691 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003692 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003693
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003694 if (len < (8 + offset + hdmi_3d_len - 1))
3695 goto out;
3696
3697 if (hdmi_3d_len < multi_len)
3698 goto out;
3699
3700 if (multi_present == 1 || multi_present == 2) {
3701 /* 3D_Structure_ALL */
3702 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3703
3704 /* check if 3D_MASK is present */
3705 if (multi_present == 2)
3706 mask = (db[10 + offset] << 8) | db[11 + offset];
3707 else
3708 mask = 0xffff;
3709
3710 for (i = 0; i < 16; i++) {
3711 if (mask & (1 << i))
3712 modes += add_3d_struct_modes(connector,
3713 structure_all,
3714 video_db,
3715 video_len, i);
3716 }
3717 }
3718
3719 offset += multi_len;
3720
3721 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3722 int vic_index;
3723 struct drm_display_mode *newmode = NULL;
3724 unsigned int newflag = 0;
3725 bool detail_present;
3726
3727 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3728
3729 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3730 break;
3731
3732 /* 2D_VIC_order_X */
3733 vic_index = db[8 + offset + i] >> 4;
3734
3735 /* 3D_Structure_X */
3736 switch (db[8 + offset + i] & 0x0f) {
3737 case 0:
3738 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3739 break;
3740 case 6:
3741 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3742 break;
3743 case 8:
3744 /* 3D_Detail_X */
3745 if ((db[9 + offset + i] >> 4) == 1)
3746 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3747 break;
3748 }
3749
3750 if (newflag != 0) {
3751 newmode = drm_display_mode_from_vic_index(connector,
3752 video_db,
3753 video_len,
3754 vic_index);
3755
3756 if (newmode) {
3757 newmode->flags |= newflag;
3758 drm_mode_probed_add(connector, newmode);
3759 modes++;
3760 }
3761 }
3762
3763 if (detail_present)
3764 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003765 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003766
3767out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003768 if (modes > 0)
3769 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003770 return modes;
3771}
3772
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003773static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003774cea_db_payload_len(const u8 *db)
3775{
3776 return db[0] & 0x1f;
3777}
3778
3779static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303780cea_db_extended_tag(const u8 *db)
3781{
3782 return db[1];
3783}
3784
3785static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003786cea_db_tag(const u8 *db)
3787{
3788 return db[0] >> 5;
3789}
3790
3791static int
3792cea_revision(const u8 *cea)
3793{
3794 return cea[1];
3795}
3796
3797static int
3798cea_db_offsets(const u8 *cea, int *start, int *end)
3799{
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003800 /* DisplayID CTA extension blocks and top-level CEA EDID
3801 * block header definitions differ in the following bytes:
3802 * 1) Byte 2 of the header specifies length differently,
3803 * 2) Byte 3 is only present in the CEA top level block.
3804 *
3805 * The different definitions for byte 2 follow.
3806 *
3807 * DisplayID CTA extension block defines byte 2 as:
3808 * Number of payload bytes
3809 *
3810 * CEA EDID block defines byte 2 as:
3811 * Byte number (decimal) within this block where the 18-byte
3812 * DTDs begin. If no non-DTD data is present in this extension
3813 * block, the value should be set to 04h (the byte after next).
3814 * If set to 00h, there are no DTDs present in this block and
3815 * no non-DTD data.
3816 */
3817 if (cea[0] == DATA_BLOCK_CTA) {
3818 *start = 3;
3819 *end = *start + cea[2];
3820 } else if (cea[0] == CEA_EXT) {
3821 /* Data block offset in CEA extension block */
3822 *start = 4;
3823 *end = cea[2];
3824 if (*end == 0)
3825 *end = 127;
3826 if (*end < 4 || *end > 127)
3827 return -ERANGE;
3828 } else {
Daniel Vetterc7581a42019-09-04 16:39:42 +02003829 return -EOPNOTSUPP;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003830 }
3831
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003832 return 0;
3833}
3834
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003835static bool cea_db_is_hdmi_vsdb(const u8 *db)
3836{
3837 int hdmi_id;
3838
3839 if (cea_db_tag(db) != VENDOR_BLOCK)
3840 return false;
3841
3842 if (cea_db_payload_len(db) < 5)
3843 return false;
3844
3845 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3846
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003847 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003848}
3849
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303850static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3851{
3852 unsigned int oui;
3853
3854 if (cea_db_tag(db) != VENDOR_BLOCK)
3855 return false;
3856
3857 if (cea_db_payload_len(db) < 7)
3858 return false;
3859
3860 oui = db[3] << 16 | db[2] << 8 | db[1];
3861
3862 return oui == HDMI_FORUM_IEEE_OUI;
3863}
3864
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02003865static bool cea_db_is_vcdb(const u8 *db)
3866{
3867 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3868 return false;
3869
3870 if (cea_db_payload_len(db) != 2)
3871 return false;
3872
3873 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
3874 return false;
3875
3876 return true;
3877}
3878
Shashank Sharma832d4f22017-07-14 16:03:46 +05303879static bool cea_db_is_y420cmdb(const u8 *db)
3880{
3881 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3882 return false;
3883
3884 if (!cea_db_payload_len(db))
3885 return false;
3886
3887 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3888 return false;
3889
3890 return true;
3891}
3892
3893static bool cea_db_is_y420vdb(const u8 *db)
3894{
3895 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3896 return false;
3897
3898 if (!cea_db_payload_len(db))
3899 return false;
3900
3901 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3902 return false;
3903
3904 return true;
3905}
3906
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003907#define for_each_cea_db(cea, i, start, end) \
3908 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3909
Shashank Sharma832d4f22017-07-14 16:03:46 +05303910static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3911 const u8 *db)
3912{
3913 struct drm_display_info *info = &connector->display_info;
3914 struct drm_hdmi_info *hdmi = &info->hdmi;
3915 u8 map_len = cea_db_payload_len(db) - 1;
3916 u8 count;
3917 u64 map = 0;
3918
3919 if (map_len == 0) {
3920 /* All CEA modes support ycbcr420 sampling also.*/
3921 hdmi->y420_cmdb_map = U64_MAX;
3922 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3923 return;
3924 }
3925
3926 /*
3927 * This map indicates which of the existing CEA block modes
3928 * from VDB can support YCBCR420 output too. So if bit=0 is
3929 * set, first mode from VDB can support YCBCR420 output too.
3930 * We will parse and keep this map, before parsing VDB itself
3931 * to avoid going through the same block again and again.
3932 *
3933 * Spec is not clear about max possible size of this block.
3934 * Clamping max bitmap block size at 8 bytes. Every byte can
3935 * address 8 CEA modes, in this way this map can address
3936 * 8*8 = first 64 SVDs.
3937 */
3938 if (WARN_ON_ONCE(map_len > 8))
3939 map_len = 8;
3940
3941 for (count = 0; count < map_len; count++)
3942 map |= (u64)db[2 + count] << (8 * count);
3943
3944 if (map)
3945 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3946
3947 hdmi->y420_cmdb_map = map;
3948}
3949
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003950static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003951add_cea_modes(struct drm_connector *connector, struct edid *edid)
3952{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003953 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003954 const u8 *db, *hdmi = NULL, *video = NULL;
3955 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003956 int modes = 0;
3957
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003958 if (cea && cea_revision(cea) >= 3) {
3959 int i, start, end;
3960
3961 if (cea_db_offsets(cea, &start, &end))
3962 return 0;
3963
3964 for_each_cea_db(cea, i, start, end) {
3965 db = &cea[i];
3966 dbl = cea_db_payload_len(db);
3967
Thomas Woodfbf46022013-10-16 15:58:50 +01003968 if (cea_db_tag(db) == VIDEO_BLOCK) {
3969 video = db + 1;
3970 video_len = dbl;
3971 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303972 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003973 hdmi = db;
3974 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303975 } else if (cea_db_is_y420vdb(db)) {
3976 const u8 *vdb420 = &db[2];
3977
3978 /* Add 4:2:0(only) modes present in EDID */
3979 modes += do_y420vdb_modes(connector,
3980 vdb420,
3981 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003982 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003983 }
3984 }
3985
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003986 /*
3987 * We parse the HDMI VSDB after having added the cea modes as we will
3988 * be patching their flags when the sink supports stereo 3D.
3989 */
3990 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003991 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3992 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003993
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003994 return modes;
3995}
3996
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003997static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3998{
3999 const struct drm_display_mode *cea_mode;
4000 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02004001 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004002 const char *type;
4003
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02004004 /*
4005 * allow 5kHz clock difference either way to account for
4006 * the 10kHz clock resolution limit of detailed timings.
4007 */
Jani Nikulad9278b42016-01-08 13:21:51 +02004008 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
4009 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004010 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02004011 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004012 clock1 = cea_mode->clock;
4013 clock2 = cea_mode_alternate_clock(cea_mode);
4014 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02004015 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
4016 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004017 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02004018 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004019 clock1 = cea_mode->clock;
4020 clock2 = hdmi_mode_alternate_clock(cea_mode);
4021 } else {
4022 return;
4023 }
4024 }
4025
4026 /* pick whichever is closest */
4027 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
4028 clock = clock1;
4029 else
4030 clock = clock2;
4031
4032 if (mode->clock == clock)
4033 return;
4034
4035 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02004036 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004037 mode->clock = clock;
4038}
4039
Uma Shankare85959d2019-05-16 19:40:08 +05304040static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
4041{
4042 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4043 return false;
4044
4045 if (db[1] != HDR_STATIC_METADATA_BLOCK)
4046 return false;
4047
4048 if (cea_db_payload_len(db) < 3)
4049 return false;
4050
4051 return true;
4052}
4053
4054static uint8_t eotf_supported(const u8 *edid_ext)
4055{
4056 return edid_ext[2] &
4057 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
4058 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
Ville Syrjäläb5e3eed2019-05-16 19:40:12 +05304059 BIT(HDMI_EOTF_SMPTE_ST2084) |
4060 BIT(HDMI_EOTF_BT_2100_HLG));
Uma Shankare85959d2019-05-16 19:40:08 +05304061}
4062
4063static uint8_t hdr_metadata_type(const u8 *edid_ext)
4064{
4065 return edid_ext[3] &
4066 BIT(HDMI_STATIC_METADATA_TYPE1);
4067}
4068
4069static void
4070drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
4071{
4072 u16 len;
4073
4074 len = cea_db_payload_len(db);
4075
4076 connector->hdr_sink_metadata.hdmi_type1.eotf =
4077 eotf_supported(db);
4078 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
4079 hdr_metadata_type(db);
4080
4081 if (len >= 4)
4082 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
4083 if (len >= 5)
4084 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
4085 if (len >= 6)
4086 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
4087}
4088
Wu Fengguang76adaa342011-09-05 14:23:20 +08004089static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004090drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004091{
Ville Syrjälä85040722012-08-16 14:55:05 +00004092 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004093
Jani Nikulaf7da77852017-11-01 16:20:57 +02004094 if (len >= 6 && (db[6] & (1 << 7)))
4095 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00004096 if (len >= 8) {
4097 connector->latency_present[0] = db[8] >> 7;
4098 connector->latency_present[1] = (db[8] >> 6) & 1;
4099 }
4100 if (len >= 9)
4101 connector->video_latency[0] = db[9];
4102 if (len >= 10)
4103 connector->audio_latency[0] = db[10];
4104 if (len >= 11)
4105 connector->video_latency[1] = db[11];
4106 if (len >= 12)
4107 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004108
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004109 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4110 "video latency %d %d, "
4111 "audio latency %d %d\n",
4112 connector->latency_present[0],
4113 connector->latency_present[1],
4114 connector->video_latency[0],
4115 connector->video_latency[1],
4116 connector->audio_latency[0],
4117 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004118}
4119
4120static void
4121monitor_name(struct detailed_timing *t, void *data)
4122{
4123 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
4124 *(u8 **)data = t->data.other_data.data.str.str;
4125}
4126
Jim Bride59f7c0f2016-04-14 10:18:35 -07004127static int get_monitor_name(struct edid *edid, char name[13])
4128{
4129 char *edid_name = NULL;
4130 int mnl;
4131
4132 if (!edid || !name)
4133 return 0;
4134
4135 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4136 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4137 if (edid_name[mnl] == 0x0a)
4138 break;
4139
4140 name[mnl] = edid_name[mnl];
4141 }
4142
4143 return mnl;
4144}
4145
4146/**
4147 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4148 * @edid: monitor EDID information
4149 * @name: pointer to a character array to hold the name of the monitor
4150 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4151 *
4152 */
4153void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4154{
4155 int name_length;
4156 char buf[13];
4157
4158 if (bufsize <= 0)
4159 return;
4160
4161 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4162 memcpy(name, buf, name_length);
4163 name[name_length] = '\0';
4164}
4165EXPORT_SYMBOL(drm_edid_get_monitor_name);
4166
Jani Nikula42750d32017-11-01 16:21:00 +02004167static void clear_eld(struct drm_connector *connector)
4168{
4169 memset(connector->eld, 0, sizeof(connector->eld));
4170
4171 connector->latency_present[0] = false;
4172 connector->latency_present[1] = false;
4173 connector->video_latency[0] = 0;
4174 connector->audio_latency[0] = 0;
4175 connector->video_latency[1] = 0;
4176 connector->audio_latency[1] = 0;
4177}
4178
Jani Nikula79436a12017-11-01 16:21:03 +02004179/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08004180 * drm_edid_to_eld - build ELD from EDID
4181 * @connector: connector corresponding to the HDMI/DP sink
4182 * @edid: EDID to parse
4183 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004184 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02004185 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004186 */
Jani Nikula79436a12017-11-01 16:21:03 +02004187static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004188{
4189 uint8_t *eld = connector->eld;
4190 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004191 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02004192 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004193 int mnl;
4194 int dbl;
4195
Jani Nikula42750d32017-11-01 16:21:00 +02004196 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03004197
Jani Nikulae9bd0b82017-02-17 17:20:52 +02004198 if (!edid)
4199 return;
4200
Wu Fengguang76adaa342011-09-05 14:23:20 +08004201 cea = drm_find_cea_extension(edid);
4202 if (!cea) {
4203 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4204 return;
4205 }
4206
Jani Nikulaf7da77852017-11-01 16:20:57 +02004207 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4208 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07004209
Jani Nikulaf7da77852017-11-01 16:20:57 +02004210 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4211 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004212
Jani Nikulaf7da77852017-11-01 16:20:57 +02004213 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004214
Jani Nikulaf7da77852017-11-01 16:20:57 +02004215 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4216 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4217 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4218 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004219
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004220 if (cea_revision(cea) >= 3) {
4221 int i, start, end;
4222
4223 if (cea_db_offsets(cea, &start, &end)) {
4224 start = 0;
4225 end = 0;
4226 }
4227
4228 for_each_cea_db(cea, i, start, end) {
4229 db = &cea[i];
4230 dbl = cea_db_payload_len(db);
4231
4232 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02004233 int sad_count;
4234
Christian Schmidta0ab7342011-12-19 20:03:38 +01004235 case AUDIO_BLOCK:
4236 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02004237 sad_count = min(dbl / 3, 15 - total_sad_count);
4238 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004239 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02004240 &db[1], sad_count * 3);
4241 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01004242 break;
4243 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004244 /* Speaker Allocation Data Block */
4245 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004246 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01004247 break;
4248 case VENDOR_BLOCK:
4249 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004250 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004251 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01004252 break;
4253 default:
4254 break;
4255 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08004256 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004257 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02004258 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004259
Jani Nikula1d1c3662017-11-01 16:20:58 +02004260 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4261 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4262 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4263 else
4264 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004265
Jani Nikula938fd8a2014-10-28 16:20:48 +02004266 eld[DRM_ELD_BASELINE_ELD_LEN] =
4267 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4268
4269 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02004270 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004271}
Wu Fengguang76adaa342011-09-05 14:23:20 +08004272
4273/**
Rafał Miłeckife214162013-04-19 19:01:25 +02004274 * drm_edid_to_sad - extracts SADs from EDID
4275 * @edid: EDID to parse
4276 * @sads: pointer that will be set to the extracted SADs
4277 *
4278 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02004279 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004280 * Note: The returned pointer needs to be freed using kfree().
4281 *
4282 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02004283 */
4284int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4285{
4286 int count = 0;
4287 int i, start, end, dbl;
4288 u8 *cea;
4289
4290 cea = drm_find_cea_extension(edid);
4291 if (!cea) {
4292 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004293 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004294 }
4295
4296 if (cea_revision(cea) < 3) {
4297 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004298 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004299 }
4300
4301 if (cea_db_offsets(cea, &start, &end)) {
4302 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4303 return -EPROTO;
4304 }
4305
4306 for_each_cea_db(cea, i, start, end) {
4307 u8 *db = &cea[i];
4308
4309 if (cea_db_tag(db) == AUDIO_BLOCK) {
4310 int j;
4311 dbl = cea_db_payload_len(db);
4312
4313 count = dbl / 3; /* SAD is 3B */
4314 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4315 if (!*sads)
4316 return -ENOMEM;
4317 for (j = 0; j < count; j++) {
4318 u8 *sad = &db[1 + j * 3];
4319
4320 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4321 (*sads)[j].channels = sad[0] & 0x7;
4322 (*sads)[j].freq = sad[1] & 0x7F;
4323 (*sads)[j].byte2 = sad[2];
4324 }
4325 break;
4326 }
4327 }
4328
4329 return count;
4330}
4331EXPORT_SYMBOL(drm_edid_to_sad);
4332
4333/**
Alex Deucherd105f472013-07-25 15:55:32 -04004334 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4335 * @edid: EDID to parse
4336 * @sadb: pointer to the speaker block
4337 *
4338 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004339 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004340 * Note: The returned pointer needs to be freed using kfree().
4341 *
4342 * Return: The number of found Speaker Allocation Blocks or negative number on
4343 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004344 */
4345int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4346{
4347 int count = 0;
4348 int i, start, end, dbl;
4349 const u8 *cea;
4350
4351 cea = drm_find_cea_extension(edid);
4352 if (!cea) {
4353 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004354 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004355 }
4356
4357 if (cea_revision(cea) < 3) {
4358 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004359 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004360 }
4361
4362 if (cea_db_offsets(cea, &start, &end)) {
4363 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4364 return -EPROTO;
4365 }
4366
4367 for_each_cea_db(cea, i, start, end) {
4368 const u8 *db = &cea[i];
4369
4370 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4371 dbl = cea_db_payload_len(db);
4372
4373 /* Speaker Allocation Data Block */
4374 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004375 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004376 if (!*sadb)
4377 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004378 count = dbl;
4379 break;
4380 }
4381 }
4382 }
4383
4384 return count;
4385}
4386EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4387
4388/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004389 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004390 * @connector: connector associated with the HDMI/DP sink
4391 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004392 *
4393 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4394 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004395 */
4396int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004397 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004398{
4399 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4400 int a, v;
4401
4402 if (!connector->latency_present[0])
4403 return 0;
4404 if (!connector->latency_present[1])
4405 i = 0;
4406
4407 a = connector->audio_latency[i];
4408 v = connector->video_latency[i];
4409
4410 /*
4411 * HDMI/DP sink doesn't support audio or video?
4412 */
4413 if (a == 255 || v == 255)
4414 return 0;
4415
4416 /*
4417 * Convert raw EDID values to millisecond.
4418 * Treat unknown latency as 0ms.
4419 */
4420 if (a)
4421 a = min(2 * (a - 1), 500);
4422 if (v)
4423 v = min(2 * (v - 1), 500);
4424
4425 return max(v - a, 0);
4426}
4427EXPORT_SYMBOL(drm_av_sync_delay);
4428
4429/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004430 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004431 * @edid: monitor EDID information
4432 *
4433 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004434 *
4435 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004436 */
4437bool drm_detect_hdmi_monitor(struct edid *edid)
4438{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004439 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004440 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004441 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004442
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004443 edid_ext = drm_find_cea_extension(edid);
4444 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004445 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004446
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004447 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004448 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004449
4450 /*
4451 * Because HDMI identifier is in Vendor Specific Block,
4452 * search it from all data blocks of CEA extension.
4453 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004454 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004455 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4456 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004457 }
4458
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004459 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004460}
4461EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4462
Dave Airlief453ba02008-11-07 14:05:41 -08004463/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004464 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004465 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004466 *
4467 * Monitor should have CEA extension block.
4468 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4469 * audio' only. If there is any audio extension block and supported
4470 * audio format, assume at least 'basic audio' support, even if 'basic
4471 * audio' is not defined in EDID.
4472 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004473 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004474 */
4475bool drm_detect_monitor_audio(struct edid *edid)
4476{
4477 u8 *edid_ext;
4478 int i, j;
4479 bool has_audio = false;
4480 int start_offset, end_offset;
4481
4482 edid_ext = drm_find_cea_extension(edid);
4483 if (!edid_ext)
4484 goto end;
4485
4486 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4487
4488 if (has_audio) {
4489 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4490 goto end;
4491 }
4492
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004493 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4494 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004495
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004496 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4497 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004498 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004499 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004500 DRM_DEBUG_KMS("CEA audio format %d\n",
4501 (edid_ext[i + j] >> 3) & 0xf);
4502 goto end;
4503 }
4504 }
4505end:
4506 return has_audio;
4507}
4508EXPORT_SYMBOL(drm_detect_monitor_audio);
4509
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004510
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004511/**
4512 * drm_default_rgb_quant_range - default RGB quantization range
4513 * @mode: display mode
4514 *
4515 * Determine the default RGB quantization range for the mode,
4516 * as specified in CEA-861.
4517 *
4518 * Return: The default RGB quantization range for the mode
4519 */
4520enum hdmi_quantization_range
4521drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4522{
4523 /* All CEA modes other than VIC 1 use limited quantization range. */
4524 return drm_match_cea_mode(mode) > 1 ?
4525 HDMI_QUANTIZATION_RANGE_LIMITED :
4526 HDMI_QUANTIZATION_RANGE_FULL;
4527}
4528EXPORT_SYMBOL(drm_default_rgb_quant_range);
4529
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004530static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4531{
4532 struct drm_display_info *info = &connector->display_info;
4533
4534 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4535
4536 if (db[2] & EDID_CEA_VCDB_QS)
4537 info->rgb_quant_range_selectable = true;
4538}
4539
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304540static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4541 const u8 *db)
4542{
4543 u8 dc_mask;
4544 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4545
4546 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
Clint Taylor9068e022018-10-05 14:52:15 -07004547 hdmi->y420_dc_modes = dc_mask;
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304548}
4549
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304550static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4551 const u8 *hf_vsdb)
4552{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304553 struct drm_display_info *display = &connector->display_info;
4554 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304555
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004556 display->has_hdmi_infoframe = true;
4557
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304558 if (hf_vsdb[6] & 0x80) {
4559 hdmi->scdc.supported = true;
4560 if (hf_vsdb[6] & 0x40)
4561 hdmi->scdc.read_request = true;
4562 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304563
4564 /*
4565 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4566 * And as per the spec, three factors confirm this:
4567 * * Availability of a HF-VSDB block in EDID (check)
4568 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4569 * * SCDC support available (let's check)
4570 * Lets check it out.
4571 */
4572
4573 if (hf_vsdb[5]) {
4574 /* max clock is 5000 KHz times block value */
4575 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4576 struct drm_scdc *scdc = &hdmi->scdc;
4577
4578 if (max_tmds_clock > 340000) {
4579 display->max_tmds_clock = max_tmds_clock;
4580 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4581 display->max_tmds_clock);
4582 }
4583
4584 if (scdc->supported) {
4585 scdc->scrambling.supported = true;
4586
4587 /* Few sinks support scrambling for cloks < 340M */
4588 if ((hf_vsdb[6] & 0x8))
4589 scdc->scrambling.low_rates = true;
4590 }
4591 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304592
4593 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304594}
4595
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004596static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4597 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004598{
Ville Syrjälä18267502016-09-28 16:51:38 +03004599 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004600 unsigned int dc_bpc = 0;
4601
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004602 /* HDMI supports at least 8 bpc */
4603 info->bpc = 8;
4604
4605 if (cea_db_payload_len(hdmi) < 6)
4606 return;
4607
4608 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4609 dc_bpc = 10;
4610 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4611 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4612 connector->name);
4613 }
4614
4615 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4616 dc_bpc = 12;
4617 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4618 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4619 connector->name);
4620 }
4621
4622 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4623 dc_bpc = 16;
4624 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4625 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4626 connector->name);
4627 }
4628
4629 if (dc_bpc == 0) {
4630 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4631 connector->name);
4632 return;
4633 }
4634
4635 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4636 connector->name, dc_bpc);
4637 info->bpc = dc_bpc;
4638
4639 /*
4640 * Deep color support mandates RGB444 support for all video
4641 * modes and forbids YCRCB422 support for all video modes per
4642 * HDMI 1.3 spec.
4643 */
4644 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4645
4646 /* YCRCB444 is optional according to spec. */
4647 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4648 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4649 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4650 connector->name);
4651 }
4652
4653 /*
4654 * Spec says that if any deep color mode is supported at all,
4655 * then deep color 36 bit must be supported.
4656 */
4657 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4658 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4659 connector->name);
4660 }
4661}
4662
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004663static void
4664drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4665{
4666 struct drm_display_info *info = &connector->display_info;
4667 u8 len = cea_db_payload_len(db);
4668
4669 if (len >= 6)
4670 info->dvi_dual = db[6] & 1;
4671 if (len >= 7)
4672 info->max_tmds_clock = db[7] * 5000;
4673
4674 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4675 "max TMDS clock %d kHz\n",
4676 info->dvi_dual,
4677 info->max_tmds_clock);
4678
4679 drm_parse_hdmi_deep_color_info(connector, db);
4680}
4681
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004682static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004683 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004684{
4685 struct drm_display_info *info = &connector->display_info;
4686 const u8 *edid_ext;
4687 int i, start, end;
4688
Mario Kleinerd0c94692014-03-27 19:59:39 +01004689 edid_ext = drm_find_cea_extension(edid);
4690 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004691 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004692
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004693 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004694
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004695 /* The existence of a CEA block should imply RGB support */
4696 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4697 if (edid_ext[3] & EDID_CEA_YCRCB444)
4698 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4699 if (edid_ext[3] & EDID_CEA_YCRCB422)
4700 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004701
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004702 if (cea_db_offsets(edid_ext, &start, &end))
4703 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004704
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004705 for_each_cea_db(edid_ext, i, start, end) {
4706 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004707
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004708 if (cea_db_is_hdmi_vsdb(db))
4709 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304710 if (cea_db_is_hdmi_forum_vsdb(db))
4711 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304712 if (cea_db_is_y420cmdb(db))
4713 drm_parse_y420cmdb_bitmap(connector, db);
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004714 if (cea_db_is_vcdb(db))
4715 drm_parse_vcdb(connector, db);
Uma Shankare85959d2019-05-16 19:40:08 +05304716 if (cea_db_is_hdmi_hdr_metadata_block(db))
4717 drm_parse_hdr_metadata_block(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004718 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004719}
4720
Keith Packard170178f2017-12-13 00:44:26 -08004721/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4722 * all of the values which would have been set from EDID
4723 */
4724void
4725drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004726{
Ville Syrjälä18267502016-09-28 16:51:38 +03004727 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004728
Keith Packard170178f2017-12-13 00:44:26 -08004729 info->width_mm = 0;
4730 info->height_mm = 0;
4731
4732 info->bpc = 0;
4733 info->color_formats = 0;
4734 info->cea_rev = 0;
4735 info->max_tmds_clock = 0;
4736 info->dvi_dual = false;
4737 info->has_hdmi_infoframe = false;
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004738 info->rgb_quant_range_selectable = false;
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004739 memset(&info->hdmi, 0, sizeof(info->hdmi));
Keith Packard170178f2017-12-13 00:44:26 -08004740
4741 info->non_desktop = 0;
4742}
Keith Packard170178f2017-12-13 00:44:26 -08004743
4744u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4745{
4746 struct drm_display_info *info = &connector->display_info;
4747
4748 u32 quirks = edid_get_quirks(edid);
4749
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004750 drm_reset_display_info(connector);
4751
Jesse Barnes3b112282011-04-15 12:49:23 -07004752 info->width_mm = edid->width_cm * 10;
4753 info->height_mm = edid->height_cm * 10;
4754
Dave Airlie66660d42017-10-16 05:08:09 +01004755 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4756
Keith Packard170178f2017-12-13 00:44:26 -08004757 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4758
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004759 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004760 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004761
4762 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004763 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004764
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004765 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004766
Mario Kleiner210a0212016-07-06 12:05:48 +02004767 /*
4768 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4769 *
4770 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4771 * tells us to assume 8 bpc color depth if the EDID doesn't have
4772 * extensions which tell otherwise.
4773 */
Ville Syrjälä3bde4492019-05-29 14:02:04 +03004774 if (info->bpc == 0 && edid->revision == 3 &&
4775 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
Mario Kleiner210a0212016-07-06 12:05:48 +02004776 info->bpc = 8;
4777 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4778 connector->name, info->bpc);
4779 }
4780
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004781 /* Only defined for 1.4 with digital displays */
4782 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004783 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004784
Jesse Barnes3b112282011-04-15 12:49:23 -07004785 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4786 case DRM_EDID_DIGITAL_DEPTH_6:
4787 info->bpc = 6;
4788 break;
4789 case DRM_EDID_DIGITAL_DEPTH_8:
4790 info->bpc = 8;
4791 break;
4792 case DRM_EDID_DIGITAL_DEPTH_10:
4793 info->bpc = 10;
4794 break;
4795 case DRM_EDID_DIGITAL_DEPTH_12:
4796 info->bpc = 12;
4797 break;
4798 case DRM_EDID_DIGITAL_DEPTH_14:
4799 info->bpc = 14;
4800 break;
4801 case DRM_EDID_DIGITAL_DEPTH_16:
4802 info->bpc = 16;
4803 break;
4804 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4805 default:
4806 info->bpc = 0;
4807 break;
4808 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004809
Mario Kleinerd0c94692014-03-27 19:59:39 +01004810 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004811 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004812
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004813 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004814 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4815 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4816 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4817 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004818 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004819}
4820
Dave Airliec97291772016-05-03 15:38:37 +10004821static int validate_displayid(u8 *displayid, int length, int idx)
4822{
4823 int i;
4824 u8 csum = 0;
4825 struct displayid_hdr *base;
4826
4827 base = (struct displayid_hdr *)&displayid[idx];
4828
4829 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4830 base->rev, base->bytes, base->prod_id, base->ext_count);
4831
4832 if (base->bytes + 5 > length - idx)
4833 return -EINVAL;
4834 for (i = idx; i <= base->bytes + 5; i++) {
4835 csum += displayid[i];
4836 }
4837 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004838 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004839 return -EINVAL;
4840 }
4841 return 0;
4842}
4843
Dave Airliea39ed682016-05-02 08:35:05 +10004844static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4845 struct displayid_detailed_timings_1 *timings)
4846{
4847 struct drm_display_mode *mode;
4848 unsigned pixel_clock = (timings->pixel_clock[0] |
4849 (timings->pixel_clock[1] << 8) |
4850 (timings->pixel_clock[2] << 16));
4851 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4852 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4853 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4854 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4855 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4856 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4857 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4858 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4859 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4860 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4861 mode = drm_mode_create(dev);
4862 if (!mode)
4863 return NULL;
4864
4865 mode->clock = pixel_clock * 10;
4866 mode->hdisplay = hactive;
4867 mode->hsync_start = mode->hdisplay + hsync;
4868 mode->hsync_end = mode->hsync_start + hsync_width;
4869 mode->htotal = mode->hdisplay + hblank;
4870
4871 mode->vdisplay = vactive;
4872 mode->vsync_start = mode->vdisplay + vsync;
4873 mode->vsync_end = mode->vsync_start + vsync_width;
4874 mode->vtotal = mode->vdisplay + vblank;
4875
4876 mode->flags = 0;
4877 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4878 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4879 mode->type = DRM_MODE_TYPE_DRIVER;
4880
4881 if (timings->flags & 0x80)
4882 mode->type |= DRM_MODE_TYPE_PREFERRED;
4883 mode->vrefresh = drm_mode_vrefresh(mode);
4884 drm_mode_set_name(mode);
4885
4886 return mode;
4887}
4888
4889static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4890 struct displayid_block *block)
4891{
4892 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4893 int i;
4894 int num_timings;
4895 struct drm_display_mode *newmode;
4896 int num_modes = 0;
4897 /* blocks must be multiple of 20 bytes length */
4898 if (block->num_bytes % 20)
4899 return 0;
4900
4901 num_timings = block->num_bytes / 20;
4902 for (i = 0; i < num_timings; i++) {
4903 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4904
4905 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4906 if (!newmode)
4907 continue;
4908
4909 drm_mode_probed_add(connector, newmode);
4910 num_modes++;
4911 }
4912 return num_modes;
4913}
4914
4915static int add_displayid_detailed_modes(struct drm_connector *connector,
4916 struct edid *edid)
4917{
4918 u8 *displayid;
4919 int ret;
4920 int idx = 1;
4921 int length = EDID_LENGTH;
4922 struct displayid_block *block;
4923 int num_modes = 0;
4924
4925 displayid = drm_find_displayid_extension(edid);
4926 if (!displayid)
4927 return 0;
4928
4929 ret = validate_displayid(displayid, length, idx);
4930 if (ret)
4931 return 0;
4932
4933 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04004934 for_each_displayid_db(displayid, block, idx, length) {
Dave Airliea39ed682016-05-02 08:35:05 +10004935 switch (block->tag) {
4936 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4937 num_modes += add_displayid_detailed_1_modes(connector, block);
4938 break;
4939 }
4940 }
4941 return num_modes;
4942}
4943
Jesse Barnes3b112282011-04-15 12:49:23 -07004944/**
Dave Airlief453ba02008-11-07 14:05:41 -08004945 * drm_add_edid_modes - add modes from EDID data, if available
4946 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004947 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004948 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004949 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004950 * &drm_display_info structure and ELD in @connector with any information which
4951 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004952 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004953 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004954 */
4955int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4956{
4957 int num_modes = 0;
4958 u32 quirks;
4959
4960 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004961 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004962 return 0;
4963 }
Alex Deucher3c537882010-02-05 04:21:19 -05004964 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004965 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004966 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004967 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004968 return 0;
4969 }
4970
Jani Nikulac945b8c2017-11-01 16:21:01 +02004971 drm_edid_to_eld(connector, edid);
4972
Adam Jacksonc867df72010-03-29 21:43:21 +00004973 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304974 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4975 * To avoid multiple parsing of same block, lets parse that map
4976 * from sink info, before parsing CEA modes.
4977 */
Keith Packard170178f2017-12-13 00:44:26 -08004978 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304979
4980 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004981 * EDID spec says modes should be preferred in this order:
4982 * - preferred detailed mode
4983 * - other detailed modes from base block
4984 * - detailed modes from extension blocks
4985 * - CVT 3-byte code modes
4986 * - standard timing codes
4987 * - established timing codes
4988 * - modes inferred from GTF or CVT range information
4989 *
Adam Jackson13931572010-08-03 14:38:19 -04004990 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004991 *
4992 * XXX order for additional mode types in extension blocks?
4993 */
Adam Jackson13931572010-08-03 14:38:19 -04004994 num_modes += add_detailed_modes(connector, edid, quirks);
4995 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004996 num_modes += add_standard_modes(connector, edid);
4997 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004998 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004999 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10005000 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03005001 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
5002 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08005003
5004 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
5005 edid_fixup_preferred(connector, quirks);
5006
Mario Kleinere10aec62016-07-06 12:05:44 +02005007 if (quirks & EDID_QUIRK_FORCE_6BPC)
5008 connector->display_info.bpc = 6;
5009
Rafał Miłecki49d45a312013-12-07 13:22:42 +01005010 if (quirks & EDID_QUIRK_FORCE_8BPC)
5011 connector->display_info.bpc = 8;
5012
Mario Kleinere345da82017-04-21 17:05:08 +02005013 if (quirks & EDID_QUIRK_FORCE_10BPC)
5014 connector->display_info.bpc = 10;
5015
Mario Kleinerbc5b9642014-05-23 21:40:55 +02005016 if (quirks & EDID_QUIRK_FORCE_12BPC)
5017 connector->display_info.bpc = 12;
5018
Dave Airlief453ba02008-11-07 14:05:41 -08005019 return num_modes;
5020}
5021EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005022
5023/**
5024 * drm_add_modes_noedid - add modes for the connectors without EDID
5025 * @connector: connector we're probing
5026 * @hdisplay: the horizontal display limit
5027 * @vdisplay: the vertical display limit
5028 *
5029 * Add the specified modes to the connector's mode list. Only when the
5030 * hdisplay/vdisplay is not beyond the given limit, it will be added.
5031 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005032 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005033 */
5034int drm_add_modes_noedid(struct drm_connector *connector,
5035 int hdisplay, int vdisplay)
5036{
5037 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005038 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005039 struct drm_device *dev = connector->dev;
5040
Daniel Vetterfbb40b22015-08-10 11:55:37 +02005041 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005042 if (hdisplay < 0)
5043 hdisplay = 0;
5044 if (vdisplay < 0)
5045 vdisplay = 0;
5046
5047 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005048 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005049 if (hdisplay && vdisplay) {
5050 /*
5051 * Only when two are valid, they will be used to check
5052 * whether the mode should be added to the mode list of
5053 * the connector.
5054 */
5055 if (ptr->hdisplay > hdisplay ||
5056 ptr->vdisplay > vdisplay)
5057 continue;
5058 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05005059 if (drm_mode_vrefresh(ptr) > 61)
5060 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005061 mode = drm_mode_duplicate(dev, ptr);
5062 if (mode) {
5063 drm_mode_probed_add(connector, mode);
5064 num_modes++;
5065 }
5066 }
5067 return num_modes;
5068}
5069EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01005070
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005071/**
5072 * drm_set_preferred_mode - Sets the preferred mode of a connector
5073 * @connector: connector whose mode list should be processed
5074 * @hpref: horizontal resolution of preferred mode
5075 * @vpref: vertical resolution of preferred mode
5076 *
5077 * Marks a mode as preferred if it matches the resolution specified by @hpref
5078 * and @vpref.
5079 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005080void drm_set_preferred_mode(struct drm_connector *connector,
5081 int hpref, int vpref)
5082{
5083 struct drm_display_mode *mode;
5084
5085 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005086 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01005087 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005088 mode->type |= DRM_MODE_TYPE_PREFERRED;
5089 }
5090}
5091EXPORT_SYMBOL(drm_set_preferred_mode);
5092
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005093static bool is_hdmi2_sink(struct drm_connector *connector)
5094{
5095 /*
5096 * FIXME: sil-sii8620 doesn't have a connector around when
5097 * we need one, so we have to be prepared for a NULL connector.
5098 */
5099 if (!connector)
5100 return true;
5101
5102 return connector->display_info.hdmi.scdc.supported ||
5103 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
5104}
5105
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305106static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5107{
5108 return sink_eotf & BIT(output_eotf);
5109}
5110
5111/**
5112 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5113 * HDR metadata from userspace
5114 * @frame: HDMI DRM infoframe
Sean Paul6ac98822019-05-23 09:54:58 -04005115 * @conn_state: Connector state containing HDR metadata
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305116 *
5117 * Return: 0 on success or a negative error code on failure.
5118 */
5119int
5120drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5121 const struct drm_connector_state *conn_state)
5122{
5123 struct drm_connector *connector;
5124 struct hdr_output_metadata *hdr_metadata;
5125 int err;
5126
5127 if (!frame || !conn_state)
5128 return -EINVAL;
5129
5130 connector = conn_state->connector;
5131
5132 if (!conn_state->hdr_output_metadata)
5133 return -EINVAL;
5134
5135 hdr_metadata = conn_state->hdr_output_metadata->data;
5136
5137 if (!hdr_metadata || !connector)
5138 return -EINVAL;
5139
5140 /* Sink EOTF is Bit map while infoframe is absolute values */
5141 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5142 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5143 DRM_DEBUG_KMS("EOTF Not Supported\n");
5144 return -EINVAL;
5145 }
5146
5147 err = hdmi_drm_infoframe_init(frame);
5148 if (err < 0)
5149 return err;
5150
5151 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5152 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5153
5154 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5155 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5156 BUILD_BUG_ON(sizeof(frame->white_point) !=
5157 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5158
5159 memcpy(&frame->display_primaries,
5160 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5161 sizeof(frame->display_primaries));
5162
5163 memcpy(&frame->white_point,
5164 &hdr_metadata->hdmi_metadata_type1.white_point,
5165 sizeof(frame->white_point));
5166
5167 frame->max_display_mastering_luminance =
5168 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5169 frame->min_display_mastering_luminance =
5170 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5171 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5172 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5173
5174 return 0;
5175}
5176EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5177
Ville Syrjälä949561e2019-10-04 17:19:13 +03005178static u8 drm_mode_hdmi_vic(struct drm_connector *connector,
5179 const struct drm_display_mode *mode)
5180{
5181 bool has_hdmi_infoframe = connector ?
5182 connector->display_info.has_hdmi_infoframe : false;
5183
5184 if (!has_hdmi_infoframe)
5185 return 0;
5186
5187 /* No HDMI VIC when signalling 3D video format */
5188 if (mode->flags & DRM_MODE_FLAG_3D_MASK)
5189 return 0;
5190
5191 return drm_match_hdmi_mode(mode);
5192}
5193
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005194static u8 drm_mode_cea_vic(struct drm_connector *connector,
5195 const struct drm_display_mode *mode)
5196{
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005197 u8 vic;
5198
5199 /*
5200 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5201 * we should send its VIC in vendor infoframes, else send the
5202 * VIC in AVI infoframes. Lets check if this mode is present in
5203 * HDMI 1.4b 4K modes
5204 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005205 if (drm_mode_hdmi_vic(connector, mode))
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005206 return 0;
5207
5208 vic = drm_match_cea_mode(mode);
5209
5210 /*
5211 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5212 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5213 * have to make sure we dont break HDMI 1.4 sinks.
5214 */
5215 if (!is_hdmi2_sink(connector) && vic > 64)
5216 return 0;
5217
5218 return vic;
5219}
5220
Thierry Reding10a85122012-11-21 15:31:35 +01005221/**
5222 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5223 * data from a DRM display mode
5224 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005225 * @connector: the connector
Thierry Reding10a85122012-11-21 15:31:35 +01005226 * @mode: DRM display mode
5227 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005228 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01005229 */
5230int
5231drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005232 struct drm_connector *connector,
5233 const struct drm_display_mode *mode)
Thierry Reding10a85122012-11-21 15:31:35 +01005234{
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305235 enum hdmi_picture_aspect picture_aspect;
Wayne Lind2b43472019-11-18 18:18:31 +08005236 u8 vic, hdmi_vic;
Thierry Reding10a85122012-11-21 15:31:35 +01005237 int err;
5238
5239 if (!frame || !mode)
5240 return -EINVAL;
5241
5242 err = hdmi_avi_infoframe_init(frame);
5243 if (err < 0)
5244 return err;
5245
Damien Lespiaubf02db92013-08-06 20:32:22 +01005246 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5247 frame->pixel_repeat = 1;
5248
Wayne Lind2b43472019-11-18 18:18:31 +08005249 vic = drm_mode_cea_vic(connector, mode);
5250 hdmi_vic = drm_mode_hdmi_vic(connector, mode);
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305251
Thierry Reding10a85122012-11-21 15:31:35 +01005252 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305253
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305254 /*
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03005255 * As some drivers don't support atomic, we can't use connector state.
5256 * So just initialize the frame with default values, just the same way
5257 * as it's done with other properties here.
5258 */
5259 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5260 frame->itc = 0;
5261
5262 /*
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305263 * Populate picture aspect ratio from either
Wayne Lind2b43472019-11-18 18:18:31 +08005264 * user input (if specified) or from the CEA/HDMI mode lists.
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305265 */
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305266 picture_aspect = mode->picture_aspect_ratio;
Wayne Lind2b43472019-11-18 18:18:31 +08005267 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE) {
5268 if (vic)
5269 picture_aspect = drm_get_cea_aspect_ratio(vic);
5270 else if (hdmi_vic)
5271 picture_aspect = drm_get_hdmi_aspect_ratio(hdmi_vic);
5272 }
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305273
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305274 /*
5275 * The infoframe can't convey anything but none, 4:3
5276 * and 16:9, so if the user has asked for anything else
5277 * we can only satisfy it by specifying the right VIC.
5278 */
5279 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
Wayne Lind2b43472019-11-18 18:18:31 +08005280 if (vic) {
5281 if (picture_aspect != drm_get_cea_aspect_ratio(vic))
5282 return -EINVAL;
5283 } else if (hdmi_vic) {
5284 if (picture_aspect != drm_get_hdmi_aspect_ratio(hdmi_vic))
5285 return -EINVAL;
5286 } else {
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305287 return -EINVAL;
Wayne Lind2b43472019-11-18 18:18:31 +08005288 }
5289
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305290 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5291 }
5292
Wayne Lind2b43472019-11-18 18:18:31 +08005293 frame->video_code = vic;
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305294 frame->picture_aspect = picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005295 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06005296 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01005297
5298 return 0;
5299}
5300EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005301
Uma Shankar0d68b882019-02-19 22:43:00 +05305302/* HDMI Colorspace Spec Definitions */
5303#define FULL_COLORIMETRY_MASK 0x1FF
5304#define NORMAL_COLORIMETRY_MASK 0x3
5305#define EXTENDED_COLORIMETRY_MASK 0x7
5306#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5307
5308#define C(x) ((x) << 0)
5309#define EC(x) ((x) << 2)
5310#define ACE(x) ((x) << 5)
5311
5312#define HDMI_COLORIMETRY_NO_DATA 0x0
5313#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5314#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5315#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5316#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5317#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5318#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5319#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5320#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5321#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5322#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5323#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5324#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5325
5326static const u32 hdmi_colorimetry_val[] = {
5327 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5328 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5329 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5330 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5331 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5332 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5333 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5334 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5335 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5336 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5337 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5338};
5339
5340#undef C
5341#undef EC
5342#undef ACE
5343
5344/**
5345 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5346 * colorspace information
5347 * @frame: HDMI AVI infoframe
5348 * @conn_state: connector state
5349 */
5350void
5351drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5352 const struct drm_connector_state *conn_state)
5353{
5354 u32 colorimetry_val;
5355 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5356
5357 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5358 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5359 else
5360 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5361
5362 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5363 /*
5364 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5365 * structure and extend it in drivers/video/hdmi
5366 */
5367 frame->extended_colorimetry = (colorimetry_val >> 2) &
5368 EXTENDED_COLORIMETRY_MASK;
5369}
5370EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5371
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005372/**
5373 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5374 * quantization range information
5375 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005376 * @connector: the connector
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005377 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005378 * @rgb_quant_range: RGB quantization range (Q)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005379 */
5380void
5381drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005382 struct drm_connector *connector,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005383 const struct drm_display_mode *mode,
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005384 enum hdmi_quantization_range rgb_quant_range)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005385{
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005386 const struct drm_display_info *info = &connector->display_info;
5387
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005388 /*
5389 * CEA-861:
5390 * "A Source shall not send a non-zero Q value that does not correspond
5391 * to the default RGB Quantization Range for the transmitted Picture
5392 * unless the Sink indicates support for the Q bit in a Video
5393 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005394 *
5395 * HDMI 2.0 recommends sending non-zero Q when it does match the
5396 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005397 */
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005398 if (info->rgb_quant_range_selectable ||
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005399 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005400 frame->quantization_range = rgb_quant_range;
5401 else
5402 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005403
5404 /*
5405 * CEA-861-F:
5406 * "When transmitting any RGB colorimetry, the Source should set the
5407 * YQ-field to match the RGB Quantization Range being transmitted
5408 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5409 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005410 *
5411 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5412 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5413 * good way to tell which version of CEA-861 the sink supports, so
5414 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5415 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005416 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005417 if (!is_hdmi2_sink(connector) ||
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005418 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005419 frame->ycc_quantization_range =
5420 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5421 else
5422 frame->ycc_quantization_range =
5423 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005424}
5425EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5426
Ville Syrjälä076d9a52019-10-08 19:48:13 +03005427/**
5428 * drm_hdmi_avi_infoframe_bars() - fill the HDMI AVI infoframe
5429 * bar information
5430 * @frame: HDMI AVI infoframe
5431 * @conn_state: connector state
5432 */
5433void
5434drm_hdmi_avi_infoframe_bars(struct hdmi_avi_infoframe *frame,
5435 const struct drm_connector_state *conn_state)
5436{
5437 frame->right_bar = conn_state->tv.margins.right;
5438 frame->left_bar = conn_state->tv.margins.left;
5439 frame->top_bar = conn_state->tv.margins.top;
5440 frame->bottom_bar = conn_state->tv.margins.bottom;
5441}
5442EXPORT_SYMBOL(drm_hdmi_avi_infoframe_bars);
5443
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005444static enum hdmi_3d_structure
5445s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5446{
5447 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5448
5449 switch (layout) {
5450 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5451 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5452 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5453 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5454 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5455 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5456 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5457 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5458 case DRM_MODE_FLAG_3D_L_DEPTH:
5459 return HDMI_3D_STRUCTURE_L_DEPTH;
5460 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5461 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5462 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5463 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5464 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5465 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5466 default:
5467 return HDMI_3D_STRUCTURE_INVALID;
5468 }
5469}
5470
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005471/**
5472 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5473 * data from a DRM display mode
5474 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005475 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005476 * @mode: DRM display mode
5477 *
5478 * Note that there's is a need to send HDMI vendor infoframes only when using a
5479 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5480 * function will return -EINVAL, error that can be safely ignored.
5481 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005482 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005483 */
5484int
5485drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005486 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005487 const struct drm_display_mode *mode)
5488{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005489 /*
5490 * FIXME: sil-sii8620 doesn't have a connector around when
5491 * we need one, so we have to be prepared for a NULL connector.
5492 */
5493 bool has_hdmi_infoframe = connector ?
5494 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005495 int err;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005496
5497 if (!frame || !mode)
5498 return -EINVAL;
5499
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005500 if (!has_hdmi_infoframe)
5501 return -EINVAL;
5502
Ville Syrjälä949561e2019-10-04 17:19:13 +03005503 err = hdmi_vendor_infoframe_init(frame);
5504 if (err < 0)
5505 return err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005506
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005507 /*
5508 * Even if it's not absolutely necessary to send the infoframe
5509 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5510 * know that the sink can handle it. This is based on a
5511 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5512 * have trouble realizing that they shuld switch from 3D to 2D
5513 * mode if the source simply stops sending the infoframe when
5514 * it wants to switch from 3D to 2D.
5515 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005516 frame->vic = drm_mode_hdmi_vic(connector, mode);
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005517 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005518
5519 return 0;
5520}
5521EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005522
Dave Airlie5e546cd2016-05-03 15:31:12 +10005523static int drm_parse_tiled_block(struct drm_connector *connector,
5524 struct displayid_block *block)
5525{
5526 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5527 u16 w, h;
5528 u8 tile_v_loc, tile_h_loc;
5529 u8 num_v_tile, num_h_tile;
5530 struct drm_tile_group *tg;
5531
5532 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5533 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5534
5535 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5536 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5537 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5538 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5539
5540 connector->has_tile = true;
5541 if (tile->tile_cap & 0x80)
5542 connector->tile_is_single_monitor = true;
5543
5544 connector->num_h_tile = num_h_tile + 1;
5545 connector->num_v_tile = num_v_tile + 1;
5546 connector->tile_h_loc = tile_h_loc;
5547 connector->tile_v_loc = tile_v_loc;
5548 connector->tile_h_size = w + 1;
5549 connector->tile_v_size = h + 1;
5550
5551 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5552 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5553 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5554 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5555 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5556
5557 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5558 if (!tg) {
5559 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5560 }
5561 if (!tg)
5562 return -ENOMEM;
5563
5564 if (connector->tile_group != tg) {
5565 /* if we haven't got a pointer,
5566 take the reference, drop ref to old tile group */
5567 if (connector->tile_group) {
5568 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5569 }
5570 connector->tile_group = tg;
5571 } else
5572 /* if same tile group, then release the ref we just took. */
5573 drm_mode_put_tile_group(connector->dev, tg);
5574 return 0;
5575}
5576
Dave Airlie40d9b042014-10-20 16:29:33 +10005577static int drm_parse_display_id(struct drm_connector *connector,
5578 u8 *displayid, int length,
5579 bool is_edid_extension)
5580{
5581 /* if this is an EDID extension the first byte will be 0x70 */
5582 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005583 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005584 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005585
5586 if (is_edid_extension)
5587 idx = 1;
5588
Dave Airliec97291772016-05-03 15:38:37 +10005589 ret = validate_displayid(displayid, length, idx);
5590 if (ret)
5591 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005592
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005593 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04005594 for_each_displayid_db(displayid, block, idx, length) {
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005595 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5596 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005597
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005598 switch (block->tag) {
5599 case DATA_BLOCK_TILED_DISPLAY:
5600 ret = drm_parse_tiled_block(connector, block);
5601 if (ret)
5602 return ret;
5603 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005604 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5605 /* handled in mode gathering code. */
5606 break;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04005607 case DATA_BLOCK_CTA:
5608 /* handled in the cea parser code. */
5609 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005610 default:
5611 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5612 break;
5613 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005614 }
5615 return 0;
5616}
5617
5618static void drm_get_displayid(struct drm_connector *connector,
5619 struct edid *edid)
5620{
5621 void *displayid = NULL;
5622 int ret;
5623 connector->has_tile = false;
5624 displayid = drm_find_displayid_extension(edid);
5625 if (!displayid) {
5626 /* drop reference to any tile group we had */
5627 goto out_drop_ref;
5628 }
5629
5630 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5631 if (ret < 0)
5632 goto out_drop_ref;
5633 if (!connector->has_tile)
5634 goto out_drop_ref;
5635 return;
5636out_drop_ref:
5637 if (connector->tile_group) {
5638 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5639 connector->tile_group = NULL;
5640 }
5641 return;
5642}