blob: 00a543b9daaba9cc48248583770a8dadb9eab62f [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/*
Ville Syrjälä7befe622019-12-13 19:43:45 +0200713 * From CEA/CTA-861 spec.
Jani Nikulad9278b42016-01-08 13:21:51 +0200714 *
Ville Syrjälä7befe622019-12-13 19:43:45 +0200715 * Do not access directly, instead always use cea_mode_for_vic().
Thierry Redinga6b21832012-11-23 15:01:42 +0100716 */
Ville Syrjälä7befe622019-12-13 19:43:45 +0200717static const struct drm_display_mode edid_cea_modes_0[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200718 /* 0 - dummy, VICs start at 1 */
719 { },
Ville Syrjälä78691962018-05-24 22:20:35 +0300720 /* 1 - 640x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100721 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
722 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300723 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530724 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300725 /* 2 - 720x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100726 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
727 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300728 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530729 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300730 /* 3 - 720x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100731 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
732 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300733 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530734 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300735 /* 4 - 1280x720@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100736 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
737 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300738 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530739 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300740 /* 5 - 1920x1080i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100741 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
742 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
743 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300744 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530745 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300746 /* 6 - 720(1440)x480i@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700747 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
748 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100749 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300750 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530751 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300752 /* 7 - 720(1440)x480i@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700753 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
754 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100755 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300756 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530757 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300758 /* 8 - 720(1440)x240@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700759 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
760 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100761 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300762 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530763 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300764 /* 9 - 720(1440)x240@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700765 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
766 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100767 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300768 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530769 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300770 /* 10 - 2880x480i@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100771 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
772 3204, 3432, 0, 480, 488, 494, 525, 0,
773 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300774 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530775 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300776 /* 11 - 2880x480i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100777 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
778 3204, 3432, 0, 480, 488, 494, 525, 0,
779 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300780 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530781 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300782 /* 12 - 2880x240@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100783 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
784 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300785 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530786 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300787 /* 13 - 2880x240@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100788 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
789 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300790 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530791 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300792 /* 14 - 1440x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100793 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
794 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300795 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530796 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300797 /* 15 - 1440x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100798 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
799 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300800 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530801 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300802 /* 16 - 1920x1080@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100803 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
804 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300805 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530806 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300807 /* 17 - 720x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100808 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
809 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300810 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530811 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300812 /* 18 - 720x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100813 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
814 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300815 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530816 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300817 /* 19 - 1280x720@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100818 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
819 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300820 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530821 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300822 /* 20 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100823 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
824 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
825 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300826 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530827 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300828 /* 21 - 720(1440)x576i@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700829 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
830 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100831 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300832 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530833 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300834 /* 22 - 720(1440)x576i@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700835 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
836 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100837 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300838 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530839 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300840 /* 23 - 720(1440)x288@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700841 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
842 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100843 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300844 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530845 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300846 /* 24 - 720(1440)x288@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700847 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
848 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100849 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300850 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530851 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300852 /* 25 - 2880x576i@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100853 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
854 3180, 3456, 0, 576, 580, 586, 625, 0,
855 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300856 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530857 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300858 /* 26 - 2880x576i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100859 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
860 3180, 3456, 0, 576, 580, 586, 625, 0,
861 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300862 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530863 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300864 /* 27 - 2880x288@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100865 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
866 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300867 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530868 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300869 /* 28 - 2880x288@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100870 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
871 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300872 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530873 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300874 /* 29 - 1440x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100875 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
876 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300877 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530878 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300879 /* 30 - 1440x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100880 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
881 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300882 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530883 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300884 /* 31 - 1920x1080@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100885 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
886 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300887 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530888 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300889 /* 32 - 1920x1080@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100890 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
891 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300892 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530893 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300894 /* 33 - 1920x1080@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100895 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
896 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300897 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530898 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300899 /* 34 - 1920x1080@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100900 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
901 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300902 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530903 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300904 /* 35 - 2880x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100905 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
906 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300907 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530908 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300909 /* 36 - 2880x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100910 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
911 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300912 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530913 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300914 /* 37 - 2880x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100915 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
916 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300917 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530918 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300919 /* 38 - 2880x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100920 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
921 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300922 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530923 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300924 /* 39 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100925 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
926 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
927 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300928 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530929 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300930 /* 40 - 1920x1080i@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100931 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
932 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
933 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300934 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530935 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300936 /* 41 - 1280x720@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100937 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
938 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300939 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530940 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300941 /* 42 - 720x576@100Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100942 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
943 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300944 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530945 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300946 /* 43 - 720x576@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100947 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
948 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300949 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530950 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300951 /* 44 - 720(1440)x576i@100Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700952 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
953 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100954 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300955 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530956 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300957 /* 45 - 720(1440)x576i@100Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700958 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
959 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100960 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300961 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530962 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300963 /* 46 - 1920x1080i@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100964 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
965 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
966 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300967 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530968 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300969 /* 47 - 1280x720@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100970 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
971 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300972 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530973 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300974 /* 48 - 720x480@120Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100975 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
976 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300977 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530978 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300979 /* 49 - 720x480@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100980 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
981 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300982 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530983 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300984 /* 50 - 720(1440)x480i@120Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700985 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
986 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100987 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300988 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530989 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300990 /* 51 - 720(1440)x480i@120Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700991 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
992 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100993 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300994 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530995 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300996 /* 52 - 720x576@200Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100997 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
998 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300999 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301000 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001001 /* 53 - 720x576@200Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001002 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1003 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001004 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301005 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001006 /* 54 - 720(1440)x576i@200Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001007 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1008 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001009 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001010 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301011 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001012 /* 55 - 720(1440)x576i@200Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001013 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1014 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001015 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001016 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301017 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001018 /* 56 - 720x480@240Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001019 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1020 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001021 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301022 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001023 /* 57 - 720x480@240Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001024 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1025 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001026 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301027 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001028 /* 58 - 720(1440)x480i@240Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001029 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1030 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001031 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001032 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301033 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001034 /* 59 - 720(1440)x480i@240Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001035 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1036 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001037 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001038 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301039 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001040 /* 60 - 1280x720@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001041 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1042 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001043 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301044 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001045 /* 61 - 1280x720@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001046 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1047 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001048 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301049 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001050 /* 62 - 1280x720@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001051 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1052 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001053 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301054 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001055 /* 63 - 1920x1080@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001056 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1057 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001058 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001059 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1060 /* 64 - 1920x1080@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001061 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001062 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001063 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001064 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1065 /* 65 - 1280x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301066 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1067 3080, 3300, 0, 720, 725, 730, 750, 0,
1068 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1069 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001070 /* 66 - 1280x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301071 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1072 3740, 3960, 0, 720, 725, 730, 750, 0,
1073 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1074 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001075 /* 67 - 1280x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301076 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1077 3080, 3300, 0, 720, 725, 730, 750, 0,
1078 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1079 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001080 /* 68 - 1280x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301081 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1082 1760, 1980, 0, 720, 725, 730, 750, 0,
1083 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1084 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001085 /* 69 - 1280x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301086 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1087 1430, 1650, 0, 720, 725, 730, 750, 0,
1088 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1089 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001090 /* 70 - 1280x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301091 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1092 1760, 1980, 0, 720, 725, 730, 750, 0,
1093 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1094 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001095 /* 71 - 1280x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301096 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1097 1430, 1650, 0, 720, 725, 730, 750, 0,
1098 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1099 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001100 /* 72 - 1920x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301101 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1102 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1103 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1104 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001105 /* 73 - 1920x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301106 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1107 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1108 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1109 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001110 /* 74 - 1920x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301111 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1112 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1113 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1114 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001115 /* 75 - 1920x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301116 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1117 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1118 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1119 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001120 /* 76 - 1920x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301121 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1122 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1123 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1124 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001125 /* 77 - 1920x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301126 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1127 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1128 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1129 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001130 /* 78 - 1920x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301131 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1132 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1133 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1134 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001135 /* 79 - 1680x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301136 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1137 3080, 3300, 0, 720, 725, 730, 750, 0,
1138 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1139 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001140 /* 80 - 1680x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301141 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1142 2948, 3168, 0, 720, 725, 730, 750, 0,
1143 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1144 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001145 /* 81 - 1680x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301146 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1147 2420, 2640, 0, 720, 725, 730, 750, 0,
1148 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1149 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001150 /* 82 - 1680x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301151 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1152 1980, 2200, 0, 720, 725, 730, 750, 0,
1153 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1154 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001155 /* 83 - 1680x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301156 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1157 1980, 2200, 0, 720, 725, 730, 750, 0,
1158 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1159 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001160 /* 84 - 1680x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301161 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1162 1780, 2000, 0, 720, 725, 730, 825, 0,
1163 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1164 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001165 /* 85 - 1680x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301166 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1167 1780, 2000, 0, 720, 725, 730, 825, 0,
1168 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1169 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001170 /* 86 - 2560x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301171 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1172 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1173 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1174 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001175 /* 87 - 2560x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301176 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1177 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1178 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1179 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001180 /* 88 - 2560x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301181 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1182 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1183 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1184 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001185 /* 89 - 2560x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301186 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1187 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1188 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1189 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001190 /* 90 - 2560x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301191 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1192 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1193 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1194 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001195 /* 91 - 2560x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301196 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1197 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1198 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1199 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001200 /* 92 - 2560x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301201 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1202 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1203 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1204 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001205 /* 93 - 3840x2160@24Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301206 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1207 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1208 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1209 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001210 /* 94 - 3840x2160@25Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301211 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1212 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1213 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1214 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001215 /* 95 - 3840x2160@30Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301216 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1217 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1218 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1219 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001220 /* 96 - 3840x2160@50Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301221 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1222 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1223 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1224 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001225 /* 97 - 3840x2160@60Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301226 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1227 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1228 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1229 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001230 /* 98 - 4096x2160@24Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301231 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1232 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1233 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1234 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001235 /* 99 - 4096x2160@25Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301236 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1237 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1238 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1239 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001240 /* 100 - 4096x2160@30Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301241 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1242 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1243 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1244 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001245 /* 101 - 4096x2160@50Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301246 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1247 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1248 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1249 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001250 /* 102 - 4096x2160@60Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301251 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1252 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1253 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1254 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001255 /* 103 - 3840x2160@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301256 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1257 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1258 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1259 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001260 /* 104 - 3840x2160@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301261 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1262 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1263 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1264 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001265 /* 105 - 3840x2160@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301266 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1267 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1268 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1269 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001270 /* 106 - 3840x2160@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301271 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1272 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1273 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1274 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001275 /* 107 - 3840x2160@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301276 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1277 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1278 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1279 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001280 /* 108 - 1280x720@48Hz 16:9 */
1281 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1282 2280, 2500, 0, 720, 725, 730, 750, 0,
1283 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1284 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1285 /* 109 - 1280x720@48Hz 64:27 */
1286 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1287 2280, 2500, 0, 720, 725, 730, 750, 0,
1288 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1289 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1290 /* 110 - 1680x720@48Hz 64:27 */
1291 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 2490,
1292 2530, 2750, 0, 720, 725, 730, 750, 0,
1293 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1294 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1295 /* 111 - 1920x1080@48Hz 16:9 */
1296 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1297 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1298 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1299 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1300 /* 112 - 1920x1080@48Hz 64:27 */
1301 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1302 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1303 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1304 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1305 /* 113 - 2560x1080@48Hz 64:27 */
1306 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 3558,
1307 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1309 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1310 /* 114 - 3840x2160@48Hz 16:9 */
1311 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1312 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1313 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1314 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1315 /* 115 - 4096x2160@48Hz 256:135 */
1316 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5116,
1317 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1318 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1319 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1320 /* 116 - 3840x2160@48Hz 64:27 */
1321 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1322 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1323 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1324 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1325 /* 117 - 3840x2160@100Hz 16:9 */
1326 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1327 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1328 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1329 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1330 /* 118 - 3840x2160@120Hz 16:9 */
1331 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1332 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1333 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1334 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1335 /* 119 - 3840x2160@100Hz 64:27 */
1336 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1337 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1338 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1339 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1340 /* 120 - 3840x2160@120Hz 64:27 */
1341 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1342 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1343 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1344 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1345 /* 121 - 5120x2160@24Hz 64:27 */
1346 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 7116,
1347 7204, 7500, 0, 2160, 2168, 2178, 2200, 0,
1348 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1349 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1350 /* 122 - 5120x2160@25Hz 64:27 */
1351 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 6816,
1352 6904, 7200, 0, 2160, 2168, 2178, 2200, 0,
1353 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1354 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1355 /* 123 - 5120x2160@30Hz 64:27 */
1356 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 5784,
1357 5872, 6000, 0, 2160, 2168, 2178, 2200, 0,
1358 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1359 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1360 /* 124 - 5120x2160@48Hz 64:27 */
1361 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5866,
1362 5954, 6250, 0, 2160, 2168, 2178, 2475, 0,
1363 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1364 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1365 /* 125 - 5120x2160@50Hz 64:27 */
1366 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 6216,
1367 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1369 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1370 /* 126 - 5120x2160@60Hz 64:27 */
1371 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5284,
1372 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
1373 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1374 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1375 /* 127 - 5120x2160@100Hz 64:27 */
1376 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 6216,
1377 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1378 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1379 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001380};
1381
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001382/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001383 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001384 */
1385static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001386 /* 0 - dummy, VICs start at 1 */
1387 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001388 /* 1 - 3840x2160@30Hz */
1389 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1390 3840, 4016, 4104, 4400, 0,
1391 2160, 2168, 2178, 2250, 0,
1392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001393 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001394 /* 2 - 3840x2160@25Hz */
1395 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1396 3840, 4896, 4984, 5280, 0,
1397 2160, 2168, 2178, 2250, 0,
1398 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001399 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001400 /* 3 - 3840x2160@24Hz */
1401 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1402 3840, 5116, 5204, 5500, 0,
1403 2160, 2168, 2178, 2250, 0,
1404 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001405 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001406 /* 4 - 4096x2160@24Hz (SMPTE) */
1407 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1408 4096, 5116, 5204, 5500, 0,
1409 2160, 2168, 2178, 2250, 0,
1410 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Wayne Lind2b43472019-11-18 18:18:31 +08001411 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001412};
1413
Adam Jackson61e57a82010-03-29 21:43:18 +00001414/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001415
Adam Jackson083ae052009-09-23 17:30:45 -04001416static const u8 edid_header[] = {
1417 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1418};
Dave Airlief453ba02008-11-07 14:05:41 -08001419
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001420/**
1421 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1422 * @raw_edid: pointer to raw base EDID block
1423 *
1424 * Sanity check the header of the base EDID block.
1425 *
1426 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001427 */
1428int drm_edid_header_is_valid(const u8 *raw_edid)
1429{
1430 int i, score = 0;
1431
1432 for (i = 0; i < sizeof(edid_header); i++)
1433 if (raw_edid[i] == edid_header[i])
1434 score++;
1435
1436 return score;
1437}
1438EXPORT_SYMBOL(drm_edid_header_is_valid);
1439
Adam Jackson47819ba2012-05-30 16:42:39 -04001440static int edid_fixup __read_mostly = 6;
1441module_param_named(edid_fixup, edid_fixup, int, 0400);
1442MODULE_PARM_DESC(edid_fixup,
1443 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001444
Dave Airlie40d9b042014-10-20 16:29:33 +10001445static void drm_get_displayid(struct drm_connector *connector,
1446 struct edid *edid);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04001447static int validate_displayid(u8 *displayid, int length, int idx);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001448
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001449static int drm_edid_block_checksum(const u8 *raw_edid)
1450{
1451 int i;
1452 u8 csum = 0;
1453 for (i = 0; i < EDID_LENGTH; i++)
1454 csum += raw_edid[i];
1455
1456 return csum;
1457}
1458
Stefan Brünsd6885d62014-11-30 19:57:41 +01001459static bool drm_edid_is_zero(const u8 *in_edid, int length)
1460{
1461 if (memchr_inv(in_edid, 0, length))
1462 return false;
1463
1464 return true;
1465}
1466
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001467/**
1468 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1469 * @raw_edid: pointer to raw EDID block
1470 * @block: type of block to validate (0 for base, extension otherwise)
1471 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001472 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001473 *
1474 * Validate a base or extension EDID block and optionally dump bad blocks to
1475 * the console.
1476 *
1477 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001478 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001479bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1480 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001481{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001482 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001483 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001484
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001485 if (WARN_ON(!raw_edid))
1486 return false;
1487
Adam Jackson47819ba2012-05-30 16:42:39 -04001488 if (edid_fixup > 8 || edid_fixup < 0)
1489 edid_fixup = 6;
1490
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001491 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001492 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001493 if (score == 8) {
1494 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001495 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001496 } else if (score >= edid_fixup) {
1497 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1498 * The corrupt flag needs to be set here otherwise, the
1499 * fix-up code here will correct the problem, the
1500 * checksum is correct and the test fails
1501 */
1502 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001503 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001504 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1505 memcpy(raw_edid, edid_header, sizeof(edid_header));
1506 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001507 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001508 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001509 goto bad;
1510 }
1511 }
Dave Airlief453ba02008-11-07 14:05:41 -08001512
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001513 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001514 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001515 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001516 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001517
Adam Jackson4a638b42010-05-25 16:33:09 -04001518 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001519 if (raw_edid[0] == CEA_EXT) {
1520 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1521 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1522 } else {
1523 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001524 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001525
Adam Jackson4a638b42010-05-25 16:33:09 -04001526 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001527 }
Dave Airlief453ba02008-11-07 14:05:41 -08001528 }
1529
Adam Jackson61e57a82010-03-29 21:43:18 +00001530 /* per-block-type checks */
1531 switch (raw_edid[0]) {
1532 case 0: /* base */
1533 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001534 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001535 goto bad;
1536 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001537
Adam Jackson61e57a82010-03-29 21:43:18 +00001538 if (edid->revision > 4)
1539 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1540 break;
1541
1542 default:
1543 break;
1544 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001545
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001546 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001547
1548bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001549 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001550 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001551 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001552 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001553 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001554 print_hex_dump(KERN_NOTICE,
1555 " \t", DUMP_PREFIX_NONE, 16, 1,
1556 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001557 }
Dave Airlief453ba02008-11-07 14:05:41 -08001558 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001559 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001560}
Carsten Emdeda0df922012-03-18 22:37:33 +01001561EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001562
1563/**
1564 * drm_edid_is_valid - sanity check EDID data
1565 * @edid: EDID data
1566 *
1567 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001568 *
1569 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001570 */
1571bool drm_edid_is_valid(struct edid *edid)
1572{
1573 int i;
1574 u8 *raw = (u8 *)edid;
1575
1576 if (!edid)
1577 return false;
1578
1579 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001580 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001581 return false;
1582
1583 return true;
1584}
Alex Deucher3c537882010-02-05 04:21:19 -05001585EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001586
Adam Jackson61e57a82010-03-29 21:43:18 +00001587#define DDC_SEGMENT_ADDR 0x30
1588/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001589 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001590 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001591 * @buf: EDID data buffer to be filled
1592 * @block: 128 byte EDID block to start fetching from
1593 * @len: EDID data buffer length to fetch
1594 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001595 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001596 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001597 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001598 */
1599static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001600drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001601{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001602 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001603 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001604 unsigned char segment = block >> 1;
1605 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001606 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001607
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001608 /*
1609 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001610 * adapter reports EAGAIN. However, we find that bit-banging transfers
1611 * are susceptible to errors under a heavily loaded machine and
1612 * generate spurious NAKs and timeouts. Retrying the transfer
1613 * of the individual block a few times seems to overcome this.
1614 */
1615 do {
1616 struct i2c_msg msgs[] = {
1617 {
Shirish Scd004b32012-08-30 07:04:06 +00001618 .addr = DDC_SEGMENT_ADDR,
1619 .flags = 0,
1620 .len = 1,
1621 .buf = &segment,
1622 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001623 .addr = DDC_ADDR,
1624 .flags = 0,
1625 .len = 1,
1626 .buf = &start,
1627 }, {
1628 .addr = DDC_ADDR,
1629 .flags = I2C_M_RD,
1630 .len = len,
1631 .buf = buf,
1632 }
1633 };
Shirish Scd004b32012-08-30 07:04:06 +00001634
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001635 /*
1636 * Avoid sending the segment addr to not upset non-compliant
1637 * DDC monitors.
1638 */
Shirish Scd004b32012-08-30 07:04:06 +00001639 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1640
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001641 if (ret == -ENXIO) {
1642 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1643 adapter->name);
1644 break;
1645 }
Shirish Scd004b32012-08-30 07:04:06 +00001646 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001647
Shirish Scd004b32012-08-30 07:04:06 +00001648 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001649}
1650
Chris Wilson14544d02016-10-24 12:38:21 +01001651static void connector_bad_edid(struct drm_connector *connector,
1652 u8 *edid, int num_blocks)
1653{
1654 int i;
1655
Jani Nikulaf0a8f532019-10-01 17:06:14 +03001656 if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
Chris Wilson14544d02016-10-24 12:38:21 +01001657 return;
1658
1659 dev_warn(connector->dev->dev,
1660 "%s: EDID is invalid:\n",
1661 connector->name);
1662 for (i = 0; i < num_blocks; i++) {
1663 u8 *block = edid + i * EDID_LENGTH;
1664 char prefix[20];
1665
1666 if (drm_edid_is_zero(block, EDID_LENGTH))
1667 sprintf(prefix, "\t[%02x] ZERO ", i);
1668 else if (!drm_edid_block_valid(block, i, false, NULL))
1669 sprintf(prefix, "\t[%02x] BAD ", i);
1670 else
1671 sprintf(prefix, "\t[%02x] GOOD ", i);
1672
1673 print_hex_dump(KERN_WARNING,
1674 prefix, DUMP_PREFIX_NONE, 16, 1,
1675 block, EDID_LENGTH, false);
1676 }
1677}
1678
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001679/* Get override or firmware EDID */
1680static struct edid *drm_get_override_edid(struct drm_connector *connector)
1681{
1682 struct edid *override = NULL;
1683
1684 if (connector->override_edid)
1685 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1686
1687 if (!override)
1688 override = drm_load_edid_firmware(connector);
1689
1690 return IS_ERR(override) ? NULL : override;
1691}
1692
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001693/**
Jani Nikula48eaeb72019-06-10 12:30:54 +03001694 * drm_add_override_edid_modes - add modes from override/firmware EDID
1695 * @connector: connector we're probing
1696 *
1697 * Add modes from the override/firmware EDID, if available. Only to be used from
1698 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1699 * failed during drm_get_edid() and caused the override/firmware EDID to be
1700 * skipped.
1701 *
1702 * Return: The number of modes added or 0 if we couldn't find any.
1703 */
1704int drm_add_override_edid_modes(struct drm_connector *connector)
1705{
1706 struct edid *override;
1707 int num_modes = 0;
1708
1709 override = drm_get_override_edid(connector);
1710 if (override) {
1711 drm_connector_update_edid_property(connector, override);
1712 num_modes = drm_add_edid_modes(connector, override);
1713 kfree(override);
1714
1715 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1716 connector->base.id, connector->name, num_modes);
1717 }
1718
1719 return num_modes;
1720}
1721EXPORT_SYMBOL(drm_add_override_edid_modes);
1722
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001723/**
1724 * drm_do_get_edid - get EDID data using a custom EDID block read function
1725 * @connector: connector we're probing
1726 * @get_edid_block: EDID block read function
1727 * @data: private data passed to the block read function
1728 *
1729 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1730 * exposes a different interface to read EDID blocks this function can be used
1731 * to get EDID data using a custom block read function.
1732 *
1733 * As in the general case the DDC bus is accessible by the kernel at the I2C
1734 * level, drivers must make all reasonable efforts to expose it as an I2C
1735 * adapter and use drm_get_edid() instead of abusing this function.
1736 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001737 * The EDID may be overridden using debugfs override_edid or firmare EDID
1738 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1739 * order. Having either of them bypasses actual EDID reads.
1740 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001741 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1742 */
1743struct edid *drm_do_get_edid(struct drm_connector *connector,
1744 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1745 size_t len),
1746 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001747{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001748 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001749 u8 *edid, *new;
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001750 struct edid *override;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001751
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001752 override = drm_get_override_edid(connector);
1753 if (override)
Jani Nikula53fd40a2017-09-12 11:19:26 +03001754 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001755
Chris Wilsonf14f3682016-10-17 09:35:12 +01001756 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001757 return NULL;
1758
1759 /* base block fetch */
1760 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001761 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001762 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001763 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001764 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001765 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001766 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001767 connector->null_edid_counter++;
1768 goto carp;
1769 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001770 }
1771 if (i == 4)
1772 goto carp;
1773
1774 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001775 valid_extensions = edid[0x7e];
1776 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001777 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001778
Chris Wilson14544d02016-10-24 12:38:21 +01001779 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001780 if (!new)
1781 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001782 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001783
Chris Wilsonf14f3682016-10-17 09:35:12 +01001784 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001785 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001786
Adam Jackson61e57a82010-03-29 21:43:18 +00001787 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001788 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001789 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001790 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001791 break;
1792 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001793
Chris Wilson14544d02016-10-24 12:38:21 +01001794 if (i == 4)
1795 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001796 }
1797
Chris Wilsonf14f3682016-10-17 09:35:12 +01001798 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001799 u8 *base;
1800
1801 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1802
Chris Wilsonf14f3682016-10-17 09:35:12 +01001803 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1804 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001805
Kees Cook6da2ec52018-06-12 13:55:00 -07001806 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
1807 GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001808 if (!new)
1809 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001810
1811 base = new;
1812 for (i = 0; i <= edid[0x7e]; i++) {
1813 u8 *block = edid + i * EDID_LENGTH;
1814
1815 if (!drm_edid_block_valid(block, i, false, NULL))
1816 continue;
1817
1818 memcpy(base, block, EDID_LENGTH);
1819 base += EDID_LENGTH;
1820 }
1821
1822 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001823 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001824 }
1825
Chris Wilsonf14f3682016-10-17 09:35:12 +01001826 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001827
1828carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001829 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001830out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001831 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001832 return NULL;
1833}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001834EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001835
1836/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001837 * drm_probe_ddc() - probe DDC presence
1838 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001839 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001840 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001841 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001842bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001843drm_probe_ddc(struct i2c_adapter *adapter)
1844{
1845 unsigned char out;
1846
1847 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1848}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001849EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001850
1851/**
1852 * drm_get_edid - get EDID data, if available
1853 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001854 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001855 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001856 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001857 * attach it to the connector.
1858 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001859 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001860 */
1861struct edid *drm_get_edid(struct drm_connector *connector,
1862 struct i2c_adapter *adapter)
1863{
Dave Airlie40d9b042014-10-20 16:29:33 +10001864 struct edid *edid;
1865
Jani Nikula15f080f2017-02-17 17:20:53 +02001866 if (connector->force == DRM_FORCE_OFF)
1867 return NULL;
1868
1869 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001870 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001871
Dave Airlie40d9b042014-10-20 16:29:33 +10001872 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1873 if (edid)
1874 drm_get_displayid(connector, edid);
1875 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001876}
1877EXPORT_SYMBOL(drm_get_edid);
1878
Jani Nikula51f8da52013-09-27 15:08:27 +03001879/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001880 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1881 * @connector: connector we're probing
1882 * @adapter: I2C adapter to use for DDC
1883 *
1884 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1885 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1886 * switch DDC to the GPU which is retrieving EDID.
1887 *
1888 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1889 */
1890struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1891 struct i2c_adapter *adapter)
1892{
1893 struct pci_dev *pdev = connector->dev->pdev;
1894 struct edid *edid;
1895
1896 vga_switcheroo_lock_ddc(pdev);
1897 edid = drm_get_edid(connector, adapter);
1898 vga_switcheroo_unlock_ddc(pdev);
1899
1900 return edid;
1901}
1902EXPORT_SYMBOL(drm_get_edid_switcheroo);
1903
1904/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001905 * drm_edid_duplicate - duplicate an EDID and the extensions
1906 * @edid: EDID to duplicate
1907 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001908 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001909 */
1910struct edid *drm_edid_duplicate(const struct edid *edid)
1911{
1912 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1913}
1914EXPORT_SYMBOL(drm_edid_duplicate);
1915
Adam Jackson61e57a82010-03-29 21:43:18 +00001916/*** EDID parsing ***/
1917
Dave Airlief453ba02008-11-07 14:05:41 -08001918/**
1919 * edid_vendor - match a string against EDID's obfuscated vendor field
1920 * @edid: EDID to match
1921 * @vendor: vendor string
1922 *
1923 * Returns true if @vendor is in @edid, false otherwise
1924 */
Keith Packard170178f2017-12-13 00:44:26 -08001925static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001926{
1927 char edid_vendor[3];
1928
1929 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1930 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1931 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001932 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001933
1934 return !strncmp(edid_vendor, vendor, 3);
1935}
1936
1937/**
1938 * edid_get_quirks - return quirk flags for a given EDID
1939 * @edid: EDID to process
1940 *
1941 * This tells subsequent routines what fixes they need to apply.
1942 */
Keith Packard170178f2017-12-13 00:44:26 -08001943static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001944{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001945 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001946 int i;
1947
1948 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1949 quirk = &edid_quirk_list[i];
1950
1951 if (edid_vendor(edid, quirk->vendor) &&
1952 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1953 return quirk->quirks;
1954 }
1955
1956 return 0;
1957}
1958
1959#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001960#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001961
Dave Airlief453ba02008-11-07 14:05:41 -08001962/**
1963 * edid_fixup_preferred - set preferred modes based on quirk list
1964 * @connector: has mode list to fix up
1965 * @quirks: quirks list
1966 *
1967 * Walk the mode list for @connector, clearing the preferred status
1968 * on existing modes and setting it anew for the right mode ala @quirks.
1969 */
1970static void edid_fixup_preferred(struct drm_connector *connector,
1971 u32 quirks)
1972{
1973 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001974 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001975 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001976
1977 if (list_empty(&connector->probed_modes))
1978 return;
1979
1980 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1981 target_refresh = 60;
1982 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1983 target_refresh = 75;
1984
1985 preferred_mode = list_first_entry(&connector->probed_modes,
1986 struct drm_display_mode, head);
1987
1988 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1989 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1990
1991 if (cur_mode == preferred_mode)
1992 continue;
1993
1994 /* Largest mode is preferred */
1995 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1996 preferred_mode = cur_mode;
1997
Alex Deucher339d2022013-08-15 11:42:14 -04001998 cur_vrefresh = cur_mode->vrefresh ?
1999 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
2000 preferred_vrefresh = preferred_mode->vrefresh ?
2001 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002002 /* At a given size, try to get closest to target refresh */
2003 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04002004 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
2005 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08002006 preferred_mode = cur_mode;
2007 }
2008 }
2009
2010 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
2011}
2012
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002013static bool
2014mode_is_rb(const struct drm_display_mode *mode)
2015{
2016 return (mode->htotal - mode->hdisplay == 160) &&
2017 (mode->hsync_end - mode->hdisplay == 80) &&
2018 (mode->hsync_end - mode->hsync_start == 32) &&
2019 (mode->vsync_start - mode->vdisplay == 3);
2020}
2021
Adam Jackson33c75312012-04-13 16:33:29 -04002022/*
2023 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
2024 * @dev: Device to duplicate against
2025 * @hsize: Mode width
2026 * @vsize: Mode height
2027 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002028 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04002029 *
2030 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002031 *
2032 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04002033 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002034struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002035 int hsize, int vsize, int fresh,
2036 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08002037{
Adam Jackson07a5e632009-12-03 17:44:38 -05002038 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08002039
Thierry Redinga6b21832012-11-23 15:01:42 +01002040 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002041 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002042 if (hsize != ptr->hdisplay)
2043 continue;
2044 if (vsize != ptr->vdisplay)
2045 continue;
2046 if (fresh != drm_mode_vrefresh(ptr))
2047 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002048 if (rb != mode_is_rb(ptr))
2049 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002050
2051 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08002052 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002053
2054 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002055}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002056EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04002057
Adam Jacksond1ff6402010-03-29 21:43:26 +00002058typedef void detailed_cb(struct detailed_timing *timing, void *closure);
2059
2060static void
Adam Jackson4d76a222010-08-03 14:38:17 -04002061cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2062{
2063 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002064 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04002065 u8 *det_base = ext + d;
2066
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002067 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04002068 for (i = 0; i < n; i++)
2069 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2070}
2071
2072static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002073vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2074{
2075 unsigned int i, n = min((int)ext[0x02], 6);
2076 u8 *det_base = ext + 5;
2077
2078 if (ext[0x01] != 1)
2079 return; /* unknown version */
2080
2081 for (i = 0; i < n; i++)
2082 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2083}
2084
2085static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00002086drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
2087{
2088 int i;
2089 struct edid *edid = (struct edid *)raw_edid;
2090
2091 if (edid == NULL)
2092 return;
2093
2094 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
2095 cb(&(edid->detailed_timings[i]), closure);
2096
Adam Jackson4d76a222010-08-03 14:38:17 -04002097 for (i = 1; i <= raw_edid[0x7e]; i++) {
2098 u8 *ext = raw_edid + (i * EDID_LENGTH);
2099 switch (*ext) {
2100 case CEA_EXT:
2101 cea_for_each_detailed_block(ext, cb, closure);
2102 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002103 case VTB_EXT:
2104 vtb_for_each_detailed_block(ext, cb, closure);
2105 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04002106 default:
2107 break;
2108 }
2109 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00002110}
2111
2112static void
2113is_rb(struct detailed_timing *t, void *data)
2114{
2115 u8 *r = (u8 *)t;
2116 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
2117 if (r[15] & 0x10)
2118 *(bool *)data = true;
2119}
2120
2121/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2122static bool
2123drm_monitor_supports_rb(struct edid *edid)
2124{
2125 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02002126 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00002127 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2128 return ret;
2129 }
2130
2131 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2132}
2133
Adam Jackson7a374352010-03-29 21:43:30 +00002134static void
2135find_gtf2(struct detailed_timing *t, void *data)
2136{
2137 u8 *r = (u8 *)t;
2138 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
2139 *(u8 **)data = r;
2140}
2141
2142/* Secondary GTF curve kicks in above some break frequency */
2143static int
2144drm_gtf2_hbreak(struct edid *edid)
2145{
2146 u8 *r = NULL;
2147 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2148 return r ? (r[12] * 2) : 0;
2149}
2150
2151static int
2152drm_gtf2_2c(struct edid *edid)
2153{
2154 u8 *r = NULL;
2155 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2156 return r ? r[13] : 0;
2157}
2158
2159static int
2160drm_gtf2_m(struct edid *edid)
2161{
2162 u8 *r = NULL;
2163 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2164 return r ? (r[15] << 8) + r[14] : 0;
2165}
2166
2167static int
2168drm_gtf2_k(struct edid *edid)
2169{
2170 u8 *r = NULL;
2171 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2172 return r ? r[16] : 0;
2173}
2174
2175static int
2176drm_gtf2_2j(struct edid *edid)
2177{
2178 u8 *r = NULL;
2179 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2180 return r ? r[17] : 0;
2181}
2182
2183/**
2184 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2185 * @edid: EDID block to scan
2186 */
2187static int standard_timing_level(struct edid *edid)
2188{
2189 if (edid->revision >= 2) {
2190 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2191 return LEVEL_CVT;
2192 if (drm_gtf2_hbreak(edid))
2193 return LEVEL_GTF2;
Lee Shawn Cbfef04a2019-10-07 21:51:27 +08002194 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
2195 return LEVEL_GTF;
Adam Jackson7a374352010-03-29 21:43:30 +00002196 }
2197 return LEVEL_DMT;
2198}
2199
Adam Jackson23425ca2009-09-23 17:30:58 -04002200/*
2201 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2202 * monitors fill with ascii space (0x20) instead.
2203 */
2204static int
2205bad_std_timing(u8 a, u8 b)
2206{
2207 return (a == 0x00 && b == 0x00) ||
2208 (a == 0x01 && b == 0x01) ||
2209 (a == 0x20 && b == 0x20);
2210}
2211
Dave Airlief453ba02008-11-07 14:05:41 -08002212/**
2213 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002214 * @connector: connector of for the EDID block
2215 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002216 * @t: standard timing params
2217 *
2218 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002219 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002220 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002221static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002222drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002223 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002224{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002225 struct drm_device *dev = connector->dev;
2226 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002227 int hsize, vsize;
2228 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002229 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2230 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002231 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2232 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002233 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002234
Adam Jackson23425ca2009-09-23 17:30:58 -04002235 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2236 return NULL;
2237
Zhao Yakui5c612592009-06-22 13:17:10 +08002238 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2239 hsize = t->hsize * 8 + 248;
2240 /* vrefresh_rate = vfreq + 60 */
2241 vrefresh_rate = vfreq + 60;
2242 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002243 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002244 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002245 vsize = hsize;
2246 else
2247 vsize = (hsize * 10) / 16;
2248 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002249 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002250 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002251 vsize = (hsize * 4) / 5;
2252 else
2253 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002254
2255 /* HDTV hack, part 1 */
2256 if (vrefresh_rate == 60 &&
2257 ((hsize == 1360 && vsize == 765) ||
2258 (hsize == 1368 && vsize == 769))) {
2259 hsize = 1366;
2260 vsize = 768;
2261 }
2262
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002263 /*
2264 * If this connector already has a mode for this size and refresh
2265 * rate (because it came from detailed or CVT info), use that
2266 * instead. This way we don't have to guess at interlace or
2267 * reduced blanking.
2268 */
Adam Jackson522032d2010-04-09 16:52:49 +00002269 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002270 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2271 drm_mode_vrefresh(m) == vrefresh_rate)
2272 return NULL;
2273
Adam Jacksona0910c82010-03-29 21:43:28 +00002274 /* HDTV hack, part 2 */
2275 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2276 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002277 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002278 if (!mode)
2279 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002280 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002281 mode->hsync_start = mode->hsync_start - 1;
2282 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002283 return mode;
2284 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002285
Zhao Yakui559ee212009-09-03 09:33:47 +08002286 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002287 if (drm_monitor_supports_rb(edid)) {
2288 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2289 true);
2290 if (mode)
2291 return mode;
2292 }
2293 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002294 if (mode)
2295 return mode;
2296
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002297 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002298 switch (timing_level) {
2299 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002300 break;
2301 case LEVEL_GTF:
2302 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2303 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002304 case LEVEL_GTF2:
2305 /*
2306 * This is potentially wrong if there's ever a monitor with
2307 * more than one ranges section, each claiming a different
2308 * secondary GTF curve. Please don't do that.
2309 */
2310 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002311 if (!mode)
2312 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002313 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002314 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002315 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2316 vrefresh_rate, 0, 0,
2317 drm_gtf2_m(edid),
2318 drm_gtf2_2c(edid),
2319 drm_gtf2_k(edid),
2320 drm_gtf2_2j(edid));
2321 }
2322 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002323 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002324 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2325 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002326 break;
2327 }
Dave Airlief453ba02008-11-07 14:05:41 -08002328 return mode;
2329}
2330
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002331/*
2332 * EDID is delightfully ambiguous about how interlaced modes are to be
2333 * encoded. Our internal representation is of frame height, but some
2334 * HDTV detailed timings are encoded as field height.
2335 *
2336 * The format list here is from CEA, in frame size. Technically we
2337 * should be checking refresh rate too. Whatever.
2338 */
2339static void
2340drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2341 struct detailed_pixel_timing *pt)
2342{
2343 int i;
2344 static const struct {
2345 int w, h;
2346 } cea_interlaced[] = {
2347 { 1920, 1080 },
2348 { 720, 480 },
2349 { 1440, 480 },
2350 { 2880, 480 },
2351 { 720, 576 },
2352 { 1440, 576 },
2353 { 2880, 576 },
2354 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002355
2356 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2357 return;
2358
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002359 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002360 if ((mode->hdisplay == cea_interlaced[i].w) &&
2361 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2362 mode->vdisplay *= 2;
2363 mode->vsync_start *= 2;
2364 mode->vsync_end *= 2;
2365 mode->vtotal *= 2;
2366 mode->vtotal |= 1;
2367 }
2368 }
2369
2370 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2371}
2372
Dave Airlief453ba02008-11-07 14:05:41 -08002373/**
2374 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2375 * @dev: DRM device (needed to create new mode)
2376 * @edid: EDID block
2377 * @timing: EDID detailed timing info
2378 * @quirks: quirks to apply
2379 *
2380 * An EDID detailed timing block contains enough info for us to create and
2381 * return a new struct drm_display_mode.
2382 */
2383static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2384 struct edid *edid,
2385 struct detailed_timing *timing,
2386 u32 quirks)
2387{
2388 struct drm_display_mode *mode;
2389 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002390 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2391 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2392 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2393 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002394 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2395 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 +01002396 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 +02002397 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 -08002398
Adam Jacksonfc438962009-06-04 10:20:34 +10002399 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002400 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002401 return NULL;
2402
Michel Dänzer0454bea2009-06-15 16:56:07 +02002403 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002404 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002405 return NULL;
2406 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002407 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002408 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002409 }
2410
Zhao Yakuifcb45612009-10-14 09:11:25 +08002411 /* it is incorrect if hsync/vsync width is zero */
2412 if (!hsync_pulse_width || !vsync_pulse_width) {
2413 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2414 "Wrong Hsync/Vsync pulse width\n");
2415 return NULL;
2416 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002417
2418 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2419 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2420 if (!mode)
2421 return NULL;
2422
2423 goto set_size;
2424 }
2425
Dave Airlief453ba02008-11-07 14:05:41 -08002426 mode = drm_mode_create(dev);
2427 if (!mode)
2428 return NULL;
2429
Dave Airlief453ba02008-11-07 14:05:41 -08002430 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002431 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002432
Michel Dänzer0454bea2009-06-15 16:56:07 +02002433 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002434
Michel Dänzer0454bea2009-06-15 16:56:07 +02002435 mode->hdisplay = hactive;
2436 mode->hsync_start = mode->hdisplay + hsync_offset;
2437 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2438 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002439
Michel Dänzer0454bea2009-06-15 16:56:07 +02002440 mode->vdisplay = vactive;
2441 mode->vsync_start = mode->vdisplay + vsync_offset;
2442 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2443 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002444
Jesse Barnes7064fef2009-11-05 10:12:54 -08002445 /* Some EDIDs have bogus h/vtotal values */
2446 if (mode->hsync_end > mode->htotal)
2447 mode->htotal = mode->hsync_end + 1;
2448 if (mode->vsync_end > mode->vtotal)
2449 mode->vtotal = mode->vsync_end + 1;
2450
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002451 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002452
2453 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002454 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002455 }
2456
Michel Dänzer0454bea2009-06-15 16:56:07 +02002457 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2458 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2459 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2460 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002461
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002462set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002463 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2464 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002465
2466 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2467 mode->width_mm *= 10;
2468 mode->height_mm *= 10;
2469 }
2470
2471 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2472 mode->width_mm = edid->width_cm * 10;
2473 mode->height_mm = edid->height_cm * 10;
2474 }
2475
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002476 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002477 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002478 drm_mode_set_name(mode);
2479
Dave Airlief453ba02008-11-07 14:05:41 -08002480 return mode;
2481}
2482
Adam Jackson07a5e632009-12-03 17:44:38 -05002483static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002484mode_in_hsync_range(const struct drm_display_mode *mode,
2485 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002486{
2487 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002488
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002489 hmin = t[7];
2490 if (edid->revision >= 4)
2491 hmin += ((t[4] & 0x04) ? 255 : 0);
2492 hmax = t[8];
2493 if (edid->revision >= 4)
2494 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002495 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002496
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002497 return (hsync <= hmax && hsync >= hmin);
2498}
2499
2500static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002501mode_in_vsync_range(const struct drm_display_mode *mode,
2502 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002503{
2504 int vsync, vmin, vmax;
2505
2506 vmin = t[5];
2507 if (edid->revision >= 4)
2508 vmin += ((t[4] & 0x01) ? 255 : 0);
2509 vmax = t[6];
2510 if (edid->revision >= 4)
2511 vmax += ((t[4] & 0x02) ? 255 : 0);
2512 vsync = drm_mode_vrefresh(mode);
2513
2514 return (vsync <= vmax && vsync >= vmin);
2515}
2516
2517static u32
2518range_pixel_clock(struct edid *edid, u8 *t)
2519{
2520 /* unspecified */
2521 if (t[9] == 0 || t[9] == 255)
2522 return 0;
2523
2524 /* 1.4 with CVT support gives us real precision, yay */
2525 if (edid->revision >= 4 && t[10] == 0x04)
2526 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2527
2528 /* 1.3 is pathetic, so fuzz up a bit */
2529 return t[9] * 10000 + 5001;
2530}
2531
Adam Jackson07a5e632009-12-03 17:44:38 -05002532static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002533mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002534 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002535{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002536 u32 max_clock;
2537 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002538
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002539 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002540 return false;
2541
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002542 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002543 return false;
2544
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002545 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002546 if (mode->clock > max_clock)
2547 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002548
2549 /* 1.4 max horizontal check */
2550 if (edid->revision >= 4 && t[10] == 0x04)
2551 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2552 return false;
2553
2554 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2555 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002556
2557 return true;
2558}
2559
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002560static bool valid_inferred_mode(const struct drm_connector *connector,
2561 const struct drm_display_mode *mode)
2562{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002563 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002564 bool ok = false;
2565
2566 list_for_each_entry(m, &connector->probed_modes, head) {
2567 if (mode->hdisplay == m->hdisplay &&
2568 mode->vdisplay == m->vdisplay &&
2569 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2570 return false; /* duplicated */
2571 if (mode->hdisplay <= m->hdisplay &&
2572 mode->vdisplay <= m->vdisplay)
2573 ok = true;
2574 }
2575 return ok;
2576}
2577
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002578static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002579drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002580 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002581{
2582 int i, modes = 0;
2583 struct drm_display_mode *newmode;
2584 struct drm_device *dev = connector->dev;
2585
Thierry Redinga6b21832012-11-23 15:01:42 +01002586 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002587 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2588 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002589 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2590 if (newmode) {
2591 drm_mode_probed_add(connector, newmode);
2592 modes++;
2593 }
2594 }
2595 }
2596
2597 return modes;
2598}
2599
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002600/* fix up 1366x768 mode from 1368x768;
2601 * GFT/CVT can't express 1366 width which isn't dividable by 8
2602 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002603void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002604{
2605 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2606 mode->hdisplay = 1366;
2607 mode->hsync_start--;
2608 mode->hsync_end--;
2609 drm_mode_set_name(mode);
2610 }
2611}
2612
Adam Jacksonb309bd32012-04-13 16:33:40 -04002613static int
2614drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2615 struct detailed_timing *timing)
2616{
2617 int i, modes = 0;
2618 struct drm_display_mode *newmode;
2619 struct drm_device *dev = connector->dev;
2620
Thierry Redinga6b21832012-11-23 15:01:42 +01002621 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002622 const struct minimode *m = &extra_modes[i];
2623 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002624 if (!newmode)
2625 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002626
Takashi Iwai969218f2017-01-17 17:43:29 +01002627 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002628 if (!mode_in_range(newmode, edid, timing) ||
2629 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002630 drm_mode_destroy(dev, newmode);
2631 continue;
2632 }
2633
2634 drm_mode_probed_add(connector, newmode);
2635 modes++;
2636 }
2637
2638 return modes;
2639}
2640
2641static int
2642drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2643 struct detailed_timing *timing)
2644{
2645 int i, modes = 0;
2646 struct drm_display_mode *newmode;
2647 struct drm_device *dev = connector->dev;
2648 bool rb = drm_monitor_supports_rb(edid);
2649
Thierry Redinga6b21832012-11-23 15:01:42 +01002650 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002651 const struct minimode *m = &extra_modes[i];
2652 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002653 if (!newmode)
2654 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002655
Takashi Iwai969218f2017-01-17 17:43:29 +01002656 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002657 if (!mode_in_range(newmode, edid, timing) ||
2658 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002659 drm_mode_destroy(dev, newmode);
2660 continue;
2661 }
2662
2663 drm_mode_probed_add(connector, newmode);
2664 modes++;
2665 }
2666
2667 return modes;
2668}
2669
Adam Jackson13931572010-08-03 14:38:19 -04002670static void
2671do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002672{
Adam Jackson13931572010-08-03 14:38:19 -04002673 struct detailed_mode_closure *closure = c;
2674 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002675 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002676
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002677 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2678 return;
2679
2680 closure->modes += drm_dmt_modes_for_range(closure->connector,
2681 closure->edid,
2682 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002683
2684 if (!version_greater(closure->edid, 1, 1))
2685 return; /* GTF not defined yet */
2686
2687 switch (range->flags) {
2688 case 0x02: /* secondary gtf, XXX could do more */
2689 case 0x00: /* default gtf */
2690 closure->modes += drm_gtf_modes_for_range(closure->connector,
2691 closure->edid,
2692 timing);
2693 break;
2694 case 0x04: /* cvt, only in 1.4+ */
2695 if (!version_greater(closure->edid, 1, 3))
2696 break;
2697
2698 closure->modes += drm_cvt_modes_for_range(closure->connector,
2699 closure->edid,
2700 timing);
2701 break;
2702 case 0x01: /* just the ranges, no formula */
2703 default:
2704 break;
2705 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002706}
2707
Adam Jackson13931572010-08-03 14:38:19 -04002708static int
2709add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2710{
2711 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002712 .connector = connector,
2713 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002714 };
2715
2716 if (version_greater(edid, 1, 0))
2717 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2718 &closure);
2719
2720 return closure.modes;
2721}
2722
Adam Jackson2255be12010-03-29 21:43:22 +00002723static int
2724drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2725{
2726 int i, j, m, modes = 0;
2727 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002728 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002729
2730 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002731 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002732 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002733 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002734 break;
2735 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002736 mode = drm_mode_find_dmt(connector->dev,
2737 est3_modes[m].w,
2738 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002739 est3_modes[m].r,
2740 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002741 if (mode) {
2742 drm_mode_probed_add(connector, mode);
2743 modes++;
2744 }
2745 }
2746 }
2747 }
2748
2749 return modes;
2750}
2751
Adam Jackson13931572010-08-03 14:38:19 -04002752static void
2753do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002754{
Adam Jackson13931572010-08-03 14:38:19 -04002755 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002756 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002757
2758 if (data->type == EDID_DETAIL_EST_TIMINGS)
2759 closure->modes += drm_est3_modes(closure->connector, timing);
2760}
2761
2762/**
2763 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002764 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002765 * @edid: EDID block to scan
2766 *
2767 * Each EDID block contains a bitmap of the supported "established modes" list
2768 * (defined above). Tease them out and add them to the global modes list.
2769 */
2770static int
2771add_established_modes(struct drm_connector *connector, struct edid *edid)
2772{
Adam Jackson9cf00972009-12-03 17:44:36 -05002773 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002774 unsigned long est_bits = edid->established_timings.t1 |
2775 (edid->established_timings.t2 << 8) |
2776 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2777 int i, modes = 0;
2778 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002779 .connector = connector,
2780 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002781 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002782
Adam Jackson13931572010-08-03 14:38:19 -04002783 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2784 if (est_bits & (1<<i)) {
2785 struct drm_display_mode *newmode;
2786 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2787 if (newmode) {
2788 drm_mode_probed_add(connector, newmode);
2789 modes++;
2790 }
2791 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002792 }
2793
Adam Jackson13931572010-08-03 14:38:19 -04002794 if (version_greater(edid, 1, 0))
2795 drm_for_each_detailed_block((u8 *)edid,
2796 do_established_modes, &closure);
2797
2798 return modes + closure.modes;
2799}
2800
2801static void
2802do_standard_modes(struct detailed_timing *timing, void *c)
2803{
2804 struct detailed_mode_closure *closure = c;
2805 struct detailed_non_pixel *data = &timing->data.other_data;
2806 struct drm_connector *connector = closure->connector;
2807 struct edid *edid = closure->edid;
2808
2809 if (data->type == EDID_DETAIL_STD_MODES) {
2810 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002811 for (i = 0; i < 6; i++) {
2812 struct std_timing *std;
2813 struct drm_display_mode *newmode;
2814
2815 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002816 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002817 if (newmode) {
2818 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002819 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002820 }
2821 }
Adam Jackson13931572010-08-03 14:38:19 -04002822 }
2823}
2824
2825/**
2826 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002827 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002828 * @edid: EDID block to scan
2829 *
2830 * Standard modes can be calculated using the appropriate standard (DMT,
2831 * GTF or CVT. Grab them from @edid and add them to the list.
2832 */
2833static int
2834add_standard_modes(struct drm_connector *connector, struct edid *edid)
2835{
2836 int i, modes = 0;
2837 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002838 .connector = connector,
2839 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002840 };
2841
2842 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2843 struct drm_display_mode *newmode;
2844
2845 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002846 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002847 if (newmode) {
2848 drm_mode_probed_add(connector, newmode);
2849 modes++;
2850 }
2851 }
2852
2853 if (version_greater(edid, 1, 0))
2854 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2855 &closure);
2856
2857 /* XXX should also look for standard codes in VTB blocks */
2858
2859 return modes + closure.modes;
2860}
2861
Dave Airlief453ba02008-11-07 14:05:41 -08002862static int drm_cvt_modes(struct drm_connector *connector,
2863 struct detailed_timing *timing)
2864{
2865 int i, j, modes = 0;
2866 struct drm_display_mode *newmode;
2867 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002868 struct cvt_timing *cvt;
2869 const int rates[] = { 60, 85, 75, 60, 50 };
2870 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002871
2872 for (i = 0; i < 4; i++) {
2873 int uninitialized_var(width), height;
2874 cvt = &(timing->data.other_data.data.cvt[i]);
2875
2876 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002877 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002878
2879 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002880 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002881 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002882 width = height * 4 / 3;
2883 break;
2884 case 0x04:
2885 width = height * 16 / 9;
2886 break;
2887 case 0x08:
2888 width = height * 16 / 10;
2889 break;
2890 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002891 width = height * 15 / 9;
2892 break;
2893 }
2894
2895 for (j = 1; j < 5; j++) {
2896 if (cvt->code[2] & (1 << j)) {
2897 newmode = drm_cvt_mode(dev, width, height,
2898 rates[j], j == 0,
2899 false, false);
2900 if (newmode) {
2901 drm_mode_probed_add(connector, newmode);
2902 modes++;
2903 }
2904 }
2905 }
2906 }
2907
2908 return modes;
2909}
2910
Adam Jackson13931572010-08-03 14:38:19 -04002911static void
2912do_cvt_mode(struct detailed_timing *timing, void *c)
2913{
2914 struct detailed_mode_closure *closure = c;
2915 struct detailed_non_pixel *data = &timing->data.other_data;
2916
2917 if (data->type == EDID_DETAIL_CVT_3BYTE)
2918 closure->modes += drm_cvt_modes(closure->connector, timing);
2919}
Adam Jackson9cf00972009-12-03 17:44:36 -05002920
2921static int
Adam Jackson13931572010-08-03 14:38:19 -04002922add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2923{
2924 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002925 .connector = connector,
2926 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002927 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002928
Adam Jackson13931572010-08-03 14:38:19 -04002929 if (version_greater(edid, 1, 2))
2930 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002931
Adam Jackson13931572010-08-03 14:38:19 -04002932 /* XXX should also look for CVT codes in VTB blocks */
2933
2934 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002935}
2936
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002937static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2938
Adam Jackson13931572010-08-03 14:38:19 -04002939static void
2940do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002941{
Adam Jackson13931572010-08-03 14:38:19 -04002942 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002943 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002944
2945 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002946 newmode = drm_mode_detailed(closure->connector->dev,
2947 closure->edid, timing,
2948 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002949 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002950 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002951
Adam Jackson13931572010-08-03 14:38:19 -04002952 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002953 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2954
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002955 /*
2956 * Detailed modes are limited to 10kHz pixel clock resolution,
2957 * so fix up anything that looks like CEA/HDMI mode, but the clock
2958 * is just slightly off.
2959 */
2960 fixup_detailed_cea_mode_clock(newmode);
2961
Adam Jackson13931572010-08-03 14:38:19 -04002962 drm_mode_probed_add(closure->connector, newmode);
2963 closure->modes++;
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002964 closure->preferred = false;
Zhao Yakui882f0212009-08-26 18:20:49 +08002965 }
Ma Ling167f3a02009-03-20 14:09:48 +08002966}
2967
Adam Jackson13931572010-08-03 14:38:19 -04002968/*
2969 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002970 * @connector: attached connector
2971 * @edid: EDID block to scan
2972 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002973 */
Adam Jackson13931572010-08-03 14:38:19 -04002974static int
2975add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2976 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002977{
Adam Jackson13931572010-08-03 14:38:19 -04002978 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002979 .connector = connector,
2980 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002981 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02002982 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002983 };
Dave Airlief453ba02008-11-07 14:05:41 -08002984
Adam Jackson13931572010-08-03 14:38:19 -04002985 if (closure.preferred && !version_greater(edid, 1, 3))
2986 closure.preferred =
2987 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002988
Adam Jackson13931572010-08-03 14:38:19 -04002989 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002990
Adam Jackson13931572010-08-03 14:38:19 -04002991 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002992}
Dave Airlief453ba02008-11-07 14:05:41 -08002993
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002994#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002995#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002996#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002997#define SPEAKER_BLOCK 0x04
Uma Shankare85959d2019-05-16 19:40:08 +05302998#define HDR_STATIC_METADATA_BLOCK 0x6
Shashank Sharma87563fc2017-07-13 21:03:10 +05302999#define USE_EXTENDED_TAG 0x07
3000#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05303001#define EXT_VIDEO_DATA_BLOCK_420 0x0E
3002#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003003#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003004#define EDID_CEA_YCRCB444 (1 << 5)
3005#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003006#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003007
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01003008/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003009 * Search EDID for CEA extension block.
3010 */
Keith Packard170178f2017-12-13 00:44:26 -08003011static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003012{
3013 u8 *edid_ext = NULL;
3014 int i;
3015
3016 /* No EDID or EDID extensions */
3017 if (edid == NULL || edid->extensions == 0)
3018 return NULL;
3019
3020 /* Find CEA extension */
3021 for (i = 0; i < edid->extensions; i++) {
3022 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10003023 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003024 break;
3025 }
3026
3027 if (i == edid->extensions)
3028 return NULL;
3029
3030 return edid_ext;
3031}
3032
Dave Airlie40d9b042014-10-20 16:29:33 +10003033
Keith Packard170178f2017-12-13 00:44:26 -08003034static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10003035{
3036 return drm_find_edid_extension(edid, DISPLAYID_EXT);
3037}
3038
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003039static u8 *drm_find_cea_extension(const struct edid *edid)
3040{
3041 int ret;
3042 int idx = 1;
3043 int length = EDID_LENGTH;
3044 struct displayid_block *block;
3045 u8 *cea;
3046 u8 *displayid;
3047
3048 /* Look for a top level CEA extension block */
3049 cea = drm_find_edid_extension(edid, CEA_EXT);
3050 if (cea)
3051 return cea;
3052
3053 /* CEA blocks can also be found embedded in a DisplayID block */
3054 displayid = drm_find_displayid_extension(edid);
3055 if (!displayid)
3056 return NULL;
3057
3058 ret = validate_displayid(displayid, length, idx);
3059 if (ret)
3060 return NULL;
3061
3062 idx += sizeof(struct displayid_hdr);
3063 for_each_displayid_db(displayid, block, idx, length) {
3064 if (block->tag == DATA_BLOCK_CTA) {
3065 cea = (u8 *)block;
3066 break;
3067 }
3068 }
3069
3070 return cea;
3071}
3072
Ville Syrjälä7befe622019-12-13 19:43:45 +02003073static const struct drm_display_mode *cea_mode_for_vic(u8 vic)
3074{
3075 if (!vic)
3076 return NULL;
3077 if (vic < ARRAY_SIZE(edid_cea_modes_0))
3078 return &edid_cea_modes_0[vic];
3079 return NULL;
3080}
3081
3082static u8 cea_num_vics(void)
3083{
3084 return ARRAY_SIZE(edid_cea_modes_0);
3085}
3086
3087static u8 cea_next_vic(u8 vic)
3088{
3089 return vic + 1;
3090}
3091
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003092/*
3093 * Calculate the alternate clock for the CEA mode
3094 * (60Hz vs. 59.94Hz etc.)
3095 */
3096static unsigned int
3097cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
3098{
3099 unsigned int clock = cea_mode->clock;
3100
3101 if (cea_mode->vrefresh % 6 != 0)
3102 return clock;
3103
3104 /*
3105 * edid_cea_modes contains the 59.94Hz
3106 * variant for 240 and 480 line modes,
3107 * and the 60Hz variant otherwise.
3108 */
3109 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003110 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003111 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003112 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003113
3114 return clock;
3115}
3116
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003117static bool
3118cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
3119{
3120 /*
3121 * For certain VICs the spec allows the vertical
3122 * front porch to vary by one or two lines.
3123 *
3124 * cea_modes[] stores the variant with the shortest
3125 * vertical front porch. We can adjust the mode to
3126 * get the other variants by simply increasing the
3127 * vertical front porch length.
3128 */
Ville Syrjälä7befe622019-12-13 19:43:45 +02003129 BUILD_BUG_ON(cea_mode_for_vic(8)->vtotal != 262 ||
3130 cea_mode_for_vic(9)->vtotal != 262 ||
3131 cea_mode_for_vic(12)->vtotal != 262 ||
3132 cea_mode_for_vic(13)->vtotal != 262 ||
3133 cea_mode_for_vic(23)->vtotal != 312 ||
3134 cea_mode_for_vic(24)->vtotal != 312 ||
3135 cea_mode_for_vic(27)->vtotal != 312 ||
3136 cea_mode_for_vic(28)->vtotal != 312);
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003137
3138 if (((vic == 8 || vic == 9 ||
3139 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3140 ((vic == 23 || vic == 24 ||
3141 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3142 mode->vsync_start++;
3143 mode->vsync_end++;
3144 mode->vtotal++;
3145
3146 return true;
3147 }
3148
3149 return false;
3150}
3151
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003152static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3153 unsigned int clock_tolerance)
3154{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303155 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003156 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003157
3158 if (!to_match->clock)
3159 return 0;
3160
Ville Syrjälä357768c2018-05-08 16:39:38 +05303161 if (to_match->picture_aspect_ratio)
3162 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3163
Ville Syrjälä7befe622019-12-13 19:43:45 +02003164 for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
3165 struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003166 unsigned int clock1, clock2;
3167
3168 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003169 clock1 = cea_mode.clock;
3170 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003171
3172 if (abs(to_match->clock - clock1) > clock_tolerance &&
3173 abs(to_match->clock - clock2) > clock_tolerance)
3174 continue;
3175
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003176 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303177 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003178 return vic;
3179 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003180 }
3181
3182 return 0;
3183}
3184
Thierry Reding18316c82012-12-20 15:41:44 +01003185/**
3186 * drm_match_cea_mode - look for a CEA mode matching given mode
3187 * @to_match: display mode
3188 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003189 * 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 +01003190 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00003191 */
Thierry Reding18316c82012-12-20 15:41:44 +01003192u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00003193{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303194 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003195 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00003196
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003197 if (!to_match->clock)
3198 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00003199
Ville Syrjälä357768c2018-05-08 16:39:38 +05303200 if (to_match->picture_aspect_ratio)
3201 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3202
Ville Syrjälä7befe622019-12-13 19:43:45 +02003203 for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
3204 struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003205 unsigned int clock1, clock2;
3206
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003207 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003208 clock1 = cea_mode.clock;
3209 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003210
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003211 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3212 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3213 continue;
3214
3215 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303216 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003217 return vic;
3218 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00003219 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003220
Stephane Marchesina4799032012-11-09 16:21:05 +00003221 return 0;
3222}
3223EXPORT_SYMBOL(drm_match_cea_mode);
3224
Jani Nikulad9278b42016-01-08 13:21:51 +02003225static bool drm_valid_cea_vic(u8 vic)
3226{
Ville Syrjälä7befe622019-12-13 19:43:45 +02003227 return cea_mode_for_vic(vic) != NULL;
Jani Nikulad9278b42016-01-08 13:21:51 +02003228}
3229
Ville Syrjälä28c03a442019-10-04 17:19:11 +03003230static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303231{
Ville Syrjälä7befe622019-12-13 19:43:45 +02003232 const struct drm_display_mode *mode = cea_mode_for_vic(video_code);
3233
3234 if (mode)
3235 return mode->picture_aspect_ratio;
3236
3237 return HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303238}
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303239
Wayne Lind2b43472019-11-18 18:18:31 +08003240static enum hdmi_picture_aspect drm_get_hdmi_aspect_ratio(const u8 video_code)
3241{
3242 return edid_4k_modes[video_code].picture_aspect_ratio;
3243}
3244
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003245/*
3246 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3247 * specific block).
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003248 */
3249static unsigned int
3250hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3251{
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003252 return cea_mode_alternate_clock(hdmi_mode);
3253}
3254
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003255static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3256 unsigned int clock_tolerance)
3257{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303258 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003259 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003260
3261 if (!to_match->clock)
3262 return 0;
3263
Wayne Lind2b43472019-11-18 18:18:31 +08003264 if (to_match->picture_aspect_ratio)
3265 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3266
Jani Nikulad9278b42016-01-08 13:21:51 +02003267 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3268 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003269 unsigned int clock1, clock2;
3270
3271 /* Make sure to also match alternate clocks */
3272 clock1 = hdmi_mode->clock;
3273 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3274
3275 if (abs(to_match->clock - clock1) > clock_tolerance &&
3276 abs(to_match->clock - clock2) > clock_tolerance)
3277 continue;
3278
Ville Syrjälä357768c2018-05-08 16:39:38 +05303279 if (drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003280 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003281 }
3282
3283 return 0;
3284}
3285
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003286/*
3287 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3288 * @to_match: display mode
3289 *
3290 * An HDMI mode is one defined in the HDMI vendor specific block.
3291 *
3292 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3293 */
3294static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3295{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303296 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003297 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003298
3299 if (!to_match->clock)
3300 return 0;
3301
Wayne Lind2b43472019-11-18 18:18:31 +08003302 if (to_match->picture_aspect_ratio)
3303 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3304
Jani Nikulad9278b42016-01-08 13:21:51 +02003305 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3306 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003307 unsigned int clock1, clock2;
3308
3309 /* Make sure to also match alternate clocks */
3310 clock1 = hdmi_mode->clock;
3311 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3312
3313 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3314 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Ville Syrjälä357768c2018-05-08 16:39:38 +05303315 drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003316 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003317 }
3318 return 0;
3319}
3320
Jani Nikulad9278b42016-01-08 13:21:51 +02003321static bool drm_valid_hdmi_vic(u8 vic)
3322{
3323 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3324}
3325
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003326static int
3327add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3328{
3329 struct drm_device *dev = connector->dev;
3330 struct drm_display_mode *mode, *tmp;
3331 LIST_HEAD(list);
3332 int modes = 0;
3333
3334 /* Don't add CEA modes if the CEA extension block is missing */
3335 if (!drm_find_cea_extension(edid))
3336 return 0;
3337
3338 /*
3339 * Go through all probed modes and create a new mode
3340 * with the alternate clock for certain CEA modes.
3341 */
3342 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003343 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003344 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003345 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003346 unsigned int clock1, clock2;
3347
Jani Nikulad9278b42016-01-08 13:21:51 +02003348 if (drm_valid_cea_vic(vic)) {
Ville Syrjälä7befe622019-12-13 19:43:45 +02003349 cea_mode = cea_mode_for_vic(vic);
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003350 clock2 = cea_mode_alternate_clock(cea_mode);
3351 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003352 vic = drm_match_hdmi_mode(mode);
3353 if (drm_valid_hdmi_vic(vic)) {
3354 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003355 clock2 = hdmi_mode_alternate_clock(cea_mode);
3356 }
3357 }
3358
3359 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003360 continue;
3361
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003362 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003363
3364 if (clock1 == clock2)
3365 continue;
3366
3367 if (mode->clock != clock1 && mode->clock != clock2)
3368 continue;
3369
3370 newmode = drm_mode_duplicate(dev, cea_mode);
3371 if (!newmode)
3372 continue;
3373
Damien Lespiau27130212013-09-25 16:45:28 +01003374 /* Carry over the stereo flags */
3375 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3376
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003377 /*
3378 * The current mode could be either variant. Make
3379 * sure to pick the "other" clock for the new mode.
3380 */
3381 if (mode->clock != clock1)
3382 newmode->clock = clock1;
3383 else
3384 newmode->clock = clock2;
3385
3386 list_add_tail(&newmode->head, &list);
3387 }
3388
3389 list_for_each_entry_safe(mode, tmp, &list, head) {
3390 list_del(&mode->head);
3391 drm_mode_probed_add(connector, mode);
3392 modes++;
3393 }
3394
3395 return modes;
3396}
Stephane Marchesina4799032012-11-09 16:21:05 +00003397
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303398static u8 svd_to_vic(u8 svd)
3399{
3400 /* 0-6 bit vic, 7th bit native mode indicator */
3401 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3402 return svd & 127;
3403
3404 return svd;
3405}
3406
Thomas Woodaff04ac2013-11-29 15:33:27 +00003407static struct drm_display_mode *
3408drm_display_mode_from_vic_index(struct drm_connector *connector,
3409 const u8 *video_db, u8 video_len,
3410 u8 video_index)
3411{
3412 struct drm_device *dev = connector->dev;
3413 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003414 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003415
3416 if (video_db == NULL || video_index >= video_len)
3417 return NULL;
3418
3419 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303420 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003421 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003422 return NULL;
3423
Ville Syrjälä7befe622019-12-13 19:43:45 +02003424 newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
Damien Lespiau409bbf12014-03-03 23:59:07 +00003425 if (!newmode)
3426 return NULL;
3427
Thomas Woodaff04ac2013-11-29 15:33:27 +00003428 newmode->vrefresh = 0;
3429
3430 return newmode;
3431}
3432
Shashank Sharma832d4f22017-07-14 16:03:46 +05303433/*
3434 * do_y420vdb_modes - Parse YCBCR 420 only modes
3435 * @connector: connector corresponding to the HDMI sink
3436 * @svds: start of the data block of CEA YCBCR 420 VDB
3437 * @len: length of the CEA YCBCR 420 VDB
3438 *
3439 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3440 * which contains modes which can be supported in YCBCR 420
3441 * output format only.
3442 */
3443static int do_y420vdb_modes(struct drm_connector *connector,
3444 const u8 *svds, u8 svds_len)
3445{
3446 int modes = 0, i;
3447 struct drm_device *dev = connector->dev;
3448 struct drm_display_info *info = &connector->display_info;
3449 struct drm_hdmi_info *hdmi = &info->hdmi;
3450
3451 for (i = 0; i < svds_len; i++) {
3452 u8 vic = svd_to_vic(svds[i]);
3453 struct drm_display_mode *newmode;
3454
3455 if (!drm_valid_cea_vic(vic))
3456 continue;
3457
Ville Syrjälä7befe622019-12-13 19:43:45 +02003458 newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
Shashank Sharma832d4f22017-07-14 16:03:46 +05303459 if (!newmode)
3460 break;
3461 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3462 drm_mode_probed_add(connector, newmode);
3463 modes++;
3464 }
3465
3466 if (modes > 0)
3467 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3468 return modes;
3469}
3470
3471/*
3472 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3473 * @connector: connector corresponding to the HDMI sink
3474 * @vic: CEA vic for the video mode to be added in the map
3475 *
3476 * Makes an entry for a videomode in the YCBCR 420 bitmap
3477 */
3478static void
3479drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3480{
3481 u8 vic = svd_to_vic(svd);
3482 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3483
3484 if (!drm_valid_cea_vic(vic))
3485 return;
3486
3487 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3488}
3489
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003490static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003491do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003492{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003493 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303494 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003495
Thomas Woodaff04ac2013-11-29 15:33:27 +00003496 for (i = 0; i < len; i++) {
3497 struct drm_display_mode *mode;
3498 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3499 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303500 /*
3501 * YCBCR420 capability block contains a bitmap which
3502 * gives the index of CEA modes from CEA VDB, which
3503 * can support YCBCR 420 sampling output also (apart
3504 * from RGB/YCBCR444 etc).
3505 * For example, if the bit 0 in bitmap is set,
3506 * first mode in VDB can support YCBCR420 output too.
3507 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3508 */
3509 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3510 drm_add_cmdb_modes(connector, db[i]);
3511
Thomas Woodaff04ac2013-11-29 15:33:27 +00003512 drm_mode_probed_add(connector, mode);
3513 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003514 }
3515 }
3516
3517 return modes;
3518}
3519
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003520struct stereo_mandatory_mode {
3521 int width, height, vrefresh;
3522 unsigned int flags;
3523};
3524
3525static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003526 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3527 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003528 { 1920, 1080, 50,
3529 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3530 { 1920, 1080, 60,
3531 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003532 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3533 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3534 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3535 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003536};
3537
3538static bool
3539stereo_match_mandatory(const struct drm_display_mode *mode,
3540 const struct stereo_mandatory_mode *stereo_mode)
3541{
3542 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3543
3544 return mode->hdisplay == stereo_mode->width &&
3545 mode->vdisplay == stereo_mode->height &&
3546 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3547 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3548}
3549
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003550static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3551{
3552 struct drm_device *dev = connector->dev;
3553 const struct drm_display_mode *mode;
3554 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003555 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003556
3557 INIT_LIST_HEAD(&stereo_modes);
3558
3559 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003560 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3561 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003562 struct drm_display_mode *new_mode;
3563
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003564 if (!stereo_match_mandatory(mode,
3565 &stereo_mandatory_modes[i]))
3566 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003567
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003568 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003569 new_mode = drm_mode_duplicate(dev, mode);
3570 if (!new_mode)
3571 continue;
3572
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003573 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003574 list_add_tail(&new_mode->head, &stereo_modes);
3575 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003576 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003577 }
3578
3579 list_splice_tail(&stereo_modes, &connector->probed_modes);
3580
3581 return modes;
3582}
3583
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003584static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3585{
3586 struct drm_device *dev = connector->dev;
3587 struct drm_display_mode *newmode;
3588
Jani Nikulad9278b42016-01-08 13:21:51 +02003589 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003590 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3591 return 0;
3592 }
3593
3594 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3595 if (!newmode)
3596 return 0;
3597
3598 drm_mode_probed_add(connector, newmode);
3599
3600 return 1;
3601}
3602
Thomas Woodfbf46022013-10-16 15:58:50 +01003603static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3604 const u8 *video_db, u8 video_len, u8 video_index)
3605{
Thomas Woodfbf46022013-10-16 15:58:50 +01003606 struct drm_display_mode *newmode;
3607 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003608
3609 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003610 newmode = drm_display_mode_from_vic_index(connector, video_db,
3611 video_len,
3612 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003613 if (newmode) {
3614 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3615 drm_mode_probed_add(connector, newmode);
3616 modes++;
3617 }
3618 }
3619 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003620 newmode = drm_display_mode_from_vic_index(connector, video_db,
3621 video_len,
3622 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003623 if (newmode) {
3624 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3625 drm_mode_probed_add(connector, newmode);
3626 modes++;
3627 }
3628 }
3629 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003630 newmode = drm_display_mode_from_vic_index(connector, video_db,
3631 video_len,
3632 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003633 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003634 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003635 drm_mode_probed_add(connector, newmode);
3636 modes++;
3637 }
3638 }
3639
3640 return modes;
3641}
3642
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003643/*
3644 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3645 * @connector: connector corresponding to the HDMI sink
3646 * @db: start of the CEA vendor specific block
3647 * @len: length of the CEA block payload, ie. one can access up to db[len]
3648 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003649 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3650 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003651 */
3652static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003653do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3654 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003655{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003656 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003657 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003658 u8 vic_len, hdmi_3d_len = 0;
3659 u16 mask;
3660 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003661
3662 if (len < 8)
3663 goto out;
3664
3665 /* no HDMI_Video_Present */
3666 if (!(db[8] & (1 << 5)))
3667 goto out;
3668
3669 /* Latency_Fields_Present */
3670 if (db[8] & (1 << 7))
3671 offset += 2;
3672
3673 /* I_Latency_Fields_Present */
3674 if (db[8] & (1 << 6))
3675 offset += 2;
3676
3677 /* the declared length is not long enough for the 2 first bytes
3678 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003679 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003680 goto out;
3681
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003682 /* 3D_Present */
3683 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003684 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003685 modes += add_hdmi_mandatory_stereo_modes(connector);
3686
Thomas Woodfbf46022013-10-16 15:58:50 +01003687 /* 3D_Multi_present */
3688 multi_present = (db[8 + offset] & 0x60) >> 5;
3689 }
3690
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003691 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003692 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003693 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003694
3695 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003696 u8 vic;
3697
3698 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003699 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003700 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003701 offset += 1 + vic_len;
3702
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003703 if (multi_present == 1)
3704 multi_len = 2;
3705 else if (multi_present == 2)
3706 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003707 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003708 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003709
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003710 if (len < (8 + offset + hdmi_3d_len - 1))
3711 goto out;
3712
3713 if (hdmi_3d_len < multi_len)
3714 goto out;
3715
3716 if (multi_present == 1 || multi_present == 2) {
3717 /* 3D_Structure_ALL */
3718 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3719
3720 /* check if 3D_MASK is present */
3721 if (multi_present == 2)
3722 mask = (db[10 + offset] << 8) | db[11 + offset];
3723 else
3724 mask = 0xffff;
3725
3726 for (i = 0; i < 16; i++) {
3727 if (mask & (1 << i))
3728 modes += add_3d_struct_modes(connector,
3729 structure_all,
3730 video_db,
3731 video_len, i);
3732 }
3733 }
3734
3735 offset += multi_len;
3736
3737 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3738 int vic_index;
3739 struct drm_display_mode *newmode = NULL;
3740 unsigned int newflag = 0;
3741 bool detail_present;
3742
3743 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3744
3745 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3746 break;
3747
3748 /* 2D_VIC_order_X */
3749 vic_index = db[8 + offset + i] >> 4;
3750
3751 /* 3D_Structure_X */
3752 switch (db[8 + offset + i] & 0x0f) {
3753 case 0:
3754 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3755 break;
3756 case 6:
3757 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3758 break;
3759 case 8:
3760 /* 3D_Detail_X */
3761 if ((db[9 + offset + i] >> 4) == 1)
3762 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3763 break;
3764 }
3765
3766 if (newflag != 0) {
3767 newmode = drm_display_mode_from_vic_index(connector,
3768 video_db,
3769 video_len,
3770 vic_index);
3771
3772 if (newmode) {
3773 newmode->flags |= newflag;
3774 drm_mode_probed_add(connector, newmode);
3775 modes++;
3776 }
3777 }
3778
3779 if (detail_present)
3780 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003781 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003782
3783out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003784 if (modes > 0)
3785 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003786 return modes;
3787}
3788
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003789static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003790cea_db_payload_len(const u8 *db)
3791{
3792 return db[0] & 0x1f;
3793}
3794
3795static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303796cea_db_extended_tag(const u8 *db)
3797{
3798 return db[1];
3799}
3800
3801static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003802cea_db_tag(const u8 *db)
3803{
3804 return db[0] >> 5;
3805}
3806
3807static int
3808cea_revision(const u8 *cea)
3809{
3810 return cea[1];
3811}
3812
3813static int
3814cea_db_offsets(const u8 *cea, int *start, int *end)
3815{
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003816 /* DisplayID CTA extension blocks and top-level CEA EDID
3817 * block header definitions differ in the following bytes:
3818 * 1) Byte 2 of the header specifies length differently,
3819 * 2) Byte 3 is only present in the CEA top level block.
3820 *
3821 * The different definitions for byte 2 follow.
3822 *
3823 * DisplayID CTA extension block defines byte 2 as:
3824 * Number of payload bytes
3825 *
3826 * CEA EDID block defines byte 2 as:
3827 * Byte number (decimal) within this block where the 18-byte
3828 * DTDs begin. If no non-DTD data is present in this extension
3829 * block, the value should be set to 04h (the byte after next).
3830 * If set to 00h, there are no DTDs present in this block and
3831 * no non-DTD data.
3832 */
3833 if (cea[0] == DATA_BLOCK_CTA) {
3834 *start = 3;
3835 *end = *start + cea[2];
3836 } else if (cea[0] == CEA_EXT) {
3837 /* Data block offset in CEA extension block */
3838 *start = 4;
3839 *end = cea[2];
3840 if (*end == 0)
3841 *end = 127;
3842 if (*end < 4 || *end > 127)
3843 return -ERANGE;
3844 } else {
Daniel Vetterc7581a42019-09-04 16:39:42 +02003845 return -EOPNOTSUPP;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003846 }
3847
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003848 return 0;
3849}
3850
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003851static bool cea_db_is_hdmi_vsdb(const u8 *db)
3852{
3853 int hdmi_id;
3854
3855 if (cea_db_tag(db) != VENDOR_BLOCK)
3856 return false;
3857
3858 if (cea_db_payload_len(db) < 5)
3859 return false;
3860
3861 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3862
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003863 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003864}
3865
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303866static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3867{
3868 unsigned int oui;
3869
3870 if (cea_db_tag(db) != VENDOR_BLOCK)
3871 return false;
3872
3873 if (cea_db_payload_len(db) < 7)
3874 return false;
3875
3876 oui = db[3] << 16 | db[2] << 8 | db[1];
3877
3878 return oui == HDMI_FORUM_IEEE_OUI;
3879}
3880
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02003881static bool cea_db_is_vcdb(const u8 *db)
3882{
3883 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3884 return false;
3885
3886 if (cea_db_payload_len(db) != 2)
3887 return false;
3888
3889 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
3890 return false;
3891
3892 return true;
3893}
3894
Shashank Sharma832d4f22017-07-14 16:03:46 +05303895static bool cea_db_is_y420cmdb(const u8 *db)
3896{
3897 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3898 return false;
3899
3900 if (!cea_db_payload_len(db))
3901 return false;
3902
3903 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3904 return false;
3905
3906 return true;
3907}
3908
3909static bool cea_db_is_y420vdb(const u8 *db)
3910{
3911 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3912 return false;
3913
3914 if (!cea_db_payload_len(db))
3915 return false;
3916
3917 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3918 return false;
3919
3920 return true;
3921}
3922
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003923#define for_each_cea_db(cea, i, start, end) \
3924 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3925
Shashank Sharma832d4f22017-07-14 16:03:46 +05303926static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3927 const u8 *db)
3928{
3929 struct drm_display_info *info = &connector->display_info;
3930 struct drm_hdmi_info *hdmi = &info->hdmi;
3931 u8 map_len = cea_db_payload_len(db) - 1;
3932 u8 count;
3933 u64 map = 0;
3934
3935 if (map_len == 0) {
3936 /* All CEA modes support ycbcr420 sampling also.*/
3937 hdmi->y420_cmdb_map = U64_MAX;
3938 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3939 return;
3940 }
3941
3942 /*
3943 * This map indicates which of the existing CEA block modes
3944 * from VDB can support YCBCR420 output too. So if bit=0 is
3945 * set, first mode from VDB can support YCBCR420 output too.
3946 * We will parse and keep this map, before parsing VDB itself
3947 * to avoid going through the same block again and again.
3948 *
3949 * Spec is not clear about max possible size of this block.
3950 * Clamping max bitmap block size at 8 bytes. Every byte can
3951 * address 8 CEA modes, in this way this map can address
3952 * 8*8 = first 64 SVDs.
3953 */
3954 if (WARN_ON_ONCE(map_len > 8))
3955 map_len = 8;
3956
3957 for (count = 0; count < map_len; count++)
3958 map |= (u64)db[2 + count] << (8 * count);
3959
3960 if (map)
3961 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3962
3963 hdmi->y420_cmdb_map = map;
3964}
3965
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003966static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003967add_cea_modes(struct drm_connector *connector, struct edid *edid)
3968{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003969 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003970 const u8 *db, *hdmi = NULL, *video = NULL;
3971 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003972 int modes = 0;
3973
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003974 if (cea && cea_revision(cea) >= 3) {
3975 int i, start, end;
3976
3977 if (cea_db_offsets(cea, &start, &end))
3978 return 0;
3979
3980 for_each_cea_db(cea, i, start, end) {
3981 db = &cea[i];
3982 dbl = cea_db_payload_len(db);
3983
Thomas Woodfbf46022013-10-16 15:58:50 +01003984 if (cea_db_tag(db) == VIDEO_BLOCK) {
3985 video = db + 1;
3986 video_len = dbl;
3987 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303988 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003989 hdmi = db;
3990 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303991 } else if (cea_db_is_y420vdb(db)) {
3992 const u8 *vdb420 = &db[2];
3993
3994 /* Add 4:2:0(only) modes present in EDID */
3995 modes += do_y420vdb_modes(connector,
3996 vdb420,
3997 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003998 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003999 }
4000 }
4001
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004002 /*
4003 * We parse the HDMI VSDB after having added the cea modes as we will
4004 * be patching their flags when the sink supports stereo 3D.
4005 */
4006 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01004007 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
4008 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004009
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004010 return modes;
4011}
4012
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004013static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
4014{
4015 const struct drm_display_mode *cea_mode;
4016 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02004017 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004018 const char *type;
4019
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02004020 /*
4021 * allow 5kHz clock difference either way to account for
4022 * the 10kHz clock resolution limit of detailed timings.
4023 */
Jani Nikulad9278b42016-01-08 13:21:51 +02004024 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
4025 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004026 type = "CEA";
Ville Syrjälä7befe622019-12-13 19:43:45 +02004027 cea_mode = cea_mode_for_vic(vic);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004028 clock1 = cea_mode->clock;
4029 clock2 = cea_mode_alternate_clock(cea_mode);
4030 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02004031 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
4032 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004033 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02004034 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004035 clock1 = cea_mode->clock;
4036 clock2 = hdmi_mode_alternate_clock(cea_mode);
4037 } else {
4038 return;
4039 }
4040 }
4041
4042 /* pick whichever is closest */
4043 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
4044 clock = clock1;
4045 else
4046 clock = clock2;
4047
4048 if (mode->clock == clock)
4049 return;
4050
4051 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02004052 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004053 mode->clock = clock;
4054}
4055
Uma Shankare85959d2019-05-16 19:40:08 +05304056static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
4057{
4058 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4059 return false;
4060
4061 if (db[1] != HDR_STATIC_METADATA_BLOCK)
4062 return false;
4063
4064 if (cea_db_payload_len(db) < 3)
4065 return false;
4066
4067 return true;
4068}
4069
4070static uint8_t eotf_supported(const u8 *edid_ext)
4071{
4072 return edid_ext[2] &
4073 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
4074 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
Ville Syrjäläb5e3eed2019-05-16 19:40:12 +05304075 BIT(HDMI_EOTF_SMPTE_ST2084) |
4076 BIT(HDMI_EOTF_BT_2100_HLG));
Uma Shankare85959d2019-05-16 19:40:08 +05304077}
4078
4079static uint8_t hdr_metadata_type(const u8 *edid_ext)
4080{
4081 return edid_ext[3] &
4082 BIT(HDMI_STATIC_METADATA_TYPE1);
4083}
4084
4085static void
4086drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
4087{
4088 u16 len;
4089
4090 len = cea_db_payload_len(db);
4091
4092 connector->hdr_sink_metadata.hdmi_type1.eotf =
4093 eotf_supported(db);
4094 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
4095 hdr_metadata_type(db);
4096
4097 if (len >= 4)
4098 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
4099 if (len >= 5)
4100 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
4101 if (len >= 6)
4102 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
4103}
4104
Wu Fengguang76adaa342011-09-05 14:23:20 +08004105static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004106drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004107{
Ville Syrjälä85040722012-08-16 14:55:05 +00004108 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004109
Jani Nikulaf7da77852017-11-01 16:20:57 +02004110 if (len >= 6 && (db[6] & (1 << 7)))
4111 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00004112 if (len >= 8) {
4113 connector->latency_present[0] = db[8] >> 7;
4114 connector->latency_present[1] = (db[8] >> 6) & 1;
4115 }
4116 if (len >= 9)
4117 connector->video_latency[0] = db[9];
4118 if (len >= 10)
4119 connector->audio_latency[0] = db[10];
4120 if (len >= 11)
4121 connector->video_latency[1] = db[11];
4122 if (len >= 12)
4123 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004124
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004125 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4126 "video latency %d %d, "
4127 "audio latency %d %d\n",
4128 connector->latency_present[0],
4129 connector->latency_present[1],
4130 connector->video_latency[0],
4131 connector->video_latency[1],
4132 connector->audio_latency[0],
4133 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004134}
4135
4136static void
4137monitor_name(struct detailed_timing *t, void *data)
4138{
4139 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
4140 *(u8 **)data = t->data.other_data.data.str.str;
4141}
4142
Jim Bride59f7c0f2016-04-14 10:18:35 -07004143static int get_monitor_name(struct edid *edid, char name[13])
4144{
4145 char *edid_name = NULL;
4146 int mnl;
4147
4148 if (!edid || !name)
4149 return 0;
4150
4151 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4152 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4153 if (edid_name[mnl] == 0x0a)
4154 break;
4155
4156 name[mnl] = edid_name[mnl];
4157 }
4158
4159 return mnl;
4160}
4161
4162/**
4163 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4164 * @edid: monitor EDID information
4165 * @name: pointer to a character array to hold the name of the monitor
4166 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4167 *
4168 */
4169void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4170{
4171 int name_length;
4172 char buf[13];
4173
4174 if (bufsize <= 0)
4175 return;
4176
4177 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4178 memcpy(name, buf, name_length);
4179 name[name_length] = '\0';
4180}
4181EXPORT_SYMBOL(drm_edid_get_monitor_name);
4182
Jani Nikula42750d32017-11-01 16:21:00 +02004183static void clear_eld(struct drm_connector *connector)
4184{
4185 memset(connector->eld, 0, sizeof(connector->eld));
4186
4187 connector->latency_present[0] = false;
4188 connector->latency_present[1] = false;
4189 connector->video_latency[0] = 0;
4190 connector->audio_latency[0] = 0;
4191 connector->video_latency[1] = 0;
4192 connector->audio_latency[1] = 0;
4193}
4194
Jani Nikula79436a12017-11-01 16:21:03 +02004195/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08004196 * drm_edid_to_eld - build ELD from EDID
4197 * @connector: connector corresponding to the HDMI/DP sink
4198 * @edid: EDID to parse
4199 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004200 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02004201 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004202 */
Jani Nikula79436a12017-11-01 16:21:03 +02004203static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004204{
4205 uint8_t *eld = connector->eld;
4206 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004207 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02004208 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004209 int mnl;
4210 int dbl;
4211
Jani Nikula42750d32017-11-01 16:21:00 +02004212 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03004213
Jani Nikulae9bd0b82017-02-17 17:20:52 +02004214 if (!edid)
4215 return;
4216
Wu Fengguang76adaa342011-09-05 14:23:20 +08004217 cea = drm_find_cea_extension(edid);
4218 if (!cea) {
4219 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4220 return;
4221 }
4222
Jani Nikulaf7da77852017-11-01 16:20:57 +02004223 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4224 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07004225
Jani Nikulaf7da77852017-11-01 16:20:57 +02004226 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4227 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004228
Jani Nikulaf7da77852017-11-01 16:20:57 +02004229 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004230
Jani Nikulaf7da77852017-11-01 16:20:57 +02004231 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4232 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4233 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4234 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004235
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004236 if (cea_revision(cea) >= 3) {
4237 int i, start, end;
4238
4239 if (cea_db_offsets(cea, &start, &end)) {
4240 start = 0;
4241 end = 0;
4242 }
4243
4244 for_each_cea_db(cea, i, start, end) {
4245 db = &cea[i];
4246 dbl = cea_db_payload_len(db);
4247
4248 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02004249 int sad_count;
4250
Christian Schmidta0ab7342011-12-19 20:03:38 +01004251 case AUDIO_BLOCK:
4252 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02004253 sad_count = min(dbl / 3, 15 - total_sad_count);
4254 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004255 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02004256 &db[1], sad_count * 3);
4257 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01004258 break;
4259 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004260 /* Speaker Allocation Data Block */
4261 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004262 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01004263 break;
4264 case VENDOR_BLOCK:
4265 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004266 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004267 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01004268 break;
4269 default:
4270 break;
4271 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08004272 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004273 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02004274 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004275
Jani Nikula1d1c3662017-11-01 16:20:58 +02004276 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4277 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4278 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4279 else
4280 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004281
Jani Nikula938fd8a2014-10-28 16:20:48 +02004282 eld[DRM_ELD_BASELINE_ELD_LEN] =
4283 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4284
4285 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02004286 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004287}
Wu Fengguang76adaa342011-09-05 14:23:20 +08004288
4289/**
Rafał Miłeckife214162013-04-19 19:01:25 +02004290 * drm_edid_to_sad - extracts SADs from EDID
4291 * @edid: EDID to parse
4292 * @sads: pointer that will be set to the extracted SADs
4293 *
4294 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02004295 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004296 * Note: The returned pointer needs to be freed using kfree().
4297 *
4298 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02004299 */
4300int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4301{
4302 int count = 0;
4303 int i, start, end, dbl;
4304 u8 *cea;
4305
4306 cea = drm_find_cea_extension(edid);
4307 if (!cea) {
4308 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004309 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004310 }
4311
4312 if (cea_revision(cea) < 3) {
4313 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004314 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004315 }
4316
4317 if (cea_db_offsets(cea, &start, &end)) {
4318 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4319 return -EPROTO;
4320 }
4321
4322 for_each_cea_db(cea, i, start, end) {
4323 u8 *db = &cea[i];
4324
4325 if (cea_db_tag(db) == AUDIO_BLOCK) {
4326 int j;
4327 dbl = cea_db_payload_len(db);
4328
4329 count = dbl / 3; /* SAD is 3B */
4330 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4331 if (!*sads)
4332 return -ENOMEM;
4333 for (j = 0; j < count; j++) {
4334 u8 *sad = &db[1 + j * 3];
4335
4336 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4337 (*sads)[j].channels = sad[0] & 0x7;
4338 (*sads)[j].freq = sad[1] & 0x7F;
4339 (*sads)[j].byte2 = sad[2];
4340 }
4341 break;
4342 }
4343 }
4344
4345 return count;
4346}
4347EXPORT_SYMBOL(drm_edid_to_sad);
4348
4349/**
Alex Deucherd105f472013-07-25 15:55:32 -04004350 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4351 * @edid: EDID to parse
4352 * @sadb: pointer to the speaker block
4353 *
4354 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004355 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004356 * Note: The returned pointer needs to be freed using kfree().
4357 *
4358 * Return: The number of found Speaker Allocation Blocks or negative number on
4359 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004360 */
4361int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4362{
4363 int count = 0;
4364 int i, start, end, dbl;
4365 const u8 *cea;
4366
4367 cea = drm_find_cea_extension(edid);
4368 if (!cea) {
4369 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004370 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004371 }
4372
4373 if (cea_revision(cea) < 3) {
4374 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004375 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004376 }
4377
4378 if (cea_db_offsets(cea, &start, &end)) {
4379 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4380 return -EPROTO;
4381 }
4382
4383 for_each_cea_db(cea, i, start, end) {
4384 const u8 *db = &cea[i];
4385
4386 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4387 dbl = cea_db_payload_len(db);
4388
4389 /* Speaker Allocation Data Block */
4390 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004391 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004392 if (!*sadb)
4393 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004394 count = dbl;
4395 break;
4396 }
4397 }
4398 }
4399
4400 return count;
4401}
4402EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4403
4404/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004405 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004406 * @connector: connector associated with the HDMI/DP sink
4407 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004408 *
4409 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4410 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004411 */
4412int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004413 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004414{
4415 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4416 int a, v;
4417
4418 if (!connector->latency_present[0])
4419 return 0;
4420 if (!connector->latency_present[1])
4421 i = 0;
4422
4423 a = connector->audio_latency[i];
4424 v = connector->video_latency[i];
4425
4426 /*
4427 * HDMI/DP sink doesn't support audio or video?
4428 */
4429 if (a == 255 || v == 255)
4430 return 0;
4431
4432 /*
4433 * Convert raw EDID values to millisecond.
4434 * Treat unknown latency as 0ms.
4435 */
4436 if (a)
4437 a = min(2 * (a - 1), 500);
4438 if (v)
4439 v = min(2 * (v - 1), 500);
4440
4441 return max(v - a, 0);
4442}
4443EXPORT_SYMBOL(drm_av_sync_delay);
4444
4445/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004446 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004447 * @edid: monitor EDID information
4448 *
4449 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004450 *
4451 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004452 */
4453bool drm_detect_hdmi_monitor(struct edid *edid)
4454{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004455 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004456 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004457 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004458
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004459 edid_ext = drm_find_cea_extension(edid);
4460 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004461 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004462
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004463 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004464 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004465
4466 /*
4467 * Because HDMI identifier is in Vendor Specific Block,
4468 * search it from all data blocks of CEA extension.
4469 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004470 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004471 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4472 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004473 }
4474
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004475 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004476}
4477EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4478
Dave Airlief453ba02008-11-07 14:05:41 -08004479/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004480 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004481 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004482 *
4483 * Monitor should have CEA extension block.
4484 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4485 * audio' only. If there is any audio extension block and supported
4486 * audio format, assume at least 'basic audio' support, even if 'basic
4487 * audio' is not defined in EDID.
4488 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004489 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004490 */
4491bool drm_detect_monitor_audio(struct edid *edid)
4492{
4493 u8 *edid_ext;
4494 int i, j;
4495 bool has_audio = false;
4496 int start_offset, end_offset;
4497
4498 edid_ext = drm_find_cea_extension(edid);
4499 if (!edid_ext)
4500 goto end;
4501
4502 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4503
4504 if (has_audio) {
4505 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4506 goto end;
4507 }
4508
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004509 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4510 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004511
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004512 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4513 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004514 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004515 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004516 DRM_DEBUG_KMS("CEA audio format %d\n",
4517 (edid_ext[i + j] >> 3) & 0xf);
4518 goto end;
4519 }
4520 }
4521end:
4522 return has_audio;
4523}
4524EXPORT_SYMBOL(drm_detect_monitor_audio);
4525
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004526
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004527/**
4528 * drm_default_rgb_quant_range - default RGB quantization range
4529 * @mode: display mode
4530 *
4531 * Determine the default RGB quantization range for the mode,
4532 * as specified in CEA-861.
4533 *
4534 * Return: The default RGB quantization range for the mode
4535 */
4536enum hdmi_quantization_range
4537drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4538{
4539 /* All CEA modes other than VIC 1 use limited quantization range. */
4540 return drm_match_cea_mode(mode) > 1 ?
4541 HDMI_QUANTIZATION_RANGE_LIMITED :
4542 HDMI_QUANTIZATION_RANGE_FULL;
4543}
4544EXPORT_SYMBOL(drm_default_rgb_quant_range);
4545
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004546static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4547{
4548 struct drm_display_info *info = &connector->display_info;
4549
4550 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4551
4552 if (db[2] & EDID_CEA_VCDB_QS)
4553 info->rgb_quant_range_selectable = true;
4554}
4555
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304556static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4557 const u8 *db)
4558{
4559 u8 dc_mask;
4560 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4561
4562 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
Clint Taylor9068e022018-10-05 14:52:15 -07004563 hdmi->y420_dc_modes = dc_mask;
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304564}
4565
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304566static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4567 const u8 *hf_vsdb)
4568{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304569 struct drm_display_info *display = &connector->display_info;
4570 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304571
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004572 display->has_hdmi_infoframe = true;
4573
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304574 if (hf_vsdb[6] & 0x80) {
4575 hdmi->scdc.supported = true;
4576 if (hf_vsdb[6] & 0x40)
4577 hdmi->scdc.read_request = true;
4578 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304579
4580 /*
4581 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4582 * And as per the spec, three factors confirm this:
4583 * * Availability of a HF-VSDB block in EDID (check)
4584 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4585 * * SCDC support available (let's check)
4586 * Lets check it out.
4587 */
4588
4589 if (hf_vsdb[5]) {
4590 /* max clock is 5000 KHz times block value */
4591 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4592 struct drm_scdc *scdc = &hdmi->scdc;
4593
4594 if (max_tmds_clock > 340000) {
4595 display->max_tmds_clock = max_tmds_clock;
4596 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4597 display->max_tmds_clock);
4598 }
4599
4600 if (scdc->supported) {
4601 scdc->scrambling.supported = true;
4602
4603 /* Few sinks support scrambling for cloks < 340M */
4604 if ((hf_vsdb[6] & 0x8))
4605 scdc->scrambling.low_rates = true;
4606 }
4607 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304608
4609 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304610}
4611
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004612static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4613 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004614{
Ville Syrjälä18267502016-09-28 16:51:38 +03004615 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004616 unsigned int dc_bpc = 0;
4617
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004618 /* HDMI supports at least 8 bpc */
4619 info->bpc = 8;
4620
4621 if (cea_db_payload_len(hdmi) < 6)
4622 return;
4623
4624 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4625 dc_bpc = 10;
4626 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4627 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4628 connector->name);
4629 }
4630
4631 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4632 dc_bpc = 12;
4633 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4634 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4635 connector->name);
4636 }
4637
4638 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4639 dc_bpc = 16;
4640 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4641 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4642 connector->name);
4643 }
4644
4645 if (dc_bpc == 0) {
4646 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4647 connector->name);
4648 return;
4649 }
4650
4651 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4652 connector->name, dc_bpc);
4653 info->bpc = dc_bpc;
4654
4655 /*
4656 * Deep color support mandates RGB444 support for all video
4657 * modes and forbids YCRCB422 support for all video modes per
4658 * HDMI 1.3 spec.
4659 */
4660 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4661
4662 /* YCRCB444 is optional according to spec. */
4663 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4664 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4665 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4666 connector->name);
4667 }
4668
4669 /*
4670 * Spec says that if any deep color mode is supported at all,
4671 * then deep color 36 bit must be supported.
4672 */
4673 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4674 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4675 connector->name);
4676 }
4677}
4678
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004679static void
4680drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4681{
4682 struct drm_display_info *info = &connector->display_info;
4683 u8 len = cea_db_payload_len(db);
4684
4685 if (len >= 6)
4686 info->dvi_dual = db[6] & 1;
4687 if (len >= 7)
4688 info->max_tmds_clock = db[7] * 5000;
4689
4690 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4691 "max TMDS clock %d kHz\n",
4692 info->dvi_dual,
4693 info->max_tmds_clock);
4694
4695 drm_parse_hdmi_deep_color_info(connector, db);
4696}
4697
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004698static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004699 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004700{
4701 struct drm_display_info *info = &connector->display_info;
4702 const u8 *edid_ext;
4703 int i, start, end;
4704
Mario Kleinerd0c94692014-03-27 19:59:39 +01004705 edid_ext = drm_find_cea_extension(edid);
4706 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004707 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004708
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004709 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004710
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004711 /* The existence of a CEA block should imply RGB support */
4712 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4713 if (edid_ext[3] & EDID_CEA_YCRCB444)
4714 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4715 if (edid_ext[3] & EDID_CEA_YCRCB422)
4716 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004717
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004718 if (cea_db_offsets(edid_ext, &start, &end))
4719 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004720
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004721 for_each_cea_db(edid_ext, i, start, end) {
4722 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004723
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004724 if (cea_db_is_hdmi_vsdb(db))
4725 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304726 if (cea_db_is_hdmi_forum_vsdb(db))
4727 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304728 if (cea_db_is_y420cmdb(db))
4729 drm_parse_y420cmdb_bitmap(connector, db);
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004730 if (cea_db_is_vcdb(db))
4731 drm_parse_vcdb(connector, db);
Uma Shankare85959d2019-05-16 19:40:08 +05304732 if (cea_db_is_hdmi_hdr_metadata_block(db))
4733 drm_parse_hdr_metadata_block(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004734 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004735}
4736
Keith Packard170178f2017-12-13 00:44:26 -08004737/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4738 * all of the values which would have been set from EDID
4739 */
4740void
4741drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004742{
Ville Syrjälä18267502016-09-28 16:51:38 +03004743 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004744
Keith Packard170178f2017-12-13 00:44:26 -08004745 info->width_mm = 0;
4746 info->height_mm = 0;
4747
4748 info->bpc = 0;
4749 info->color_formats = 0;
4750 info->cea_rev = 0;
4751 info->max_tmds_clock = 0;
4752 info->dvi_dual = false;
4753 info->has_hdmi_infoframe = false;
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004754 info->rgb_quant_range_selectable = false;
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004755 memset(&info->hdmi, 0, sizeof(info->hdmi));
Keith Packard170178f2017-12-13 00:44:26 -08004756
4757 info->non_desktop = 0;
4758}
Keith Packard170178f2017-12-13 00:44:26 -08004759
4760u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4761{
4762 struct drm_display_info *info = &connector->display_info;
4763
4764 u32 quirks = edid_get_quirks(edid);
4765
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004766 drm_reset_display_info(connector);
4767
Jesse Barnes3b112282011-04-15 12:49:23 -07004768 info->width_mm = edid->width_cm * 10;
4769 info->height_mm = edid->height_cm * 10;
4770
Dave Airlie66660d42017-10-16 05:08:09 +01004771 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4772
Keith Packard170178f2017-12-13 00:44:26 -08004773 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4774
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004775 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004776 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004777
4778 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004779 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004780
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004781 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004782
Mario Kleiner210a0212016-07-06 12:05:48 +02004783 /*
4784 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4785 *
4786 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4787 * tells us to assume 8 bpc color depth if the EDID doesn't have
4788 * extensions which tell otherwise.
4789 */
Ville Syrjälä3bde4492019-05-29 14:02:04 +03004790 if (info->bpc == 0 && edid->revision == 3 &&
4791 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
Mario Kleiner210a0212016-07-06 12:05:48 +02004792 info->bpc = 8;
4793 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4794 connector->name, info->bpc);
4795 }
4796
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004797 /* Only defined for 1.4 with digital displays */
4798 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004799 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004800
Jesse Barnes3b112282011-04-15 12:49:23 -07004801 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4802 case DRM_EDID_DIGITAL_DEPTH_6:
4803 info->bpc = 6;
4804 break;
4805 case DRM_EDID_DIGITAL_DEPTH_8:
4806 info->bpc = 8;
4807 break;
4808 case DRM_EDID_DIGITAL_DEPTH_10:
4809 info->bpc = 10;
4810 break;
4811 case DRM_EDID_DIGITAL_DEPTH_12:
4812 info->bpc = 12;
4813 break;
4814 case DRM_EDID_DIGITAL_DEPTH_14:
4815 info->bpc = 14;
4816 break;
4817 case DRM_EDID_DIGITAL_DEPTH_16:
4818 info->bpc = 16;
4819 break;
4820 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4821 default:
4822 info->bpc = 0;
4823 break;
4824 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004825
Mario Kleinerd0c94692014-03-27 19:59:39 +01004826 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004827 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004828
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004829 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004830 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4831 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4832 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4833 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004834 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004835}
4836
Dave Airliec97291772016-05-03 15:38:37 +10004837static int validate_displayid(u8 *displayid, int length, int idx)
4838{
4839 int i;
4840 u8 csum = 0;
4841 struct displayid_hdr *base;
4842
4843 base = (struct displayid_hdr *)&displayid[idx];
4844
4845 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4846 base->rev, base->bytes, base->prod_id, base->ext_count);
4847
4848 if (base->bytes + 5 > length - idx)
4849 return -EINVAL;
4850 for (i = idx; i <= base->bytes + 5; i++) {
4851 csum += displayid[i];
4852 }
4853 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004854 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004855 return -EINVAL;
4856 }
4857 return 0;
4858}
4859
Dave Airliea39ed682016-05-02 08:35:05 +10004860static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4861 struct displayid_detailed_timings_1 *timings)
4862{
4863 struct drm_display_mode *mode;
4864 unsigned pixel_clock = (timings->pixel_clock[0] |
4865 (timings->pixel_clock[1] << 8) |
4866 (timings->pixel_clock[2] << 16));
4867 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4868 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4869 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4870 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4871 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4872 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4873 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4874 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4875 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4876 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4877 mode = drm_mode_create(dev);
4878 if (!mode)
4879 return NULL;
4880
4881 mode->clock = pixel_clock * 10;
4882 mode->hdisplay = hactive;
4883 mode->hsync_start = mode->hdisplay + hsync;
4884 mode->hsync_end = mode->hsync_start + hsync_width;
4885 mode->htotal = mode->hdisplay + hblank;
4886
4887 mode->vdisplay = vactive;
4888 mode->vsync_start = mode->vdisplay + vsync;
4889 mode->vsync_end = mode->vsync_start + vsync_width;
4890 mode->vtotal = mode->vdisplay + vblank;
4891
4892 mode->flags = 0;
4893 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4894 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4895 mode->type = DRM_MODE_TYPE_DRIVER;
4896
4897 if (timings->flags & 0x80)
4898 mode->type |= DRM_MODE_TYPE_PREFERRED;
4899 mode->vrefresh = drm_mode_vrefresh(mode);
4900 drm_mode_set_name(mode);
4901
4902 return mode;
4903}
4904
4905static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4906 struct displayid_block *block)
4907{
4908 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4909 int i;
4910 int num_timings;
4911 struct drm_display_mode *newmode;
4912 int num_modes = 0;
4913 /* blocks must be multiple of 20 bytes length */
4914 if (block->num_bytes % 20)
4915 return 0;
4916
4917 num_timings = block->num_bytes / 20;
4918 for (i = 0; i < num_timings; i++) {
4919 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4920
4921 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4922 if (!newmode)
4923 continue;
4924
4925 drm_mode_probed_add(connector, newmode);
4926 num_modes++;
4927 }
4928 return num_modes;
4929}
4930
4931static int add_displayid_detailed_modes(struct drm_connector *connector,
4932 struct edid *edid)
4933{
4934 u8 *displayid;
4935 int ret;
4936 int idx = 1;
4937 int length = EDID_LENGTH;
4938 struct displayid_block *block;
4939 int num_modes = 0;
4940
4941 displayid = drm_find_displayid_extension(edid);
4942 if (!displayid)
4943 return 0;
4944
4945 ret = validate_displayid(displayid, length, idx);
4946 if (ret)
4947 return 0;
4948
4949 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04004950 for_each_displayid_db(displayid, block, idx, length) {
Dave Airliea39ed682016-05-02 08:35:05 +10004951 switch (block->tag) {
4952 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4953 num_modes += add_displayid_detailed_1_modes(connector, block);
4954 break;
4955 }
4956 }
4957 return num_modes;
4958}
4959
Jesse Barnes3b112282011-04-15 12:49:23 -07004960/**
Dave Airlief453ba02008-11-07 14:05:41 -08004961 * drm_add_edid_modes - add modes from EDID data, if available
4962 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004963 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004964 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004965 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004966 * &drm_display_info structure and ELD in @connector with any information which
4967 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004968 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004969 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004970 */
4971int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4972{
4973 int num_modes = 0;
4974 u32 quirks;
4975
4976 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004977 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004978 return 0;
4979 }
Alex Deucher3c537882010-02-05 04:21:19 -05004980 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004981 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004982 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004983 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004984 return 0;
4985 }
4986
Jani Nikulac945b8c2017-11-01 16:21:01 +02004987 drm_edid_to_eld(connector, edid);
4988
Adam Jacksonc867df72010-03-29 21:43:21 +00004989 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304990 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4991 * To avoid multiple parsing of same block, lets parse that map
4992 * from sink info, before parsing CEA modes.
4993 */
Keith Packard170178f2017-12-13 00:44:26 -08004994 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304995
4996 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004997 * EDID spec says modes should be preferred in this order:
4998 * - preferred detailed mode
4999 * - other detailed modes from base block
5000 * - detailed modes from extension blocks
5001 * - CVT 3-byte code modes
5002 * - standard timing codes
5003 * - established timing codes
5004 * - modes inferred from GTF or CVT range information
5005 *
Adam Jackson13931572010-08-03 14:38:19 -04005006 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00005007 *
5008 * XXX order for additional mode types in extension blocks?
5009 */
Adam Jackson13931572010-08-03 14:38:19 -04005010 num_modes += add_detailed_modes(connector, edid, quirks);
5011 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00005012 num_modes += add_standard_modes(connector, edid);
5013 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00005014 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03005015 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10005016 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03005017 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
5018 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08005019
5020 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
5021 edid_fixup_preferred(connector, quirks);
5022
Mario Kleinere10aec62016-07-06 12:05:44 +02005023 if (quirks & EDID_QUIRK_FORCE_6BPC)
5024 connector->display_info.bpc = 6;
5025
Rafał Miłecki49d45a312013-12-07 13:22:42 +01005026 if (quirks & EDID_QUIRK_FORCE_8BPC)
5027 connector->display_info.bpc = 8;
5028
Mario Kleinere345da82017-04-21 17:05:08 +02005029 if (quirks & EDID_QUIRK_FORCE_10BPC)
5030 connector->display_info.bpc = 10;
5031
Mario Kleinerbc5b9642014-05-23 21:40:55 +02005032 if (quirks & EDID_QUIRK_FORCE_12BPC)
5033 connector->display_info.bpc = 12;
5034
Dave Airlief453ba02008-11-07 14:05:41 -08005035 return num_modes;
5036}
5037EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005038
5039/**
5040 * drm_add_modes_noedid - add modes for the connectors without EDID
5041 * @connector: connector we're probing
5042 * @hdisplay: the horizontal display limit
5043 * @vdisplay: the vertical display limit
5044 *
5045 * Add the specified modes to the connector's mode list. Only when the
5046 * hdisplay/vdisplay is not beyond the given limit, it will be added.
5047 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005048 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005049 */
5050int drm_add_modes_noedid(struct drm_connector *connector,
5051 int hdisplay, int vdisplay)
5052{
5053 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005054 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005055 struct drm_device *dev = connector->dev;
5056
Daniel Vetterfbb40b22015-08-10 11:55:37 +02005057 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005058 if (hdisplay < 0)
5059 hdisplay = 0;
5060 if (vdisplay < 0)
5061 vdisplay = 0;
5062
5063 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005064 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005065 if (hdisplay && vdisplay) {
5066 /*
5067 * Only when two are valid, they will be used to check
5068 * whether the mode should be added to the mode list of
5069 * the connector.
5070 */
5071 if (ptr->hdisplay > hdisplay ||
5072 ptr->vdisplay > vdisplay)
5073 continue;
5074 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05005075 if (drm_mode_vrefresh(ptr) > 61)
5076 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005077 mode = drm_mode_duplicate(dev, ptr);
5078 if (mode) {
5079 drm_mode_probed_add(connector, mode);
5080 num_modes++;
5081 }
5082 }
5083 return num_modes;
5084}
5085EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01005086
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005087/**
5088 * drm_set_preferred_mode - Sets the preferred mode of a connector
5089 * @connector: connector whose mode list should be processed
5090 * @hpref: horizontal resolution of preferred mode
5091 * @vpref: vertical resolution of preferred mode
5092 *
5093 * Marks a mode as preferred if it matches the resolution specified by @hpref
5094 * and @vpref.
5095 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005096void drm_set_preferred_mode(struct drm_connector *connector,
5097 int hpref, int vpref)
5098{
5099 struct drm_display_mode *mode;
5100
5101 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005102 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01005103 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005104 mode->type |= DRM_MODE_TYPE_PREFERRED;
5105 }
5106}
5107EXPORT_SYMBOL(drm_set_preferred_mode);
5108
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005109static bool is_hdmi2_sink(struct drm_connector *connector)
5110{
5111 /*
5112 * FIXME: sil-sii8620 doesn't have a connector around when
5113 * we need one, so we have to be prepared for a NULL connector.
5114 */
5115 if (!connector)
5116 return true;
5117
5118 return connector->display_info.hdmi.scdc.supported ||
5119 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
5120}
5121
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305122static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5123{
5124 return sink_eotf & BIT(output_eotf);
5125}
5126
5127/**
5128 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5129 * HDR metadata from userspace
5130 * @frame: HDMI DRM infoframe
Sean Paul6ac98822019-05-23 09:54:58 -04005131 * @conn_state: Connector state containing HDR metadata
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305132 *
5133 * Return: 0 on success or a negative error code on failure.
5134 */
5135int
5136drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5137 const struct drm_connector_state *conn_state)
5138{
5139 struct drm_connector *connector;
5140 struct hdr_output_metadata *hdr_metadata;
5141 int err;
5142
5143 if (!frame || !conn_state)
5144 return -EINVAL;
5145
5146 connector = conn_state->connector;
5147
5148 if (!conn_state->hdr_output_metadata)
5149 return -EINVAL;
5150
5151 hdr_metadata = conn_state->hdr_output_metadata->data;
5152
5153 if (!hdr_metadata || !connector)
5154 return -EINVAL;
5155
5156 /* Sink EOTF is Bit map while infoframe is absolute values */
5157 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5158 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5159 DRM_DEBUG_KMS("EOTF Not Supported\n");
5160 return -EINVAL;
5161 }
5162
5163 err = hdmi_drm_infoframe_init(frame);
5164 if (err < 0)
5165 return err;
5166
5167 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5168 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5169
5170 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5171 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5172 BUILD_BUG_ON(sizeof(frame->white_point) !=
5173 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5174
5175 memcpy(&frame->display_primaries,
5176 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5177 sizeof(frame->display_primaries));
5178
5179 memcpy(&frame->white_point,
5180 &hdr_metadata->hdmi_metadata_type1.white_point,
5181 sizeof(frame->white_point));
5182
5183 frame->max_display_mastering_luminance =
5184 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5185 frame->min_display_mastering_luminance =
5186 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5187 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5188 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5189
5190 return 0;
5191}
5192EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5193
Ville Syrjälä949561e2019-10-04 17:19:13 +03005194static u8 drm_mode_hdmi_vic(struct drm_connector *connector,
5195 const struct drm_display_mode *mode)
5196{
5197 bool has_hdmi_infoframe = connector ?
5198 connector->display_info.has_hdmi_infoframe : false;
5199
5200 if (!has_hdmi_infoframe)
5201 return 0;
5202
5203 /* No HDMI VIC when signalling 3D video format */
5204 if (mode->flags & DRM_MODE_FLAG_3D_MASK)
5205 return 0;
5206
5207 return drm_match_hdmi_mode(mode);
5208}
5209
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005210static u8 drm_mode_cea_vic(struct drm_connector *connector,
5211 const struct drm_display_mode *mode)
5212{
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005213 u8 vic;
5214
5215 /*
5216 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5217 * we should send its VIC in vendor infoframes, else send the
5218 * VIC in AVI infoframes. Lets check if this mode is present in
5219 * HDMI 1.4b 4K modes
5220 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005221 if (drm_mode_hdmi_vic(connector, mode))
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005222 return 0;
5223
5224 vic = drm_match_cea_mode(mode);
5225
5226 /*
5227 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5228 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5229 * have to make sure we dont break HDMI 1.4 sinks.
5230 */
5231 if (!is_hdmi2_sink(connector) && vic > 64)
5232 return 0;
5233
5234 return vic;
5235}
5236
Thierry Reding10a85122012-11-21 15:31:35 +01005237/**
5238 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5239 * data from a DRM display mode
5240 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005241 * @connector: the connector
Thierry Reding10a85122012-11-21 15:31:35 +01005242 * @mode: DRM display mode
5243 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005244 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01005245 */
5246int
5247drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005248 struct drm_connector *connector,
5249 const struct drm_display_mode *mode)
Thierry Reding10a85122012-11-21 15:31:35 +01005250{
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305251 enum hdmi_picture_aspect picture_aspect;
Wayne Lind2b43472019-11-18 18:18:31 +08005252 u8 vic, hdmi_vic;
Thierry Reding10a85122012-11-21 15:31:35 +01005253 int err;
5254
5255 if (!frame || !mode)
5256 return -EINVAL;
5257
5258 err = hdmi_avi_infoframe_init(frame);
5259 if (err < 0)
5260 return err;
5261
Damien Lespiaubf02db92013-08-06 20:32:22 +01005262 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5263 frame->pixel_repeat = 1;
5264
Wayne Lind2b43472019-11-18 18:18:31 +08005265 vic = drm_mode_cea_vic(connector, mode);
5266 hdmi_vic = drm_mode_hdmi_vic(connector, mode);
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305267
Thierry Reding10a85122012-11-21 15:31:35 +01005268 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305269
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305270 /*
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03005271 * As some drivers don't support atomic, we can't use connector state.
5272 * So just initialize the frame with default values, just the same way
5273 * as it's done with other properties here.
5274 */
5275 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5276 frame->itc = 0;
5277
5278 /*
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305279 * Populate picture aspect ratio from either
Wayne Lind2b43472019-11-18 18:18:31 +08005280 * user input (if specified) or from the CEA/HDMI mode lists.
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305281 */
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305282 picture_aspect = mode->picture_aspect_ratio;
Wayne Lind2b43472019-11-18 18:18:31 +08005283 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE) {
5284 if (vic)
5285 picture_aspect = drm_get_cea_aspect_ratio(vic);
5286 else if (hdmi_vic)
5287 picture_aspect = drm_get_hdmi_aspect_ratio(hdmi_vic);
5288 }
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305289
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305290 /*
5291 * The infoframe can't convey anything but none, 4:3
5292 * and 16:9, so if the user has asked for anything else
5293 * we can only satisfy it by specifying the right VIC.
5294 */
5295 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
Wayne Lind2b43472019-11-18 18:18:31 +08005296 if (vic) {
5297 if (picture_aspect != drm_get_cea_aspect_ratio(vic))
5298 return -EINVAL;
5299 } else if (hdmi_vic) {
5300 if (picture_aspect != drm_get_hdmi_aspect_ratio(hdmi_vic))
5301 return -EINVAL;
5302 } else {
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305303 return -EINVAL;
Wayne Lind2b43472019-11-18 18:18:31 +08005304 }
5305
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305306 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5307 }
5308
Wayne Lind2b43472019-11-18 18:18:31 +08005309 frame->video_code = vic;
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305310 frame->picture_aspect = picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005311 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06005312 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01005313
5314 return 0;
5315}
5316EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005317
Uma Shankar0d68b882019-02-19 22:43:00 +05305318/* HDMI Colorspace Spec Definitions */
5319#define FULL_COLORIMETRY_MASK 0x1FF
5320#define NORMAL_COLORIMETRY_MASK 0x3
5321#define EXTENDED_COLORIMETRY_MASK 0x7
5322#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5323
5324#define C(x) ((x) << 0)
5325#define EC(x) ((x) << 2)
5326#define ACE(x) ((x) << 5)
5327
5328#define HDMI_COLORIMETRY_NO_DATA 0x0
5329#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5330#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5331#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5332#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5333#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5334#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5335#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5336#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5337#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5338#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5339#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5340#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5341
5342static const u32 hdmi_colorimetry_val[] = {
5343 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5344 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5345 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5346 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5347 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5348 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5349 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5350 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5351 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5352 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5353 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5354};
5355
5356#undef C
5357#undef EC
5358#undef ACE
5359
5360/**
5361 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5362 * colorspace information
5363 * @frame: HDMI AVI infoframe
5364 * @conn_state: connector state
5365 */
5366void
5367drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5368 const struct drm_connector_state *conn_state)
5369{
5370 u32 colorimetry_val;
5371 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5372
5373 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5374 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5375 else
5376 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5377
5378 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5379 /*
5380 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5381 * structure and extend it in drivers/video/hdmi
5382 */
5383 frame->extended_colorimetry = (colorimetry_val >> 2) &
5384 EXTENDED_COLORIMETRY_MASK;
5385}
5386EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5387
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005388/**
5389 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5390 * quantization range information
5391 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005392 * @connector: the connector
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005393 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005394 * @rgb_quant_range: RGB quantization range (Q)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005395 */
5396void
5397drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005398 struct drm_connector *connector,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005399 const struct drm_display_mode *mode,
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005400 enum hdmi_quantization_range rgb_quant_range)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005401{
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005402 const struct drm_display_info *info = &connector->display_info;
5403
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005404 /*
5405 * CEA-861:
5406 * "A Source shall not send a non-zero Q value that does not correspond
5407 * to the default RGB Quantization Range for the transmitted Picture
5408 * unless the Sink indicates support for the Q bit in a Video
5409 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005410 *
5411 * HDMI 2.0 recommends sending non-zero Q when it does match the
5412 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005413 */
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005414 if (info->rgb_quant_range_selectable ||
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005415 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005416 frame->quantization_range = rgb_quant_range;
5417 else
5418 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005419
5420 /*
5421 * CEA-861-F:
5422 * "When transmitting any RGB colorimetry, the Source should set the
5423 * YQ-field to match the RGB Quantization Range being transmitted
5424 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5425 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005426 *
5427 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5428 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5429 * good way to tell which version of CEA-861 the sink supports, so
5430 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5431 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005432 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005433 if (!is_hdmi2_sink(connector) ||
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005434 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005435 frame->ycc_quantization_range =
5436 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5437 else
5438 frame->ycc_quantization_range =
5439 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005440}
5441EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5442
Ville Syrjälä076d9a52019-10-08 19:48:13 +03005443/**
5444 * drm_hdmi_avi_infoframe_bars() - fill the HDMI AVI infoframe
5445 * bar information
5446 * @frame: HDMI AVI infoframe
5447 * @conn_state: connector state
5448 */
5449void
5450drm_hdmi_avi_infoframe_bars(struct hdmi_avi_infoframe *frame,
5451 const struct drm_connector_state *conn_state)
5452{
5453 frame->right_bar = conn_state->tv.margins.right;
5454 frame->left_bar = conn_state->tv.margins.left;
5455 frame->top_bar = conn_state->tv.margins.top;
5456 frame->bottom_bar = conn_state->tv.margins.bottom;
5457}
5458EXPORT_SYMBOL(drm_hdmi_avi_infoframe_bars);
5459
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005460static enum hdmi_3d_structure
5461s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5462{
5463 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5464
5465 switch (layout) {
5466 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5467 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5468 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5469 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5470 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5471 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5472 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5473 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5474 case DRM_MODE_FLAG_3D_L_DEPTH:
5475 return HDMI_3D_STRUCTURE_L_DEPTH;
5476 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5477 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5478 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5479 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5480 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5481 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5482 default:
5483 return HDMI_3D_STRUCTURE_INVALID;
5484 }
5485}
5486
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005487/**
5488 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5489 * data from a DRM display mode
5490 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005491 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005492 * @mode: DRM display mode
5493 *
5494 * Note that there's is a need to send HDMI vendor infoframes only when using a
5495 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5496 * function will return -EINVAL, error that can be safely ignored.
5497 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005498 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005499 */
5500int
5501drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005502 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005503 const struct drm_display_mode *mode)
5504{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005505 /*
5506 * FIXME: sil-sii8620 doesn't have a connector around when
5507 * we need one, so we have to be prepared for a NULL connector.
5508 */
5509 bool has_hdmi_infoframe = connector ?
5510 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005511 int err;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005512
5513 if (!frame || !mode)
5514 return -EINVAL;
5515
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005516 if (!has_hdmi_infoframe)
5517 return -EINVAL;
5518
Ville Syrjälä949561e2019-10-04 17:19:13 +03005519 err = hdmi_vendor_infoframe_init(frame);
5520 if (err < 0)
5521 return err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005522
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005523 /*
5524 * Even if it's not absolutely necessary to send the infoframe
5525 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5526 * know that the sink can handle it. This is based on a
5527 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5528 * have trouble realizing that they shuld switch from 3D to 2D
5529 * mode if the source simply stops sending the infoframe when
5530 * it wants to switch from 3D to 2D.
5531 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005532 frame->vic = drm_mode_hdmi_vic(connector, mode);
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005533 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005534
5535 return 0;
5536}
5537EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005538
Dave Airlie5e546cd2016-05-03 15:31:12 +10005539static int drm_parse_tiled_block(struct drm_connector *connector,
5540 struct displayid_block *block)
5541{
5542 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5543 u16 w, h;
5544 u8 tile_v_loc, tile_h_loc;
5545 u8 num_v_tile, num_h_tile;
5546 struct drm_tile_group *tg;
5547
5548 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5549 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5550
5551 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5552 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5553 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5554 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5555
5556 connector->has_tile = true;
5557 if (tile->tile_cap & 0x80)
5558 connector->tile_is_single_monitor = true;
5559
5560 connector->num_h_tile = num_h_tile + 1;
5561 connector->num_v_tile = num_v_tile + 1;
5562 connector->tile_h_loc = tile_h_loc;
5563 connector->tile_v_loc = tile_v_loc;
5564 connector->tile_h_size = w + 1;
5565 connector->tile_v_size = h + 1;
5566
5567 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5568 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5569 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5570 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5571 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5572
5573 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5574 if (!tg) {
5575 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5576 }
5577 if (!tg)
5578 return -ENOMEM;
5579
5580 if (connector->tile_group != tg) {
5581 /* if we haven't got a pointer,
5582 take the reference, drop ref to old tile group */
5583 if (connector->tile_group) {
5584 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5585 }
5586 connector->tile_group = tg;
5587 } else
5588 /* if same tile group, then release the ref we just took. */
5589 drm_mode_put_tile_group(connector->dev, tg);
5590 return 0;
5591}
5592
Dave Airlie40d9b042014-10-20 16:29:33 +10005593static int drm_parse_display_id(struct drm_connector *connector,
5594 u8 *displayid, int length,
5595 bool is_edid_extension)
5596{
5597 /* if this is an EDID extension the first byte will be 0x70 */
5598 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005599 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005600 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005601
5602 if (is_edid_extension)
5603 idx = 1;
5604
Dave Airliec97291772016-05-03 15:38:37 +10005605 ret = validate_displayid(displayid, length, idx);
5606 if (ret)
5607 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005608
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005609 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04005610 for_each_displayid_db(displayid, block, idx, length) {
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005611 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5612 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005613
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005614 switch (block->tag) {
5615 case DATA_BLOCK_TILED_DISPLAY:
5616 ret = drm_parse_tiled_block(connector, block);
5617 if (ret)
5618 return ret;
5619 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005620 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5621 /* handled in mode gathering code. */
5622 break;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04005623 case DATA_BLOCK_CTA:
5624 /* handled in the cea parser code. */
5625 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005626 default:
5627 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5628 break;
5629 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005630 }
5631 return 0;
5632}
5633
5634static void drm_get_displayid(struct drm_connector *connector,
5635 struct edid *edid)
5636{
5637 void *displayid = NULL;
5638 int ret;
5639 connector->has_tile = false;
5640 displayid = drm_find_displayid_extension(edid);
5641 if (!displayid) {
5642 /* drop reference to any tile group we had */
5643 goto out_drop_ref;
5644 }
5645
5646 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5647 if (ret < 0)
5648 goto out_drop_ref;
5649 if (!connector->has_tile)
5650 goto out_drop_ref;
5651 return;
5652out_drop_ref:
5653 if (connector->tile_group) {
5654 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5655 connector->tile_group = NULL;
5656 }
5657 return;
5658}